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

212 lines
13 KiB
C++

/* Derived from libr4d/r4d_ar_seq.h by the libhalo rename transform (2026-10-26);
* see libhalo/README.md. Op schemas, row names and stored weight layouts are
* shared with libr4d by design. Everything else in this file is libhalo's own
* and diverges as it is measured on gfx1151. */
#pragma once
// halo_ar_seq.h: the first step of every all-reduce and all-gather kernel (its handshake sequence
// number and scratch slot) and the wrap-safe wait after the push. Shared by the 2-rank and wide
// families: kernels sharing an instance's buffers must take the step identically or the ranks
// disagree.
//
// Counter allocation: 2 * nbw words, zeroed once (nbw = block capacity the flag array was sized
// for), then the landed counter (halo_ar_link_landed):
//
// [0, nbw) Handshake counters, one per block. Block b advances word b once per launch it
// runs in, publishes it to the peer and waits for the peer's. Per block so a
// block idle through narrow launches resumes one step past its peer's last flag;
// the wrap-safe compare needs that gap far under 2^31.
//
// [nbw, 2*nbw) Parity counters. Every launch advances all nbw of them once, whatever its block
// count (block b takes words b, b + nb, b + 2*nb, ...), so each equals the launch
// count and a block reads the slot parity off its own word.
//
// [2*nbw] Landed counter: blocks of the running launch that have seen their peer's push
// land; back at zero when the launch ends.
//
// The slot cannot come from the handshake counter. Consecutive launches on one instance must use
// opposite scratch slots, since launch k+1 may push while the peer still reduces launch k. Block
// counts and per-block byte ranges vary by launch, so handshake counters drift apart per block,
// and a block of launch k+1 could push into the slot a different block of launch k is still
// reading. The parity counters move in lockstep, so the slot alternates per launch for every block.
//
// Cost: one more returning atomic, issued from a second wave so its round trip overlaps the
// handshake's, plus nbw / nb fire-and-forget atomics over the other threads. Those only need to
// land before the next launch, which the kernel boundary guarantees. All state is device-resident,
// so a captured graph replays.
#include <hip/hip_runtime.h>
#include "halo_common.h" // halo_xor_lane_u32: the wave sum on DPP instead of the LDS crossbar
// Sets `s_seq` to this block's handshake value and `s_slot` to the launch's scratch slot (0 or 1),
// then barriers so every thread can read both. `nbw` is the capacity the counters were allocated
// for, and gridDim.x must not exceed it. `steps` handshake values are taken at once (s_seq is the
// first): a kernel that handshakes more than twice per launch reserves the flag values it
// publishes, so every kernel on the instance stays in the same monotone flag space. All ranks must
// take the same number for the same block.
//
// The barrier fences LDS only, since it publishes just the two LDS words. A full __syncthreads
// would wait for the outstanding parity atomics and invalidate the vector caches, putting that
// traffic on the path to the first push.
__device__ __forceinline__ void halo_ar_seq_take(unsigned int* __restrict__ ctrs, unsigned int nbw,
unsigned int& s_seq, unsigned int& s_slot,
unsigned int steps = 1u) {
const unsigned int b = blockIdx.x, nb = gridDim.x, tid = threadIdx.x, nt = blockDim.x;
unsigned int* const par = ctrs + nbw;
const unsigned int pt = nt > 32u ? 32u : 0u; // first lane of the second wave, if there is one
if (tid == 0) s_seq = atomicAdd(&ctrs[b], steps) + 1u;
if (tid == pt) s_slot = (atomicAdd(&par[b], 1u) + 1u) & 1u;
for (unsigned int j = b + (tid + 1u) * nb; j < nbw; j += nt * nb) atomicAdd(&par[j], 1u);
__builtin_amdgcn_fence(__ATOMIC_RELEASE, "workgroup", "local");
__builtin_amdgcn_s_barrier();
__builtin_amdgcn_fence(__ATOMIC_ACQUIRE, "workgroup", "local");
}
// The engine's hold on the link, released by the launch (rad_abi.h, rad_kernel_collective
// returning 2). The word is odd exactly while the engine holds the link for this launch and
// nothing else writes it meanwhile, so each block's first thread reads it once at the start
// (halo_ar_link_word), where the host-memory read overlaps the push instead of delaying the reduce.
//
// Every block calls halo_ar_link_landed once its handshake has seen the peer's push land. The last
// block knows all of the peer's bytes have arrived, so the link is free for the rest of the
// kernel; it decrements the word if odd, atomically so it commutes with any barrier counting the
// same word down. `ctr` counts blocks and returns to zero at the end of the launch. The DMA engine
// polls the word past every cache, so it is accessed at system scope.
__device__ __forceinline__ long long halo_ar_link_word(const long long* gate, unsigned int tid) {
return gate && tid == 0 ? __hip_atomic_load(gate, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_SYSTEM)
: 0;
}
__device__ __forceinline__ void halo_ar_link_landed(long long* gate, long long word,
unsigned int* ctr, unsigned int nb,
unsigned int tid) {
if (!gate || tid != 0) return;
const unsigned int prev = __hip_atomic_fetch_add(ctr, 1u, __ATOMIC_RELAXED,
__HIP_MEMORY_SCOPE_AGENT);
if (prev + 1u != nb) return;
__hip_atomic_store(ctr, 0u, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_AGENT);
if (word & 1) __hip_atomic_fetch_add(gate, -1LL, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_SYSTEM);
}
// True while `flag` has not reached `want`. The u32 counters wrap, so compare the signed
// difference: a peer at or past `want` (possibly a launch ahead) reads as arrived across the wrap,
// where a plain `flag < want` would stop waiting once `want` wraps to a small number.
__device__ __forceinline__ bool halo_ar_seq_behind(unsigned int flag, unsigned int want) {
return (int)(flag - want) < 0;
}
// ---- The push check. A peer's push over PCIe P2P can land after its release flag (measured on 2x
// R9700: the reader sometimes found the slot's previous contents right after the handshake, and
// the new bytes ~1 us later), so the flag alone does not say the bytes are there. The pushed bytes
// wait in the writer's L2 for the release's writeback, and that writeback and the flag store reach
// the peer by different paths. The writer sums mix(dword, index) over what it pushes and stores the
// block's sum, salted with its handshake value, into the peer's check word for (slot, block):
// fine-grained words after the flags (halo_ar_entry.hip sizes the allocation). The reader sums the
// same over the bytes it is about to read and reads again until the two agree. A stale element and
// a stale check word (an older handshake value) both disagree, so only the landed push passes; the
// order the two land in does not matter. The sum is order-free, so writer and reader may split the
// bytes differently.
#define HALO_ARCHK_SALT 0x6C8E9CF5u
// wall_clock64 ticks (100 MHz): 2 s. A push that never lands is a lockstep fault, so the reader traps.
#define HALO_ARCHK_DEADLINE 200000000ull
#define HALO_ARCHK_U16 0x80000000u // index space of 16-bit fields (wire scales), apart from dwords
// MurmurHash3's finalizer over (value, index): every bit of the value reaches every bit of the term,
// so a sum of terms changes when any value does. A linear mix is not enough: (v ^ c_e) summed over
// a run of indices can lose v entirely, and a message of one repeated value (a test pattern, a
// zero-filled row) would then pass whatever the slot held.
__device__ __forceinline__ unsigned int halo_archk_mix(unsigned int v, unsigned int e) {
unsigned int x = v ^ (e * 0x9E3779B9u);
x ^= x >> 16; x *= 0x85EBCA6Bu;
x ^= x >> 13; x *= 0xC2B2AE35u;
x ^= x >> 16;
return x;
}
// A 16B word at dword index `e`.
__device__ __forceinline__ unsigned int halo_archk_u4(int4 v, unsigned int e) {
return halo_archk_mix((unsigned int)v.x, e) + halo_archk_mix((unsigned int)v.y, e + 1u) +
halo_archk_mix((unsigned int)v.z, e + 2u) + halo_archk_mix((unsigned int)v.w, e + 3u);
}
__device__ __forceinline__ unsigned int halo_archk_u4(uint4 v, unsigned int e) {
return halo_archk_mix(v.x, e) + halo_archk_mix(v.y, e + 1u) + halo_archk_mix(v.z, e + 2u) +
halo_archk_mix(v.w, e + 3u);
}
// The check word of (slot, block) in a flags allocation: two parity slots of nbw words after the
// nbw flags.
__device__ __forceinline__ unsigned int* halo_archk_word(unsigned int* flags, unsigned int nbw,
unsigned int slot, unsigned int b) {
return flags + nbw + slot * nbw + b;
}
// The same partners in the same order as `for (o = 16; o; o >>= 1) h += __shfl_xor(h, o, 32)`,
// on DPP and permlanex16 (halo_xor_lane) rather than one ds_bpermute_b32 per stage: this sum sits
// on the handshake path of every block. Integer adds commute, so the bits are the same either way.
__device__ __forceinline__ unsigned int halo_archk_wave_sum(unsigned int h) {
h += halo_xor_lane_u32<16>(h);
h += halo_xor_lane_u32<8>(h);
h += halo_xor_lane_u32<4>(h);
h += halo_xor_lane_u32<2>(h);
h += halo_xor_lane_u32<1>(h);
return h;
}
// Writer: every thread of the block calls this after its pushes, before the handshake's barrier.
// Thread 0 stores the block's sum into the peer's check word.
__device__ __forceinline__ void halo_archk_put(unsigned int h, unsigned int* peer_flags,
unsigned int nbw, unsigned int slot,
unsigned int b, unsigned int seq,
bool release = false) {
__shared__ unsigned int s_ckp[32];
const unsigned int tid = threadIdx.x, nt = blockDim.x;
h = halo_archk_wave_sum(h);
if ((tid & 31u) == 0u) s_ckp[tid >> 5] = h;
__syncthreads();
if (tid == 0) {
unsigned int t = 0u;
for (unsigned int w = 0; w < (nt + 31u) / 32u; ++w) t += s_ckp[w];
/* The pushed bytes sit in this card's L2 until a system-scope release writes them back. The
* flag's release, right after this, does that, so the word itself can be relaxed (the reader
* re-reads until the bytes agree with it). Where the flag went out before the push (the test
* mode, drain 4) nothing else would write them back before the kernel ends: a release. */
unsigned int* const cw = halo_archk_word(peer_flags, nbw, slot, b);
if (release)
__hip_atomic_store(cw, t + seq * HALO_ARCHK_SALT, __ATOMIC_RELEASE, __HIP_MEMORY_SCOPE_SYSTEM);
else
__hip_atomic_store(cw, t + seq * HALO_ARCHK_SALT, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_SYSTEM);
}
}
// Reader: every thread of the block calls this after the handshake; `rehash(h)` adds the thread's
// share of the bytes the block is about to read, with the same loads the kernel then makes.
template <typename F>
__device__ __forceinline__ void halo_archk_wait(unsigned int* my_flags, unsigned int nbw,
unsigned int slot, unsigned int b,
unsigned int seq, const F& rehash) {
__shared__ unsigned int s_ckw[32];
__shared__ unsigned int s_ckok;
const unsigned int tid = threadIdx.x, nt = blockDim.x;
const unsigned long long t0 = tid == 0 ? wall_clock64() : 0ull;
for (;;) {
/* The check word first, so its round trip overlaps the re-hash's loads. Read before the bytes
* it is compared with, it can only be older than them, and an older word just fails this try. */
const unsigned int want = tid == 0 ? __hip_atomic_load(halo_archk_word(my_flags, nbw, slot, b),
__ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_SYSTEM)
: 0u;
unsigned int h = 0u;
rehash(h);
h = halo_archk_wave_sum(h);
if ((tid & 31u) == 0u) s_ckw[tid >> 5] = h;
__syncthreads();
if (tid == 0) {
unsigned int t = 0u;
for (unsigned int w = 0; w < (nt + 31u) / 32u; ++w) t += s_ckw[w];
const bool ok = t + seq * HALO_ARCHK_SALT == want;
if (!ok && wall_clock64() - t0 > HALO_ARCHK_DEADLINE) __builtin_trap();
s_ckok = ok ? 1u : 0u;
}
__syncthreads();
if (s_ckok) return;
__syncthreads(); // s_ckw and s_ckok are rewritten by the next try
/* Drop the vector caches, so the next try reads the bytes from where the push lands. */
__builtin_amdgcn_fence(__ATOMIC_ACQUIRE, "");
__builtin_amdgcn_s_sleep(2);
}
}