Archived
radiance 1.14.0
New models and formats: - libr3d: a kernel library for RDNA3 (gfx11) cards - nomic-embed-text-v2-moe (the nomicbert plugin) - Gemma 4 E2B with its per-layer MLP width, and Google's unmodified E2B/E4B directories in bf16 - DeepSeek-V4.1-Flash converted straight from its release: the Engram tables, the fused imatrix and rad-convert --chat-template for a release that ships no template - GGUF Q8_0, Q4_K and Q6_K tensors import as their planes; rad-convert writes them without a recipe - Qwen3.8-Flash-Next-FP8 converts and serves through qwen4exp_fp8 Speed: - hc_read's decode kernels as one grid (34.7 -> 25.2 us at 4 rows) and its tiled up-mix pipelined - gemm_fp8a8: the narrow form's scales staged through LDS (Flash-Next int8 at 32 rows 83.6 -> 68.3 us), the gated three-tile form at 8 waves (gate_up at 48 rows 272.9 -> 180.6 us) - Qwen3.8-27B: the delta net's out-projection read beside its decode recurrent update (x1 19.40 -> 19.10 ms a step), and the verify's split-KV attention sized by context depth (x3 at 180K 42.4 -> 40.3 ms a step) - Hy-Memory (HYV3) decode: fused QK norm, RoPE and KV store, residual adds folded into the norms, coalesced one-token expert GEMMs - spechub: the coupled verify walks the live candidates only (151 -> 31 us a launch) Speculation: - DFlash2: lossless coupled acceptance at T > 0 (--draft-coupling on) - A block drafter's proposals verified as a tree, on by default for the Gemma 4 31B's DFlash2, with a block-16 tree that runs its short block under load Features: - Decode-hot residency: --draft-expert-placement host, --expert-profile, --expert-pin-top, and --expert-stats FILE for the routed experts each layer selects - --ngram-placement ram=DIR: one n-gram table shared by engines on separate cards - Prefix cache: --prefix-resume exact (default) resumes a hit on the cold run's own chunk grid, so it answers bit-identically; snapshots at a head other prompts share, from 528-token prompts, and for tip-only one drafter window below the tip; hits on models whose KV groups have different block sizes; the snapshot store keeps a floor of 8 ahead of --host-headroom-mib - Typed tool-call argument tags; rad-chatparse --request renders and reads back one request as the server does - MiniMax-H3: keyframes ride a latent upscale - Gemma 3's fused all-reduce junction on the lossy wire Fixes: - A speculative step shorter than its band (an MTP step of 4 rows at gqa 8) no longer stops the engine with a scratch refusal at issue (#293) - --p2p off: prefill back to 1.12.0's rate; 1.13.0's push check read a host-memory slot over the link twice (#323) - A chat template that cannot render a conversation is refused at load, not mid-request - imatrix entries found under llama.cpp's spelling; the W4A8 prefill's tail scale read; the GDN conv kernels on an f32 weight; dense integer rows at the group they compute (a Q8_0 weight at group 32) - --expert-profile refuses a profile recorded on another model - hc_read's one-grid wait traps past its deadline instead of reading a stale value Changes: Plugin ABI 31, unchanged. RADIANCE_DRAFT_TREE, DFLASH2_TREE_NODES, DFLASH2_TREE_TEMP and DFLASH_Q_TEMP are gone (trees run where the probe says they pay; temperatures 1.25 / 0.6).
This commit is contained in:
1 parent
481fcd5df0
commit
4a61d7296b
160 files changed
+8790
-6819
No files matched your search
+60
-74
@@ -1,45 +1,39 @@
|
||||
/* r3d_common.h -- the RDNA3 seams a kernel needs: the wave's lane maths, the loads, the block
|
||||
* reduce, the occupancy and LDS conventions.
|
||||
/* r3d_common.h -- RDNA3 kernel primitives: lane maths, global loads, the block reduce, occupancy
|
||||
* and LDS conventions. The codecs are in r3d_codecs.h.
|
||||
*
|
||||
* What RDNA3 gives, measured on the ROCm this tree builds against (AMD clang 24; `__has_builtin`
|
||||
* off --offload-device-only, and llvm-mc -show-encoding per target). The codecs are in r3d_codecs.h;
|
||||
* this header is what is left.
|
||||
* Instruction availability on gfx11 with the AMD clang this tree builds with (checked with
|
||||
* `__has_builtin` under --offload-device-only and llvm-mc -show-encoding per target):
|
||||
*
|
||||
* v_dot2acc_f32_f16 yes, every gfx11 target, from __builtin_amdgcn_fdot2, and RDNA3 pairs
|
||||
* it as v_dual_dot2acc_f32_f16 where the scheduler can. The matrix work.
|
||||
* v_dot2 with bf16 no, and the builtin's bf16 selector is accepted and ignored -- the f16
|
||||
* instruction is emitted -- so bf16 is widened, never asserted.
|
||||
* WMMA the mnemonic is unreachable -- every v_wmma_* is rejected by the
|
||||
* assembler on gfx1100, gfx1102, gfx1151 and gfx1201 alike, and inline
|
||||
* asm dies in amdgcn-link -- but the builtin is not:
|
||||
* __builtin_amdgcn_wmma_f32_16x16x16_f16_w32 compiles for the three gfx11
|
||||
* targets and emits a real tile instruction. Measured here against dot2 at
|
||||
* four occupancies, 1.99 against 1.97 TFLOP/s: RDNA3's AI accelerator is a
|
||||
* 2x f16-rate feature and a paired dot2 is already at that rate, so the
|
||||
* tile buys a fragment layout and a block-alignment requirement and no
|
||||
* throughput. No fragment layouts here, so no repacked weights, so no
|
||||
* layout hook: a dot2 GEMM reads a weight in the order it is stored.
|
||||
* fp8 convert no (needs the fp8 feature); the builtins are declared and die at
|
||||
* instruction selection, which is why the codecs are software.
|
||||
* v_dot2acc_f32_f16 yes, all gfx11, via __builtin_amdgcn_fdot2; dual-issued as
|
||||
* v_dual_dot2acc_f32_f16 where possible. Carries the matrix work.
|
||||
* v_dot2 with bf16 no. The builtin's bf16 selector is accepted and ignored (the f16
|
||||
* instruction is emitted), so bf16 is widened.
|
||||
* WMMA the assembler rejects every v_wmma_* mnemonic and inline asm fails in
|
||||
* amdgcn-link, but __builtin_amdgcn_wmma_f32_16x16x16_f16_w32 compiles on
|
||||
* gfx11. It runs at the same rate as paired dot2 (about 2 TFLOP/s each
|
||||
* on the tested part; RDNA3's matrix unit is a 2x f16-rate feature that
|
||||
* dual dot2 already reaches), so it would add a fragment layout and an
|
||||
* alignment requirement for no throughput. Without fragment layouts no
|
||||
* weight is repacked: a dot2 GEMM reads a weight in stored order.
|
||||
* fp8 convert no (needs the fp8 feature); the builtins are declared but fail at
|
||||
* instruction selection, so the codecs are software.
|
||||
* v_cvt_pkrtz_f16_f32 yes. Used only where it is exact.
|
||||
* v_cvt_pk_bf16_f32 no on gfx1100/1102/1151 in this build, so bf16 packs are software.
|
||||
* DPP16, v_permlanex16 yes, RDNA1 onward. The lane maths below is libr4d's, unchanged: the
|
||||
* encodings are the same silicon, and they were verified on hardware.
|
||||
* v_cvt_pk_bf16_f32 no on gfx1100/1102/1151, so bf16 packs are software.
|
||||
* DPP16, v_permlanex16 yes (RDNA1 onward). The lane maths below uses libr4d's encodings,
|
||||
* which are hardware-verified.
|
||||
* ballot_w32, readlane,
|
||||
* readfirstlane, ds_bpermute,
|
||||
* v_perm_b32, exp2f, rcpf,
|
||||
* s_barrier, fence,
|
||||
* sched_group_barrier yes.
|
||||
* transposed loads no: neither global_load_tr_b128 (RDNA4) nor ds_read_b64_tr_b16 (dropped
|
||||
* by RDNA4, kept here as a fact about gfx11 -- this ROCm's assembler
|
||||
* rejects it too). A transpose is done in registers.
|
||||
* transposed loads no: neither global_load_tr_b128 (RDNA4) nor ds_read_b64_tr_b16 (the
|
||||
* assembler rejects it for gfx11). Transposes are done in registers.
|
||||
*
|
||||
* Wave32 is gfx11's default and every kernel here is written for it; the guard below fires if a
|
||||
* build asks for wave64, because that computes garbage rather than running slower.
|
||||
* Every kernel is written for wave32, gfx11's default; the guard below rejects a wave64 build,
|
||||
* which would compute wrong results.
|
||||
*
|
||||
* The register file is the one number that is NOT the same as RDNA4's: a gfx11 SIMD has 1024 VGPRs
|
||||
* for a wave32, allocated in groups of 8, against gfx1201's 1536. R3D_WAVES is stated per kernel,
|
||||
* and a kernel's budget is computed against 1024.
|
||||
* Register file: a gfx11 SIMD has 1024 VGPRs for wave32, allocated in groups of 8 (gfx1201 has
|
||||
* 1536). R3D_WAVES is set per kernel and each kernel's budget is computed against 1024.
|
||||
*/
|
||||
#ifndef R3D_COMMON_H
|
||||
#define R3D_COMMON_H
|
||||
@@ -57,26 +51,25 @@
|
||||
|
||||
enum : int { kWave = 32 };
|
||||
|
||||
/* A 16-byte staging register as a native vector. HIP's uint4 is a class template wrapping a union,
|
||||
* and an array of them carried across a loop is kept in scratch by LLVM 22 and 24; an
|
||||
* ext_vector_type array is promoted to registers. Loaded and stored whole only. */
|
||||
/* A 16-byte staging register as a native vector. HIP's uint4 is a class wrapping a union, and LLVM
|
||||
* 22 and 24 keep an array of them carried across a loop in scratch; an ext_vector_type array is
|
||||
* promoted to registers. Loaded and stored whole only. */
|
||||
typedef unsigned int r3d_u32x4 __attribute__((ext_vector_type(4)));
|
||||
typedef unsigned int r3d_u32x2 __attribute__((ext_vector_type(2)));
|
||||
|
||||
/* ================================================================== the occupancy a kernel is
|
||||
* built for
|
||||
*
|
||||
* Fixes the waves per SIMD the compiler schedules for. Left unstated, the scheduler picks the
|
||||
* target itself and the choice moves between compiler releases. gfx11's budget is 1024 VGPRs a
|
||||
* SIMD at wave32, in granules of 8: a kernel asking for 5 waves has 204 registers to spend. */
|
||||
* Fixes the waves per SIMD the compiler schedules for; left unstated, the choice changes between
|
||||
* compiler releases. gfx11's budget is 1024 VGPRs a SIMD at wave32, in granules of 8: a kernel
|
||||
* asking for 5 waves has 204 registers to spend. */
|
||||
#define R3D_WAVES(n) __attribute__((amdgpu_waves_per_eu((n), (n))))
|
||||
|
||||
/* ================================================================== exp2
|
||||
*
|
||||
* The hardware transcendental. libr4d's rule applies: exp2f, powf and sincosf are the accurate
|
||||
* forms, not the __ approximations -- rope positions reach 262144, past __sincosf's argument
|
||||
* reduction, and libref uses libm. exp2f itself is the one place the hardware op is exactly what
|
||||
* the reference computes, because both sides round the same result once. */
|
||||
* The hardware transcendental. Elsewhere use the accurate exp2f, powf and sincosf, not the __
|
||||
* approximations: rope positions reach 262144, past __sincosf's argument reduction, and libref uses
|
||||
* libm. exp2 is the exception because the hardware op and the reference round the same result once. */
|
||||
__device__ __forceinline__ float ex2(float x) {
|
||||
return __builtin_amdgcn_exp2f(x);
|
||||
}
|
||||
@@ -87,12 +80,11 @@ __device__ __forceinline__ float rcp(float x) { return __builtin_amdgcn_rcpf(x);
|
||||
*
|
||||
* A 16-bit element of global memory, zero-extended into a whole register (global_load_u16). Read as
|
||||
* `uint16_t` it lands in a register half (global_load_d16_b16) whose other half the waitcnt pass
|
||||
* then waits for; through a generic pointer it is also a flat load. The pointer must address global
|
||||
* memory, which every caller's operand is.
|
||||
* then waits for, and through a generic pointer it is a flat load. The pointer must address global
|
||||
* memory.
|
||||
*
|
||||
* libr4d notes that LLVM 24 gives gfx12 real 16-bit registers and the packability that follows;
|
||||
* gfx11 does not have them, so keeping bf16 in whole registers from load to store is the plain
|
||||
* reading as well as the portable one. */
|
||||
* gfx11 has no true 16-bit registers (LLVM 24 gives them to gfx12 only), so bf16 stays in whole
|
||||
* registers from load to store. */
|
||||
typedef const uint16_t __attribute__((address_space(1))) *r3d_gu16;
|
||||
__device__ __forceinline__ uint32_t ldg_u16(const uint16_t* p) { return *(r3d_gu16)p; }
|
||||
__device__ __forceinline__ uint32_t ldg_u32(const uint32_t* p) { return *(const __attribute__((address_space(1))) uint32_t*)p; }
|
||||
@@ -102,16 +94,15 @@ __device__ __forceinline__ float ldg_f32(const float* p) {
|
||||
|
||||
/* ================================================================== lane maths
|
||||
*
|
||||
* A wave is 32 lanes, two rows of sixteen. Reductions are XOR butterflies, in the order a
|
||||
* __shfl_xor loop runs in, so the result is bit-identical to that loop -- which is what libref
|
||||
* sums, since the reference sums a row in ascending index order and a wave of lanes maps to
|
||||
* consecutive elements.
|
||||
* A wave is 32 lanes, two rows of sixteen. Reductions are XOR butterflies in the order a
|
||||
* __shfl_xor loop runs them, so results are bit-identical to that loop and to libref, which sums a
|
||||
* row in ascending index order over consecutive elements.
|
||||
*
|
||||
* `__shfl_xor` lowers to ds_bpermute_b32 plus s_wait_dscnt, an LDS round trip that dominates a
|
||||
* dependency chain. DPP16's ROW_XMASK (control 0x160 | N) makes the partner read a modifier on the
|
||||
* consuming VALU op, and N = 16 crosses the two rows of a wave32 with v_permlanex16, still one VALU
|
||||
* op. Row and bank masks are all-ones because every lane participates; bound_ctrl is moot because
|
||||
* every lane has a partner. These are libr4d's encodings, verified on hardware. */
|
||||
* consuming VALU op, and N = 16 crosses the two rows with v_permlanex16, also one VALU op. Row and
|
||||
* bank masks are all-ones because every lane participates; bound_ctrl is moot because every lane
|
||||
* has a partner. */
|
||||
template <int N>
|
||||
__device__ __forceinline__ uint32_t r3d_xor_lane_u32(uint32_t v) {
|
||||
static_assert(N >= 1 && N <= 16 && (N & (N - 1)) == 0, "a lane xor within the wave");
|
||||
@@ -139,7 +130,7 @@ __device__ __forceinline__ unsigned long long r3d_xor_lane_u64(unsigned long lon
|
||||
* other half; sel0 covers lanes 0-7, sel1 lanes 8-15); zero selectors silently broadcast lane 0. */
|
||||
__device__ __forceinline__ float swap16(float x) { return r3d_xor_lane<16>(x); }
|
||||
|
||||
/* v + the partner's v, the partner read by DPP so the add carries it. */
|
||||
/* v + the partner's v, read by DPP as a modifier on the add. */
|
||||
template <int CTRL>
|
||||
__device__ __forceinline__ float r3d_dpp_xor_add(float v) {
|
||||
return v + __uint_as_float(__builtin_amdgcn_update_dpp(0, __float_as_uint(v), CTRL, 0xF, 0xF,
|
||||
@@ -166,7 +157,7 @@ __device__ __forceinline__ float wave_max(float v) {
|
||||
|
||||
/* The same butterflies over a group of W lanes (a power of two up to the wave), in the order
|
||||
* `for (o = W/2; o; o >>= 1) v = op(v, __shfl_xor(v, o))` runs them, so bit-identical to it. A row
|
||||
* of sixteen lanes -- the sixteen columns a lane owns in a bf16 pair layout -- uses W = 16. */
|
||||
* of sixteen lanes (the sixteen columns of a bf16 pair layout) uses W = 16. */
|
||||
template <int W>
|
||||
__device__ __forceinline__ float r3d_xor_sum(float v) {
|
||||
static_assert(W >= 1 && W <= 32 && (W & (W - 1)) == 0, "a power-of-two group within the wave");
|
||||
@@ -190,8 +181,8 @@ __device__ __forceinline__ float r3d_xor_max(float v) {
|
||||
}
|
||||
|
||||
/* A wave's inclusive prefix sum in registers: row_shr 1, 2, 4 and 8 within each row of sixteen,
|
||||
* then the other row's total from one readlane. Lane L ends with the sum over lanes 0..L. Replaces
|
||||
* an LDS step-doubling scan, which costs two barriers a round. Integer, so combine order is free.
|
||||
* then the first row's total from one readlane. Lane L ends with the sum over lanes 0..L. Avoids an
|
||||
* LDS step-doubling scan, which costs two barriers a round. Integer, so combine order is free.
|
||||
* Every lane must be active. */
|
||||
__device__ __forceinline__ uint32_t wave_prefix_u32(uint32_t x, int lane) {
|
||||
x += (uint32_t)__builtin_amdgcn_update_dpp(0, (int)x, 0x111, 0xF, 0xF, true); /* row_shr:1 */
|
||||
@@ -205,9 +196,8 @@ __device__ __forceinline__ uint32_t wave_prefix_u32(uint32_t x, int lane) {
|
||||
/* ================================================================== a block's sum
|
||||
*
|
||||
* Wave sum, one LDS round trip, then every thread adds the wave partials in wave order. The order
|
||||
* is the contract: libref sums a row in ascending index order, the waves cover consecutive
|
||||
* elements, and adding the partials in wave order is the same bracketing at any thread count.
|
||||
* `lds` holds NWAVES floats. */
|
||||
* is part of the contract: waves cover consecutive elements, so wave order gives the same
|
||||
* bracketing at any thread count. `lds` holds NWAVES floats. */
|
||||
template <int NTHREADS>
|
||||
__device__ __forceinline__ float block_sum(float v, float* lds) {
|
||||
constexpr int NWAVES = NTHREADS / kWave;
|
||||
@@ -225,22 +215,19 @@ __device__ __forceinline__ float block_sum(float v, float* lds) {
|
||||
|
||||
/* ================================================================== scheduling
|
||||
*
|
||||
* LLVM single-buffers LDS and drains before every dependent read unless told otherwise; on gfx11
|
||||
* the matrix unit is absent so there is nothing to overlap a load with, and the barrier the
|
||||
* kernels need is the plain one. */
|
||||
* LLVM single-buffers LDS and drains before every dependent read unless told otherwise. On gfx11
|
||||
* there is no matrix unit to overlap a load with, so the plain barrier is enough. */
|
||||
__device__ __forceinline__ void sched_barrier() { __builtin_amdgcn_sched_barrier(0); }
|
||||
__device__ __forceinline__ void group_barrier() { __syncthreads(); }
|
||||
|
||||
/* ================================================================== the geometry constants
|
||||
*
|
||||
* A gfx11 GPU's wave slots: a CU has 4 SIMDs, a SIMD holds 16 wave32s, so 64 slots a CU. HIP's
|
||||
* multiProcessorCount reports CUs on gfx11 (it reports WGPs on gfx12, which is where libr4d's 2048
|
||||
* comes from), and a launch whose grid passes 64 * multiProcessorCount waves has more work than
|
||||
* slots: the tail waves start after another wave retires. A row-per-block kernel with one wave a
|
||||
* block is exactly that cliff, and its row count is where the cliff is.
|
||||
* A gfx11 GPU's wave slots: a CU has 4 SIMDs and a SIMD holds 16 wave32s, so 64 slots a CU. HIP's
|
||||
* multiProcessorCount reports CUs on gfx11 (WGPs on gfx12, hence libr4d's different constant). A
|
||||
* grid with more than 64 * multiProcessorCount waves runs its tail waves only after others retire,
|
||||
* so for a one-wave row-per-block kernel that row count is a performance cliff.
|
||||
*
|
||||
* A launcher's question, so a host function: this HIP declares no device-side hipGetDevice or
|
||||
* hipDeviceGetAttribute, and a __device__ body does not compile at all. */
|
||||
* Host only: HIP declares no device-side hipGetDevice or hipDeviceGetAttribute. */
|
||||
static inline int wave_slot_count() {
|
||||
int dev = 0, cu = 0;
|
||||
(void)hipGetDevice(&dev);
|
||||
@@ -248,9 +235,8 @@ static inline int wave_slot_count() {
|
||||
return 64 * cu;
|
||||
}
|
||||
|
||||
/* The LDS a workgroup gets is 64 KiB, the same figure RDNA4 gives, and no kernel in libr3d needs
|
||||
* more. There is no hipFuncSetAttribute opt-in: 64 KiB of dynamic shared memory is available as
|
||||
* soon as it is asked for. */
|
||||
/* A workgroup gets 64 KiB of LDS, as on RDNA4, and no libr3d kernel needs more. No
|
||||
* hipFuncSetAttribute opt-in is needed for the full 64 KiB of dynamic shared memory. */
|
||||
enum : int { kLdsCap = 64 * 1024 };
|
||||
|
||||
#endif /* R3D_COMMON_H */
|
||||
Reference in new issue
Block a user