Field Report · Inference · 2026-11-01

Two Wrong Theories and a Table Nobody Filled In

Fixing llama.cpp's CUDA token speed on old Maxwell GPUs: 18.9 to 29.2 tokens a second on a $67 Quadro M4000, with a 21-line change.

✦ ❦ ✦

Limits first

The problem

We put two Quadro M4000s, about $67 each, into two Dell 5810 workstations. Out of the box, llama.cpp's Vulkan backend wrote text at about 30 tokens a second on a small model; its CUDA backend managed 19. But CUDA read prompts 3.4 times faster than Vulkan (236 vs 69 tok/s). You had to pick one strength.

Theory 1 (wrong): the missing instruction

Maxwell lacks __dp4a, the instruction newer cards use to multiply four 8-bit numbers at once, and llama.cpp emulates it there with four separate multiplies. It looked like the obvious culprit. We revived the float-math kernels llama.cpp removed in 2024 (DMMV), which never use that instruction. Result: 11.7 tok/s. Slower.

Theory 2 (wrong): the gaps between jobs

llama.cpp turns CUDA graphs off on cards older than Volta, so each of the hundreds of small steps per token launches separately. We turned graphs on for Maxwell and confirmed they engaged on every token. Result: 19.00 tok/s, unchanged.

What worked: measuring every step

We stopped guessing and timed every operation in the model, on both backends, at the model's real sizes (llama.cpp's own test-export-graph-ops + test-backend-ops perf, against Vulkan's GGML_VK_PERF_LOGGER=1). Two steps held the whole gap:

step, per token (Gemma 3 4B)CUDAVulkan
FFN gate/up, 2560 → 10240, Q4_K, ×68330 µs185 µs
output layer, 262,144 rows, Q6_K9.4 ms5.3 ms

The pattern was short rows. Where rows were long, CUDA was already close to Vulkan. Where they were short (2,560 values, only ten compressed blocks), CUDA's default layout of 4 warps per row left most of its workers idle. llama.cpp has hand-tuned layout tables for Turing, several AMD generations and NVIDIA's GB10. Maxwell had none and fell through to the generic default.

The sweep (llama-bench tg128, Gemma 3 4B Q4_K_M, all on the M4000)

warps × rows per blocktok/s
4 × 1 (stock)18.88
8 × 116.48
2 × 120.24
1 × 123.77
4 × 223.65
2 × 224.97
1 × 228.53
2 × 425.94
1 × 429.15
1 × 826.24
Vulkan, same card29.8

Results, on current llama.cpp (master 785322d, 2026-11-01)

Quadro M4000stock CUDApatched
Gemma 3 4B Q4_K_M, generation19.0729.22
Gemma 3 4B Q4_K_M, prompt (pp512)236.6235.8
Gemma 4 26B-A4B IQ4_XS, 20 layers' experts on CPU16.9122.10

Single-token matmul (4096×14336) was faster on 25 of 26 weight formats, by 13% to 38%: for example Q4_0 390 → 275 µs, Q4_K 487 → 397, Q6_K 586 → 460, Q8_0 551 → 478, IQ1_S 509 → 328, IQ4_XS 430 → 302, MXFP4 475 → 388.

In production: one of our local models (Gemma 4 26B-A4B, 64K context, vision on the card) went from 12.5 to 19.9 tok/s writing and 55 to 113 tok/s reading on a 3,000-token prompt.

Correctness

The patch

It adds a Maxwell entry (MMVQ_PARAMETERS_MAXWELL) to the single-token kernel's parameter table in ggml/src/ggml-cuda/mmvq.cu: 1 warp and 4 rows per block for single-token decode, NVFP4 excluded, everything else on the generic table. The two numbers sit behind GGML_CUDA_MMVQ_MAXWELL_NWARPS / _RPB in case another Maxwell card prefers different values.

Download the patch
# against llama.cpp master 785322d17
git am maxwell-mmvq-llama.cpp-785322d.patch
cmake -B build -DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=52
cmake --build build -j
# Maxwell needs CUDA 12.x: CUDA 13 dropped sm_5x

A note on upstream

We'd like this in llama.cpp itself, but we won't be the ones to submit it. The project's contribution rules forbid AI agents from opening pull requests and forbid AI-written PR descriptions and commit messages. This lab's code is written by AI, and the founder doesn't write code or use git himself. So rather than break their rules, we're publishing it here.

The patch is yours. If you have a Maxwell card, test it. If you're a llama.cpp contributor and want to carry it upstream, please do, and tell us how it went: @Escher2112 on X.

What we learnedThe fix was a table nobody had filled in for old hardware. It took two confident, plausible theories, both wrong, before we measured instead of reasoning. The measuring tools were already inside llama.cpp, and once we used them it took minutes.

Built in a basement lab in Michigan, on hardware nobody else wanted. 🖤