Skip to content

[Codegen][CPU] Fix lowerGenericScalarToVectorContract for rank-N inner tiles. - #24488

Merged
bjacob merged 1 commit into
mainfrom
users/bjacob/cpu-generic-scalar-rank-n-tile
May 14, 2026
Merged

bjacob merged 1 commit into
mainfrom
users/bjacob/cpu-generic-scalar-rank-n-tile

Conversation

@bjacob

@bjacob bjacob commented May 14, 2026

Copy link
Copy Markdown
Collaborator

After #24455 attaches the per-operand swizzle to the encoder info, the inner_tiled op for the generic-scalar 1×1×1 MMA family receives operands whose non-unit dim (size = intrinsics_{m,n,k}) can sit at any position in the rank-N tile, not just at the start. The previous dropTrailingUnitDims reduction relied on non-unit dims being leading, so e.g. an LHS tile of shape vector<1x1x4x1x1xf32> (intrinsics_m=4 with N=K=1) collapsed to rank-3 vector<1x1x4> instead of the rank-2 (M, K) shape vector.contract needs — and the wrapper code then emitted a malformed vector.broadcast of vector<4x1> into vector<1x1x4x1x1> to glue the result back to the inner_tiled's output tile.

Switch to a vector.shape_cast directly to the canonical (M, K) / (N, K) / (M, N) rank-2 shape: by construction (1×1×1 base intrinsic) every non-unit dim contributing to an operand tile came from an intrinsics_* cross-intrinsic factor, so the total element count of each operand is exactly intrinsics_m * intrinsics_k (etc.) and the shape_cast is element-preserving. shape_cast the contract result back to the inner_tiled op's original ACC tile shape so verification matches downstream.

Progress towards #24323.

…r tiles.

After #24455 attaches the per-operand swizzle to the encoder info, the
`inner_tiled` op for the generic-scalar 1×1×1 MMA family receives
operands whose non-unit dim (size = `intrinsics_{m,n,k}`) can sit at
any position in the rank-N tile, not just at the start. The previous
`dropTrailingUnitDims` reduction relied on non-unit dims being leading,
so e.g. an LHS tile of shape `vector<1x1x4x1x1xf32>` (intrinsics_m=4
with N=K=1) collapsed to rank-3 `vector<1x1x4>` instead of the rank-2
`(M, K)` shape `vector.contract` needs — and the wrapper code then
emitted a malformed `vector.broadcast` of `vector<4x1>` into
`vector<1x1x4x1x1>` to glue the result back to the inner_tiled's
output tile.

Switch to a `vector.shape_cast` directly to the canonical
`(M, K) / (N, K) / (M, N)` rank-2 shape: by construction (1×1×1 base
intrinsic) every non-unit dim contributing to an operand tile came
from an `intrinsics_*` cross-intrinsic factor, so the total element
count of each operand is exactly `intrinsics_m * intrinsics_k` (etc.)
and the shape_cast is element-preserving. `shape_cast` the contract
result back to the inner_tiled op's original ACC tile shape so
verification matches downstream.

Progress towards #24323.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Signed-off-by: Benoit Jacob <[email protected]>
@bjacob
bjacob marked this pull request as ready for review May 14, 2026 16:41
@bjacob
bjacob requested a review from hanhanW as a code owner May 14, 2026 16:41
@bjacob bjacob mentioned this pull request May 14, 2026
25 of 28 tasks
@bjacob
bjacob merged commit 1f2c362 into main May 14, 2026
64 of 66 checks passed
@bjacob
bjacob deleted the users/bjacob/cpu-generic-scalar-rank-n-tile branch May 14, 2026 20:18
RattataKing pushed a commit to RattataKing/iree that referenced this pull request May 27, 2026
…r tiles. (iree-org#24488)

After iree-org#24455 attaches the per-operand swizzle to the encoder info, the
`inner_tiled` op for the generic-scalar 1×1×1 MMA family receives
operands whose non-unit dim (size = `intrinsics_{m,n,k}`) can sit at any
position in the rank-N tile, not just at the start. The previous
`dropTrailingUnitDims` reduction relied on non-unit dims being leading,
so e.g. an LHS tile of shape `vector<1x1x4x1x1xf32>` (intrinsics_m=4
with N=K=1) collapsed to rank-3 `vector<1x1x4>` instead of the rank-2
`(M, K)` shape `vector.contract` needs — and the wrapper code then
emitted a malformed `vector.broadcast` of `vector<4x1>` into
`vector<1x1x4x1x1>` to glue the result back to the inner_tiled's output
tile.

Switch to a `vector.shape_cast` directly to the canonical `(M, K) / (N,
K) / (M, N)` rank-2 shape: by construction (1×1×1 base intrinsic) every
non-unit dim contributing to an operand tile came from an `intrinsics_*`
cross-intrinsic factor, so the total element count of each operand is
exactly `intrinsics_m * intrinsics_k` (etc.) and the shape_cast is
element-preserving. `shape_cast` the contract result back to the
inner_tiled op's original ACC tile shape so verification matches
downstream.

Progress towards iree-org#24323.

Signed-off-by: Benoit Jacob <[email protected]>
Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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