Skip to content

[Codegen] Materialize implicit broadcasts for iGEMM consumer fusions#23954

Open
Max191 wants to merge 1 commit intomainfrom
users/Max191/igemm-broadcast-materialize
Open

[Codegen] Materialize implicit broadcasts for iGEMM consumer fusions#23954
Max191 wants to merge 1 commit intomainfrom
users/Max191/igemm-broadcast-materialize

Conversation

@Max191
Copy link
Copy Markdown
Contributor

@Max191 Max191 commented Mar 27, 2026

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.

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>
@Max191 Max191 changed the title [Common] Materialize implicit broadcasts for iGEMM consumer fusions [Codegen] Materialize implicit broadcasts for iGEMM consumer fusions Mar 27, 2026

// -----

// Test that an expand_shape before a broadcasted element-wise consumer
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// into their consumers to produce compact element-wise generics.
// into their consumers to produce compact elementwise generics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants