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

+2 -2
View File
@@ -31,10 +31,10 @@ The table lists a selection; `r4d_rows.cpp` and `r4d.h` hold the full set.
| `attn_decode_h256_gqa6_fp8kv` / `..._bf16kv` | the same geometry, split-KV, `q_len * gqa` ≤ 64 |
| `attn_decode_h256_gqa6_scratch_bytes` / `attn_decode_h128_gqa4_scratch_bytes` | bytes of split-KV scratch a launch needs; ask before allocating, since the split count is chosen from the geometry |
| `attn_vit_h72_bf16` | dense non-causal vision-encoder attention, head_dim 72 native, varlen over images |
| `gdn_conv_prep_w4_h128_bf16` | the GDN prefill preamble in one kernel: causal conv (width 4, silu, with its state cache), q/k/v split, qk l2norm, gating and the per-chunk gate cumsum |
| `gdn_conv_prep_w4_h128_bf16` / `..._f32wgt` | the GDN prefill preamble in one kernel: causal conv (width 4, silu, with its state cache), q/k/v split, qk l2norm, gating and the per-chunk gate cumsum |
| `gdn_kkt_solve_k128_c64_bf16` | `A = (I + strict_lower(diag(beta) K K^T e^dg))^-1` per chunk of 64: the gram and its triangular inverse, without the fp32 gram reaching memory |
| `gdn_chunk_scan_k128_v128_c64_bf16` | gated-delta-net chunked scan: WY recompute, state recurrence and output in one kernel; head_k 128, head_v 128, chunk 64 |
| `gdn_conv_update_w4_h128_bf16` | the same convolution for a decode step: a rolling speculative window over the conv state cache, writing q/k/v directly |
| `gdn_conv_update_w4_h128_bf16` / `..._f32wgt` | the same convolution for a decode step: a rolling speculative window over the conv state cache, writing q/k/v directly |
| `gdn_recurrent_update_k128_v128_bf16_fp32state` | the decode-time recurrent delta-rule update against the paged fp32 state cache, gating and qk l2norm included |
| `gdn_gated_rmsnorm_h128_bf16` | gated RMS norm over a 128-channel row, `out = rms(x) . w . act(z)` |
| `ar_oneshot_2rank_exact` | one-shot push all-reduce over P2P, exactly 2 ranks, exact bf16/fp16/fp32 |
+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
+1 -1
View File
@@ -10,7 +10,7 @@
/* Every `const void*` libr4d takes has one element type, cast inside the kernel (e.g.
* r4d_gdn_conv_prep_w4_h128_bf16 reads `wgt` as bf16 and `A_log` as f32); the signature does not
* say so. A plugin declaring `ssm_conv1d.weight` or the `gdn_kkt` buffer as f32 would be read as
* say so. A plugin declaring the `gdn_kkt` buffer as f32 would be read as
* bf16 on the device, while libref (which honours each operand's dtype) stays correct, so the bug
* would show only on the device path. The shim therefore checks dtypes by name (spec §2.1). */
static inline int r4d_dt(const RadTensor* t, uint32_t want) {
+13
View File
@@ -4,9 +4,22 @@
// A single definition keeps the fold byte-identical to the standalone path: the reciprocal form
// below changes the last bit of some bf16 outputs.
#pragma once
#include "r4d_gdn_wmma.h"
#define R4D_GDN_CONV_W 4 // conv width; the state holds R4D_GDN_CONV_W - 1 taps of history
// The weight is bf16 from a checkpoint and f32 from a GGUF, which keeps ssm_conv1d unquantised.
// cp_taps is a channel's taps as one vector load; cp_tap widens one tap to f32, exactly for
// either type.
template <typename WT> struct cp_vec4;
template <> struct cp_vec4<unsigned short> { using T = ushort4; };
template <> struct cp_vec4<float> { using T = float4; };
template <typename WT> using cp_taps = typename cp_vec4<WT>::T;
static_assert(R4D_GDN_CONV_W == 4, "cp_taps holds a channel's taps in one four-wide vector");
__device__ __forceinline__ float cp_tap(unsigned short w) { return bf2f(w); }
__device__ __forceinline__ float cp_tap(float w) { return w; }
// The result is rounded to bf16 immediately, so an IEEE-exact divide buys nothing: v_rcp_f32 is
// 1 ULP (~1e-7 relative) against bf16's 2^-8 quantum. The exact form is ~10 dependent instructions
// (v_div_scale, v_rcp, Newton, v_div_fmas, v_div_fixup); this is two. The conv update runs four
+80 -22
View File
@@ -72,10 +72,10 @@ __device__ __forceinline__ bool r4d_has_init(const void* p, int i32, int n) {
return i32 ? ((const int*)p)[n] != 0 : ((const unsigned char*)p)[n] != 0;
}
template <int HPB, int ABF16>
template <int HPB, int ABF16, typename WT>
__global__ __launch_bounds__(HPB * 32)
void r4d_gdn_conv_prep_kernel(const unsigned short* __restrict__ x, long xpitch,
const unsigned short* __restrict__ wgt,
const WT* __restrict__ wgt,
const unsigned short* __restrict__ bias,
unsigned short* __restrict__ cstate,
long cs_seq, long cs_dim, long cs_tok,
@@ -150,7 +150,7 @@ void r4d_gdn_conv_prep_kernel(const unsigned short* __restrict__ x, long xpitch,
#pragma unroll
for (int c = 0; c < CP_DPL; ++c) {
#pragma unroll
for (int i = 0; i < CP_W; ++i) wt[i][c] = bf2f(wgt[(size_t)(d0 + c) * CP_W + i]);
for (int i = 0; i < CP_W; ++i) wt[i][c] = cp_tap(wgt[(size_t)(d0 + c) * CP_W + i]);
bs[c] = bias ? bf2f(bias[d0 + c]) : 0.0f;
}
@@ -241,7 +241,8 @@ void r4d_gdn_conv_prep_kernel(const unsigned short* __restrict__ x, long xpitch,
}
}
extern "C" int r4d_gdn_conv_prep_w4_h128_bf16(
template <typename WT>
static int cp_prep_launch(
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,
@@ -256,8 +257,8 @@ extern "C" int r4d_gdn_conv_prep_w4_h128_bf16(
const int nchunk_ub = (T + CP_BT - 1) / CP_BT + N;
dim3 grid(nchunk_ub, units / hpb), blk(hpb * 32);
#define CP_LAUNCH(P, AB) \
hipLaunchKernelGGL((r4d_gdn_conv_prep_kernel<P, AB>), grid, blk, 0, (hipStream_t)stream, \
(const unsigned short*)x, xpitch, (const unsigned short*)wgt, \
hipLaunchKernelGGL((r4d_gdn_conv_prep_kernel<P, AB, WT>), grid, blk, 0, (hipStream_t)stream, \
(const unsigned short*)x, xpitch, (const WT*)wgt, \
(const unsigned short*)bias, (unsigned short*)cstate, \
cs_seq, cs_dim, cs_tok, (const int*)cache_idx, ci_stride, \
has_init, hi_i32, a, b, ab_stride, \
@@ -277,16 +278,44 @@ extern "C" int r4d_gdn_conv_prep_w4_h128_bf16(
return (int)hipGetLastError();
}
extern "C" int r4d_gdn_conv_prep_w4_h128_bf16(
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)
{
return cp_prep_launch<unsigned short>(x, xpitch, wgt, bias, cstate, cs_seq, cs_dim, cs_tok,
cache_idx, ci_stride, has_init, hi_i32, a, b, ab_stride,
ab_is_bf16, A_log, dt_bias, q, k, v, g, beta, cu, N, T, H,
Hg, K, V, width, softplus_thr, stream);
}
extern "C" 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)
{
return cp_prep_launch<float>(x, xpitch, wgt, bias, cstate, cs_seq, cs_dim, cs_tok, cache_idx,
ci_stride, has_init, hi_i32, a, b, ab_stride, ab_is_bf16, A_log,
dt_bias, q, k, v, g, beta, cu, N, T, H, Hg, K, V, width,
softplus_thr, stream);
}
// ---------------------------------------------------------------------------------------------
// Decode-time convolution. Same filter, but a step's tokens are a speculative window and the
// state cache is a rolling buffer of width-1 + num_spec entries: a step reads its window starting
// at the slot the last accepted token left, and rewrites the buffer shifted by one. Writes q, k
// and v in their own layouts (no torch.cat for the recurrent kernel).
// ---------------------------------------------------------------------------------------------
template <int HPB>
template <int HPB, typename WT>
__global__ __launch_bounds__(HPB * 32)
void r4d_gdn_conv_update_kernel(const unsigned short* __restrict__ x, long xpitch,
const unsigned short* __restrict__ wgt,
const WT* __restrict__ wgt,
const unsigned short* __restrict__ bias,
unsigned short* __restrict__ cstate,
long cs_seq, long cs_dim, long cs_tok, int state_len_max,
@@ -312,15 +341,14 @@ void r4d_gdn_conv_update_kernel(const unsigned short* __restrict__ x, long xpitc
const int unit = blockIdx.y * HPB + warp;
const int d0 = unit * CP_HD + lane * CP_DPL;
// A channel's weights are CP_W contiguous shorts: one vector load per channel.
static_assert(CP_W == 4, "the weight load reads a channel's taps as one ushort4");
// A channel's weights are CP_W contiguous elements: one vector load per channel.
float wt[CP_W][CP_DPL], bs[CP_DPL];
#pragma unroll
for (int c = 0; c < CP_DPL; ++c) {
const ushort4 w4 = *(const ushort4*)(wgt + (size_t)(d0 + c) * CP_W);
const unsigned short* ws = (const unsigned short*)&w4;
const cp_taps<WT> w4 = *(const cp_taps<WT>*)(wgt + (size_t)(d0 + c) * CP_W);
const WT* ws = (const WT*)&w4;
#pragma unroll
for (int i = 0; i < CP_W; ++i) wt[i][c] = bf2f(ws[i]);
for (int i = 0; i < CP_W; ++i) wt[i][c] = cp_tap(ws[i]);
bs[c] = bias ? bf2f(bias[d0 + c]) : 0.0f;
}
@@ -428,7 +456,8 @@ void r4d_gdn_conv_update_kernel(const unsigned short* __restrict__ x, long xpitc
#undef CU_TOKEN_BODY
}
extern "C" int r4d_gdn_conv_update_w4_h128_bf16(
template <typename WT>
static int cu_update_launch(
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,
@@ -443,8 +472,8 @@ extern "C" int r4d_gdn_conv_update_w4_h128_bf16(
while (hpb > 1 && (long)N * (units / hpb) < 256) hpb >>= 1;
dim3 grid(N, units / hpb), blk(hpb * 32);
#define CU_LAUNCH(P) \
hipLaunchKernelGGL((r4d_gdn_conv_update_kernel<P>), grid, blk, 0, (hipStream_t)stream, \
(const unsigned short*)x, xpitch, (const unsigned short*)wgt, \
hipLaunchKernelGGL((r4d_gdn_conv_update_kernel<P, WT>), grid, blk, 0, (hipStream_t)stream, \
(const unsigned short*)x, xpitch, (const WT*)wgt, \
(const unsigned short*)bias, (unsigned short*)cstate, cs_seq, cs_dim, \
cs_tok, state_len_max, (const int*)cache_idx, ci_stride, \
(const int*)num_accepted, (unsigned short*)q, (unsigned short*)k, \
@@ -459,6 +488,28 @@ extern "C" int r4d_gdn_conv_update_w4_h128_bf16(
return (int)hipGetLastError();
}
extern "C" int r4d_gdn_conv_update_w4_h128_bf16(
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)
{
return cu_update_launch<unsigned short>(x, xpitch, wgt, bias, cstate, cs_seq, cs_dim, cs_tok,
state_len_max, cache_idx, ci_stride, num_accepted, q,
k, v, cu, N, H, Hg, K, V, width, max_query_len, stream);
}
extern "C" 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)
{
return cu_update_launch<float>(x, xpitch, wgt, bias, cstate, cs_seq, cs_dim, cs_tok,
state_len_max, cache_idx, ci_stride, num_accepted, q, k, v, cu,
N, H, Hg, K, V, width, max_query_len, stream);
}
// ============================================================== the plugin ABI entry points
// Shared operand helpers: r4d_gdn_args.h. Operand enums use an OPD_ prefix because CP_W and CP_ST
// are already kernel constants in this unit.
@@ -535,12 +586,16 @@ extern "C" int r4d_rad_gdn_conv_prep(const RadArgs* a, RadStream s) {
if (tb->dtype != ta->dtype) return R4D_NO(RAD_E_DTYPE);
if (!ab_is_bf16 && ta->dtype != RAD_F32) return R4D_NO(RAD_E_DTYPE);
/* bf16 x, weights, conv state and q/k/v; fp32 A_log, dt_bias, g and beta. */
R4D_DT(x, RAD_BF16); R4D_DT(w, RAD_BF16); R4D_DT(cst, RAD_BF16);
/* bf16 x, conv state and q/k/v; bf16 or f32 weights (r4d_gdn_conv_tap.h); fp32 A_log,
* dt_bias, g and beta. */
R4D_DT(x, RAD_BF16); R4D_DT(cst, RAD_BF16);
R4D_DT(q, RAD_BF16); R4D_DT(k, RAD_BF16); R4D_DT(v, RAD_BF16);
R4D_DT(alog, RAD_F32); R4D_DT(dtb, RAD_F32); R4D_DT(g, RAD_F32); R4D_DT(beta, RAD_F32);
if (w->dtype != RAD_BF16 && w->dtype != RAD_F32) return R4D_NO(RAD_E_DTYPE);
const auto prep = w->dtype == RAD_F32 ? r4d_gdn_conv_prep_w4_h128_bf16_f32wgt
: r4d_gdn_conv_prep_w4_h128_bf16;
return R4D_RAW(r4d_gdn_conv_prep_w4_h128_bf16(
return R4D_RAW(prep(
x->data, (long)xpitch, w->data, b ? b->data : nullptr, cst->data,
(long)cst->stride[0], (long)cst->stride[1], (long)cst->stride[2],
cidx->data, (long)cidx->stride[0], hin ? hin->data : nullptr,
@@ -588,9 +643,12 @@ extern "C" int r4d_rad_gdn_conv_update(const RadArgs* a, RadStream s) {
if (H == 0 || Hg == 0 || H % Hg) return R4D_NO(RAD_E_SHAPE);
if (v->shape[0] != T || k->shape[0] != T) return R4D_NO(RAD_E_SHAPE);
/* bf16 x, weights, conv state and q/k/v, as in the prefill conv. */
R4D_DT(x, RAD_BF16); R4D_DT(w, RAD_BF16); R4D_DT(cst, RAD_BF16);
/* bf16 x, conv state and q/k/v, bf16 or f32 weights, as in the prefill conv. */
R4D_DT(x, RAD_BF16); R4D_DT(cst, RAD_BF16);
R4D_DT(q, RAD_BF16); R4D_DT(k, RAD_BF16); R4D_DT(v, RAD_BF16);
if (w->dtype != RAD_BF16 && w->dtype != RAD_F32) return R4D_NO(RAD_E_DTYPE);
const auto update = w->dtype == RAD_F32 ? r4d_gdn_conv_update_w4_h128_bf16_f32wgt
: r4d_gdn_conv_update_w4_h128_bf16;
const int width = (int)r4d_geti_or(a, "conv_width", 4);
/* state_len_max and max_query_len describe one window, so only one is free. The state cache
@@ -606,7 +664,7 @@ extern "C" int r4d_rad_gdn_conv_update(const RadArgs* a, RadStream s) {
const long long mql = state_len_max - (width - 2);
if (width < 2 || mql < 1) return R4D_NO(RAD_E_SHAPE);
return R4D_RAW(r4d_gdn_conv_update_w4_h128_bf16(
return R4D_RAW(update(
x->data, (long)xpitch, w->data, b ? b->data : nullptr, cst->data,
(long)cst->stride[0], (long)cst->stride[1], (long)cst->stride[2],
(int)state_len_max, sidx->data, (long)sidx->stride[0],
@@ -37,6 +37,7 @@
#include <cstring>
#include <map>
#include <mutex>
#include <type_traits>
#include <utility>
#define RU_K 128 // head_k
@@ -187,9 +188,11 @@ __device__ __forceinline__ float ru_act(float z, int kind) {
// channels and resets the counter (no waiting). A value head's v channels have one reader and are
// rewritten by it. Two launches sharing a counter block must not overlap; blocks are keyed on
// (stream, output), as split_ctr in r4d_gemm_fp8a8.hip.
//
// CV is also the weight's type: 1 bf16, 2 f32, read as gdn_conv_update reads it.
struct RuConv {
const unsigned short* x; long xpitch; // the projection's [q | k | v] columns, row pitch
const unsigned short* w; // [conv_dim, R4D_GDN_CONV_W]
const void* w; // [conv_dim, R4D_GDN_CONV_W], bf16 or f32 (CV)
const unsigned short* b; // [conv_dim] or null
unsigned short* cs; // the conv state cache
long cs_seq, cs_dim, cs_tok;
@@ -293,13 +296,15 @@ void r4d_gdn_recurrent_update_kernel(const unsigned short* __restrict__ q,
const int off = naccept ? naccept[n] - 1 : 0;
const int ca = tid < RU_K ? hk * RU_K + tid : (Hg + hk) * RU_K + (tid - RU_K);
const int cb = (2 * Hg + hv) * RU_V + tid;
using CWT = std::conditional_t<CV == 2, float, unsigned short>;
const CWT* const cw = (const CWT*)cv.w;
const unsigned short* xr = cv.x + (size_t)bos * cv.xpitch;
#pragma unroll
for (int t = 0; t < RU_CVT; ++t)
if (t < T) cxa[t] = xr[(size_t)t * cv.xpitch + ca];
{
const ushort4 w4 = *(const ushort4*)(cv.w + (size_t)ca * CW);
cwa[0] = bf2f(w4.x); cwa[1] = bf2f(w4.y); cwa[2] = bf2f(w4.z); cwa[3] = bf2f(w4.w);
const cp_taps<CWT> w4 = *(const cp_taps<CWT>*)(cw + (size_t)ca * CW);
cwa[0] = cp_tap(w4.x); cwa[1] = cp_tap(w4.y); cwa[2] = cp_tap(w4.z); cwa[3] = cp_tap(w4.w);
if (cv.b) cba = bf2f(cv.b[ca]);
}
spa = cv.cs + (size_t)cslot * cv.cs_seq + (size_t)ca * cv.cs_dim;
@@ -309,8 +314,8 @@ void r4d_gdn_recurrent_update_kernel(const unsigned short* __restrict__ q,
#pragma unroll
for (int t = 0; t < RU_CVT; ++t)
if (t < T) cxb[t] = xr[(size_t)t * cv.xpitch + cb];
const ushort4 w4 = *(const ushort4*)(cv.w + (size_t)cb * CW);
cwb[0] = bf2f(w4.x); cwb[1] = bf2f(w4.y); cwb[2] = bf2f(w4.z); cwb[3] = bf2f(w4.w);
const cp_taps<CWT> w4 = *(const cp_taps<CWT>*)(cw + (size_t)cb * CW);
cwb[0] = cp_tap(w4.x); cwb[1] = cp_tap(w4.y); cwb[2] = cp_tap(w4.z); cwb[3] = cp_tap(w4.w);
if (cv.b) cbb = bf2f(cv.b[cb]);
spb = cv.cs + (size_t)cslot * cv.cs_seq + (size_t)cb * cv.cs_dim;
#pragma unroll
@@ -864,7 +869,7 @@ static unsigned int* ru_conv_ctr(RadStream s, const void* out) {
// The recurrent update with gdn_conv_update folded in, decode shape only (bf16 a/b, fused row
// norm, one workgroup per (sequence, value head)). State contract, non-temporal choice and
// factor-block bounds are as in ru_update_launch.
// factor-block bounds are as in ru_update_launch. `w_f32` is the conv weight's type.
static int ru_conv_recurrent_launch(const RuConv& cv, const void* a, const void* b, long ab_stride,
const void* A_log, const void* dt_bias, void* state,
long st_slot, long st_head, void* o, void* oq, void* os,
@@ -872,7 +877,7 @@ static int ru_conv_recurrent_launch(const RuConv& cv, const void* a, const void*
long sidx_stride, const void* nacc, const void* z,
long z_pitch, const void* nw, float neps, int nact, int N,
int H, int Hg, float scale, float thr, int state_fp16,
RadStream stream, int oq_i8, bool anc) {
RadStream stream, int oq_i8, bool anc, bool w_f32) {
if (anc && sidx_stride < 6) return RAD_E_SHAPE;
if (anc && sidx_stride * RU_FSTR > st_head) return RAD_E_SHAPE;
const int sdt = state_fp16 ? 1 : 0;
@@ -880,11 +885,11 @@ static int ru_conv_recurrent_launch(const RuConv& cv, const void* a, const void*
const long flood = (long)N * slots_written * st_slot * (sdt ? 2 : 4);
const bool nt = flood <= (long)RU_NT_MB * 1024 * 1024;
const dim3 grid(N, H, 1), blk(RU_V * 2);
#define RC_LAUNCH(NTC, ANCC, SDTC) \
do { if (oq_i8) RC_LAUNCH_NM(2, NTC, ANCC, SDTC); else RC_LAUNCH_NM(1, NTC, ANCC, SDTC); } \
while (0)
#define RC_LAUNCH_NM(NM, NTC, ANCC, SDTC) \
hipLaunchKernelGGL((r4d_gdn_recurrent_update_kernel<1, NM, 1, NTC, ANCC, 0, SDTC, 1>), \
#define RC_LAUNCH(NTC, ANCC, SDTC, CVC) \
do { if (oq_i8) RC_LAUNCH_NM(2, NTC, ANCC, SDTC, CVC); \
else RC_LAUNCH_NM(1, NTC, ANCC, SDTC, CVC); } while (0)
#define RC_LAUNCH_NM(NM, NTC, ANCC, SDTC, CVC) \
hipLaunchKernelGGL((r4d_gdn_recurrent_update_kernel<1, NM, 1, NTC, ANCC, 0, SDTC, CVC>), \
grid, blk, 0, (hipStream_t)stream, nullptr, nullptr, nullptr, a, b, \
ab_stride, (const float*)A_log, (const float*)dt_bias, \
(ru_state<SDTC>::T*)state, st_slot, st_head, (unsigned short*)o, \
@@ -892,11 +897,14 @@ static int ru_conv_recurrent_launch(const RuConv& cv, const void* a, const void*
(const int*)sidx, sidx_stride, (const int*)nacc, \
(const unsigned short*)z, z_pitch, (const float*)nw, neps, nact, H, Hg, \
scale, thr, cv)
#define RC_PICKNT(ANCC, SDTC) \
do { if (nt) RC_LAUNCH(1, ANCC, SDTC); else RC_LAUNCH(0, ANCC, SDTC); } while (0)
#define RC_PICKANC(SDTC) \
do { if (anc) RC_PICKNT(1, SDTC); else RC_PICKNT(0, SDTC); } while (0)
if (sdt) RC_PICKANC(1); else RC_PICKANC(0);
#define RC_PICKNT(ANCC, SDTC, CVC) \
do { if (nt) RC_LAUNCH(1, ANCC, SDTC, CVC); else RC_LAUNCH(0, ANCC, SDTC, CVC); } while (0)
#define RC_PICKANC(SDTC, CVC) \
do { if (anc) RC_PICKNT(1, SDTC, CVC); else RC_PICKNT(0, SDTC, CVC); } while (0)
#define RC_PICKSDT(CVC) \
do { if (sdt) RC_PICKANC(1, CVC); else RC_PICKANC(0, CVC); } while (0)
if (w_f32) RC_PICKSDT(2); else RC_PICKSDT(1);
#undef RC_PICKSDT
#undef RC_PICKANC
#undef RC_PICKNT
#undef RC_LAUNCH
@@ -1082,9 +1090,10 @@ extern "C" int r4d_rad_gdn_conv_recurrent_update(const RadArgs* a, RadStream s)
const long long ab_stride = r4d_row_pitch(ta);
if (ab_stride < 0 || r4d_row_pitch(tb) != ab_stride) return R4D_NO(RAD_E_STRIDE);
R4D_DT(x, RAD_BF16); R4D_DT(cw, RAD_BF16); R4D_DT(cb, RAD_BF16); R4D_DT(cst, RAD_BF16);
R4D_DT(x, RAD_BF16); R4D_DT(cb, RAD_BF16); R4D_DT(cst, RAD_BF16);
R4D_DT(ta, RAD_BF16); R4D_DT(tb, RAD_BF16); R4D_DT(o, RAD_BF16); R4D_DT(z, RAD_BF16);
R4D_DT(alog, RAD_F32); R4D_DT(dtb, RAD_F32); R4D_DT(nw, RAD_F32);
if (cw->dtype != RAD_BF16 && cw->dtype != RAD_F32) return R4D_NO(RAD_E_DTYPE);
if (state->dtype != RAD_F32 && state->dtype != RAD_F16) return R4D_NO(RAD_E_DTYPE);
if (oq) {
if (oq->dtype != RAD_F8E4M3 && oq->dtype != RAD_I8) return R4D_NO(RAD_E_DTYPE);
@@ -1113,7 +1122,7 @@ extern "C" int r4d_rad_gdn_conv_recurrent_update(const RadArgs* a, RadStream s)
RuConv cv{};
cv.x = (const unsigned short*)x->data; cv.xpitch = (long)xpitch;
cv.w = (const unsigned short*)cw->data; cv.b = cb ? (const unsigned short*)cb->data : nullptr;
cv.w = cw->data; cv.b = cb ? (const unsigned short*)cb->data : nullptr;
cv.cs = (unsigned short*)cst->data;
cv.cs_seq = (long)cst->stride[0]; cv.cs_dim = (long)cst->stride[1];
cv.cs_tok = (long)cst->stride[2];
@@ -1128,5 +1137,5 @@ extern "C" int r4d_rad_gdn_conv_recurrent_update(const RadArgs* a, RadStream s)
os ? (long)r4d_row_pitch(os) : 0, cu->data, sidx->data, (long)sidx->stride[0],
nacc ? nacc->data : nullptr, z->data, (long)z_row, nw->data, neps, nact, N, (int)H,
(int)Hg, scale, thr, state->dtype == RAD_F16 ? 1 : 0, s,
oq && oq->dtype == RAD_I8 ? 1 : 0, anc != 0);
oq && oq->dtype == RAD_I8 ? 1 : 0, anc != 0, cw->dtype == RAD_F32);
}
+3 -3
View File
@@ -7262,7 +7262,7 @@ R4D_WIN_PAIR(512, 1) R4D_WIN_PAIR(512, 2) R4D_WIN_PAIR(512, 4) R4D_WIN_PAIR(512,
"gdn prefill preamble: causal conv + qkv split + qk l2norm + gating + per-chunk cumsum "
"[UNVALIDATED: DPP row_xmask rewrite never correctness-gated]",
"conv width 4, head_k/head_v 128, chunk 64, varlen, conv state read and rewritten in place",
"bf16 x / weights / conv state / q,k,v out, fp32 a,b and gate/beta out",
"bf16 x / conv state / q,k,v out, bf16 or f32 weights, fp32 a,b and gate/beta out",
RAD_DOMAIN_DEVICE, R4D_PRIO_ONLY,
ROW(cGdnConvPrep), NOTUNE,
nullptr, nullptr, r4d_rad_gdn_conv_prep },
@@ -7272,7 +7272,7 @@ R4D_WIN_PAIR(512, 1) R4D_WIN_PAIR(512, 2) R4D_WIN_PAIR(512, 4) R4D_WIN_PAIR(512,
"gdn decode conv: rolling speculative window over the conv state cache, writes q/k/v "
"[UNVALIDATED: DPP row_xmask rewrite never correctness-gated]",
"conv width 4, head_k/head_v 128, state cache width-1 + num_spec, read at accepted offset",
"bf16 x / weights / conv state / q,k,v out",
"bf16 x / conv state / q,k,v out, bf16 or f32 weights",
RAD_DOMAIN_DEVICE, R4D_PRIO_ONLY,
ROW(cGdnConvUpdate), NOTUNE,
nullptr, nullptr, r4d_rad_gdn_conv_update },
@@ -7301,7 +7301,7 @@ R4D_WIN_PAIR(512, 1) R4D_WIN_PAIR(512, 2) R4D_WIN_PAIR(512, 4) R4D_WIN_PAIR(512,
"workgroup convolves its key head's q and k and its value head's v into LDS, and the last "
"workgroup of a key head to arrive rewrites that head's conv state",
"head_k/head_v 128, conv width 4, a sequence's window at most 8 tokens, the fused row norm",
"bf16 x / conv weights / conv state / a,b / out; the state cache is f32 or f16. "
"bf16 x / conv state / a,b / out, bf16 or f32 conv weights; the state cache is f32 or f16. "
"Byte-identical to gdn_conv_update followed by gdn_recurrent_update",
RAD_DOMAIN_DEVICE, R4D_PRIO_ONLY,
ROW(cGdnConvRecurrentUpdate), NOTUNE,
+179 -4
View File
@@ -4146,9 +4146,10 @@ static int64_t i8_code_misses(const uint16_t* x, int64_t x_ld, const int8_t* q,
*
* The key heads' conv state must have moved, so the check is sensitive. The anchor form runs in a
* child process, as in gdn_recurrent_anchor. `i8` runs both at int8 codes and also holds the pair's
* codes to quant_act_i8g over its `o`. */
* codes to quant_act_i8g over its `o`. `f32w` hands the fold the conv weight in f32, as a GGUF
* stores it, and leaves the pair's in bf16: the values are bf16's, so the bytes must not change. */
static void gdn_conv_fold_run(const Plugin& pl, const char* nm, const char* form,
bool i8 = false) {
bool i8 = false, bool f32w = false) {
const RadKernelInfo* rf = find(pl, "gdn_conv_recurrent_update_k128_v128_bf16");
const RadKernelInfo* rc = find(pl, "gdn_conv_update_w4_h128_bf16");
const RadKernelInfo* rr = find(pl, "gdn_recurrent_update_k128_v128_bf16_fp32state");
@@ -4175,7 +4176,8 @@ static void gdn_conv_fold_run(const Plugin& pl, const char* nm, const char* form
const std::vector<uint16_t> hw = bf((size_t)(conv_dim * W), 0.5f);
const std::vector<uint16_t> hcs = bf((size_t)(CSLOTS * conv_dim * SL), 1.0f);
std::vector<float> hst((size_t)(SSLOTS * H * V * K)), halog((size_t)H), hdtb((size_t)H),
hnw((size_t)V);
hnw((size_t)V), hwf(hw.size());
for (size_t i = 0; i < hw.size(); ++i) hwf[i] = h_bf16(hw[i]);
for (auto& e : hst) e = 0.1f * rnd();
for (int64_t h = 0; h < H; ++h) { halog[(size_t)h] = -2.0f + 0.25f * (float)h;
hdtb[(size_t)h] = -1.0f + 0.5f * (float)h; }
@@ -4196,6 +4198,7 @@ static void gdn_conv_fold_run(const Plugin& pl, const char* nm, const char* form
void* d_in = dev(nullptr, in_b);
void* d_ab = dev(nullptr, (size_t)(Td * 2 * H) * 2);
void* d_w = dev(hw.data(), hw.size() * 2);
void* d_wf = dev(hwf.data(), hwf.size() * 4);
void* d_alog = dev(halog.data(), halog.size() * 4);
void* d_dtb = dev(hdtb.data(), hdtb.size() * 4);
void* d_nw = dev(hnw.data(), hnw.size() * 4);
@@ -4224,6 +4227,7 @@ static void gdn_conv_fold_run(const Plugin& pl, const char* nm, const char* form
const RadTensor ta = view(d_ab, RAD_BF16, Td, H, 2 * H, 0);
const RadTensor tb = view(d_ab, RAD_BF16, Td, H, 2 * H, H);
const RadTensor tw = T(d_w, RAD_BF16, { conv_dim, W });
const RadTensor tfw = f32w ? T(d_wf, RAD_F32, { conv_dim, W }) : tw;
const RadTensor tal = T(d_alog, RAD_F32, { H }), tdt = T(d_dtb, RAD_F32, { H });
const RadTensor tnw = T(d_nw, RAD_F32, { V });
const RadTensor tci = T(d_cidx, RAD_I32, { N }), tsi = T(d_sidx, RAD_I32, { N, COLS });
@@ -4269,7 +4273,7 @@ static void gdn_conv_fold_run(const Plugin& pl, const char* nm, const char* form
e = run(rr, { tq, tk, tv, ta, tb, tal, tdt, st(0), tsi, tna, tcu, tz, tnw, to(0),
toq(0), tos(0) }, pr);
if (e != RAD_OK) { why = "pair rc=" + std::to_string(e); break; }
e = run(rf, { tx, tw, none, cs(1), tci, ta, tb, tal, tdt, st(1), tsi, tna, tcu, tz, tnw,
e = run(rf, { tx, tfw, none, cs(1), tci, ta, tb, tal, tdt, st(1), tsi, tna, tcu, tz, tnw,
to(1), toq(1), tos(1) }, pf);
if (e != RAD_OK) { why = "fold rc=" + std::to_string(e); break; }
@@ -4316,6 +4320,8 @@ static void gdn_conv_fold(const Plugin& pl) {
const char* row = "gdn_conv_recurrent_update_k128_v128_bf16";
const char* nmp = "gdn_conv_recurrent_update is byte-identical to the pair, per_candidate";
const char* nma = "gdn_conv_recurrent_update is byte-identical to the pair, anchor";
const char* nmf = "gdn_conv_recurrent_update over an f32 conv weight is byte-identical to the "
"pair over its bf16 twin, per_candidate";
if (sel(row)) {
gdn_conv_fold_run(pl, nmp, "per_candidate");
gdn_conv_fold_run(pl, "gdn_conv_recurrent_update is byte-identical to the pair at int8 "
@@ -4323,6 +4329,174 @@ static void gdn_conv_fold(const Plugin& pl) {
"per_candidate", true);
}
if (sel(row) || sel(nma)) gdn_conv_fold_run(pl, nma, "anchor");
if (sel(row) || sel(nmf)) gdn_conv_fold_run(pl, nmf, "per_candidate", false, true);
}
/* gdn_conv_prep and gdn_conv_update over an f32 weight, as a GGUF stores ssm_conv1d, against the
* same weight in bf16.
*
* The weight's values are bf16's, so both forms widen to the same taps and every byte a row writes
* must match: q, k and v, g and beta at prefill, and the conv state. Both runs start from identical
* copies of the cache and from outputs poisoned with 0xFF, so an element the f32 instance never
* writes is caught even where the bf16 one misses it as well. Prefill has two sequences seeded
* from their cached history, one over two chunks, and a one-token sequence without; decode has
* uneven windows and read offsets, sequence 1 at slot 0. The cache must have moved, and an f16
* weight is refused. */
static void gdn_conv_f32_weight(const Plugin& pl) {
const struct { const char* row; const char* nm; bool prep; } forms[] = {
{ "gdn_conv_prep_w4_h128_bf16",
"gdn_conv_prep over an f32 weight is byte-identical to its bf16 twin", true },
{ "gdn_conv_update_w4_h128_bf16",
"gdn_conv_update over an f32 weight is byte-identical to its bf16 twin", false },
};
for (const auto& f : forms) {
if (!sel(f.row) && !sel(f.nm)) continue;
const RadKernelInfo* r = find(pl, f.row);
if (!r) { ok(f.nm, false, "row absent"); continue; }
const int64_t K = 128, V = 128, H = 4, Hg = 2, N = 3, W = 4, MQ = 4, CSLOTS = 3;
const int64_t xdim = 2 * Hg * K + H * V;
/* Prefill reads W - 1 taps of history from a W-deep slot; decode rolls a W - 2 + MQ one. */
const int64_t SL = f.prep ? W : W - 2 + MQ;
const int32_t plen[N] = { 70, 1, 57 }, dlen[N] = { 4, 1, 3 };
const int32_t slot[N] = { 2, 0, 1 }, nacc[N] = { 2, 1, 3 };
const uint8_t init[N] = { 1, 0, 1 };
int64_t Tn = 0;
std::vector<int32_t> cu(1, 0);
for (int64_t n = 0; n < N; ++n) {
Tn += f.prep ? plen[n] : dlen[n];
cu.push_back((int32_t)Tn);
}
uint32_t seed = 0x2f37c0d5u;
auto rnd = [&seed]() {
seed = st_mix32(seed + 0x9e3779b9u);
return (float)(seed & 0xFFFFu) * (1.0f / 32768.0f) - 1.0f;
};
auto bf = [&](size_t n, float s) {
std::vector<uint16_t> v(n);
for (auto& e : v) e = h_to_bf16(s * rnd());
return v;
};
const std::vector<uint16_t> hw = bf((size_t)(xdim * W), 0.5f), hb = bf((size_t)xdim, 0.25f);
const std::vector<uint16_t> hx = bf((size_t)(Tn * xdim), 1.0f);
const std::vector<uint16_t> hab = bf((size_t)(Tn * 2 * H), 1.0f);
const std::vector<uint16_t> hcs = bf((size_t)(CSLOTS * xdim * SL), 1.0f);
std::vector<float> hwf(hw.size()), halog((size_t)H), hdtb((size_t)H);
for (size_t i = 0; i < hw.size(); ++i) hwf[i] = h_bf16(hw[i]);
for (int64_t h = 0; h < H; ++h) { halog[(size_t)h] = -2.0f + 0.25f * (float)h;
hdtb[(size_t)h] = -1.0f + 0.5f * (float)h; }
auto dev = [](const void* h, size_t bytes) {
void* d = dalloc(bytes);
if (d && h) st_memcpy(d, h, bytes, hipMemcpyHostToDevice);
return d;
};
const size_t cs_b = hcs.size() * 2, qk_b = (size_t)(Tn * Hg * K) * 2,
v_b = (size_t)(Tn * H * V) * 2, g_b = (size_t)(Tn * H) * 4;
void* d_x = dev(hx.data(), hx.size() * 2);
void* d_ab = dev(hab.data(), hab.size() * 2);
void* d_b = dev(hb.data(), hb.size() * 2);
void* d_w[2] = { dev(hw.data(), hw.size() * 2), dev(hwf.data(), hwf.size() * 4) };
void* d_alog = dev(halog.data(), halog.size() * 4);
void* d_dtb = dev(hdtb.data(), hdtb.size() * 4);
void* d_slot = dev(slot, sizeof(slot));
void* d_nacc = dev(nacc, sizeof(nacc));
void* d_init = dev(init, sizeof(init));
void* d_cu = dev(cu.data(), cu.size() * 4);
void* d_cs[2]; void* d_q[2]; void* d_k[2]; void* d_v[2]; void* d_g[2]; void* d_beta[2];
for (int i = 0; i < 2; ++i) {
d_cs[i] = dev(hcs.data(), cs_b);
d_q[i] = dev(nullptr, qk_b); d_k[i] = dev(nullptr, qk_b); d_v[i] = dev(nullptr, v_b);
d_g[i] = dev(nullptr, g_b); d_beta[i] = dev(nullptr, g_b);
}
if (!d_x || !d_cu || !d_cs[1] || !d_beta[1]) { ok(f.nm, false, "hipMalloc"); continue; }
for (int i = 0; i < 2; ++i) {
st_memset(d_q[i], 0xFF, qk_b); st_memset(d_k[i], 0xFF, qk_b);
st_memset(d_v[i], 0xFF, v_b); st_memset(d_g[i], 0xFF, g_b);
st_memset(d_beta[i], 0xFF, g_b);
}
/* a and b_gate are column views of one [Tn, 2H] row, as the block lays them out. */
auto view = [](void* base, int64_t rows, int64_t cols, int64_t pitch, int64_t col0) {
RadTensor t = T((char*)base + (size_t)col0 * 2, RAD_BF16, { rows, cols });
t.stride[0] = pitch;
return t;
};
auto ops = [&](int i, uint32_t wdt) {
const RadTensor tx = T(d_x, RAD_BF16, { Tn, xdim }), tb = T(d_b, RAD_BF16, { xdim });
const RadTensor tw = T(d_w[i], wdt, { xdim, W });
const RadTensor tcs = T(d_cs[i], RAD_BF16, { CSLOTS, xdim, SL });
const RadTensor tcu = T(d_cu, RAD_I32, { N + 1 }), tsl = T(d_slot, RAD_I32, { N });
const RadTensor tq = T(d_q[i], RAD_BF16, { Tn, Hg, K }),
tk = T(d_k[i], RAD_BF16, { Tn, Hg, K }),
tv = T(d_v[i], RAD_BF16, { Tn, H, V });
if (!f.prep)
return std::vector<RadTensor>{ tx, tw, tb, tcs, tsl, T(d_nacc, RAD_I32, { N }), tcu,
tq, tk, tv };
return std::vector<RadTensor>{
tx, tw, tb, T(d_alog, RAD_F32, { H }), T(d_dtb, RAD_F32, { H }), tcs, tcu,
view(d_ab, Tn, H, 2 * H, 0), view(d_ab, Tn, H, 2 * H, H), tsl,
T(d_init, RAD_U8, { N }), tq, tk, tv, T(d_g[i], RAD_F32, { Tn, H }),
T(d_beta[i], RAD_F32, { Tn, H }) };
};
std::vector<RadParam> ps = f.prep
? std::vector<RadParam>{ PI("M", Tn), PI("head_k", K), PI("head_v", V),
PI("chunk", 64), PI("conv_width", W) }
: std::vector<RadParam>{ PI("q_len", MQ), PI("head_k", K), PI("head_v", V),
PI("conv_width", W) };
auto run = [&](std::vector<RadTensor> ts) {
RadArgs a; std::memset(&a, 0, sizeof(a));
a.t = ts.data(); a.n_t = (int)ts.size(); a.p = ps.data(); a.n_p = (int)ps.size();
a.world_size = 1;
const int rc_ = r->launch(&a, (RadStream) nullptr);
return rc_ != RAD_OK ? rc_ : (st_stream_sync(nullptr) != hipSuccess ? -1000 : RAD_OK);
};
auto fetch = [](void* d, size_t b) {
std::vector<uint8_t> h(b);
st_memcpy(h.data(), d, b, hipMemcpyDeviceToHost);
return h;
};
std::string why;
for (int i = 0; i < 2 && why.empty(); ++i) {
const int e = run(ops(i, i ? RAD_F32 : RAD_BF16));
if (e != RAD_OK) why = std::string(i ? "f32" : "bf16") + " rc=" + std::to_string(e);
}
struct Out { const char* what; void* a; void* b; size_t n; size_t es; };
std::vector<Out> outs = { { "q", d_q[0], d_q[1], qk_b, 2 },
{ "k", d_k[0], d_k[1], qk_b, 2 },
{ "v", d_v[0], d_v[1], v_b, 2 },
{ "conv_state", d_cs[0], d_cs[1], cs_b, 2 } };
if (f.prep) {
outs.push_back({ "g", d_g[0], d_g[1], g_b, 4 });
outs.push_back({ "beta", d_beta[0], d_beta[1], g_b, 4 });
}
for (const Out& o : outs) {
if (!why.empty()) break;
const std::vector<uint8_t> A = fetch(o.a, o.n), B = fetch(o.b, o.n);
size_t diff = 0, poisoned = 0;
for (size_t j = 0; j < o.n; ++j) diff += A[j] != B[j];
for (size_t j = 0; j < o.n; j += o.es) {
size_t ff = 0;
for (size_t e = 0; e < o.es; ++e) ff += B[j + e] == 0xFF;
poisoned += ff == o.es;
}
if (diff)
why = std::string(o.what) + " differs in " + std::to_string(diff) + " of " +
std::to_string(o.n) + " bytes";
else if (poisoned)
why = std::string(o.what) + ": " + std::to_string(poisoned) + " elements unwritten";
}
if (why.empty() && fetch(d_cs[1], cs_b) == std::vector<uint8_t>(
(const uint8_t*)hcs.data(), (const uint8_t*)hcs.data() + cs_b))
why = "the conv state never moved";
if (why.empty()) {
const int e = run(ops(1, RAD_F16));
if (e != RAD_E_DTYPE) why = "an f16 weight gave rc=" + std::to_string(e);
}
ok(f.nm, why.empty(), why);
}
}
/* The gated norm's gate as a column slice, which one pitch cannot describe.
@@ -29534,6 +29708,7 @@ static void device_phase(const Plugin& pl) {
}
gdn_recurrent_anchor(pl);
gdn_conv_fold(pl);
gdn_conv_f32_weight(pl);
if (sel("gdn_gated_rmsnorm_h128_bf16")) {
const RadKernelInfo* r = find(pl, "gdn_gated_rmsnorm_h128_bf16");
if (!r) ok("gdn_gated_rmsnorm_h128_bf16", false, "row absent");