Archived
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.
This commit is contained in:
commit
9ed3ef7a7b
452 files changed
+167762
-1346
No files matched your search
+89
-204
@@ -55,20 +55,8 @@ constexpr uint32_t kBlock = 128;
|
||||
// bandwidth; 128 B is also full speed; 512 B needs 64 VGPRs of prefetch and does not build).
|
||||
constexpr uint32_t kFKNarrow = 256;
|
||||
|
||||
// ---- the prefill tile's geometry ---------------------------------------------------------------
|
||||
//
|
||||
// A block owns 128 weight rows x 128 activation rows: eight waves as kPWW (weight) x kPWA
|
||||
// (activation), each wave kPTW weight tiles x kPTA activation tiles of 16 x 16. Eight accumulator
|
||||
// tiles a wave is a hard cap: each is two f32 sets (`raw` and `out`), so more spills. The staged K
|
||||
// tile is kPFK bytes, two per 128-column scale block. See gemm_8a8_prefill_kernel for the layout
|
||||
// and what was measured.
|
||||
constexpr uint32_t kPTW = 2, kPTA = 4, kPWW = 4, kPWA = 2;
|
||||
constexpr uint32_t kPBN = kPWW * kPTW * 16, kPBM = kPWA * kPTA * 16; // weight x activation rows
|
||||
constexpr uint32_t kPWaves = kPWW * kPWA;
|
||||
constexpr uint32_t kPFK = 64;
|
||||
static_assert(kPBN == kBlock, "a block's weight rows are one scale row");
|
||||
// Activation bands per raster group of the prefill tile; see the kernel's grouping.
|
||||
constexpr uint32_t kGroupM = 8;
|
||||
// ---- the prefill tile: its geometry and body (shared with the IQR tile) ------------------------
|
||||
#include "r4d_gemm_8a8_prefill.h"
|
||||
|
||||
// Blocks the split aims for. A fixed tuning default, not derived from the CU count: `ksplit` sets
|
||||
// the order K partials are summed in, so deriving it would make output depend on the card.
|
||||
@@ -754,190 +742,13 @@ __global__ void splitk_reduce_kernel(const float* __restrict__ ws, uint16_t* __r
|
||||
y[i] = f32_to_bf16(acc);
|
||||
}
|
||||
|
||||
// ---- the prefill tile ---------------------------------------------------------------------------
|
||||
//
|
||||
// 128 weight rows x 128 activation rows a block, eight waves as kPWW (weight) x kPWA (activation),
|
||||
// a wave kPTW weight tiles x kPTA activation tiles. The weight is the WMMA A operand, read from the
|
||||
// fragment-order plane straight into registers: a lane's 32 bytes are its four fragments for 64 k,
|
||||
// so a wave's load is one contiguous KiB and the weight never touches LDS. The activation is the B
|
||||
// operand, staged through LDS and read by the four waves that share its rows. A lane's accumulator
|
||||
// is eight consecutive weight rows of one activation row, so the fold takes one activation scale a
|
||||
// lane a tile (and the block's one weight scale), and the store is one 16-byte write.
|
||||
//
|
||||
// What decides the layout is LDS bandwidth. gfx1201 serves 64 bytes of LDS a clock per CU, loads
|
||||
// and stores alike, and issues an fp8 WMMA every 8 clocks per SIMD, so a CU has 256 bytes of LDS
|
||||
// per WMMA at the WMMA rate (libr4d/isa/wmmamix.hip). Staging both operands with one activation
|
||||
// tile x eight weight tiles a wave moves 288 bytes of fragment reads and 64 of stores per WMMA,
|
||||
// which alone caps a loop at ~73% of the WMMA rate (measured with nothing else in it). This layout
|
||||
// reads 128 bytes and stores 32 per WMMA, and the weight's 64 bytes come through the vector cache.
|
||||
//
|
||||
// At the 300 W limit every GEMM shape here is power-bound (sclk 2.1-2.3 GHz against 2.55 for bare
|
||||
// WMMA on random operands), so a variant's speed tracks the bytes it moves as much as the
|
||||
// instructions it issues. Measured against the both-operands-through-LDS 1x8 tile at the DiT's
|
||||
// shapes (M 18648) and LLM prefill shapes (M 300-4096), 160 TFLOP/s at gate_up:
|
||||
// - this layout with the per-row activation scales gathered from global, mul + add fold: +12%;
|
||||
// - the activation scales staged through LDS (`s_as`), one row a thread: +4%. A lane's gather
|
||||
// touched sixteen cachelines a load, more bytes than its weight fragments;
|
||||
// - the fold as one fma instead of a rounded multiply and an add: +4-5%. Not bit-identical to
|
||||
// the separate multiply (rel_l2 ~2e-5 against it, both well inside bf16 output);
|
||||
// - unconditional prefetch (the last tile's prefetch re-reads the last tile, discarded): +1%.
|
||||
// A conditional load joins two paths with different counts and the compiler waits for zero;
|
||||
// - the LDS-only barrier (lds_barrier) instead of __syncthreads: +1%; the latter's release waits
|
||||
// for every outstanding load, the weight prefetch included;
|
||||
// - kGroupM 8 instead of 16: +1-3%; 4 ties 8.
|
||||
// Measured and rejected:
|
||||
// - 2 x 4 waves of 4 weight x 2 activation tiles (half the LDS reads, twice the weight bytes
|
||||
// through the vector cache): 3-5% slower;
|
||||
// - 8 x 1 waves (256 x 64 blocks, no weight tile read twice in a block): ties at o and gate_up;
|
||||
// - the weight two tiles ahead: 240 VGPRs and scratch spills, 25-38% slower;
|
||||
// - 12 or 16 waves (192 or 256 activation rows a block, up to a quarter less L2 traffic): ties
|
||||
// to 1% slower, a higher clock at a lower rate per clock;
|
||||
// - four threads an activation row, 16 bytes each (whole 64-byte segments a load): neutral;
|
||||
// - raw buffer loads with 32-bit offsets for both operands: 20% slower;
|
||||
// - s_setprio around the WMMA run: neutral. CU mode (-mcumode): ~10% slower.
|
||||
template <bool I8>
|
||||
template <bool I8, int RB = 0>
|
||||
__global__ __launch_bounds__(kPWaves * kWave) R4D_WAVES(6)
|
||||
void gemm_8a8_prefill_kernel(const uint8_t* __restrict__ A, const float* __restrict__ Sa,
|
||||
const uint8_t* __restrict__ W, const uint16_t* __restrict__ Sw,
|
||||
uint16_t* __restrict__ C, uint32_t M, uint32_t K, uint32_t N,
|
||||
uint32_t a_ld, uint32_t sa_ld, uint32_t sw_ld) {
|
||||
constexpr uint32_t P = lds_pitch<kPFK>();
|
||||
static_assert(kPBM * 2u == kPWaves * kWave, "two threads stage an activation row");
|
||||
// Double-buffered: one barrier a staged tile, which publishes it.
|
||||
__shared__ __attribute__((aligned(16))) uint8_t s_a[2][kPBM * P];
|
||||
// The activation scales of the current and the next 128-column block, one per block row.
|
||||
__shared__ float s_as[2][kPBM];
|
||||
|
||||
const uint32_t tid = threadIdx.x, lane = tid % kWave;
|
||||
// Uniform per wave, and through readfirstlane known so, so what derives from it stays scalar.
|
||||
const uint32_t wave = __builtin_amdgcn_readfirstlane(tid / kWave);
|
||||
const uint32_t ww = wave % kPWW, wa = wave / kPWW;
|
||||
|
||||
// The grid runs in groups of kGroupM activation bands. Blocks dispatch in flattened-id order;
|
||||
// with the plain x-fastest grid the activation is read once per 128 weight rows, which halves
|
||||
// the rate once it exceeds the 64 MB MALL. Within a group the bands stay cached across the N
|
||||
// sweep and the weight is read once per group. With kGroupM bands or fewer the plain order is
|
||||
// used and the division skipped.
|
||||
uint32_t bm = blockIdx.x, bn = blockIdx.y;
|
||||
if (gridDim.x > kGroupM) {
|
||||
const uint32_t per = kGroupM * gridDim.y;
|
||||
const uint32_t lin = blockIdx.y * gridDim.x + blockIdx.x;
|
||||
const uint32_t first = (lin / per) * kGroupM, r = lin % per;
|
||||
const uint32_t gm = min(gridDim.x - first, kGroupM);
|
||||
bm = first + r % gm;
|
||||
bn = r / gm;
|
||||
}
|
||||
const uint32_t m0 = bm * kPBM, n0 = bn * kPBN;
|
||||
const uint32_t ksuper = K / kSuperK, nkb = K / kBlock;
|
||||
|
||||
// Staging: two threads a row, 32 bytes each. Rows past M re-read row M-1, and every load is
|
||||
// issued unconditionally (the last tile's prefetch re-reads the last tile), so the loop has no
|
||||
// branch and its waits count exactly; nothing past M is stored.
|
||||
const uint32_t sr = tid / 2u, sc = (tid % 2u) * 32u;
|
||||
const uint8_t* const asrc = A + (size_t)min(m0 + sr, M - 1u) * a_ld + sc;
|
||||
// Thread t loads the scale of block row t % 128; both threads of a row write the same value.
|
||||
const float* const ssrc = Sa + (size_t)min(m0 + tid % kPBM, M - 1u) * sa_ld;
|
||||
// This wave's weight tiles, kTileBytes a 64-k supertile, `ksuper` supertiles a tile row.
|
||||
const uint32_t wt0 = n0 / 16u + ww * kPTW;
|
||||
const uint8_t* const wsrc = W + (size_t)wt0 * ksuper * kTileBytes + lane * kLaneBytes;
|
||||
// Activation rows this wave reads from the staged tile, and the lane's column in each.
|
||||
const uint32_t arow = wa * kPTA * 16u;
|
||||
|
||||
f8v raw[kPTW][kPTA], out[kPTW][kPTA];
|
||||
#pragma unroll
|
||||
for (uint32_t i = 0; i < kPTW; ++i)
|
||||
#pragma unroll
|
||||
for (uint32_t j = 0; j < kPTA; ++j) out[i][j] = acc_zero();
|
||||
|
||||
Stage8 pa = stage8_load(asrc, true);
|
||||
Stage8 w0[kPTW], w1[kPTW];
|
||||
#pragma unroll
|
||||
for (uint32_t i = 0; i < kPTW; ++i)
|
||||
w0[i] = stage8_load(wsrc + (size_t)i * ksuper * kTileBytes, true);
|
||||
s_as[0][tid % kPBM] = ssrc[0];
|
||||
float scn = ssrc[min(1u, nkb - 1u)];
|
||||
|
||||
/* One staged K tile, the first or second half of scale block `kb`: publish the activation
|
||||
* tile (and in the second half the next block's scales), issue the next tile's loads, then four
|
||||
* k steps from `cur`. The first k step of a block starts from a zero accumulator, so `raw` needs
|
||||
* no clearing after the fold. */
|
||||
auto tile = [&](uint32_t kb, uint32_t half, Stage8 (&cur)[kPTW], Stage8 (&nxt)[kPTW]) {
|
||||
stage8_store<kPFK>(s_a[half], sr, sc, pa);
|
||||
if (half == 1u) s_as[(kb + 1u) % 2u][tid % kPBM] = scn;
|
||||
lds_barrier();
|
||||
const uint32_t c1 = min(kb * kBlock + (half + 1u) * kPFK, K - kPFK);
|
||||
pa = stage8_load(asrc + c1, true);
|
||||
#pragma unroll
|
||||
for (uint32_t i = 0; i < kPTW; ++i)
|
||||
nxt[i] = stage8_load(wsrc + ((size_t)i * ksuper + c1 / kSuperK) * kTileBytes, true);
|
||||
if (half == 1u) scn = ssrc[min(kb + 2u, nkb - 1u)];
|
||||
#pragma unroll
|
||||
for (uint32_t ks = 0; ks < kPFK / kK; ++ks) {
|
||||
i2v bf[kPTA];
|
||||
#pragma unroll
|
||||
for (uint32_t j = 0; j < kPTA; ++j) bf[j] = frag<kPFK>(s_a[half], arow + j * 16u, ks * kK, lane);
|
||||
#pragma unroll
|
||||
for (uint32_t i = 0; i < kPTW; ++i) {
|
||||
const i2v af = frag_of(cur[i], ks);
|
||||
#pragma unroll
|
||||
for (uint32_t j = 0; j < kPTA; ++j)
|
||||
raw[i][j] = mma8<I8>(af, bf[j], (half == 0u && ks == 0u) ? acc_zero() : raw[i][j]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
for (uint32_t kb = 0; kb < nkb; ++kb) {
|
||||
// The weight's scales for this block, read ahead of the two tiles that hide them: one bf16
|
||||
// for the block's 128 rows, or with I8 one per row, a lane's eight rows of a tile adjacent
|
||||
// in the tile-major [N/16][K/128][16] plane.
|
||||
float ws = 0.0f;
|
||||
uint4 w8[I8 ? kPTW : 1u];
|
||||
if constexpr (I8) {
|
||||
#pragma unroll
|
||||
for (uint32_t i = 0; i < kPTW; ++i)
|
||||
w8[i] = *(const uint4*)(Sw + ((size_t)(wt0 + i) * nkb + kb) * 16u + (lane >> 4) * 8u);
|
||||
} else {
|
||||
ws = bscale(Sw[(size_t)(n0 / kBlock) * sw_ld + kb]);
|
||||
}
|
||||
tile(kb, 0u, w0, w1);
|
||||
tile(kb, 1u, w1, w0);
|
||||
#pragma unroll
|
||||
for (uint32_t j = 0; j < kPTA; ++j) {
|
||||
const float as = s_as[kb % 2u][arow + j * 16u + frag_c(lane)];
|
||||
#pragma unroll
|
||||
for (uint32_t i = 0; i < kPTW; ++i) {
|
||||
float s[8];
|
||||
if constexpr (I8) {
|
||||
const uint32_t d[4] = { w8[i].x, w8[i].y, w8[i].z, w8[i].w };
|
||||
#pragma unroll
|
||||
for (uint32_t t = 0; t < 8; ++t)
|
||||
s[t] = as * bscale((uint16_t)(d[t / 2] >> (16 * (t % 2))));
|
||||
} else {
|
||||
#pragma unroll
|
||||
for (uint32_t t = 0; t < 8; ++t) s[t] = ws * as;
|
||||
}
|
||||
#pragma unroll
|
||||
for (uint32_t t = 0; t < 8; ++t)
|
||||
out[i][j][t] = __builtin_fmaf(acc_val<I8>(raw[i][j][t]), s[t], out[i][j][t]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// D is [weight row][activation row]: eight consecutive columns of one C row a lane a tile.
|
||||
#pragma unroll
|
||||
for (uint32_t i = 0; i < kPTW; ++i)
|
||||
#pragma unroll
|
||||
for (uint32_t j = 0; j < kPTA; ++j) {
|
||||
const uint32_t m = m0 + arow + j * 16u + frag_c(lane);
|
||||
const uint32_t n = n0 + (ww * kPTW + i) * 16u + acc_row(lane, 0);
|
||||
if (m < M) {
|
||||
const f8v v = out[i][j];
|
||||
/* Packed in whole registers (bf16x2_rne, f32_to_bf16's bits). */
|
||||
*(uint4*)(C + (size_t)m * N + n) =
|
||||
make_uint4(bf16x2_rne(v[0], v[1]), bf16x2_rne(v[2], v[3]),
|
||||
bf16x2_rne(v[4], v[5]), bf16x2_rne(v[6], v[7]));
|
||||
}
|
||||
}
|
||||
gemm_8a8_prefill_body<I8, RB>(A, Sa, W, Sw, C, M, K, N, a_ld, sa_ld, sw_ld, PrefillPlain{});
|
||||
}
|
||||
|
||||
// ---- the prefill tile, gated -------------------------------------------------------------------
|
||||
@@ -1135,13 +946,19 @@ constexpr uint32_t kMaxCtr = 8192;
|
||||
* (rad_kernel_concurrent); overlapping launches on one stream write disjoint outputs, and launches
|
||||
* sharing an output on one stream are ordered by their dependency. A step has a few dozen distinct
|
||||
* outputs at fixed arena addresses, so this is a few dozen 32 KiB blocks, allocated once. A block
|
||||
* is never freed: a recorded pass replays the pointer. */
|
||||
* is never freed: a recorded pass replays the pointer.
|
||||
*
|
||||
* The lock is not held while a block is made. Zeroing it waits for the card, and under tensor
|
||||
* parallelism the card can be inside an all-reduce whose other half the peer rank has yet to issue;
|
||||
* if the peer's first launch of a split GEMM then waited on this lock, neither rank would advance. */
|
||||
unsigned int* split_ctr(RadStream s, const void* out) {
|
||||
static std::mutex m;
|
||||
static std::map<std::pair<RadStream, const void*>, unsigned int*> blocks;
|
||||
std::lock_guard<std::mutex> lk(m);
|
||||
const auto key = std::make_pair(s, out);
|
||||
if (auto it = blocks.find(key); it != blocks.end()) return it->second;
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(m);
|
||||
if (auto it = blocks.find(key); it != blocks.end()) return it->second;
|
||||
}
|
||||
void* p = nullptr;
|
||||
if (hipMalloc(&p, (size_t)kMaxCtr * sizeof(unsigned int)) != hipSuccess) return nullptr;
|
||||
/* Zero before any launch reads it. In the engine hipMemset is the AQL backend's and has
|
||||
@@ -1152,8 +969,15 @@ unsigned int* split_ctr(RadStream s, const void* out) {
|
||||
(void)hipFree(p);
|
||||
return nullptr;
|
||||
}
|
||||
blocks.emplace(key, (unsigned int*)p);
|
||||
return (unsigned int*)p;
|
||||
unsigned int* kept = nullptr;
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(m);
|
||||
const auto [it, fresh] = blocks.emplace(key, (unsigned int*)p);
|
||||
if (fresh) return it->second;
|
||||
kept = it->second;
|
||||
}
|
||||
(void)hipFree(p); // another thread made this key's block in the meantime
|
||||
return kept;
|
||||
}
|
||||
// The narrow tile's wave count MW, which is its M tile: the wave grid is MW x 1, so a block covers
|
||||
// MW*16 weight rows and the grid over N is N/(MW*16). The rule is fitted together with
|
||||
@@ -1219,15 +1043,23 @@ uint32_t narrow_mw(uint32_t n, uint32_t m) {
|
||||
* must agree. */
|
||||
inline uint32_t narrow_fk(uint32_t K) { return (K % kFKNarrow == 0u) ? kFKNarrow : 128u; }
|
||||
|
||||
/* Test hook behind r4d_gemm_i8a8_pin_split_waves: zero is each caller's own target, anything else
|
||||
* overrides every call's. The selftest pins the IQR narrow tile's target around its int8
|
||||
* reference, so the two sum their K partials in one order and compare to the byte. */
|
||||
std::atomic<uint32_t> g_split_waves_force{0u};
|
||||
|
||||
// The split, given the narrow grid. Shared by the scratch query and the launch so they agree on the
|
||||
// number of partial planes. `short_unsplit` is the `gemm_nt_q_short` row's opt-in (see below).
|
||||
// `target` is the waves the split aims for: kSplitTarget for the fp8a8 and i8a8 tiles; the IQR
|
||||
// narrow tile (r4d_gemm_iqr.hip), whose waves decode before they multiply, asks for more.
|
||||
uint32_t narrow_ksplit(uint32_t N, uint32_t K, uint32_t M, uint32_t* ck_out,
|
||||
bool short_unsplit = false) {
|
||||
bool short_unsplit = false, uint32_t target = kSplitTarget) {
|
||||
*ck_out = 0;
|
||||
if (const uint32_t f = g_split_waves_force.load(std::memory_order_relaxed)) target = f;
|
||||
const uint32_t mw = narrow_mw(N, M);
|
||||
const uint32_t fm = mw * 16u; // the narrow tile is one M tile a wave
|
||||
const uint32_t gx = (N + fm - 1) / fm; // the M grid runs over the weight rows
|
||||
if (K < 512u || gx * mw >= kSplitTarget) return 1;
|
||||
if (K < 512u || gx * mw >= target) return 1;
|
||||
/* A narrow weight (N <= 512, the attention k/v projections) at more than 40 tokens: the split
|
||||
* runs into a cliff there (gfx1200, cold weights: N = 512, K = 2048, M = 44..64 split 51-54 us,
|
||||
* unsplit 23-26; K = 5120, M = 41..64 58-63 against 40-48), while at K >= 8192 the split still
|
||||
@@ -1236,7 +1068,7 @@ uint32_t narrow_ksplit(uint32_t N, uint32_t K, uint32_t M, uint32_t* ck_out,
|
||||
* opt-in: only `gemm_nt_q_short`, whose declaration the model owns, takes it, and every other
|
||||
* caller keeps the split and its bits. */
|
||||
if (short_unsplit && N <= 512u && M > 40u && K <= 5120u) return 1;
|
||||
const uint32_t want = (kSplitTarget + gx * mw - 1) / (gx * mw);
|
||||
const uint32_t want = (target + gx * mw - 1) / (gx * mw);
|
||||
uint32_t ckw = ((K / want) + kBlock - 1u) / kBlock * kBlock;
|
||||
if (ckw < kBlock) ckw = kBlock;
|
||||
uint32_t k2 = (K + ckw - 1) / ckw;
|
||||
@@ -1255,6 +1087,14 @@ uint32_t narrow_ksplit(uint32_t N, uint32_t K, uint32_t M, uint32_t* ck_out,
|
||||
|
||||
} // namespace
|
||||
|
||||
/* The narrow tile's grid and split rules and its finisher's counters, for the IQR narrow tile
|
||||
* (r4d_gemm_iqr.hip): its split sums each output as this tile's does. */
|
||||
uint32_t r4d_8a8_narrow_mw(uint32_t n, uint32_t m) { return narrow_mw(n, m); }
|
||||
uint32_t r4d_8a8_narrow_ksplit(uint32_t N, uint32_t K, uint32_t M, uint32_t* ck, uint32_t target) {
|
||||
return narrow_ksplit(N, K, M, ck, false, target);
|
||||
}
|
||||
unsigned int* r4d_8a8_split_ctr(RadStream s, const void* out) { return split_ctr(s, out); }
|
||||
|
||||
// ================================================================== the entry points
|
||||
|
||||
extern "C" int r4d_gemm_fp8a8_block(void) { return (int)kBlock; }
|
||||
@@ -1275,6 +1115,10 @@ extern "C" int r4d_gemm_fp8a8_nt_m16_max_m(void) { return 64; }
|
||||
|
||||
/* See r4d.h. Only instantiated wave counts are accepted; anything else clears the override rather
|
||||
* than falling through to the dispatch's last arm. */
|
||||
extern "C" void r4d_gemm_i8a8_pin_split_waves(int waves) {
|
||||
g_split_waves_force.store(waves > 0 ? (uint32_t)waves : 0u, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
extern "C" void r4d_gemm_fp8a8_pin_mw(int mw) {
|
||||
const uint32_t v = (mw == 1 || mw == 2 || mw == 4 || mw == 8 || mw == 16) ? (uint32_t)mw : 0u;
|
||||
g_mw_force.store(v, std::memory_order_relaxed);
|
||||
@@ -1590,7 +1434,7 @@ static int gemm_fp8a8_gated_launch(long a, long ascale, long wq, long ws, long q
|
||||
// The same GEMM for prefill row counts: same operands and layouts, the 128x128 prefill tile
|
||||
// (gemm_8a8_prefill_kernel). No split-K: the grid is ceil(M/128) x N/128, hundreds of blocks at any
|
||||
// prefill shape.
|
||||
template <bool I8>
|
||||
template <bool I8, int RB = 0>
|
||||
static int gemm_8a8_tiled(long a, long ascale, long wq, long ws, long c, int M, int K, int N,
|
||||
int a_ld, int sa_ld, int w_ld, int sw_ld, long stream);
|
||||
|
||||
@@ -1608,6 +1452,23 @@ extern "C" int r4d_gemm_i8a8_tiled(long a, long ascale, long wq, long ws, long c
|
||||
return gemm_8a8_tiled<true>(a, ascale, wq, ws, c, M, K, N, a_ld, sa_ld, w_ld, sw_ld, stream);
|
||||
}
|
||||
|
||||
// The same with the weight's scale one per 8 rows and 128 K (each row of the plane holding its
|
||||
// block's value), folded as the fp8 tile folds (gemm_8a8_prefill_kernel's RB).
|
||||
extern "C" int r4d_gemm_i8a8_rb8_tiled(long a, long ascale, long wq, long ws, long c,
|
||||
int M, int K, int N, int a_ld, int sa_ld, int w_ld,
|
||||
int sw_ld, long stream) {
|
||||
return gemm_8a8_tiled<true, 8>(a, ascale, wq, ws, c, M, K, N, a_ld, sa_ld, w_ld, sw_ld,
|
||||
stream);
|
||||
}
|
||||
|
||||
// The same at a weight scale per 32 rows, a wave's: the fp8 tile's fold.
|
||||
extern "C" int r4d_gemm_i8a8_rb32_tiled(long a, long ascale, long wq, long ws, long c,
|
||||
int M, int K, int N, int a_ld, int sa_ld, int w_ld,
|
||||
int sw_ld, long stream) {
|
||||
return gemm_8a8_tiled<true, 32>(a, ascale, wq, ws, c, M, K, N, a_ld, sa_ld, w_ld, sw_ld,
|
||||
stream);
|
||||
}
|
||||
|
||||
extern "C" int r4d_gemm_i8a8_nt_m16(long a, long ascale, long wq, long ws, long c,
|
||||
int M, int K, int N, int a_ld, int sa_ld, int w_ld, int sw_ld,
|
||||
long scratch, long scratch_bytes, long stream) {
|
||||
@@ -1615,7 +1476,7 @@ extern "C" int r4d_gemm_i8a8_nt_m16(long a, long ascale, long wq, long ws, long
|
||||
scratch, scratch_bytes, (RadStream)(uintptr_t)stream, true);
|
||||
}
|
||||
|
||||
template <bool I8>
|
||||
template <bool I8, int RB>
|
||||
static int gemm_8a8_tiled(long a, long ascale, long wq, long ws, long c, int M, int K, int N,
|
||||
int a_ld, int sa_ld, int w_ld, int sw_ld, long stream) {
|
||||
if (!a || !ascale || !wq || !ws || !c) return -1;
|
||||
@@ -1633,7 +1494,7 @@ static int gemm_8a8_tiled(long a, long ascale, long wq, long ws, long c, int M,
|
||||
if (!sw_ld) sw_ld = nkb;
|
||||
|
||||
const dim3 grid(((uint32_t)M + kPBM - 1) / kPBM, (uint32_t)N / kPBN, 1);
|
||||
const int rc = R4D_EMIT((RadStream)(uintptr_t)stream, gemm_8a8_prefill_kernel<I8>, grid,
|
||||
const int rc = R4D_EMIT((RadStream)(uintptr_t)stream, (gemm_8a8_prefill_kernel<I8, RB>), grid,
|
||||
dim3(kPWaves * kWave), 0, (const uint8_t*)a, (const float*)ascale,
|
||||
(const uint8_t*)wq, (const uint16_t*)ws, (uint16_t*)c, (uint32_t)M,
|
||||
(uint32_t)K, (uint32_t)N, (uint32_t)a_ld, (uint32_t)sa_ld,
|
||||
@@ -1827,6 +1688,30 @@ extern "C" int r4d_rad_gemm_i8a8_tiled(const RadArgs* a, RadStream s) {
|
||||
return e == 0 ? RAD_OK : RAD_E_SHAPE;
|
||||
}
|
||||
|
||||
extern "C" int r4d_rad_gemm_i8a8_rb8_tiled(const RadArgs* a, RadStream s) {
|
||||
Fp8Ops g;
|
||||
int rc = fp8_ops(a, &g, 1, FP8_OPS_ROW_SCALE);
|
||||
if (rc != RAD_OK) return rc;
|
||||
if (g.a->dtype != RAD_I8) return R4D_NO(RAD_E_DTYPE);
|
||||
const int e = r4d_gemm_i8a8_rb8_tiled(
|
||||
r4d_addr(g.a), r4d_addr(g.ascale), r4d_addr(g.b), r4d_addr(g.bscale), r4d_addr(g.y),
|
||||
(int)g.M, (int)g.K, (int)g.N, (int)g.a_ld, (int)g.sa_ld, (int)g.w_ld, (int)g.sw_ld,
|
||||
(long)(uintptr_t)s);
|
||||
return e == 0 ? RAD_OK : RAD_E_SHAPE;
|
||||
}
|
||||
|
||||
extern "C" int r4d_rad_gemm_i8a8_rb32_tiled(const RadArgs* a, RadStream s) {
|
||||
Fp8Ops g;
|
||||
int rc = fp8_ops(a, &g, 1, FP8_OPS_ROW_SCALE);
|
||||
if (rc != RAD_OK) return rc;
|
||||
if (g.a->dtype != RAD_I8) return R4D_NO(RAD_E_DTYPE);
|
||||
const int e = r4d_gemm_i8a8_rb32_tiled(
|
||||
r4d_addr(g.a), r4d_addr(g.ascale), r4d_addr(g.b), r4d_addr(g.bscale), r4d_addr(g.y),
|
||||
(int)g.M, (int)g.K, (int)g.N, (int)g.a_ld, (int)g.sa_ld, (int)g.w_ld, (int)g.sw_ld,
|
||||
(long)(uintptr_t)s);
|
||||
return e == 0 ? RAD_OK : RAD_E_SHAPE;
|
||||
}
|
||||
|
||||
extern "C" int r4d_rad_gemm_fp8a8_tiled(const RadArgs* a, RadStream s) {
|
||||
Fp8Ops g;
|
||||
int rc = fp8_ops(a, &g, 1);
|
||||
|
||||
Reference in new issue
Block a user