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:
NunzeandClaude Opus 5.5 committed 2026-10-21 15:26:57 +02:00
1 parent 1ff9abe2ba
commit f909576d09
5 files changed
+245

No files matched your search

+3
View File
@@ -965,6 +965,9 @@ int r4d_rope_mc_bf16(long qkv, long pos, int M, int head_dim, int n_rope_heads,
// that compares neighbouring probabilities. K must be a multiple of 8.
int r4d_logits_gemm_bf16(long a, long w, long c, int M, int K, int N, int a_ld, int c_ld,
long stream);
// The same bytes from a wave per four vocabulary columns; K must be 4096.
int r4d_logits_gemm_bf16_cols(long a, long w, long c, int M, int K, int N, int a_ld, int c_ld,
long stream);
// Scatter into kv_cache[n_blocks, kv_heads, block_size, 2*head_dim]: K at [.., d], V at
// [.., head_dim + d], slot decomposing as block = slot / block_size, offset = slot % block_size.
int r4d_kv_store_bf16(long k, long v, long slot, long kv, int M, int head_dim, int kv_heads,