Repository navigation
gpu: on an integrated device, a decode gemv warp asks L2 for its whole row before the walk - #27
Conversation
|
@midagedev The red On a DGX Spark, I can't rerun the workflow from here, so I'm leaving that with you. |
|
@juliankang4 Thank you for the diagnosis. The red This PR is in our landing train now. The fixture gates are running, and the A6000 A/B (non-inferiority, 14 rounds) runs right after. We merge it here when both are green. |
|
@juliankang4 The A6000 A/B is in, and the prefetch loses there. Qwen3.6-35B-A3B Q4_K_M, depth 6, 14 interleaved rounds, one process per arm, same lease:
Every round reads 0.955 to 0.959, so this is not noise. Our card predicted −0.5 to +2 %. It assumed a warp frees its lines as it walks, so about half a row per warp is in flight. That is the term that was wrong. Your L2-room concern looks right: the A6000 has 6 MB of L2. So we cannot land it as it is. We land the rest of the train without it today. Two ways forward, your choice:
We will run nsys on both arms on the A6000 and post the per-kernel times here, so you can see which kernels lose. Thank you for the careful PR. The Spark gain is real, and we want it in. |
|
@midagedev Thank you for the A/B and the clear table. I'll take option 1. The fact I'd read is The plan for this branch:
Option 2 could give the A6000 something too, but I can't time it there, and each try would cost you an A/B. If your nsys times show the loss only in |
|
The per-kernel numbers I promised. Nsight Systems on the A6000, both builds, Qwen3.6-35B-A3B Q4_K_M, depth 6, mean of 6 decode replays. The step goes from 4876 to 5079 us (+203 us, +4.2 %). The gaps between kernels do not move.
The rest move less than 5 us. The loss also shows on kernels whose rows in flight fit the 6 MB L2 (qkv at about 3 MB), so L2 room is not the whole cause. The router norm gains, and it is the one kernel with other work before its walk. So your option 1 (prefetch only on an integrated device) fits these numbers. Thank you for the careful PR. Also: we changed CONTRIBUTING today. A number from your own NVIDIA card now counts for your PR on that card, with the |
db6546e to
0b5c2fc
Compare
|
@midagedev Thank you for the nsys table. I pushed option 1: the prefetch now runs only when One thing to know before your A6000 A/B: with the argument at 0 the kernels are not main's. The prefetch code moves register allocation even where it does not run (sm_86 ptxas: Your table also shows |
|
Thank you. Yes, please add the second entry without the prefetch. Then a card with its own memory runs main's PTX, and |
0b5c2fc to
af9c455
Compare
|
@midagedev Done: each prefetching kernel now has a Four of the twelve are copies of their plain entry's body: On the same two DGX Sparks against main Agreed on the A6000 router_norm gain as a separate PR later. |
|
Thank you. I am checking af9c455 now: our own ptx-scan of generate_ds41 and gate_e2e against main, and the new ptx-shapes rows. If both hold, it goes into the next landing train. Keeping the four plain bodies as main's text is the right choice. |
… and decision share one expansion serve::media::expand_spans (each placeholder run of the prompt ids expanded to its image's token count, a placeholder carried in text refused by name) moves with Expanded and ExpandError to crates/vision/src/media.rs, the model-generic owner beside MediaModel, so the decision crate can call it without a serve dependency. serve calls it and maps ExpandError into MediaError. A move: serve's gates unchanged and green. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… as the release does (vision R4c-b) - request: images in llama.cpp's order (the request's `images`, then the state's image_url parts), each a data URL, at most 8; the state comes back without those parts. videos stays 501, a non-data URL and a ninth image stay 400. The request is valid with images; encode and the label model refuse them by name (NotSupported, llama.cpp's hint), so today's seats answer as before. - encode_media(tok, req, &dyn MediaModel, counts, max): the media piece is the placeholders and a "\n" tokenized in one call, each pad run expanded to its image's count through vision::media::expand_spans; Encoded.image_spans names them; fixed counts the media ids; a placeholder in text and media ids past the context are refused by name. - gate-decision-clef: hw_clef_image_ids_equal_the_release — every set D request's input_ids equal the release's, list for list (6 of 6). Set D (images.jsonl) states no identity, so this clause reads it raw beside the same run's reference.jsonl (its revision equals clefvis.sh's, its ids equal) — a substitute for a family check until the writer states one. FAIL-first: D3 (no "\n" after the last image) red on the box at c1 234, c2 1108, c3 234, i640 338, i1024 806; D1 and D2 red in host tests (set D has no state image part to catch them). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ile, from the listing or the verified cache Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eat flags and projector, the encoder reserve in the whole-fit verdict (qwen35_open::open_seated), Body35's media hidden call, the image refusals by name Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s with the encoder, 501 with llama.cpp's hint without it, the image 400s, the --hf projector pick Co-Authored-By: Claude Opus 5.5 <[email protected]>
… open_tower open a seat's projector and tower for any serve seat, merged_cells and Flags::wanted beside them (span_rows loses its rows_of parameter); image_plan holds the plan's side of an image input free of the encoder crates (the tower's reserve on the stage card, the refusal that names it, the rotation table's bytes per position) so every build's placement can take it; ds41's seat opens through them Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nd prefill_media in serve_seats/qwen3, the tower's reserve and the rotation tables in qwen3moe's placed plan and whole fit (each named in the ctx and whole-fit lines), the &VISION record; gate_qwen3_serve's --images clauses: set E prompt ids, set F chat inside the CUDA/CPU agreeing prefix with a first divergence only at a near tie (PIN F_NEAR_TIE 0.1), an image slot beside a text slot, the refusals and the plan's reserve, each FAIL-first by its own mutant Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ion_seat::open_seat takes the file the seat resolved (the decide seat's --hf pick), open_tower, merged_cells; the whole-fit line's encoder note has one owner, image_plan::note Co-Authored-By: Claude Opus 5.5 <[email protected]>
…the gates that reach it, the Qwen3.6 image clause's plan budget has its defaults twin, rustfmt Co-Authored-By: Claude Opus 5.5 <[email protected]>
…is tree on a contributor's machine with a card of its own - docs/contrib/local-check.md rows 1, 3, 4, 5 and 7. No ssh and no rsync: bash runs the same command line in this tree, guard and profile and exports included. The environment file is BLOOMERY_ENV_FILE (default ~/bloomery-env.sh; missing: 69). Refused (64) on a host that is not Linux, with BLOOMERY_BOX_QUEUE=1, and where /root/bloomery-cpu.lock exists. - BLOOMERY_LOCK_DIR (tools/ref/lease-probe.sh's LOCK_DIR, /root when unset) holds the timing lease, the holds, the gate locks, the V4.1 load lock and queue and the batch hold. Local mode defaults it to ~/.cache/bloomery/locks and makes it. It refuses (64) a relative path, which two trees would read apart, and /root however it is spelled, where its guard would make the box's lease file; an environment file or BLOOMERY_BOX_ENV that moves it after the guard is refused (64), and so is an environment file's BLOOMERY_ARCH other than the one the recipe expanded. lease-probe.sh's holds glob and give-way check and gpu-gate.sh's lock descriptors take the path whole, so a path with a space or a ; works. - lease-probe.sh owns the box's mark: on_box (/root/bloomery-cpu.lock exists) and box_lock_dir (a directory that is /root). box.sh, gpu-gate.sh and lease_take read them. - gpu-gate.sh: BLOOMERY_BOX_CARD=local takes one lock, bloomery-gate-local.lock, for what the machine shows, and leaves CUDA_VISIBLE_DEVICES as it finds it; its lock directory is never /root (64). `both` in BLOOMERY_CARD or BLOOMERY_GATE_CARD is refused (64); a held lease is waited for as the lock is. On the box, BLOOMERY_BOX_CARD=local and a BLOOMERY_LOCK_DIR other than /root are refused (64), as lease_take refuses another lease file there. - CUDA_OXIDE_BACKEND is unset after the environment file (row 7), so cargo oxide builds and keeps its own backend (no rc 70 check). BLOOMERY_REMOTE adds no CARGO_BUILD_JOBS. - The command runs without the variables box.sh reads on this side (BLOOMERY_MODEL above all: the model crate's tests read it as a model path), without box.sh's own outputs (BLOOMERY_REF_MODEL_PROFILE, the fixture tier's BLOOMERY_CARD_BUDGET and BLOOMERY_FIXTURE_MODEL) and without the lease's file names, as over ssh. - box-gc.sh refuses (64) local mode: its root is then the contributor's tree, whose binaries are their own runs. - Unset or 0 leaves the ssh, rsync and queue arguments box.sh builds byte-identical, direct and queued. - card-tests: the local mode cases, the lock directory (two holds' give-way under a path with a space among them), the refusals, LOCAL=0 against unset, and on the box gpu-gate.sh's box refusals; the helpers drop the new variables a caller in local mode would pass. gpu-gate.sh --self-test: the local lock, the V4.1 load lock, a held lease. FAIL-first: against main's box.sh, gpu-gate.sh, lease-probe.sh, lease.sh and box-gc.sh, 27 card tests are red. With gpu-gate.sh's local arm removed the self-test's six local cases are red, and with take_local not reading the lease its lease case is red. On a stand-in for the box (a root container where /root/bloomery-cpu.lock exists), removing gpu-gate.sh's box refusal turns its two card tests red.
…ERY_BOX_CARD=local): timing-card.sh times the one card nvidia-smi lists by UUID, the lease and its trace sit in BLOOMERY_LOCK_DIR, the witness prints the card, its Xid count, the shared memory pool and the machine, and depth-qwen3moe.sh fails an arm on an Xid or a lost card FAIL-first: against the local mode commit's timing-card.sh, lease.sh, arm-place.sh, depth-qwen3moe.sh and lcpp-warm.sh, 18 card tests are red on a Mac (the same 18 of 583 on Linux): 17 of the 18 local mode cases (the 18th, an arm on a card that answers, is a control) and lease_take's machine lease under BLOOMERY_LOCK_DIR. With lease.sh's local label and its trace path in the lock directory removed, the lease self-test's tag-local-busy and trace-file-lock-dir are red. Against the local mode commit's runner the stub suite's local, local-xid and local-twocard cases are red (3 of 69, on Linux). With the journal check reading its stderr with its stdout, the case of a journal that only warns on stderr is red; with the local refusal tagged [timing-cards], its tag case is red. The pool line's fields are pinned by the stub suite's local case alone (with the earlier pool line, 1 of 69 is red on Linux); the bound on the UUID query and the journal check's skip for root have no test that can see them.
…ork's cargo-oxide (87bc9518, merged on bloomery) reads `[target.<triple>] extra-rustflags`, so .cargo/cuda-oxide.toml carries znver3 (with -sse4a) for x86_64-unknown-linux-gnu only and target-cpu=native for aarch64-unknown-linux-gnu, and .cargo/config.toml takes the same aarch64 table; the flat znver3 reached aarch64 builds, where rustc warned on every crate and crashed in LLVM on glob and regex-syntax. check-rustflags reads each list's codegen options in every spelling rustc takes (-C x, -Cx, --codegen, target_cpu for target-cpu), holds each triple's two lists equal, x86_64 to znver3 and -sse4a, aarch64 to an aarch64 CPU name (native, generic, cortex-*, neoverse-*, apple-*) and no target-feature, and refuses a top-level CPU flag; its twelve cases (the old flat list and its joined spelling, znver3 or haswell or an x86 feature or the target_cpu spelling on aarch64, a missing side, ...) run red on every call. The x86_64 flags an oxide build gets with --target x86_64-unknown-linux-gnu are byte-identical to the flat list's. The [patch] pin moves 4da6c138 -> 87bc9518 (pin/4da6c138 is tagged); 87bc9518 differs from 4da6c138 only in crates/cargo-oxide, so the backend crates are untouched Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…t the pinned rev (midagedev#36 review) — a cargo-oxide older than 87bc9518 reads only the top-level extra-rustflags and ignores the [target.<triple>] tables without a word, so with this branch's .cargo/cuda-oxide.toml it would build the host code without znver3 and -sse4a while every check stays green. A command that builds with cargo-oxide (one that names `cargo oxide`, `gate.sh --oxide` or `release/build.sh`, once any `release/build.sh --check`, which only reads built binaries, is taken out of it, so a build chained after a --check is still checked) now reads `cargo install --list` on the box, after the BLOOMERY_BOX_ENV exports so a CARGO_HOME or PATH set there is the one checked, and goes on only when its cargo-oxide line names the pin's rev (`...?rev=<rev>#<short>`); any other rev, or an install with no rev (a path install), stops with rc 70 naming the installed rev, the pin and the reinstall line in docs/BUILD.md. Other commands are unchanged. card-tests: the remote command of each of the three forms carries the check, after a BLOOMERY_BOX_ENV CARGO_HOME, and so does a --check chained with a build; a plain cargo call and a lone `release/build.sh --check` do not; the check run against a stub `cargo install --list` passes the pin and refuses 4da6c138 and a path install. FAIL-first: with the old box.sh the presence check and both refusals were red (the pin case passed) Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…pointee, so the decode gemvs' L2 row prefetch shares it A move: ptx-scan --no-jit of generate_qwen3moe equal to main's, the table and the md5 of all 215 entries.
…e row before the walk Each lane issues prefetch.global.L2 for one 128-byte line of the warp's row per pass, from the line that holds the row's first byte, before the walk. A hint: it changes no value. Each kernel that walks a decode row gains a `_prefetch` entry that does this: q4k_gemv, q6k_gemv, q4k_gemv_sel, q6k_gemv_sel, qwen3moe_qkv_q4k, qwen3moe_o_resid_q4k, qwen3moe_head_q6k_argmax, qwen3moe_gate_up_swiglu_q4k (its gate and up rows) and the four router-norm kernels (warp 0, on the first token). row_prefetch reads CU_DEVICE_ATTRIBUTE_INTEGRATED when the Gpu and each kernel set load; the host launches the `_prefetch` entry on an integrated device and the plain one elsewhere, and the launch-order gates name the entry Gpu::row_prefetch picks. On a card with its own memory the prefetch costs more than it hides (an A6000 read 0.957 of main's decode with it on), and the plain entries there are main's: ptx-scan --no-jit of generate_qwen3moe prints the md5 of all 217 of main's entries unchanged, plus the twelve `_prefetch` entries. q4k_gemv, q6k_gemv and qwen3moe_o_resid_q4k share their body with their `_prefetch` entry through one inline walk over a const PREFETCH, as gate_up_row and norm_row_body do. For q4k_gemv_sel, q6k_gemv_sel, qwen3moe_qkv_q4k and qwen3moe_head_q6k_argmax that walk changed the plain entry's PTX, so the `_prefetch` entry is a copy of the body. A single entry that took the device fact as an argument did not keep main's code where the prefetch does not run: sm_86 ptxas put qwen3moe_o_resid_q4k at 64 registers instead of 48, and that walk read 0.99 of main's on the Spark. On a DGX Spark (GB10, stock clocks), Qwen3.6-35B-A3B Q4_K_M decode tok/s over main's in one lease, six rounds, n = 96, on two machines: 1.1616 ± 0.0070 and 1.1668 ± 0.0022 at depth 6, 1.1664 ± 0.0020 and 1.1681 ± 0.0012 at depth 512, 1.1631 ± 0.0085 and 1.1611 ± 0.0110 at depth 4096; prefill at P = 512 and 4096 reads 1.0001 to 1.0064 of main's, each interval holding 1. A same-binary A/A arm read 0.9987 ± 0.0038 and 1.0022 ± 0.0047.
af9c455 to
fed530d
Compare
|
This branch now points at its commit in the 0.3.0 release train. The ptx-scan of generate_qwen3moe keeps all 217 existing entries byte-identical and adds the 12 prefetch entries. It lands with the release tonight. |
…its fork A `9>&-` on the command is applied after its words are expanded. The background child held the lease through the $(declare -f …) fork, so on a loaded CI runner the next take or probe found it held (#27). The subshell now runs `exec 9>&-` first. The self-test gains trace-waiter-frees-lease-slow-fork, which slows that fork by 0.3 s: it fails on the old spawn and passes on the fix. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… locality was the term The opening says what the document is, where each lever stands and how to read it, and explains GEMV and PDL. The Verdict gains a Status column; it keeps the design's predictions, and where one was refuted it is struck with a pointer to section 10, which holds the measured values for each card. Section 4.4 opens with "Closed by section 10's measurement" and the rule's arithmetic with the measured c_node. In the text four predictions are struck with the corrected value and the measuring comment beside them: c_node 0.6 to 1.5 µs (now 0.553 µs), the row-locality form's −1.4 ms bound on GB10 (passed at stock clocks by −1.550 ms on public commits and −1.65 and −1.69 ms under a lease, and by −1.62 ms at a 1989 MHz cap), 0 ± ruler on the A6000 (0.9570 of main's decode tok/s), and section 4.3's 74 KB in flight (66 to 295 KB at the JIT's 4 blocks per SM). Section 10 adds the prefetch pair on public commits (fed530d against 4a89639 at stock clocks), the lease numbers from midagedev#27, the A6000 run and the router rescan that landed (midagedev#35). headpick-warmup.md and adaptive-picks.md cite sparkdec by section instead of line, and adaptive-picks.md 3.14 now cites lever 1d (section 4.3), whose model gives 0 on the A6000, instead of the router regrid's band.
…s what its earlier commits earned A merged pull request is labelled from its merge commit against that commit's first parent. A rebase merge, the only kind this repository's merge button allows, has no merge commit: merge_commit_sha is the pull request's last commit, so the diff covers that commit alone, and the labels its open runs put on for the earlier commits came off at the merge. A merge now adds labels and removes none. Walking back the pull request's commits does not fix the diff: a stack pushed at once (#27, #36, #38, #39) lists every commit below it, so each would take the whole stack's labels.
… locality was the term The opening says what the document is, where each lever stands and how to read it, and explains GEMV and PDL. The Verdict gains a Status column; it keeps the design's predictions, and where one was refuted it is struck with a pointer to section 10, which holds the measured values for each card. Section 4.4 opens with "Closed by section 10's measurement" and the rule's arithmetic with the measured c_node. In the text four predictions are struck with the corrected value and the measuring comment beside them: c_node 0.6 to 1.5 µs (now 0.553 µs), the row-locality form's −1.4 ms bound on GB10 (passed at stock clocks by −1.550 ms on public commits and −1.65 and −1.69 ms under a lease, and by −1.62 ms at a 1989 MHz cap), 0 ± ruler on the A6000 (0.9570 of main's decode tok/s), and section 4.3's 74 KB in flight (66 to 295 KB at the JIT's 4 blocks per SM). Section 10 adds the prefetch pair on public commits (fed530d against 4a89639 at stock clocks), the lease numbers from midagedev#27, the A6000 run and the router rescan that landed (midagedev#35). headpick-warmup.md and adaptive-picks.md cite sparkdec by section instead of line, and adaptive-picks.md 3.14 now cites lever 1d (section 4.3), whose model gives 0 on the A6000, instead of the router regrid's band.
… locality was the term The opening says what the document is, where each lever stands and how to read it, and explains GEMV and PDL. The Verdict gains a Status column; it keeps the design's predictions, and where one was refuted it is struck with a pointer to section 10, which holds the measured values for each card. Section 4.4 opens with "Closed by section 10's measurement" and the rule's arithmetic with the measured c_node. In the text four predictions are struck with the corrected value and the measuring comment beside them: c_node 0.6 to 1.5 µs (now 0.553 µs), the row-locality form's −1.4 ms bound on GB10 (passed at stock clocks by −1.550 ms on public commits and −1.65 and −1.69 ms under a lease, and by −1.62 ms at a 1989 MHz cap), 0 ± ruler on the A6000 (0.9570 of main's decode tok/s), and section 4.3's 74 KB in flight (66 to 295 KB at the JIT's 4 blocks per SM). Section 10 adds the prefetch pair on public commits (fed530d against 4a89639 at stock clocks), the lease numbers from midagedev#27, the A6000 run and the router rescan that landed (midagedev#35). headpick-warmup.md and adaptive-picks.md cite sparkdec by section instead of line, and adaptive-picks.md 3.14 now cites lever 1d (section 4.3), whose model gives 0 on the A6000, instead of the router regrid's band.
… locality was the term The opening says what the document is, where each lever stands and how to read it, and explains GEMV and PDL. The Verdict gains a Status column; it keeps the design's predictions, and where one was refuted it is struck with a pointer to section 10, which holds the measured values for each card. Section 4.4 opens with "Closed by section 10's measurement" and the rule's arithmetic with the measured c_node. In the text four predictions are struck with the corrected value and the measuring comment beside them: c_node 0.6 to 1.5 µs (now 0.553 µs), the row-locality form's −1.4 ms bound on GB10 (passed at stock clocks by −1.550 ms on public commits and −1.65 and −1.69 ms under a lease, and by −1.62 ms at a 1989 MHz cap), 0 ± ruler on the A6000 (0.9570 of main's decode tok/s), and section 4.3's 74 KB in flight (66 to 295 KB at the JIT's 4 blocks per SM). Section 10 adds the prefetch pair on public commits (fed530d against 4a89639 at stock clocks), the lease numbers from #27, the A6000 run and the router rescan that landed (#35). headpick-warmup.md and adaptive-picks.md cite sparkdec by section instead of line, and adaptive-picks.md 3.14 now cites lever 1d (section 4.3), whose model gives 0 on the A6000, instead of the router regrid's band.
What and why
The L2 row prefetch from #17 (#17 (comment)), as its own pull
request, now only on an integrated device (your option 1 after the A6000 A/B), and with a second entry per kernel so a
card with its own memory runs main's PTX. Part of #13.
A decode gemv warp walks its weight row with few loads in flight per lane: the walk's addresses are known in advance,
but each term feeds the next add. On a GB10 the gemv kernels read at 177.5 GB/s against 235.6 GB/s for a plain read of
the same memory (the section 2 reading on #13), so I read the step as waiting on DRAM latency more than on bandwidth.
With this change, each lane of the warp first issues
prefetch.global.L2for one 128-byte line of the row per pass,starting at the line that holds the row's first byte. The whole row is requested before the walk, and the walk's loads
hit L2. The prefetch is a hint. It reads nothing into registers and changes no value.
Each kernel that walks a decode row gains a
_prefetchentry that does this:q4k_gemvandq6k_gemv(lib.rs),q4k_gemv_selandq6k_gemv_sel;qwen3moe_qkv_q4k,qwen3moe_o_resid_q4kandqwen3moe_head_q6k_argmax;qwen3moe_gate_up_swiglu_q4k, for its gate row and its up row;qwen3moe_router_norm,qwen3moe_router_norm_m,qwen35moe_router_norm,qwen35moe_router_norm_m): warp 0 asks for the block's f32 row on the first token, and the row loads into L2 whilethe norm runs.
gpu::row_prefetchreadsCU_DEVICE_ATTRIBUTE_INTEGRATEDonce when the model loads (besideraw_device_integrated,which the room on an integrated device already reads).
Gpuand each qwen3moe kernel set keep it asrow_prefetch,and each launch of those kernels picks the
_prefetchentry when it is set and the plain entry when it is not. TheGB10 reports 1; a card with its own memory reports 0 and launches only the plain entries, which are main's:
tools/ptx-scan.sh --no-jit generate_qwen3moeprints the same md5 as main for all 217 of main's entries, and the 12_prefetchentries besides.Gpu::row_prefetchgives the same fact to the gates that compare a captured launch orderby name (
hw_nodes_name_each_kernel_in_enqueue_orderingraph.rs, and the V4.1 step and skew gates' shadow tables inds41_shadow.rs), so they expect the entry the device launches.How the two entries share their body:
q4k_gemv,q6k_gemvandqwen3moe_o_resid_q4kcall one#[inline(always)]walk over aconst PREFETCH: bool;gate_up_rowandnorm_row_bodytake the same const. Both entries compute their row and call the walk.q4k_gemv_sel,q6k_gemv_sel,qwen3moe_qkv_q4kandqwen3moe_head_q6k_argmaxkeep main's entry as it is, andthe
_prefetchentry is a copy of its body with the one prefetch call. Sharing those bodies through the same inlinewalk changed the plain entry's PTX (a block order, an
orthat became anadd), so the md5 did not hold. Each ofthe four plain entries gains one doc line that names its copy.
The common Q4_K and Q6_K entries have callers outside qwen3moe too:
enqueue_gemv_q4kincrates/gpu-deepseek41/src/dense.rs,enqueue_gemv_q6kincrates/gpu-deepseek41/src/draft/head.rsandenqueue_gemv_q4k_selincrates/gpu-glm5next/src/tier.rs. They launch throughGpu, so on an integrated devicethose paths get the prefetch as well. I timed only the Qwen3.6 step.
On two DGX Sparks, in one lease each against main at stock clocks (
docs/contrib/dgx-spark.mdsection 3.5),Qwen3.6-35B-A3B Q4_K_M decodes 16.2 % and 16.7 % faster at depth 6, 16.6 % and 16.8 % at depth 512, and 16.3 % and
16.1 % at depth 4096. Every arm generates the same ids. Prefill at P = 512 and 4096 does not move. The tables are
under "What I ran".
Other row walks do not prefetch yet: the Q3_K, IQ and Q5_1 gemvs, the DeepSeek and GLM crates' own kernels, and the
m-column entries (
q4k_gemv_mcol,qwen3moe_qkv_q4k_mcol,qwen3moe_o_resid_q4k_mcol) that this model's dense Q4_Kprojections take for a prompt of more than one token. I measured only the Qwen3.6 decode step, so I left them as they
are.
There are two commits. The first moves
global_addr(thecvta.to.global.u64conversion) fromlinear/delta.rsintocores.rs, generic over the pointee and otherwise unchanged, so the prefetch can share it. The second adds theprefetch, the
_prefetchentries and the launch split.Code shape
_prefetchentries are copies of their plain entry's body(
q4k_gemv_sel,q6k_gemv_sel,qwen3moe_qkv_q4k,qwen3moe_head_q6k_argmax). Each copy's doc line says it isa copy and why, and each plain entry's doc names its copy, so a change to one points at the other. No gate on a
card with its own memory runs the copies; on an integrated device the owning gates run only them. Shared through
an inline walk, those plain entries no longer matched main's md5. The other
eight share their body through a
const PREFETCHwalk. The prefetch itself is one helper,cores::l2_prefetch, whose address conversion iscores::global_addr, lifted out oflinear/delta.rsby thefirst commit. Each call site passes its row's byte range (144 bytes per Q4_K superblock, 210 per Q6_K, 4 per f32),
the range its walk reads. The device fact has one reader,
row_prefetch._prefetchentries and thesame launch split. The pick is a device fact read at load, not a lever, and no model branches on it.
w, andeach call site's range is the row the kernel then walks.
tools/unsafe-ratchet.txtgoes fromgpu 1682 188togpu 1717 191with aPIN(2026-10-11):line that counts each part: the prefetch hint (one block), the three walks (three unsafe fns)and their six calls, the four copies' blocks (2 + 6 + 1 + 10) and the gate-up and router-norm entries'
(1 + 4 × 2), each with its SAFETY line. The
_prefetchentries that take more than seven arguments carry theclippy::too_many_argumentsallow that main's kernel entries use, with the same reason, and the lint count staysat the ratchet's 41.
tools/ref/ptx-shapes.tsvgains a row for each_prefetchentry ingenerate_ds41andgate_e2e; the values are under "What I ran".cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up.Duplication found or removed:
crates/gpu/src/linear/delta.rs:117(global_addr), lifted tocrates/gpu/src/cores.rs:73and shared bylinear::deltaandcores::l2_prefetch. Duplication added: the fourcopied
_prefetchbodies above.What I ran
On a Mac with the pinned nightly, at this branch's head on main
6d2b1765:tools/ptx-scan.sh --no-jit generate_qwen3moe(sm_86, the dev container's ptxas), main against this branch: the md5block holds the same 217 entries with the same md5 on both, and this branch adds exactly
q4k_gemv_prefetch,q4k_gemv_sel_prefetch,q6k_gemv_prefetch,q6k_gemv_sel_prefetch,qwen3moe_qkv_q4k_prefetch,qwen3moe_o_resid_q4k_prefetch,qwen3moe_head_q6k_argmax_prefetch,qwen3moe_gate_up_swiglu_q4k_prefetch,qwen3moe_router_norm_prefetch,qwen3moe_router_norm_m_prefetch,qwen35moe_router_norm_prefetchandqwen35moe_router_norm_m_prefetch. The main side here was main plus the two runner commits section 3.5 needs on a Spark(#38 and #39), which change no kernel source: their only file under
crates/is the lever registry. To reproduce: buildgenerate_qwen3moeat main and at this branch, run the scan on each, and diff the lines afterptx-scan-md5:.tools/ref/ptx-shapes.tsvgains a row for each_prefetchentry ingenerate_ds41andgate_e2e. I scanned bothbinaries on main and on this branch with
tools/ptx-scan.sh(sm_86, ptxas 13.3.73, with the driver JIT) on a DGX Spark:spill(ptxas) reads 0 for all 12 entries in both binaries, as their plain entries do. On main the column equals thetable in all 285 and 217 rows, and every main entry reads the same spill, registers and
jit_localon this branch.jit_localis your 3090's JIT, which I cannot run. The GB10's JIT reads 0 for all 12. On main the GB10's JIT differsfrom the table in 13 rows of
generate_ds41and 8 ofgate_e2e, always above it (for exampleq4k_gemv_tiles184against 0), so it does not stand in for the 3090. I pinned the 12 rows at 0 like their plain entries.
just gate-ptx-spillon your box is the check; a row that reads otherwise there takes your number.I measured on main
2ce989d7with those two runner commits and ranmac-staticon6d2b1765, then rebased the twocommits onto
0c8397dbunchanged. The four upstream commits since2ce989d7add the remote static-tier tool(
tools/mac-remote.shwith its recipe, docs andcheck-recipes.shlines) and changecrates/serve/; none touches afile of this branch.
The box gates need your workstation. On one DGX Spark I ran the 42 selected gate recipes that have a fixture-tier
line, through
tools/box.sh's local mode in the dev container, once on main and once on this branch:machine does not have (
ref_qwen35moe,ref_qwen4exp,ref-synth,ref-mtp,ref-vision,glm5next/corpus-prose.ids), the Qwen3.6 file, which the fixture tier does not mount, andgate-gpu-qwen38-serve's--place gate, which asks for a 3090. 4 exit 64 on both: the two-card recipes, which local mode leaves to the box.7 exit 66 on both: the V4.1 fixture set here does not hold the DSpark fixture draft.
gate-gpu-libpasses on this branch (194 tests, then the 3hw_held_tests), withhw_nodes_name_each_kernel_in_enqueue_orderexpectingq4k_gemv_prefetchon the GB10. The V4.1 step gate, whoseshadow table now takes the device fact, is one of the 7 that exit 66 here, so its structure clauses ran on neither
side. On your box the device is not integrated, and the tables hold main's names.
The A/B on two DGX Sparks
tools/ref/depth-qwen3moe.shthroughtools/box.sh's local mode on each Spark's host, in one lease withLC_ALL=C,six rounds with the order rotated each round, n = 96. The arms were
6 bin:ab-m4:6 512 bin:ab-m4:512 4096 bin:ab-m4:4096 6@BLOOMERY_AB_LOAD=arm(eachbin:arm names its binary'spath): "ours" is this branch on main
2ce989d7,bin:ab-m4is main2ce989d7, and the last arm is the machine's A/Aat depth 6. Each machine built both binaries in the dev container (CUDA 13.3.1, the pinned nightly), and both builds
came out the same: ours sha256
a7aed7cdad5d…, main1861c79d7097….Decode, tok/s @ n=96, GB10, Qwen3.6-35B-A3B Q4_K_M (
Qwen3.6-35B-A3B-Q4_K_M.gguf, sha2564ac6a06bce551257…). Thestep column is the mean of the rows' mean step.
The runner's ratio lines, each cut after its per-round values (the busy and cold counts after them are 0 throughout):
grows with depth and the row walks do not.
Spark C; its pass runs the expert, router-norm, Q6_K and head row kernels this touches. The 512- and 4096-token
prompts run the gemm path, which this does not touch, and read 1.0064 ± 0.0108 and 1.0022 ± 0.0048 on Spark A,
1.0024 ± 0.0061 and 1.0001 ± 0.0070 on Spark C.
at depth 6, 12 at 512 and 12 at 4096).
2470 MHz (Spark C) around the arms (maximum 3003 MHz; 208 MHz on the idle card before the first arm), and the
clock-event mask was 0 in all 86 blocks.
MemAvailablestayed between 93.9 and 116.7 GiB, above the 21.2 GB modelfile. [cpu-busy] 0 of 42 rows, cold 0 of 42, failed arms 0.
local-appscarries[timing-card-busy]on the 24"pre" witnesses of our own arms (ours and the A/A arm): that process is the arm itself, loaded and waiting under
--arm-sync. No "post" witness has it.The card predicted +14 to +18 % at depth 6 and the runs read +16.2 % and +16.7 %.
spark-prefetch-rebase.card (sha256 e6d3d4cf3adb…, as the lease printed it)
The earlier sittings: this form on the previous main, one entry with the device fact as an argument, the prefetch without the device gate, and its first form
This form, on main
9873a363before the rebase (cardspark-prefetch-split, the same arms against that main), read1.1654 ± 0.0054 (Spark A) and 1.1700 ± 0.0044 (Spark C) at depth 6, 1.1627 ± 0.0049 and 1.1666 ± 0.0034 at depth 512,
and 1.1610 ± 0.0058 and 1.1653 ± 0.0107 at depth 4096, with an A/A arm of 1.0007 ± 0.0030 and 1.0032 ± 0.0082. The
rebase brought in the router's top-k change (#35), which both arms carry.
The form before this one kept one entry per kernel and passed the device fact as a
prefetch: u32argument, withl2_prefetchreturning at once when it was 0. On the same two Sparks against main it read 1.1644 ± 0.0081 (Spark A)and 1.1698 ± 0.0153 (Spark C) at depth 6, 1.1669 ± 0.0008 and 1.1657 ± 0.0087 at depth 512, and 1.1655 ± 0.0066 and
1.1599 ± 0.0114 at depth 4096, with an A/A arm of 0.9958 ± 0.0062 and 1.0016 ± 0.0065. This form reads the same within
those intervals. Its forced-off arm is the reason for the second entry; see "What I ran into".
Before the device gate the prefetch ran on every card. Against main in one lease each, on Spark A and on a second
machine, Spark B, it read 1.1649 ± 0.0079 and 1.1609 ± 0.0050 at depth 6, 1.1653 ± 0.0029 and 1.1588 ± 0.0032 at
depth 512, and 1.1635 ± 0.0044 and 1.1535 ± 0.0106 at depth 4096 (card
spark-prefetch-final, predicted +14 to+18 %), with an A/A arm of 0.9987 ± 0.0041 and 0.9990 ± 0.0060. That is the form your A6000 A/B read at 0.9570 ± 0.0006.
The form in the #17 probe issued its lines from the row's first byte, so a row that starts inside a line and reaches
past
ceil(bytes / 128)lines left its last line to the walk. On Qwen3.6 that is a quarter of the Q6_K down rows(K = 512, 420 bytes). That form read 1.1675 ± 0.0046 on Spark A and 1.1626 ± 0.0072 on Spark B at depth 6 against
main. The form in this pull request counts lines from the line that holds the row's first byte; against the first
form in one lease on Spark B, under a non-inferiority card (
spark-prefetch-aligned, predicted 0 to +0.5 %):The effect came out below the predicted band but inside the ruler: −0.13 % at depth 6, not resolved by six rounds. I
kept the aligned form because it asks for every line of the row, which is what the helper's contract says.
I did not commit the cards, because
docs/is yours.What I ran into
One entry with a runtime flag did not keep main's code where the prefetch is off. The form before this one passed
the device fact as an argument and returned from
l2_prefetchat once when it was 0. I expected a card with its ownmemory to run main's walk plus one uniform compare per row walk. It did not: with the argument forced to 0, the Spark's
walk read 0.9899 ± 0.0065 (Spark A) and 0.9879 ± 0.0106 (Spark C) of main's at depth 6, per round in the same lease.
The prefetch loop sits in each kernel's code whether or not it runs, so the compiler allocates registers for it. From
tools/ptx-scan.sh(registers per thread, main to that form):q4k_gemv_selqwen3moe_qkv_q4kqwen3moe_o_resid_q4kqwen35moe_router_norm#[launch_bounds(256, 5)]onqwen3moe_o_resid_q4kheld ptxas at 48 registers but spilled 136 bytes, so I did nottake it. A second entry per kernel avoids the question, and the md5 block shows it with no timing.
Sharing the body through an inline function can still change the plain entry's PTX. My first two-entry form put
every kernel's body in an
#[inline(always)]walk over aconst PREFETCH: bool, called by both entries. The constremoves the prefetch from the plain entry, but the md5 of four plain entries still moved:
q4k_gemv_sel,q6k_gemv_sel,qwen3moe_qkv_q4kandqwen3moe_head_q6k_argmax.tools/ref/ptx-canon.pyon the two scans showedblocks in another order and an
orthat became anaddin an address. I did not find a source form that kept thosefour byte for byte, so their plain entries are main's text and the
_prefetchentries are copies. If you would ratherhave one body and accept a PTX change in those four, the inline walk is the other choice; it would then need the A6000
non-inferiority A/B that the md5 avoids here.
Two cuda-oxide limits shaped the code, in case they help the next kernel that needs two entries:
thread::index_1dand the other thread index helpers work only inside a#[kernel]or#[device]fn, so each entrycomputes its row and passes it to the walk; and a generic
#[device]fn compiles as#[inline(never)], so the walksare plain
#[inline(always)]fns, not#[device]ones.Your nsys table also shows
qwen35moe_router_norm30 us faster with the prefetch on the A6000. A card with its ownmemory runs the plain entry here too; a separate pull request can switch that one kernel, with your A/B.
Hardware
DGX Spark, two machines of the same build: NVIDIA GB10 (compute capability 12.1), driver 595.84 (
nvidia-smi:NVIDIA GB10, 595.84, CUDA Version 13.2), CPU Cortex-X925 and Cortex-A725 (20 cores), 128 GB unified memory, Ubuntu24.04.5 LTS, kernel 6.17.0-1032-nvidia. The dev container has CUDA 13.3.1, LLVM 21.1.8 and the pinned nightly. The
kernels are
sm_86PTX through the driver's JIT (docs/contrib/dgx-spark.mdsection 5, answer 7). Clocks are stock:maximum SM clock 3003 MHz, 2411 to 2483 MHz read around the arms, clock-event mask 0.
Docs
I did not change the docs. The spot this moves is
docs/contrib/dgx-spark.mdsection 2, "our gemv kernels' own rateis still unread" and the decision rule under it. By the whole-step reading on #13 (2061.4 MB a step over the step's
p50), main reads 175.4 and 175.3 GB/s in these leases and this branch 204.5 and 204.8 GB/s
[derived: #13's byte count, not re-read on this build]. That is the whole step, not the gemv kernels' own rate the rule names, which I havenot re-read with ncu and nsys on this build.