Archived
MXFP4 decode rows: review fixes and docs
The parts of the series' review rounds that concern these rows, carried over when the series was split: - gemm_mxfp4a8_decode: the 64-wide slab is chosen by the split the launch runs (a pin or a tuned point included), as before the register kernel; the header states the split-row bound the rule applies (ks*M = 1024). - r4d_selftest: the priority order of the MXFP4 rows is checked (gemv / gemv_wide over decode, decode_shortk over gemv_wide, decode over tiled); gemv_wide's numeric cases at K 256 and at 56 rows; the M-invariance check names the decode_shortk corner it does not cover. - Comments: gemv_wide's two-tile condition (N >= 4096, K >= 3072, an even tile count), the decode_shortk corner's bit change at M = 33, decode_shortk in the list of rows whose state is keyed on the output. - libr4d/README.md: the rows by row count, with the measurements behind each band; docs/TOOLS.md: r4d_selftest and its --perfmxd mode. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
40d205929a
commit
fb880cbc2d
6 files changed
+140
-14
No files matched your search
@@ -52,6 +52,8 @@ The table lists a selection; `r4d_rows.cpp` and `r4d.h` hold the full set.
|
||||
| `gemm_w8a16_nt_m64` | 8-bit weight, f16 activation, skinny |
|
||||
| `gemm_w2a8_nt` | 2-bit weight against int8 activation: the DFlash2 draft head |
|
||||
| `gemm_mxfp4a8_nt_m64` | OCP-MXFP4 weight, fp8 activation, skinny |
|
||||
| `gemm_mxfp4a8_gemv` | the same operands for one to eight rows: the weight streamed straight to registers, 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 |
|
||||
| `gemm_mxfp4a8_gemv_wide` | its WMMA form at 9..64 rows: up to four 16-row tiles a wave over each weight word, two 16-column tiles a block on wide, deep weights |
|
||||
| `gemm_mxfp4a8_decode` | the same operands for the decode band (M ≤ 128): split-K across workgroups with a last-arriver reduction, the partial in the op's scratch |
|
||||
| `gemm_mxfp4a8_decode_shortk` | the decode kernel at 33..64 rows of a wide, short weight (N ≥ 8192, K ≤ 2560), above `gemm_mxfp4a8_gemv_wide`, which loses there |
|
||||
| `gemm_mxfp4a8_tiled` | the prefill sibling: the activation re-tiled into fragment order in the op's scratch and read straight into registers, the weight unpacked once per K slab for a 256-row block |
|
||||
@@ -111,6 +113,89 @@ diverge by about 1 ULP.
|
||||
6. Add a case to `libr4d/r4d_selftest.cpp` so the row is called at least once; a row without one
|
||||
reports `no smoke case`.
|
||||
|
||||
## The OCP-MXFP4 GEMM by row count
|
||||
|
||||
`gemm_nt_q` at `mxfp4a8` has six rows over one stored weight (the skinny kernel's fragment-order
|
||||
codes, `[K/32][N]` E8M0 exponents and a per-row reference exponent), so the selector moves between
|
||||
them by M with no second copy. Each needs N a multiple of 16 and K of 64; of those whose
|
||||
constraints hold, the highest priority serves:
|
||||
|
||||
| row | band | priority |
|
||||
| --- | --- | --- |
|
||||
| `gemm_mxfp4a8_decode_shortk` | 33 ≤ M ≤ 64, 8192 ≤ N ≤ 36864, K ≤ 2560 | 59 |
|
||||
| `gemm_mxfp4a8_gemv` | M ≤ 8 | 58 |
|
||||
| `gemm_mxfp4a8_gemv_wide` | 9 ≤ M ≤ 64, K a multiple of 128 | 58 |
|
||||
| `gemm_mxfp4a8_decode` | M ≤ 128, N ≤ 36864 | 55 |
|
||||
| `gemm_mxfp4a8_nt_m64` | M ≤ 64 | 50 |
|
||||
| `gemm_mxfp4a8_tiled` | any M | 30 |
|
||||
|
||||
One stream's decode (M = 1 + the draft depth) takes `gemv`; several streams with speculation land
|
||||
in `gemv_wide` (4 × (1 + 7) = 32 rows, 16 × (1 + 3) = 64); `decode` keeps 65..128 rows, and 9..64
|
||||
where K is not a multiple of 128; `tiled` takes the rest. Unless stated, times are one rank's
|
||||
weight of Qwen3.8-27B or TranslateGemma 27B at TP2 on an R9700, each row alone (`r4d_selftest
|
||||
--perfmxd`). Over 16 per-rank shapes of other models and card counts (Qwen3.8-27B at TP4 and TP8,
|
||||
1B-, 4B- and 8B-class dense at TP1 and TP2, a 31B-class at TP4), M 1..128, the selection below
|
||||
against the better of the decode and skinny rows before it: median -10.3%, mean -10.6% over 192
|
||||
cells.
|
||||
|
||||
**`gemm_mxfp4a8_gemv`** (M ≤ 8). One stream's decode is a pure weight stream, and staging the
|
||||
weight through LDS left narrow projections at a third to two thirds of DRAM bandwidth. This row
|
||||
loads each weight word straight into registers and folds it to e4m3 there: WMMA from register
|
||||
fragments when K is a multiple of 128, `v_dot4` otherwise. The form and the waves a block depend on
|
||||
K alone, so a row's bits do not depend on M, and a verify step's first row is the plain decode of
|
||||
it (`r4d_selftest` checks the first row's bits against M). The scale and reference planes must be
|
||||
4-byte aligned.
|
||||
|
||||
**`gemm_mxfp4a8_gemv_wide`** (9..64 rows, K a multiple of 128). The WMMA form with up to four 16-row
|
||||
tiles a wave: each weight word of a chunk is loaded and folded once and multiplied with every
|
||||
tile's activation fragment, so the weight streams once whatever the row count. A row's sum is its
|
||||
tile's WMMA chain alone, so its bits are `gemv`'s at every M (except in the `decode_shortk` corner,
|
||||
where the decode kernel serves 33..64 rows). From 25 rows, where N ≥ 4096, K ≥ 3072 and the tile
|
||||
count is even, a block carries two 16-column tiles: the activation is read per block, and with one
|
||||
tile a 64-row activation was read N/16 times (356 MB from L2 on a 17408-row gate_up, against a 47 MB
|
||||
weight). On narrower or shallower weights two tiles lost 4..37 % (fewer blocks than the part has
|
||||
units, a short K a wave), so they stay at one. Against the decode row that served 9..64 rows
|
||||
before, in µs: Qwen down 51-80 against 56-105, ssm_out 27-42 against 30-55, q|gate 40-63 against
|
||||
44-74; TranslateGemma down 61-97 against 66-123, o 22-35 against 25-51; gate_up at 24-48 rows
|
||||
110-141 against 145-170. With two tiles a block, 17408 × 5120 at 32 rows 125 → 85 µs and at 64
|
||||
157 → 122, 21504 × 5376 154 → 111 and 183 → 150.
|
||||
|
||||
**`gemm_mxfp4a8_decode_shortk`** (33..64 rows, 8192 ≤ N ≤ 36864, K ≤ 2560). The decode row's
|
||||
kernel, scratch hook and tunables at priority 59, above `gemv_wide`. On a short K a `gemv_wide`
|
||||
block's three or four row tiles make its cross-wave reduction outweigh its WMMAs, and a wide N
|
||||
makes many such blocks. Over 24 per-rank shapes (Qwen3.8 and TranslateGemma at TP1, 2, 4 and 8,
|
||||
and 1B- to 8B-class dense) at 24..64 rows, `gemv_wide` matched or beat the previous decode kernel
|
||||
everywhere but this corner, where it lost by 7..30 %; there this row wins:
|
||||
|
||||
| shape, 64 rows | `gemv_wide` | previous decode kernel | `decode_shortk` |
|
||||
| --- | --- | --- | --- |
|
||||
| 19456 × 2560 | 131.8 µs | 104.5 | 93.3 |
|
||||
| 16384 × 2048 | 92.8 | 76.1 | 68.6 |
|
||||
| 9728 × 2560 | 74.1 | 67.4 | 52.5 |
|
||||
|
||||
Narrower N stays with `gemv_wide` (5120 × 2176 at 40 rows 39.2 µs against 52.8), as do Qwen3.8-27B's
|
||||
and TranslateGemma's two-rank shapes. It is a row rather than a rule inside the gemv entry so that
|
||||
the choice stays a lookup over constraints, and `--debug-selection` names it.
|
||||
|
||||
**`gemm_mxfp4a8_decode`** (65..128 rows, and 9..64 where K is not a multiple of 128). Past 16 rows
|
||||
each wave loads its weight words straight into registers, as `gemv` does (a fragment-order word is
|
||||
the WMMA fragment's register), and only the shared activation is double-buffered in LDS, one
|
||||
barrier a slab. The fold, k-step, slab order, scale carry and epilogue are unchanged, and the whole
|
||||
output was compared byte for byte with the LDS-staged kernel's (312 cases, 17..128 rows, both scale
|
||||
grids, forced splits): 17408 × 5120 at 96 rows 205 → 159 µs, at 128 245 → 214; 5120 × 8704 at 128
|
||||
169 → 139; 6144 × 5120 at 128 121 → 92. The split and slab rule past 64 rows was then re-tuned for
|
||||
this kernel: the 128-wide slab always, and a split only while every split keeps 16 slabs, towards a
|
||||
48-block grid or, at K ≥ 8192, regardless, up to ks·M = 1024 split rows. At 80 / 96 / 128 rows:
|
||||
17408 × 5120 161 / 187 / 215 → 161 / 175 / 197 µs, 5120 × 3072 71 / 79 / 67 → 55 / 60 / 69, 21504 ×
|
||||
5376 192 / 207 / 228 → 187 / 200 / 217. A different split sums a row in a different order, so at
|
||||
65..128 rows the re-tuned rule moves output bits within the selftest's bound: the one change in
|
||||
this family that is not bit for bit. Up to 64 rows the rule is as it was.
|
||||
|
||||
**Tunables.** `gemv` and `gemv_wide` have none, so a `RADIANCE_TUNE` pin on `gemm_nt_q` passes
|
||||
them by. `decode_shortk` shares the decode row's axes (`ks`, `bk`, `nt`; 0 the rule), so a pin of
|
||||
those reaches both. A pin applies to every row serving the op, and an axis a serving row lacks
|
||||
stops startup by name.
|
||||
|
||||
## Notes on the kernels
|
||||
|
||||
Three properties of the architecture are assumed throughout and not restated per kernel:
|
||||
|
||||
Reference in new issue
Block a user