Simulation, numerics and systems
int4-gemv-cuda
Single-token LLM decode reads every layer weight once for a single multiply-add, making it memory-bandwidth bound: how close to the DRAM ceiling can a custom CUDA 4-bit weight-only GEMV kernel get across Turing, Ampere and Blackwell GPUs?
Answer
On an NVIDIA RTX PRO 6000 Blackwell Server Edition (96 GB GDDR7, 1,598 GB/s theoretical peak, 1,530 GB/s plain-read ceiling), the fused 4-bit kernel reaches 1,030 to 1,289 GB/s at batch 1 across 7B and 70B layer shapes: 2.91 to 3.57 times faster than fp16 cuBLAS (1,301 to 1,435 GB/s), matching PyTorch's bfloat16 tinygemm (1,018 to 1,347 GB/s) with 10 times lower worst-case relative error (2.16e-04 vs 2.14e-03 against float64), and staying 1.28 to 1.53 times ahead of fp16 cuBLAS through batch 8. On a Tesla T4 (320 GB/s peak, 269 GB/s plain read), it reaches 182 to 199 GB/s median (2.78 to 2.99 times over fp16 cuBLAS, up to 259 GB/s before 70 W board power capping), while dequantizing to fp16 before cuBLAS drops to 19 to 20 GB/s (0.29 to 0.30 times).
How it was measured
- Symmetric 4-bit group-wise format (group size 128 with float16 scales, 4.125 bits per weight): 128-bit coalesced loads unpack eight nibbles in registers via float32 mantissa bit operations, accumulate dot products in float32, and reduce across warps without writing dequantized weights to global memory.
- Cold-L2 CUDA-graph timing (50 replays per shape and batch from 1 to 32), cycling through 12 to 47 distinct weight copies on Blackwell's 128 MB L2 cache so every launch streams weights from GDDR7 (p10 to p90 spread under 5.9 % across all 96 timed configurations).
- Three GPU architectures logged once per second during execution: Blackwell sm_120 (RTX PRO 6000 Server, 28 to 48 C), Turing sm_75 (Tesla T4, 48 to 62 C), and Ampere sm_86 (RTX 3050 Laptop, where 65 to 88 C thermal throttling widened p10 to p90 spreads up to 113 % while peak repetitions hit 155 to 169 GB/s against a 167 GB/s read ceiling).
- All 144 correctness checks on Blackwell and Ampere (112 on T4, which lacks sm_80 tinygemm) pass against exact float64 reference products, including non-template batch 3 and multi-slice batch 40; CI compiles kernels under nvcc 12.8 and nvcc 13.5 for sm_75, sm_80 and sm_90 with 0 register spills.
Proof
Every file is pinned to the commit the numbers come from, so the links cannot drift.
Reproduce it
pip install -r requirements.txt
pytest && python scripts/compile_check.py
python run_bench.py --out results/<gpu> && python -m w4.report results/<gpu>/results.jsonUnit tests, the CPU dry-run pipeline and nvcc 12.8 and nvcc 13.5 register and spill checks run in GitHub Actions without a GPU; standalone Colab notebooks reproduce the T4 and Blackwell runs end to end.
Limits
- The kernel uses FP32 CUDA cores rather than Tensor Cores: once batch size passes 8 on Blackwell (or 4 on T4), Tensor-Core fp16 cuBLAS overtakes it (0.50 to 0.69 times at batch 16), where a Tensor-Core W4A16 kernel such as Marlin is needed.
- Layers are timed in isolation on synthetic normal weights: kernel speed depends only on tensor shape and memory traffic, whereas real LLM outlier channels require activation-aware scaling to preserve model quality.