Skip to content

[Codegen][CPU] Add a type-polymorphic generic-scalar MMA fallback. - #24389

Merged
bjacob merged 1 commit into
iree-org:mainfrom
bjacob:users/bjacob/cpu-skip-data-tiling-generic-mma-single
May 7, 2026
Merged

bjacob merged 1 commit into
iree-org:mainfrom
bjacob:users/bjacob/cpu-skip-data-tiling-generic-mma-single

Conversation

@bjacob

@bjacob bjacob commented May 7, 2026

Copy link
Copy Markdown
Collaborator

Adds two new MMAIntrinsic values, MMA_GENERIC_SCALAR_1x1x1_REG8 and _REG16, that the data-tiling cost model picks when no element-type- specific intrinsic on the target supports the matmul's (LHS, RHS, ACC) types. This intentionally breaks the "an MMAIntrinsic enum value pins down a specific element-type triple" invariant in exchange for not having to add one enum value per supported triple. Element types live on new DataTiledMMAAttr.{lhs,rhs,acc}_type parameters, populated by the cost model only when the chosen intrinsic is one of the polymorphic variants.

The cost model picks _REG16 on 64-bit ISAs (x86_64, AArch64, RISC-V) and _REG8 on 32-bit ISAs. The number is a register-budget for the unroll heuristic — one element of any width occupies one register, but the architectural register file the lowering ends up in (GPR or SIMD- scalar lane) is up to LLVM. The budget is encoded in the low byte of the enum value, so chooseUnrolling can read it back.

Since the intrinsic is 1×1×1, the operand tiles after intrinsics_m / intrinsics_n / intrinsics_k are simple row-major (M, K) / (N, K) / (M, N) — linalg.mmt4d-shaped. DataTiledMMAAttr::buildUnderlyingOperations therefore short-circuits the swizzle/distribute pipeline for these intrinsics and emits a single vector.contract directly, with arith.extf / arith.extsi widening narrow LHS/RHS to ACC's element type. For sub-byte LHS/RHS types chooseUnrolling also picks the smallest power-of-two intrinsics_k such that KlhsBits and KrhsBits are byte-aligned (e.g. K=2 for i4/f4, K=4 for f6, K=8 for i1).

Progress towards #24323

@bjacob
bjacob force-pushed the users/bjacob/cpu-skip-data-tiling-generic-mma-single branch from 24f612b to 1c13744 Compare May 7, 2026 14:41
@bjacob
bjacob marked this pull request as ready for review May 7, 2026 15:09
@bjacob bjacob mentioned this pull request May 7, 2026
25 of 28 tasks

@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, overall looks good to me.

@bjacob
bjacob force-pushed the users/bjacob/cpu-skip-data-tiling-generic-mma-single branch 2 times, most recently from a778777 to 6a264ca Compare May 7, 2026 19:43
Adds two new `MMAIntrinsic` values, `MMA_GENERIC_SCALAR_1x1x1_REG8` and
`_REG16`, that the data-tiling cost model picks when no element-type-
specific intrinsic on the target supports the matmul's (LHS, RHS, ACC)
types. This intentionally breaks the "an MMAIntrinsic enum value pins
down a specific element-type triple" invariant in exchange for not
having to add one enum value per supported triple. Element types live
on new `DataTiledMMAAttr.{lhs,rhs,acc}_type` parameters, populated by
the cost model only when the chosen intrinsic is one of the polymorphic
variants.

The cost model picks `_REG16` on 64-bit ISAs (x86_64, AArch64, RISC-V)
and `_REG8` on 32-bit ISAs. The number is a register-budget for the
unroll heuristic — one element of any width occupies one register, but
the architectural register file the lowering ends up in (GPR or SIMD-
scalar lane) is up to LLVM. The budget is encoded in the low byte of
the enum value, so `chooseUnrolling` can read it back.

Since the intrinsic is 1×1×1, the operand tiles after `intrinsics_m` /
`intrinsics_n` / `intrinsics_k` are simple row-major (M, K) / (N, K) /
(M, N) — `linalg.mmt4d`-shaped. `DataTiledMMAAttr::buildUnderlyingOperations`
therefore short-circuits the swizzle/distribute pipeline for these
intrinsics and emits a single `vector.contract` directly, with
`arith.extf` / `arith.extsi` widening narrow LHS/RHS to ACC's element
type. For sub-byte LHS/RHS types `chooseUnrolling` also picks the
smallest power-of-two `intrinsics_k` such that K*lhsBits and K*rhsBits
are byte-aligned (e.g. K=2 for i4/f4, K=4 for f6, K=8 for i1).

Signed-off-by: Benoit Jacob <[email protected]>

Progress towards iree-org#24323
@bjacob
bjacob force-pushed the users/bjacob/cpu-skip-data-tiling-generic-mma-single branch from 6a264ca to 698d160 Compare May 7, 2026 19:48
@bjacob
bjacob enabled auto-merge (squash) May 7, 2026 20:01
@bjacob
bjacob merged commit c4da71c into iree-org:main May 7, 2026
60 of 62 checks passed
bjacob added a commit that referenced this pull request May 12, 2026
Adds an `e2e_matmul_cpu_dt_inner_tiled_*` family that mirrors the
existing legacy-path `e2e_matmul_cpu_dt_*` block (same type matrix:
i8/i32, f32/f32, f64/f64, f16/f16, f16/f32, bf16/bf16, bf16/f32; same
per-type x86 cpu-features variants; f64-demote guard; riscv/wasm
tags) but with `--iree-opt-data-tiling --iree-llvmcpu-enable-inner-tiled`.

Type×feature combos that match a hardware MMA intrinsic (e.g. f32/f32
on AVX2, bf16/f32 on AVX-512-BF16, i8/i32 on AVX-512-VNNI) exercise
the new `iree_codegen.inner_tiled` lowering; the rest fall through to
the type-polymorphic generic-scalar MMA (#24389), so this is a
correctness check on data-tiling-enabled compilation either way.

Shapes use the `default` set, except f64 (`small`, due to f64-demote
handling). The prerequisite pre-transposed-enum PR is what lets us
start at the full shape set rather than progressively widen.

Progress towards #24323.

Signed-off-by: Benoit Jacob <[email protected]>
bjacob added a commit that referenced this pull request May 13, 2026
Adds an `e2e_matmul_cpu_dt_inner_tiled_*` family that mirrors the
existing legacy-path `e2e_matmul_cpu_dt_*` block (same type matrix:
i8/i32, f32/f32, f64/f64, f16/f16, f16/f32, bf16/bf16, bf16/f32; same
per-type x86 cpu-features variants; f64-demote guard; riscv/wasm
tags) but with `--iree-opt-data-tiling --iree-llvmcpu-enable-inner-tiled`.

Type×feature combos that match a hardware MMA intrinsic (e.g. f32/f32
on AVX2, bf16/f32 on AVX-512-BF16, i8/i32 on AVX-512-VNNI) exercise
the new `iree_codegen.inner_tiled` lowering; the rest fall through to
the type-polymorphic generic-scalar MMA (#24389), so this is a
correctness check on data-tiling-enabled compilation either way.

Shapes use the `default` set, except f64 (`small`, due to f64-demote
handling). The prerequisite pre-transposed-enum PR is what lets us
start at the full shape set rather than progressively widen.

Progress towards #24323.

Signed-off-by: Benoit Jacob <[email protected]>
bjacob added a commit that referenced this pull request May 14, 2026
Adds an `e2e_matmul_cpu_dt_inner_tiled_*` family that mirrors the
existing legacy-path `e2e_matmul_cpu_dt_*` block (same type matrix:
i8/i32, f32/f32, f64/f64, f16/f16, f16/f32, bf16/bf16, bf16/f32; same
per-type x86 cpu-features variants; f64-demote guard; riscv/wasm
tags) but with `--iree-opt-data-tiling --iree-llvmcpu-enable-inner-tiled`.

Type×feature combos that match a hardware MMA intrinsic (e.g. f32/f32
on AVX2, bf16/f32 on AVX-512-BF16, i8/i32 on AVX-512-VNNI) exercise
the new `iree_codegen.inner_tiled` lowering; the rest fall through to
the type-polymorphic generic-scalar MMA (#24389), so this is a
correctness check on data-tiling-enabled compilation either way.

Shapes use the `default` set, except f64 (`small`, due to f64-demote
handling). The prerequisite pre-transposed-enum PR is what lets us
start at the full shape set rather than progressively widen.

Progress towards #24323.

Signed-off-by: Benoit Jacob <[email protected]>
bjacob added a commit that referenced this pull request May 14, 2026
Adds an `e2e_matmul_cpu_dt_inner_tiled_*` family that mirrors the
existing legacy-path `e2e_matmul_cpu_dt_*` block (same type matrix:
i8/i32, f32/f32, f64/f64, f16/f16, f16/f32, bf16/bf16, bf16/f32; same
per-type x86 cpu-features variants; f64-demote guard; riscv/wasm
tags) but with `--iree-opt-data-tiling --iree-llvmcpu-enable-inner-tiled`.

Type×feature combos that match a hardware MMA intrinsic (e.g. f32/f32
on AVX2, bf16/f32 on AVX-512-BF16, i8/i32 on AVX-512-VNNI) exercise
the new `iree_codegen.inner_tiled` lowering; the rest fall through to
the type-polymorphic generic-scalar MMA (#24389), so this is a
correctness check on data-tiling-enabled compilation either way.

Shapes use the `default` set, except f64 (`small`, due to f64-demote
handling). The prerequisite pre-transposed-enum PR is what lets us
start at the full shape set rather than progressively widen.

Progress towards #24323.

Signed-off-by: Benoit Jacob <[email protected]>
bjacob added a commit that referenced this pull request May 14, 2026
Adds an `e2e_matmul_cpu_dt_inner_tiled_*` family that mirrors the
existing legacy-path `e2e_matmul_cpu_dt_*` block (same type matrix:
i8/i32, f32/f32, f64/f64, f16/f16, f16/f32, bf16/bf16, bf16/f32; same
per-type x86 cpu-features variants; f64-demote guard; riscv/wasm
tags) but with `--iree-opt-data-tiling --iree-llvmcpu-enable-inner-tiled`.

Type×feature combos that match a hardware MMA intrinsic (e.g. f32/f32
on AVX2, bf16/f32 on AVX-512-BF16, i8/i32 on AVX-512-VNNI) exercise
the new `iree_codegen.inner_tiled` lowering; the rest fall through to
the type-polymorphic generic-scalar MMA (#24389), so this is a
correctness check on data-tiling-enabled compilation either way.

Shapes use the `default` set, except f64 (`small`, due to f64-demote
handling). The prerequisite pre-transposed-enum PR is what lets us
start at the full shape set rather than progressively widen.

Progress towards #24323.

Signed-off-by: Benoit Jacob <[email protected]>
bjacob added a commit that referenced this pull request May 15, 2026
Adds an `e2e_matmul_cpu_dt_inner_tiled_*` family that mirrors the
existing legacy-path `e2e_matmul_cpu_dt_*` block (same type matrix:
i8/i32, f32/f32, f64/f64, f16/f16, f16/f32, bf16/bf16, bf16/f32; same
per-type x86 cpu-features variants; f64-demote guard; riscv/wasm
tags) but with `--iree-opt-data-tiling --iree-llvmcpu-enable-inner-tiled`.

Type×feature combos that match a hardware MMA intrinsic (e.g. f32/f32
on AVX2, bf16/f32 on AVX-512-BF16, i8/i32 on AVX-512-VNNI) exercise
the new `iree_codegen.inner_tiled` lowering; the rest fall through to
the type-polymorphic generic-scalar MMA (#24389), so this is a
correctness check on data-tiling-enabled compilation either way.

Shapes use the `default` set, except f64 (`small`, due to f64-demote
handling). The prerequisite pre-transposed-enum PR is what lets us
start at the full shape set rather than progressively widen.

Progress towards #24323.

Signed-off-by: Benoit Jacob <[email protected]>
bjacob added a commit that referenced this pull request May 15, 2026
Adds an `e2e_matmul_cpu_dt_inner_tiled_*` family that mirrors the
existing legacy-path `e2e_matmul_cpu_dt_*` block (same type matrix:
i8/i32, f32/f32, f64/f64, f16/f16, f16/f32, bf16/bf16, bf16/f32; same
per-type x86 cpu-features variants; f64-demote guard; riscv/wasm
tags) but with `--iree-opt-data-tiling --iree-llvmcpu-enable-inner-tiled`.

Type×feature combos that match a hardware MMA intrinsic (e.g. f32/f32
on AVX2, bf16/f32 on AVX-512-BF16, i8/i32 on AVX-512-VNNI) exercise
the new `iree_codegen.inner_tiled` lowering; the rest fall through to
the type-polymorphic generic-scalar MMA (#24389), so this is a
correctness check on data-tiling-enabled compilation either way.

Shapes use the `default` set, except f64 (`small`, due to f64-demote
handling). The prerequisite pre-transposed-enum PR is what lets us
start at the full shape set rather than progressively widen.

Progress towards #24323.

Signed-off-by: Benoit Jacob <[email protected]>
bjacob added a commit that referenced this pull request May 15, 2026
Adds an `e2e_matmul_cpu_dt_inner_tiled_*` family that mirrors the
existing legacy-path `e2e_matmul_cpu_dt_*` block (same type matrix:
i8/i32, f32/f32, f64/f64, f16/f16, f16/f32, bf16/bf16, bf16/f32; same
per-type x86 cpu-features variants; f64-demote guard; riscv/wasm
tags) but with `--iree-opt-data-tiling --iree-llvmcpu-enable-inner-tiled`.

Type×feature combos that match a hardware MMA intrinsic (e.g. f32/f32
on AVX2, bf16/f32 on AVX-512-BF16, i8/i32 on AVX-512-VNNI) exercise
the new `iree_codegen.inner_tiled` lowering; the rest fall through to
the type-polymorphic generic-scalar MMA (#24389), so this is a
correctness check on data-tiling-enabled compilation either way.

Shapes use the `default` set, except f64 (`small`, due to f64-demote
handling). The prerequisite pre-transposed-enum PR is what lets us
start at the full shape set rather than progressively widen.

Progress towards #24323.

Signed-off-by: Benoit Jacob <[email protected]>
bjacob added a commit that referenced this pull request May 15, 2026
Adds an `e2e_matmul_cpu_dt_inner_tiled_*` family that mirrors the
existing legacy-path `e2e_matmul_cpu_dt_*` block (same type matrix:
i8/i32, f32/f32, f64/f64, f16/f16, f16/f32, bf16/bf16, bf16/f32; same
per-type x86 cpu-features variants; f64-demote guard; riscv/wasm
tags) but with `--iree-opt-data-tiling --iree-llvmcpu-enable-inner-tiled`.

Type×feature combos that match a hardware MMA intrinsic (e.g. f32/f32
on AVX2, bf16/f32 on AVX-512-BF16, i8/i32 on AVX-512-VNNI) exercise
the new `iree_codegen.inner_tiled` lowering; the rest fall through to
the type-polymorphic generic-scalar MMA (#24389), so this is a
correctness check on data-tiling-enabled compilation either way.

Shapes use the `default` set, except f64 (`small`, due to f64-demote
handling). The prerequisite pre-transposed-enum PR is what lets us
start at the full shape set rather than progressively widen.

Progress towards #24323.

Signed-off-by: Benoit Jacob <[email protected]>
bjacob added a commit that referenced this pull request May 15, 2026
#24492)

Adds an `e2e_matmul_cpu_dt_inner_tiled_*` family that mirrors the
existing legacy-path `e2e_matmul_cpu_dt_*` block (same type matrix:
i8/i32, f32/f32, f64/f64, f16/f16, f16/f32, bf16/bf16, bf16/f32; same
per-type x86 cpu-features variants; f64-demote guard; riscv/wasm tags)
but with `--iree-opt-data-tiling --iree-llvmcpu-enable-inner-tiled`.

Type×feature combos that match a hardware MMA intrinsic (e.g. f32/f32 on
AVX2, bf16/f32 on AVX-512-BF16, i8/i32 on AVX-512-VNNI) exercise the new
`iree_codegen.inner_tiled` lowering; the rest fall through to the
type-polymorphic generic-scalar MMA (#24389), so this is a correctness
check on data-tiling-enabled compilation either way.

Shapes use the `default` set, except f64 (`small`, due to f64-demote
handling). The prerequisite pre-transposed-enum PR is what lets us start
at the full shape set rather than progressively widen.

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
…ree-org#24389)

Adds two new `MMAIntrinsic` values, `MMA_GENERIC_SCALAR_1x1x1_REG8` and
`_REG16`, that the data-tiling cost model picks when no element-type-
specific intrinsic on the target supports the matmul's (LHS, RHS, ACC)
types. This intentionally breaks the "an MMAIntrinsic enum value pins
down a specific element-type triple" invariant in exchange for not
having to add one enum value per supported triple. Element types live on
new `DataTiledMMAAttr.{lhs,rhs,acc}_type` parameters, populated by the
cost model only when the chosen intrinsic is one of the polymorphic
variants.

The cost model picks `_REG16` on 64-bit ISAs (x86_64, AArch64, RISC-V)
and `_REG8` on 32-bit ISAs. The number is a register-budget for the
unroll heuristic — one element of any width occupies one register, but
the architectural register file the lowering ends up in (GPR or SIMD-
scalar lane) is up to LLVM. The budget is encoded in the low byte of the
enum value, so `chooseUnrolling` can read it back.

Since the intrinsic is 1×1×1, the operand tiles after `intrinsics_m` /
`intrinsics_n` / `intrinsics_k` are simple row-major (M, K) / (N, K) /
(M, N) — `linalg.mmt4d`-shaped.
`DataTiledMMAAttr::buildUnderlyingOperations` therefore short-circuits
the swizzle/distribute pipeline for these intrinsics and emits a single
`vector.contract` directly, with `arith.extf` / `arith.extsi` widening
narrow LHS/RHS to ACC's element type. For sub-byte LHS/RHS types
`chooseUnrolling` also picks the smallest power-of-two `intrinsics_k`
such that K*lhsBits and K*rhsBits are byte-aligned (e.g. K=2 for i4/f4,
K=4 for f6, K=8 for i1).

Progress towards iree-org#24323
RattataKing pushed a commit to RattataKing/iree that referenced this pull request May 27, 2026
iree-org#24492)

Adds an `e2e_matmul_cpu_dt_inner_tiled_*` family that mirrors the
existing legacy-path `e2e_matmul_cpu_dt_*` block (same type matrix:
i8/i32, f32/f32, f64/f64, f16/f16, f16/f32, bf16/bf16, bf16/f32; same
per-type x86 cpu-features variants; f64-demote guard; riscv/wasm tags)
but with `--iree-opt-data-tiling --iree-llvmcpu-enable-inner-tiled`.

Type×feature combos that match a hardware MMA intrinsic (e.g. f32/f32 on
AVX2, bf16/f32 on AVX-512-BF16, i8/i32 on AVX-512-VNNI) exercise the new
`iree_codegen.inner_tiled` lowering; the rest fall through to the
type-polymorphic generic-scalar MMA (iree-org#24389), so this is a correctness
check on data-tiling-enabled compilation either way.

Shapes use the `default` set, except f64 (`small`, due to f64-demote
handling). The prerequisite pre-transposed-enum PR is what lets us start
at the full shape set rather than progressively widen.

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