Archived
libr3d: the RDNA3 (gfx11) wave-matrix kernel plugin
A self-contained HIP kernel plugin for gfx11 (RDNA3) that exposes the
libref-declared ops as device rows the engine can tune and dispatch:
* GEMMs (bf16, f16, int8-activation, vocab) retiled to 16x128 on the
wave-matrix (WMMA) builtins. The retile removes the 8x wave
redundancy of the naive tile and stages the activation once per
16x128 block; the 16-row and 64-row forms share the stage. The k-walk
double-buffers the 128-deep tile (the next tile stages while the
current one multiplies), on the m64 and tiled forms.
* Quantised GEMMs: fp8-e4m3 x e4m3 (tiled and ALU), mxfp4 x a8, w2a8,
w4a16, w5a16, w8a8 (the prefill heights 17..127 on the wave matrix),
and the gated (swiglu) form. E4M3 decodes exactly to f16 through a
256-entry LDS table; the WMMA fragments bit-cast the staged halfs
(a uint16-to-_Float16 assignment is a value conversion, not a
reinterpret).
* Half-precision-accumulate arms (acc = 1) on the m64 wave matrix:
the f16/bf16 16x16x16 builtins with the compile-time opsel half
select.
* Grouped MoE GEMMs (bf16, e4m3 with F32 block scales, mxfp4a8, w4a8),
retiled the same way, over the run-walk / gather structure.
* Normalisation (layernorm / rmsnorm) and the quantisation ops.
* GDN linear-attention, the QSA/KV state ops, and the MoE
router/scatter/gather family (router_topk_scatter, router_sigmoid_topk
with the correction bias, moe_gather, moe_gather_inv; the top-k
router runs to n_expert 512).
Every row implements an op libref declares; the selector (tune) picks
the implementation and the NOTUNE rows carry the untuned default.
Selftest-clean (121 rows, schema + finiteness); values verified against
CPU references per op.
This commit is contained in:
1 parent
203064b487
commit
34c52ebe96
54 files changed
+12621
-862
No files matched your search
+14
-1
@@ -278,7 +278,15 @@ enum {
|
||||
* so no fixed default is legal at every shape, and an illegal default would make an untuned install
|
||||
* fail. The GEMM unit resolves the sentinel.
|
||||
*/
|
||||
struct R3dGemmCfg { int wv, sk, kb, nt; }; /* waves a block, split-K, K slab, non-temporal loads */
|
||||
/* waves a block, split-K, K slab, non-temporal loads, and the implementation arm (0 = the dot2
|
||||
* pairs, 1 = the 16x16x16 wave matrix) */
|
||||
struct R3dGemmCfg { int wv, sk, kb, nt, impl; };
|
||||
struct R3dMoeCfg { int mrows; int vgpr; int acc; };
|
||||
/* the grouped E4M3 GEMM's point: the kernel arm (0 = the 16x16 tile, 1 = the same tile with the
|
||||
* ALU decode, 2 = the 16x128 block) and the block's register budget and accumulator */
|
||||
struct R3dMoeQCfg { int impl, vgpr, acc; };
|
||||
/* the block's row count (16, 32 or 64); the per-wave register budget (128 = the 8-wave cap, 512
|
||||
* natural); the accumulator's precision (0 = f32, 1 = the half-precision WMMA tile) */
|
||||
struct R3dSplitCfg { int splits; }; /* split-KV segments; 0 is the kernel's own law */
|
||||
struct R3dTopkCfg { int rc, nch; }; /* candidates a chunk keeps, chunk width in columns */
|
||||
|
||||
@@ -290,8 +298,13 @@ extern "C" {
|
||||
* untuned install runs. They cannot fail: the loader refuses a plugin whose default is not one of
|
||||
* the axis's values. */
|
||||
void r3d_cfg_gemm (const RadArgs*, struct R3dGemmCfg*);
|
||||
void r3d_cfg_moe (const RadArgs*, struct R3dMoeCfg*);
|
||||
void r3d_cfg_moe_q(const RadArgs*, struct R3dMoeQCfg*);
|
||||
void r3d_cfg_split(const RadArgs*, struct R3dSplitCfg*);
|
||||
void r3d_cfg_topk (const RadArgs*, struct R3dTopkCfg*);
|
||||
/* the 16x128 block's launcher with the register budget and accumulator passed through (the e4m3
|
||||
* row's impl 2 arm reads them from its own tune, not the bf16 row's) */
|
||||
int r3d_moe_gemm_fp8_f32scale_run(const RadArgs*, RadStream, int vgpr, int acc);
|
||||
|
||||
} /* extern "C" */
|
||||
|
||||
|
||||
Reference in new issue
Block a user