perf(qwen35): faster concurrent verify rounds on RDNA4 (MMQ tiles and prefetch, batched commit)
Summary
The drafter-attention tile skip from the same work is #958. The q8_1 producers (RMS norms and SWIGLU writing their MMQ reader's rows) moved to #969.
Five changes to the concurrent DFlash verify round of Qwen3.8-27B on the R9700. At C4 a round verifies 4 lanes × 8 tokens, so most of its MMQ calls are 32 columns wide: past the 16-column RDNA4 tile twins, on the parent tiles. Per-request throughput over main: +16% at C3 and C4, +9-10% at C5 and C6, +7-8% at C7 and C8, +3-4% at C2 and paged C1, with no regression at any lane count and 0 errors (measured before the q8_1 producers moved out, see Evidence).
None has a runtime switch: each is always on where its rules allow it. Everything is bit-exact except split-k, which runs only inside a batched verify of two or more lanes. A single request's output is therefore unchanged.
per C4 verify round (Qwen3.8-27B UD-IQ4_XS, R9700, 4 lanes x 8 tokens = 32 columns)
before after
MMQ tile, 17-48 cols parent tiles: IQ3 128-row at x32 measured per type and height: 64-row x48,
(the slow x-tile of the q8_0 path) 32/64-row x32, 32-row x16 for small outputs
x48 tile at 32 cols last 16-column tile computed, unused skipped (compile-time body for mmq_x - 16)
MMQ k-loop __syncthreads waits for every global loads issued one phase ahead, LDS-only
load: loads and dots barely overlap barrier (64-row twins)
small grids 80-tile ffn_down: 1.25 waves on 64 CU split k in 2-4, C>1 verify only
commit 5 D2H validation reads, ~130 launches validated from host copies, 4 launches
replay log, z one copy each per GDN layer read in place (96 launches)
- Measured MMQ tile (
mmq-tile-twin-gate.h). A dense MMQ call of 17–48 columns on RDNA4 takes the tile measured fastest for its type and output height, on the real Qwen3.8 tensors at N = 24/32/48. For example, IQ3_S 5120-row goes from 252 to 204 µs, and the Q5_K lm_head from 2036 to 1691 µs. Every x-tile accumulates each element over k in the same order, so the outputs match the parent bit for bit. Each twin has one bridge entry,mul_mat_q_case_rows<rows>_<type>(ctx, args, stream, mmq_x). - x48 at 32 columns (
mmq.cuh).vec_dot_q8_0_q8_1_mmagets a second compile-time body for the firstmmq_x - 16columns, taken when the tile's valid columns fit. At N=32, IQ4_XS goes from 166.4 to 155.2 µs (−6.7%). At N=48 it is within 1–2.6%, running the full body. - Prefetch kernel and split-k (
mmq.cuhmul_mat_q_pf). The 64-row twins run their plain 2D calls of 17–48 columns through a kernel with these properties:- It issues each phase's global loads one phase early, into registers.
- It waits on an LDS-only barrier.
__syncthreads()also drains every outstanding global load, which is why the loads never overlapped the dot products. - IQ4_XS splits its x load into a fetch and a store, with 32-bit row offsets.
- Without a split it is bit-exact.
- Inside
ggml_backend_cuda_set_mmq_splitk_scope(thread-local, off by default) it splits k in 2 or 4 for grids under 256 workgroups, at 16 or more k-iterations per split on average. The last split to finish a tile sums the partials in split order, so the result is deterministic but not bit-exact against the unsplit sum. - The per-tile counters belong to the backend context and are zeroed on its stream, so two model blocks on one GPU never share them. A context splits only on its own device's stream 0.
- The concurrent engine holds the scope around a verify of two or more lanes only.
- Batched commit (
gdn-replay-log.cu).ggml_backend_cuda_tree_commit_transaction_hostvalidates the concurrent fixed-chain commit from the engine's host copies of the maps instead of reading them back. It then commits in four launches: K/V rows as 16-byte vectors, feature rows, every layer's state, and every conv window. The per-element arithmetic is the same. A refused preflight falls back to the device-validated transaction. - Replay log and z in place (
qwen35_target_graph.cpp,glue_fusions.h). The tree commit reads the replay log through the GDN result's view, as SINGLE_REPLAY already does.strided_gdn_planlets the mapped verify feed z to the fused silu*mul as a strided view.
server/deps/llama.cpp/ggml/
include/ggml-cuda.h + split-k scope, host commit
src/ggml-cuda/mmq-tile-twin-gate.h ~ 17-48 column choices (pure, unit-tested)
src/ggml-cuda/mmq.cuh + prefetch kernel + split-k; x48 body for mmq_x - 16; one twin entry
src/ggml-cuda/mmq.cu ~ twin dispatch by x-tile; split-k scope
src/ggml-cuda/mmq_tile_twins.h ~ one bridge entry per twin
src/ggml-cuda/template-instances/ + rows64 IQ4_XS/Q5_K/Q3_K/IQ2_S, rows32 Q3_K/IQ2_S twins
src/ggml-cuda/common.cuh + the context's split-k counters
src/ggml-cuda/gdn-replay-log.cu + host-validated batched commit
server/src/qwen35/
concurrency/qwen35_seq_engine.cpp ~ split-k scope around the C>1 verify; host commit
qwen35_target_graph.cpp ~ replay log view for the tree commit
glue_fusions.h ~ z view for the mapped verify
Two commits: the MMQ work (ggml-cuda), then the commit and in-place reads (qwen35).
Evidence
Throughput across lane counts, R9700. Setup:
- Qwen3.8-27B UD-IQ4_XS target, DFlash2 Q8_0 drafter,
--profile qwen38-r9700, paged attention,--max-concurrency 8. - Clients in a closed loop, 40 prompts × 1024 tokens, thinking on, greedy.
- Main
dd85248d3against this branch, interleaved ABBA (twice at C4), each server run with a warm-up. Both arms carry a small private patch that returns step counts and token ids. - Compared paired by request, with a 95% CI.
- Measured on an earlier head (
fc658bc15) that also carried the q8_1 producers, now in #969. They measured +0.64% (±0.51) and +0.34% (±0.36) steps/s at C4, so read each row as up to about 1% high. The table has not been re-run on this head. What changed since, besides the producers moving out, is the twin dispatch (same kernels per call, checked by the parity test) and where the split-k counters live.
| clients | rate, main → this PR (tok/s per request) | rate, paired | steps/s, paired | tokens/step, paired | aggregate tok/s | errors |
|---|---|---|---|---|---|---|
| 1, paged | 94.62 → 98.80 | +4.45% (±0.76) | +4.50% (±0.18) | -0.04% (±0.78) | 84.6 → 88.1 | 0/160 |
| 2 | 82.61 → 85.46 | +3.45% (±0.13) | +3.45% (±0.13) | +0.00% (±0.00) | 153.8 → 159.1 | 0/160 |
| 3 | 61.93 → 71.80 | +16.09% (±1.77) | +15.65% (±1.04) | +0.38% (±1.40) | 167.2 → 193.1 | 0/160 |
| 4 | 56.57 → 65.48 | +15.99% (±2.25) | +14.84% (±1.01) | +1.00% (±1.81) | 202.4 → 229.8 | 0/320 |
| 5 | 52.50 → 56.76 | +8.53% (±2.91) | +9.49% (±0.94) | -0.88% (±2.57) | 232.4 → 253.4 | 0/160 |
| 6 | 49.76 → 54.56 | +9.84% (±1.87) | +7.95% (±1.22) | +1.80% (±1.67) | 261.9 → 284.2 | 0/160 |
| 7 | 43.00 → 45.81 | +6.69% (±1.94) | +13.90% (±2.24) | -5.90% (±2.67) | 261.3 → 278.4 | 0/160 |
| 8 | 41.55 → 44.64 | +7.58% (±1.94) | +14.40% (±2.29) | -5.52% (±2.91) | 286.1 → 306.7 | 0/160 |
Why it is uneven:
- C2 and paged C1 verify at most 16 columns, so they keep the older tile twins and gain only from the commit and glue changes. Their tokens/step do not move.
- C3 and C4 verify 24 and 32 columns, where the new tiles and the x48 skip help most.
- C5 and C6 verify 48 columns (5 lanes round up to the 6-lane graph): the x48 skip does nothing there.
- C7 and C8 share an 8-lane graph. Width 6 stays at 48 columns on the new kernels while width 8 falls back to the parent tiles at 64 columns, which likely explains why steps got faster and tokens/step dropped. I did not read the controller's choices directly.
Outputs at C > 1 are not compared byte for byte: the engine is not batch-invariant, so two runs of main differ there too.
C1 identity, R9700 (also on fc658bc15). Setup:
- Same model and drafter, greedy, thinking on,
max_tokens2048, AR burst pinned off. - 30 prompts, 6 each from gsm8k, math500, humaneval, mbpp and mt-bench.
Result: 30/30 identical by token ids, 26,327 tokens and 4,997 steps in both arms, 0 errors. Token ids came from main and the branch each built with a small private patch that returns them; the plain builds match too, on content, reasoning text, token count and finish reason (30/30). Rate 102.67 → 103.36 tok/s (+0.7%, one run each). The 23-column DDTree verify takes the new tiles and the prefetch kernel; split-k never engages there. Peak VRAM goes up by 6 MB.
Per-change increments (measured while developing, each on top of the previous ones, with runtime switches since removed and instrumentation that counted verify steps; C4 ABBA×2, steps/s paired by request):
| change | steps/s at C4 |
|---|---|
| measured MMQ tile | +3.50% (±0.63) |
| batched commit | +2.58% (±0.34) |
| prefetch + LDS barrier + split-k | +3.46% (±0.52) |
| replay log + z in place | +1.85% (±0.15), measured together with #958 |
| x48 skip at 32 columns | +3.10% (±0.24) for an earlier variant; the one here is 4–5% slower per call than it at 32 columns and 4–5% faster at 48 (microbench) |
Tests (R9700, all pass on this head):
test_mmq_tile_twins: 1980 arm cases compared with the parent tiles at 8/16/24/32/48 columns over 11 types × 9 shapes, with 861 running a twin. They are bit-identical, except inside the split-k scope, where only 64-row wide calls with ≥ 32 k-iterations may differ: those match the unsplit run within 1e-5 relative, and 11 cases split.- The same test runs one split case on two backends of the same device at once, one thread each: every run, each backend's first included, is bit-identical to the serial split run. This fails when the counters are zeroed off the launch stream. With the counters shared between the two contexts it still passed in 3 runs (their launches did not interleave on this card), so it does not prove the per-context counters.
test_mmq_tile_twin_gate: the per-type choices, including the IQ4_XS 64-row x48.test_glue_fusions: the mapped verify takes the z view.test_glue_fusions_gpu(#948's): bit-identical across its 5 arms.test_gdn_replay_log: the host-validated commit writes the device-validated commit's bits (272 B and 12 B rows, an inactive lane, partial and empty prefixes); a refused preflight changes nothing.test_gdn_single_commitand its GPU arms (#946): pass.
Merge Danger
Door: two-way. Every change is local to its kernel or graph rule, with no format, API or file change, and reverts cleanly. Everything but split-k is bit-exact against the code it replaces. Split-k changes C>1 outputs at the rounding level, as any change to batch composition already does.
Blast Radius: mostly RDNA4. Ramifications:
- MMQ tiles and the prefetch kernel: every model on RDNA4 with dense MMQ calls of 17–48 columns takes the new tiles. This is bit-exact, covered by the parity test. Other devices keep the parent tiles.
- x48 skip: compiled for every AMD MMA tile of the q8_0 dot path with 48 ≤
mmq_x< 128, so the parent tiles and CDNA (MFMA) builds take it too. It only drops column tiles past the call's columns, so it is bit-exact; it was run and measured on the R9700 only. - Split-k: only the Qwen3.5/3.8 concurrent engine's verify of two or more lanes on RDNA4.
- Batched commit, replay log and z: the Qwen3.5/3.8 concurrent engine. The device-validated commit stays as the fallback.
- Build: the HIP build compiles six more twin translation units and a prefetch kernel in each 64-row twin.
- Not in this PR:
🤖 Generated with Claude Code