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
Deadcode 9ed3ef7a7b radiance 1.15.0
New models and formats:
- IQR for Qwen3.8-27B: weights on the int8 grid under GPTQ, a trellis down each GPTQ column
  (IQR-V2), and IQR-V3, a computed trellis code under one scale a row, kept at its codes' width in
  VRAM and decoded in the GEMM; 15 IQR-V3 recipes from ~2 to ~7 bits a weight
  (data/recipes/q38-27b-*-v3.recipe, docs/IQR.md)
- libhalo: a kernel library for Strix Halo (gfx1151), preferred there over libr3d
- Nemotron 3.5 Embed 1B and 8B (nemotron35_embed): text and image embeddings through a Pixtral
  tower, on the card and on the CPU
- Nemotron 3.5 Rerank 8B
- /v1/systemone: Cloudflare's clef and clef-flash, Convai Innovations' Laya and Mica beside
  LiquidAI d1; scored steps read the candidates' logits from the head table with no lm_head pass
- LFM2's 8-bit trunk: block-fp8 or int8 linears with the fused producers, and the d1-3B recipe
- DeepSeek-V4.1's reply format with DSML tool calls and typed argument tags

Weights on the drive:
- The file tier reads only the experts the pass routes rows to; the draft head's weights stay in
  the host pool
- A hot VRAM cache for routed experts read off the drive, reads deposited straight into free host
  pool slots, and copyless evictions; the file tier's counters are now ssd_*
- GLM-5 Next shards its routed experts by expert, not by width, so they can live on the drive
- The stall watch counts drive reads as progress, and the DMA lane's room check reads the lane's
  own completion fence

Quantisation tooling:
- --calib-corpus, --calib-dir and --calib-layers record each linear's input Hessian; beside
  --kld-record the reference's own run records them
- --kld-top N records a sparse KL reference (the N most likely tokens and the tail's mass)
- GPTQ in a third of the time with the same codes, trellis GPTQ on the card, vector codebooks
  with coordinate descent, and rad-convert --reuse repeated, each container supplying what the
  earlier ones lack

Speculation:
- Prompt lookup alone (--spec-ngram K, --spec-ngram-min/-max): each sequence keeps an index of its
  n-grams, and a proposal is verified only when its measured step cost says it pays;
  --draft-window adaptive follows it

Speed:
- IQR decode: the narrow tile splits K for four times the int8 tile's waves and folds each 128-K
  block once; at 8 tokens down and the output projections run in 0.61-0.82x and 0.70-0.92x FP8's
  time (2-6 bits); IQ6R-S-V3 with its DFlash2 drafter steps in 26.3 ms at TP2, against 29.4 ms
  before and FP8's 27.3
- Qwen MXFP4 feed-forward: the gated fold up to 16 rows, not 8
- libr4d: the gated prefill fold, the short-prompt split row, and the rows forms of rmsnorm and
  rope; KLATE again for the head-256 gqa6 paged prefill; gram_accum on the matrix cores

Features:
- /health, /v1/health and /ping answer 503 with "status": "stuck" once the device has advanced
  nothing for a minute or a queue has faulted, so a supervisor can restart a wedged server (#356)
- --image-gen-max-pixels and --image-gen-max-refs size an image generator's buffers (#344)
- The startup report lists only the options not at their default, with a count; -v lists all
  (#250)
- --preempt-wait-ms bounds how long a preempted prefill waits for its whole-recompute room
- --placement layer_offload spills dense layers so one --max-model-len sequence fits
- Startup refuses amdgpu with CWSR off and says how to fix it;
  --proceed-with-incompatible-configuration starts anyway under an UNSUPPORTED banner

Fixes:
- The n-gram read-ahead hands each row to the reader once and reads only as far ahead as the row
  cache holds, and pauses while decode reads: about one drive read a row instead of two (#355)
- A file-tier window reads each of its runs once, not once a run per run
- The decode split law's verify floor is bounded by the batch's workgroups: max_seqs 256 no longer
  declares 64x the scratch (#342)
- A prefetch DMA list's mark stays out of the signal pool until the engine has read it, and a
  prefill stage copies only the blocks its own tables name (#343)
- The split-KV row sum is read with fetch-inactive (#328)
- LFM2 on the host backend: libref and libavx serve the row-form ops it declares (#348)
- The preempted-prefill gate skips a KV group that holds no blocks (#352)
- Every request entry point bounded, gated and sanitised (JSON depth, invalid UTF-8, control bytes
  in the log, the dashboard's CSP, cross-origin browsers on the loopback-only routes); a prompt id
  outside the vocabulary refused at admission; --api-key "" refused at startup
- The telemetry the HTTP thread reads is atomic
- An RMS norm row no longer depends on how many rows its launch carries; prefill attention's
  rescale is decided by live rows only
- A --kld-record prefill chunk that finishes no sequence gets its logits on a tied-head model
- A kernel's lazily made counter block is zeroed outside the lock other ranks take (a TP2 first-step
  hang)

Changes: Plugin ABI 32. Every plugin exports a layout fingerprint of the ABI structs and the loader
refuses a plugin without it or with another (#302), so out-of-tree plugins must be rebuilt.
Appended: RadBuildCtx calib_* and gen_max_*, RadArchProbe gen_max_*, RadBatch score_only and
plugin_words, RadDeviceProps::unified, RadChatFormat arg_json_value_prefix.
2026-10-30 22:01:01 +01:00

248 lines
11 KiB
Plaintext

/* Derived from libr4d/r4d_audio.hip by the libhalo rename transform (2026-10-26),
* then ported to gfx1151; see libhalo/README.md. */
// halo_conv_t1d.hip -- a vocoder's transposed convolution, gfx1151: the bf16 conv_t1d row, which
// libr4d keeps inside r4d_audio.hip beside conv1d (libhalo's halo_audio.hip holds the rest of that
// unit; this one is extracted so the two lanes' slices stay apart).
//
// The implicit GEMM is libr4d's, with the two gfx11 fragment changes halo_gdn_wmma.h states:
// the fragment pointer loses `4 * (lane >> 4)` (a lane holds the whole 16-wide k run, 32 bytes) and
// the accumulator's element e is D[2e + (lane>>4)][lane & 15], so the blocked store goes through
// accPack -- four v_permlanex16 -- to hand each lane its own eight consecutive channels back.
// Arithmetic is untouched: f32 accumulation, one WMMA per 16 K ascending, bias after the product,
// RTNE bf16 stores (libref/ref_audio.cpp's conv_t1d).
#include "halo.h"
#include "halo_args.h"
#include "halo_common.h"
#include "halo_gdn_wmma.h"
#include <cmath>
#include <cstdint>
#include <cstring>
namespace {
// libr4d's r4d_gdn_wmma.h carried this name; libhalo's halo_gdn_wmma.h is the RDNA3.5 fragment
// layer and does not, so the units that need it define it locally (halo_audio.hip does the same).
__device__ __forceinline__ float bf2f(uint16_t h) { return __uint_as_float((uint32_t)h << 16); }
constexpr int kC1T = 256;
__device__ __forceinline__ void st8(uint16_t* p, const float* f) {
uint4 u;
u.x = (uint32_t)f32_to_bf16(f[0]) | ((uint32_t)f32_to_bf16(f[1]) << 16);
u.y = (uint32_t)f32_to_bf16(f[2]) | ((uint32_t)f32_to_bf16(f[3]) << 16);
u.z = (uint32_t)f32_to_bf16(f[4]) | ((uint32_t)f32_to_bf16(f[5]) << 16);
u.w = (uint32_t)f32_to_bf16(f[6]) | ((uint32_t)f32_to_bf16(f[7]) << 16);
*(uint4*)p = u;
}
// The sequence that owns row r: linear, because a vocoder pass has two (a stereo pair).
__device__ __forceinline__ int seq_of(const int* cu, int n_seq, int r) {
int s = 0;
while (s + 1 < n_seq && cu[s + 1] <= r) ++s;
return s;
}
#define C1_BK 64
#define C1_PITCH (C1_BK + 8)
// ---------------------------------------------------------------------------- conv_t1d
// The transposed convolution of kernel `taps` s (two taps or one), stride s, padding P
// ((k - s) / 2, or 0 for the causal form) as s convolutions of `taps` taps, one a grid slice
// (blockIdx.z is the phase r): output row lo = q s + r - P of a sequence of L input rows reads
// x[q - t] for each tap t (PyTorch's tap r + t s). For a phase below P the q that land inside the
// sequence are 1..L, otherwise 0..L-1, so each phase has L output rows, one per input row: the M
// dimension is the input rows, as for conv1d. The weight is relayouted to [s][cout][taps][cin],
// which does not depend on P.
template <int TP, int TC>
__global__ __launch_bounds__(256) void conv_t1d_kernel(
const uint16_t* __restrict__ x, const uint16_t* __restrict__ w,
const uint16_t* __restrict__ bias, const int* __restrict__ cu, uint16_t* __restrict__ y,
int n_seq, int r_beg, int r_end, int cin, int cout, int s, int P, int taps, int x_ld,
int y_ld) {
constexpr int BP = 2 * TP * 16, BC = 4 * TC * 16;
constexpr int CPR = C1_BK / 8;
constexpr int AL = BP * CPR / 256, WL = BC * CPR / 256;
static_assert(AL >= 1 && WL >= 1, "every thread stages whole chunks");
__shared__ __attribute__((aligned(16))) uint16_t sA[BP * C1_PITCH];
__shared__ __attribute__((aligned(16))) uint16_t sW[BC * C1_PITCH];
const int tid = threadIdx.x, wave = tid >> 5, lane = tid & 31;
const int wp = wave / 4, wc = wave % 4;
const int p0 = r_beg + blockIdx.x * BP, c0 = blockIdx.y * BC;
const int ph = blockIdx.z, qoff = ph < P ? 1 : 0;
const int K = taps * cin;
const uint16_t* wph = w + (size_t)ph * cout * K;
int a_q[AL], a_t[AL], a_ci[AL], a_s0[AL], a_len[AL];
bool a_ok[AL];
uint16_t* adst[AL];
#pragma unroll
for (int i = 0; i < AL; ++i) {
const int c = tid + 256 * i, r = c / CPR, e = (c % CPR) * 8;
const int m = p0 + r;
a_ok[i] = m < r_end;
const int mm = a_ok[i] ? m : r_beg;
const int sq = seq_of(cu, n_seq, mm);
a_s0[i] = cu[sq];
a_len[i] = cu[sq + 1] - cu[sq];
a_q[i] = mm - cu[sq] + qoff;
a_t[i] = e / cin;
a_ci[i] = e % cin;
adst[i] = sA + r * C1_PITCH + e;
}
size_t w_off[WL];
int w_e[WL];
bool w_ok[WL];
uint16_t* wdst[WL];
#pragma unroll
for (int i = 0; i < WL; ++i) {
const int c = tid + 256 * i, r = c / CPR, e = (c % CPR) * 8;
const int co = c0 + r;
w_ok[i] = co < cout;
w_off[i] = (size_t)(w_ok[i] ? co : 0) * K + e;
w_e[i] = e;
wdst[i] = sW + r * C1_PITCH + e;
}
const halo_u32x4 zero = {0u, 0u, 0u, 0u};
auto loadA = [&](int i) -> halo_u32x4 {
if (!a_ok[i] || a_t[i] >= taps) return zero;
const int qi = a_q[i] - a_t[i];
if (qi < 0 || qi >= a_len[i]) return zero;
return *(const halo_u32x4*)(x + (size_t)(a_s0[i] + qi) * x_ld + a_ci[i]);
};
auto loadW = [&](int i, int kt) -> halo_u32x4 {
if (!w_ok[i] || kt * C1_BK + w_e[i] >= K) return zero;
return *(const halo_u32x4*)(wph + w_off[i] + (size_t)kt * C1_BK);
};
/* This lane's fragment row of each tile, at the un-split k offset (halo_gdn_wmma.h's rowP). */
const uint16_t* fa = sA + (wp * TP * 16 + (lane & 15)) * C1_PITCH;
const uint16_t* fw = sW + (wc * TC * 16 + (lane & 15)) * C1_PITCH;
v8f acc[TC][TP];
#pragma unroll
for (int j = 0; j < TC; ++j)
#pragma unroll
for (int i = 0; i < TP; ++i) acc[j][i] = (v8f)(0.f);
halo_u32x4 ra[AL], rw[WL];
#pragma unroll
for (int i = 0; i < AL; ++i) ra[i] = loadA(i);
#pragma unroll
for (int i = 0; i < WL; ++i) rw[i] = loadW(i, 0);
const int nk = (K + C1_BK - 1) / C1_BK;
for (int kt = 0; kt < nk; ++kt) {
__syncthreads();
#pragma unroll
for (int i = 0; i < AL; ++i) *(halo_u32x4*)adst[i] = ra[i];
#pragma unroll
for (int i = 0; i < WL; ++i) *(halo_u32x4*)wdst[i] = rw[i];
__syncthreads();
if (kt + 1 < nk) {
#pragma unroll
for (int i = 0; i < AL; ++i) {
a_ci[i] += C1_BK;
while (a_ci[i] >= cin) { a_ci[i] -= cin; ++a_t[i]; }
ra[i] = loadA(i);
}
#pragma unroll
for (int i = 0; i < WL; ++i) rw[i] = loadW(i, kt + 1);
}
#pragma unroll
for (int ss = 0; ss < C1_BK / 16; ++ss) {
v16bf af[TP], wf[TC];
#pragma unroll
for (int i = 0; i < TP; ++i) af[i] = fragP(fa + i * 16 * C1_PITCH + ss * 16);
#pragma unroll
for (int j = 0; j < TC; ++j) wf[j] = fragP(fw + j * 16 * C1_PITCH + ss * 16);
#pragma unroll
for (int j = 0; j < TC; ++j)
#pragma unroll
for (int i = 0; i < TP; ++i) acc[j][i] = mma(wf[j], af[i], acc[j][i]);
}
}
/* Lane l's element e is channel cb + accRow(l, e) of input row accCol(l), so the bias is added
* per element and accPack then reassembles the tile's sixteen consecutive channels. */
#pragma unroll
for (int j = 0; j < TC; ++j)
#pragma unroll
for (int i = 0; i < TP; ++i) {
const int m = p0 + (wp * TP + i) * 16 + accCol(lane);
if (m >= r_end) continue;
const int cb = c0 + (wc * TC + j) * 16;
const int sq = seq_of(cu, n_seq, m);
const int q = m - cu[sq] + qoff;
const int orow = cu[sq] * s + q * s + ph - P;
uint16_t* dst = y + (size_t)orow * y_ld + cb;
if (cb + 16 <= cout && (cout & 7) == 0) {
float f[8];
#pragma unroll
for (int e = 0; e < 8; ++e) f[e] = acc[j][i][e] + bf2f(bias[cb + accRow(lane, e)]);
*(uint4*)(dst + accPackRow(lane)) = accPack(f, lane);
} else {
#pragma unroll
for (int e = 0; e < 8; ++e) {
const int co = cb + accRow(lane, e);
if (co < cout) dst[co] = f32_to_bf16(acc[j][i][e] + bf2f(bias[co]));
}
}
}
}
inline int c1_st_of(hipError_t e) { return e == hipSuccess ? RAD_OK : HALO_NO(RAD_E_DEVICE); }
inline bool c1_is_bf16(const RadTensor* t) { return t && t->dtype == RAD_BF16; }
inline bool c1_is_i32(const RadTensor* t) { return t && t->dtype == RAD_I32; }
} // namespace
// ============================================================== the plugin ABI entry point
extern "C" int halo_rad_conv_t1d(const RadArgs* a, RadStream s) {
const RadTensor *x = halo_opt(a, 0), *w = halo_opt(a, 1), *b = halo_opt(a, 2),
*cu = halo_opt(a, 3);
const RadTensor *y = halo_opt(a, 4);
if (!x || !w || !b || !cu || !y) return HALO_NO(RAD_E_INVAL);
if (!c1_is_bf16(x) || !c1_is_bf16(w) || !c1_is_bf16(b) || !c1_is_bf16(y) || !c1_is_i32(cu))
return HALO_NO(RAD_E_DTYPE);
const long long cin = halo_geti_or(a, "cin", 0), cout = halo_geti_or(a, "cout", 0);
const long long st = halo_geti_or(a, "stride", 0);
/* Kernel 2 stride (two taps) or stride (one); without `pad`, the symmetric (k - stride) / 2,
* which needs k - stride even. */
const long long kw = halo_geti_or(a, "k", 2 * st), pad = halo_geti_or(a, "pad", -1);
const long long P = pad >= 0 ? pad : (kw - st) / 2;
if (cin <= 0 || cout <= 0 || st <= 0 || (kw != st && kw != 2 * st) ||
(pad < 0 && ((kw - st) & 1)) || P >= st || (cin % 8))
return HALO_NO(RAD_E_SHAPE);
const int taps = (int)(kw / st);
long long rx = 0, ry = 0;
const long long xl = halo_rows_pitch(x, cin, &rx), yl = halo_rows_pitch(y, cout, &ry);
if (xl < 0 || yl < 0 || (xl % 8) || ((uintptr_t)x->data & 15) || ((uintptr_t)w->data & 15))
return HALO_NO(RAD_E_STRIDE);
const long long n_seq = halo_numel(cu) - 1;
if (n_seq <= 0 || rx <= 0 || ry < rx * st || halo_numel(w) < cin * cout * kw ||
halo_numel(b) < cout)
return HALO_NO(RAD_E_SHAPE);
if (cout >= 128) {
constexpr int TP = 4, TC = 2, BP = 128, BC = 128;
hipLaunchKernelGGL((conv_t1d_kernel<TP, TC>),
dim3((unsigned)((rx + BP - 1) / BP), (unsigned)((cout + BC - 1) / BC),
(unsigned)st),
dim3(256), 0, (hipStream_t)s, (const uint16_t*)x->data,
(const uint16_t*)w->data, (const uint16_t*)b->data, (const int*)cu->data,
(uint16_t*)y->data, (int)n_seq, 0, (int)rx, (int)cin, (int)cout, (int)st,
(int)P, taps, (int)xl, (int)yl);
} else {
constexpr int TP = 4, TC = 1, BP = 128, BC = 64;
hipLaunchKernelGGL((conv_t1d_kernel<TP, TC>),
dim3((unsigned)((rx + BP - 1) / BP), (unsigned)((cout + BC - 1) / BC),
(unsigned)st),
dim3(256), 0, (hipStream_t)s, (const uint16_t*)x->data,
(const uint16_t*)w->data, (const uint16_t*)b->data, (const int*)cu->data,
(uint16_t*)y->data, (int)n_seq, 0, (int)rx, (int)cin, (int)cout, (int)st,
(int)P, taps, (int)xl, (int)yl);
}
return c1_st_of(hipGetLastError());
}