Skip to content

[w2] mmvq: opt-in Q6_K single-warp 4-row variant on RDNA3 (GGML_CUDA_MMVQ_Q6K_LANES) - #164

Merged
rafasmour merged 1 commit into
masterfrom
opt/w2-q6k-lane-waste
Dec 4, 2026
Merged

rafasmour merged 1 commit into
masterfrom
opt/w2-q6k-lane-waste

Conversation

@rafasmour

Copy link
Copy Markdown
Owner

What / why

RDNA3 (gfx1100) Q6_K mat-vec with one column uses 4 warps per row. For rows of 9-11 superblocks (K=2304/2560/2816: Nemotron Bolt E4B FFN and head) the 4-warp block takes three trips and the last is part idle. For rows of 1-2 superblocks (K<=512, Qwen4 hc_up 8192x256, 80 calls/token) the default is already 1 warp, 1 row (small_k), with a block per row.

New template flag q6k_lanes on mul_mat_vec_q: Q6_K, ncols_dst==1, RDNA3_0 only: 1 warp per row, 4 rows per block (every lane busy; a Q6_K superblock is exactly one warp, qi=32). Selected at runtime when GGML_CUDA_MMVQ_Q6K_LANES=1, nrows % 4 == 0 and blocks_per_row is 1-2 or 9-11. Every other Q6_K shape (K=17408, 10240, 5120, 2048, ...) is unchanged. Fused gate/up GLU and the shared-expert path use the same kernel (rows_per_block 4 already satisfies the one-lane-per-output static_assert; the mixed-type shared expert instance is untouched).

Plan correction: the task said to check whether small_k already covers K<=512. It does (1 warp, 1 row per block), so for K<=512 the variant only changes rows per block 1 -> 4.

Expected gain (estimate, unmeasured)

Nemotron +1-3% tg (Q6_K K=2560 kernels at about 666 vs 700+ GB/s). Qwen4 hc_up: launch-dominated, maybe 0.1-0.2 ms/token over 80 calls.

Env switch

GGML_CUDA_MMVQ_Q6K_LANES=1 (opt-in, default off; the row reduction order changes).

Files

ggml/src/ggml-cuda/mmvq.cu, tests/test-backend-ops.cpp (MUL_MAT q6_K n=1 for (10240,2560), (2560,2560), (16384,2304), (8192,256), (2048,512), (4096,2816), (4099,2560 - fallback), (10240,3072 / 2560,5120 - unchanged); MUL_MAT_FUSION Q6_K gate/up at k=2560/2304/256 and a MoE case).

Risks

  • 1 warp rows may lose memory parallelism on 10240-row matrices (2560 blocks of 32 threads); measure in model, isolated perf is distorted by the 80 MB Infinity Cache.
  • Register pressure of the fused path (4 rows x gate).
  • mmvq.cu textual conflicts with iq-mmvq-latency and gemma-iq-verify; changes stay inside the Q6_K ncols_dst==1 selection and add a trailing template param/args.

Checks done (no GPU used)

HIP compile of mmvq.cu.o for gfx1100 clean; CPU test-backend-ops compile. No GPU, no production, nothing touched in ggml-org/llama.cpp.

GPU validation tonight (NOT YET RUN)

R=/home/tom/docker/projects/llama.cpp-RDNA3; K=$R/build-bins/kern; cd $K   # plus preamble P
GPURUN_OPTS='-e GGML_CUDA_MMVQ_Q6K_LANES=1' ./gpusmall.sh ./test2.sh w2-q6k $BA - MUL_MAT 'type_a=q6_K,.*n=1,'
./gpusmall.sh ./perf2.sh w2-q6k-off $BA - MUL_MAT 'type_a=q6_K,.*n=1,'
GPURUN_OPTS='-e GGML_CUDA_MMVQ_Q6K_LANES=1' ./gpusmall.sh ./perf2.sh w2-q6k-on $BA - MUL_MAT 'type_a=q6_K,.*n=1,'
GPURUN_OPTS='-e GGML_CUDA_MMVQ_Q6K_LANES=1' ./gpublock.sh ./lb.sh nb-q6k-on $BA $NB $NBA -p 0 -n 128 -r 5
./gpublock.sh ./lb.sh nb-q6k-off $BA $NB $NBA -p 0 -n 128 -r 5
# same pair for $Q4 $Q4A -p 0 -n 128 -r 5
./gpublock.sh ./kl.sh nb-q6k-base $BA $NB base $NBA
./gpublock.sh env KL_ENV=GGML_CUDA_MMVQ_Q6K_LANES=1 ./kl.sh nb-q6k $BA $NB test $NBA   # pass: Mean KLD <= 0.0005

Also run MUL_MAT_FUSION for q6_K at k=2560.

Assisted-by: Claude Sonnet 5.5

…Q6K_LANES)

For Q6_K, one column, RDNA3_0: rows of 9..11 superblocks (K=2304/2560/2816)
run one warp per row with four rows per block instead of four warps on one
row (the third trip of the 4 warp block is part idle), and rows of 1..2
superblocks (K<=512, e.g. Qwen4 hc_up 8192x256) get four rows per block
instead of one. Needs nrows % 4 == 0, otherwise the old path is used.
Fused gate/up and the shared expert go through the same kernel.
Opt-in because the row reduction order changes.

Adds MUL_MAT / MUL_MAT_FUSION cases for these shapes (eval and perf).

Assisted-by: Claude Sonnet 5.5
@rafasmour
rafasmour force-pushed the opt/w2-q6k-lane-waste branch from 1e560ff to 0ffe5c0 Compare December 4, 2026 13:28
@rafasmour
rafasmour merged commit 9ebc5c5 into master Dec 4, 2026
10 of 30 checks passed
@rafasmour

Copy link
Copy Markdown
Owner Author

Reverted from master on 2026-12-04 (w2 build crashed Qwen4-single at >20k ctx; no measured gain). Commit preserved on branch archive/w2-25f0def; will be re-landed individually after GPU validation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant