Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
34 KiB
Roofline model of the Leleka serve runtime
Branch claude/schedule. Analysis only: the numbers below are measured ceilings (jobs 905-909, 9051 on the 5090; WSL runs on the
3080 laptop), counted model constants, or labelled A (assumption) / E (estimate from a measured number). Port timings are the
recorded ones (docs/prefill-throughput.md, docs/serve-step-costs.md, docs/decode-parity.md, holder logs 953/958/960/961/984/985); no new
model run was made. The companion docs/schedule-design.md turns these floors into a schedule. The offline model that produced every
derived number is tools/microbench/roofline_model.py; the microbenchmarks are in tools/microbench/.
0. Summary
| RTX 5090 server | what bounds it | |
|---|---|---|
| Prefill, 8192-token chunk, ideal | 0.64 s GPU floor; 1.0 s PCIe if all 50.3 GB are streamed (8.3k tok/s); 0.67 s routed-only (12k tok/s) | PCIe (51 GB/s with page-aligned runs) and the GPU are balanced; whichever schedule loses overlap pays the sum |
| Prefill today | port 1.82 s stream mode (4.4k tok/s), 2.13 s ring mode (3.8k); Original 1.5 s (5.4-5.9k) | serialization, 1,130 host round trips per chunk, copy rate 30-40 GB/s |
| Decode window, ideal at 41 % VRAM hit | 22-25 ms (80-90 tok/s) attainable, 19 ms hard bound (104 tok/s) at 2.0 tokens per window | host DRAM bandwidth for the misses (74.5 GB/s shared by the CPU leg and the DMA) plus a GPU dependency chain |
| Decode today (2048 slots) | Original 68.8 / 84.0, port 64.1 / 80.5 tok/s (pass 0 / 1) | the chain (12.9 ms) and the miss phase (17.2 ms) run one after the other |
| Decode today (auto cache, 68 % hit) | Original 94 / 129, port 84 / 110 | the chain (11 ms) is now larger than the miss phase (10 ms) |
| RTX 3080 laptop | ||
| ceilings as found (30 W GPU power cap, see 1.7) | H2D 3.0 GB/s, VRAM 40 GB/s, bf16 8 TFLOP/s, host DRAM 24 GB/s | not representative of the card; nameplate numbers in 1.7 |
The three facts that matter most:
- Decode misses are bound by host DRAM bandwidth, not by PCIe and not by the CPU cores: the CPU leg and the DMA read the same DRAM and together reach 74.5 GB/s (CPU alone 61 GB/s on two CCDs, 51-54 on one). The Original's miss phase is already at 95-105 % of that roofline; the way to be faster is fewer missed bytes (VRAM residency) and a shorter / overlapped GPU chain, not a smarter split.
- Prefill moves 50.3 GB per chunk when it streams every expert, 34 GB when it streams only the routed ones, and needs about 0.64 s of floor GPU work at 8192 tokens: PCIe and compute are of equal size, so overlap is everything. Page alignment of the source pieces is worth 7-18 % of PCIe rate (1.3).
- The port's GEMMs, recurrence and attention are mostly near their floors; the losses are in (a) overlap, (b) the MoE routed-expert compute (330 ms against an 86 ms floor), (c) hyper-connection and QSA index passes, (d) copy rate.
1. Hardware ceilings (measured)
Programs: mb_h2d, mb_h2d2, mb_dram, mb_dram_pcie, mb_gpu, mb_lat (tools/microbench, README there). Run as holder-queue jobs
905-roofline-lat, 906-roofline-gpu, 907-roofline-h2d, 908-roofline-dram, 909-roofline-mix, 9051-roofline-h2d2 (the GPU was not
shared during a job). Host: Ryzen 9 9950X3D (two CCDs, L3 96 + 32 MiB), 121 GB DDR5, GPU RTX 5090 on PCIe 5.0 x16, driver 595.99, CUDA 13.2.
GPU state during the jobs: P0, 2.57-2.94 GHz, link gen 5 x16 (it idles at gen 1 and trains up under load).
1.1 Ceilings used below (RTX 5090 server)
| quantity | value | source |
|---|---|---|
| H2D, pinned, one stream, 2 MB copies | 46.3 GB/s (50.0 with 4 KiB-aligned random sources) | job 907 |
| H2D, pinned, >= 8 MB copies | 51.3 GB/s (the link ceiling) | job 907 |
| H2D, 3 x 682 KB sequential pieces (the port's expert copy) | 40.3 GB/s | job 907, job 959 (40.3) |
| H2D, 64 KB copies | 30.0 GB/s (2.1 us per call on the host) | job 907 |
| H2D, 2 and 3 streams | no gain (45.2 against 46.3 at 2 MB) | job 907 |
| H2D registered anonymous 4 KiB pages | within 3 % of cudaHostAlloc (43.9 at 2 MB, 50.4 at >= 8 MB); registering 2 GiB takes 88 ms (23 GiB/s) |
job 907 |
| H2D pageable | 19.4 GB/s (staging inside the driver), host call blocks 105 us per 2 MB | job 907 |
| H2D read-only file mapping registered | not supported on this driver (cudaHostRegisterReadOnly -> operation not supported); the production banks are anonymous registered memory |
job 907 |
| D2H pinned | 51-52.6 GB/s; H2D + D2H together 53.7 GB/s total (the two directions do not add: one shared ceiling) | job 907 |
| Host DRAM read, one thread | 53.4 GB/s | job 908 |
| Host DRAM read, 2 threads on different CCDs | 61.3 GB/s (CPU-only maximum; 57-58 at 16-32 threads) | job 908 |
| Host DRAM read, one CCD only (any thread count) | 50-54 GB/s (the CCD's link) | job 908 |
| CPU readers + PCIe DMA at the same time | sum 74.5 GB/s (CPU 41.1 + PCIe 33.4 at 2 readers; 38.3 + 36.1 at 1); 70 at 24 readers | job 909; job 987-b (15 readers: 42 + 32 = 74) |
| GPU memory read / write / copy | 1693 GB/s read (nameplate 1792), 1670 write, 1505 copy (r+w) | job 906 |
| GPU L2-resident reread | 5.0 TB/s | job 906 |
| bf16 / fp16 tensor, cuBLAS, real shapes at T = 8192 | 219-232 TFLOP/s (qkv 229, gate/z 219, out 231, q 232; small-K/N shapes 177-190); square peak 243.5 | job 906 |
| int8 tensor (IMMA), cuBLAS | 620-870 TOPS on the real shapes, 695 square | job 906 |
| per-expert GEMM, int8, T_e = 160 / 40 rows | gate+up 185 / 55 TOPS, down 162 / 45 TOPS (one expert per launch: SM-starved, a lower bound for grouped MMQ) | job 906 |
| decode-sized GEMM (T = 1..12, bf16 weights) | 1.47-1.66 TB/s weight streaming, 35 us for a 52 MB matrix, flat in T | job 906 |
1.2 Latencies (job 905, RTX 5090 + Linux)
| primitive | median | note |
|---|---|---|
| kernel launch, host call | 1.14 us | 1.30 us per kernel back to back |
| launch + stream sync round trip | 4.4 us | |
| GPU gap between dependent kernels, stream | 1.28 us | |
| GPU gap between dependent kernels, in a graph | 0.51 us | timer quantum 0.26 us |
| graph launch, host call | 1.0-1.9 us for 1 to 2400 nodes | independent of node count |
| graph execution of empty nodes | 0.38 us per node (1000 nodes: 384 us) | |
cudaEventRecord / cudaStreamWaitEvent, host call |
0.11 / 0.10 us | |
| GPU-side event dependency gap (kernel in s0 -> event -> kernel in s1) | 1.54 us | |
| event wait: spin (default) / query poll / blocking sync | 4.6 / 4.4 / 26 us | blocking sync must never be on a critical path |
| host flag -> GPU spin kernel -> host flag (doorbell round trip) | 1.17 us (0.6 us one way) | the decode doorbell mechanism |
| GPU raises a flag the host spins on (launch included) | 4.6 us | |
host thread ping-pong across CCDs: spin / sched_yield / futex |
0.35 / 0.46 / 2.34 us round trip | futex wake is about 1 us each way |
cudaMemcpyAsync 4 KiB H2D, host call / to done |
1.15 / 3.9 us |
1.3 Copy shape: piece alignment, size and batching (jobs 907, 9051)
Sequential sources at the stride of the size (unaligned starts) against random 4 KiB-aligned sources, pinned, one stream:
| size | sequential, unaligned starts | random, page-aligned starts |
|---|---|---|
| 65,536 | 30.0 | 26.4 |
| 682,000 | 40.3 | 47.7 |
| 2,046,400 | 46.3 | 50.0 |
| >= 8 MB | 51.3 | n.a. |
The routed experts sit in the bank at arbitrary byte offsets (layer 2: gate and up pieces of 531,730 B at base + e * 531,730), so the
port's three-piece expert copy runs at the unaligned 40 GB/s, not at the 46-50 GB/s of aligned copies, and the contiguous 8 MB runs of
consecutive experts (stream-all order) would reach 51 GB/s. Job 9051 (mb_h2d2) measures this on the real piece sizes: raw, rounded to
64 B, rounded to 4 KiB, runs of 4 and 16 consecutive experts, pitched 2D copies and cudaMemcpyBatchAsync. Pending in the queue; the
result decides the bank repack and the copy shape (section 6, item 3).
1.4 How PCIe and the CPU leg share DRAM (job 909, 987-b)
Readers = pinned CPU threads streaming 2 MB random blobs; PCIe = 2 MB H2D copies, one stream:
| CPU readers | PCIe GB/s | CPU GB/s | sum | PCIe share of the sum |
|---|---|---|---|---|
| 0 | 45.9 | 0 | 45.9 | 1.00 |
| 1 | 36.1 | 38.3 | 74.3 | 0.49 |
| 2 | 33.4 | 41.1 | 74.5 | 0.45 |
| 4 | 34.0 | 38.9 | 72.9 | 0.47 |
| 8 | 34.7 | 38.2 | 72.9 | 0.48 |
| 16 | 34.0 (ccd0 only: 31.1) | 37.0 | 71.1 | 0.48 |
| 24 | 33.8 | 36.3 | 70.1 | 0.48 |
The sum is flat at 72-75 GB/s from one reader on; more readers do not add bandwidth, they only take a little (the sum falls to 70 at 24, to 68.8 at 16 readers confined to one CCD). Two streams do not change it. The optimal number of CPU workers is the smallest number whose compute rate reaches about 40 GB/s of expert weights (a core-bound property of the IQ3 kernels, not a memory property), not 15.
1.5 RTX 3080 laptop (i9-11900H, WSL2) - as found, power-capped
nvidia-smi -q during the runs: power limit 30 W (default 115 W, max 140 W), clock-event reasons SW power cap + SW thermal slowdown, P5,
memory clock 810 MHz, SM clock 210-1635 MHz under load, PCIe link gen 4 x8 (nominal gen 4 x16), AC power, Windows scheme "Performance".
This is a machine state (probably the vendor's silent profile), not a property of the card; I did not change any system setting. Values
as found (logs in WSL ~/roofline-laptop-*.log):
| quantity | as found | nameplate (A) |
|---|---|---|
| H2D pinned, 2 MB | 3.0 GB/s (pageable 3.0, registered file mapping 3.0-3.1; flat in size/streams) | PCIe 4.0 x16 about 24 GB/s (x8: 13) |
| D2H pinned | 3.3 GB/s | same |
| VRAM read / write / copy | 40 / 41 / 36 GB/s (matches the 810 MHz memory clock) | 448 GB/s |
| bf16 GEMM, real shapes, T = 8192 | 5-8 TFLOP/s (square 8.3); int8 14-20 TOPS | about 38-42 TFLOP/s (48 SMs x 512 FLOP/clk x 1.55-1.7 GHz), int8 2x |
| host DRAM read (WSL2), 16 threads / 2 threads | 24 / 18 GB/s | DDR4-3200 dual channel 51 GB/s peak |
| kernel launch / graph chain gap / doorbell round trip | 4.2 us / 2.05 us / 3.9 us | WDDM-virtualized; 4x the Linux values |
| graph execution of empty nodes | 1.3 us per node | |
| event wait spin / blocking | 19 / 22 us | |
| host thread ping-pong spin / futex | 0.15 / 2.4 us |
The laptop ceilings above are what the current machine state delivers; the operator should switch the machine to its performance profile
and re-run tools/microbench/run_laptop.sh (about 6 minutes) before laptop targets are fixed. Everything laptop-related in sections 5-6 is
therefore given in both columns.
1.6 RTX 3080 laptop, Turbo mode (re-run 2026-10-24, branch claude/laptop-opt)
The 2026-10-23 re-run (same binaries) was made twice: first in the OEM profile again (power limit 30 W, P5, memory 810 MHz, SW power cap + SW thermal
slowdown active even at idle: every number identical to 1.5 within 5 %, i.e. 1.5 is that profile's property, not a measurement error), then, after the
operator set Turbo mode, with the guarded runner scripts/laptop/lap_run.sh (preflight: P0, limit 130-140 W, no throttle reason; 1 Hz watchdog; logs
~/lopt/results/MB{1,2,3}_*, joined as roofline-laptop-turbo-2026-10-24.log). Mean clocks during the GPU suite: SM 1,839 MHz, memory 7,151 MHz, 118 W,
max 77 C. PCIe link gen 4 x8 (the card is wired x8 here).
| quantity | OEM 30 W profile (1.5) | Turbo (measured 2026-10-24) | nameplate (A) |
|---|---|---|---|
| H2D pinned (hostalloc), 2 MB / 8 MB, 1 stream | 3.1 GB/s | 11.8 / 12.0 GB/s (2 and 3 streams: same) | gen4 x8 about 13-14 GB/s |
H2D registered file mapping (cuMemHostRegister of the page cache) |
3.0-3.1 | 12.0 / 11.0 | |
| H2D registered anonymous 4 KiB pages | 3.1 | 9.8 / 11.3 | |
| H2D pageable (driver stages through its own pinned buffer), 2 MB / 8 MB | 3.1 | 7.4 / 7.8 GB/s (host 275 us / 1,070 us per call, the calling thread is blocked) | |
| D2H pinned / both directions | 3.2-3.3 / 3.2 | 12.4-12.7 / 12.1 (sum, not 2x) | |
| 3 pieces per expert, 16 experts per call, pinned | 3.1 | 11.6-11.9 (1 expert per call: 11.2, 160 us host per expert) | |
| VRAM read / write / copy | 40 / 41 / 36 | 445 / 437 / 426 GB/s | 448 |
| bf16 GEMM T = 8192 (gdn_qkv, qsa_q, 8192^3) | 5-8 TFLOP/s | 44.2 / 44.3 / 44.1 TFLOP/s; fp16 43; int8 128-153 TOPS | 38-42 (A) |
| bf16 GEMV T = 1 gdn_qkv (52 MB) / expert_down T = 10 | 38 GB/s | 390 GB/s / 252 GB/s | |
| host DRAM read, 1 / 2 / 4 / 8 / 16 threads (stream) | 14.8 / 21.9 / 24.6 / 26.5 / 26.3 | 13.8 / 18.2 / 20.4 / 20.1 / 23.8 GB/s (2 MB random blobs: 8.7 / 14.0 / 19.9 / 20.6 / 24.3) | DDR4-3200 dual channel 51 peak |
| PCIe pinned copy while N CPU readers stream blobs (PCIe + CPU = sum) | 3.0 + 9.8..21.5 = 12.8..24.2 | N=0: 9.1; N=1: 7.7 + 9.0 = 16.6; N=4: 5.8 + 13.7 = 19.5; N=8: 5.8 + 16.0 = 21.8; N=16: 3.5 + 17.1 = 20.6 | |
| kernel launch / graph chain gap / doorbell round trip | 3.5 / 2.05 / 4.2 us | 3.5 / 1.0 / 3.0 us | WDDM-virtualised |
| graph of 1000 empty nodes | 1.3 ms | 0.73 ms | |
| thread ping-pong spin / futex | 0.15 / 1.85 us | 0.16 / 2.4 us |
Reading for the engine: with Turbo the GPU side becomes 11x faster (VRAM, compute) and the link 3.8x faster, but host DRAM (about 24 GB/s mixed,
not the 51 GB/s nameplate) and the link share it: while the CPU leg streams blobs the PCIe copy drops from 9-12 to 5.8 GB/s and the sum saturates at
about 20-22 GB/s. The 7-worker CPU expert pool and PCIe misses therefore compete for the same DRAM bandwidth, and the optimum worker count is the smallest
one that reaches the sum (4-8 readers), as on the server. The pageable path (the mapped bank without registered pages) tops out at 7.4-7.8 GB/s with a
blocked host thread; registering the file pages (cuMemHostRegister, 0.06 s for 2 GiB, file mapping read-only) gets the pinned 12 GB/s.
2. Model accounting (counted from data/iq3_s/index.txt, native_experts.txt, include/strata/core/layout.hpp)
- 48 layers: 36 GDN (all layers with l mod 4 != 3) and 12 QSA (3, 7, ..., 47); hidden 2560, four hyper-connection streams (R = 10240 floats per token), 512 experts per layer, top-10, expert intermediate 640, 24 query / 2 KV heads of 256, indexer 4 x 128 with top-2048 cells, GDN 16 K-heads / 48 V-heads of 128 (state 3.1 MB per layer).
- Routed experts: 24,576 blobs, 50.29 GB in total, mean 2.046 MB (1.51-2.66 MB by layer, gate/up IQ3_S-family, down IQ4_NL/Q2_0).
- Dense weights read once per window: GDN layer 96.2 MB (qkv 27.9, gate 16.7, out 16.7, shared expert 5.2, router 2.6, hyper-connection 26.2 as bf16, ssm 0.5), QSA layer 90.5 MB; total with the 675 MB output head 5.23 GB.
- Multiply-accumulates per token: GDN layer 77.2 M, QSA layer 70.8 M (+ 25 M attention over 2048 cells), routed experts 49.2 M per layer. Per token 6.0 G MAC dense + routed, 12.6 GFLOP per token, 103 TFLOP per 8192-token chunk (matmuls only).
- Expert miss statistics (job 984/985
strata decode timing): union of distinct experts per layer for T rows is U = 10 T^0.85 (T = 2 -> 18, 2.7 -> 23, 3.8 -> 30-34); 2048 slots give a hit fraction of 0.41 at T = 2.68, the auto cache (9,971 slots) 0.68.
3. Prefill chunk (8192 tokens) - per-step roofline
"Floor" = the larger of the bytes / measured bandwidth and the FLOPs / measured rate (bf16 229 TFLOP/s, int8 450 TOPS effective = 65 % of
the cuBLAS peak at grouped-tile shapes A, HBM 1693 GB/s). "Now" = job 961 PREFILL-COMMANDS (GPU command time of the per-layer sums, ring
mode, tier off) or the nearest recorded span. Bytes are HBM traffic E unless the step is a GEMM (weights + activations).
| step | HBM GB | TFLOP | floor ms | now ms | eff. | limiter / note |
|---|---|---|---|---|---|---|
| GDN qkv, z, out GEMMs (36) | 46.8 | 34.0 | 148.5 | 148 | 100 % | tensor-core ceiling (cuBLAS 229 TFLOP/s measured here and in the run) |
| GDN conv, gates, L2, out-norm, state (36) | 72.5 | - | 42.8 | 49 | 87 % | HBM, A: six passes over the 335 MB qkv tensor |
| GDN recurrence (36) | - | 0.9 | 130 | 150 | 87 % | latency: two dependent 128-FMA chains + an update per token, about 1280 cycles at 2.9 GHz E; cannot be reordered without changing bits |
| QSA q, k, v, out, indexer GEMMs (12) | 0.6 | 10.1 | 44 | 56 | 79 % | tensor cores |
| QSA index, norm, rope, select (12) | 9.7 | - | 6 | 42 | 14 % | A-floor, large gap: per-token loops and launch-bound pieces (ledger to attribute) |
| QSA attention, 2048 cells (12) | 12.9 | 5.0 | 43 | 113 | 38 % | A: mma flash kernel at 50 % of peak |
| KV append, gate, misc (12) | 1.2 | - | 1 | 17 | 4 % | launch-bound small kernels |
| hyper-connection GEMMs (96 halves) | 34.2 | 10.3 | 45 | 71 | 63 % | K or N = 320 shapes (cuBLAS 177-232 TFLOP/s) |
| hyper-connection norm, mix, inject (96) | 112.7 | - | 67 | 110 | 61 % | HBM, A: floor = read R, write R, read gated once per half (fused) |
| router + shared expert (48) | 12.4 | 4.9 | 21 | 25 | 86 % | tensor cores; current only approximately attributed |
| routed experts MMQ: gather, gate/up, swiglu, quantize, down (48) | 114.8 | 38.7 | 86 | 330 | 26 % | integer MMQ at 450 TOPS effective; "now" is the ring with the expert DMA skipped (job 705, includes gather, scatter, combine, status) |
| PLE, init, validate, publish, host misc | - | - | 3 | 25 | 12 % | |
| GPU sum | 103 | 637 | 1136 | 56 % | ||
| expert PCIe stream | 50.3 (stream-all) / 34 (routed 68 %) | - | 1093 / 743 at 46 GB/s; 986 / 667 at 51 GB/s | 1110 (moe.ring, 34 GB at 30.6 GB/s) | 66-90 % | PCIe, copy rate and overlap |
Host-visible total of the same chunk: 2.13 s (ring mode: 1.14 GPU + 1.11 s moe.ring partly serial) and 1.82 s (stream on; job 960).
3.1 Chunk ideals (5090)
Time of a chunk = max(GPU floor, PCIe time) with perfect overlap. PCIe at 46 GB/s (2 MB pieces); at 51 GB/s with page-aligned 8 MB runs the stream-all column becomes 986 ms. Routed share of the bank: 0.60 / 0.65 / 0.68 / 0.75 at 2048 / 4096 / 8192 / 16384 tokens (0.60 overlap agent, 0.68 job 705, others A). "10 GB resident" = about 4,900 experts kept in VRAM (20 %).
| chunk T | GPU floor ms | PCIe stream-all ms | routed-only ms | ideal tok/s: stream-all | routed-only | stream-all + 10 GB resident | routed-only + 10 GB |
|---|---|---|---|---|---|---|---|
| 2048 | 162 | 1093 | 656 | 1,873 | 3,122 | 2,338 | 4,669 |
| 4096 | 320 | 1093 | 711 | 3,746 | 5,764 | 4,676 | 8,304 |
| 8192 | 637 | 1093 | 743 | 7,493 (8.3k at 51 GB/s) | 11,019 | 9,352 | 12,856 |
| 16384 | 1271 | 1093 | 820 | 12,886 | 12,886 | 12,886 | 12,886 |
Reading: below 8192 tokens the chunk is PCIe-bound whatever the GPU does (a full bank pass per chunk), above it GPU-bound. Bytes per token shrink with the chunk; chunk size changes rounding (docs/prefill-throughput.md: relative L2 0.14-0.20 between any two chunk sizes), so the chunk plan is a numerics choice and the ideals above are the PCIe cost of each choice, not a recommendation to change it.
3.2 Measured against the ideals
| chunk ms | tok/s | % of stream-all ideal (986-1093 ms) | |
|---|---|---|---|
| port, ring mode (job 960) | 2,136 | 3,835 | 46-51 % |
| port, stream mode (job 960, depth 2) | 1,822-1,852 | 4,420-4,490 | 53-60 % |
| Original, 8192 chunk (docs/prefill-throughput.md) | about 1,500 | 5,400-5,900 | about 70 % |
| Original, 180k prompt, 30 chunks of 6000 (job 916) | 1,313 | 4,571 | 49.3 GB streamed per chunk = 37.6 GB/s |
| port, 180k prompt, 22 chunks of 8192 (job 915) | 2,314 | 3,536 | |
| port, tail chunk of 1,695 tokens (job 915) | 1,409 | 1,203 | a full bank pass for 1,695 tokens |
4. Decode round - per-step roofline
4.1 One verify window (T = 2.7 rows, 2048 slots, hit 0.41; Original job 984, 48 layers)
Per layer and window: 23.1 distinct experts = 9.4 VRAM hits + 7.0 PCIe + 6.7 CPU (9.4 CPU entries). The miss bytes per window are 13.6 x 48 x 2.046 MB = 1.337 GB.
| step | bytes | floor ms | now ms (Original / port) | limiter |
|---|---|---|---|---|
| GPU dense chain: 48 x (HC read, mixer, router, shared expert, combine) + head | 5.5 GB (dense 5.23 + state 0.23 + KV) = 3.3 ms of HBM + 1,200 kernels x 0.51 us graph gap = 0.6 ms | 4.0 (5 practical) | 12.9 "GPU-reach wait" (GPU stage profile: 12.3 non-wait work: GDN 8.4, QSA 3.4, head 0.5) / same + 0.1 | HBM + kernel chain; 25 kernels per layer, 0.26 ms per layer against 0.08-0.10 ms floor |
| GPU experts: hits + staged | 1.6 GB | 0.95 | inside the chain | HBM |
| miss phase: PCIe leg + CPU leg | 1.337 GB | 18.1 (at 74.5 GB/s) | 17.2 (CPU 16.6) / PCIe stage 32.4 vs 25.9 ms per window (+6.5) | host DRAM |
| per-window handoffs, stage, unattributed | 0.5 | 1.1 | doorbell 1.2 us round trip, plan, submit, flag | |
| draft chain + commit | 4-5 graphs, each at least one head read | 1.5 A | 1.2 / 2.2 | HBM + per-graph sync |
| window total, serial | 24-25 | 32.6 / ~35 by phase rate, ~40 by stage stamps (Original + 6.5 ms PCIe stage + 1.0 ms draft; the port also takes 2.5 tokens per window against 2.2) |
The serial sum (chain + miss + draft) reproduces both recorded windows: model 32.2 ms against 32.6 measured (2048 slots), 21.8 against 23.8 (auto cache). The window is therefore chain + miss, not max(chain, miss).
The Original's miss phase is on its roofline (1.337 GB in 17.2 ms = 77.7 GB/s against the 74.5 measured ceiling; the 4 % excess is L3 reuse of hot experts). The CPU leg alone: 6.7 experts x 2.046 MB x 48 = 0.66 GB in 16.6 ms = 40 GB/s, the contended CPU rate of job 909 (38-41 GB/s) - it is at its ceiling, and so is the DMA leg. Splitting differently, more workers or faster kernels cannot shorten the miss phase; only fewer missed bytes can (and, for the PCIe leg only, the 6.5 ms per window the port loses against the Original, whose cause is the one in decode-parity.md finding 2: the port's copy inside the window contends more).
4.2 The PCIe / CPU split (closed form)
Let m = missed experts per layer (U (1 - h)), s = 2.046 MB, x = PCIe share, and P, C the rates of the two legs measured with both running. Time of the layer's miss phase t(x) = max(x m s / P, (1 - x) m s / C, m s / D) with D the DRAM sum. The first two legs balance at
x* = P / (P + C) t* = m s / (P + C) (valid while P + C <= D, which is the measured regime: 33.4 + 41.1 = 74.5)
so the optimum is x* = 0.45 (2 readers) to 0.49 (1 reader), 0.43 with the 15-worker mix of job 987-b. When the sum is DRAM-capped every x in
[1 - C/D, P/D] ties; with the measured rates that interval has zero width. At the shipped x = 0.55 the DMA leg carries 0.55 m s at 34 GB/s
and takes 0.0162 m s against the optimum 0.0135 m s: up to 20 % of the miss phase (3.6 ms of 18) if the DMA really runs at its contended
rate, less when it does not. Measured sweeps agree with x* = 0.45: DMA 0.45 / 0.55 / 0.65 / 0.75 = 56.9 / 55.4 / 49.0 / 44.6 tok/s (static),
adaptive 0.35 / 0.45 / 0.55 = 60.9 / 64.8 / 64.2. The Original's copy-kernel mode preferred 0.35 (+6 % of tok/s) because the copy kernel also
occupies SMs. LELEKA_PCIE_AUTO should equalize the two legs' completion times per layer; the achievable gain over a good fixed share is a
few percent of the window.
Worker count: P + C is flat from one reader on and falls from 74.5 to 70 at 24 readers; P itself does not depend on the number of readers
beyond the first. Use the fewest workers that sustain C = 40 GB/s with the real kernel (mb_dram measures bandwidth, not the IQ3 dot kernel;
the per-thread GB/s of the kernel is in the cpu.compute span, not yet read) and place them on both CCDs (one CCD alone caps the
CPU leg at 51-54 GB/s even without PCIe).
4.3 Throughput as a function of hit rate (rows 2.7, 2.0 tokens per window, draft + commit 1.2 ms)
serial = chain + miss + draft (the shape of every recorded window). prefetch = the same with the DMA leg started one layer early (schedule-design.md 3.2,
upper bound with perfect prediction; multiply the saving by the recall). bound = max(chain, miss) + draft, not attainable because the CPU
leg needs the layer's activations.
| hit h | miss GB | miss ms | chain 12.9 (today): serial / prefetch | chain 6 (floor): serial / prefetch / bound |
|---|---|---|---|---|
| 0.00 | 2.29 | 30.7 | 44.8 ms (45 tok/s) / 38.8 (51) | 37.9 (53) / 35.1 (57) / 31.9 (63) |
| 0.20 | 1.83 | 24.5 | 38.6 (52) / 32.7 (61) | 31.7 (63) / 29.0 (69) / 25.7 (78) |
| 0.41 (2048 slots) | 1.35 | 18.1 | 32.2 (62) / 26.3 (76) | 25.3 (79) / 22.5 (89) / 19.3 (104) |
| 0.60 | 0.91 | 12.3 | 26.4 (76) / 20.4 (98) | 19.5 (103) / 16.7 (120) / 13.5 (148) |
| 0.68 (auto cache) | 0.73 | 9.8 | 23.9 (84) / 18.0 (111) | 17.0 (118) / 14.3 (140) / 11.0 (182) |
| 0.80 | 0.46 | 6.1 | 20.2 (99) / 14.3 (140) | 13.3 (150) / 10.6 (189) / 7.3 (273) |
| 0.90 | 0.23 | 3.1 | 17.2 (117) / 14.1 (142) | 10.3 (195) / 7.5 (266) / 7.2 (278) |
Each +10 points of hit rate removes about 3.1 ms of miss time per window at 2.7 rows; below h = 0.7 the miss phase dominates, above it the GPU chain does. At 4 and 6 rows the unions are 32 and 46 experts per layer and the same table scales by U(T)/U(2.7) (1.4x and 2.0x the miss time), which is why larger speculative windows pay only when the chain, not the miss phase, is the larger term.
4.4 MTP drafter chain
The MTP pack is 116 MB dense, 708 MB of experts (all 512, VRAM-resident) and a draft vocabulary of 106k ids (draft_vocab.bin). One chain step
reads about 0.12 GB dense + 14 MB experts + the head over the draft vocabulary (0.29 GB, A: Q8_0 rows of the draft ids) = 0.43 GB = 0.25 ms of HBM,
against 0.68 ms measured per step graph (decode-parity finding 4): the step is latency-bound (about 25 kernels, a host sync per graph), 37 % of
its floor. Chain of 4 steps + seed: 1.5 ms floor, 2.2 ms port, 1.2 ms Original.
4.5 Where the port stands (decode)
| config | Original | port | gap | cause (recorded) |
|---|---|---|---|---|
| 2048 slots, phase tok/s pass 0 / 1 | 68.8 / 84.0 | 64.1 / 80.5 | -7 % / -4 % | PCIe copy stage 25-35 % slower inside the window (contention), draft + commit +1.0 ms, per-request assembly 63 ms |
the same, --pcie-frac 0.35 Original |
72.8 / 89.1 | -12 % | ||
| auto cache (Original 9,971 slots, port 8,820) | 94.4 / 129.1 | 84.3 / 110.1 | -11 % / -15 % | 1,151 fewer slots, CPU pool 9.6 vs 5.5 ms per window at the auto cache (fixed per-group cost, unattributed), same copy stage effect |
5. Best achievable tokens per second
5.1 RTX 5090 server (measured ceilings)
| workload | ideal | basis | today (port / Original) |
|---|---|---|---|
| prefill, 8192-token chunks, Original algorithm (stream every expert) | 7.5k tok/s at 46 GB/s, 8.3k at 51 GB/s | PCIe: 50.3 GB per chunk | 4.4k / 5.4-5.9k |
| prefill, routed experts only (68 %), predictor with repair | 11.0k (12k at 51 GB/s) | PCIe 34 GB, GPU floor 0.64 s | |
| prefill, routed-only + 10 GB resident | 12.9k | GPU floor | |
| 180k-token prompt (22 chunks of 8192) | 15-24 s | 22 x 0.67-1.09 s, plus the context growth of QSA (12 x 4.5 TFLOP at 180k, E +5 %) | 50.9 s / 39.4 s |
| decode, 2048 slots (hit 0.41), 2.0 tokens per window | 89 tok/s attainable (chain 6 ms, prefetch), 79 serial with a short chain, 104 hard bound | 1.337 GB of misses at 74.5 GB/s | 64 / 69 (pass 0) |
| decode, auto cache (hit 0.68) | 140 tok/s attainable, 118 serial with a short chain, 182 hard bound | 0.73 GB of misses | 84 / 94 |
| decode, VRAM 2x larger (hit 0.80) | 189 | 0.46 GB of misses |
5.2 RTX 3080 laptop
Turbo ideals (section 1.6 numbers, added 2026-10-24). Dense chain 5.5 GB at 445 GB/s = 12.4 ms per window (plus launch gaps, about 1.0 us per graph node). Misses at 3,133-4,400 VRAM slots (hit rate 0.50-0.55, about 1.0-1.2 GB per window) over the PCIe + CPU sum of 20-22 GB/s: 50-60 ms; the serial window is therefore about 65-70 ms, and with 2.0-2.5 accepted tokens per window the decode ideal is 29-38 tok/s (3 tokens per round: 43-46 tok/s; with perfect overlap of chain and misses 40-50). Prefill is bound by streaming the bank (50.3 GB per chunk) over the link: pinned/registered 11.8 GB/s = 4.3 s per chunk (480 tok/s at 2048, 1,900 tok/s at 8192); through the pageable path 7.5 GB/s = 6.7 s (305 / 1,220 tok/s). The bf16 GEMM floor is 2.3 s per 8192 chunk (3,500 tok/s) so it is link-bound at every chunk size; the page cache holds only about 30-34 of the 50 GB, so a chunk also pays NVMe reads for the rest unless the bank is read ahead.
The two columns below are the OEM 30 W profile (section 1.5) and nameplate.
Two columns, because the machine is power-capped (1.5). Laptop VRAM is 16 GB: dense weights 5.2 GB + KV + workspace leaves about 9 GB, i.e. about 4,400 expert slots (18 % of the bank), hit rate about 0.55 A (between 0.41 at 2048 and 0.68 at 9,971 slots). The experts are file-mapped (page cache), the bank (50.3 GB) exceeds the WSL page cache (about 34 GB available), so a chunk's expert bytes come from RAM and disk.
| quantity | as found | nameplate (A: x16 gen 4 24 GB/s, DDR4 dual channel 40 GB/s native, VRAM 448 GB/s, 40 TFLOP/s) |
|---|---|---|
| prefill chunk PCIe time, stream-all (50.3 GB) | 16.8 s (3.0 GB/s) | 2.1 s |
| prefill GPU floor, 8192 tokens | about 13 s (bf16 8 TFLOP/s; 103 TFLOP) | about 2.6 s (E) |
| ideal prefill | about 490 tok/s (PCIe-bound) | about 3,100 tok/s if the bank is in RAM; the page cache holds 68 % of the bank, the rest comes from NVMe at 3-7 GB/s, E 1,500-2,500 tok/s |
| decode window miss phase (4,400 slots, h 0.55, U 23): 1.0 GB | 37 ms at 27 GB/s (24 DRAM + 3 PCIe) | 1.0 GB / 40 GB/s native (CPU 40 + PCIe overlapping): 22-25 ms |
| decode GPU chain (5.5 GB at the VRAM bandwidth) | 138 ms at 40 GB/s | 12.3 ms at 448 GB/s |
| ideal decode, 2.0 tokens per window | about 11 tok/s | about 45 tok/s (serial), 50 with prefetch |
The laptop decode ideal is the sum of the GPU chain (VRAM-bound, 12 ms at nameplate: larger than the 5090's chain by 3.7x) and the miss phase (DRAM-bound), which is why trimming kernel count helps the laptop less than keeping experts in VRAM and DRAM traffic low.
6. Gaps ranked, and the targets the ledger is judged against
Targets are per step floors (section 3 and 4 tables) plus a stretch target = the floor divided by 0.8 for bandwidth/compute-bound steps and the measured value for latency chains. Gains are chunk-level or window-level milliseconds on the 5090.
6.1 Prefill chunk (8192), port stream mode 1,830 ms -> target 750-850 ms
| rank | gap | size | target | how (owner) |
|---|---|---|---|---|
| 1 | Serialization of copy and compute plus host round trips: GPU-sum 1,136 ms and PCIe 1,100 ms run partly in sequence; 1,130 blocking host-device calls per chunk | ~700 ms (1,830 - 1,136) | chunk = max(GPU, PCIe) <= 1,150 | event dependencies, deferred guards, no H2D on the compute path (prefill-overlap; schedule-design.md 2) |
| 2 | Routed-expert MMQ 330 ms against an 86 ms floor | ~245 ms | <= 160 | grouped MMQ with direct group-slot DMA (no gather), device-built tiles, fewer launches (prefill-kernels) |
| 3 | PCIe rate: 30.6 GB/s observed (34 GB in 1.11 s), 40 GB/s unaligned pieces, 46-51 aligned | ~300 ms of the 1.1 s | 50.3 GB at >= 46 GB/s or runs at 51 | repack the bank with 4 KiB-aligned pieces, 8 MB runs of consecutive experts, copy straight into group slots (job 9051 decides) |
| 4 | Bytes: stream-all 50.3 GB against 34 GB routed | ~350 ms at the PCIe-bound point | routed-only with predictor, recall >= 97 % | schedule-design.md 2.4 (needs the recall measurement first) |
| 5 | Hyper-connection norm/mix/inject 110 ms, GEMMs 71 ms | ~70 ms | 67 + 45 | fuse; GEMMs near their shapes' ceiling |
| 6 | QSA attention 113 ms (43), index/select 42 ms (6), KV/gate 17 (1) | ~120 ms | 43 / 12 / 5 | attention kernel efficiency; index/select launch fusion (ledger to attribute) |
| 7 | GDN recurrence 150 ms (130 latency floor), conv/gates 49 (43) | ~25 ms | keep | none worth the risk: bit-exact chain |
| 8 | Host misc: validate, init, finite admission 0.8 s once per process | 25 ms + 0.8 s first chunk | <= 5 ms; admission at load |
6.2 Decode window (2048 slots) 32.6 ms Original / ~38 port -> target 24-26 ms
| rank | gap | size | target | how (owner) |
|---|---|---|---|---|
| 1 | Missed bytes (hit 0.41): 1.337 GB per window = 18.1 ms of DRAM time | each +10 points of hit = 3.1 ms | h >= 0.68 (auto cache) | VRAM residency, adaptive cadence 2 (+1.4-2.3 %), reserve (expert-residency, memory-safety) |
| 2 | GPU chain 12.9 ms (floor 4, practical 5-6) | ~7 ms | <= 6 ms | kernel fusion keeping the per-kernel arithmetic, graph gap 0.51 us, 25 -> 12 kernels per layer (decode-parity) |
| 3 | Chain and miss phase serialized | up to 0.46 x chain = 2.3-6 ms | prefetch of the DMA leg one layer ahead (recall dependent) | schedule-design.md 3.2 item 1 |
| 4 | Port DMA stage +6.5 ms against the Original | 6.5 ms | = Original | contention (decode-parity finding 2): count/placement of CPU workers (2-8, both CCDs), 4 KiB-aligned pieces |
| 5 | Port draft + commit 2.2 ms (Original 1.2, floor 1.5) | 0.7-1.0 ms | <= 1.5 | device-resident chain, one sync per round |
| 6 | CPU pool fixed cost at the auto cache: 9.6 vs 5.5 ms per window | up to 4 ms | = Original | decode-parity item 2 (LELEKA_OPEN_CACHE) |
| 7 | Per-request assembly 63 ms + teardown 10 ms | 4-6 % of a short request | persistent verifier | decode-parity |
| 8 | Split fraction 0.55 against x* 0.45 | 0-5 % of the miss phase | LELEKA_PCIE_AUTO toward leg-completion equalization |
decode-parity |
6.3 Ceiling-level targets for the harness
- PCIe: achieve >= 90 % of the measured copy ceiling for the shape actually used (46.3 GB/s at 2 MB pieces, 51.3 at >= 8 MB, 47.7 for aligned 682 KB pieces); report GB/s per chunk from the copy-stats events.
- GPU: GEMM steps >= 90 % of the cuBLAS rates of 1.1; elementwise steps >= 70 % of 1693 GB/s; the sum of GPU command times of a chunk against the 637 ms floor.
- Decode: miss phase >= 90 % of 74.5 GB/s (already met); chain <= 6 ms at 2.7 rows; window <= 26 ms at hit 0.41.
7. Open items and reproduction
- Job 9051 (
mb_h2d2): copy shapes on the real piece sizes - changes the PCIe line of every table above by up to +25 %. - Recall / precision of the routing predictors (schedule-design.md 5.1) - gates the routed-only line.
- Per-thread GB/s of the CPU expert kernel (span
cpu.compute) - sets the worker count of 4.2. - Ledger (CUPTI) kernel timeline - replaces the A floors of the elementwise steps in section 3.
- Laptop re-run in a non-capped machine state.
python tools/microbench/roofline_model.pyprints every derived table;tools/microbench/build.shbuilds in WSL;tools/microbench/jobs/make_jobs.sh DIRwrites the holder jobs;tools/microbench/run_laptop.sh OUT [suite...]runs the laptop suite.