[Codegen] Materialize implicit broadcasts for iGEMM consumer fusions#23954
Open
[Codegen] Materialize implicit broadcasts for iGEMM consumer fusions#23954
Conversation
When fusing consumer operations with iGEMM results, implicit broadcasts in the consumer's indexing maps must be materialized as explicit linalg.broadcast operations. Without this, the fused operation would have mismatched iteration domains. Add a utility to detect and materialize these implicit broadcasts before consumer fusion, ensuring the consumer's operands have compatible shapes with the iGEMM result. Signed-off-by: Max Dawkins <max.dawkins@gmail.com>
yzhang93
approved these changes
Mar 27, 2026
|
|
||
| // ----- | ||
|
|
||
| // Test that an expand_shape before a broadcasted element-wise consumer |
Contributor
There was a problem hiding this comment.
Suggested change
| // Test that an expand_shape before a broadcasted element-wise consumer | |
| // Test that an expand_shape before a broadcasted elementwise consumer |
| } | ||
| } | ||
|
|
||
| // Materialize implicit broadcasts in element-wise consumer ops. Consumer |
Contributor
There was a problem hiding this comment.
Suggested change
| // Materialize implicit broadcasts in element-wise consumer ops. Consumer | |
| // Materialize implicit broadcasts in elementwise consumer ops. Consumer |
| // generics with non-identity indexing maps (e.g., per-row bias with map | ||
| // (d0,d1,d2,d3) -> (d1)) cannot be folded through by the reshape | ||
| // propagation patterns below. Materialize the broadcasts explicitly to | ||
| // turn consumers into pure element-wise ops with identity maps. |
Contributor
There was a problem hiding this comment.
Suggested change
| // turn consumers into pure element-wise ops with identity maps. | |
| // turn consumers into pure elementwise ops with identity maps. |
| return failure(); | ||
| } | ||
| } | ||
| // Re-fuse the materialized broadcasts back into their element-wise |
Contributor
There was a problem hiding this comment.
Suggested change
| // Re-fuse the materialized broadcasts back into their element-wise | |
| // Re-fuse the materialized broadcasts back into their elementwise |
| // and linalg.transpose ops so reshape propagation could fold through | ||
| // identity-map generics. Now that reshapes have been pushed to the | ||
| // boundaries, generalize those named ops to generics and fuse them back | ||
| // into their consumers to produce compact element-wise generics. |
Contributor
There was a problem hiding this comment.
Suggested change
| // into their consumers to produce compact element-wise generics. | |
| // into their consumers to produce compact elementwise generics. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When converting convolutions to IGEMM and collapsing spatial/batch dimensions together, expand_shape ops are created at the result of the GEMM. These need to be propagated through the dispatch, but there could be consumers that are broadcasting across the expanded dimensions. These cannot be collapsed by normal reshape propagation patterns, so this PR adds additional patterns to decompose the broadcast out of elementwise ops before doing reshape propagation. Elementwise op fusion patterns are then used to clean up any decomposed ops that were not collapsed.