This is an archive of the discontinued LLVM Phabricator instance.

[mlir][sparse] Implement sparse_tensor.select
ClosedPublic

Authored by jim22k on Sep 27 2022, 1:41 PM.

Details

Summary

The region within select is used as the runtime criteria
of an scf::IfOp. If the check succeeds, the original value from the
sparse tensor remains in the output at the same location. If it fails,
the location becomes missing in the output.

The value is provided to the region block for the comparison. However,
the indices of the value may also be used during the comparison for
selecting the upper triangle of a matrix, for example.

Diff Detail

Event Timeline

jim22k created this revision.Sep 27 2022, 1:41 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 27 2022, 1:41 PM
jim22k requested review of this revision.Sep 27 2022, 1:41 PM
aartbik added inline comments.Sep 29 2022, 1:44 PM
mlir/include/mlir/Dialect/SparseTensor/Utils/Merger.h
77

would you mind moving this under kUnary (at all relevant places), so it follows the order in which you introduced them in the .td file better?

mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp
890

can you merge the else/if and save the extra "walk to the right"

894

See comment below.

mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp
1236

oh, this feels a bit hacky, since I would not expect a side effect from calling this method
the bookkeeping of caching the value should probably live in sparsification?

jim22k updated this revision to Diff 464705.Oct 3 2022, 8:59 AM
jim22k marked 3 inline comments as done.
  • Updates based on feedback
mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp
1236

I moved the runtime "value saving" to Sparsification. It does feel better there.

aartbik accepted this revision.Oct 3 2022, 9:50 AM

Nice work!

mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp
885

add an

assert(merger.exp(exp).val);

before the assignment

1054

add { } around the if and ass an

assert(!merger.exp(exp).val)

before the assignment

This revision is now accepted and ready to land.Oct 3 2022, 9:50 AM
jim22k updated this revision to Diff 464768.Oct 3 2022, 12:23 PM
jim22k marked 2 inline comments as done.
  • Add assert statements
This revision was landed with ongoing or failed builds.Oct 3 2022, 12:39 PM
This revision was automatically updated to reflect the committed changes.