Repository navigation
f32 gemv: the m-column walk keeps eight chunks' loads in flight a column - #511
Conversation
The router and f32_gemv at 2 to 8 columns walked one chunk a trip behind each column's guard, one load in flight a lane. A trip now takes LANE_UNROLL chunks: the row's words once, then each live column's chunks loaded before its first multiply-add. f32_load_chunks owns the eight stride-32 loads and f32_fold_chunks the fold, and both single-column walks use them too, so every walk adds a column's chunks in the same order and its sums keep the single-column body's bits.
There was a problem hiding this comment.
Verdict: CLEAN: No correctness or proven quality defect survives the review.
Non-blocking
⚠ Complete the device proof: crates/gpu/src/q8f32.rs:123.
Each eight-chunk trip loads eight weight values per lane, then eight activation values before folding each live column. For the occupancy/geometry class, attach base/head JIT register and spill tables and the selected owning just gate-* commands with output. Include the nvidia-smi line and raw A/B output for the stated commits. The no-JIT md5 summary and timing tables leave this proof incomplete; recording it now makes later regressions comparable.
Checked
Duplicates: 3 new items checked; no duplicate owner. Dryer's pair at q8f32.rs:271/325 has different load widths; the shared eight-chunk loads and folds now use the same helpers.
Complexity: f32_lane_partials rose from 10 to 18 through column guards in the unrolled loop; its responsibility remains one row walk.
Silent failure: 0 added default or swallowed-error sites. GEMV and router launchers reject invalid geometry and propagate shape errors.
Tests: static mutation check: dropping the column-7 fold at line 156 makes the independent scalar assertion at line 2350 fail; dropping the wider walk's fold at line 517 makes line 2361 fail. Rust tests were not executed here.
Gates: unsafe ratchet adds 15 blocks and 2 functions with a dated PIN and reason; no numerical band changed.
Escapes: none of C1–C4 matched. Exact-trip boundaries, all tail lengths, inactive columns and unchanged per-column FMA order were checked.
Notes
The PR body still marks the unit-test, t0 and clippy results TBD. No GPU gate run meeting CONTRIBUTING.md's evidence list is supplied.
Card check: needs-gpu. This pull request changes crates/gpu/src/q8f32.rs and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
|
The review is done and the contribution check passed, so I'm merging this. |
MTP 검증 단계에서 라우터와 F32 GEMV가 여러 열을 계산할 때 메모리 읽기를 여러 개 미리 띄우게 바꿔서, DGX Spark 한 대에서 MTP 디코드를 빠르게 하는 작업입니다.
Part of #493, section 8.5 (one DGX Spark, TP=1).
What and why
This PR speeds up the MTP verify pass, where the target model checks 2 to 4 drafted rows at once. On one DGX Spark running Qwen3.8-Flash-Next with the shared Q8_0 MTP draft, drafted decode at 4,096 tokens went from 47.84 to 51.28 tok/s on the code-functions prompt set (+7.2%) and from 32.38 to 34.91 tok/s on English prose (+7.8%). Every run decoded the same tokens as main.
The change is in
f32_lane_partials(crates/gpu/src/q8f32.rs). It is the per-lane row walk thatf32_gemvandqwen35moe_router_fused_512use when a launch has more than one column. The walk already read each weight word once and multiplied it into every live column. It moved one 32-value chunk per trip, though, and each column's multiply-add sits behind a runtime column guard, so a lane had only one load in flight.LANE_UNROLL(8) chunks. The lane loads the row's eight weight words once. Each live column then loads its eight values before its first multiply-add, in the new helperf32_fold_chunks. The helperf32_load_chunksowns the eight stride-32 loads, for the weight words and the column values alike. The guarded one-chunk walk handles the remaining chunks when the row does not fill a whole trip.f32_lane_partial_1colandf32_lane_partial_1col_w32load and fold their eight-chunk trips through the same two helpers, so the chunk offsets and order have one owner. Their compiled code does not change: against main, aptx-scanofgenerate_qwen3moeandgenerate_ds41moves onlyf32_gemv,qwen35moe_router_fused,qwen35moe_router_fused_512andqwen3moe_router_fused, the four entries that run the m-column walk. Every other entry keeps its PTX md5.q8f32::tests::f32_walks_are_the_scalar_walk: for 1 to 8 columns and every row length from 32 to 1536 (the unrolled trips of both widths and each tail the walks can end in), column c equals a plain sequentialfmawalk over column c's chunks, bit for bit, in every lane. One column runs the single-column body, andf32_lane_partial_1col_w32must give the same bits. The oracle does not callf32_fold_chunks. Swapping two multiply-adds in that helper fails the test, and so does dropping the fold call from either single-column walk.tools/unsafe-ratchet.txt: the gpu crate goes from 1943 to 1958 unsafe blocks and from 212 to 214 unsafe fns, with aPIN(2026-10-19):line. Each fold call has its own block and SAFETY line.Release notes: Changed: the F32 GEMV and the fused Qwen3.5 MoE router keep eight loads in flight per lane when a launch has 2 to 8 columns, which shortens each MTP verify pass.
Code shape
f32_gemvand the router already sharef32_lane_partials, so both get the change from one place. The m-column walk and both single-column walks load and fold eight chunks through the same two helpers.check_gemv_geometrystill holds the column count to 1..=8.PIN(2026-10-19):and its reason.cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up.rustfmt --checkis clean onq8f32.rs; clippy on the head: TBD(clippy)Duplication found or removed (
path:line), or "none": the eight-chunk load and multiply-add body off32_lane_partial_1colandf32_lane_partial_1col_w32(crates/gpu/src/q8f32.rs), nowf32_load_chunksandf32_fold_chunks.What I ran
On the head
TBD(head):tools/gate.sh --oxide -p bloomery-gpu --release --lib -- q8f32::tests::f32_walks_are_the_scalar_walk: TBD(unit-f32 /test result/)just contrib-check --tier t0: TBD(t0 /DONE tier=t0/)rustfmt --edition 2024 --check crates/gpu/src/q8f32.rs: rc 0.just check-unsafe: ok (29 crates, 2998 blocks, 417 fns, 28 impls).just check-comments: ok (1024 files).PTX_SCAN_ARCH=sm_121 bash tools/ptx-scan.sh --no-jit generate_qwen3moeand the same forgenerate_ds41(built with--features deepseek41), on this tree and with its two files reset to main: onlyf32_gemv,qwen35moe_router_fused,qwen35moe_router_fused_512andqwen3moe_router_fusedchange md5.Decode A/B on one DGX Spark
The A/B ran on
d6fea090against maine8abdc89. When both are built on one tree, thecrates/gpu/src/q8f32.rsof that commit and of this head give the same PTX md5 for every entry ofgenerate_qwen3moeandgenerate_ds41. The head adds thetools/unsafe-ratchet.txtpin. Its newer main changescrates/gpuonly in the Qwen3.8 PLE host decode, which keeps the IQ4_NL rows of the GGUF below on the path they took before.Both binaries were built from one base and alternated in one timing lease, in the order main, head, head, main, main, head for each prompt set. Each run loaded a fresh process, prefilled the first 4,096 tokens of the prompt set from #493 and decoded 96 greedy tokens with MTP. The table gives the median of three runs per arm. The verify column is the median, over the three runs, of each run's median 4-row verify pass.
Every run in order:
In each round the head beat main by 3.19 to 3.73 tok/s on code-fn and by 2.22 to 2.99 tok/s on prose-en.
An nsys trace of the 4-row verify passes on the code-fn prompt set splits the time by kernel. The two kernels this PR changes take 4.25 ms less per pass, close to the 4.93 ms the A/B measured:
qwen35moe_router_fused_512f32_gemvf32_gemvf32_gemvTo reproduce, build
generate_qwen3moeon each commit:and run each binary with
IDSset to the prompt set's first 4,096 token ids, comma separated:The tok/s is the
tok/s(mean)field of theSMOKEline.Hardware
One DGX Spark (NVIDIA GB10, driver 595.84). The binaries were built in the CUDA 13.3.1 devel container and ran on the host. Before the lease no other GPU process ran and the load average was 0.57.
Model:
unsloth/Qwen3.8-Flash-Next-GGUFat revision766911a6b7369840a91dbcd95f9f997acaab6cd6, UD-Q4_K_XL, with the shared Q8_0 MTP draft from the same repository. Context 4,352.What I ran into
None of this blocks the PR. On code-fn, run 1 (main) and run 2 (head) came in below the other runs of their arm, at 45.42 and 49.15 tok/s. The slow runs hit both arms, and neither is a median.
AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.