This is an archive of the discontinued LLVM Phabricator instance.

[mlir][Linalg] Add callbacks to fusion of elementwise operations to control fusion.
ClosedPublic

Authored by mravishankar on Apr 2 2021, 3:24 PM.

Details

Summary

Right now Elementwise operations fusion in Linalg fuses everything it
can. This can run up against resource limits of the target hardware
without some checks. This patch adds a callback function that clients
can use to implement a cost function. When two elementwise operations
are deemed structurally fusable, the callback can be used to control
if the fusion applies.

Depends On D99819

Diff Detail

Event Timeline

mravishankar created this revision.Apr 2 2021, 3:24 PM
mravishankar requested review of this revision.Apr 2 2021, 3:24 PM
hanchung accepted this revision.Apr 4 2021, 11:51 PM
hanchung added inline comments.
mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h
73–76

Adding a blank line right before the comment usually helps readability.

91

/*producer=*/ and /*consumer=*/

mlir/test/lib/Transforms/TestLinalgElementwiseFusion.cpp
22–24

Do we really need a template here? I don't see a reason to make it template. How about making limit to be a function argument?

25–28

When I see a dyn_cast, I would expect you to check if it is null. Otherwise, it should be cast, and will hit an assertion in dbg mode if it is not a Linalg op (because this is really wrong).

This revision is now accepted and ready to land.Apr 4 2021, 11:51 PM
mravishankar marked 2 inline comments as done.

Addressing comments.

mravishankar marked 2 inline comments as done.Apr 5 2021, 3:35 PM
mravishankar added inline comments.
mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h
91

I dont think so. They are arguments here (they are just not used).

mlir/test/lib/Transforms/TestLinalgElementwiseFusion.cpp
22–24

Then it cant be used as a callback directly below.

25–28

Yeah, good catch. Just dropping use of LinalgOp here.

mravishankar marked 2 inline comments as done.

Fixing builds

This revision was landed with ongoing or failed builds.Apr 5 2021, 4:09 PM
This revision was automatically updated to reflect the committed changes.