This is an archive of the discontinued LLVM Phabricator instance.

[mlir][linalg] Avoid illegal elementwise fusion into reductions
ClosedPublic

Authored by herhut on Nov 9 2021, 10:51 AM.

Details

Summary

Fusing into a reduction is only valid if doing so does not erase information on a reduction dimensions size.

Diff Detail

Event Timeline

herhut created this revision.Nov 9 2021, 10:51 AM
herhut requested review of this revision.Nov 9 2021, 10:51 AM
mlir/test/Dialect/Linalg/fusion-elementwise-ops.mlir
918

the test name is confusing, how does it relate to fusion?

926

what is the proposed outcome here?

herhut updated this revision to Diff 386463.Nov 11 2021, 2:40 AM

Fix test

herhut marked an inline comment as done.Nov 11 2021, 2:40 AM
herhut added inline comments.
mlir/test/Dialect/Linalg/fusion-elementwise-ops.mlir
918

Yeah, I meant fusion. Got confused by the test above.

926

I added CHECK statements to ensure two linalg operations remain. A fusion would be illegal anyway, so the compiler aborts in that case.

nicolasvasilache accepted this revision.Nov 11 2021, 3:47 AM
nicolasvasilache added inline comments.
mlir/test/Dialect/Linalg/fusion-elementwise-ops.mlir
926

Ah yes, I missed it among the rest of the IR.

Do you mind putting those together at the top of the function block with a comment and a TODO: extend elementwise fusion to handle such cases ?

Thanks!

This revision is now accepted and ready to land.Nov 11 2021, 3:47 AM
herhut updated this revision to Diff 386503.Nov 11 2021, 6:54 AM
herhut marked an inline comment as done.

Add comment in test

This revision was landed with ongoing or failed builds.Nov 11 2021, 6:56 AM
This revision was automatically updated to reflect the committed changes.
mlir/test/Dialect/Linalg/fusion-elementwise-ops.mlir
926

To close the loop on this as we discussed offlie:
A fusion would be illegal anyway, so the compiler aborts in that case.

We know how to express and fuse this, it is similar to the shape-carrying operand we use in maxpooling: it is just NYI atm.
This shape-carrying operand may be the proper motivation to have the proper shape ops piped through linalg (TL;DR the output tensor we discussed a while back was not a proper motivation).