docs(prefill): compute-stage kernel results (RTX 5090 job 961, laptop gates)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Pavlo Ratushnyi
2026-10-17 08:23:13 +02:00
co-authored by Claude Sonnet 5.5
parent 14eeb39865
commit f29d8ad400
+66
View File
@@ -146,3 +146,69 @@ tokens, 2 passes); the port `e9b8a5e` with the VRAM tier auto + profile and the
(The page cache dominates both: the earlier docs/laptop-profile.md run had the Original at 12.4 and the port at
3.1 tok/s; n = 6, indicative only.)
## Compute-stage kernels (branch `claude/prefill-kernels`)
Goal: the non-DMA compute of the batched prefill (input, init, GDN, QSA, GR reads and injections). Everything below is
exact: every change keeps the arithmetic expression of the kernel it replaces, and each is behind a switch so the same
binary measures old against new.
| change | switch (default on) | what it replaces |
| --- | --- | --- |
| chunk-wide KAR PLE + embedding staging | `LELEKA_PREFILL_STAGED_INPUT=0` | per token: 16-row scatter, 16-row decode, synchronous readback, host assembly and upload of the 10240-float residual row |
| guards folded into the producers | `LELEKA_PREFILL_FUSED_SCANS=0` | GR read/inject and GDN chain: a second pass over every 335 MB tensor just to scan it |
| element-parallel dequantization (GDN, QSA) | `LELEKA_PREFILL_FAST_DEQUANT=0` | one thread per 32 values, ~6 GB/s on the laptop |
| GDN chunk starts from the mirror's device state | `LELEKA_PREFILL_GDN_MIRROR=0` | canonical host state converted and uploaded for every layer of every chunk |
| two-barrier GDN recurrence (EXPERIMENTAL, off) | `LELEKA_PREFILL_FAST_REC=1` | `gdn_rec_cols_pipe_kernel` |
Input staging: the rows of a chunk (16 per token) are resolved against the cache map on the host, the packets of the
misses are read in parallel (`pread`, up to 32 threads), and one kernel decodes all of them straight into the arena's
PleEmbedding span; each distinct token's embedding row is decoded once, uploaded once, and broadcast to the four
residual streams by a kernel. `KarPleCache::stage_batch` evicts least recently used rows the chunk does not touch
(pure `lookup_rows`/`assign_slots`, unit tested with a tiny capacity). A non-finite value, bad slot or partition is
refused by the device flags with the same error class as the host path.
New sealed asset `crates/cuda-driver/src/prefill_stage.cu` (precise recipe, nvcc 13.2.86; `extra-seal-plan.json`
group `prefill-stage`, sm_86 companion in `ptx-sm86/`). Kernels: `leleka_prefill_ple_scatter`, `_ple_decode`,
`_embed_broadcast`, `_gr_norm_rs`, `_gr_mix_r`, `_gr_write_norm_rs`, `_gr_write`, `_dequant_{q8_0,q4_k,q5_k,q6_k,iq4_nl,iq4_xs}`,
`_gdn_conv_tiled`, `_gdn_l2`, `_gdn_out_norm`, `_gdn_rec`.
### Quality gates
- Model-free GPU probes (`LELEKA_PREFILL_STAGE_GPU=yes`, RTX 3080 laptop; the same tests run on the 5090 in job 960):
`staged_input_equals_the_per_token_kernels_bit_for_bit` (512,000 PLE values and the broadcast rows),
`gr_fused_guards_equal_the_separate_guard_kernels_bit_for_bit` (outputs and flag words, clean and with a non-finite R
word, gate word and an overflowing product), `gdn_stage_kernels_equal_the_originals_bit_for_bit` (all six dequantized
formats, convolution, L2 norm, output norm and their status words) and `gdn_recurrence_equals_the_original_bit_for_bit`
(t = 1, 7, 200, 1500 and an overflowing state): every comparison is identical bit for bit, maximum difference 0.
- `LELEKA_TRACE_PREFILL_R=1` prints an FNV-1a hash of the bits of every row of the chunk's final residual R (all four
streams, after 48 layers). On the laptop (prompts of 300, 1,200 and 2,600 tokens, chunks 299 / 1,199 / 2,048 / 551) the hash of every
chunk is identical between the all-switches-off arm and the default arm, and the 16 greedy output ids of the three
prompts are identical.
### RTX 5090 (job 961, one binary, tier off, greedy, 16 new tokens; `B` = the four switches off, `N` = defaults)
Greedy output ids of all 16 runs of `N` and `B` equal job 0708's (2048-token chunks: 8000 `271,248068,271,248069,...`,
16000 `271,248068,198,760,...`; 8192-token chunks: both prompts `271,248068,271,248069,...`). `LELEKA_TRACE_PREFILL_R=1`
(cap 8192): the FNV-1a hash of every row of the final residual R of each chunk is identical between `N` and `B`
(7999 rows `11c898a92de08a9b`; 8192 rows `7ea88178bf76c5a1`; 7807 rows `8a27594e2b566315`).
Prefill tok/s, two interleaved repetitions (`B` reproduces job 0708: 2,970 vs 2,941 at 16,000 tokens / 8192):
| chunk | tokens | B rep1 / rep2 | N rep1 / rep2 | gain |
| --- | --- | --- | --- | --- |
| 2048 | 8,000 | 1,096 / 1,168 | 1,298 / 1,300 | +15% |
| 2048 | 16,000 | 1,468 / 1,456 | 1,651 / 1,651 | +13% |
| 8192 | 8,000 (first prompt of the process) | 1,935 / 1,879 | 1,994 / 2,186 | +6%..+16% |
| 8192 | 16,000 | 2,971 / 2,969 | 3,735 / 3,715 | +25% |
Per 8192-token chunk (job 961 rep1, first chunk of the 8,000-token prompt; ms, host spans, expert DMA still not
overlapped): total 2,713 -> 2,158; input 178 -> 3; init 169 -> 1.5; attn_read 115 -> 68; ffn_read 114 -> 67; inject 125 -> 75;
gdn 548 -> 471 (compute 428 -> 365; state_in 38 -> 40, state_out 32 -> 34); qsa 253 -> 241; moe 1,303 -> 1,279 (ring 1,114
unchanged). The 16,000-token prompt's 7,807-token chunk: 2,671 -> 2,125.
Where the rest goes (job 961 `PROFILE_SYNC` arm, one chunk, ms): GDN cuBLAS GEMMs 152 (QKV 68, Z 43, Out 41; ~220 TFLOP/s,
at the hardware limit), recurrence 155, convolution 17, output norm 16, L2 6, dequantization 9 (was 29), GDN host row/state
bookkeeping ~75; QSA attention 113 (already tensor-core `mma`), index/norm/rope 38, Q projection 33, Out projection 17, KV
append 14; GR reads: mix 47, GEMMs 70; injection (write + next norm) 55. What is left outside the expert ring (~1.04 s) is
bandwidth-, tensor-core- or latency-bound; the per-stage host drains remain (claude/prefill-overlap).