This repository has been archived on 2026-11-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Asim Siddiqui 34c52ebe96 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.
2026-11-01 20:56:25 +01:00

28 lines
1.1 KiB
C

/* r3d_launch.h -- kernel launch macros for libr3d units.
*
* R3D_KLAUNCH is the triple-chevron launch on the stream the engine hands the entry point, which is
* a stream hipLaunchKernel accepts (docs/PLUGIN.md §5). It is a macro so a test can redefine it and
* run the same sources through a host SIMT emulator.
*
* R3D_DYN_LDS declares a kernel's dynamic LDS, sized by the launch. RDNA3 gives a workgroup 64 KiB,
* as RDNA4 does, so a tile sized for libr4d fits.
*
* R3D_KNAME wraps a kernel name that contains commas, like HIP_KERNEL_NAME.
*/
#ifndef R3D_LAUNCH_H
#define R3D_LAUNCH_H
#define R3D_KNAME(...) __VA_ARGS__
#ifndef R3D_KLAUNCH
#define R3D_KLAUNCH(kernel, grid, block, stream, ...) kernel<<<grid, block, 0, stream>>>(__VA_ARGS__)
#endif
/* The same launch with a dynamic-LDS byte count, for the rows whose stage is sized by the launch
* rather than a template constant. */
#ifndef R3D_KLAUNCH_S
#define R3D_KLAUNCH_S(kernel, grid, block, smem, stream, ...) \
kernel<<<grid, block, smem, stream>>>(__VA_ARGS__)
#endif
#ifndef R3D_DYN_LDS
#define R3D_DYN_LDS(type, name) extern __shared__ type name[]
#endif
#endif