Repository navigation
Revert "[Codegen][CPU] Replace transposed_intrinsic with explicit pre-transposed enums." - #24427
Merged
kuhar merged 1 commit intoMay 9, 2026
Conversation
…-transpo…" This reverts commit a65bb23.
bjacob
approved these changes
May 9, 2026
kuhar
deleted the
revert-24404-users/bjacob/cpu-inner-tiled-pretransposed-intrinsics
branch
May 9, 2026 19:52
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, 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]>
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. 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]>
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. 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]>
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. 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]>
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. 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]>
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. 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]>
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. 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]>
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. 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]>
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. 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]>
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]>
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]>
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]>
RattataKing
pushed a commit
to RattataKing/iree
that referenced
this pull request
May 27, 2026
…-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) ```
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.
Revert #24404. This regressed matmul tests on rdna4: