This is an archive of the discontinued LLVM Phabricator instance.

[mlir][sparse] Reducing computational complexity
ClosedPublic

Authored by wrengr on Jul 1 2022, 12:02 PM.

Details

Summary

This is a followup to D128847. The AffineMap::getPermutedPosition method performs a linear scan of the map, thus the previous implementation had asymptotic complexity of O(|topSort| * |m|). This change reduces that to O(|topSort| + |m|).

Diff Detail

Event Timeline

wrengr created this revision.Jul 1 2022, 12:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 1 2022, 12:02 PM
wrengr requested review of this revision.Jul 1 2022, 12:02 PM
aartbik added inline comments.Jul 1 2022, 12:16 PM
mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp
129

why do you compute the invSz and permSz twice?
just use the one below, and assert on it if you are worried about a mismatch
(although that is done at many other places too already)

132

Perhaps, in the long run, we should push such logic into AffineMap for permutations, so that getPermutedPosition is O(1) again, or we get a direct inverse back, because the original code is easier to read than the optimized code (and it would benefit all clients). Maybe add a TODO for that (bonus points for also making it happen ;-)

wrengr marked an inline comment as done.Jul 1 2022, 12:40 PM
wrengr added inline comments.
mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp
129

Each one is only computed once? I use them separately because of the mismatch worry. I considered asserting they were the same, but wasn't sure if that was actually an invariant or not (it's been too ling since I looked at this code). I'll add the assertion

132

+1. I'll write up an RFC for that

wrengr updated this revision to Diff 441771.Jul 1 2022, 12:41 PM
wrengr marked 2 inline comments as done.

addressing comments

aartbik accepted this revision.Jul 1 2022, 12:43 PM

Ship it!

This revision is now accepted and ready to land.Jul 1 2022, 12:43 PM
This revision was landed with ongoing or failed builds.Jul 1 2022, 12:55 PM
This revision was automatically updated to reflect the committed changes.