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
@@ -597,7 +597,7 @@ __global__ __launch_bounds__(kThreads) R3D_WAVES(4) void sample_topk_kernel(
|
||||
if (x0 != x0) { /* topk_next's seed, as in row_topk */
|
||||
for (uint32_t r = 0; r < n_cand; ++r) {
|
||||
if (r >= k) { hole(r); continue; }
|
||||
ir[r] = vocab_off;
|
||||
ir[r] = 0; /* cand_idx is local: the NaN logit's column */
|
||||
vr[r] = x0;
|
||||
if (pp) { pp[2 * r] = vocab_off; pp[2 * r + 1] = *(const int32_t*)&x0; }
|
||||
}
|
||||
@@ -788,8 +788,11 @@ __global__ __launch_bounds__(kThreads) R3D_WAVES(4) void narrow_kernel(
|
||||
if (s_ev[i] * inv >= th) { cnt += 1.0f; last = (float)i; }
|
||||
}
|
||||
/* Count and last index are order-free (a sum of small integers and a max), so no serial
|
||||
* loop is needed; candidates are re-tested below from the same `s_ev`. */
|
||||
* loop is needed; candidates are re-tested below from the same `s_ev`. The two
|
||||
* reductions share the `red` scratch: block_sum ends on a read of it and block_max
|
||||
* begins on a write, so the barrier between them is the read/write fence. */
|
||||
const float n_above = block_sum<kThreads>(cnt, red);
|
||||
__syncthreads();
|
||||
const float hi = block_max(last, red);
|
||||
if (n_above < 2.0f) return; /* needs two to exclude all but the least likely */
|
||||
const int32_t keep = (int32_t)hi;
|
||||
|
||||
Reference in new issue
Block a user