Repository navigation
[Codegen][CPU] Replace transposed_intrinsic with explicit pre-transposed enums. - #24456
Merged
bjacob merged 1 commit intoMay 13, 2026
Merged
Conversation
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
force-pushed
the
users/bjacob/cpu-inner-tiled-pretransposed-intrinsics-take-two
branch
from
May 13, 2026 16:55
4363123 to
0d209aa
Compare
bjacob
marked this pull request as ready for review
May 13, 2026 18:08
bjacob
requested review from
Groverkss,
MaheshRavishankar,
Max191,
amd-eochoalo,
benvanik,
hanhanW,
jtuyls,
krzysz00,
kuhar,
nirvedhmeshram,
qedawkins and
sommerlukas
as code owners
May 13, 2026 18:08
bjacob
marked this pull request as draft
May 13, 2026 18:17
bjacob
removed request for
Groverkss,
MaheshRavishankar,
Max191,
amd-eochoalo,
benvanik,
hanhanW,
jtuyls,
krzysz00,
kuhar,
nirvedhmeshram,
qedawkins and
sommerlukas
May 13, 2026 18:18
bjacob
changed the base branch from
users/bjacob/cpu-encoder-info-swizzle
to
main
May 13, 2026 18:20
bjacob
marked this pull request as ready for review
May 13, 2026 18:24
hanhanW
approved these changes
May 13, 2026
bjacob
enabled auto-merge (squash)
May 13, 2026 19:26
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]>
2 tasks
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.
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
MMAIntrinsicenum values — one per orientation — named after their actual MxNxK shape (e.g.MMA_X86_AVX512_1x16x1_F32_F32and its M↔N-swapped siblingMMA_X86_AVX512_16x1x1_F32_F32). The swapped sibling ofXisX | 1(bit 0 of D in the enum's encoding), so consecutive enum values form natural/swapped pairs. Thetransposed_intrinsicboolean onDataTiledMMAAttris removed; both orientations show up as distinct candidates ingetMmaIntrinsicsForTargetConfigand the existingchooseIntrinsicscoring picks between them.A new
assert(isMmaIntrinsicArrayValid(...))at the bottom ofgetMmaIntrinsicsForTargetConfigenforces the convention: strictly increasing, every swapped entry preceded by its natural sibling, and square/type-symmetric singletons allowed (covers the generic-scalar 1×1×1 family).Motivation: the boolean was originally there to avoid 2× enum growth, but it leaked orientation-handling into every layer that touched MMA layouts — swizzles, ACC encoding-info, the cross-intrinsic ACC index, broadcast direction. It was also poised to get worse: asymmetric LLVM intrinsics (vpdpbusd) and non-x86 targets (no broadcast) would each need bespoke handling under the boolean. With separate enum values, each orientation lowers independently.
Swapped enums are the first intrinsics to exercise a non-identity ACC swizzle permutation:
Codegen::expandon 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:DataTiledMMAAttr::getUndistributedTileTypeshonor the swizzle's permutation (rank-N tile type that reflects the actual memory order).MaterializeEncodingInfo(info.swizzle = ...) so the packed inner tile is the swizzle's permuted-expanded layout — the encoder-side counterpart to [Codegen][CPU] Fix DataTiledMMAAttr::getUndistributedTileTypes to honor swizzle permutation. #24437.With both in place, the
reshapeToSwizzleDistributedbridge inMMAUtils.cppcollapses to a plainvector.shape_cast— same as it was before non-identity permutations existed. New CHECKs inlower_inner_tiled.mlir'slower_avx512_16x1x1_f32pin 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
getUndistributedTileTypesreturning the wrong shape and introduced an explicitvector.transposeinreshapeToSwizzleDistributedto 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.