Skip to content

[Codegen][CPU] Add e2e matmul tests for the inner_tiled lowering path. - #24405

Merged
bjacob merged 2 commits into
mainfrom
users/bjacob/cpu-inner-tiled-e2e-tests
May 8, 2026
Merged

bjacob merged 2 commits into
mainfrom
users/bjacob/cpu-inner-tiled-e2e-tests

Conversation

@bjacob

@bjacob bjacob commented May 8, 2026 •

Copy link
Copy Markdown
Collaborator

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.

Progress towards #24323

@bjacob bjacob mentioned this pull request May 8, 2026
25 of 28 tasks
@bjacob
bjacob force-pushed the users/bjacob/cpu-inner-tiled-pretransposed-intrinsics branch from 01324d2 to f7573b5 Compare May 8, 2026 15:37
@bjacob
bjacob force-pushed the users/bjacob/cpu-inner-tiled-e2e-tests branch 2 times, most recently from 5b88fac to de7b3aa Compare May 8, 2026 16:07
@bjacob
bjacob force-pushed the users/bjacob/cpu-inner-tiled-pretransposed-intrinsics branch from f7573b5 to 5af6e0f Compare May 8, 2026 16:07
@bjacob
bjacob marked this pull request as ready for review May 8, 2026 16:38
@bjacob
bjacob force-pushed the users/bjacob/cpu-inner-tiled-e2e-tests branch 2 times, most recently from d951093 to dd3e47f Compare May 8, 2026 20:05
@bjacob
bjacob force-pushed the users/bjacob/cpu-inner-tiled-pretransposed-intrinsics branch from e211a28 to 52f0ad0 Compare May 8, 2026 20:05
bjacob added 2 commits May 8, 2026 16:08
…sed enums.

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.

MMAUtils permutation fix:

  `buildDataTiledMMAUnderlyingOperations` previously moved between the
  caller's logical (M, N)-ordered tile type and the swizzle's
  distributed N-D form via a linear-preserving `vector.shape_cast` —
  sound only for identity permutations. Pre-existing intrinsics all
  happened to be identity, so the bug was dormant. Every swapped enum
  added here produces a non-identity permutation (cross-intrinsic-N
  injected before cross-intrinsic-M, putting N first in storage), and
  the shape_cast scrambles (m, n) coordinates so result values land in
  the wrong cells.

  Fix: split the reshape into a logical-shape `shape_cast` plus a
  `vector.transpose` by the swizzle's permutation (input side) / its
  inverse (output side). Folds to a no-op for identity permutations,
  so existing natural-orientation intrinsics produce the same IR as
  before. Verified by extending the existing `lower_avx512_16x1x1_f32`
  test in `lower_inner_tiled.mlir` (the first to exercise a
  non-identity permutation) with `CHECK` lines pinning the
  shape_cast/transpose pairs around the FMA call.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

Progress towards #24323

Signed-off-by: Benoit Jacob <[email protected]>
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 an MMA intrinsic (e.g. f32/f32 on AVX2,
bf16/f32 on AVX-512-BF16, i8/i32 on AVX-512-VNNI) actually exercise
the new `iree_codegen.inner_tiled` lowering; the rest fall through to
the standard codegen path via the earlier "skip data tiling" commit
in this stack. Either way it's a correctness check on data-tiling-
enabled compilation for that target.

Shapes use the `default` set, except f64 (`small`, due to f64-demote
handling). The pre-transposed enums earlier in this stack are what let
us start at the full shape set rather than progressively widen.

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

Progress towards #24323
@bjacob
bjacob force-pushed the users/bjacob/cpu-inner-tiled-e2e-tests branch from dd3e47f to 73f8129 Compare May 8, 2026 20:08
@bjacob
bjacob force-pushed the users/bjacob/cpu-inner-tiled-pretransposed-intrinsics branch from 52f0ad0 to 7cffbfe Compare May 8, 2026 20:08
Base automatically changed from users/bjacob/cpu-inner-tiled-pretransposed-intrinsics to main May 8, 2026 22:00
@bjacob
bjacob merged commit fbe60d8 into main May 8, 2026
56 of 62 checks passed
@hanhanW

hanhanW commented May 8, 2026

Copy link
Copy Markdown
Contributor

There are many remarks about "hoistable conversion" starting from this change: https://github.com/iree-org/iree/actions/runs/25581695297/job/75101859714

INFO: From Compiling IREE module e2e_matmul_cpu_dt_inner_tiled_f16_f16_llvm-cpu_local-task_matmul_module... //tests/e2e/matmul:e2e_matmul_cpu_dt_inner_tiled_f16_f16_llvm-cpu_local-task_matmul_module:
bazel-out/k8-opt/bin/tests/e2e/matmul/e2e_matmul_cpu_dt_inner_tiled_f16_f16_llvm-cpu_local-task.mlir:32:13: remark: hoistable_conversion was not hoisted or cancelled; inlining in place drop_unit_dims inverting add_unit_dims
  %result = linalg.matmul   ins(%lhs, %rhs: tensor<2x2xf16>, tensor<2x2xf16>) outs(%acc: tensor<2x2xf16>) -> tensor<2x2xf16>
            ^
bazel-out/k8-opt/bin/tests/e2e/matmul/e2e_matmul_cpu_dt_inner_tiled_f16_f16_llvm-cpu_local-task.mlir:31:1: note: called from
util.func @matmul_accumulate_2x2xf16_times_2x2xf16_into_2x2xf16(%lhs: tensor<2x2xf16>, %rhs: tensor<2x2xf16>, %acc: tensor<2x2xf16>) -> tensor<2x2xf16> {
^
bazel-out/k8-opt/bin/tests/e2e/matmul/e2e_matmul_cpu_dt_inner_tiled_f16_f16_llvm-cpu_local-task.mlir:19:13: remark: hoistable_conversion was not hoisted or cancelled; inlining in place drop_unit_dims inverting add_unit_dims
  %result = linalg.matmul   ins(%lhs, %rhs: tensor<?x?xf16>, tensor<?x?xf16>) outs(%acc: tensor<?x?xf16>) -> tensor<?x?xf16>
            ^
bazel-out/k8-opt/bin/tests/e2e/matmul/e2e_matmul_cpu_dt_inner_tiled_f16_f16_llvm-cpu_local-task.mlir:11:1: note: called from
util.func @matmul_DYNxDYNxf16_times_DYNxDYNxf16_into_DYNxDYNxf16(%lhs: tensor<?x?xf16>, %rhs: tensor<?x?xf16>) -> tensor<?x?xf16> {
^
bazel-out/k8-opt/bin/tests/e2e/matmul/e2e_matmul_cpu_dt_inner_tiled_f16_f16_llvm-cpu_local-task.mlir:2:13: remark: hoistable_conversion was not hoisted or cancelled; inlining in place drop_unit_dims inverting add_unit_dims
  %result = linalg.matmul   ins(%lhs, %rhs: tensor<?x?xf16>, tensor<?x?xf16>) outs(%acc: tensor<?x?xf16>) -> tensor<?x?xf16>
            ^
bazel-out/k8-opt/bin/tests/e2e/matmul/e2e_matmul_cpu_dt_inner_tiled_f16_f16_llvm-cpu_local-task.mlir:1:1: note: called from
util.func @matmul_accumulate_DYNxDYNxf16_times_DYNxDYNxf16_into_DYNxDYNxf16(%lhs: tensor<?x?xf16>, %rhs: tensor<?x?xf16>, %acc: tensor<?x?xf16>) -> tensor<?x?xf16> {

They are not failures, so we can either send a post fix next Monday or reland it.

@bjacob

bjacob commented May 8, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks for the catch! Let's revert, since that was unexpected.

bjacob added a commit that referenced this pull request May 9, 2026
RattataKing pushed a commit to RattataKing/iree that referenced this pull request May 27, 2026
iree-org#24405)

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`.

Progress towards iree-org#24323

---------

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