Skip to content

[CPU][RISC-V] Add M0=1 IME vmadot mmt4d ukernel tiles - #25385

Draft
egebeysel wants to merge 1 commit into
mainfrom
users/egebeysel/ime-m0-1-vmadot
Draft

egebeysel wants to merge 1 commit into
mainfrom
users/egebeysel/ime-m0-1-vmadot

Conversation

@egebeysel

Copy link
Copy Markdown
Contributor

On +xsmtvdot, contractions without an M dimension (vecmat, and matvec after the narrow-N transpose) materialize to mmt4d with a 1 x 4a x 2a layout, where a is the vmadot atom (4/8/16 for zvl256b/1024b/4096b). The riscv_64 ukernel had no tile for M0=1, so these ops fell back to the generic tile function and issued no vmadot. Since #25099 folds the unit M dim after the QDQ conversion, M=1 QDQ matmuls take this path too.

This adds single-row xsmtvdot tiles 1x16x8 (zvl256b), 1x32x16 (zvl1024b) and 1x64x32 (zvl4096b). The LHS row is loaded into row 0 of the vmadot A operand. The other rows only feed accumulator rows that are never stored, so they are left as they are. Broadcasting the row with vrgather, as the i8mm kernel does, measured about 2x slower at VLEN 1024. No compiler change is needed: the resolver already emits these layouts.

Fixes #25338.

Performance

i8 vecmat/matvec with the weight as a parameter, so the weight pack is hoisted into the initializer. iree-benchmark-module, median ms, main → this PR:

case K1 1T K1 4T K3 1T K3 4T
vecmat 4096x4096 116.1 → 3.10 32.3 → 3.22 98.0 → 0.99 25.3 → 0.88
matvec 11008x4096 313.5 → 7.96 81.8 → 7.42 263.2 → 2.52 68.4 → 2.03
M=1 QDQ matmul from #25338 (512x512) 1.82 → 0.092 0.63 → 0.20 1.56 → 0.046 0.51 → 0.12
  • K1: SpacemiT X60, VLEN 256, +zvl256b,+xsmtvdot, cpus 0-3.
  • K3: SpacemiT A100 cores, VLEN 1024, +zvl1024b,+xsmtvdot, one 4-core cluster.

The large shapes are DRAM-bound: one core already streams most of what a cluster delivers, so 4 threads gain little over 1.

Testing

  • mmt4d_test now covers M0=1 for xsmtvdot; it passes on the K1.
  • Compiled vmfbs are checked against numpy references on the K1 and the K3. The cases are vecmat, matvec and batch_vecmat (including odd, padded shapes and an accumulating init) and the [CPU][RISC-V] SpaceMiT IME vmadot no longer selected for an M=1 QDQ matmul #25338 reproducer.
  • materialize_encoding_riscv.mlir pins the 1x16x8 and 1x32x16 layouts for vecmat and matvec.

Assisted-by: Claude Code

🤖 Generated with Claude Code

On +xsmtvdot, matmuls without an M dimension (vecmat, and matvec after
the narrow-N transpose) materialize to mmt4d with a 1 x 4a x 2a layout,
where a is the vmadot atom edge (4/8/16 for zvl256b/1024b/4096b): the
resolver picks the IME tile a x 4a x 2a and drops M0. The riscv_64
ukernel had no tile for that shape, so these ops fell back to the
generic tile function and issued no vmadot. Since the unit M dim is
folded after QDQ conversion, M=1 QDQ matmuls take this path too
(#25338).

Add single-row xsmtvdot tiles 1x16x8 (zvl256b), 1x32x16 (zvl1024b) and
1x64x32 (zvl4096b). The LHS row is loaded into row 0 of the vmadot A
operand and only row 0 of each accumulator group is used. The other A
rows are left as they are: they only feed accumulator rows that are
dropped, and broadcasting the row with vrgather was about 2x slower at
VLEN=1024. Each K panel issues the same 4 vmadot as the 1x4-atom tile.

Tests: mmt4d_test and mmt4d_benchmark cover M0=1 for xsmtvdot, and
materialize_encoding_riscv.mlir pins the 1x16x8 and 1x32x16 layouts for
vecmat and matvec.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Ege Beysel <[email protected]>

This branch has not been deployed

No deployments
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.

[CPU][RISC-V] SpaceMiT IME vmadot no longer selected for an M=1 QDQ matmul

1 participant