This is an archive of the discontinued LLVM Phabricator instance.

[mlir][sparse] Improve the non-stable sort implementation.
ClosedPublic

Authored by bixia on Nov 2 2022, 2:32 PM.

Details

Summary

Replace the quick sort partition method with one that is more similar to the
method used by C++ std quick sort. This improves the runtime for sorting
sk_2005.mtx by more than 10x.

Diff Detail

Event Timeline

bixia created this revision.Nov 2 2022, 2:32 PM
Herald added a project: Restricted Project. · View Herald Transcript
bixia requested review of this revision.Nov 2 2022, 2:32 PM
bixia edited the summary of this revision. (Show Details)Nov 2 2022, 2:32 PM
bixia edited the summary of this revision. (Show Details)Nov 2 2022, 2:38 PM
bixia updated this revision to Diff 473264.Nov 4 2022, 9:39 AM

Refactor the functions for creating code to compare xs values.

aartbik added inline comments.Nov 4 2022, 3:42 PM
mlir/lib/Dialect/SparseTensor/Transforms/SparseBufferRewriting.cpp
145

Here and below, super nit, but

"whether x[i] is equal to x[j]."

reads a bit better?

180

is this line correct? seems from the less than code?

339

assert(step < 0) or explicit test and third branch not reached?

mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_rewrite_sort.mlir
85

is this now stable too, or by luck?

aartbik accepted this revision.Nov 4 2022, 4:16 PM

Good to go after addressing nits.

This revision is now accepted and ready to land.Nov 4 2022, 4:16 PM
bixia updated this revision to Diff 473537.Nov 6 2022, 6:50 PM
bixia marked 3 inline comments as done.

Address review comments.

mlir/lib/Dialect/SparseTensor/Transforms/SparseBufferRewriting.cpp
145

Agree, fixed here and below.

180

should compare x2[i] != x2[j]. thanks for catching this.

339

add assert.

mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_rewrite_sort.mlir
85

By luck. The algorithm may or may not maintain the order of equal elements.

This revision was automatically updated to reflect the committed changes.