This is an archive of the discontinued LLVM Phabricator instance.

[mlir][sparse] add asCOO() functionality to sparse tensor object
ClosedPublic

Authored by aartbik on Aug 24 2021, 6:59 PM.

Details

Summary

This prepares general sparse to sparse conversions. The code that
needs to be generated using this new feature is now simply:

(1) coo = sparse_tensor_1->asCOO(); source format1
(2) sparse_tensor_2 = newSparseTensor(coo);
destination format2

By using COO as an intermediate, we can do *all* conversions without
having to implement the full O(N^2) conversion matrix. Note that we
can always improve particular conversions individually if a faster
solution is required.

Diff Detail

Event Timeline

aartbik created this revision.Aug 24 2021, 6:59 PM
aartbik requested review of this revision.Aug 24 2021, 7:00 PM
aartbik added inline comments.Aug 24 2021, 8:21 PM
mlir/lib/ExecutionEngine/SparseUtils.cpp
297

Please note that this implementation does not take the permutation of either source or destination into account yet (i.e. this version is for the identity permutations). A follow-up CL will dot all the i's and cross the t's, followed by actual lowering code support in SparseTensorConversion.

aartbik updated this revision to Diff 368689.Aug 25 2021, 11:35 AM

cross the ts and dot the is

mlir/lib/ExecutionEngine/SparseUtils.cpp
297

I added the required permutation requirements in this CL also. The next revision that will build on this will finalize the sparse conversions (with just a few lines of code).

bixia accepted this revision.Aug 25 2021, 2:56 PM
bixia added inline comments.
mlir/lib/ExecutionEngine/SparseUtils.cpp
224–230

It could be nice if we can have a more specially names or/and documentation to help understanding of the two usages of "tmp".
the first tmp: Apply the reversed permutation to the storage sizes to get the sizes of the tensor.
the second tmp: Apply the reversed permutation to the permutation of the coo tensor to get the accumulated permutation from the tensor to the coo tensor.

This revision is now accepted and ready to land.Aug 25 2021, 2:56 PM
aartbik marked an inline comment as done.Aug 25 2021, 8:43 PM
aartbik added inline comments.
mlir/lib/ExecutionEngine/SparseUtils.cpp
224–230

Yeah, probably premature optimization keeping the same vector for both.
I changed this back into two vectors with better names, leaving the optimization for another time (not that this one will help much anyway).

aartbik updated this revision to Diff 368800.Aug 25 2021, 9:03 PM
aartbik marked an inline comment as done.

renamed tmp vector, used two different ones, added comments