This is an archive of the discontinued LLVM Phabricator instance.

[mlir][sparse] add ability to select pointer/index storage type
ClosedPublic

Authored by aartbik on Nov 25 2020, 12:35 PM.

Details

Summary

This change gives sparse compiler clients more control over selecting
individual types for the pointers and indices in the sparse storage schemes.
Narrower width obviously results in smaller memory footprints, but the
range should always suffice for the maximum number of entries or index value.

Diff Detail

Event Timeline

aartbik created this revision.Nov 25 2020, 12:35 PM
aartbik requested review of this revision.Nov 25 2020, 12:35 PM
penpornk accepted this revision.Nov 25 2020, 4:23 PM

Thank you, Aart!

mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h
831

This is great. :)
I think there could be use cases for even kI16 or kI8 in the future, e.g., edge devices. (Some might store offset from the last nonzero instead of the absolute position.)

837

I like that the pointers and indices types are decoupled.

mlir/lib/Dialect/Linalg/Transforms/Sparsification.cpp
590–595

This is loop-invariant. Why it is moved into the loop? Just for my information.

mlir/test/Dialect/Linalg/sparse_storage.mlir
27

Wow. I'm loving the new, more meaningful RegEx labels!

30

Just curious, are these casts free in practice?

This revision is now accepted and ready to land.Nov 25 2020, 4:23 PM
aartbik marked an inline comment as done.Nov 25 2020, 5:08 PM
aartbik added inline comments.
mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h
831

yes, sounds like a good extension (starter project?!)

837

I indeed had them combined first, and then decided we needed even finer-grain control ;-)

mlir/lib/Dialect/Linalg/Transforms/Sparsification.cpp
590–595

Note that codegeneration relies on CSE and DCE to cleanup duplicates and remove unused code (like even when I generate the same constant, like zero or one many times, we end up with just one at the end of this pass). I moved it in so that we don't generate it when it is not needed (vis. no sparse code), but we might as well keep it out. Let me know if you prefer one strongly over the other.

mlir/test/Dialect/Linalg/sparse_storage.mlir
27

Yes, advantage of hand-written over auto generated ;-)

30

If indexType == xxType, it is a nop. But even if the widths are different, it comes typically for free with a truncating or extending move, on x86 at least.

penpornk added inline comments.Nov 25 2020, 5:28 PM
mlir/lib/Dialect/Linalg/Transforms/Sparsification.cpp
590–595

I have no preferences. Was just curious. Thank you for the explanation! :)

penpornk added inline comments.Nov 25 2020, 5:30 PM
mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h
831

Sounds good! Will try this when I'm done setting up.

This revision was automatically updated to reflect the committed changes.
aartbik marked an inline comment as done.

LGTM, thanks Aart!