Archived
MXFP4 tiled GEMM: review fixes, tests and docs
Carried from the series' review rounds when it was split: numeric cases for the plain kernel at a whole row of blocks (TN=4 forced and by the rule from 1024 rows, TN=2 at the 64-wide slab), the plain kernel's comment, and libr4d/README.md's account of the row with the measurements behind TN=4 from 1024 rows, the slab-ahead weight load and the thin last row. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
6249462bfa
commit
824e238996
3 files changed
+31
-2
No files matched your search
@@ -110,6 +110,28 @@ 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 tiled GEMM (prefill)
|
||||
|
||||
**`gemm_mxfp4a8_tiled`** (`gemm_nt_q` at `mxfp4a8`, the rows past the decode band). TN = 4 (256 ×
|
||||
128 blocks) from 1024 rows (it was 2048), unless its blocks would number under 128: at the
|
||||
crossover Qwen3.8-27B's gate_up -2 %, down -3 %, TranslateGemma 27B's gate_up -9 %, its down +1 %,
|
||||
and at 1536 rows all four better; TranslateGemma's 1024-row chunks run there. The weight words a
|
||||
thread stages are loaded into registers a slab ahead, right after the staging barrier, so their
|
||||
DRAM round trip runs under the slab's WMMAs (+1 VGPR at TN = 4, no spills). At 1024 rows Qwen
|
||||
gate_up 804 → 768 µs, down 443 → 417, ssm_in 396 → 384, ssm_out 249 → 231, q|gate 306 → 318;
|
||||
TranslateGemma gate_up 1063 → 1029, down 651 → 617; at 2048 rows 0..-4 %; a 41k-token Qwen3.8-27B
|
||||
prefill on two cards 8.57 → 8.28 s. A thin last row of blocks (1..160 rows, M under 1024) runs a
|
||||
second kernel whose blocks of that row skip the WMMAs of fragments past M, where the plain kernel
|
||||
computes them on clamped copies (half the only block's math at 129 rows); every other M runs the
|
||||
plain kernel, whose code is instruction for instruction the single kernel's from before the split
|
||||
(a guard inside the one kernel cost full blocks 1..15 %). Same-session A/B over 12 shapes: M
|
||||
129..160 -8..-20 %, 320..384 -2..-16 % (Qwen gate_up at 320 rows 402 → 339 µs, TranslateGemma's 513
|
||||
→ 441). Each of the three keeps the fold, the WMMAs and their order per output byte. Times are one
|
||||
rank's weight at TP2 on an R9700, the row alone, clocks warmed; over 20 shapes, M 129..2048: median
|
||||
-7.4 % over 140 cells, none slower beyond run-to-run noise.
|
||||
|
||||
`tn` (0 the rule, 2, 4) pins the TN choice through `RADIANCE_TUNE`.
|
||||
|
||||
## Notes on the kernels
|
||||
|
||||
Three properties of the architecture are assumed throughout and not restated per kernel:
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
//
|
||||
// The weight words and exponents a thread stages are loaded a slab ahead, into registers, right
|
||||
// after the staging barrier, so their DRAM round trip runs under the slab's WMMAs instead of in
|
||||
// front of the next unpack (+1 VGPR at TN=4; r4d_selftest --perfmx, warmed: Qwen3.8 gate_up at
|
||||
// front of the next unpack (+1 VGPR at TN=4; the row alone, clocks warmed: Qwen3.8 gate_up at
|
||||
// 1024 rows 804 -> 768 us, down 443 -> 417, TranslateGemma down 651 -> 617, attention q|gate
|
||||
// 6144 x 5120 306 -> 318; at 2048 rows 0..-4 %). Loading the A fragments a slab ahead too (+38
|
||||
// VGPRs) is slower everywhere.
|
||||
@@ -323,7 +323,8 @@ __device__ __forceinline__ void r4d_gemm_mxfp4a8_tiled_body(
|
||||
}
|
||||
}
|
||||
|
||||
// The plain kernel: every block the unguarded body, over the body's own LDS (the kernel as it always was).
|
||||
// The plain kernel: every block the unguarded body, over the body's own LDS (the single kernel's code
|
||||
// from before the part kernel split off).
|
||||
template <int TN, int LBK, bool ABLK>
|
||||
__global__ __launch_bounds__(R4D_MXT_NTHR) void r4d_gemm_mxfp4a8_tiled_kernel(
|
||||
const unsigned char* __restrict__ AT, const float* __restrict__ As,
|
||||
|
||||
@@ -25992,6 +25992,12 @@ static void device_phase(const Plugin& pl) {
|
||||
mxfp4a8_numeric(pl, "gemm_mxfp4a8_tiled", 300, 272, 640, 2, true);
|
||||
mxfp4a8_numeric(pl, "gemm_mxfp4a8_tiled", 300, 400, 640, 4, true);
|
||||
mxfp4a8_numeric(pl, "gemm_mxfp4a8_tiled", 2100, 512, 2560, 0, true);
|
||||
/* The plain kernel at a whole row of blocks (not the part kernel, which takes a last row of
|
||||
* 1..160 under 1024 rows): TN=4 forced and by the rule from 1024 rows, and TN=2 at the
|
||||
* 64-wide slab (K not a multiple of 128). */
|
||||
mxfp4a8_numeric(pl, "gemm_mxfp4a8_tiled", 256, 400, 640, 4, true);
|
||||
mxfp4a8_numeric(pl, "gemm_mxfp4a8_tiled", 1024, 4096, 640, 0, true);
|
||||
mxfp4a8_numeric(pl, "gemm_mxfp4a8_tiled", 512, 272, 576, 2, true);
|
||||
/* K not a multiple of 128: the TN=2 kernel takes the 64-wide slab. */
|
||||
mxfp4a8_numeric(pl, "gemm_mxfp4a8_tiled", 300, 272, 576, 2);
|
||||
mxfp4a8_numeric(pl, "gemm_mxfp4a8_tiled", 300, 272, 576, 2, true);
|
||||
|
||||
Reference in new issue
Block a user