From e28f5de2cddbee985e1918151e95081dece7588f Mon Sep 17 00:00:00 2001 From: Pavlo Ratushnyi Date: Tue, 27 Oct 2026 22:49:36 +0100 Subject: [PATCH] docs/upstream-port-plan.md: how much of a prefill chunk is host-only (drained profile), ceiling of a pipeline restructuring, GR read/inject as the better lever Co-Authored-By: Claude Sonnet 5.5 --- docs/upstream-port-plan.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/upstream-port-plan.md b/docs/upstream-port-plan.md index 7e68ce7d..ef8f81ae 100644 --- a/docs/upstream-port-plan.md +++ b/docs/upstream-port-plan.md @@ -200,6 +200,19 @@ Question: does the ring skip experts that are resident, and is the copy stream e Reading: nearly all of the 734 ms is the host waiting for kernels that are still running, so most of these syncs do not by themselves idle the GPU. What idles it is the host-only work after a sync returns and before the next layer's first launch: per chunk `gdn.state_in` 35 + `gdn.state_out` 41 + `moe.prepare` 122 (of which 53 is the drain of site 5) + `moe.spans` 26 + `moe.finish` 38 + `input`/`validate`/QSA host bookkeeping, i.e. the 0.3-0.4 s between the kernel sum (about 1.2 s) and the chunk (1.6 s). The in-situ DMA is 44.6 GB/s (gate above), so the "22 GB/s" of the stream window is the window, not the engine. Removing these syncs is not a matter of deferring status words: sites 1, 2, 5 gate the host's own next step (the route ids, the download of the recurrent state, the status words of the layer). It needs the host work of layer k+1 (router readback and grouping, state upload) to overlap the kernels of layer k, which is a double-buffered restructuring of `prepare` / `produce` / `finish`; not started. The exact deferral that exists is `LELEKA_PREFILL_DEFER_GUARDS` (on). +### Is there 0.3-0.4 s of host-only time per chunk to pipeline away? (job `rest-gdn-laps`, `LELEKA_PREFILL_PROFILE_SYNC=1`, chunk 8192, 2026-10-27) + +With every span drained (so a span shows its own GPU + host time) the chunk is 1,558 ms against 1,631 ms undrained: the drains cost nothing, the work is a serial chain. The same chunk (position 32k): + +| span | drained ms | undrained ms (139k) | what is in it | +|---|---:|---:|---| +| `moe.prepare` | 47.6 | 122 | router + top-k kernels, route-id readback, host grouping. **The 122 ms of the undrained run contain the wait for the GPU work queued before it** (attention / FFN reads, injects are asynchronous there: 7 ms each undrained, 70-83 ms drained) | +| `moe.spans` | 25.7 | 26 | pure host loop over the ~512 experts of the layer (bank spans, descriptor checks) | +| `moe.finish` | 38.0 | 38 | combine kernels + status read | +| `gdn.state_in` / `state_out` | 24.5 / 37.0 | 35 / 41 | per layer: chunk start + 8,192 row keys 16.0 ms, state upload / alloc 8.4, seal (row edges) 8.7, `owner.finish` (3.1 MB download, finite scan of the host copy, mirror adopt) 28.2 | + +GPU time of the chunk, summed over its commands (`PREFILL-COMMANDS`, includes the per-command launch overhead of the drained profile): GDN 369, QSA 275 + index 79 + KV 22, GR read / inject 184 (`readn` 124: `gr_mix_r` 48, three GEMMs 72; `injectf` `gr_write_norm_rs` 56), MoE (MMQ + gather + combine, ledger) ~330: about 1.27 s of the 1.56 s. So the GPU idle time is about 0.3 s, but the **purely host-side items that a pipeline could hide add up to about 100-120 ms** (`state_in` 25 + `state_out` 37 + `spans` 26 + the host part of `prepare` ~35 + `input`/`validate`/`init` ~30); the rest of the idle time is launch latency inside chains of small kernels. The cheap host trims that need no redesign (skip the finite scan of an already validated mirror-resident state, reuse the row keys across the 36 GDN layers of a chunk, pool the 3 MB state buffer) are worth about 20-30 ms per chunk (1.5 %), below the 1-2 % noise of a paired A/B. Hiding the rest means keeping layer k+1's route readback / grouping and state upload in flight under layer k's kernels, i.e. double-buffering ownership types that are single-owner by design (`GdnChunkStart` / `GdnChunkRow` capabilities, `OriginalMoePromptLayer`): large, and its ceiling is ~7 % of a chunk. **Not started; a better lever is the GR read / inject pair**, 180 ms of bandwidth-bound passes over the 335 MB residual (R is 4 streams x 8192 x 2560 x 4 B) that run at 2-3x their traffic floor: bit-identical fusion / re-tiling candidates (`gr_mix_r`, `gr_write_norm_rs`, the three read GEMMs) with a model-free byte-compare probe, no ownership changes. + ## Not taken (reasons in the digest) Qwen3.6-35B-A3B path, Metal/SYCL/HIP-only changes, K8V4 streaming and elastic KV (`--kv-grow`; our serve path excludes K8V4), the installers and host app.