This is an archive of the discontinued LLVM Phabricator instance.

[mlir][sparse] support Parallel for/reduction.
ClosedPublic

Authored by Peiming on Oct 13 2022, 5:16 PM.

Diff Detail

Event Timeline

Peiming created this revision.Oct 13 2022, 5:16 PM
Herald added a project: Restricted Project. · View Herald Transcript
Peiming requested review of this revision.Oct 13 2022, 5:16 PM
Peiming updated this revision to Diff 468242.Oct 17 2022, 10:01 AM

update comments

Peiming updated this revision to Diff 468245.Oct 17 2022, 10:08 AM

update comments..

Peiming updated this revision to Diff 468251.Oct 17 2022, 10:27 AM

add more assertions

Peiming updated this revision to Diff 468253.Oct 17 2022, 10:32 AM

minor fix

Peiming updated this revision to Diff 468281.Oct 17 2022, 11:41 AM

code cleanup

Peiming updated this revision to Diff 468282.Oct 17 2022, 11:43 AM

minor updates.

wrengr added inline comments.Oct 18 2022, 5:50 PM
mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.h
361

Like I commented on D136185, do you actually need SmallVectorImpl here or can you use MutableArrayRef instead?

451

ditto

455

ditto

Peiming updated this revision to Diff 469796.Oct 21 2022, 3:25 PM

minor changes..

Peiming marked 3 inline comments as done.Oct 24 2022, 12:31 PM
Peiming updated this revision to Diff 470268.Oct 24 2022, 12:52 PM

minor fix

aartbik added inline comments.Oct 26 2022, 6:18 PM
mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.h
430

Can you make this

For sequential for loops:

(the For for reads a bit like a typo)

445

do we only support addition reduction?

mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp
442

Variables

mlir/test/Dialect/SparseTensor/sparse_parallel.mlir
155

this is good for *this* test, since it looks for structure

but can you also add a more strict CHECK test for all details of scf.reduce?
that all values in and out are right and such, preferably not in this test but a new one

mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_matvec.mlir
8

parallelizaiton

Peiming added inline comments.Oct 26 2022, 7:13 PM
mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.h
445

No, but we only support "one-line reduction".

Peiming updated this revision to Diff 471242.Oct 27 2022, 11:36 AM
Peiming marked 4 inline comments as done.

+ address comments
+ add a check test

Peiming marked an inline comment as done.Oct 27 2022, 11:37 AM
Peiming added inline comments.
mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.h
430

Haha, indeed!

445

I added some comment here to make it more clear.

some super nits to wrap this up ;-)

mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.cpp
197

although correct english, do you really need temporally or temporarily?

465

Here and below, follow the "full sentence" style we usually follow

mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.h
436

end with :

449–450

period

mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp
910–911

"reduction*s*" or "a parallel reduction"

mlir/test/Dialect/SparseTensor/sparse_parallel_reduce.mlir
42 ↗(On Diff #471245)

yeah, nice!

mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_matmul.mlir
6 ↗(On Diff #471245)

period at end

mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_matvec.mlir
8

same

Peiming updated this revision to Diff 472345.Nov 1 2022, 10:15 AM
Peiming marked 8 inline comments as done.

rebase + address comments from Aart.

mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.cpp
197

You are right ;-(.

aartbik added inline comments.Nov 2 2022, 9:29 AM
mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.cpp
216

not for this revision, but the loop emitter methods are becoming a bit big (for example this one, but also the exit loop below!)

perhaps we can later refactor the public methods into small methods that call a number of private methods with a very specific function, e.g. prepare induction, do reduction etc.

WDYT?

mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp
443

The name genReducUpdateStmt is a bit misnomer, right?
You basically do all the logic needed for starting/ending a loop, including handling reductions?
Can we come up with something better?

But moving the two similar parts into one method is good refactoring!

911

testing for expCount is very hard to read in these expression

can we make this something like

isExpanion = codegenExpCount

and then use it in the expressions?

Peiming added inline comments.Nov 2 2022, 5:46 PM
mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.cpp
216

yeah, that's a good idea!

Peiming updated this revision to Diff 472969.Nov 3 2022, 9:45 AM
Peiming marked an inline comment as done.

address comments from Aart.

mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp
911

I instead followed the way how you did with codegen.SparseOut, which seems even more clear!

Peiming marked an inline comment as done.Nov 3 2022, 11:16 AM
aartbik accepted this revision.Nov 3 2022, 8:52 PM

Nice work, Peiming!

This finishes your starter ;-)

This revision is now accepted and ready to land.Nov 3 2022, 8:52 PM
This revision was automatically updated to reflect the committed changes.

This change appears to have broken the Windows buildbot. https://lab.llvm.org/buildbot/#/builders/13/builds/28002/steps/6/logs/stdio

C:\buildbot\mlir-x64-windows-ninja\llvm-project\mlir\lib\Dialect\SparseTensor\Transforms\CodegenUtils.cpp(227): error C2220: the following warning is treated as an error
C:\buildbot\mlir-x64-windows-ninja\llvm-project\mlir\lib\Dialect\SparseTensor\Transforms\CodegenUtils.cpp(227): warning C4804: '<=': unsafe use of type 'bool' in operation

This change appears to have broken the Windows buildbot. https://lab.llvm.org/buildbot/#/builders/13/builds/28002/steps/6/logs/stdio

C:\buildbot\mlir-x64-windows-ninja\llvm-project\mlir\lib\Dialect\SparseTensor\Transforms\CodegenUtils.cpp(227): error C2220: the following warning is treated as an error
C:\buildbot\mlir-x64-windows-ninja\llvm-project\mlir\lib\Dialect\SparseTensor\Transforms\CodegenUtils.cpp(227): warning C4804: '<=': unsafe use of type 'bool' in operation

Thanks, I will take a look!

This change appears to have broken the Windows buildbot. https://lab.llvm.org/buildbot/#/builders/13/builds/28002/steps/6/logs/stdio

C:\buildbot\mlir-x64-windows-ninja\llvm-project\mlir\lib\Dialect\SparseTensor\Transforms\CodegenUtils.cpp(227): error C2220: the following warning is treated as an error
C:\buildbot\mlir-x64-windows-ninja\llvm-project\mlir\lib\Dialect\SparseTensor\Transforms\CodegenUtils.cpp(227): warning C4804: '<=': unsafe use of type 'bool' in operation

Please see https://reviews.llvm.org/D137560