Hi all,
I’m optimizing a small LLM inference engine on NVIDIA V100-32GB, focused on batched autoregressive decode.
Current setup:
- GPU: V100 32GB
- Model: Qwen3-8B Q4_K_M GGUF
- Decode batch: 4 active sequences
- Prompt is short; benchmark is mainly decode TPOT
- Current throughput: ~73 tok/s at batch=4, max_new=32
- We require token/text equality against the reference path for production optimizations
Current optimized decode path:
- Device-resident hidden state across transformer layers
- GPU RMSNorm and residual add
- Q4_K raw-weight cache for FFN gate/up
- Fused Q4_K gate + up + SiLU kernel
- Paged KV cache
- CUDA kernel for batched KV writes
- Batched block-table upload
- Paged-attention launcher caches device properties to avoid per-layer cudaGetDeviceProperties calls
After these changes, the remaining stage timing roughly looks like:
- ffn_gate_up: ~32%
- ffn_down: ~24%
- qkv_matmul: ~16%
- attn_o: ~9%
- lm_head: ~8%
- logits_sample: ~4%
- paged_attn: ~2%
- kv_write: <1%
Nsight Compute on the Q4_K gate/up/SiLU kernel shows approximately:
- Registers/thread: 48
- Static shared memory/block: ~16 KB
- Theoretical occupancy: ~50%
- Achieved occupancy: ~49%
- Compute throughput: ~59%
- Memory throughput: ~52%
- DRAM throughput: ~17%
- L1/TEX throughput: ~54%
- LSU/XU/ALU/FMA pipes all non-trivial
So the Q4_K kernel does not appear to be purely DRAM-bandwidth bound. It looks more like unpack/address/scale/min/instruction-mix pressure.
We experimented with using raw Q4_K for ffn_down as well. The isolated down path improved ffn_down time, but because the safe raw-weight cache cap is limited
by V100 memory pressure, allocating down weights displaced gate/up cached weights and reduced end-to-end throughput. Under the safe cache cap, the gate/up
fusion is more valuable than adding down.
Questions:
-
For small-M decode GEMM on V100, M=1..4, K/N around transformer FFN sizes, is it usually better to:
- consume the original GGUF Q4_K raw layout directly in the kernel, or
- prepack/decode the quantized weights once into a custom GPU layout optimized for the kernel?
-
If using a prepacked Q4_K cache, what layout tends to work best on Volta-class GPUs?
For example:- group scales/mins separately from nibbles?
- interleave scale/min with quant blocks?
- pack for warp-level contiguous reads?
- pre-expand scales/mins to fp16/fp32?
- tile K-major vs N-major for M=1..4?
-
Nsight suggests the current kernel is not DRAM-bound. Are there common V100-specific pitfalls for Q4-style unpack kernels where L1/TEX/LSU/XU pressure
dominates?
Would you first attack:- register pressure,
- shared memory usage,
- integer unpack instruction count,
- address arithmetic,
- or memory layout?
-
Is it worth experimenting with cache load modifiers such as
.cg/.cafor this type of kernel on V100, or should that be treated as a last-mile
microbenchmark-only tweak?
I’m aware that forcing-dlcm=cacan hurt some kernels badly. -
For decode batch=4, the LM head and logits sampling are now around 10-12% combined.
The current path computes full vocab logits, copies logits back to host, then samples/argmaxes on CPU.
For temperature=0 / greedy decode, would you recommend:- GPU argmax over vocabulary and copy back only token IDs,
- fused lm_head + top1/topk,
- or keeping cuBLAS lm_head and adding a separate reduction kernel?
-
Are there known examples, papers, or open-source kernels for V100/Pascal/Turing-era small-M low-bit GEMM that are more relevant than modern FP4/Blackwell
tensor-core kernels?
I’m especially interested in practical CUDA engineering guidance, not only algorithmic quantization. The current bottleneck is end-to-end decode latency, not
standalone large-M GEMM throughput.
Thanks!