This is an archive of the discontinued LLVM Phabricator instance.

[mlir][sparse] Start migration to new surface syntax for STEA
ClosedPublic

Authored by aartbik on Jun 28 2023, 12:57 PM.

Details

Summary

We are in the progress of migrating to a much improved surface syntax for the Sparse Tensor Encoding Attribute (STEA).

You can see a preview of this in the StableHLO RFC at

https://github.com/openxla/stablehlo/blob/main/rfcs/20230210-sparsity.md

This design is courtesy Wren Romano.

This initial revision
(1) Introduces the first version of a new parser written by Wren Romano
(2) Introduces a simple "migration plan" using NEW_SYNTAX on the STEA, which will allow us to test the new parser with new examples, as well as migrate existing examples over without the need to rewrite them all

This first "drop" merely provides the entry points to parse the new syntax. The parser is still under active development. For example, we need to address the "lookahead" issue when parsing the lvl spec (viz. do we see l0 = d0 or a direct d0). Another larger task is to actually implement "affine" parsing (since the MLIR affine parser is not accessible in other parts of the tree).

EXAMPLE:

Currently, CSR looks like

#CSR = #sparse_tensor.encoding<{
  lvlTypes = ["dense","compressed"],
  dimToLvl = affine_map<(i,j) -> (i,j)>
}>

but you can "force" the new parser with

#CSR = #sparse_tensor.encoding<{
  NEW_SYNTAX =
  (d0, d1) -> (l0 = d0 : dense, l1 = d1 : compressed)
}>

Diff Detail

Event Timeline

aartbik created this revision.Jun 28 2023, 12:57 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 28 2023, 12:57 PM
aartbik requested review of this revision.Jun 28 2023, 12:57 PM
aartbik edited the summary of this revision. (Show Details)Jun 28 2023, 1:00 PM
aartbik edited the summary of this revision. (Show Details)
aartbik updated this revision to Diff 535506.Jun 28 2023, 1:39 PM

rebased with main

aartbik edited the summary of this revision. (Show Details)Jun 28 2023, 1:44 PM
aartbik updated this revision to Diff 535535.Jun 28 2023, 2:22 PM

windows build issue

aartbik updated this revision to Diff 535550.Jun 28 2023, 3:43 PM

windows build

aartbik updated this revision to Diff 535552.Jun 28 2023, 3:48 PM

rebased with main

Peiming added inline comments.Jun 28 2023, 4:42 PM
mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.h
143–169

Are these too much code duplication (here and below)

If type safety is important here, why not using a template and merge all the lvl/dim variants below?

aartbik edited the summary of this revision. (Show Details)Jun 28 2023, 6:34 PM
aartbik updated this revision to Diff 535598.Jun 28 2023, 6:42 PM

lint issues

aartbik updated this revision to Diff 535617.Jun 28 2023, 8:57 PM

windows build

aartbik marked an inline comment as done.Jun 28 2023, 9:00 PM
aartbik added inline comments.
mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.h
143–169

Yeah, perhaps there is a future change in mind, but for now let's get this in as close to Wren's code as possible (there are already various minor changes), so the history will become more clear.

aartbik updated this revision to Diff 535871.Jun 29 2023, 10:10 AM
aartbik marked an inline comment as done.

more window build fixes

Peiming accepted this revision.Jun 29 2023, 11:30 AM
This revision is now accepted and ready to land.Jun 29 2023, 11:30 AM