Repository navigation
[Codegen][CPU] Replace transposed_intrinsic with explicit pre-transposed enums. - #24404
Conversation
f7573b5 to
5af6e0f
Compare
| MMAIntrinsic::MMA_X86_AVX512_16x1x2_I32_I8_CASTI16, | ||
| MMAIntrinsic::MMA_X86_AVX512VNNI_1x16x2_I32_I8_CASTI16, | ||
| MMAIntrinsic::MMA_X86_AVX512VNNI_16x1x2_I32_I8_CASTI16, | ||
| }; |
There was a problem hiding this comment.
We can make it more robust. I think we can use getMaxEnumValForXXX and symbolize method to construct the array/vector. Here is an example:
iree/compiler/src/iree/compiler/Codegen/Dialect/GPU/IR/IREEGPUAttrs.cpp
Lines 3232 to 3238 in 1d87665
iree/compiler/src/iree/compiler/Codegen/Dialect/GPU/IR/IREEGPUEnums.td
Lines 545 to 566 in 1d87665
There are two options:
- Group MMA intrinsics based on arch. E.g., we can group
MMA_X86_*into aIREECPU_I32EnumAttr, then you can do the trick here. - We still use the single big group, and we can filter it from the string view, like:
for (uint32_t i = 0; i <= getMaxEnumValForMyEnum(); ++i) {
if (std::optional<MyEnum> val = symbolizeMyEnum(i)) {
// Convert the enum value back to its string name
llvm::StringRef name = stringifyMyEnum(*val);
// Check if it starts with "foo_"
if (name.starts_with("foo_")) {
fooCases.push_back(*val);
}
}
}
(2) has a hidden assumption that all the enums' name start with MMA_X86 but I think it is fine.
There was a problem hiding this comment.
I thought about that, but the enum values here are very sparse (even within one arch), and could get even sparser in the future, so this isn't practical.
This also violates a principle from the Google c++ guide: "don't parse". Relying in parsing string can come back to haunt us in the future. It also makes it harder to navigate the code, as one can't simply grep or clangd-reference-jump to specific enum values anymore.
Finally, the current solution is fairly "solid" thanks to the assert(isMmaIntrinsicArrayValid(...)). If one makes a mistake updating this array, this will be caught in assert-enabled builds.
| static bool isMmaIntrinsicArrayValid(MLIRContext *ctx, | ||
| ArrayRef<IREE::CPU::MMAIntrinsic> arr) { | ||
| using IREE::CPU::DataTiledMMAAttr; | ||
| using IREE::CPU::MMAIntrinsic; | ||
|
|
||
| // Conventions (1) and (2): order, strict increase, swap-pair structure. | ||
| if (!arr.empty() && (static_cast<uint32_t>(arr[0]) & 1) != 0) { | ||
| return false; | ||
| } | ||
| for (size_t i = 1; i < arr.size(); ++i) { | ||
| uint32_t v = static_cast<uint32_t>(arr[i]); | ||
| uint32_t prev = static_cast<uint32_t>(arr[i - 1]); | ||
| if (prev >= v) { | ||
| return false; | ||
| } | ||
| if ((v & 1) != 0 && prev != (v ^ 1)) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| // For (3) and (4) we need shape + element types from `DataTiledMMAAttr`. | ||
| auto getShapeAndTypes = [&](MMAIntrinsic intr) { | ||
| auto attr = DataTiledMMAAttr::get(ctx, intr, /*intrinsics_m=*/1, | ||
| /*intrinsics_n=*/1, /*intrinsics_k=*/1, | ||
| /*lhs_type=*/Type(), | ||
| /*rhs_type=*/Type(), | ||
| /*acc_type=*/Type()); | ||
| SmallVector<VectorType> tiles; | ||
| attr.getUndistributedTileTypes(tiles); | ||
| assert(tiles.size() == 3); | ||
| return std::make_tuple(tiles[0].getShape()[0], // M (LHS dim 0) | ||
| tiles[1].getShape()[0], // N (RHS dim 0) | ||
| tiles[0].getShape()[1], // K (LHS dim 1) | ||
| tiles[0].getElementType(), // LHS elem | ||
| tiles[1].getElementType(), // RHS elem | ||
| tiles[2].getElementType()); // ACC elem | ||
| }; | ||
|
|
||
| for (size_t i = 0; i < arr.size(); ++i) { | ||
| if ((static_cast<uint32_t>(arr[i]) & 1) != 0) { | ||
| continue; // swapped entry — checked when we hit its natural sibling. | ||
| } | ||
| if (IREE::CPU::isGenericScalar(arr[i])) { | ||
| continue; // type-polymorphic 1×1×1: vacuously valid. | ||
| } | ||
| auto [mn, nn, kn, lhsn, rhsn, accn] = getShapeAndTypes(arr[i]); | ||
| bool hasSibling = | ||
| (i + 1 < arr.size()) && (static_cast<uint32_t>(arr[i + 1]) == | ||
| (static_cast<uint32_t>(arr[i]) | 1)); | ||
| if (hasSibling) { | ||
| auto [ms, ns, ks, lhss, rhss, accs] = getShapeAndTypes(arr[i + 1]); | ||
| // Condition (3): siblings have M↔N and LHS↔RHS exchanged; K and ACC | ||
| // element type are unchanged. | ||
| if (ms != nn || ns != mn || ks != kn) { | ||
| return false; | ||
| } | ||
| if (lhss != rhsn || rhss != lhsn || accs != accn) { | ||
| return false; | ||
| } | ||
| } else { | ||
| // Condition (4): singleton — must be self-symmetric. | ||
| if (mn != nn || lhsn != rhsn) { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
| return true; | ||
| } |
There was a problem hiding this comment.
I'm thinking if we should add a few methods for those - 1, | 1, ^ 1 methods for readability. E.g., we can have getSiblingInst, isNativeInst, etc. What do you think?
There was a problem hiding this comment.
I would like to keep the explicit bit ops here because it's more transparent how they interact with one another. Example at line 411:
if ((v & 1) != 0 && prev != (v ^ 1)) {If thanks to helpers I rewrite that into
if (isTransposed(v) != 0 && prev != sibling(v)) {then one has to mentally expand the definitions of isTransposed and sibling to understand how this fits together.
hanhanW
left a comment
There was a problem hiding this comment.
The PR description is still using | 1, not ^ 1.
e211a28 to
52f0ad0
Compare
…sed enums. 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. MMAUtils permutation fix: `buildDataTiledMMAUnderlyingOperations` previously moved between the caller's logical (M, N)-ordered tile type and the swizzle's distributed N-D form via a linear-preserving `vector.shape_cast` — sound only for identity permutations. Pre-existing intrinsics all happened to be identity, so the bug was dormant. Every swapped enum added here produces a non-identity permutation (cross-intrinsic-N injected before cross-intrinsic-M, putting N first in storage), and the shape_cast scrambles (m, n) coordinates so result values land in the wrong cells. Fix: split the reshape into a logical-shape `shape_cast` plus a `vector.transpose` by the swizzle's permutation (input side) / its inverse (output side). Folds to a no-op for identity permutations, so existing natural-orientation intrinsics produce the same IR as before. Verified by extending the existing `lower_avx512_16x1x1_f32` test in `lower_inner_tiled.mlir` (the first to exercise a non-identity permutation) with `CHECK` lines pinning the shape_cast/transpose pairs around the FMA call. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> Progress towards #24323 Signed-off-by: Benoit Jacob <[email protected]>
52f0ad0 to
7cffbfe
Compare
…-transposed enums." (#24427) Revert #24404. This regressed matmul tests on rdna4: ``` The following tests FAILED: 1695 - iree/tests/e2e/matmul/e2e_matmul_rdna4_dt_f16_rocm_hip (Failed) 1696 - iree/tests/e2e/matmul/e2e_matmul_rdna4_dt_f8E4M3FN_rocm_hip (Failed) 1697 - iree/tests/e2e/matmul/e2e_matmul_rdna4_dt_i8_rocm_hip (Failed) ```
…sed enums. This is take two of #24404 which was reverted due to a RDNA4 regression, see below. 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. MMAUtils permutation fix: `buildDataTiledMMAUnderlyingOperations` previously moved between the caller's logical (M, N)-ordered tile type and the swizzle's distributed N-D form via a linear-preserving `vector.shape_cast` — sound only for identity permutations. Pre-existing intrinsics all happened to be identity, so the bug was dormant. Every swapped enum added here produces a non-identity permutation (cross-intrinsic-N injected before cross-intrinsic-M, putting N first in storage), and the shape_cast scrambles (m, n) coordinates so result values land in the wrong cells. Fix: split the reshape into a logical-shape `shape_cast` plus a `vector.transpose` by the swizzle's permutation (input side) / its inverse (output side). Folds to a no-op for identity permutations, so existing natural-orientation intrinsics produce the same IR as before. Verified by extending the existing `lower_avx512_16x1x1_f32` test in `lower_inner_tiled.mlir` (the first to exercise a non-identity permutation) with `CHECK` lines pinning the shape_cast/transpose pairs around the FMA call. RDNA4 regression fix (delta from #24404): The original PR was reverted (#24427) due to numerical mismatches in `e2e_matmul_rdna4_dt_{f16, f8E4M3FN, i8}`. The MMAUtils fix above unconditionally applied `vector.transpose` by `swizzle.permutation()` on the way into `distributeMmaFragmentToIntrinsics`. That's correct for the CPU caller (whose `getUndistributedTileTypes` returns 2-D operand-natural tiles with the permutation *un*-applied), but wrong for the GPU caller — `DataTiledMMAInterfaceAttr::getDistributedTileTypes` already applies the permutation via `sliceSwizzledShape`, so the second transpose scrambled per-lane data. The bug was latent on GPU swizzles with identity permutation and only surfaced on RDNA4, where the permutation is non-trivial. Take-two discriminates by incoming `VectorType::getShape()`: if it already equals `fullDistributedShape(swizzle)`, the value passes through untouched (GPU); otherwise it's shape-cast to logical N-D and transposed by `swizzle.permutation()` to reach distributed form (CPU). The reassemble path is symmetric: emit the inverse transpose + shape_cast only when the caller's `origAccType` doesn't already match the distributed shape. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> Progress towards #24323 Signed-off-by: Benoit Jacob <[email protected]>
…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. MMAUtils permutation context: `buildDataTiledMMAUnderlyingOperations` moves between the caller's logical (M, N)-ordered tile type and the swizzle's distributed N-D form via `reshapeToSwizzleDistributed`. Pre-existing intrinsics all produce identity-permutation swizzles, so a plain `vector.shape_cast` is correct. New swapped enums in this commit add intrinsics where the expand-insertion order for cross-intrinsic-N (before M) used to leave a non-identity permutation on the CPU swizzle — which broke the shape_cast assumption. Resolved by the first branch in the stack ("Force CPU swizzle permutation to identity to align with GPU"): CPU's row-major-by-group storage is now what the swizzle's permutation actually says, so the shape_cast is correct uniformly without a CPU/GPU branch. 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 kept the bogus non-identity permutation on the CPU swizzle 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 it at the CPU swizzle source removes the asymmetry 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: mirror GPU's `DataTiledMMAInterfaceAttr::getUndistributedTileTypes` algorithm — walk every dim of `expandShape`, then `applyPermutationToVector` with `swizzle.permutation()`. For trivial 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. CPU still diverges from GPU on unit dims that come from thread distribution (CPU has no `CrossThread` dims and so naturally lacks the corresponding unit axes that GPU keeps as separate dims). That's orthogonal to honoring the permutation. `getTileMxNxK` in `CPUEncodingExternalModels.cpp` previously read M, N, K positionally from the post-permutation tile shape, which is wrong once the permutation is honored. It now derives M, N, K from a 1×1×1- unrolled sibling `DataTiledMMAAttr` (whose swizzle always has an identity permutation) and multiplies by this attr's `intrinsics_{m,n,k}`. 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]>
…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. MMAUtils permutation context: `buildDataTiledMMAUnderlyingOperations` moves between the caller's logical (M, N)-ordered tile type and the swizzle's distributed N-D form via `reshapeToSwizzleDistributed`. Pre-existing intrinsics all produce identity-permutation swizzles, so a plain `vector.shape_cast` is correct. New swapped enums in this commit add intrinsics where the expand-insertion order for cross-intrinsic-N (before M) used to leave a non-identity permutation on the CPU swizzle — which broke the shape_cast assumption. Resolved by the first branch in the stack ("Force CPU swizzle permutation to identity to align with GPU"): CPU's row-major-by-group storage is now what the swizzle's permutation actually says, so the shape_cast is correct uniformly without a CPU/GPU branch. 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 kept the bogus non-identity permutation on the CPU swizzle 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 it at the CPU swizzle source removes the asymmetry 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: mirror GPU's `DataTiledMMAInterfaceAttr::getUndistributedTileTypes` algorithm — walk every dim of `expandShape`, then `applyPermutationToVector` with `swizzle.permutation()`. For trivial 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. CPU still diverges from GPU on unit dims that come from thread distribution (CPU has no `CrossThread` dims and so naturally lacks the corresponding unit axes that GPU keeps as separate dims). That's orthogonal to honoring the permutation. `getTileMxNxK` in `CPUEncodingExternalModels.cpp` previously read M, N, K positionally from the post-permutation tile shape, which is wrong once the permutation is honored. It now derives M, N, K from a 1×1×1- unrolled sibling `DataTiledMMAAttr` (whose swizzle always has an identity permutation) and multiplies by this attr's `intrinsics_{m,n,k}`. 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]>
…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. MMAUtils permutation context: `buildDataTiledMMAUnderlyingOperations` moves between the caller's logical (M, N)-ordered tile type and the swizzle's distributed N-D form via `reshapeToSwizzleDistributed`. Pre-existing intrinsics all produce identity-permutation swizzles, so a plain `vector.shape_cast` is correct. New swapped enums in this commit add intrinsics where the expand-insertion order for cross-intrinsic-N (before M) used to leave a non-identity permutation on the CPU swizzle — which broke the shape_cast assumption. Resolved by the first branch in the stack ("Force CPU swizzle permutation to identity to align with GPU"): CPU's row-major-by-group storage is now what the swizzle's permutation actually says, so the shape_cast is correct uniformly without a CPU/GPU branch. 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 kept the bogus non-identity permutation on the CPU swizzle 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 it at the CPU swizzle source removes the asymmetry 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: mirror GPU's `DataTiledMMAInterfaceAttr::getUndistributedTileTypes` algorithm — walk every dim of `expandShape`, then `applyPermutationToVector` with `swizzle.permutation()`. For trivial 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. CPU still diverges from GPU on unit dims that come from thread distribution (CPU has no `CrossThread` dims and so naturally lacks the corresponding unit axes that GPU keeps as separate dims). That's orthogonal to honoring the permutation. `getTileMxNxK` in `CPUEncodingExternalModels.cpp` previously read M, N, K positionally from the post-permutation tile shape, which is wrong once the permutation is honored. It now derives M, N, K from a 1×1×1- unrolled sibling `DataTiledMMAAttr` (whose swizzle always has an identity permutation) and multiplies by this attr's `intrinsics_{m,n,k}`. 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]>
…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. MMAUtils permutation context: `buildDataTiledMMAUnderlyingOperations` moves between the caller's logical (M, N)-ordered tile type and the swizzle's distributed N-D form via `reshapeToSwizzleDistributed`. Pre-existing intrinsics all produce identity-permutation swizzles, so a plain `vector.shape_cast` is correct. New swapped enums in this commit add intrinsics where the expand-insertion order for cross-intrinsic-N (before M) used to leave a non-identity permutation on the CPU swizzle — which broke the shape_cast assumption. Resolved by the first branch in the stack ("Force CPU swizzle permutation to identity to align with GPU"): CPU's row-major-by-group storage is now what the swizzle's permutation actually says, so the shape_cast is correct uniformly without a CPU/GPU branch. 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 kept the bogus non-identity permutation on the CPU swizzle 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 it at the CPU swizzle source removes the asymmetry 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 post-permutation tile shape, which is wrong once the permutation is honored. It now derives M, N, K from a 1×1×1- unrolled sibling `DataTiledMMAAttr` (whose swizzle always has an identity permutation) and multiplies by this attr's `intrinsics_{m,n,k}`. 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]>
…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. MMAUtils permutation context: `buildDataTiledMMAUnderlyingOperations` moves between the caller's logical (M, N)-ordered tile type and the swizzle's distributed N-D form via `reshapeToSwizzleDistributed`. Pre-existing intrinsics all produce identity-permutation swizzles, so a plain `vector.shape_cast` is correct. New swapped enums in this commit add intrinsics where the expand-insertion order for cross-intrinsic-N (before M) used to leave a non-identity permutation on the CPU swizzle — which broke the shape_cast assumption. Resolved by the first branch in the stack ("Force CPU swizzle permutation to identity to align with GPU"): CPU's row-major-by-group storage is now what the swizzle's permutation actually says, so the shape_cast is correct uniformly without a CPU/GPU branch. 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 kept the bogus non-identity permutation on the CPU swizzle 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 it at the CPU swizzle source removes the asymmetry 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]>
…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. MMAUtils permutation context: `buildDataTiledMMAUnderlyingOperations` moves between the caller's logical (M, N)-ordered tile type and the swizzle's distributed N-D form via `reshapeToSwizzleDistributed`. Pre-existing intrinsics all produce identity-permutation swizzles, so a plain `vector.shape_cast` is correct. New swapped enums in this commit add intrinsics where the expand-insertion order for cross-intrinsic-N (before M) used to leave a non-identity permutation on the CPU swizzle — which broke the shape_cast assumption. Resolved by the first branch in the stack ("Force CPU swizzle permutation to identity to align with GPU"): CPU's row-major-by-group storage is now what the swizzle's permutation actually says, so the shape_cast is correct uniformly without a CPU/GPU branch. 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 kept the bogus non-identity permutation on the CPU swizzle 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 it at the CPU swizzle source removes the asymmetry and keeps the shared lowering body uniform across targets. Progress towards #24323 Signed-off-by: Benoit Jacob <[email protected]>
…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. The first branch in this stack ("Fix DataTiledMMAAttr::getUndistributedTileTypes to honor swizzle permutation") 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 the first branch of this stack 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]>
…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. The first branch in this stack ("Fix DataTiledMMAAttr::getUndistributedTileTypes to honor swizzle permutation") 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 the first branch of this stack removes the transpose entirely and keeps the shared lowering body uniform across targets. Progress towards #24323 Signed-off-by: Benoit Jacob <[email protected]>
…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]>
…or swizzle permutation. (#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 #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 #24323. Signed-off-by: Benoit Jacob <[email protected]>
…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]>
…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]>
…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]>
…sed enums. (iree-org#24404) 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. MMAUtils permutation fix: `buildDataTiledMMAUnderlyingOperations` previously moved between the caller's logical (M, N)-ordered tile type and the swizzle's distributed N-D form via a linear-preserving `vector.shape_cast` — sound only for identity permutations. Pre-existing intrinsics all happened to be identity, so the bug was dormant. Every swapped enum added here produces a non-identity permutation (cross-intrinsic-N injected before cross-intrinsic-M, putting N first in storage), and the shape_cast scrambles (m, n) coordinates so result values land in the wrong cells. Fix: split the reshape into a logical-shape `shape_cast` plus a `vector.transpose` by the swizzle's permutation (input side) / its inverse (output side). Folds to a no-op for identity permutations, so existing natural-orientation intrinsics produce the same IR as before. Verified by extending the existing `lower_avx512_16x1x1_f32` test in `lower_inner_tiled.mlir` (the first to exercise a non-identity permutation) with `CHECK` lines pinning the shape_cast/transpose pairs around the FMA call. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> Progress towards iree-org#24323 Signed-off-by: Benoit Jacob <[email protected]>
…-transposed enums." (iree-org#24427) Revert iree-org#24404. This regressed matmul tests on rdna4: ``` The following tests FAILED: 1695 - iree/tests/e2e/matmul/e2e_matmul_rdna4_dt_f16_rocm_hip (Failed) 1696 - iree/tests/e2e/matmul/e2e_matmul_rdna4_dt_f8E4M3FN_rocm_hip (Failed) 1697 - iree/tests/e2e/matmul/e2e_matmul_rdna4_dt_i8_rocm_hip (Failed) ```
…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]>
…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]>
Each non-square hardware MMA now appears as two
MMAIntrinsicenum values — one per orientation — named after their actual MxNxK shape (e.g.MMA_X86_AVX512_1x16x1_F32_F32and its M↔N-swapped siblingMMA_X86_AVX512_16x1x1_F32_F32). The swapped sibling ofXisX ^ 1(bit 0 of D in the enum's encoding), so consecutive enum values form natural/swapped pairs. Thetransposed_intrinsicboolean onDataTiledMMAAttris removed; both orientations show up as distinct candidates ingetMmaIntrinsicsForTargetConfigand the existingchooseIntrinsicscoring picks between them.A new
assert(isMmaIntrinsicArrayValid(...))at the bottom ofgetMmaIntrinsicsForTargetConfigenforces 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.
MMAUtils permutation fix:
buildDataTiledMMAUnderlyingOperationspreviously moved between thecaller's logical (M, N)-ordered tile type and the swizzle's
distributed N-D form via a linear-preserving
vector.shape_cast—sound only for identity permutations. Pre-existing intrinsics all
happened to be identity, so the bug was dormant. Every swapped enum
added here produces a non-identity permutation (cross-intrinsic-N
injected before cross-intrinsic-M, putting N first in storage), and
the shape_cast scrambles (m, n) coordinates so result values land in
the wrong cells.
Fix: split the reshape into a logical-shape
shape_castplus avector.transposeby the swizzle's permutation (input side) / itsinverse (output side). Folds to a no-op for identity permutations,
so existing natural-orientation intrinsics produce the same IR as
before. Verified by extending the existing
lower_avx512_16x1x1_f32test in
lower_inner_tiled.mlir(the first to exercise anon-identity permutation) with
CHECKlines pinning theshape_cast/transpose pairs around the FMA call.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Progress towards #24323