This is an archive of the discontinued LLVM Phabricator instance.

[mlir][sparse] reject kernels with non-sparsfiable reduction expression.
ClosedPublic

Authored by Peiming on Dec 8 2022, 12:03 PM.

Details

Summary

To address https://github.com/llvm/llvm-project/issues/59394.

Reduction on negation of the output tensor is a non-sparsifiable kernel, it creates cyclic dependency.

This patch reject those cases instead of crashing.

Diff Detail

Event Timeline

Peiming created this revision.Dec 8 2022, 12:03 PM
Herald added a project: Restricted Project. · View Herald Transcript
Peiming requested review of this revision.Dec 8 2022, 12:03 PM
Peiming edited the summary of this revision. (Show Details)Dec 8 2022, 12:05 PM
Peiming added a reviewer: qcolombet.
Peiming updated this revision to Diff 481397.Dec 8 2022, 12:12 PM

small fix

aartbik added inline comments.Dec 8 2022, 12:22 PM
mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp
588

It would then require ... (no s)

604

remove empty line

mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp
456

This should be an OR, right, not an AND?

out = (-out) + a

460

could we write this more concisely by testing that for every sub, check that LHS operand does not contain tensor, either direct, or deeper nested.

Thanks for the quick fix!
Could you add a test case as well? (E.g., the one from the bug.)

Peiming updated this revision to Diff 481438.Dec 8 2022, 1:45 PM

address comments.

Thanks for the quick fix!
Could you add a test case as well? (E.g., the one from the bug.)

The patch simply does not crash, your test file will still not be compiled ;-(

aartbik added inline comments.Dec 8 2022, 1:52 PM
mlir/include/mlir/Dialect/SparseTensor/Utils/Merger.h
275

nit, just t is the style in this file

mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp
99

move typedef and static helper *before* the Constructors section

(and leave empty vspace)

388

super nit: but we use unsigned t in this file for tensor (tid is your loop generator convention)

Peiming updated this revision to Diff 481443.Dec 8 2022, 1:59 PM
Peiming marked 7 inline comments as done.

address comments.

wrengr added inline comments.Dec 8 2022, 2:15 PM
mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp
27

+1 :)

wrengr added inline comments.Dec 8 2022, 2:19 PM
mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp
389

nit: since you only use this variable as the scrutinee of the switch statement, it'd be nicer to inline it there

423

ditto

aartbik accepted this revision.Dec 8 2022, 2:42 PM
aartbik added inline comments.
mlir/include/mlir/Dialect/SparseTensor/Utils/Merger.h
274

last nit: Returns

277

last nit: Returns

mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp
389

yeah, agreed, it will easily fit inside the switch (..)

This revision is now accepted and ready to land.Dec 8 2022, 2:42 PM

Thanks for the quick fix!
Could you add a test case as well? (E.g., the one from the bug.)

The patch simply does not crash, your test file will still not be compiled ;-(

You could still check that the IR is left untouched.
I assume that’s what you mean by not compiled.

Peiming updated this revision to Diff 481457.Dec 8 2022, 3:03 PM

add rejected test case

You could still check that the IR is left untouched.

And you could also do that on more complicated expressions to test hasNegateOnOut more thoroughly (like out = add in, (mul out, -1)).

Peiming updated this revision to Diff 481458.Dec 8 2022, 3:06 PM
Peiming marked 2 inline comments as done.

address comments

Peiming marked 3 inline comments as done.Dec 8 2022, 3:07 PM
Peiming updated this revision to Diff 481460.Dec 8 2022, 3:16 PM

add some comments in rejected.mlir

This revision was landed with ongoing or failed builds.Dec 8 2022, 3:36 PM
This revision was automatically updated to reflect the committed changes.