This is an archive of the discontinued LLVM Phabricator instance.

[mlir][Linalg] Avoid unnecessary propagating producer result to fused op result.
ClosedPublic

Authored by mravishankar on Nov 16 2022, 12:02 AM.

Details

Summary

Elementwise op fusion conserves the result of the producer in the
fused op, relying on later clean up patterns to drop unused results of
the fused op. Instead, if the producer result has no other use apart
from the consumer op, avoid making the producer result available in
the fused node. This saves some unnecessary IR manipulations.

Diff Detail

Event Timeline

mravishankar created this revision.Nov 16 2022, 12:02 AM
mravishankar requested review of this revision.Nov 16 2022, 12:02 AM
hanchung requested changes to this revision.Nov 17 2022, 9:56 AM

I was wondering why there are no tests, and found that corresponding lit tests failed. The code itself looks good to me, please also fix the lit test. Thanks!

This revision now requires changes to proceed.Nov 17 2022, 9:56 AM

Rebase and add lit test.

I was wondering why there are no tests, and found that corresponding lit tests failed. The code itself looks good to me, please also fix the lit test. Thanks!

Actually the lit test failure is just mid-air collision. Should be fixed now. With the pattern to remove unused results this change is mostly NFC. Added a test anyway.

hanchung accepted this revision.Nov 21 2022, 2:42 PM
This revision is now accepted and ready to land.Nov 21 2022, 2:42 PM

Hi Mahesh, I have a question regarding Linalg fusion in general.

It's common that user wants to fuse a matmul with a unary elementwise op (such as relu). Since matmul usually have 2 parallel + 1 reduction iterator, while the elementwise op usually only have 2 parallel iterators, it's hard to combine them into a single linalg.generic op like the examples in fusion-elementwise-ops.mlir.

So I'm wondering how is this type of fusion supported (or planned) currently? I'm trying to fuse a matmul op with a relu (contained in a generic op), both have memref input and output, so It will be really good if there are some examples of this type of fusion in the repo.

Thank you!