CUDA: Pascal DP4A MMQ config uses I=64 for Q8_0; I=128 gives +12% pp512 on sm_61
Summary
On sm_61 (Tesla P4, DP4A path), raising I from 64 to 128 in the eleven
CASE(GGML_TYPE_Q8_0, ...) entries of
ggml/src/ggml-cuda/mmq-config-pascal-dp4a.cuh gives a +12% prompt
processing speedup, with Q4_K and Q6_K unchanged within noise.
I is documented in ggml_cuda_mmq_config as "SRAM tile width in
src0->ne[1]/dst->ne[0] direction". mmq-config-ampere.cuh already uses
I=128 for Q8_0; the Pascal DP4A config uses 64 for all 22 types.
The change
Eleven lines, all in one file. Only I changes; nthreads, occupancy,
sram_layout, K_vram, stream_k and fallback are untouched.
--- a/ggml/src/ggml-cuda/mmq-config-pascal-dp4a.cuh
+++ b/ggml/src/ggml-cuda/mmq-config-pascal-dp4a.cuh
@@
- CASE(GGML_TYPE_Q8_0, 256, 2, 64, 8, GGML_CUDA_MMQ_SRAM_LAYOUT_Q8_0, MMQ_ITER_K, false, true);
- CASE(GGML_TYPE_Q8_0, 256, 2, 64, 16, GGML_CUDA_MMQ_SRAM_LAYOUT_Q8_0, MMQ_ITER_K, false, true);
- CASE(GGML_TYPE_Q8_0, 256, 2, 64, 32, GGML_CUDA_MMQ_SRAM_LAYOUT_Q8_0, MMQ_ITER_K, false, true);
- CASE(GGML_TYPE_Q8_0, 256, 2, 64, 64, GGML_CUDA_MMQ_SRAM_LAYOUT_Q8_0, MMQ_ITER_K, false, true);
- CASE(GGML_TYPE_Q8_0, 256, 2, 64, 8, GGML_CUDA_MMQ_SRAM_LAYOUT_Q8_0, MMQ_ITER_K, false, false);
- CASE(GGML_TYPE_Q8_0, 256, 2, 64, 16, GGML_CUDA_MMQ_SRAM_LAYOUT_Q8_0, MMQ_ITER_K, false, false);
- CASE(GGML_TYPE_Q8_0, 256, 2, 64, 24, GGML_CUDA_MMQ_SRAM_LAYOUT_Q8_0, MMQ_ITER_K, false, false);
- CASE(GGML_TYPE_Q8_0, 256, 2, 64, 32, GGML_CUDA_MMQ_SRAM_LAYOUT_Q8_0, MMQ_ITER_K, false, false);
- CASE(GGML_TYPE_Q8_0, 256, 2, 64, 40, GGML_CUDA_MMQ_SRAM_LAYOUT_Q8_0, MMQ_ITER_K, false, false);
- CASE(GGML_TYPE_Q8_0, 256, 2, 64, 48, GGML_CUDA_MMQ_SRAM_LAYOUT_Q8_0, MMQ_ITER_K, false, false);
- CASE(GGML_TYPE_Q8_0, 256, 2, 64, 64, GGML_CUDA_MMQ_SRAM_LAYOUT_Q8_0, MMQ_ITER_K, false, false);
+ CASE(GGML_TYPE_Q8_0, 256, 2, 128, 8, GGML_CUDA_MMQ_SRAM_LAYOUT_Q8_0, MMQ_ITER_K, false, true);
+ CASE(GGML_TYPE_Q8_0, 256, 2, 128, 16, GGML_CUDA_MMQ_SRAM_LAYOUT_Q8_0, MMQ_ITER_K, false, true);
+ CASE(GGML_TYPE_Q8_0, 256, 2, 128, 32, GGML_CUDA_MMQ_SRAM_LAYOUT_Q8_0, MMQ_ITER_K, false, true);
+ CASE(GGML_TYPE_Q8_0, 256, 2, 128, 64, GGML_CUDA_MMQ_SRAM_LAYOUT_Q8_0, MMQ_ITER_K, false, true);
+ CASE(GGML_TYPE_Q8_0, 256, 2, 128, 8, GGML_CUDA_MMQ_SRAM_LAYOUT_Q8_0, MMQ_ITER_K, false, false);
+ CASE(GGML_TYPE_Q8_0, 256, 2, 128, 16, GGML_CUDA_MMQ_SRAM_LAYOUT_Q8_0, MMQ_ITER_K, false, false);
+ CASE(GGML_TYPE_Q8_0, 256, 2, 128, 24, GGML_CUDA_MMQ_SRAM_LAYOUT_Q8_0, MMQ_ITER_K, false, false);
+ CASE(GGML_TYPE_Q8_0, 256, 2, 128, 32, GGML_CUDA_MMQ_SRAM_LAYOUT_Q8_0, MMQ_ITER_K, false, false);
+ CASE(GGML_TYPE_Q8_0, 256, 2, 128, 40, GGML_CUDA_MMQ_SRAM_LAYOUT_Q8_0, MMQ_ITER_K, false, false);
+ CASE(GGML_TYPE_Q8_0, 256, 2, 128, 48, GGML_CUDA_MMQ_SRAM_LAYOUT_Q8_0, MMQ_ITER_K, false, false);
+ CASE(GGML_TYPE_Q8_0, 256, 2, 128, 64, GGML_CUDA_MMQ_SRAM_LAYOUT_Q8_0, MMQ_ITER_K, false, false);
Results
llama-bench, pp512. A/B interleaved (A,B,A,B,…), 8 pairs per model,
median of each build, sign test over the pairs. GPU idle: all services on the
card were stopped for the runs.
| model | GGML type | delta | pairs won | sign test |
|---|---|---|---|---|
| bge-reranker-v2-m3 | Q8_0 | +12.1% | 8/8 | p = 0.0078 |
| bge-m3 | Q8_0 | +11.6% | 8/8 | p = 0.0078 |
| bge-reranker-v2-m3 | Q4_K_M | −0.7% | 3/8 | p = 0.73 |
| Qwen3.5-4B | Q6_K | −0.1% | 3/8 | p = 0.73 |
Sanity check: tg128 on the Q6_K decoder moves −0.3%. Token generation is
bandwidth-bound and must not respond to a matmul tile change — when it does,
the measurement is wrong, and three earlier runs were discarded on exactly
that signal.
Interleaving is not optional here. The same binary measured back-to-back on this card spans 919–2622 ms on a fixed workload — 163% of the median — because the P4 is passively cooled and the host is shared. A before/after comparison without interleaving measures thermal drift.
Why only Q8_0
Changing I to 128 for every type in the file gives the same Q8_0 gain and
wrecks everything else:
| model | GGML type | global patch | Q8_0-only patch |
|---|---|---|---|
| bge-reranker-v2-m3 | Q8_0 | +13.3% | +12.1% |
| bge-m3 | Q8_0 | +12.2% | +11.6% |
| bge-reranker-v2-m3 | Q4_K_M | −24.4% | −0.7% |
| Qwen3.5-4B | Q6_K | −51.7% | −0.1% |
I=160 regresses 45.7% even on Q8_0, and I>=192 fails to compile — Pascal
shared-memory limit. 128 is the largest value that fits, and it is what
mmq-config-ampere.cuh already uses for this type.
Still applies on current master
Re-checked on b11476 (commit 9881906): the eleven Q8_0 lines in
mmq-config-pascal-dp4a.cuh are unchanged (I=64), and the patch applies
cleanly. The patched build has been serving a Q8_0 cross-encoder
(bge-reranker-v2-m3) in production on the P4 since 2026-09-06, and since
2026-10-09 also a Q8_0 embedding model (embeddinggemma-2).
What was NOT measured
- One GPU. Tesla P4,
sm_61. No other Pascal card, and nothing outside Pascal. Whether this generalises across DP4A cards is untested. pp512only. No sweep over prompt length; no batch-size sweep.- 3 of 22 types. The file defines
CASEentries for 22 GGML types. OnlyQ8_0,Q4_KandQ6_Kwere exercised.Q4_0,Q5_K, theIQ*family,MXFP4andNVFP4are untouched by this patch but also unverified as unaffected. - Two Q8_0 models of the same family. Both are BGE encoders (BERT). The +12% is not confirmed on a Q8_0 decoder.
Environment
GPU Tesla P4, compute capability 6.1, driver 551.78
CUDA 12.6 (V12.6.85)
Host Windows, MSVC 19.44.35228.0
CMake -DCMAKE_BUILD_TYPE=Release -DGGML_CUDA=ON
-DCMAKE_CUDA_ARCHITECTURES=61 -DGGML_CUDA_FORCE_MMQ=ON
-DGGML_CUDA_FA=ON
Source llama.cpp 0.3.0-dev, build 10793, commit d230ddd76
(tarball without .git; version read back from the built binary)
Reproducing
# control
llama-bench -m bge-reranker-v2-m3-Q8_0.gguf -p 512 -n 0 -r 5
# patched: the 11 CASE(GGML_TYPE_Q8_0, ...) lines, I 64 -> 128
llama-bench -m bge-reranker-v2-m3-Q8_0.gguf -p 512 -n 0 -r 5
Alternate the two builds rather than running one after the other, and compare medians. On a card with this much thermal spread, a single pair proves nothing.