This is an archive of the discontinued LLVM Phabricator instance.

[mlir][SparseTensor] Split scf.for loop into masked/unmasked parts
ClosedPublic

Authored by springerm on Aug 9 2021, 12:26 AM.

Details

Summary

Apply the "for loop peeling" pattern from SCF dialect transforms. This pattern splits scf.for loops into full and partial iterations. In the full iteration, all masked loads/stores are canonicalized to unmasked loads/stores.

Depends On D107222

Diff Detail

Event Timeline

springerm created this revision.Aug 9 2021, 12:26 AM
springerm requested review of this revision.Aug 9 2021, 12:26 AM
aartbik added inline comments.Aug 9 2021, 1:32 PM
mlir/test/Dialect/SparseTensor/sparse_vector.mlir
9–10

you are running all the tests in this file now for VEC-2-PEELED
shall we test the peeling in a separate test that does just that?

e.g. sparse_vector_peeled.mlir with just that one function, the one RUN, and the one CHECK?

springerm updated this revision to Diff 366178.Aug 12 2021, 8:52 PM
springerm marked an inline comment as done.

address comments

mlir/test/Dialect/SparseTensor/sparse_vector.mlir
9–10

sounds good!

aartbik added inline comments.Aug 13 2021, 5:50 PM
mlir/test/Dialect/SparseTensor/sparse_vector.mlir
139

would it be worthwhile to check this part too?

#map = affine_map<(d0, d1)[s0] -> (16, d0 - d1)>

or, if you don't want to do this here repeatedly, at least in the new sparse_vector_peeled test (but then as a before/after peeling, in that case we will need the CHECK-prefix again, see there

mlir/test/Dialect/SparseTensor/sparse_vector_peeled.mlir
3

no need for prefix anymore, just remove and use CHECK

springerm marked 2 inline comments as done.

address comments

mlir/test/Dialect/SparseTensor/sparse_vector.mlir
139

Yes, it should really be checked.

It just required a few smaller changes (replace CHECK-LABEL with -split-input-file).

aartbik added inline comments.Aug 16 2021, 9:45 AM
mlir/test/Dialect/SparseTensor/sparse_vector.mlir
22

here and below, why did you remove the LABEL check? that should still work well with the split input feature, right?

mlir/test/Dialect/SparseTensor/sparse_vector_peeled.mlir
21

probably still clean to have a

CHECK-LABEL: func @mul_ds

at the start

springerm marked an inline comment as done.Aug 16 2021, 5:04 PM
springerm added inline comments.
mlir/test/Dialect/SparseTensor/sparse_vector.mlir
22

The affine map that I check for (#[[map]]) appears outside of the function body. If I use CHECK-LABEL here, I cannot refer to variables that are defined before the CHECK-LABEL line.

Only CHECK-VEC2 and CHECK-VEC3 have a map in some of their test cases, but I removed the LABEL part everywhere for consistency. I think -split-input-file has the same purpose as CHECK-LABEL: to avoid mixing up regex variables from different test cases.

mlir/test/Dialect/SparseTensor/sparse_vector_peeled.mlir
21

Same problem here. If the CHECK-LABEL is before the CHECK-DAG: #[[map0..., I can no longer match the map0 (because it appears before the function). If I replace the CHECK: func @mul_s with a CHECK-LABEL: func @mul_s, the map was matched but I can no longer refer to [[map0]] after CHECK-LABEL.

But we should add a -split-input-file when more tests are added to this file.

aartbik added inline comments.Aug 16 2021, 9:28 PM
mlir/test/Dialect/SparseTensor/sparse_vector.mlir
22

Looking at test/Dialect//Affine/canonicalize.mlir, there a split file is used, a CHECK-DAG outside func and a CHECK-LABEL. So it seems to work if you -DAG the affine map check?

aartbik accepted this revision.Aug 16 2021, 9:32 PM

I will stop the bikeshedding and LG this revision. But please still have a look if you can keep the -LABEL.
If not, go ahead and I will have a look at it later once it goes in to convince myself one way or the other... ;-)

This revision is now accepted and ready to land.Aug 16 2021, 9:32 PM
mlir/test/Dialect/SparseTensor/sparse_vector.mlir
22

FWIW, the trick here is to use the $ character: see e.g. mlir/test/Dialect/Linalg/tile-indexed.mlir

// TILE-10n25-DAG: [[$MAP:#[a-zA-Z0-9_]*]] = affine_map<(d0, d1) -> (d0 + d1)>
// TILE-10n25-LABEL: func @indexed_vector
...
// TILE-10n25:     %[[NEW_I:.*]] = affine.apply [[$MAP]](%[[I]], %[[J]])
aartbik added inline comments.Aug 17 2021, 3:55 PM
mlir/test/Dialect/SparseTensor/sparse_vector.mlir
22

FWIW, the trick here is to use the $ character: see e.g. mlir/test/Dialect/Linalg/tile-indexed.mlir

Ah sweet! Yes, I had seen that test/Dialect//Affine/canonicalize.mlir worked the way I wanted, for example, but overlooked that the $ was used there too. Thanks for the detail here!

springerm updated this revision to Diff 367428.Aug 19 2021, 2:06 AM
springerm marked an inline comment as done.

address comments

springerm marked 3 inline comments as done.Aug 19 2021, 2:07 AM
springerm added inline comments.
mlir/test/Dialect/SparseTensor/sparse_vector.mlir
22

Nice, that fixed the issue.

This revision was landed with ongoing or failed builds.Aug 19 2021, 5:53 AM
This revision was automatically updated to reflect the committed changes.
springerm marked an inline comment as done.