libr4d: the gdn conv kernels read an f32 weight -- a GGUF ships ssm_conv1d in f32

llama.cpp keeps a Gated DeltaNet's ssm_conv1d unquantised, in f32, and a container converted from
a GGUF holds it so. The three kernels that read the convolution weight, gdn_conv_prep,
gdn_conv_update and the convolution gdn_conv_recurrent_update folds in, read bf16, so their shims
refuse an f32 weight. The weight's element type is now a template parameter of all three.
r4d_gdn_conv_tap.h, which already holds the arithmetic the fold shares with the standalone path,
gives the vector a channel's taps are loaded as (ushort4 or float4) and the widening of one tap,
exact for either type. The shims take a bf16 or an f32 weight and pick the instance by its dtype;
any other dtype is still refused.

The raw entry points keep their signatures. r4d.h gets an f32 twin of each standalone one,
r4d_gdn_conv_prep_w4_h128_bf16_f32wgt and r4d_gdn_conv_update_w4_h128_bf16_f32wgt, rather than a
flag, so no caller of the bf16 ones changes. The fold has no raw entry point; its CV parameter now
also says the weight's type (1 bf16, 2 f32), which leaves every existing instance's template
arguments and name as they were. That is twelve new conv instances and sixteen new fold ones.

The bf16 instances compile to the same code. Built before and after with the build's flags, all
116 kernels of the two units have the same instructions, resource counts and metadata; only the
conv kernels' names change with the added template argument. The bf16 reads keep their shape:
widening gdn_conv_update's ushort4 to a float4 before use reorders its loads. The f32 conv
instances use no scratch, conv_prep 56 to 57 VGPRs (53 at bf16) and conv_update 108 (96 at bf16,
12 waves per SIMD instead of 16); each f32 fold instance has exactly its bf16 twin's counts.

r4d_selftest gets three cases for the card. gdn_conv_prep and gdn_conv_update over an f32 weight
holding bf16's values must write the bytes they write over the bf16 weight: q, k and v, g and beta
at prefill, and the conv state. The sequences are uneven; at prefill two are seeded from their
cache, one of them over two chunks, and a one-token one is not. Outputs are poisoned, the cache
must move and an f16 weight must be refused. The fold over the f32 weight must match the pair
over the bf16 one, byte for byte as the fold already does at bf16.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
NunzeandClaude Opus 5.5 authored and StillDeadcode committed 2026-10-28 12:49:37 +01:00
1 parent d73abc28d5
commit 64c3dc9893
8 files changed
+323 -52

No files matched your search

+16
View File
@@ -220,6 +220,16 @@ int r4d_gdn_conv_prep_w4_h128_bf16(
const void* A_log, const void* dt_bias, void* q, void* k, void* v, void* g, void* beta,
const void* cu, int N, int T, int H, int Hg, int K, int V, int width, float softplus_thr,
void* stream);
// The same with an f32 `wgt`, as a GGUF stores ssm_conv1d. Every other operand is as above, and
// a bf16-representable weight gives the same bytes.
int r4d_gdn_conv_prep_w4_h128_bf16_f32wgt(
const void* x, long xpitch, const void* wgt, const void* bias, void* cstate,
long cs_seq, long cs_dim, long cs_tok, const void* cache_idx, long ci_stride,
const void* has_init, int hi_i32,
const void* a, const void* b, long ab_stride, int ab_is_bf16,
const void* A_log, const void* dt_bias, void* q, void* k, void* v, void* g, void* beta,
const void* cu, int N, int T, int H, int Hg, int K, int V, int width, float softplus_thr,
void* stream);
// The same convolution for a decode step over a speculative window. The state cache is a rolling
// buffer of width-1 + num_spec entries read at the slot the last accepted token left; q / k / v
@@ -229,6 +239,12 @@ int r4d_gdn_conv_update_w4_h128_bf16(
long cs_seq, long cs_dim, long cs_tok, int state_len_max, const void* cache_idx,
long ci_stride, const void* num_accepted, void* q, void* k, void* v, const void* cu,
int N, int H, int Hg, int K, int V, int width, int max_query_len, void* stream);
// The same with an f32 `wgt`, as for the prefill convolution.
int r4d_gdn_conv_update_w4_h128_bf16_f32wgt(
const void* x, long xpitch, const void* wgt, const void* bias, void* cstate,
long cs_seq, long cs_dim, long cs_tok, int state_len_max, const void* cache_idx,
long ci_stride, const void* num_accepted, void* q, void* k, void* v, const void* cu,
int N, int H, int Hg, int K, int V, int width, int max_query_len, void* stream);
// The gated RMS norm on the layer's output: out = rms(x) . w . act(z), one row per (token, head).
// Replaces FLA's rmsnorm_fn. act: 0 = silu/swish, 1 = sigmoid. Prefill only; the decode kernel