This is an archive of the discontinued LLVM Phabricator instance.

[mlir][sparse] Converting SparseTensorCOO to use standard C++-style iterators.
ClosedPublic

Authored by wrengr on Oct 7 2022, 1:47 PM.

Details

Summary

This differential comprises three related changes: (1) it gives SparseTensorCOO standard C++-style iterators; (2) it removes the old iterator stuff from SparseTensorCOO; and (3) it introduces SparseTensorIterator which behaves like the old SparseTensorCOO iterator stuff used to.

The SparseTensorIterator class is needed because the MLIR codegen cannot easily use the C++-style iterators (hence why SparseTensorCOO had the old iterator stuff). Distinguishing SparseTensorIterator from SparseTensorCOO also helps improve API hygiene since these two classes are used for distinct purposes. And having SparseTensorIterator as its own class enables changing the underlying implementation in the future, without needing to worry about updating all the codegen tests etc.

Diff Detail

Event Timeline

wrengr created this revision.Oct 7 2022, 1:47 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 7 2022, 1:47 PM
wrengr requested review of this revision.Oct 7 2022, 1:47 PM
wrengr updated this revision to Diff 466168.Oct 7 2022, 1:50 PM

removing obsolete todos

aartbik accepted this revision.Oct 11 2022, 1:16 PM
aartbik added inline comments.
mlir/include/mlir/ExecutionEngine/SparseTensor/COO.h
99

yeah, this is a pretty neat "forwarding" to avoid the problem

mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorConversion.cpp
887

note that we don't really have this method, so perhaps

new SparseTensor(src, Iterator)

or something like that will make that more clear/

This revision is now accepted and ready to land.Oct 11 2022, 1:16 PM
wrengr marked an inline comment as done.Oct 11 2022, 1:59 PM
wrengr added inline comments.
mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorConversion.cpp
887

but we don't have that method either ;) Or did you mean spelling it more like the generated MLIR code rather than like the pseudo-C++ code used in the rest of the comment?

fwiw, I was thinking about changing the SparseTensorIterator ctor to take the SparseTensorStorage object directly (and call toCOO internally), but got a bit hung up on the details since toCOO also takes a permutation argument but the current version takes it as just a pointer rather than using a cleaner/safer API. So I'll probably end up making that change a bit down the road once I work out the details a bit more