This is an archive of the discontinued LLVM Phabricator instance.

[mlir][sparse] Add rewrite rules for sparse-to-sparse reshape operators.
ClosedPublic

Authored by bixia on Oct 3 2022, 7:14 AM.

Diff Detail

Event Timeline

bixia created this revision.Oct 3 2022, 7:14 AM
Herald added a project: Restricted Project. · View Herald Transcript
bixia requested review of this revision.Oct 3 2022, 7:14 AM
Peiming added inline comments.Oct 3 2022, 11:40 AM
mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp
382

Do we really need to distinguish enableRT here? Because I see no problem of rewriting reshape/concatenate even when RT is enabled.

Since the from/toCOO <==> foreach operator, we can relies on RT only for insertion?

But I am okay with how it works right now, maybe it should not be addressed now...

Peiming added inline comments.Oct 3 2022, 11:42 AM
mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp
425–426

Maybe you should use the builder from callback

bixia added inline comments.Oct 3 2022, 2:11 PM
mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp
382

If enableRT means keep using the RT libs as we are right now, we should rerwrite sparse2sparse reshape here.

bixia updated this revision to Diff 465010.Oct 4 2022, 7:44 AM
bixia marked an inline comment as done.

Use the foreach builder.

bixia updated this revision to Diff 465425.Oct 5 2022, 9:04 AM

Rebase.

LGTM.

mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp
385–386

Isn't it already guaranteed by verifier?

Anyway, no harm to do extra check

aartbik added inline comments.Oct 5 2022, 11:34 AM
mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp
301–366

not to nitpick, but we always use singular here, since each rule applies to one operator

382

But isn't it easier to have two ruless then, and add them below based on enableRT or not
(see how Peiming added rule conditionally at L540?

Having the bool leak into the constructors with different codepaths is harder to read than just applying different rule sets?

517

why is this so far away from the other reshape rewriter def?

mlir/test/Dialect/SparseTensor/sparse_reshape.mlir
3

shall we make a new test flag --test_sparse_rewriting that only calls populateSparseTensorRewriting() and applies those rules, so we can test this rewriting without having the full sparsification?

aartbik added inline comments.Oct 5 2022, 2:31 PM
mlir/test/Dialect/SparseTensor/sparse_reshape.mlir
3

This lifts rewriting into its own pass

https://reviews.llvm.org/D135319

so we can test the rewrite in isolation from sparsification

bixia updated this revision to Diff 465558.Oct 5 2022, 2:35 PM
bixia marked 3 inline comments as done.

Split the reshape rewrite rules.

bixia added inline comments.Oct 5 2022, 2:37 PM
mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp
301–366

I was thinking this is a template and is used to two reshape operators. But use singular instead.

382

Split into two rules anyway. It is a little different in the sense that we now add two rewrite rules for one operator.

385–386

Remove the check

bixia added inline comments.Oct 5 2022, 2:42 PM
mlir/test/Dialect/SparseTensor/sparse_reshape.mlir
3

Thanks. Will update the test when this is landed.

bixia updated this revision to Diff 465564.Oct 5 2022, 2:54 PM

Remove the check for element type.

Yeah, this looks really good. I will wait for the CHECK test simplification, but then good to go!

mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp
301–366

Ah, yeah, that is a good point too actually ;-)

382

I love how it looks now. Having two rules for same op is fine, since the logic is mutually exclusive, right?!

bixia updated this revision to Diff 465593.Oct 5 2022, 4:22 PM

Use sparse-tensor-rewrite for the test.

bixia marked an inline comment as done.Oct 5 2022, 4:24 PM
bixia added inline comments.
mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp
382

Yes, the two rewrite are mutually exclusive.

mlir/test/Dialect/SparseTensor/sparse_reshape.mlir
3

Fixed the test.

aartbik accepted this revision.Oct 5 2022, 4:28 PM
This revision is now accepted and ready to land.Oct 5 2022, 4:28 PM