Repository navigation
[Codegen][CPU] Lower inner_tiled to llvm.call_intrinsic. - #24345
Merged
Merged
Conversation
Implements CPU's `DataTiledMMAAttr::buildUnderlyingOperations` by reusing the shared `Codegen::buildDataTiledMMAUnderlyingOperations` from #24326. CPU passes a callback, `createCpuMmaIntrinsicCall`, that emits an `llvm.call_intrinsic` for each per-intrinsic invocation. The function dispatches on the `MMAIntrinsic` enum value through a switch. Before the switch, LHS (M=1, K elements) is replicated across RHS's N lanes so both operands share the intrinsic's flat lane width. Each `case` then emits the call via a small `call(name, resultType, args)` helper, with operands listed in the order the x86 intrinsic expects: * FMA-style intrinsics compute `a*b + c`, so the args are `{lhs, rhs, acc}`. Covers the 1xNx1 generic `llvm.fma.v*` cases: - MMA_X86_AVX2_FMA_1x8x1_F32_F32 -> llvm.fma.v8f32 - MMA_X86_AVX512_1x8x1_F64_F64 -> llvm.fma.v8f64 - MMA_X86_AVX512_1x16x1_F32_F32 -> llvm.fma.v16f32 - MMA_X86_AVX512_1x16x1_F32_F16_CASTF32 -> llvm.fma.v16f32 (after arith.extf) - MMA_X86_AVX512FP16_1x32x1_F16_F16 -> llvm.fma.v32f16 * Accumulating dot intrinsics compute `acc + a·b`, so the args are `{acc, lhs, rhs}`. Covers the x86 dots that fold the accumulation: - MMA_X86_AVX512BF16_1x16x2_F32_BF16 -> llvm.x86.avx512bf16.dpbf16ps.512 - MMA_X86_AVX512VNNI_1x16x2_I32_I16 -> llvm.x86.avx512.vpdpwssd.512 - MMA_X86_AVX512VNNI_1x16x2_I32_I8_CASTI16 -> llvm.x86.avx512.vpdpwssd.512 (after arith.extsi) * Non-accumulating dot intrinsics compute `a·b`, so the args are `{lhs, rhs}`. The accumulator is folded in afterwards via `arith.addi`. Covers the non-VNNI integer path: - MMA_X86_AVX512_1x16x2_I32_I16 -> llvm.x86.avx512.pmaddw.d.512 - MMA_X86_AVX512_1x16x2_I32_I8_CASTI16 -> llvm.x86.avx512.pmaddw.d.512 (after arith.extsi) The `*_CASTF32` and `*_CASTI16` variants share their target intrinsic with a wider element type; their switch cases inline a `widen` helper that emits the appropriate `arith.extf`/`arith.extsi` at the call site. New intrinsics that don't fit this structure are free to compose ops directly inside their `case`. The pre-switch broadcast assumes the natural operand orientation — LHS is the narrower (M=1, K elements), RHS is the wider (NxK) — and is *not* yet generalized for the `transposed_intrinsic` flag, which flips those roles in the narrow-N case. `buildUnderlyingOperations` explicitly returns failure when `transposed_intrinsic` is set so we fall back rather than silently produce wrong code; a follow-up commit makes the broadcast symmetric and lifts that restriction. The shared helper now also handles CPU's 2-D (outer x inner) collapsed operand form by reshaping inputs to the swizzle's distributed N-D form on the way in (and back to the original on the way out). This reshape is a no-op for GPU operands, which already arrive in distributed N-D form per `DataTiledMMAInterfaceAttr::getDistributedTileTypes`. Adds three FileCheck tests covering each call shape in test/lower_inner_tiled.mlir; the existing AVX-512 BF16 case in iree_cpu_inner_tiled_ops.mlir already covers the accumulating-dot shape without widening. Signed-off-by: Benoit Jacob <[email protected]> Progress towards #24323
25 of 28 tasks
bjacob
marked this pull request as ready for review
May 1, 2026 19:08
bjacob
requested review from
MaheshRavishankar,
Max191,
hanhanW and
qedawkins
as code owners
May 1, 2026 19:08
hanhanW
approved these changes
May 1, 2026
….cpp Co-authored-by: Han-Chung Wang <[email protected]>
….cpp Co-authored-by: Han-Chung Wang <[email protected]>
bjacob
enabled auto-merge (squash)
May 4, 2026 14:08
jerryyin
pushed a commit
that referenced
this pull request
May 7, 2026
Implements CPU's `DataTiledMMAAttr::buildUnderlyingOperations` by reusing the shared `Codegen::buildDataTiledMMAUnderlyingOperations` from #24326. CPU passes a callback, `createCpuMmaIntrinsicCall`, that emits an `llvm.call_intrinsic` for each per-intrinsic invocation. The function dispatches on the `MMAIntrinsic` enum value through a switch. Progress towards #24323 --------- Co-authored-by: Han-Chung Wang <[email protected]>
RattataKing
pushed a commit
to RattataKing/iree
that referenced
this pull request
May 27, 2026
) Implements CPU's `DataTiledMMAAttr::buildUnderlyingOperations` by reusing the shared `Codegen::buildDataTiledMMAUnderlyingOperations` from iree-org#24326. CPU passes a callback, `createCpuMmaIntrinsicCall`, that emits an `llvm.call_intrinsic` for each per-intrinsic invocation. The function dispatches on the `MMAIntrinsic` enum value through a switch. Progress towards iree-org#24323 --------- Co-authored-by: Han-Chung Wang <[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.
Implements CPU's
DataTiledMMAAttr::buildUnderlyingOperationsby reusing the sharedCodegen::buildDataTiledMMAUnderlyingOperationsfrom #24326. CPU passes a callback,createCpuMmaIntrinsicCall, that emits anllvm.call_intrinsicfor each per-intrinsic invocation. The function dispatches on theMMAIntrinsicenum value through a switch.Progress towards #24323