Archived
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:
1 parent
b068190326
commit
1e968f6e1d
739 files changed
+128447
-84632
No files matched your search
+45
-272
@@ -2,45 +2,28 @@
|
||||
// M up to a prefill chunk, gfx1201. C[M,N] = A[M,K] @ dequant(Wq)[N,K]^T, A quantised per row and
|
||||
// W per (row, 128-wide group).
|
||||
//
|
||||
// WHY THIS EXISTS. The INT4 target promotes 80 of its 256 linears -- every down_proj and the
|
||||
// sixteen attention o_proj -- to eight bits, because those two groups are where the 4-bit grid
|
||||
// costs the most KL. Serving those through a library int8 matmul means a composite -- rotate the
|
||||
// activation with a bf16 matmul, quantise it, call the library, then scale an int32 [M,N] back to
|
||||
// bf16 -- which is eight launches and three materialised intermediates per site, 80 sites a step.
|
||||
// It also THROWS AWAY the fused rms+Hadamard+quantise producer the 4-bit sites read: the int8 the
|
||||
// norm has already written is ignored and the bf16 is re-rotated and re-quantised.
|
||||
// Serves the linears an INT4 model promotes to eight bits (every down_proj and the attention
|
||||
// o_proj, where the 4-bit grid costs the most KL) in one launch that reads exactly what the 4-bit
|
||||
// GEMM reads: the same permuted int8 activation from the fused rms+Hadamard+quantise producer, the
|
||||
// same per-row scale, and a weight in the same fragment order at twice the radix.
|
||||
//
|
||||
// This is one launch that reads exactly what the 4-bit GEMM reads: the SAME permuted int8
|
||||
// activation buffer, the SAME per-row scale, and a weight in the same fragment order at twice the
|
||||
// radix. Nothing about the producer changes; only the GEMM does.
|
||||
// It is r4d_gemm_w4a8_nt_m64 without the unpack: the eight weight bytes are the B fragment. The A
|
||||
// fragment read, split-K reduction, per-group scale fold and per-row activation scale at the store
|
||||
// are the same.
|
||||
//
|
||||
// IT IS r4d_gemm_w4a8_nt_m64 WITH THE UNPACK DELETED. That kernel spends two v_and_b32 and one
|
||||
// v_lshlrev_b32 turning a dword of nibbles into eight int8 lanes; here the eight bytes ARE the
|
||||
// fragment, so the B operand is two dwords straight out of the load and the dequant is nothing at
|
||||
// all. Everything else -- the A fragment read, the split-K reduction, the per-group scale folded
|
||||
// with one v_cvt_f32_i32 and one fma, the per-row activation scale applied once at the store -- is
|
||||
// the same code.
|
||||
// gemm_w8a16_nt_m64 uses the f16 WMMA (207 TF/s vs 407 for iu8), which is fine for lm_head at M=8
|
||||
// (DRAM bound) but caps these sites at M=72.
|
||||
//
|
||||
// WHY NOT gemm_w8a16_nt_m64, WHICH ALREADY EXISTS. It runs v_wmma_f32_16x16x16_f16 at 207 TF/s
|
||||
// where v_wmma_i32_16x16x16_iu8 runs at 407. For lm_head at M=8 that is invisible -- the kernel is
|
||||
// at the DRAM roofline and the matrix pipe is free -- but the promoted sites run at M=8 AND at
|
||||
// M=72, and the f16 form is where the M=64 cliff in that kernel comes from. An 8-bit weight has
|
||||
// no reason to widen to 16 bits to be multiplied by an 8-bit activation.
|
||||
//
|
||||
// THE WEIGHT LAYOUT. Per n-tile t (16 output rows) and k-block kb (KPB=32 columns), 32 lanes hold
|
||||
// 16 bytes each: 512 bytes covering 16 rows x 32 k, which is TWO WMMA k steps. Byte j of lane l is
|
||||
// Weight layout: per n-tile t (16 output rows) and k-block kb (KPB=32 columns), 32 lanes hold
|
||||
// 16 bytes each, 512 bytes covering 16 rows x 32 k (two WMMA k steps). Byte j of lane l is
|
||||
//
|
||||
// W[t*16 + (l & 15)][kb*32 + 16*(j >> 3) + 8*((j & 7) >> 2) + 4*(l >> 4) + (j & 3)]
|
||||
//
|
||||
// -- the iu8 16x16x16 fragment order the A side already uses, so one permutation serves both
|
||||
// operands and the packer is the same routine at a different radix. A group is GROUP/KPB blocks
|
||||
// and its f16 scale is read once per group per n-plane, as in the 4-bit kernel.
|
||||
// the iu8 16x16x16 fragment order the A side uses, so one permutation serves both operands. A
|
||||
// group is GROUP/KPB blocks; its f16 scale is read once per group per n-plane.
|
||||
//
|
||||
// THE SCALE PLANE IS f16-ONLY, NOT THE SHARED (scale, zero) DWORD. There is no zero point on a
|
||||
// symmetric grid and this kernel is DRAM-bound at the decode batch, so the dead half of that dword
|
||||
// would be pure traffic: at group 128 it is 32 bytes per 2048 of weight, 1.5% of everything read.
|
||||
// The 4-bit kernel keeps the dword because r4d_gemm_w4a16_nt_m64 shares its bytes; nothing shares
|
||||
// these.
|
||||
// The scale plane is f16 only: a symmetric grid has no zero point, and the unused half of a
|
||||
// (scale, zero) dword would be 1.5% extra traffic on a DRAM-bound kernel.
|
||||
#include "r4d.h"
|
||||
#include "r4d_gemm_args.h"
|
||||
#include "r4d_common.h"
|
||||
@@ -50,12 +33,8 @@
|
||||
#include <cstdint>
|
||||
#include <stdexcept>
|
||||
|
||||
// Not structural: mt0 = blockIdx.y * MT tiles M and the row index is clamped into 0..M-1, so any M
|
||||
// is correct. It is a guard against a caller handing over a garbage shape.
|
||||
// Not structural (grid.y tiles M, rows are clamped); a sanity bound only.
|
||||
#define R4D_GEMM_W8A8_MAX_M 32768
|
||||
#ifndef R4D_GEMM_W8A8_GROUP
|
||||
#define R4D_GEMM_W8A8_GROUP 128
|
||||
#endif
|
||||
#define R4D_GEMM_W8A8_KPB 32 // K per packed block: 2 k steps, 16 bytes per lane
|
||||
#define WAVE32 32
|
||||
|
||||
@@ -68,65 +47,8 @@ typedef unsigned uint2v __attribute__((ext_vector_type(2)));
|
||||
typedef __attribute__((address_space(1))) const uint4v* r4d_gw8;
|
||||
typedef __attribute__((address_space(1))) const unsigned short* r4d_gs2;
|
||||
typedef __attribute__((address_space(1))) const uint2v* r4d_ga2;
|
||||
typedef __attribute__((address_space(1))) const unsigned* r4d_gu1;
|
||||
|
||||
// 0 reads A row-major, which only a harness feeding an unpermuted buffer needs; the serving path
|
||||
// always feeds the permuted buffer the quantiser writes.
|
||||
#ifndef R4D_W8A8_APERM
|
||||
#define R4D_W8A8_APERM 1
|
||||
#endif
|
||||
|
||||
// COST ABLATIONS. Wrong answers by construction; they exist to say what the time is made of.
|
||||
// 1 no scale load (sc = 1)
|
||||
// 2 no activation load (the A fragment is a constant)
|
||||
// 4 no weight load (the B fragment is a constant; leaves the A stream and the WMMA)
|
||||
#ifndef R4D_W8A8_ABL
|
||||
#define R4D_W8A8_ABL 0
|
||||
#endif
|
||||
|
||||
// SOFTWARE-PIPELINE THE WEIGHT: hold the NEXT group's weight in registers so its load is issued a
|
||||
// whole group ahead of the wait, instead of issuing two loads, waiting, and then spending the WMMA
|
||||
// block with no memory in flight. Costs bpg*NPW*4 VGPRs.
|
||||
#ifndef R4D_W8A8_PF
|
||||
#define R4D_W8A8_PF 0
|
||||
#endif
|
||||
|
||||
// STAGGER THE GROUP ORDER PER WAVE. Every plane pitch here is a multiple of 4096 and a 256-bit
|
||||
// GDDR6 part sweeps all sixteen channels in exactly 4096 bytes, so without this every wave in the
|
||||
// grid is at the same address modulo 4096 and aimed at the same channel group. Starting each wave
|
||||
// at a different group inside its OWN k-slice and wrapping changes only the order.
|
||||
// NOTE this reorders an fp32 accumulation, so results move by ~1 ULP.
|
||||
#ifndef R4D_W8A8_STAGGER
|
||||
#define R4D_W8A8_STAGGER 0
|
||||
#endif
|
||||
|
||||
#if R4D_W8A8_STAGGER
|
||||
#if R4D_W8A8_APERM
|
||||
#define AOFF8(g) ((g) * (R4D_GEMM_W8A8_GROUP / 8))
|
||||
#else
|
||||
#define AOFF8(g) ((g) * (R4D_GEMM_W8A8_GROUP / 4))
|
||||
#endif
|
||||
#else
|
||||
#define AOFF8(g) 0
|
||||
#endif
|
||||
|
||||
// HOIST THE ACTIVATION LOADS OFF THEIR WMMA.
|
||||
// Read `afrag[i]` inside the k-step loop immediately before the WMMA that consumes it and the group
|
||||
// loop gets one wait per load: at MT=5, NPW=1 that is 40 `global_load_b64`, 40 WMMA and 37
|
||||
// `s_wait_loadcnt`. The wave issues one load, stalls on it, runs one matrix instruction and issues
|
||||
// the next, so there is no memory-level parallelism and the matrix pipe is fully exposed instead of
|
||||
// co-issued. The ablations below price that exposure at a significant fraction of the kernel.
|
||||
//
|
||||
// A lane's eight A bytes for consecutive k steps are SIXTEEN bytes apart -- the intervening eight
|
||||
// belong to the other lane half -- so they cannot be merged into one b128, and the layout is fixed:
|
||||
// the same buffer feeds r4d_gemm_w4a8_nt_m64. What can change is when they are
|
||||
// issued. 1 loads the two k steps of a weight block up front (2*MT loads, then 2*NPW*MT WMMA);
|
||||
// 2 loads the whole group (2*bpg*MT), which costs bpg times the registers.
|
||||
#ifndef R4D_W8A8_AHOIST
|
||||
#define R4D_W8A8_AHOIST 2
|
||||
#endif
|
||||
|
||||
// The A fragment, byte for byte what r4d_gemm_w4a8_nt_m64 reads -- same buffer, same producer.
|
||||
// The A fragment, as r4d_gemm_w4a8_nt_m64 reads it.
|
||||
__device__ __forceinline__ v2i fragA8w(r4d_ga2 p, int u) {
|
||||
const uint2v w = p[2 * u];
|
||||
v2i r;
|
||||
@@ -135,44 +57,16 @@ __device__ __forceinline__ v2i fragA8w(r4d_ga2 p, int u) {
|
||||
return r;
|
||||
}
|
||||
|
||||
__device__ __forceinline__ v2i fragA8row(r4d_gu1 p, int u) {
|
||||
v2i r;
|
||||
r[0] = p[4 * u];
|
||||
r[1] = p[4 * u + 2];
|
||||
return r;
|
||||
}
|
||||
|
||||
__device__ __forceinline__ v8i mmai8(v2i a, v2i b, v8i c) {
|
||||
return __builtin_amdgcn_wmma_i32_16x16x16_iu8_w32_gfx12(true, a, true, b, c, false);
|
||||
}
|
||||
|
||||
// __launch_bounds__ IS A REGISTER BUDGET, AND IT HAS TO SEE MT.
|
||||
// A block of T threads is T/32 waves spread over four SIMDs, so the compiler budgets 1536/(T/128)
|
||||
// VGPRs per wave: 1024 threads leaves 192, 512 leaves 256 (the architectural cap), 256 the same.
|
||||
// The accumulator is what runs out -- `acc` is MT*NPW*8 VGPRs and `g_acc` another MT*NPW*8 while a
|
||||
// group is in flight -- so MT*NPW is the thing that decides, and a bound written in NPW alone is
|
||||
// blind to half of it. A flat bound of 1024 leaves 192 VGPRs, and under that bound
|
||||
// `-Rpass-analysis=kernel-resource-usage` reports every wide tile SPILLING:
|
||||
//
|
||||
// MT=5..8, NPW=2 192 VGPRs, 15 / 51 / 87 / 123 spilled
|
||||
// MT=3,4, NPW=4 256 VGPRs, 11 / 65 spilled
|
||||
// MT=2,3,4 NPW=8 256 VGPRs, 99 / 287 / 530 spilled
|
||||
//
|
||||
// and those are the configs M=72 wants, because MB=5 or 6 is what covers five row tiles in one
|
||||
// block. A wide tile has plenty of independent WMMA to hide latency with and does not need the
|
||||
// waves; it needs the registers. Bounding it at 256 threads gives it all 256 VGPRs.
|
||||
//
|
||||
// The bound is a REAL constraint on the launch, not a hint: a kernel built for 256 threads cannot
|
||||
// be launched with more, so the host checks WV*SK against the same expression and refuses instead
|
||||
// of failing at dispatch.
|
||||
#ifndef R4D_GEMM_W8A8_LB
|
||||
#define R4D_GEMM_W8A8_LB 1
|
||||
#endif
|
||||
#if R4D_GEMM_W8A8_LB
|
||||
// __launch_bounds__ is a register budget and depends on MT*NPW. A block of T threads gives
|
||||
// 1536/(T/128) VGPRs per wave (1024 threads: 192; 512 or fewer: the 256 cap). `acc` and `g_acc` are
|
||||
// MT*NPW*8 VGPRs each, so under a flat 1024 bound every wide tile spills. A wide tile has enough
|
||||
// independent WMMA to hide latency without more waves; bounding it at 256 threads gives it 256
|
||||
// VGPRs. The bound is a hard launch limit, so the host checks WV*SK against the same expression.
|
||||
#define R4D_W8A8_BOUNDS(MT, NPW) ((MT) * (NPW) >= 8 ? 256 : ((MT) * (NPW) >= 4 ? 512 : 1024))
|
||||
#else
|
||||
#define R4D_W8A8_BOUNDS(MT, NPW) 1024
|
||||
#endif
|
||||
|
||||
template <int MT, int NPW, bool NT>
|
||||
__global__ __launch_bounds__(R4D_W8A8_BOUNDS(MT, NPW)) void r4d_gemm_w8a8_nt_m64_kernel(
|
||||
@@ -196,24 +90,15 @@ __global__ __launch_bounds__(R4D_W8A8_BOUNDS(MT, NPW)) void r4d_gemm_w8a8_nt_m64
|
||||
for (int i = 0; i < MT; i++) acc[j][i] = (v8f)(0.f);
|
||||
|
||||
if (n0 < N) {
|
||||
// Rows clamped, never masked: a tile past M recomputes the last valid row and the store
|
||||
// discards it. A is int8, so the row stride is K bytes.
|
||||
#if R4D_W8A8_APERM
|
||||
// Rows clamped into 0..M-1, never masked; the store discards rows past M. A is int8, so the
|
||||
// row stride is K bytes.
|
||||
r4d_ga2 pa[MT];
|
||||
#else
|
||||
r4d_gu1 pa[MT];
|
||||
#endif
|
||||
#pragma unroll
|
||||
for (int i = 0; i < MT; i++) {
|
||||
int r = (mt0 + i) * 16 + (lane & 15);
|
||||
r = r < M - 1 ? r : M - 1;
|
||||
#if R4D_W8A8_APERM
|
||||
const size_t off = (size_t)r * K + kbase + 8 * (lane >> 4);
|
||||
pa[i] = (r4d_ga2)(const uint2v*)(A + off);
|
||||
#else
|
||||
const size_t off = (size_t)r * K + kbase + 4 * (lane >> 4);
|
||||
pa[i] = (r4d_gu1)(const unsigned*)(A + off);
|
||||
#endif
|
||||
}
|
||||
|
||||
const int kpb = K / R4D_GEMM_W8A8_KPB;
|
||||
@@ -232,118 +117,41 @@ __global__ __launch_bounds__(R4D_W8A8_BOUNDS(MT, NPW)) void r4d_gemm_w8a8_nt_m64
|
||||
|
||||
const int bpg = R4D_GEMM_W8A8_GROUP / R4D_GEMM_W8A8_KPB;
|
||||
|
||||
#if R4D_W8A8_PF
|
||||
uint4v nx[NPW][R4D_GEMM_W8A8_GROUP / R4D_GEMM_W8A8_KPB];
|
||||
#pragma unroll
|
||||
for (int j = 0; j < NPW; j++)
|
||||
#pragma unroll
|
||||
for (int b = 0; b < bpg; b++)
|
||||
nx[j][b] = NT ? __builtin_nontemporal_load(&pw[j][(size_t)b * WAVE32])
|
||||
: pw[j][(size_t)b * WAVE32];
|
||||
#endif
|
||||
|
||||
#if R4D_W8A8_STAGGER
|
||||
const int gstag = groups > 1 ? (wave * R4D_W8A8_STAGGER) % groups : 0;
|
||||
#endif
|
||||
for (int gi = 0; gi < groups; gi++) {
|
||||
#if R4D_W8A8_STAGGER
|
||||
const int g = gi + gstag < groups ? gi + gstag : gi + gstag - groups;
|
||||
#else
|
||||
const int g = gi;
|
||||
#endif
|
||||
for (int g = 0; g < groups; g++) {
|
||||
float sc[NPW];
|
||||
#pragma unroll
|
||||
for (int j = 0; j < NPW; j++)
|
||||
#if R4D_W8A8_ABL & 1
|
||||
sc[j] = 1.f;
|
||||
#else
|
||||
sc[j] = __half2float(__ushort_as_half(ps[j][(size_t)g * 16]));
|
||||
#endif
|
||||
|
||||
v8i g_acc[NPW][MT];
|
||||
#if R4D_W8A8_PF
|
||||
uint4v cw[NPW][R4D_GEMM_W8A8_GROUP / R4D_GEMM_W8A8_KPB];
|
||||
#pragma unroll
|
||||
for (int j = 0; j < NPW; j++)
|
||||
#pragma unroll
|
||||
for (int b = 0; b < bpg; b++) cw[j][b] = nx[j][b];
|
||||
if (g + 1 < groups) {
|
||||
#pragma unroll
|
||||
for (int j = 0; j < NPW; j++)
|
||||
#pragma unroll
|
||||
for (int b = 0; b < bpg; b++) {
|
||||
const size_t o = (size_t)((g + 1) * bpg + b) * WAVE32;
|
||||
nx[j][b] = NT ? __builtin_nontemporal_load(&pw[j][o]) : pw[j][o];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if R4D_W8A8_AHOIST == 2
|
||||
// The whole group's activation, issued before any of it is consumed.
|
||||
// The whole group's activation, issued before any of it is consumed. Loading each fragment
|
||||
// just before its WMMA gives one s_wait_loadcnt per load and no memory-level parallelism; a
|
||||
// lane's A bytes for consecutive k steps are 16 bytes apart, so they cannot merge into one
|
||||
// b128 and only the issue order can change.
|
||||
v2i afg[2 * (R4D_GEMM_W8A8_GROUP / R4D_GEMM_W8A8_KPB)][MT];
|
||||
#pragma unroll
|
||||
for (int u = 0; u < 2 * bpg; u++)
|
||||
#pragma unroll
|
||||
for (int i = 0; i < MT; i++)
|
||||
#if R4D_W8A8_ABL & 2
|
||||
{ afg[u][i][0] = 0x01010101; afg[u][i][1] = 0x01010101; }
|
||||
#elif R4D_W8A8_APERM
|
||||
afg[u][i] = fragA8w(pa[i] + AOFF8(g), u);
|
||||
#else
|
||||
afg[u][i] = fragA8row(pa[i] + AOFF8(g), u);
|
||||
#endif
|
||||
#endif
|
||||
afg[u][i] = fragA8w(pa[i], u);
|
||||
#pragma unroll
|
||||
for (int b = 0; b < bpg; b++) {
|
||||
uint4v wv[NPW];
|
||||
#pragma unroll
|
||||
for (int j = 0; j < NPW; j++) {
|
||||
#if R4D_W8A8_PF
|
||||
wv[j] = cw[j][b];
|
||||
#else
|
||||
const size_t o = (size_t)(g * bpg + b) * WAVE32;
|
||||
#if R4D_W8A8_ABL & 4
|
||||
(void)o;
|
||||
wv[j] = (uint4v)(0x01010101u);
|
||||
#else
|
||||
wv[j] = NT ? __builtin_nontemporal_load(&pw[j][o]) : pw[j][o];
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
#if R4D_W8A8_AHOIST == 1
|
||||
// Both k steps of this weight block, issued before either is consumed.
|
||||
v2i afb[2][MT];
|
||||
#pragma unroll
|
||||
for (int s = 0; s < 2; s++)
|
||||
#pragma unroll
|
||||
for (int i = 0; i < MT; i++)
|
||||
#if R4D_W8A8_ABL & 2
|
||||
{ afb[s][i][0] = 0x01010101; afb[s][i][1] = 0x01010101; }
|
||||
#elif R4D_W8A8_APERM
|
||||
afb[s][i] = fragA8w(pa[i] + AOFF8(g), b * 2 + s);
|
||||
#else
|
||||
afb[s][i] = fragA8row(pa[i] + AOFF8(g), b * 2 + s);
|
||||
#endif
|
||||
#endif
|
||||
// Two WMMA k steps per 16-byte weight load: dwords (0,1) then (2,3).
|
||||
#pragma unroll
|
||||
for (int s = 0; s < 2; s++) {
|
||||
const int u = b * 2 + s;
|
||||
v2i afrag[MT];
|
||||
#pragma unroll
|
||||
#if R4D_W8A8_AHOIST == 2
|
||||
for (int i = 0; i < MT; i++) afrag[i] = afg[u][i];
|
||||
#elif R4D_W8A8_AHOIST == 1
|
||||
for (int i = 0; i < MT; i++) afrag[i] = afb[s][i];
|
||||
#elif R4D_W8A8_ABL & 2
|
||||
for (int i = 0; i < MT; i++) { afrag[i][0] = 0x01010101; afrag[i][1] = 0x01010101; }
|
||||
#elif R4D_W8A8_APERM
|
||||
for (int i = 0; i < MT; i++) afrag[i] = fragA8w(pa[i] + AOFF8(g), u);
|
||||
#else
|
||||
for (int i = 0; i < MT; i++) afrag[i] = fragA8row(pa[i] + AOFF8(g), u);
|
||||
#endif
|
||||
#pragma unroll
|
||||
for (int j = 0; j < NPW; j++) {
|
||||
// The eight bytes ARE the fragment: no mask, no shift, no zero point.
|
||||
// The eight weight bytes are the fragment.
|
||||
v2i bfrag;
|
||||
bfrag[0] = (int)wv[j][2 * s];
|
||||
bfrag[1] = (int)wv[j][2 * s + 1];
|
||||
@@ -361,28 +169,17 @@ __global__ __launch_bounds__(R4D_W8A8_BOUNDS(MT, NPW)) void r4d_gemm_w8a8_nt_m64
|
||||
#pragma unroll
|
||||
for (int e = 0; e < 8; e++)
|
||||
acc[j][i][e] = fmaf((float)g_acc[j][i][e], sc[j], acc[j][i][e]);
|
||||
#if !R4D_W8A8_STAGGER
|
||||
#pragma unroll
|
||||
#if R4D_W8A8_APERM
|
||||
for (int i = 0; i < MT; i++) pa[i] += R4D_GEMM_W8A8_GROUP / 8;
|
||||
#else
|
||||
for (int i = 0; i < MT; i++) pa[i] += R4D_GEMM_W8A8_GROUP / 4;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// Split-K reduction and store, one row tile at a time. The per-row activation scale is applied
|
||||
// here and only here: it is constant over n and over the group index, so it never entered the
|
||||
// k loop.
|
||||
// Split-K reduction and store, one row tile at a time, applying the per-row activation scale.
|
||||
const int ncols = WV * NPW;
|
||||
const int nthreads = WV * SK * WAVE32;
|
||||
|
||||
// AT SK == 1 THERE IS NOTHING TO REDUCE. The general path below writes eight floats per
|
||||
// accumulator to LDS and reads them straight back, and pays two __syncthreads() per row tile to
|
||||
// do it -- MB row tiles is MB barrier pairs on a kernel whose whole job is to keep a load in
|
||||
// flight. With one k-slice a lane already holds the finished value, and the same (m, n) it
|
||||
// would have landed on is just the LDS index arithmetic with off = e*32 + lane substituted in.
|
||||
// At SK == 1 there is nothing to reduce: store directly and skip the two barriers per row tile.
|
||||
// (m, n) is the LDS path's index arithmetic with off = e*32 + lane.
|
||||
if (SK == 1) {
|
||||
if (n0 >= N) return;
|
||||
#pragma unroll
|
||||
@@ -432,14 +229,8 @@ void r4d_gemm_w8a8_nt_m64(long a, long ascale, long wq, long ws, long c, int M,
|
||||
throw std::runtime_error("r4d gemm_w8a8_nt_m64: K must be divisible by SK*group");
|
||||
if (WV * SK * WAVE32 > R4D_W8A8_BOUNDS(MB, NPW))
|
||||
throw std::runtime_error("r4d gemm_w8a8_nt_m64: WV*SK*32 exceeds this tile's launch bound");
|
||||
// MB RUNS TO EIGHT, AND THAT IS THE WHOLE POINT AT M = 72. A block covers MB row tiles and
|
||||
// grid.y takes the rest, so every extra grid.y walks the WHOLE weight again -- the same
|
||||
// "seventeen rows is two macro tiles" that makes a library GEMM read a 636 MB lm_head twice. At
|
||||
// eight concurrent sequences the target verifies 8 x 9 = 72 rows, which is mtiles = 5, so a cap
|
||||
// of 4 would force grid.y = 2 and read the whole weight twice to do LESS work than M = 64 does
|
||||
// in one pass. Five is the shape the model actually runs.
|
||||
if (MB < 1 || MB > 8) throw std::runtime_error("r4d gemm_w8a8_nt_m64: MB must be 1..8");
|
||||
if (MB * NPW > 10) throw std::runtime_error("r4d gemm_w8a8_nt_m64: MB*NPW > 10 would spill");
|
||||
// cfg_for (r4d_gemm_args.h) caps MB at 4.
|
||||
if (MB < 1 || MB > 4) throw std::runtime_error("r4d gemm_w8a8_nt_m64: MB must be 1..4");
|
||||
if (NPW != 1 && NPW != 2 && NPW != 4 && NPW != 8)
|
||||
throw std::runtime_error("r4d gemm_w8a8_nt_m64: NPW must be 1, 2, 4 or 8");
|
||||
const int ntiles = N / 16, mtiles = (M + 15) / 16;
|
||||
@@ -455,39 +246,24 @@ void r4d_gemm_w8a8_nt_m64(long a, long ascale, long wq, long ws, long c, int M,
|
||||
hipStream_t st = (hipStream_t)stream;
|
||||
#define LAUNCH8(MT, NP, TT) hipLaunchKernelGGL((r4d_gemm_w8a8_nt_m64_kernel<MT, NP, TT>), \
|
||||
grid, block, smem, st, Ap, Sp, Wp, Zp, Cp, M, K, N, WV, SK)
|
||||
// WHICH (MT, NPW) EXIST AT ALL. `acc` is MT*NPW*8 VGPRs and `g_acc` another MT*NPW*8 while a
|
||||
// group is in flight, so a tile costs 16*MT*NPW registers plus about forty of addressing against
|
||||
// an architectural cap of 256 -- and `-Rpass-analysis=kernel-resource-usage` puts the boundary
|
||||
// exactly where that predicts: MT*NPW = 10 lands at 207 VGPRs and does not spill, 12 spills 33,
|
||||
// and 16 spills 119 to 530. A spilling tile can never win, so it is not built: it would only cost
|
||||
// compile time and give the tuner configs to reject.
|
||||
#define LAUNCH8_MB8(NP, TT) switch (MB) { \
|
||||
// Only tiles with MT*NPW <= 8 are built: a tile costs about 16*MT*NPW + 40 VGPRs against the 256
|
||||
// cap.
|
||||
#define LAUNCH8_MB4(NP, TT) switch (MB) { \
|
||||
case 1: LAUNCH8(1, NP, TT); break; \
|
||||
case 2: LAUNCH8(2, NP, TT); break; \
|
||||
case 3: LAUNCH8(3, NP, TT); break; \
|
||||
case 4: LAUNCH8(4, NP, TT); break; \
|
||||
case 5: LAUNCH8(5, NP, TT); break; \
|
||||
case 6: LAUNCH8(6, NP, TT); break; \
|
||||
case 7: LAUNCH8(7, NP, TT); break; \
|
||||
case 8: LAUNCH8(8, NP, TT); break; \
|
||||
default: throw std::runtime_error("r4d gemm_w8a8_nt_m64: MB unsupported"); }
|
||||
#define LAUNCH8_MB5(NP, TT) switch (MB) { \
|
||||
case 1: LAUNCH8(1, NP, TT); break; \
|
||||
case 2: LAUNCH8(2, NP, TT); break; \
|
||||
case 3: LAUNCH8(3, NP, TT); break; \
|
||||
case 4: LAUNCH8(4, NP, TT); break; \
|
||||
case 5: LAUNCH8(5, NP, TT); break; \
|
||||
default: throw std::runtime_error("r4d gemm_w8a8_nt_m64: MB*NPW > 10 would spill"); }
|
||||
#define LAUNCH8_MB2(NP, TT) switch (MB) { \
|
||||
case 1: LAUNCH8(1, NP, TT); break; \
|
||||
case 2: LAUNCH8(2, NP, TT); break; \
|
||||
default: throw std::runtime_error("r4d gemm_w8a8_nt_m64: MB*NPW > 10 would spill"); }
|
||||
default: throw std::runtime_error("r4d gemm_w8a8_nt_m64: MB*NPW > 8 would spill"); }
|
||||
#define LAUNCH8_MB1(NP, TT) switch (MB) { \
|
||||
case 1: LAUNCH8(1, NP, TT); break; \
|
||||
default: throw std::runtime_error("r4d gemm_w8a8_nt_m64: MB*NPW > 10 would spill"); }
|
||||
default: throw std::runtime_error("r4d gemm_w8a8_nt_m64: MB*NPW > 8 would spill"); }
|
||||
#define LAUNCH8_NPW(TT) switch (NPW) { \
|
||||
case 1: LAUNCH8_MB8(1, TT); break; \
|
||||
case 2: LAUNCH8_MB5(2, TT); break; \
|
||||
case 1: LAUNCH8_MB4(1, TT); break; \
|
||||
case 2: LAUNCH8_MB4(2, TT); break; \
|
||||
case 4: LAUNCH8_MB2(4, TT); break; \
|
||||
case 8: LAUNCH8_MB1(8, TT); break; \
|
||||
default: throw std::runtime_error("r4d gemm_w8a8_nt_m64: NPW must be 1, 2, 4 or 8"); }
|
||||
@@ -495,20 +271,17 @@ void r4d_gemm_w8a8_nt_m64(long a, long ascale, long wq, long ws, long c, int M,
|
||||
#undef LAUNCH8_NPW
|
||||
#undef LAUNCH8_MB1
|
||||
#undef LAUNCH8_MB2
|
||||
#undef LAUNCH8_MB5
|
||||
#undef LAUNCH8_MB8
|
||||
#undef LAUNCH8_MB4
|
||||
#undef LAUNCH8
|
||||
}
|
||||
|
||||
int r4d_gemm_w8a8_nt_m64_max_m(void) { return R4D_GEMM_W8A8_MAX_M; }
|
||||
int r4d_gemm_w8a8_nt_m64_group(void) { return R4D_GEMM_W8A8_GROUP; }
|
||||
int r4d_gemm_w8a8_nt_m64_kpb(void) { return R4D_GEMM_W8A8_KPB; }
|
||||
int r4d_gemm_w8a8_nt_m64_aperm(void) { return R4D_W8A8_APERM; }
|
||||
|
||||
// ============================================================== 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_w8a8_m64(const RadArgs* a, RadStream s) {
|
||||
GemmOps g;
|
||||
int rc = gemm_ops(a, &g, 1);
|
||||
|
||||
Reference in new issue
Block a user