This is an archive of the discontinued LLVM Phabricator instance.

[mlir][sparse] Add sparse rewriting rules for tensor::ReshapeOp
ClosedPublic

Authored by anlunx on Apr 30 2023, 6:19 PM.

Diff Detail

Event Timeline

anlunx created this revision.Apr 30 2023, 6:19 PM
Herald added a project: Restricted Project. · View Herald Transcript
anlunx requested review of this revision.Apr 30 2023, 6:19 PM
anlunx updated this revision to Diff 518592.May 1 2023, 4:08 PM

Improve algorithm

Peiming added a subscriber: Peiming.May 1 2023, 4:37 PM
Peiming added inline comments.
mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp
389

Just think out loud, I somehow feel that you can reuse (or extend current collapse/expand_shape) here.

For example, extend reshapeCvs to take two reassociations, one for collapse and one for expand. collapse_shape/expand_shape only have one reassociation set, while reshape has both set. So that you can merge the three rewriters into similar implementation.

aartbik added inline comments.May 2 2023, 10:45 AM
mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp
349

super nit, all rules here have a comment of the form

/// Sparse rewriting rule for the xxx operator.

that just describes the operator, but does not repeat the exact type found in the template following anyway

367

can't we combine this with L361, before we collect the sizes?
there is nothing dependent on that call, right?

375

an unordered

387

This block of code needs a leading comment that shows some pseudo-code on what construct is being generate
Also +1 on Peiming's feedback, it feels like you borrowed sufficient code from elsewhere that making small shared utils starts to make more sense

402

These comments really do not help much without a leading comment that describes what is happening

anlunx updated this revision to Diff 519299.May 3 2023, 4:34 PM
anlunx marked 6 inline comments as done.

Address comments

mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp
367

Yes. It should be combined.

387

Added comment block

389

Used reshapeCvs twice to compute the destination coords

This looks good with the modifications. One last request, can you also add a CHECK test on the generated pattern. It does not have to test all the details, but at least the resulting loop structure to some extend?

mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_reshape.mlir
18

do we really need to test (VLA) vectorization here too?

anlunx updated this revision to Diff 522735.May 16 2023, 12:12 PM

Add a CHECK test

anlunx marked an inline comment as done.May 16 2023, 12:14 PM
anlunx added inline comments.
mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_reshape.mlir
18

Removed vectorization test

aartbik accepted this revision.May 16 2023, 1:14 PM
This revision is now accepted and ready to land.May 16 2023, 1:14 PM
This revision was landed with ongoing or failed builds.May 16 2023, 2:56 PM
This revision was automatically updated to reflect the committed changes.
anlunx marked an inline comment as done.