Skip to content

Revert "[Codegen][CPU] Replace transposed_intrinsic with explicit pre-transposed enums." - #24427

Merged
kuhar merged 1 commit into
mainfrom
revert-24404-users/bjacob/cpu-inner-tiled-pretransposed-intrinsics
May 9, 2026
Merged

kuhar merged 1 commit into
mainfrom
revert-24404-users/bjacob/cpu-inner-tiled-pretransposed-intrinsics

Conversation

@kuhar

@kuhar kuhar commented May 9, 2026 •

Copy link
Copy Markdown
Member

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)

@kuhar
kuhar requested review from Max191, jtuyls and qedawkins as code owners May 9, 2026 19:25
@kuhar
kuhar enabled auto-merge (squash) May 9, 2026 19:31
@kuhar
kuhar merged commit 0629d80 into main May 9, 2026
64 of 65 checks passed
@kuhar
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants