Archived
libr4d: logits_gemm_bf16_cols -- the bf16 head without a block per column at n_embd 4096
logits_gemm_bf16 runs a 256-thread block per vocabulary column. At n_embd 4096 a thread makes two 16-byte weight loads before the block-wide sum, and each row widens both operands for its own product: GLM-5.3's TP8 slice (19360 columns) took 303 us at six rows and 1133 at 24, where a verify pass of eight streams lands, against 235 at one. The new row runs a wave per four columns: lane l takes, in turn, threads 32q + l of the old block for q = 0..7 -- the same 8-wide k chunks summed from 0 and added in k order, the same lane butterfly per q, the eight wave sums added in q order from 0 -- so each column gets the old row's bytes. bf16 widens to f32 exactly, so each weight is widened once for every row and each activation once for every column. It outranks the block row at n_embd 4096 only; the block row is unchanged and serves every other width. Measured at the TP8 slice (r4d_selftest --perflogits), us: rows 1 6 8 16 24 48 logits_gemm_bf16 239.1 303.2 378.2 741.4 1133.2 2354.5 ..._cols 235.5 247.5 250.4 404.5 635.6 1220.1 Two columns a wave and 16 rows a pass measured slower. r4d_selftest compares both rows byte for byte from one row to past one 8-row chunk, at a vocabulary off the column step and a pitched activation with a NaN and a signed zero. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1ff9abe2ba
commit
f909576d09
5 files changed
+245
No files matched your search
@@ -4995,6 +4995,7 @@ static const RadConstraint cSampleCand[] = { C_GE("n_cand", 1), C_LE("n_cand", 4
|
||||
static const RadConstraint cSampleLogprobs[] = { C_GE("n_vocab", 1), C_GE("k", 1), C_LE("k", 64) };
|
||||
/* The activation width the column loop vectorises over; M is unbounded -- the kernel chunks rows. */
|
||||
static const RadConstraint cLogitsGemm[] = { C_DIV("n_embd", 8), C_IN("dtype", "bf16") };
|
||||
static const RadConstraint cLogitsGemmCols[] = { C_EQ("n_embd", 4096), C_IN("dtype", "bf16") };
|
||||
/* The fp8 head: n_embd on the 128 scale block, and no cap on M. The row relayouts the weight, so
|
||||
* it must cover the whole range; above a cap the bf16 projection would read the E4M3 codes as bf16.
|
||||
* The kernel chunks above 32, and core/build/rad_builder.cpp refuses a capped arrangement.
|
||||
@@ -5684,6 +5685,16 @@ static const RadKernelInfo kKernels[] = {
|
||||
nullptr, nullptr, r4d_rad_logits_gemm, nullptr, nullptr, nullptr,
|
||||
r4d_shape_logits_gemm },
|
||||
|
||||
{ "logits_gemm_bf16_cols", "logits_gemm", "vocab",
|
||||
"logits_gemm_bf16 with a wave per four vocabulary columns: lane l runs that row's threads 32q + l "
|
||||
"in turn, so each column keeps its k chunks, lane butterfly and wave order",
|
||||
"any M and any vocabulary; n_embd 4096 exactly; the activation's row pitch whole 16 bytes",
|
||||
"bf16 x and lm_head, F32 LOGITS OUT, fp32 accumulate. BYTE-IDENTICAL to logits_gemm_bf16",
|
||||
RAD_DOMAIN_DEVICE, R4D_PRIO_LOGITS_COLS,
|
||||
ROW(cLogitsGemmCols), NOTUNE,
|
||||
nullptr, nullptr, r4d_rad_logits_gemm_cols, nullptr, nullptr, nullptr,
|
||||
r4d_shape_logits_gemm },
|
||||
|
||||
{ "logits_gemm_fp8", "logits_gemm", "vocab",
|
||||
"the lm_head projection over an fp8 head: C[M, n_vocab] f32 = x[M, n_embd] @ dequant(W)^T, "
|
||||
"one wave a vocabulary row, the row's own scales in its tail",
|
||||
|
||||
Reference in new issue
Block a user