Skip to content

[Codegen][CPU] Add x86 AVX-512 VNNI 16x16x2 i8 MMA intrinsic. - #24534

Merged
bjacob merged 2 commits into
mainfrom
users/bjacob/cpu-i8-mma-16x16x2
Jun 5, 2026
Merged

bjacob merged 2 commits into
mainfrom
users/bjacob/cpu-i8-mma-16x16x2

Conversation

@bjacob

@bjacob bjacob commented May 25, 2026

Copy link
Copy Markdown
Collaborator

MMA_X86_AVX512VNNI_16x16x2_I32_I8_CASTI16 processes a full 16x16x2 i8 matmul tile, mirroring the mmt4d ukernel's hot loop. Unlike the 1x16x2 / 16x1x2 CASTI16 variants -- one row per intrinsic, with a per-row i8->i16 widen + broadcast -- it consumes whole 16x2 i8 panels: one vpmovsxbw widen per panel, 4 in-lane + 4 128-bit-block shuffles to fan the panels across a 4x4 grid, then 16 vpdpwssd. The 16x16 accumulator uses a block-interleaved TileSwizzle so each vpdpwssd accumulator is a contiguous register.

i8 inner_tiled matmul, 4096x4096 on Zen 4: 72.5ms -> 52.9ms.

Progress towards #24515.

@bjacob
bjacob marked this pull request as ready for review June 1, 2026 15:27
@bjacob
bjacob requested review from Max191, hanhanW and jtuyls as code owners June 1, 2026 15:27
@bjacob
bjacob force-pushed the users/bjacob/cpu-i8-mma-16x16x2 branch from a8e703f to e880789 Compare June 3, 2026 18:46
@bjacob
bjacob force-pushed the users/bjacob/cpu-encoding-combine-layout branch from c531378 to 3a9e9b4 Compare June 3, 2026 18:46
@egebeysel

Copy link
Copy Markdown
Contributor

do we actually have an e2e test that runs this code path?

@bjacob

bjacob commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator Author

do we actually have an e2e test that runs this code path?

Yes — the in-tree e2e_matmul_cpu_dt_i8_i32_llvm-cpu_local-task_avx512vnni and e2e_matmul_cpu_experimental_dt_i8_i32_llvm-cpu_local-task_avx512vnni tests cover it. Pre-PR, the cost model picks a smaller i8 intrinsic for the data-tiled VNNI matmul; this PR's kAllX86[] entry plus the lowering at lowerX86Avx512Vnni16x16x2I8 make MMA_X86_AVX512VNNI_16x16x2_I32_I8_CASTI16 the preferred choice (largest register footprint at avx512), so post-PR those tests go through the new lowering numerically. I confirmed via --mlir-print-ir-after-all on a representative shape on this branch that the cost model does select this intrinsic for a data-tiled i8 matmul.

GPU's configuration pipeline folds the `pack`/`expand_shape`/`transpose`
relayout chain from encoding materialization into a single
`iree_linalg_ext.map_store` before tiling; CPU did not. For a non-row-
major encoding swizzle the intervening `tensor.expand_shape` (not a
`TilingInterface` op) blocks producer fusion and strands an untiled,
whole-tensor `pack` intermediate.

Mirror GPU on CPU:
- Add `RelayoutCombinationScope::DispatchReshape`: like `Dispatch` but
  restricted to chains whose backward slice contains an
  expand/collapse_shape. Pure pack/unpack/transpose chains tile fine and
  are left alone.
- Run `CombineResultLayoutTransformation` with that scope in the CPU
  configuration pipeline, after MaterializeDeviceEncoding.
- Skip `map_load`/`map_store` as `getRootOperation` candidates, so a
  dispatch with a real compute op plus a `map_store` roots on the
  compute op.

Inert for existing (row-major) CPU encodings.

Progress towards #24515.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
Signed-off-by: Benoit Jacob <[email protected]>
@bjacob
bjacob force-pushed the users/bjacob/cpu-encoding-combine-layout branch from 3a9e9b4 to 5a6b922 Compare June 5, 2026 15:08
`MMA_X86_AVX512VNNI_16x16x2_I32_I8_CASTI16` processes a full 16x16x2 i8
matmul tile, mirroring the mmt4d ukernel's hot loop. Unlike the 1x16x2 /
16x1x2 CASTI16 variants -- one row per intrinsic, with a per-row i8->i16
widen + broadcast -- it consumes whole 16x2 i8 panels: one `vpmovsxbw`
widen per panel, 4 in-lane + 4 128-bit-block shuffles to fan the panels
across a 4x4 grid, then 16 `vpdpwssd`. The 16x16 accumulator uses a
block-interleaved `TileSwizzle` so each `vpdpwssd` accumulator is a
contiguous register.

i8 inner_tiled matmul, 4096x4096 on Zen 4: 72.5ms -> 52.9ms.

Progress towards #24515.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
Signed-off-by: Benoit Jacob <[email protected]>
@bjacob
bjacob force-pushed the users/bjacob/cpu-i8-mma-16x16x2 branch from e880789 to 9816c54 Compare June 5, 2026 15:11
Base automatically changed from users/bjacob/cpu-encoding-combine-layout to main June 5, 2026 16:20
@bjacob
bjacob merged commit c675333 into main Jun 5, 2026
62 of 63 checks passed
@bjacob
bjacob deleted the users/bjacob/cpu-i8-mma-16x16x2 branch June 5, 2026 16:20
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.

3 participants