Skip to content

[Codegen][CPU] Replace transposed_intrinsic with explicit pre-transposed enums. - #24456

Merged
bjacob merged 1 commit into
mainfrom
users/bjacob/cpu-inner-tiled-pretransposed-intrinsics-take-two
May 13, 2026
Merged

bjacob merged 1 commit into
mainfrom
users/bjacob/cpu-inner-tiled-pretransposed-intrinsics-take-two

Conversation

@bjacob

@bjacob bjacob commented May 12, 2026

Copy link
Copy Markdown
Collaborator

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:

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.

@bjacob bjacob mentioned this pull request May 12, 2026
25 of 28 tasks
An error occurred while trying to automatically change base from users/bjacob/cpu-encoder-info-swizzle to main May 13, 2026 16:16
…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
bjacob force-pushed the users/bjacob/cpu-inner-tiled-pretransposed-intrinsics-take-two branch from 4363123 to 0d209aa Compare May 13, 2026 16:55
@bjacob
bjacob marked this pull request as ready for review May 13, 2026 18:08
@bjacob
bjacob marked this pull request as draft May 13, 2026 18:17
@bjacob
bjacob changed the base branch from users/bjacob/cpu-encoder-info-swizzle to main May 13, 2026 18:20
@bjacob
bjacob marked this pull request as ready for review May 13, 2026 18:24
@bjacob
bjacob requested a review from hanhanW May 13, 2026 18:24
@bjacob
bjacob enabled auto-merge (squash) May 13, 2026 19:26
@bjacob
bjacob merged commit e6d5e70 into main May 13, 2026
150 of 153 checks passed
@bjacob
bjacob deleted the users/bjacob/cpu-inner-tiled-pretransposed-intrinsics-take-two branch May 13, 2026 20:12
bjacob added a commit that referenced this pull request May 14, 2026
The comment claimed CPU's swizzle permutation is always identity, but
that hasn't been true since #24456 introduced swapped MMA intrinsics:
when both `intrinsics_n > 1` and `intrinsics_m > 1`, `Codegen::expand`
on the ACC operand sets a non-identity permutation. The bridge still
collapses to a plain `shape_cast` not because the permutation is
identity, but because `getUndistributedTileTypes` (CPU, since #24437)
and `getDistributedTileTypes` (GPU) both produce shapes that already
reflect the swizzle's permutation — the reshape only adjusts rank.

Signed-off-by: Benoit Jacob <[email protected]>
bjacob added a commit that referenced this pull request May 14, 2026
The comment claimed CPU's swizzle permutation is always identity, but
that hasn't been true since #24456 introduced swapped MMA intrinsics:
when both `intrinsics_n > 1` and `intrinsics_m > 1`, `Codegen::expand`
on the ACC operand sets a non-identity permutation. The bridge still
collapses to a plain `shape_cast` not because the permutation is
identity, but because `getUndistributedTileTypes` (CPU, since #24437)
and `getDistributedTileTypes` (GPU) both produce shapes that already
reflect the swizzle's permutation — the reshape only adjusts rank.

Signed-off-by: Benoit Jacob <[email protected]>
bjacob added a commit that referenced this pull request May 15, 2026
The comment claimed CPU's swizzle permutation is always identity, but
that hasn't been true since #24456 introduced swapped MMA intrinsics:
when both `intrinsics_n > 1` and `intrinsics_m > 1`, `Codegen::expand`
on the ACC operand sets a non-identity permutation. The bridge still
collapses to a plain `shape_cast` not because the permutation is
identity, but because `getUndistributedTileTypes` (CPU, since #24437)
and `getDistributedTileTypes` (GPU) both produce shapes that already
reflect the swizzle's permutation — the reshape only adjusts rank.

Signed-off-by: Benoit Jacob <[email protected]>
bjacob added a commit that referenced this pull request May 15, 2026
The comment claimed CPU's swizzle permutation is always identity, but
that hasn't been true since #24456 introduced swapped MMA intrinsics:
when both `intrinsics_n > 1` and `intrinsics_m > 1`, `Codegen::expand`
on the ACC operand sets a non-identity permutation. The bridge still
collapses to a plain `shape_cast` not because the permutation is
identity, but because `getUndistributedTileTypes` (CPU, since #24437)
and `getDistributedTileTypes` (GPU) both produce shapes that already
reflect the swizzle's permutation — the reshape only adjusts rank.

Signed-off-by: Benoit Jacob <[email protected]>
bjacob added a commit that referenced this pull request May 15, 2026
The comment claimed CPU's swizzle permutation is always identity, but
that hasn't been true since #24456 introduced swapped MMA intrinsics:
when both `intrinsics_n > 1` and `intrinsics_m > 1`, `Codegen::expand`
on the ACC operand sets a non-identity permutation. The bridge still
collapses to a plain `shape_cast` not because the permutation is
identity, but because `getUndistributedTileTypes` (CPU, since #24437)
and `getDistributedTileTypes` (GPU) both produce shapes that already
reflect the swizzle's permutation — the reshape only adjusts rank.

Signed-off-by: Benoit Jacob <[email protected]>
bjacob added a commit that referenced this pull request May 15, 2026
The comment claimed CPU's swizzle permutation is always identity, but
that hasn't been true since #24456 introduced swapped MMA intrinsics:
when both `intrinsics_n > 1` and `intrinsics_m > 1`, `Codegen::expand`
on the ACC operand sets a non-identity permutation. The bridge still
collapses to a plain `shape_cast` not because the permutation is
identity, but because `getUndistributedTileTypes` (CPU, since #24437)
and `getDistributedTileTypes` (GPU) both produce shapes that already
reflect the swizzle's permutation — the reshape only adjusts rank.

Signed-off-by: Benoit Jacob <[email protected]>
bjacob added a commit that referenced this pull request May 15, 2026
The comment claimed CPU's swizzle permutation is always identity, but
that hasn't been true since #24456 introduced swapped MMA intrinsics:
when both `intrinsics_n > 1` and `intrinsics_m > 1`, `Codegen::expand`
on the ACC operand sets a non-identity permutation. The bridge still
collapses to a plain `shape_cast` not because the permutation is
identity, but because `getUndistributedTileTypes` (CPU, since #24437)
and `getDistributedTileTypes` (GPU) both produce shapes that already
reflect the swizzle's permutation — the reshape only adjusts rank.

Signed-off-by: Benoit Jacob <[email protected]>
RattataKing pushed a commit to RattataKing/iree that referenced this pull request May 27, 2026
…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