libr4d: gemm_mxfp4a8_gemv, the MXFP4 x fp8 GEMM for one to eight rows

One stream's decode (M = 1 + the draft depth) is a pure weight stream; the decode row stages the
weight through LDS and leaves narrow projections at a third to two thirds of DRAM bandwidth. The new
row (priority 58; M <= 8, K % 64, N % 16; the same packed weight bytes as every MXFP4 row) keeps the
weight in registers: WMMA from register fragments when K % 128 == 0, v_dot4 otherwise. The form and
the wave count per block depend on K alone, so a row's output bits do not depend on M (a verify
step's first row equals the plain decode of it). The scale and reference planes must be 4-byte
aligned.

Selftest: every reachable instantiation (both forms, both activation grids, M = 1..8, tile counts
divisible by 4, by 2 only and odd, parts), the output prefilled with NaN, an odd column stride, and
the first row's bits against M for gemv and decode. --perfmx times the MXFP4 rows at one shape.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
mici81andClaude Opus 5.5 authored and StillDeadcode committed 2026-10-24 11:09:03 +02:00
1 parent d6957e88a1
commit 75b4d0baa7
5 files changed
+458 -7

No files matched your search

+21 -1
View File
@@ -4798,10 +4798,17 @@ static const RadConstraint cGemmW4A8Tiled[] = {
};
/* r4d_gemm_mxfp4a8_decode. Entry point: M <= 128, N % 16, K % 64, and N up to its counter block's
* 36864. Above the skinny row by priority, so it takes the decode band; the skinny row keeps the
* wider N up to M = 64, the tiled row everything else. */
* wider N up to M = 64 (from M = 9: the gemv row below takes M <= 8 at any N), the tiled row
* everything else. */
static const RadConstraint cGemmMxfp4A8Decode[] = {
C_LE("M", 128), C_LE("N", 36864), C_DIV("K", 64), C_DIV("N", 16), C_IN("dtype", "mxfp4a8"),
};
/* r4d_gemm_mxfp4a8_gemv. Entry point: M <= 8, N % 16, K % 64, no N bound (no counters). Above the
* decode row by priority, so one stream's decode (M = 1 + the draft depth) takes it, at any N; the
* decode row keeps M = 9..128. */
static const RadConstraint cGemmMxfp4A8Gemv[] = {
C_LE("M", 8), C_DIV("K", 64), C_DIV("N", 16), C_IN("dtype", "mxfp4a8"),
};
/* r4d_gemm_mxfp4a8_tiled. Entry point: N % 16 (the fragment-order weight), K % 64 (its narrowest
* K slab), M >= 1. The decode and skinny rows outrank it in their bands by priority, so the band
* starts at 1 rather than at a hand-picked crossover. */
@@ -7504,6 +7511,19 @@ R4D_WIN_PAIR(512, 1) R4D_WIN_PAIR(512, 2) R4D_WIN_PAIR(512, 4) R4D_WIN_PAIR(512,
nullptr, nullptr, r4d_rad_gemm_mxfp4a8_m64, nullptr, r4d_rad_layout_mxfp4,
r4d_rad_relayout_mxfp4 },
{ "gemm_mxfp4a8_gemv", "gemm_nt_q", "gemm",
"the OCP-MXFP4 GEMM for ONE TO EIGHT rows: the weight streamed straight to registers and folded "
"to e4m3 there, no LDS staging; WMMA when K is a multiple of 128, v_dot4 otherwise, chosen from "
"K alone so a row's bits do not depend on M",
"M <= 8; N a multiple of 16; K a multiple of 64; the skinny kernel's fragment-order weight, "
"[K/32][N] E8M0 exponents and per-row reference exponent",
"e4m3 A with an f32 scale per row or per (row, 128), e2m1 W with an E8M0 scale per 32 K folded "
"into the element against a per-row reference, bf16 C, fp32 accumulate",
RAD_DOMAIN_DEVICE, R4D_PRIO_GEMM_MXGEMV,
ROW(cGemmMxfp4A8Gemv), NOTUNE,
nullptr, nullptr, r4d_rad_gemm_mxfp4a8_gemv, nullptr,
r4d_rad_layout_mxfp4, r4d_rad_relayout_mxfp4 },
{ "gemm_mxfp4a8_decode", "gemm_nt_q", "gemm",
"the OCP-MXFP4 GEMM for the DECODE band: split-K across workgroups with a fused last-arriver "
"reduction, the weight unpacked through LDS, streaming weight loads",