Repository navigation
[Codegen][CPU] Fix DataTiledMMAAttr::getUndistributedTileTypes to honor swizzle permutation. - #24437
Merged
Merged
Conversation
bjacob
force-pushed
the
users/bjacob/cpu-mma-align-permutation-with-gpu
branch
from
May 11, 2026 19:29
e8d7312 to
ff1f83a
Compare
bjacob
added a commit
that referenced
this pull request
May 11, 2026
…sed enums. This is take two of #24404 which was reverted due to a RDNA4 regression (#24427); see commit message below for what changed in the reland. Each non-square hardware MMA now appears as two `MMAIntrinsic` enum values — one per orientation — named after their actual MxNxK shape (e.g. `MMA_X86_AVX512_1x16x1_F32_F32` and its M↔N-swapped sibling `MMA_X86_AVX512_16x1x1_F32_F32`). The swapped sibling of `X` is `X | 1` (bit 0 of D in the enum's encoding), so consecutive enum values form natural/swapped pairs. The `transposed_intrinsic` boolean on `DataTiledMMAAttr` is removed; both orientations show up as distinct candidates in `getMmaIntrinsicsForTargetConfig` and the existing `chooseIntrinsic` scoring picks between them. A new `assert(isMmaIntrinsicArrayValid(...))` at the bottom of `getMmaIntrinsicsForTargetConfig` enforces the convention: strictly increasing, every swapped entry preceded by its natural sibling, and square/type-symmetric singletons allowed (covers the generic-scalar 1×1×1 family). Motivation: the boolean was originally there to avoid 2× enum growth, but it leaked orientation-handling into every layer that touched MMA layouts — swizzles, ACC encoding-info, the cross-intrinsic ACC index, broadcast direction. It was also poised to get worse: asymmetric LLVM intrinsics (vpdpbusd) and non-x86 targets (no broadcast) would each need bespoke handling under the boolean. With separate enum values, each orientation lowers independently. Swapped enums introduce intrinsics where the ACC swizzle's `Codegen::expand` insertion order leaves a non-identity permutation (intrinsics_n then intrinsics_m, interleaving N and M dims in memory). That permutation is what's actually stored, but the previous `DataTiledMMAAttr::getUndistributedTileTypes` silently ignored it and returned the operand-natural `(prod(group[0]), prod(group[1]))` shape — wrong once the permutation is non-trivial, latent until now. #24437 fixes that at the source: tile types now reflect the swizzle's actual memory order. With that in place, the `reshapeToSwizzleDistributed` bridge in `MMAUtils.cpp` collapses to a plain `vector.shape_cast` — same as it was before non-identity permutations existed. New CHECKs in `lower_inner_tiled.mlir`'s `lower_avx512_16x1x1_f32` pin the shape_cast pair on the first multi-non-unit-dim swapped-intrinsic test case in the file. RDNA4 regression delta from #24404: the reverted PR took a different path — it left `getUndistributedTileTypes` returning the wrong shape and introduced an explicit `vector.transpose` in `reshapeToSwizzleDistributed` to compensate. That transpose was correct for CPU but on GPU stacked on top of GPU's already-permuted distributed shape, scrambling per-lane data on RDNA4 (the only target whose swizzle has a non-trivial permutation today). Fixing the bogus shape at the `getUndistributedTileTypes` source in #24437 removes the transpose entirely and keeps the shared lowering body uniform across targets. Progress towards #24323 Signed-off-by: Benoit Jacob <[email protected]>
…or swizzle permutation. The swizzle's `permutation` is ground truth for CPU memory layout — for pre-transposed intrinsics with both `intrinsics_m > 1` and `intrinsics_n > 1` on the ACC, the `Codegen::expand` insertion order produces a non-identity permutation that interleaves M and N dims, and that interleaved order is what the encoding materialization actually lays out in memory. `DataTiledMMAAttr::getUndistributedTileTypes` was silently ignoring that permutation: it returned `(prod(expandShape[0]), prod(expandShape[1]))` — operand-natural row-major — which contradicted the swizzle's stated memory order. The mismatch was dormant when the permutation happened to be identity (all pre-pretransposed intrinsics) but produces wrong tile types for the M↔N-swapped enum values that the next branch in this stack introduces, and is the root cause of the RDNA4 regression that took down #24404. Fix: lift the per-dim walk into a new shared utility `Codegen::getTileVectorType(swizzle, elemType[, keepSize])` in `IREECodegenTypes`. The shape is `sliceSwizzledShape(swizzle, keepSize)` — every dim of `expandShape` in `swizzle.permutation()` order, with optional per-dim masking to size 1. A dim with a non-`One` symbolic multiplier maps to a scalable axis. CPU's `DataTiledMMAAttr::getUndistributedTileTypes` and GPU's `DataTiledMMAInterfaceAttr::{getUndistributedTileTypes,getDistributedTileTypes}` now all go through it (the GPU distributed variant passes a `d.kind() != CrossThread` mask to fold thread-distribution factors to size-1 axes). For trivial CPU cases (every `expandShape` group is a single dim — the only configuration `fixupSwizzle` leaves after the base intrinsic build, where `intrinsics_{m,n,k}` haven't yet been expanded in) the result is the same rank-2 `(outer, inner)` shape CPU historically returned. For non-identity permutations introduced by combined `intrinsics_m` and `intrinsics_n` unrolling on ACC, the rank grows because the permutation interleaves M and N dims and there's no rank-2 collapse that faithfully represents the memory layout — and that's the whole point: the tile type now matches what's actually in memory. `getTileMxNxK` in `CPUEncodingExternalModels.cpp` previously read M, N, K positionally from the tile vector shape, which is wrong once the permutation is honored (M can be spread across multiple dims and interleaved with N). It now goes through the LHS/RHS `TileSwizzle`s directly: M is the product of LHS `expandShape[0]`, K is the product of LHS `expandShape[1]`, N is the product of RHS `expandShape[0]` — the per-operand `[M, K]` / `[N, K]` group partition is what `getIntrinsicSwizzle` establishes by construction, regardless of how the permutation later orders dims in memory. Test fallout in this branch is limited to `invalid.mlir` (one expected error string updated to reflect the rank increase from honoring the permutation on a 16×1 LHS); other CPU lit tests on origin/main use trivial unrollings that keep the rank-2 shape. Signed-off-by: Benoit Jacob <[email protected]>
bjacob
force-pushed
the
users/bjacob/cpu-mma-align-permutation-with-gpu
branch
from
May 12, 2026 14:49
ff1f83a to
b52079d
Compare
bjacob
marked this pull request as ready for review
May 12, 2026 15:26
bjacob
requested review from
Groverkss,
MaheshRavishankar,
Max191,
hanhanW,
jtuyls,
krzysz00,
nirvedhmeshram and
qedawkins
as code owners
May 12, 2026 15:26
25 of 28 tasks
hanhanW
approved these changes
May 12, 2026
bjacob
added a commit
that referenced
this pull request
May 12, 2026
…sed enums. This is take two of #24404, which was reverted due to a RDNA4 regression (#24427); see the regression delta at the end. Each non-square hardware MMA now appears as two `MMAIntrinsic` enum values — one per orientation — named after their actual MxNxK shape (e.g. `MMA_X86_AVX512_1x16x1_F32_F32` and its M↔N-swapped sibling `MMA_X86_AVX512_16x1x1_F32_F32`). The swapped sibling of `X` is `X | 1` (bit 0 of D in the enum's encoding), so consecutive enum values form natural/swapped pairs. The `transposed_intrinsic` boolean on `DataTiledMMAAttr` is removed; both orientations show up as distinct candidates in `getMmaIntrinsicsForTargetConfig` and the existing `chooseIntrinsic` scoring picks between them. A new `assert(isMmaIntrinsicArrayValid(...))` at the bottom of `getMmaIntrinsicsForTargetConfig` enforces the convention: strictly increasing, every swapped entry preceded by its natural sibling, and square/type-symmetric singletons allowed (covers the generic-scalar 1×1×1 family). Motivation: the boolean was originally there to avoid 2× enum growth, but it leaked orientation-handling into every layer that touched MMA layouts — swizzles, ACC encoding-info, the cross-intrinsic ACC index, broadcast direction. It was also poised to get worse: asymmetric LLVM intrinsics (vpdpbusd) and non-x86 targets (no broadcast) would each need bespoke handling under the boolean. With separate enum values, each orientation lowers independently. Swapped enums are the first intrinsics to exercise a non-identity ACC swizzle permutation: `Codegen::expand` on intrinsics_n then intrinsics_m interleaves N and M dims in memory. Two prerequisite commits make that permutation observable consistently across the type and encoder sides: - #24437 makes `DataTiledMMAAttr::getUndistributedTileTypes` honor the swizzle's permutation (rank-N tile type that reflects the actual memory order). - The predecessor commit on this branch attaches the swizzle to the encoder's `MaterializeEncodingInfo` (`info.swizzle = ...`) so the packed inner tile is the swizzle's permuted-expanded layout — the encoder-side counterpart to #24437. With both in place, the `reshapeToSwizzleDistributed` bridge in `MMAUtils.cpp` collapses to a plain `vector.shape_cast` — same as it was before non-identity permutations existed. New CHECKs in `lower_inner_tiled.mlir`'s `lower_avx512_16x1x1_f32` pin the shape_cast pair on the first multi-non-unit-dim swapped-intrinsic test case in the file. RDNA4 regression delta from #24404: the reverted PR left `getUndistributedTileTypes` returning the wrong shape and introduced an explicit `vector.transpose` in `reshapeToSwizzleDistributed` to compensate. That transpose was correct for CPU but on GPU stacked on top of GPU's already-permuted distributed shape, scrambling per-lane data on RDNA4 (the only target whose swizzle had a non-trivial permutation at the time). Fixing the tile type at the source removes the transpose and keeps the shared lowering body uniform across targets. Progress towards #24323. Signed-off-by: Benoit Jacob <[email protected]>
This was referenced May 12, 2026
bjacob
added a commit
that referenced
this pull request
May 13, 2026
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
added a commit
that referenced
this pull request
May 13, 2026
…sed enums. This is take two of #24404, which was reverted due to a RDNA4 regression (#24427); see the regression delta at the end. Each non-square hardware MMA now appears as two `MMAIntrinsic` enum values — one per orientation — named after their actual MxNxK shape (e.g. `MMA_X86_AVX512_1x16x1_F32_F32` and its M↔N-swapped sibling `MMA_X86_AVX512_16x1x1_F32_F32`). The swapped sibling of `X` is `X | 1` (bit 0 of D in the enum's encoding), so consecutive enum values form natural/swapped pairs. The `transposed_intrinsic` boolean on `DataTiledMMAAttr` is removed; both orientations show up as distinct candidates in `getMmaIntrinsicsForTargetConfig` and the existing `chooseIntrinsic` scoring picks between them. A new `assert(isMmaIntrinsicArrayValid(...))` at the bottom of `getMmaIntrinsicsForTargetConfig` enforces the convention: strictly increasing, every swapped entry preceded by its natural sibling, and square/type-symmetric singletons allowed (covers the generic-scalar 1×1×1 family). Motivation: the boolean was originally there to avoid 2× enum growth, but it leaked orientation-handling into every layer that touched MMA layouts — swizzles, ACC encoding-info, the cross-intrinsic ACC index, broadcast direction. It was also poised to get worse: asymmetric LLVM intrinsics (vpdpbusd) and non-x86 targets (no broadcast) would each need bespoke handling under the boolean. With separate enum values, each orientation lowers independently. Swapped enums are the first intrinsics to exercise a non-identity ACC swizzle permutation: `Codegen::expand` on intrinsics_n then intrinsics_m interleaves N and M dims in memory. Two prerequisite commits make that permutation observable consistently across the type and encoder sides: - #24437 makes `DataTiledMMAAttr::getUndistributedTileTypes` honor the swizzle's permutation (rank-N tile type that reflects the actual memory order). - The predecessor commit on this branch attaches the swizzle to the encoder's `MaterializeEncodingInfo` (`info.swizzle = ...`) so the packed inner tile is the swizzle's permuted-expanded layout — the encoder-side counterpart to #24437. With both in place, the `reshapeToSwizzleDistributed` bridge in `MMAUtils.cpp` collapses to a plain `vector.shape_cast` — same as it was before non-identity permutations existed. New CHECKs in `lower_inner_tiled.mlir`'s `lower_avx512_16x1x1_f32` pin the shape_cast pair on the first multi-non-unit-dim swapped-intrinsic test case in the file. RDNA4 regression delta from #24404: the reverted PR left `getUndistributedTileTypes` returning the wrong shape and introduced an explicit `vector.transpose` in `reshapeToSwizzleDistributed` to compensate. That transpose was correct for CPU but on GPU stacked on top of GPU's already-permuted distributed shape, scrambling per-lane data on RDNA4 (the only target whose swizzle had a non-trivial permutation at the time). Fixing the tile type at the source removes the transpose and keeps the shared lowering body uniform across targets. Progress towards #24323. Signed-off-by: Benoit Jacob <[email protected]>
bjacob
added a commit
that referenced
this pull request
May 13, 2026
…sed enums. (#24456) This is take two of #24404, which was reverted due to a RDNA4 regression (#24427); see the regression delta at the end. Each non-square hardware MMA now appears as two `MMAIntrinsic` enum values — one per orientation — named after their actual MxNxK shape (e.g. `MMA_X86_AVX512_1x16x1_F32_F32` and its M↔N-swapped sibling `MMA_X86_AVX512_16x1x1_F32_F32`). The swapped sibling of `X` is `X | 1` (bit 0 of D in the enum's encoding), so consecutive enum values form natural/swapped pairs. The `transposed_intrinsic` boolean on `DataTiledMMAAttr` is removed; both orientations show up as distinct candidates in `getMmaIntrinsicsForTargetConfig` and the existing `chooseIntrinsic` scoring picks between them. A new `assert(isMmaIntrinsicArrayValid(...))` at the bottom of `getMmaIntrinsicsForTargetConfig` enforces the convention: strictly increasing, every swapped entry preceded by its natural sibling, and square/type-symmetric singletons allowed (covers the generic-scalar 1×1×1 family). Motivation: the boolean was originally there to avoid 2× enum growth, but it leaked orientation-handling into every layer that touched MMA layouts — swizzles, ACC encoding-info, the cross-intrinsic ACC index, broadcast direction. It was also poised to get worse: asymmetric LLVM intrinsics (vpdpbusd) and non-x86 targets (no broadcast) would each need bespoke handling under the boolean. With separate enum values, each orientation lowers independently. Swapped enums are the first intrinsics to exercise a non-identity ACC swizzle permutation: `Codegen::expand` on intrinsics_n then intrinsics_m interleaves N and M dims in memory. Two prerequisite commits make that permutation observable consistently across the type and encoder sides: - #24437 makes `DataTiledMMAAttr::getUndistributedTileTypes` honor the swizzle's permutation (rank-N tile type that reflects the actual memory order). - The predecessor commit on this branch attaches the swizzle to the encoder's `MaterializeEncodingInfo` (`info.swizzle = ...`) so the packed inner tile is the swizzle's permuted-expanded layout — the encoder-side counterpart to #24437. With both in place, the `reshapeToSwizzleDistributed` bridge in `MMAUtils.cpp` collapses to a plain `vector.shape_cast` — same as it was before non-identity permutations existed. New CHECKs in `lower_inner_tiled.mlir`'s `lower_avx512_16x1x1_f32` pin the shape_cast pair on the first multi-non-unit-dim swapped-intrinsic test case in the file. RDNA4 regression delta from #24404: the reverted PR left `getUndistributedTileTypes` returning the wrong shape and introduced an explicit `vector.transpose` in `reshapeToSwizzleDistributed` to compensate. That transpose was correct for CPU but on GPU stacked on top of GPU's already-permuted distributed shape, scrambling per-lane data on RDNA4 (the only target whose swizzle had a non-trivial permutation at the time). Fixing the tile type at the source removes the transpose and keeps the shared lowering body uniform across targets. Progress towards #24323. Signed-off-by: Benoit Jacob <[email protected]>
bjacob
added a commit
that referenced
this pull request
May 14, 2026
The comment claimed CPU's swizzle permutation is always identity, but that hasn't been true since #24456 introduced swapped MMA intrinsics: when both `intrinsics_n > 1` and `intrinsics_m > 1`, `Codegen::expand` on the ACC operand sets a non-identity permutation. The bridge still collapses to a plain `shape_cast` not because the permutation is identity, but because `getUndistributedTileTypes` (CPU, since #24437) and `getDistributedTileTypes` (GPU) both produce shapes that already reflect the swizzle's permutation — the reshape only adjusts rank. Signed-off-by: Benoit Jacob <[email protected]>
bjacob
added a commit
that referenced
this pull request
May 14, 2026
The comment claimed CPU's swizzle permutation is always identity, but that hasn't been true since #24456 introduced swapped MMA intrinsics: when both `intrinsics_n > 1` and `intrinsics_m > 1`, `Codegen::expand` on the ACC operand sets a non-identity permutation. The bridge still collapses to a plain `shape_cast` not because the permutation is identity, but because `getUndistributedTileTypes` (CPU, since #24437) and `getDistributedTileTypes` (GPU) both produce shapes that already reflect the swizzle's permutation — the reshape only adjusts rank. Signed-off-by: Benoit Jacob <[email protected]>
bjacob
added a commit
that referenced
this pull request
May 15, 2026
The comment claimed CPU's swizzle permutation is always identity, but that hasn't been true since #24456 introduced swapped MMA intrinsics: when both `intrinsics_n > 1` and `intrinsics_m > 1`, `Codegen::expand` on the ACC operand sets a non-identity permutation. The bridge still collapses to a plain `shape_cast` not because the permutation is identity, but because `getUndistributedTileTypes` (CPU, since #24437) and `getDistributedTileTypes` (GPU) both produce shapes that already reflect the swizzle's permutation — the reshape only adjusts rank. Signed-off-by: Benoit Jacob <[email protected]>
bjacob
added a commit
that referenced
this pull request
May 15, 2026
The comment claimed CPU's swizzle permutation is always identity, but that hasn't been true since #24456 introduced swapped MMA intrinsics: when both `intrinsics_n > 1` and `intrinsics_m > 1`, `Codegen::expand` on the ACC operand sets a non-identity permutation. The bridge still collapses to a plain `shape_cast` not because the permutation is identity, but because `getUndistributedTileTypes` (CPU, since #24437) and `getDistributedTileTypes` (GPU) both produce shapes that already reflect the swizzle's permutation — the reshape only adjusts rank. Signed-off-by: Benoit Jacob <[email protected]>
bjacob
added a commit
that referenced
this pull request
May 15, 2026
The comment claimed CPU's swizzle permutation is always identity, but that hasn't been true since #24456 introduced swapped MMA intrinsics: when both `intrinsics_n > 1` and `intrinsics_m > 1`, `Codegen::expand` on the ACC operand sets a non-identity permutation. The bridge still collapses to a plain `shape_cast` not because the permutation is identity, but because `getUndistributedTileTypes` (CPU, since #24437) and `getDistributedTileTypes` (GPU) both produce shapes that already reflect the swizzle's permutation — the reshape only adjusts rank. Signed-off-by: Benoit Jacob <[email protected]>
bjacob
added a commit
that referenced
this pull request
May 15, 2026
The comment claimed CPU's swizzle permutation is always identity, but that hasn't been true since #24456 introduced swapped MMA intrinsics: when both `intrinsics_n > 1` and `intrinsics_m > 1`, `Codegen::expand` on the ACC operand sets a non-identity permutation. The bridge still collapses to a plain `shape_cast` not because the permutation is identity, but because `getUndistributedTileTypes` (CPU, since #24437) and `getDistributedTileTypes` (GPU) both produce shapes that already reflect the swizzle's permutation — the reshape only adjusts rank. Signed-off-by: Benoit Jacob <[email protected]>
bjacob
added a commit
that referenced
this pull request
May 15, 2026
The comment claimed CPU's swizzle permutation is always identity, but that hasn't been true since #24456 introduced swapped MMA intrinsics: when both `intrinsics_n > 1` and `intrinsics_m > 1`, `Codegen::expand` on the ACC operand sets a non-identity permutation. The bridge still collapses to a plain `shape_cast` not because the permutation is identity, but because `getUndistributedTileTypes` (CPU, since #24437) and `getDistributedTileTypes` (GPU) both produce shapes that already reflect the swizzle's permutation — the reshape only adjusts rank. Signed-off-by: Benoit Jacob <[email protected]>
RattataKing
pushed a commit
to RattataKing/iree
that referenced
this pull request
May 27, 2026
…or swizzle permutation. (iree-org#24437) The swizzle's `permutation` is ground truth for memory layout — for pre-transposed intrinsics with both `intrinsics_m > 1` and `intrinsics_n > 1` on the ACC, the `Codegen::expand` insertion order produces a non-identity permutation that interleaves M and N dims, and that interleaved order is what the encoding materialization actually lays out in memory. `DataTiledMMAAttr::getUndistributedTileTypes` was silently ignoring that permutation: it returned `(prod(expandShape[0]), prod(expandShape[1]))` — operand-natural row-major — which contradicted the swizzle's stated memory order. The mismatch was dormant when the permutation happened to be identity (all pre-pretransposed intrinsics) but produces wrong tile types for the M↔N-swapped enum values that the next branch in this stack introduces, and is the root cause of the RDNA4 regression that took down iree-org#24404. Fix: lift the per-dim walk into a new shared utility `Codegen::getTileVectorType(swizzle, elemType[, keepSize])` in `IREECodegenTypes`. The shape is `sliceSwizzledShape(swizzle, keepSize)` — every dim of `expandShape` in `swizzle.permutation()` order, with optional per-dim masking to size 1. A dim with a non-`One` symbolic multiplier maps to a scalable axis. CPU's `DataTiledMMAAttr::getUndistributedTileTypes` and GPU's `DataTiledMMAInterfaceAttr::{getUndistributedTileTypes,getDistributedTileTypes}` now all go through it (the GPU distributed variant passes a `d.kind() != CrossThread` mask to fold thread-distribution factors to size-1 axes). For trivial CPU cases (every `expandShape` group is a single dim — the only configuration `fixupSwizzle` leaves after the base intrinsic build, where `intrinsics_{m,n,k}` haven't yet been expanded in) the result is the same rank-2 `(outer, inner)` shape CPU historically returned. For non-identity permutations introduced by combined `intrinsics_m` and `intrinsics_n` unrolling on ACC, the rank grows because the permutation interleaves M and N dims and there's no rank-2 collapse that faithfully represents the memory layout — and that's the whole point: the tile type now matches what's actually in memory. `getTileMxNxK` in `CPUEncodingExternalModels.cpp` previously read M, N, K positionally from the tile vector shape, which is wrong once the permutation is honored (M can be spread across multiple dims and interleaved with N). It now goes through the LHS/RHS `TileSwizzle`s directly: M is the product of LHS `expandShape[0]`, K is the product of LHS `expandShape[1]`, N is the product of RHS `expandShape[0]` — the per-operand `[M, K]` / `[N, K]` group partition is what `getIntrinsicSwizzle` establishes by construction, regardless of how the permutation later orders dims in memory. Test fallout in this branch is limited to `invalid.mlir` (one expected error string updated to reflect the rank increase from honoring the permutation on a 16×1 LHS); other CPU lit tests on origin/main use trivial unrollings that keep the rank-2 shape. 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
…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
…sed enums. (iree-org#24456) This is take two of iree-org#24404, which was reverted due to a RDNA4 regression (iree-org#24427); see the regression delta at the end. Each non-square hardware MMA now appears as two `MMAIntrinsic` enum values — one per orientation — named after their actual MxNxK shape (e.g. `MMA_X86_AVX512_1x16x1_F32_F32` and its M↔N-swapped sibling `MMA_X86_AVX512_16x1x1_F32_F32`). The swapped sibling of `X` is `X | 1` (bit 0 of D in the enum's encoding), so consecutive enum values form natural/swapped pairs. The `transposed_intrinsic` boolean on `DataTiledMMAAttr` is removed; both orientations show up as distinct candidates in `getMmaIntrinsicsForTargetConfig` and the existing `chooseIntrinsic` scoring picks between them. A new `assert(isMmaIntrinsicArrayValid(...))` at the bottom of `getMmaIntrinsicsForTargetConfig` enforces the convention: strictly increasing, every swapped entry preceded by its natural sibling, and square/type-symmetric singletons allowed (covers the generic-scalar 1×1×1 family). Motivation: the boolean was originally there to avoid 2× enum growth, but it leaked orientation-handling into every layer that touched MMA layouts — swizzles, ACC encoding-info, the cross-intrinsic ACC index, broadcast direction. It was also poised to get worse: asymmetric LLVM intrinsics (vpdpbusd) and non-x86 targets (no broadcast) would each need bespoke handling under the boolean. With separate enum values, each orientation lowers independently. Swapped enums are the first intrinsics to exercise a non-identity ACC swizzle permutation: `Codegen::expand` on intrinsics_n then intrinsics_m interleaves N and M dims in memory. Two prerequisite commits make that permutation observable consistently across the type and encoder sides: - iree-org#24437 makes `DataTiledMMAAttr::getUndistributedTileTypes` honor the swizzle's permutation (rank-N tile type that reflects the actual memory order). - The predecessor commit on this branch attaches the swizzle to the encoder's `MaterializeEncodingInfo` (`info.swizzle = ...`) so the packed inner tile is the swizzle's permuted-expanded layout — the encoder-side counterpart to iree-org#24437. With both in place, the `reshapeToSwizzleDistributed` bridge in `MMAUtils.cpp` collapses to a plain `vector.shape_cast` — same as it was before non-identity permutations existed. New CHECKs in `lower_inner_tiled.mlir`'s `lower_avx512_16x1x1_f32` pin the shape_cast pair on the first multi-non-unit-dim swapped-intrinsic test case in the file. RDNA4 regression delta from iree-org#24404: the reverted PR left `getUndistributedTileTypes` returning the wrong shape and introduced an explicit `vector.transpose` in `reshapeToSwizzleDistributed` to compensate. That transpose was correct for CPU but on GPU stacked on top of GPU's already-permuted distributed shape, scrambling per-lane data on RDNA4 (the only target whose swizzle had a non-trivial permutation at the time). Fixing the tile type at the source removes the transpose and keeps the shared lowering body uniform across targets. Progress towards iree-org#24323. Signed-off-by: Benoit Jacob <[email protected]>
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.
The swizzle's
permutationis ground truth for memory layout — for pre-transposed intrinsics with bothintrinsics_m > 1andintrinsics_n > 1on the ACC, theCodegen::expandinsertion order produces a non-identity permutation that interleaves M and N dims, and that interleaved order is what the encoding materialization actually lays out in memory.DataTiledMMAAttr::getUndistributedTileTypeswas silently ignoring that permutation: it returned(prod(expandShape[0]), prod(expandShape[1]))— operand-natural row-major — which contradicted the swizzle's stated memory order. The mismatch was dormant when the permutation happened to be identity (all pre-pretransposed intrinsics) but produces wrong tile types for the M↔N-swapped enum values that the next branch in this stack introduces, and is the root cause of the RDNA4 regression that took down #24404.Fix: lift the per-dim walk into a new shared utility
Codegen::getTileVectorType(swizzle, elemType[, keepSize])inIREECodegenTypes. The shape issliceSwizzledShape(swizzle, keepSize)— every dim ofexpandShapeinswizzle.permutation()order, with optional per-dim masking to size 1. A dim with a non-Onesymbolic multiplier maps to a scalable axis. CPU'sDataTiledMMAAttr::getUndistributedTileTypesand GPU'sDataTiledMMAInterfaceAttr::{getUndistributedTileTypes,getDistributedTileTypes}now all go through it (the GPU distributed variant passes ad.kind() != CrossThreadmask to fold thread-distribution factors to size-1 axes).For trivial CPU cases (every
expandShapegroup is a single dim — the only configurationfixupSwizzleleaves after the base intrinsic build, whereintrinsics_{m,n,k}haven't yet been expanded in) the result is the same rank-2(outer, inner)shape CPU historically returned. For non-identity permutations introduced by combinedintrinsics_mandintrinsics_nunrolling on ACC, the rank grows because the permutation interleaves M and N dims and there's no rank-2 collapse that faithfully represents the memory layout — and that's the whole point: the tile type now matches what's actually in memory.getTileMxNxKinCPUEncodingExternalModels.cpppreviously read M, N, K positionally from the tile vector shape, which is wrong once the permutation is honored (M can be spread across multiple dims and interleaved with N). It now goes through the LHS/RHSTileSwizzles directly: M is the product of LHSexpandShape[0], K is the product of LHSexpandShape[1], N is the product of RHSexpandShape[0]— the per-operand[M, K]/[N, K]group partition is whatgetIntrinsicSwizzleestablishes by construction, regardless of how the permutation later orders dims in memory.Test fallout in this branch is limited to
invalid.mlir(one expected error string updated to reflect the rank increase from honoring the permutation on a 16×1 LHS); other CPU lit tests on origin/main use trivial unrollings that keep the rank-2 shape.Progress towards #24323.