Skip to content

[Codegen][CPU] Attach swizzle to inner_tiled encoder info. - #24455

Merged
bjacob merged 1 commit into
mainfrom
users/bjacob/cpu-encoder-info-swizzle
May 13, 2026
Merged

bjacob merged 1 commit into
mainfrom
users/bjacob/cpu-encoder-info-swizzle

Conversation

@bjacob

@bjacob bjacob commented May 12, 2026

Copy link
Copy Markdown
Collaborator

Follow-up to #24437. That commit made getUndistributedTileTypes honor the swizzle's permutation, but the encoder side (getInnerTiledEncodingInfo) was still producing a rank-2 row-major inner tile that ignored the swizzle's expand_shape and permutation. For existing intrinsics the two sides happen to be compatible under matchTileTypes' unit-dim filter, but the encoder's rank-2 shape disagrees with the rank-N permutation-aware tile type as soon as any swizzle has a non-identity permutation (e.g. pre-transposed intrinsics, added in a follow-up).

Set info.swizzle = IREE::CPU::getSwizzle(mma, operandIdx) so the pack pipeline's existing getSwizzledShape bridge applies the swizzle's expand_shape + transpose to the packed inner tile, matching the tile type getUndistributedTileTypes returns. Mirrors GPU's getEncodingInfoImpl. Drop the stale "Only used on GPU" comment on the swizzle field.

Test fallout: materialize_encoding_x86_64.mlir's four _inner_tiled_avx512 CHECK groups now expect the
tensor.expand_shape after each pack and the
tensor.collapse_shape before the unpack, with the rank-N inner tile that the swizzle materializes.

Progress towards #24323.

Follow-up to #24437. That commit made `getUndistributedTileTypes`
honor the swizzle's permutation, but the encoder side
(`getInnerTiledEncodingInfo`) was still producing a rank-2 row-major
inner tile that ignored the swizzle's `expand_shape` and
permutation. For existing intrinsics the two sides happen to be
compatible under `matchTileTypes`' unit-dim filter, but the
encoder's rank-2 shape disagrees with the rank-N permutation-aware
tile type as soon as any swizzle has a non-identity permutation
(e.g. pre-transposed intrinsics, added in a follow-up).

Set `info.swizzle = IREE::CPU::getSwizzle(mma, operandIdx)` so the
pack pipeline's existing `getSwizzledShape` bridge applies the
swizzle's `expand_shape` + `transpose` to the packed inner tile,
matching the tile type `getUndistributedTileTypes` returns.
Mirrors GPU's `getEncodingInfoImpl`. Drop the stale "Only used on
GPU" comment on the `swizzle` field.

Test fallout: `materialize_encoding_x86_64.mlir`'s four
`_inner_tiled_avx512` CHECK groups now expect the
`tensor.expand_shape` after each pack and the
`tensor.collapse_shape` before the unpack, with the rank-N inner
tile that the swizzle materializes.

Progress towards #24323.

Signed-off-by: Benoit Jacob <[email protected]>
@bjacob bjacob mentioned this pull request May 12, 2026
25 of 28 tasks
@bjacob
bjacob marked this pull request as ready for review May 12, 2026 19:37
@bjacob
bjacob merged commit 2418e61 into main May 13, 2026
65 of 66 checks passed
bjacob added a commit that referenced this pull request May 14, 2026
…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]>
bjacob added a commit that referenced this pull request May 14, 2026
…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 added a commit that referenced this pull request May 14, 2026
…r tiles. (#24488)

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.

Signed-off-by: Benoit Jacob <[email protected]>
Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
RattataKing pushed a commit to RattataKing/iree that referenced this pull request May 27, 2026
…24455)

Follow-up to iree-org#24437. That commit made `getUndistributedTileTypes` honor
the swizzle's permutation, but the encoder side
(`getInnerTiledEncodingInfo`) was still producing a rank-2 row-major
inner tile that ignored the swizzle's `expand_shape` and permutation.
For existing intrinsics the two sides happen to be compatible under
`matchTileTypes`' unit-dim filter, but the encoder's rank-2 shape
disagrees with the rank-N permutation-aware tile type as soon as any
swizzle has a non-identity permutation (e.g. pre-transposed intrinsics,
added in a follow-up).

Set `info.swizzle = IREE::CPU::getSwizzle(mma, operandIdx)` so the pack
pipeline's existing `getSwizzledShape` bridge applies the swizzle's
`expand_shape` + `transpose` to the packed inner tile, matching the tile
type `getUndistributedTileTypes` returns. Mirrors GPU's
`getEncodingInfoImpl`. Drop the stale "Only used on GPU" comment on the
`swizzle` field.

Test fallout: `materialize_encoding_x86_64.mlir`'s four
`_inner_tiled_avx512` CHECK groups now expect the
`tensor.expand_shape` after each pack and the
`tensor.collapse_shape` before the unpack, with the rank-N inner tile
that the swizzle materializes.

Progress towards iree-org#24323.

Signed-off-by: Benoit Jacob <[email protected]>
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