Skip to content

[Codegen][CPU] Drop the power-of-two cap on chooseUnrolling. - #24495

Merged
bjacob merged 3 commits into
mainfrom
users/bjacob/cpu-mma-drop-pow2-unrolling-cap
May 19, 2026
Merged

bjacob merged 3 commits into
mainfrom
users/bjacob/cpu-mma-drop-pow2-unrolling-cap

Conversation

@bjacob

@bjacob bjacob commented May 14, 2026

Copy link
Copy Markdown
Collaborator

chooseUnrolling previously enumerated intrinsics_m / intrinsics_n through powers of two. There's no real reason for that — within the register budget, the cost model can pick any factor.

Looking ahead: some intrinsics may eventually want the unroll factor on a particular dim to be a multiple of some target-specific number — Arm scalar-by-element FMA forms are an example, where the scalar is a lane of a vector register, so covering whole vector registers is more efficient. But even there it's not a strict preference: narrow matmuls (e.g. matrix-vector) are better off avoiding the padding that imposing that multiple would force. So a simple per-intrinsic "preferred multiple" doesn't capture it. We'll come back to this when we have a concrete need.

Lit-test fallout: relaxing pow2 lets the cost model land on better non-pow2 unrolls in some cases the existing tests pin (e.g. materialize_encoding_x86_64.mlir's dynamic-N AVX-512 case now picks intrinsics_m = 29 instead of 16 — saturating the zmm register file much more tightly, and at higher arithmetic intensity per the existing scoring formula). CHECK lines updated to the new values.

Progress towards #24323.

@bjacob bjacob mentioned this pull request May 14, 2026
25 of 28 tasks
@bjacob
bjacob force-pushed the users/bjacob/cpu-inner-tiled-vpdpbusd branch from d877a4b to 41d1eb5 Compare May 15, 2026 14:04
@bjacob
bjacob force-pushed the users/bjacob/cpu-mma-drop-pow2-unrolling-cap branch from bca2822 to d933814 Compare May 15, 2026 14:04
@bjacob
bjacob force-pushed the users/bjacob/cpu-inner-tiled-vpdpbusd branch from 41d1eb5 to 75c3ec0 Compare May 15, 2026 15:54
@bjacob
bjacob force-pushed the users/bjacob/cpu-mma-drop-pow2-unrolling-cap branch from d933814 to 00e5785 Compare May 15, 2026 15:54
@bjacob
bjacob force-pushed the users/bjacob/cpu-inner-tiled-vpdpbusd branch from 75c3ec0 to e850560 Compare May 15, 2026 16:02
@bjacob
bjacob force-pushed the users/bjacob/cpu-mma-drop-pow2-unrolling-cap branch from 00e5785 to 321ccbe Compare May 15, 2026 16:02
@bjacob
bjacob force-pushed the users/bjacob/cpu-inner-tiled-vpdpbusd branch from e850560 to ac57449 Compare May 15, 2026 17:06
@bjacob
bjacob force-pushed the users/bjacob/cpu-mma-drop-pow2-unrolling-cap branch from 321ccbe to 2c2f57d Compare May 15, 2026 17:06
bjacob and others added 3 commits May 15, 2026 15:41
…ework.

The framework so far only generated symmetric-type matmuls (LHS and
RHS of the same type via `--lhs_rhs_type`). This generalizes it to
support `--lhs` and `--rhs` separately so we can test asymmetric-type
intrinsics like the upcoming x86 AVX-512 VNNI vpdpbusd (LHS=ui8,
RHS=i8 → ACC=i32).

- `generate_e2e_matmul_tests.py`: replace `--lhs_rhs_type` with the
  per-operand `--lhs` / `--rhs` pair (legacy form still accepted; the
  CLI requires exactly one form). Adds a `ui8` choice. Plumbing for
  separate `lhs_type`/`rhs_type` is threaded through `generate()` /
  `generate_function()` / `generate_call()`.
- `generate_code.py`: emit a `linalg.generic` (with `arith.extui` /
  `arith.extsi` widening) when LHS != RHS or an operand is unsigned;
  buffer-view printing uses the `ui8` HAL element type for unsigned
  operands.
- `iree-e2e-matmul-test.cc`: new
  `REFERENCE_MATMUL(uint8_t, int8_t, int32_t, int32_t)` reference and
  matching dispatch arm for `IREE_HAL_ELEMENT_TYPE_UINT_8` LHS /
  signed-i8 RHS.

New test `e2e_matmul_cpu_dt_inner_tiled_ui8_i8_i32` exercises the
generated ui8/i8 matmul through the data-tiling + inner-tiled
pipeline. No matching hardware MMA intrinsic exists yet (this commit
is purely framework), so it only runs on the `generic` CPU variant
and falls through to the type-polymorphic generic-scalar MMA. A
follow-up PR adds the vpdpbusd MMA and an `avx512vnni` variant.

Progress towards #24323.

Signed-off-by: Benoit Jacob <[email protected]>
Adds `vpdpbusd` — the AVX-512-VNNI byte dot-product — as a data-tiled
MMA intrinsic. It is the first asymmetric MMA: the first byte source
is unsigned, the second is signed, so the natural and swapped
orientations need different arg-routing at the call site (unlike the
LHS/RHS-symmetric FMA / dpbf16ps / vpdpwssd / pmaddw already
supported).

Two new enum values, `MMA_X86_AVX512VNNI_1x16x4_I32_UI8_I8` and its
M↔N-swapped sibling `MMA_X86_AVX512VNNI_16x1x4_I32_I8_UI8`, both
lower to `llvm.x86.avx512.vpdpbusd.512`. The swapped lowering flips
its (lhs, rhs) call args so the unsigned operand still lands in the
first slot.

Signedness handling — per IREE convention, vector tile types in IR are
signless, with the signed/unsigned distinction carried on the
encoding's `element_types`. `getABCElementTypes(intrinsic)` now
returns `ui8` where applicable, used by the cost model and validator
for matching against an encoding's `element_types`;
`getUndistributedTileTypes` strips the signedness when constructing
tile types. The validator and cost-model `getIntrinsicInfo` bypass
`getUndistributedTileTypes` and read shape + types straight from the
intrinsic via `getRowMajorTilesMNKShape` and `getABCElementTypes`,
which become public for that reason.

The prerequisite "distinct LHS/RHS types" PR added the
`e2e_matmul_cpu_dt_inner_tiled_ui8_i8_i32` test on the `generic`
variant only; this commit adds the `avx512vnni` variant that
actually selects the new intrinsic.

Progress towards #24323.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Signed-off-by: Benoit Jacob <[email protected]>
`chooseUnrolling` previously enumerated `intrinsics_m` / `intrinsics_n`
through powers of two. There's no real reason for that — within the
register budget, the cost model can pick any factor.

Looking ahead: some intrinsics may eventually want the unroll factor
on a particular dim to be a multiple of some target-specific number —
Arm scalar-by-element FMA forms are an example, where the scalar is
a lane of a vector register, so covering whole vector registers is
more efficient. But even there it's not a strict preference: narrow
matmuls (e.g. matrix-vector) are better off avoiding the padding
that imposing that multiple would force. So a simple per-intrinsic
"preferred multiple" doesn't capture it. We'll come back to this when
we have a concrete need.

Lit-test fallout: relaxing pow2 lets the cost model land on better
non-pow2 unrolls in some cases the existing tests pin (e.g.
`materialize_encoding_x86_64.mlir`'s dynamic-N AVX-512 case now picks
`intrinsics_m = 29` instead of 16 — saturating the zmm register file
much more tightly, and at higher arithmetic intensity per the
existing scoring formula). CHECK lines updated to the new values.

Progress towards #24323.

Signed-off-by: Benoit Jacob <[email protected]>
@bjacob
bjacob force-pushed the users/bjacob/cpu-inner-tiled-vpdpbusd branch from ac57449 to 5773d5c Compare May 15, 2026 19:41
@bjacob
bjacob force-pushed the users/bjacob/cpu-mma-drop-pow2-unrolling-cap branch from 2c2f57d to 05a52e4 Compare May 15, 2026 19:41
@bjacob
bjacob marked this pull request as ready for review May 15, 2026 20:02
Base automatically changed from users/bjacob/cpu-inner-tiled-vpdpbusd to main May 19, 2026 15:39
@bjacob
bjacob requested a review from benvanik as a code owner May 19, 2026 15:39
@bjacob
bjacob merged commit f0103e8 into main May 19, 2026
62 of 64 checks passed
@bjacob
bjacob deleted the users/bjacob/cpu-mma-drop-pow2-unrolling-cap branch May 19, 2026 15:39
RattataKing pushed a commit to RattataKing/iree that referenced this pull request May 27, 2026
…org#24495)

`chooseUnrolling` previously enumerated `intrinsics_m` / `intrinsics_n`
through powers of two. There's no real reason for that — within the
register budget, the cost model can pick any factor.

Looking ahead: some intrinsics may eventually want the unroll factor on
a particular dim to be a multiple of some target-specific number — Arm
scalar-by-element FMA forms are an example, where the scalar is a lane
of a vector register, so covering whole vector registers is more
efficient. But even there it's not a strict preference: narrow matmuls
(e.g. matrix-vector) are better off avoiding the padding that imposing
that multiple would force. So a simple per-intrinsic "preferred
multiple" doesn't capture it. We'll come back to this when we have a
concrete need.

Lit-test fallout: relaxing pow2 lets the cost model land on better
non-pow2 unrolls in some cases the existing tests pin (e.g.
`materialize_encoding_x86_64.mlir`'s dynamic-N AVX-512 case now picks
`intrinsics_m = 29` instead of 16 — saturating the zmm register file
much more tightly, and at higher arithmetic intensity per the existing
scoring formula). CHECK lines updated to the new values.

Progress towards iree-org#24323.

---------

Signed-off-by: Benoit Jacob <[email protected]>
Co-authored-by: Claude Opus 4.7 (1M context) <[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