[Mlir-commits] [mlir] [mlir] [linalg] Add canonicalize pattern to swap transpose with broadcast (PR #97063)

Stella Laurenzo llvmlistbot at llvm.org
Sat Jul 6 19:12:46 PDT 2024


stellaraccident wrote:

> Add canonicalize pattern that implement canonicalize:
> 
> transpose(broadcast(input)) -> broadcast(transpose(input))
> 
> Reduce the cost of transpose.

I'm not opposed to this being a canonicalization outright, but -- transpose and broadcast have no cost on their own/abstractly and justifying it based on that puts this in the realm of an optimization, not a canonicalization.

With that said, if we want to say that this is a canonical form, that  may be an ok thing to do, but we need to define it in terms of the lattice of all such ops. As Diego says above, there is often an interplay between several ops of this category and I'd prefer we not add a one off pattern without a better justification and analysis of what it means for all of them.

No matter what we do, let's not land such a canonicalization with a justification that it is an optimization (ie. Which is what the pr description states as the justification). I'm marking changes requested on that point and am happy to be overridden on that if the consensus is that this makes sense in terms of the lattice versus as a piece of a specific optimization strategy.

In general, there are entire optimization pipelines that are responsible for propagating various classes of layout and data movement operations. Such things are non trivial and are better done as an actual algorithm that can be controlled/cost modeled/etc.

https://github.com/llvm/llvm-project/pull/97063


More information about the Mlir-commits mailing list