radiance 1.7.0

- every model serves without a GPU: libavx covers every op, so `--kernels libavx` alone serves
  every shipped container
- Qwen3-ASR (zivius): speech to text on /v1/audio/transcriptions and live over /v1/realtime
- /v1/messages works with Claude Code as it ships (gearwave00001)
- a long agent conversation keeps its cached history when the client rewrites its last turn
  (manueloverride)
- a stream's first event goes out with the first token, so llama-benchy measures prefill right
- opt-in --prefill-interleave (Smellyyyy, baKon) and --prefill-span (keptn42)
- four-rank TP releases the link early; four-rank selftests and docs/TP4.md (goodman-b)
- NVFP4 and FP8 compressed-tensors imports (devmilan); tools/rad-export for finetunes and LoRA
  adapters (baKon)
- many fixes, among them lost tokens on stop strings under concurrency, keep-alive, MiniCPM5 tool
  arguments and the CPU's vision and audio encoders
- plugin ABI 17 and changed op schemas: out-of-tree plugins must be rebuilt
This commit is contained in:
Deadcode committed 2026-10-16 18:25:18 +02:00
1 parent b068190326
commit 1e968f6e1d
739 files changed
+128447 -84632

No files matched your search

+116 -188
View File
@@ -1,10 +1,9 @@
/* r4d_plugin.h -- what libr4d's translation units share.
*
* The row table (r4d_rows.cpp) and the weight layouts (r4d_layout.cpp) are PURE HOST C++ and
* include only this file and the ABI; the launch shims include r4d.h and therefore
* <hip/hip_runtime.h>. That split is deliberate: it is what lets the constraint table -- the part
* a transcription error hides in -- be compiled and read on a machine with no ROCm, and it is why
* every shim is declared here rather than in the file that defines it.
* The row table (r4d_rows.cpp) and the weight layouts (r4d_layout.cpp) are pure host C++ and
* include only this file and the ABI; the launch shims include r4d.h and so <hip/hip_runtime.h>.
* The split lets the constraint table compile and be checked without ROCm, and is why every shim
* is declared here rather than beside its definition.
*
* Nothing in this header may include r4d.h.
*/
@@ -16,68 +15,61 @@
/* ================================================================== the priority ladder
*
* The selector ranks candidate rows by an integer priority (spec §2.1). Where two rows of one op
* can both match a geometry, the value is what decides which serves it; each group below states
* the reason its order is what it is.
*
* Values are spaced by ten so a row can be slipped between two of them without renumbering.
* The selector ranks candidate rows by an integer priority (spec §2.1); where two rows of one op
* can match a geometry, it decides which serves. Each group states the reason for its order.
* Values are spaced by ten so a row can be slipped between two without renumbering.
*/
enum {
/* A two-shot row's constraints are a SUPERSET of the one-shot's at the same world_size, so a
* two-shot that ranked below could never be reached: every query it serves the one-shot also
* matches. Its lower bound on `numel` is what keeps a small message on the one-shot, and the
* priority is what hands a large one to the two-shot. */
/* A two-shot row's constraints are a superset of the one-shot's at the same world_size, so it
* must rank higher to be reachable. Its lower bound on `numel` keeps small messages on the
* one-shot. */
R4D_PRIO_AR_TWOSHOT = 70,
R4D_PRIO_AR_ONESHOT = 60,
/* One op (`attn_paged`) banded on q_len, so the decode row's bound -- q_len<=10 at h256,
* q_len<=16 at h128 -- is a bucket boundary and not a partition: inside the low band BOTH rows
* match. The decode row therefore has to outrank the prefill one, which is the same choice a
* caller selecting an entry point by hand would make. */
/* `attn_paged` is banded on q_len, and the decode row's bound (q_len<=10 at h256, q_len<=16 at
* h128) is a bucket boundary, not a partition: both rows match in the low band, so decode must
* outrank prefill. */
R4D_PRIO_ATTN_DECODE = 70,
R4D_PRIO_ATTN_PREFILL = 60,
/* The windowed kernels (r4d_attn_paged_window.hip) serve every q_len, so where their geometry
* meets another leg's -- h256 at gqa 2 -- they match in both of that leg's bands, and rank
* below both: timed by rad-kbench on two R9700s at the 31B's shapes (window 1024, fp8 cache),
* the h256/gqa2 decode kernel takes 0.26-0.71 of the windowed kernel's time at q_len 1..32 and
* its prefill kernel 0.43-0.67 at 33..512, a bf16 cache the same order. The windowed rows keep
* that geometry's non-causal band past q_len 32, and attn_paged_qrow, which no other kernel
* serves. */
* meets another leg's (h256 at gqa 2) they match in both of that leg's bands and rank below
* both: on R9700 at the 31B's shapes (window 1024, fp8 cache) the h256/gqa2 decode kernel takes
* 0.26-0.71 of the windowed kernel's time at q_len 1..32 and its prefill kernel 0.43-0.67 at
* 33..512, bf16 cache similar. The windowed rows keep that geometry's non-causal band past
* q_len 32, and attn_paged_qrow, which no other kernel serves. */
R4D_PRIO_ATTN_WINDOW = 50,
/* At M<=16 with K%256==0 both bf16 skinny rows match and the m16 (dot2) kernel is taken.
* The m64 WMMA kernel is faster on every shape measured, so a caller that wants it at low M
* asks with M=64 to exclude m16. */
/* At M<=16 with K%256==0 both bf16 skinny rows match and the m16 (dot2) kernel is taken. The
* m64 WMMA kernel is faster on every shape measured, so a caller wanting it at low M asks with
* M=64 to exclude m16. */
R4D_PRIO_GEMM_M16 = 60,
R4D_PRIO_GEMM_SKINNY = 50,
/* The MXFP4 decode row outranks the MXFP4 skinny row, whose band it shares up to N = 36864. */
R4D_PRIO_GEMM_MXDEC = 55,
/* The skinny m64 row has no upper bound on M, so the tiled bf16 row -- M > 64 only -- has to
* outrank it to be reached, and stays below m16 whose band it never enters. */
/* The skinny m64 row has no upper bound on M, so the tiled bf16 row (M > 64 only) must outrank
* it, and stays below m16, whose band it never enters. */
R4D_PRIO_GEMM_BF16_TILED = 55,
/* The bands already separate the tiled and prefill GEMMs from the skinny kernels -- skinny is
* M<=64, these are unbounded -- so this pair only decides the M>64 band. `pf` is the newer
* kernel and its tuned picks fall back to the tiled one where it is absent, so it outranks.
* WHAT THIS CANNOT EXPRESS: the optimum crosses BETWEEN the two kernels at a shape-dependent
* M, and the tuning axis is variants WITHIN a kernel, so a per-shape crossover has no home
* here. */
/* Bands already separate these from the skinny kernels (skinny is M<=64, these unbounded), so
* this pair only decides M>64. `pf` is the newer kernel and its tuned picks fall back to the
* tiled one, so it outranks. Not expressible here: the optimum crosses between the two kernels
* at a shape-dependent M, and tuning varies only within a kernel. */
R4D_PRIO_GEMM_PREFILL = 40,
R4D_PRIO_GEMM_TILED = 30,
/* The block-scaled fp8 family. fp8a16 is a separate dtype and needs no ordering against these
* two; the narrow fp8a8 row's M <= 16 is a subset of the tiled row's unbounded M, so the
* narrow row must outrank or it could not be reached. These sit above the skinny int8 GEMMs'
* band only in the sense that no dtype string reaches both. */
/* The block-scaled fp8 family. fp8a16 is a separate dtype and needs no ordering against these;
* the narrow fp8a8 row's M <= 16 is a subset of the tiled row's unbounded M, so it must
* outrank. No dtype string reaches both these and the skinny int8 GEMMs. */
R4D_PRIO_GEMM_FP8_M16 = 60,
R4D_PRIO_GEMM_FP8_TILED = 40,
/* The lm_head at fp8, above the bf16 projection: both serve the same declared geometry, and
* the one that reads half the bytes wins. The container follows the resolved row (spec 4.2),
* so this choice is what decides the format the head is stored in. */
/* The lm_head at fp8 (and int8), above the bf16 projection, which reads twice the bytes.
* The head's encoding, fixed at conversion, decides which rows are candidates (spec §4.3):
* these rows' layout hooks refuse a bf16 head, and the bf16 row has no hook for a scaled
* one. */
R4D_PRIO_LOGITS_FP8 = 60,
/* Everything with exactly one candidate row per (op, geometry). The value carries no ordering
* information; it exists so a user's override plugin has room underneath and above. */
/* Exactly one candidate row per (op, geometry). The value carries no ordering; it leaves a
* user's override plugin room above and below. */
R4D_PRIO_ONLY = 50,
};
@@ -97,17 +89,17 @@ int r4d_rad_attn_decode_h128_fp8 (const RadArgs*, RadStream);
int r4d_rad_attn_decode_h128_bf16 (const RadArgs*, RadStream);
int64_t r4d_rad_attn_decode_h256_scratch(const RadArgs*);
int64_t r4d_rad_attn_decode_h128_scratch(const RadArgs*);
/* Gemma 4 dense sliding window (r4d_attn_paged_h256_gqa2.hip): head_dim 256, 2 queries per KV head,
* windowed. Both bands: the decode band (q_len*gqa <= 64, verify width 32 against the gqa6 leg's
* 10) and the windowed prefill band (the same r4d_attn_prefill_kernel the gqa6 leg uses, WIN on). */
int r4d_rad_attn_prefill_h256_gqa2_fp8 (const RadArgs*, RadStream);
int r4d_rad_attn_prefill_h256_gqa2_bf16 (const RadArgs*, RadStream);
int r4d_rad_attn_decode_h256_gqa2_fp8 (const RadArgs*, RadStream);
int r4d_rad_attn_decode_h256_gqa2_bf16 (const RadArgs*, RadStream);
int64_t r4d_rad_attn_decode_h256_gqa2_scratch(const RadArgs*);
/* Gemma 4 dense sliding window (r4d_attn_paged_h256_gqa2.hip): head_dim 256, 2 queries per KV
* head. Both bands: decode (q_len*gqa <= 64, verify width 32 against the gqa6 leg's 10) and
* windowed prefill (the gqa6 leg's r4d_attn_prefill_kernel with WIN on). */
int r4d_rad_attn_prefill_h256_gqa2_fp8 (const RadArgs*, RadStream);
int r4d_rad_attn_prefill_h256_gqa2_bf16 (const RadArgs*, RadStream);
int r4d_rad_attn_decode_h256_gqa2_fp8 (const RadArgs*, RadStream);
int r4d_rad_attn_decode_h256_gqa2_bf16 (const RadArgs*, RadStream);
int64_t r4d_rad_attn_decode_h256_gqa2_scratch(const RadArgs*);
/* Paged attention at head_dim 256 and 512, 1/2/4/8 queries per KV head, any window, causal or not
* (r4d_attn_paged_window.hip): one entry point a geometry and cache dtype, serving every q_len and
* reading q at any row pitch, so the same entry points serve attn_paged and attn_paged_qrow. */
* (r4d_attn_paged_window.hip): one entry point per geometry and cache dtype, every q_len and any q
* row pitch, so they serve both attn_paged and attn_paged_qrow. */
int r4d_rad_attn_window_h256_gqa1_bf16(const RadArgs*, RadStream);
int r4d_rad_attn_window_h256_gqa1_fp8 (const RadArgs*, RadStream);
int r4d_rad_attn_window_h256_gqa2_bf16(const RadArgs*, RadStream);
@@ -138,6 +130,7 @@ int r4d_rad_join_add_scale_bf16 (const RadArgs*, RadStream);
int r4d_rad_expert_scale_bf16 (const RadArgs*, RadStream);
int r4d_rad_attn_vit (const RadArgs*, RadStream);
int r4d_rad_attn_dense (const RadArgs*, RadStream);
int r4d_rad_seg_sinusoid (const RadArgs*, RadStream);
/* The image generator's attention (r4d_attn_gen.hip): a paged prefix and the pass's own rows, the
* causal-capable dense form at head_dim 128 (a text encoder's prompt), and one 1152-wide head
* (an image decoder's mid block). */
@@ -162,9 +155,9 @@ int r4d_rad_s2d_avg_add (const RadArgs*, RadStream);
int r4d_rad_to_rgba8 (const RadArgs*, RadStream);
int r4d_rad_gelu_tanh (const RadArgs*, RadStream);
int r4d_rad_scatter_add_rows (const RadArgs*, RadStream);
/* Eight queries per KV head (r4d_attn_paged_gqa8.hip): the routed 35B-A3B at head_dim 256
* and MiniCPM5-2B at 128. A decode workgroup holds 64 rows of q_len*gqa, so the verify
* width is 8 here against the gqa6 leg's 10 -- which is the row's constraint value. */
/* Eight queries per KV head (r4d_attn_paged_gqa8.hip): the routed 35B-A3B at head_dim 256 and
* MiniCPM5-2B at 128. A decode workgroup holds 64 rows of q_len*gqa, so the verify width (the
* row's constraint value) is 8, against the gqa6 leg's 10. */
int r4d_rad_attn_prefill_h256_gqa8_fp8 (const RadArgs*, RadStream);
int r4d_rad_attn_prefill_h256_gqa8_bf16(const RadArgs*, RadStream);
int r4d_rad_attn_decode_h256_gqa8_fp8 (const RadArgs*, RadStream);
@@ -175,54 +168,45 @@ int r4d_rad_attn_prefill_h128_gqa8_bf16(const RadArgs*, RadStream);
int r4d_rad_attn_decode_h128_gqa8_fp8 (const RadArgs*, RadStream);
int r4d_rad_attn_decode_h128_gqa8_bf16 (const RadArgs*, RadStream);
int64_t r4d_rad_attn_decode_h128_gqa8_scratch(const RadArgs*);
/* Four queries a KV head, head_dim 256 only -- Qwen3.5-0.8B. Same body, different
* instantiation (r4d_attn_paged_h256_gqa4.hip). */
/* Four queries per KV head, head_dim 256 only (Qwen3.5-0.8B); same body, another instantiation
* (r4d_attn_paged_h256_gqa4.hip). */
int r4d_rad_attn_prefill_h256_gqa4_fp8 (const RadArgs*, RadStream);
int r4d_rad_attn_prefill_h256_gqa4_bf16(const RadArgs*, RadStream);
int r4d_rad_attn_decode_h256_gqa4_fp8 (const RadArgs*, RadStream);
int r4d_rad_attn_decode_h256_gqa4_bf16 (const RadArgs*, RadStream);
int64_t r4d_rad_attn_decode_h256_gqa4_scratch(const RadArgs*);
/* ...and its head_dim 64 prefill leg, LFM2's geometry, which serves every query length. */
/* ...and its head_dim 64 prefill leg, LFM2's geometry, serving every query length. */
int r4d_rad_attn_prefill_h64_gqa4_fp8 (const RadArgs*, RadStream);
int r4d_rad_attn_prefill_h64_gqa4_bf16(const RadArgs*, RadStream);
/* Twelve queries a KV head, head_dim 256 only -- Qwen3.8-Flash-Next's QSA layers. Same body,
* different instantiation; r4d_attn_paged_h256_gqa12.hip is four lines. */
/* Two queries per KV head at head_dim 128 (Qwen3-1.7B, Qwen3-ASR's decoder): the gqa8 body at
* gqa 2 (r4d_attn_paged_h128_gqa2.hip). */
int r4d_rad_attn_prefill_h128_gqa2_fp8 (const RadArgs*, RadStream);
int r4d_rad_attn_prefill_h128_gqa2_bf16(const RadArgs*, RadStream);
int r4d_rad_attn_decode_h128_gqa2_fp8 (const RadArgs*, RadStream);
int r4d_rad_attn_decode_h128_gqa2_bf16 (const RadArgs*, RadStream);
int64_t r4d_rad_attn_decode_h128_gqa2_scratch(const RadArgs*);
/* Twelve queries per KV head, head_dim 256 only: Qwen3.8-Flash-Next's QSA layers. Same body,
* another instantiation (r4d_attn_paged_h256_gqa12.hip). */
int r4d_rad_attn_prefill_h256_gqa12_fp8 (const RadArgs*, RadStream);
int r4d_rad_attn_prefill_h256_gqa12_bf16(const RadArgs*, RadStream);
int r4d_rad_attn_decode_h256_gqa12_fp8 (const RadArgs*, RadStream);
int r4d_rad_attn_decode_h256_gqa12_fp8_describe(const RadArgs*, RadStream, RadLaunchDesc*,
int, int*);
int r4d_rad_attn_decode_h256_gqa12_bf16 (const RadArgs*, RadStream);
int r4d_rad_attn_decode_h256_gqa12_bf16_describe(const RadArgs*, RadStream, RadLaunchDesc*,
int, int*);
int r4d_rad_attn_decode_gq_h256_gqa12_fp8(const RadArgs*, RadStream);
int r4d_rad_attn_decode_gq_h256_gqa12_fp8_describe(const RadArgs*, RadStream, RadLaunchDesc*,
int, int*);
int r4d_rad_attn_decode_gq_h256_gqa12_bf16(const RadArgs*, RadStream);
int r4d_rad_attn_decode_gq_h256_gqa12_bf16_describe(const RadArgs*, RadStream, RadLaunchDesc*,
int, int*);
int64_t r4d_rad_attn_decode_h256_gqa12_scratch(const RadArgs*);
/* Six queries a KV head, head_dim 256, paged block 4 -- the same QSA layers at four ranks, where
* the KV head is replicated across a rank pair. Same body again; the verify width is 64/6 = 10
* against gqa12's 5, which is the decode rows' constraint value. */
/* Six queries per KV head, head_dim 256, paged block 4: the same QSA layers at four ranks, with
* the KV head replicated across a rank pair. The verify width is 64/6 = 10 against gqa12's 5,
* the decode rows' constraint value. */
int r4d_rad_attn_prefill_h256_gqa6_fp8 (const RadArgs*, RadStream);
int r4d_rad_attn_prefill_h256_gqa6_bf16(const RadArgs*, RadStream);
int r4d_rad_attn_decode_h256_gqa6_fp8 (const RadArgs*, RadStream);
int r4d_rad_attn_decode_h256_gqa6_fp8_describe(const RadArgs*, RadStream, RadLaunchDesc*,
int, int*);
int r4d_rad_attn_decode_h256_gqa6_bf16 (const RadArgs*, RadStream);
int r4d_rad_attn_decode_h256_gqa6_bf16_describe(const RadArgs*, RadStream, RadLaunchDesc*,
int, int*);
int64_t r4d_rad_attn_decode_h256_gqa6_scratch(const RadArgs*);
/* The same two merges with the output gate and the quantiser in them, at the four-rank ratio. The
* body instantiates these at every ratio (`R4D_ATTN_GQA` pastes them), so unlike `all_gather` this
* one needed a ROW and not a kernel — see attn_decode_gq_h256_gqa6_fp8kv. */
/* The same two merges with the output gate and the quantiser, at the four-rank ratio. The body
* instantiates these at every ratio (`R4D_ATTN_GQA` pastes them), so this needed a row, not a
* kernel; see attn_decode_gq_h256_gqa6_fp8kv. */
int r4d_rad_attn_decode_gq_h256_gqa6_fp8(const RadArgs*, RadStream);
int r4d_rad_attn_decode_gq_h256_gqa6_fp8_describe(const RadArgs*, RadStream, RadLaunchDesc*,
int, int*);
int r4d_rad_attn_decode_gq_h256_gqa6_bf16(const RadArgs*, RadStream);
int r4d_rad_attn_decode_gq_h256_gqa6_bf16_describe(const RadArgs*, RadStream, RadLaunchDesc*,
int, int*);
/* -- gated delta net (r4d_gdn_*.hip) -- */
int r4d_rad_gdn_chunk_scan (const RadArgs*, RadStream);
@@ -230,8 +214,8 @@ int r4d_rad_gdn_conv_prep (const RadArgs*, RadStream);
int r4d_rad_gdn_conv_update (const RadArgs*, RadStream);
int r4d_rad_gdn_kkt_solve (const RadArgs*, RadStream);
int r4d_rad_gdn_recurrent_update(const RadArgs*, RadStream);
/* gdn_conv_update folded into the recurrent update's prologue: the decode shape, q/k/v never
* written (r4d_gdn_recurrent_update_k128_v128_bf16_fp32state.hip). */
/* gdn_conv_update folded into the recurrent update's prologue for the decode shape; q/k/v are
* never written (r4d_gdn_recurrent_update_k128_v128_bf16_fp32state.hip). */
int r4d_rad_gdn_conv_recurrent_update(const RadArgs*, RadStream);
int r4d_rad_gdn_gated_rmsnorm (const RadArgs*, RadStream);
int r4d_rad_dflash_conv (const RadArgs*, RadStream);
@@ -240,19 +224,16 @@ int r4d_rad_dflash_select (const RadArgs*, RadStream);
/* -- the gated residual (r4d_hc_bf16.hip) -- */
int r4d_rad_hc_enter (const RadArgs*, RadStream);
int r4d_rad_mtp_enter (const RadArgs*, RadStream);
int r4d_rad_mtp_enter_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int64_t r4d_rad_mtp_enter_scratch(const RadArgs*);
int r4d_rad_hc_read (const RadArgs*, RadStream);
int r4d_rad_hc_read_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int64_t r4d_rad_hc_read_scratch(const RadArgs*);
int r4d_rad_hc_write (const RadArgs*, RadStream);
int r4d_rad_hc_write_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
/* -- all-reduce (r4d_ar_entry.hip) -- */
int r4d_rad_ar_init(const RadParam*, int, int rank, int world, void** out);
void r4d_rad_ar_fini(void*);
/* The same three inits with every rank's exchange buffers in pinned host memory: the host twins
* of the collective rows (r4d_rows.cpp) take them, and every launch and the fini are shared. */
/* The same three inits with every rank's exchange buffers in pinned host memory, for the host
* twins of the collective rows (r4d_rows.cpp); launches and fini are shared. */
int r4d_rad_ar_host_init(const RadParam*, int, int rank, int world, void** out);
int r4d_rad_ar_ln_host_init(const RadParam*, int, int rank, int world, void** out);
int r4d_rad_ar_hc_wide_host_init(const RadParam*, int, int rank, int world, void** out);
@@ -295,7 +276,6 @@ int r4d_rad_gemm_w4a16asym_m64(const RadArgs*, RadStream);
int r4d_rad_gemm_w4a8i8_tiled(const RadArgs*, RadStream);
int r4d_rad_gemm_w5a8i8_tiled(const RadArgs*, RadStream);
int r4d_rad_givens_dense_quant(const RadArgs*, RadStream);
int r4d_rad_givens_dense_quant_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int r4d_rad_gemm_w8a16_m64 (const RadArgs*, RadStream);
int r4d_rad_gemm_w4a8_m64 (const RadArgs*, RadStream);
int r4d_rad_gemm_w4a8_tiled (const RadArgs*, RadStream);
@@ -310,52 +290,42 @@ int r4d_rad_gemm_mxfp4a8_decode(const RadArgs*, RadStream);
int64_t r4d_rad_gemm_mxfp4a8_decode_scratch(const RadArgs*);
int r4d_rad_dequant_w4 (const RadArgs*, RadStream);
int r4d_rad_rowtopk (const RadArgs*, RadStream);
int r4d_rad_rowtopk_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int64_t r4d_rad_rowtopk_scratch(const RadArgs*);
int r4d_rad_rowtopk_merge (const RadArgs*, RadStream);
int r4d_rad_logit_rerank (const RadArgs*, RadStream);
int r4d_rad_logit_rerank_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int r4d_rad_logit_rerank_i8 (const RadArgs*, RadStream);
int r4d_rad_logit_rerank_i8_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
/* -- the routed mixture of experts (r4d_moe.hip) --
*
* `moe_gemm_q`'s weight operands are TABLES (RAD_OPD_WTAB): the core resolves a run of declared
* weights to a device array of pointers, one per expert, because after placement a layer's
* experts are not in one place. See abi/rad_runtime.h. */
* `moe_gemm_q`'s weight operands are tables (RAD_OPD_WTAB): the core resolves a run of declared
* weights to a device array of per-expert pointers, since after placement a layer's experts are
* not contiguous. See abi/rad_runtime.h. */
int r4d_rad_router_topk (const RadArgs*, RadStream);
int r4d_rad_moe_scatter (const RadArgs*, RadStream);
int r4d_rad_router_topk_scatter(const RadArgs*, RadStream);
int r4d_rad_router_topk_scatter_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
/* The router GEMM, the selection and the sort in one launch, the shared gate optionally beside
* them. init takes the instance's arrival counter (r4d_moe.hip, THE ARRIVAL COUNTER) and fini
* gives it back; a launch with no instance is refused. */
/* The router GEMM, selection and sort in one launch, optionally with the shared gate. init takes
* the instance's arrival counter (r4d_moe.hip, "the arrival counter") and fini returns it; a
* launch with no instance is refused. */
int r4d_rad_router_gemm_topk_scatter_init(const RadParam*, int, int rank, int world, void** out);
void r4d_rad_router_gemm_topk_scatter_fini(void*);
int r4d_rad_router_gemm_topk_scatter(const RadArgs*, RadStream);
int r4d_rad_router_gemm_topk_scatter_describe(const RadArgs*, RadStream, RadLaunchDesc*, int,
int*);
int64_t r4d_rad_moe_scatter_scratch(const RadArgs*);
int r4d_rad_moe_gemm_q (const RadArgs*, RadStream);
/* Scratch for the run map the prefill form is aligned by. Zero in the decode band and zero for a
* shape whose parameters do not describe one, so a caller that never asks still gets a correct
* uniform grid. */
/* Scratch for the run map that aligns the prefill form. Zero in the decode band and for a shape
* whose parameters do not describe one, so a caller that never asks still gets a correct uniform
* grid. */
int64_t r4d_rad_moe_gemm_q_scratch (const RadArgs*);
int64_t r4d_rad_moe_gemm_w4a8_scratch(const RadArgs*);
/* The same grouped GEMM with the expert weight at FOUR BITS: same operands, same schema, same
* inner loop -- only the LDS staging and the scale grid differ. See r4d_layout.cpp's moe w4
* section for the stored plane. */
/* The same grouped GEMM with a 4-bit expert weight: same operands, schema and inner loop; only the
* LDS staging and scale grid differ. See r4d_layout.cpp's moe w4 section for the stored plane. */
int r4d_rad_moe_gemm_w4a8 (const RadArgs*, RadStream);
int r4d_rad_moe_gemm_w4a8_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
/* `moe_gemm_q_mod4`: the same two kernels over four classes of experts, by the expert's number
* mod 4. The scratch hooks are the two-class ones. */
int r4d_rad_moe_gemm_q_mod4 (const RadArgs*, RadStream);
int r4d_rad_moe_gemm_w4a8_mod4 (const RadArgs*, RadStream);
int r4d_rad_moe_gemm_w4a8_mod4_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
/* `moe_gemm` at bf16: one weight table of the checkpoint's own row-major planes, no scales. The
* same grouping and the same three forms; its scratch hook sizes the same run map. */
/* `moe_gemm` at bf16: one weight table of the checkpoint's row-major planes, no scales. Same
* grouping and three forms; its scratch hook sizes the same run map. */
int r4d_rad_moe_gemm_bf16 (const RadArgs*, RadStream);
int r4d_rad_moe_gemm_bf16_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int64_t r4d_rad_moe_gemm_bf16_scratch(const RadArgs*);
int r4d_rad_moe_gather (const RadArgs*, RadStream);
int r4d_rad_scale_rows (const RadArgs*, RadStream);
@@ -363,83 +333,59 @@ int64_t r4d_rad_moe_gather_scratch (const RadArgs*);
/* -- quantisation, norms and the fusions (r4d_*quant*.hip, r4d_qk_norm_rope_gate.hip) -- */
int r4d_rad_quant_act_i8 (const RadArgs*, RadStream);
int r4d_rad_quant_act_i8_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int r4d_rad_qkv_norm_rope (const RadArgs*, RadStream);
int r4d_rad_qkv_norm_rope_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int r4d_rad_gelu_mul_quant_i8 (const RadArgs*, RadStream);
int r4d_rad_gelu_mul_quant_i8_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int r4d_rad_ar_rmsnorm_quant_i8 (const RadArgs*, RadStream);
int r4d_rad_rmsnorm_quant_i8 (const RadArgs*, RadStream);
int r4d_rad_rmsnorm_quant_i8_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int r4d_rad_had_quant_act_i8 (const RadArgs*, RadStream);
int r4d_rad_rmsnorm_had_quant_i8 (const RadArgs*, RadStream);
int r4d_rad_gated_had_quant_i8 (const RadArgs*, RadStream);
int r4d_rad_gdn_gated_norm_hq_i8 (const RadArgs*, RadStream);
int r4d_rad_qk_norm_rope_gate (const RadArgs*, RadStream);
int r4d_rad_qk_norm_rope_gate_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int r4d_rad_qk_norm_rope_gate_kv_store(const RadArgs*, RadStream);
int r4d_rad_qk_norm_rope_gate_kv_store_describe(const RadArgs*, RadStream, RadLaunchDesc*, int,
int*);
int r4d_rad_rope_table (const RadArgs*, RadStream);
int r4d_rad_rope_table_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
/* -- block-scaled fp8, and the device sampler (r4d_gemm_fp8*.hip / r4d_fp8_layout.cpp) --
*
* These entry points RETURN a negative code rather than throwing, unlike the rest of libr4d's GEMM
* family, so their shims carry no R4D_TRY. */
* These return a negative code instead of throwing, unlike the rest of libr4d's GEMMs, so their
* shims carry no R4D_TRY. */
int r4d_rad_gemm_fp8a16_m1 (const RadArgs*, RadStream);
int r4d_rad_gemm_fp8a8_m16 (const RadArgs*, RadStream);
int r4d_rad_gemm_fp8a8_m16_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int r4d_rad_gemm_fp8a8_gated_m16(const RadArgs*, RadStream);
int64_t r4d_rad_gemm_fp8a8_m16_scratch(const RadArgs*);
int r4d_rad_gemm_fp8a8_tiled(const RadArgs*, RadStream);
int r4d_rad_gemm_i8a8_m16 (const RadArgs*, RadStream);
int r4d_rad_gemm_i8a8_m16_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int64_t r4d_rad_gemm_i8a8_m16_scratch(const RadArgs*);
int r4d_rad_logits_gemm_i8(const RadArgs*, RadStream);
int r4d_rad_gemm_i8a8_tiled(const RadArgs*, RadStream);
int r4d_rad_quant_act_i8g(const RadArgs*, RadStream);
int r4d_rad_quant_act_i8g_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int r4d_rad_had_quant_act_i8g(const RadArgs*, RadStream);
int r4d_rad_had_quant_act_i8g_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int r4d_rad_quant_act_fp8 (const RadArgs*, RadStream);
int r4d_rad_quant_act_fp8_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int r4d_rad_had_quant_act_fp8 (const RadArgs*, RadStream);
int r4d_rad_had_quant_act_fp8_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int r4d_rad_givens_rotate (const RadArgs*, RadStream);
int r4d_rad_givens_rotate_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int r4d_rad_rmsnorm_quant_fp8(const RadArgs*, RadStream);
int r4d_rad_gated_quant_fp8 (const RadArgs*, RadStream);
int r4d_rad_gated_quant_fp8_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int r4d_rad_gated_had_quant_fp8(const RadArgs*, RadStream);
int r4d_rad_gated_had_quant_fp8_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int r4d_rad_gate_quant_fp8 (const RadArgs*, RadStream);
int r4d_rad_gate_quant_fp8_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int r4d_rad_gram_accum (const RadArgs*, RadStream);
/* The same accumulator over a plain bf16 activation, no scale operand. */
int r4d_rad_gram_accum_bf16 (const RadArgs*, RadStream);
int r4d_rad_qsa_block_key_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int r4d_rad_qsa_block_key (const RadArgs*, RadStream);
int r4d_rad_qsa_score_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int r4d_rad_qsa_score (const RadArgs*, RadStream);
int r4d_rad_qsa_select_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int r4d_rad_qsa_select (const RadArgs*, RadStream);
int64_t r4d_rad_qsa_select_scratch(const RadArgs*);
int r4d_rad_qsa_tail_store_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int r4d_rad_qsa_tail_store (const RadArgs*, RadStream);
int r4d_rad_qsa_work_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int r4d_rad_qsa_work (const RadArgs*, RadStream);
int r4d_rad_sample_chain (const RadArgs*, RadStream);
int r4d_rad_logits_gemm_fp8 (const RadArgs*, RadStream);
/* -- what each weight-reading kernel stores, from a weight's canonical planes --
*
* RadLayoutFn / RadRelayoutFn / RadUnrelayoutFn (rad_abi.h, spec §4.3). r4d_fp8_layout.cpp holds the
* fp8 families -- block-fp8 codes in fragment order, the lm_head and the hyper-connection and MTP
* rows with their scales in each row's tail -- and r4d_layout.cpp the packed integer ones. Each
* refuses an encoding its kernel does not read. A family whose kernel reads the canonical plane as
* it is -- the row-major fp8 matvec, the fp8 experts -- has only the layout hook, to check what it
* is handed. */
* RadLayoutFn / RadRelayoutFn / RadUnrelayoutFn (rad_abi.h, spec §4.3). r4d_fp8_layout.cpp holds
* the fp8 families (block-fp8 codes in fragment order; the lm_head, hyper-connection and MTP rows
* with scales in each row's tail), r4d_layout.cpp the packed integer ones. Each refuses an
* encoding its kernel does not read. A family whose kernel reads the canonical plane unchanged
* (the row-major fp8 matvec, the fp8 experts) has only the layout hook, to check its input. */
#define R4D_HOOKS(name) \
int r4d_rad_layout_##name(const RadParam*, int, int, const RadEncoding*, const int*, \
const RadTensor*, int, RadLayout*); \
@@ -505,31 +451,21 @@ int r4d_rad_unrelayout_givens_pairs(const RadParam*, int, int, const RadEncoding
/* -- the small bf16 model ops (r4d_model_bf16.hip) --
*
* The embedding gather, the norm, the adds, the rotary and the KV scatter. Uninteresting kernels
* that the engine cannot run without: its buffers are in VRAM and an op with no DEVICE launch is a
* fatal issue, not a slow one. `logits_gemm` is declared with them. */
* The embedding gather, norm, adds, rotary and KV scatter. Required because the buffers are in
* VRAM and an op with no device launch is a fatal issue. `logits_gemm` is declared with them. */
int r4d_rad_embed_lookup (const RadArgs*, RadStream);
int r4d_rad_embed_lookup_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
/* The quantised gather (embed_lookup_q): the n-gram table's, where a card reads the table -- in
* VRAM, or in pinned host memory over the link. */
/* The quantised gather (embed_lookup_q) for the n-gram table, read from VRAM or from pinned host
* memory over the link. */
int r4d_rad_embed_lookup_q (const RadArgs*, RadStream);
int r4d_rad_embed_lookup_q_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int r4d_rad_ngram_ids (const RadArgs*, RadStream);
/* ABI v10: the same dispatch, described. Generated with the launch above by R4D_ENTRY, from one
* body, so the two cannot describe different work. */
int r4d_rad_ngram_ids_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int r4d_rad_ple_gate (const RadArgs*, RadStream);
int r4d_rad_ple_conv (const RadArgs*, RadStream);
int r4d_rad_causal_conv1d (const RadArgs*, RadStream);
int r4d_rad_cast (const RadArgs*, RadStream);
int r4d_rad_gather_rows (const RadArgs*, RadStream);
int r4d_rad_gather_rows_u8 (const RadArgs*, RadStream);
int r4d_rad_gather_rows_u8_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int r4d_rad_scatter_rows_u8 (const RadArgs*, RadStream);
int r4d_rad_scatter_rows_u8_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int r4d_rad_scatter_rows_bf16(const RadArgs*, RadStream);
int r4d_rad_scatter_rows_bf16_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int r4d_rad_gather_rows_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int r4d_rad_rmsnorm (const RadArgs*, RadStream);
int r4d_rad_rmsnorm_p (const RadArgs*, RadStream);
int r4d_rad_add (const RadArgs*, RadStream);
@@ -546,6 +482,7 @@ int r4d_rad_clamp (const RadArgs*, RadStream);
int r4d_rad_conv2d (const RadArgs*, RadStream);
int r4d_rad_conv1d_dw (const RadArgs*, RadStream);
int r4d_rad_rel_sinusoid (const RadArgs*, RadStream);
int r4d_rad_conv2d_unfold (const RadArgs*, RadStream);
int r4d_rad_attn_local_rel (const RadArgs*, RadStream);
int r4d_rad_sigmoid (const RadArgs*, RadStream);
int r4d_rad_fill (const RadArgs*, RadStream);
@@ -556,23 +493,18 @@ int r4d_rad_gelu_mul (const RadArgs*, RadStream);
int r4d_rad_rope (const RadArgs*, RadStream);
/* -- the vision tower's ops (r4d_vit_bf16.hip) -- */
int r4d_rad_layernorm (const RadArgs*, RadStream);
int r4d_rad_layernorm_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int r4d_rad_grid_embed (const RadArgs*, RadStream);
int r4d_rad_grid_embed_aa (const RadArgs*, RadStream);
int r4d_rad_grid_embed_aa_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int r4d_rad_grid_embed_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int r4d_rad_gemm_nt_bias (const RadArgs*, RadStream);
int r4d_rad_gemm_nt_bias_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int r4d_rad_kv_store (const RadArgs*, RadStream);
int r4d_rad_kv_store_fp8 (const RadArgs*, RadStream);
int r4d_rad_kv_store_fp8_describe(const RadArgs*, RadStream, RadLaunchDesc*, int, int*);
int r4d_rad_logits_gemm (const RadArgs*, RadStream);
/* -- the decomposed sampler chain (r4d_sample_stages_f32.hip) --
*
* docs/OPS.md's eleven ops, as opposed to r4d_rad_sample_chain's fused form above. Both stay: the
* fused one is what a speculative verify wants, these are what an engine that composes the chain
* per request needs, and they carry the stages the fused one has no room for. */
* docs/OPS.md's eleven ops, beside r4d_rad_sample_chain's fused form. The fused one suits a
* speculative verify; these let an engine compose the chain per request and carry the stages the
* fused one lacks. */
int r4d_rad_sample_penalties (const RadArgs*, RadStream);
int r4d_rad_sample_dry (const RadArgs*, RadStream);
int r4d_rad_sample_temp (const RadArgs*, RadStream);
@@ -589,15 +521,14 @@ int r4d_rad_sample_merge_topk(const RadArgs*, RadStream);
/* -- operand descriptions (r4d_shapes.cpp, pure host) --
*
* `RadKernelInfo::opd_shape`: how big is operand i of this op at this geometry, and what may be in
* it. One function per OP and not per row, because the description is a property of the operand
* list and not of the tiling: all six `attn_paged` rows take one function and read the cache's
* width off `kv_dtype`. Where two rows of one op genuinely differ, they take different functions
* -- or the one that cannot be described carries a NULL and is skipped by name, which is what
* `logits_gemm`'s fp8 row does. r4d_shapes.cpp's header lists every decline and its reason.
* `RadKernelInfo::opd_shape`: the size and allowed contents of operand i of this op at this
* geometry. One function per op, not per row, because the description belongs to the operand list,
* not the tiling: all six `attn_paged` rows share one and read the cache width off `kv_dtype`.
* Where rows genuinely differ they take different functions, or carry NULL and are skipped by name
* (`logits_gemm`'s fp8 row). r4d_shapes.cpp's header lists every decline and its reason.
*
* Pure host code, called before anything is allocated, so it includes neither r4d.h nor
* <hip/hip_runtime.h> -- the same split r4d_rows.cpp and r4d_layout.cpp keep. */
* Pure host code called before allocation, so like r4d_rows.cpp and r4d_layout.cpp it includes
* neither r4d.h nor <hip/hip_runtime.h>. */
int r4d_shape_embed_lookup (const RadParam*, int, int operand, RadOpdDesc*);
int r4d_shape_embed_lookup_q (const RadParam*, int, int operand, RadOpdDesc*);
int r4d_shape_gather_rows (const RadParam*, int, int operand, RadOpdDesc*);
@@ -686,20 +617,17 @@ int r4d_shape_dflash_select (const RadParam*, int, int operand, RadOpdDesc*);
/* -- declared fusions (r4d_fuse.cpp, pure host) --
*
* `RadKernelInfo::replaces`: the chain of conventional ops this kernel computes in one launch, so
* that a tool may run the chain out of this plugin's OWN unfused rows and compare the bytes. One
* function per FUSED ROW and not per op, unlike the shape hooks: two rows of one op could fold
* different things, and the chain is a claim about a kernel rather than about an operand list.
* `RadKernelInfo::replaces`: the chain of conventional ops this kernel computes in one launch, so a
* tool can run the chain on this plugin's own unfused rows and compare bytes. One function per
* fused row, not per op: two rows of one op could fold different things.
*
* FIVE ROWS DECLARE ONE AND THE REST DELIBERATELY DO NOT. r4d_fuse.cpp's header lists every
* decline with the line of libr4d that decides it -- the int8 rotated family runs its Hadamard
* before the norm closes and keeps the product in f32, so `silu_mul` + `had_quant_act_i8` is a
* different function however it is spelled, and `ar_ln_had_quant_i8` reduces without the bf16
* round its unfused pair stores. A chain that is merely close publishes no hook, because a false
* failure is worse than a skip.
* Only some rows declare one. r4d_fuse.cpp's header lists each decline with the libr4d line that
* decides it: the int8 rotated family runs its Hadamard before the norm closes and keeps the
* product in f32, so `silu_mul` + `had_quant_act_i8` is a different function, and
* `ar_ln_had_quant_i8` reduces without the bf16 round its unfused pair stores. A chain that is only
* close publishes no hook, because a false failure is worse than a skip.
*
* Pure host code, called before anything is allocated, so it includes neither r4d.h nor
* <hip/hip_runtime.h> -- the same split r4d_rows.cpp, r4d_layout.cpp and r4d_shapes.cpp keep. */
* Pure host code, like r4d_rows.cpp, r4d_layout.cpp and r4d_shapes.cpp. */
int r4d_fuse_rmsnorm_quant_fp8 (const RadParam*, int, uint64_t, int, RadFuseStep*);
int r4d_fuse_gated_quant_fp8 (const RadParam*, int, uint64_t, int, RadFuseStep*);
int r4d_fuse_gate_quant_fp8 (const RadParam*, int, uint64_t, int, RadFuseStep*);