Skip to content

[Codegen][CPU] Lower inner_tiled to llvm.call_intrinsic. - #24345

Merged
bjacob merged 3 commits into
mainfrom
users/bjacob/mma-underlying-ops
May 4, 2026
Merged

bjacob merged 3 commits into
mainfrom
users/bjacob/mma-underlying-ops

Conversation

@bjacob

@bjacob bjacob commented May 1, 2026

Copy link
Copy Markdown
Collaborator

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

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
@bjacob bjacob mentioned this pull request May 1, 2026
25 of 28 tasks
@bjacob
bjacob marked this pull request as ready for review May 1, 2026 19:08
@bjacob bjacob changed the title [Codegen][CPU] Lower data-tiled inner_tiled to llvm.call_intrinsic. [Codegen][CPU] Lower inner_tiled to llvm.call_intrinsic. May 1, 2026

@hanhanW hanhanW left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some nits

@bjacob
bjacob enabled auto-merge (squash) May 4, 2026 14:08
@bjacob
bjacob merged commit d358e81 into main May 4, 2026
63 of 65 checks passed
@bjacob
bjacob deleted the users/bjacob/mma-underlying-ops branch May 4, 2026 14:35
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]>
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