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

+34 -61
View File
@@ -1,33 +1,21 @@
// r4d_gemm_bf16_nt_m64.hip - r4d_gemm_bf16_nt_m64: skinny bf16 GEMM at any M, gfx1201.
//
// THE NAME SAYS 64 AND THE KERNEL IS GENERAL IN M. MT row tiles live in a block and `grid.y`
// covers the rest -- `mt0 = blockIdx.y * MT`, fragment rows clamped to M-1, the store guarded by
// `m < M` -- so any M up to R4D_GEMM64_MAX_M is served. The 64 is the registry band this row is
// listed under, not a limit of the kernel; the M <= 16 row forwards here as well.
//
// C[M,N] = A[M,K] @ W[N,K]^T, bf16 in and out, fp32 accumulate.
//
// THE SCALAR ALTERNATIVE is a wave per output COLUMN holding M accumulators for it, so every
// 16-wide step of K costs one weight load and M activation loads. That ratio is the whole cost at
// these shapes: at M=16, N=48, K=5120 the activation is re-read sixteen times per weight element,
// 7.9 MB against a 480 KiB weight, so the kernel is bound by traffic it did not need to move.
// Above M=16 that form cannot run at all -- 64 accumulators per column leaves nothing to prefetch
// with.
// General in M up to R4D_GEMM64_MAX_M: MT row tiles per block, grid.y covers the rest. The 64 is
// the registry band, not a kernel limit; the M <= 16 row forwards here too.
//
// WMMA fixes the ratio by construction. One wmma_f32_16x16x16 consumes a 16x16 activation fragment
// and a 16x16 weight fragment and produces a whole 16(M) x 16(N) tile, so a step of 16 K costs
// ceil(M/16) activation fragments and ONE weight fragment however large M is, and the accumulator
// for a tile is 8 VGPRs per lane instead of 16 scalars per output element. At M=64 that is four
// fragments and four wmma per weight fragment, against sixty-four loads before.
// A scalar kernel (one wave per output column, M accumulators) costs one weight load and M
// activation loads per 16 K, and cannot run above M=16. One wmma_f32_16x16x16 produces a whole
// 16x16 tile, so a 16-K step costs ceil(M/16) activation fragments and one weight fragment, with
// 8 VGPRs per lane of accumulator per tile.
//
// Parallel decomposition: a block is WV column-tiles x SK k-splits
// waves, each wave owning one 16-wide N tile over one contiguous slice of K, and the k-splits are
// reduced through LDS in wave order so the result does not depend on how the waves are scheduled.
// N=48 (a TP=2 shard of the gated-delta-net b/a projection) is three tiles; three waves would leave
// the machine idle, so SK is what fills it.
// A block is WV column tiles x SK k-splits waves; each wave owns one 16-wide N tile over one
// contiguous K slice. Splits are reduced through LDS in wave order, so the result does not depend
// on scheduling. SK fills the machine when N is small (N=48 is three tiles).
//
// Fragment rows are CLAMPED, not masked: a tile whose rows run past M or N re-reads the last valid
// row, computes a result nobody stores, and never touches memory it does not own.
// Fragment rows are clamped, not masked: rows past M or N re-read the last valid row and their
// results are never stored.
#include "r4d.h"
#include "r4d_gemm_args.h"
#include "r4d_gdn_wmma.h"
@@ -38,19 +26,15 @@
#define R4D_GEMM64_MAX_M 65536
#define WAVE32 32
// A fragment from a base pointer plus a COMPILE-TIME k step. The header's fragGo takes a 32-bit
// element offset, which is correct but leaves LLVM re-deriving a 64-bit address per fragment per
// step -- a b64 shift and a carry-in add pair, three instructions each, twenty per step around four
// WMMA. Holding one pointer per fragment and stepping it with a constant turns those into the
// 13-bit immediate field of global_load_b64: a k step is 32 bytes, so eight of them fit.
// A fragment from a base pointer plus a compile-time k step. With fragGo's 32-bit element offset,
// LLVM re-derives a 64-bit address per fragment per step (a b64 shift and a carry-in add pair); a
// constant step instead folds into the 13-bit immediate of global_load_b64 (32 bytes per k step,
// so eight fit).
//
// The pointer is explicitly in the global address space. Held as a plain `const uint2*` it is a
// GENERIC pointer once it lives in an array across loop iterations -- LLVM's address-space
// inference does not see through that -- and every load becomes flat_load_b64, which on gfx12
// increments dscnt as well as loadcnt, so any later LDS wait also waits on HBM.
// The element type is a scalar rather than uint2: HIP's vector types are structs whose assignment
// operator does not accept an address-space-qualified source, and an 8-byte scalar carries the same
// alignment the paired load needs.
// The pointer is explicitly global: a plain pointer held in an array across iterations becomes
// generic, so loads become flat_load_b64, which on gfx12 also increments dscnt and makes later LDS
// waits wait on HBM. The element is a scalar because HIP's vector structs cannot be assigned from
// an address-space-qualified source.
typedef __attribute__((address_space(1))) const unsigned long long* r4d_gu2;
__device__ __forceinline__ v8bf fragU(r4d_gu2 p, int u) {
@@ -60,13 +44,10 @@ __device__ __forceinline__ v8bf fragU(r4d_gu2 p, int u) {
return x.f;
}
// MT = row tiles per BLOCK, held as MT v8f accumulators (8 VGPRs each); grid.y covers the rest.
// More row tiles per block amortises the weight fragment over more WMMA, fewer of them put more
// blocks on the machine -- which one wins is a per-shape question, so MT is tunable, not assumed.
// KU is how many k steps the loop unrolls; see the loop for why it exists.
#ifndef KU
#define KU 8
#endif
// MT = row tiles per block, held as MT v8f accumulators (8 VGPRs each); grid.y covers the rest.
// More amortises each weight fragment, fewer puts more blocks on the machine, so MT is tunable.
// KU is the k-step unroll; see the loop.
constexpr int KU = 8;
template <int MT>
__global__ __launch_bounds__(1024) void r4d_gemm_bf16_nt_m64_kernel(
const unsigned short* __restrict__ A, const unsigned short* __restrict__ W,
@@ -83,20 +64,16 @@ __global__ __launch_bounds__(1024) void r4d_gemm_bf16_nt_m64_kernel(
#pragma unroll
for (int i = 0; i < MT; i++) acc[i] = (v8f)(0.f);
// Row offsets as 32-bit ELEMENT offsets: computing them as pointers instead makes the size_t row
// stride a 64-bit multiply-add and the row clamp exec-mask work, none of which LLVM keeps live
// across the loop. They are turned into pointers ONCE, below.
// Row offsets as 32-bit element offsets, turned into pointers once below; as pointers, LLVM
// would not keep the 64-bit stride math and the row clamp out of the loop.
unsigned woff = rowGo((unsigned)K, n0, N - 1, lane) + (unsigned)kbase;
unsigned aoff[MT];
#pragma unroll
for (int i = 0; i < MT; i++)
aoff[i] = rowGo((unsigned)K, (mt0 + i) * 16, M - 1, lane) + (unsigned)kbase;
// Unrolled so the k step is a load IMMEDIATE rather than an address update. Rolled, LLVM widens
// each offset to a 64-bit induction variable and rebuilds the address every step: a b64 shift and
// a carry-in add pair per fragment, twenty instructions per step around four WMMA. Unrolled, the
// sub-step offset is a constant that folds into the 13-bit field of global_load_b64, and the base
// offsets advance once per block of KU.
// Unrolled so the k step is a load immediate (the 13-bit field of global_load_b64) and the base
// pointers advance once per KU steps; rolled, LLVM rebuilds a 64-bit address every step.
if (n0 < N) {
r4d_gu2 pw = (r4d_gu2)(const unsigned long long*)(W + woff);
r4d_gu2 pa[MT];
@@ -125,11 +102,8 @@ __global__ __launch_bounds__(1024) void r4d_gemm_bf16_nt_m64_kernel(
}
}
// Reduce one row tile at a time: SK partial tiles is WV*SK KiB of LDS whatever MT is, where
// holding all MT at once would be four times that at M=64. The sum is spread over every thread
// in the block rather than left to the k-split-0 waves, which at SK=8 is one output element per
// thread instead of sixty-four; the order over splits is fixed, so the result does not depend on
// how the waves were scheduled.
// Reduce one row tile at a time, so LDS is WV*SK KiB regardless of MT. Every thread in the block
// shares the sum (one element per thread at SK=8); the order over splits is fixed.
const int slot = (col_local * SK + ksplit) * 256;
const int nthreads = WV * SK * WAVE32;
#pragma unroll
@@ -145,15 +119,15 @@ __global__ __launch_bounds__(1024) void r4d_gemm_bf16_nt_m64_kernel(
const int l = off & 31;
const int n = (blockIdx.x * WV + col) * 16 + (l & 15);
const int m = (mt0 + i) * 16 + 8 * (l >> 4) + (off >> 5);
// The language's own float-to-bf16 conversion, deliberately and not the header's f2bf,
// which rounds half away from zero.
// The language's float-to-bf16 conversion on purpose; the header's f2bf rounds half away
// from zero.
if (n < N && m < M) C[(size_t)m * N + n] = (__hip_bfloat16)v;
}
}
}
// grid = ceil(ceil(N/16)/WV) blocks; block = WV*SK waves. MT is compile-time so the accumulators
// and the fragment loop are exactly the size M needs.
// grid = ceil(ceil(N/16)/WV) x ceil(ceil(M/16)/MB) blocks; block = WV*SK waves. MT = MB is
// compile-time so the accumulators are sized exactly.
void r4d_gemm_bf16_nt_m64(long a, long w, long c, int M, int K, int N, int WV, int SK, int MB,
long stream) {
if (M < 1 || M > R4D_GEMM64_MAX_M) throw std::runtime_error("r4d gemm_bf16_nt_m64: M out of range");
@@ -182,8 +156,7 @@ int r4d_gemm_bf16_nt_m64_max_m(void) { return R4D_GEMM64_MAX_M; }
// ============================================================== the plugin ABI entry points
//
// The operand reader and the split law are in r4d_gemm_args.h. See libr4d/r4d_args.h for why there
// is no adapter directory between the core and these launches.
// The operand reader and the split law are in r4d_gemm_args.h; see libr4d/r4d_args.h.
extern "C" int r4d_rad_gemm_bf16_m64(const RadArgs* a, RadStream s) {
GemmOps g;
int rc = gemm_ops(a, &g, 0);