engine
An LLM inference server written from scratch in C++ and CUDA. Paged KV cache, continuous batching, prefix caching, OpenAI-compatible streaming API. Source on GitHub.
Generated 2026-10-11 from bench/results/.
Last full run on NVIDIA A40 49140 MiB, Intel(R) Xeon(R) Gold 6342 CPU @ 2.80GHz, CUDA 12.8, driver 580.178.04, commit 9643a72. Each row below names the machine it was measured on; rows may come from different machines.
Serving throughput and latency
Qwen2.5-0.5B-Instruct, 32 concurrent requests, prompt mix 128/512/1024 at 50/30/20, geometric output lengths around 128, median of the recorded runs.
Do not read this table across instances. The same code on two rented A40s, same GPU model, same Xeon 6342, same vCPU allocation, measured 386 and 771 tok/s, with inter-token latency of 80.3 ms and 39.1 ms. A factor of two that the hardware label described identically; the cause is unknown and one observation per machine is not enough to find it. Rows name their instance, and a ratio is only meaningful between rows sharing one. The vLLM row was measured on pod b0flqxf against engine rows reading 327 and 386 tok/s there, a gap of 15.4x. The engine rows here come from a faster instance, and dividing one by the other would flatter this engine by about half.
| Config | Backend | Tokens/s | TTFT p50 | TTFT p95 | ITL p50 | ITL p95 | runs |
|---|---|---|---|---|---|---|---|
| HF transformers, batch 1 | reference floor | not measured | not measured | not measured | not measured | not measured | - |
| HF transformers, padded batch 32 | naive batching | not measured | not measured | not measured | not measured | not measured | - |
| engine, static batching | CPU backend · hardware not recorded | 38.9 | 13,673 ms | 14,696 ms | 94.9 ms | 117.1 ms | 1 |
| engine, continuous batching | CPU backend · hardware not recorded | 57.1 | 2,330 ms | 2,522 ms | 106.7 ms | 122.5 ms | 1 |
| engine, static batching | CUDA backend · NVIDIA A40 / pod isx98c0 | 564.4 | 3,993 ms | 7,628 ms | 23.1 ms | 37.4 ms | 3 |
| engine, continuous batching | CUDA backend · NVIDIA A40 / pod isx98c0 | 770.9 | 75 ms | 83 ms | 39.1 ms | 42.0 ms | 3 |
| engine, + prefix caching | CUDA backend | not measured | not measured | not measured | not measured | not measured | - |
| engine, + fused kernels | CUDA backend · NVIDIA A40 / pod isx98c0 | 979.8 | 57 ms | 62 ms | 29.4 ms | 31.4 ms | 3 |
| engine, + CUDA graphs | CUDA backend | not measured | not measured | not measured | not measured | not measured | - |
| vLLM, same model and GPU | reference · NVIDIA A40 / pod b0flqxf | 5,927.5 | 31 ms | 173 ms | 3.5 ms | 8.7 ms | 3 |
KV cache efficiency
Allocator property, measured with a fake model, so it is hardware independent. 256 requests, 65,536 KV token slots (4096 blocks of 16), outputs around 128 tokens.
| Strategy | Slot utilization | KV waste | Resident seqs | Decoding seqs | Preemptions |
|---|---|---|---|---|---|
| contiguous (reserve maxmodellen) | 1.7% | 98.3% | 2.0 | 1.3 | 0 |
| contiguous (reserve prompt + max_tokens) | 35.2% | 64.8% | 42.0 | 8.4 | 0 |
| contiguous (reserve prompt + max_tokens) | 54.8% | 45.2% | 20.2 | 20.2 | 0 |
| paged, static batching | 98.6% | 1.4% | 63.8 | 11.7 | 0 |
| paged, continuous batching | 99.0% | 1.0% | 23.1 | 22.9 | 0 |
Prefix caching
32 requests sharing a 512-token system prompt with a 128-token tail each.
| Metric | Cache off | Cache on | Change |
|---|---|---|---|
| TTFT p50 | 1,627.1 ms | 112.8 ms | 14.4x faster |
| TTFT p95 | 3,698.4 ms | 1,823.2 ms | 2.0x faster |
| end-to-end p50 | 5.4 s | 0.6 s | 8.5x faster |
| wall clock | 44.0 s | 7.8 s | 5.7x faster |
Block hit ratio 95.8%.
Where a decode step goes
CUDA events on the default stream, 32 concurrent requests, 36.09 ms of device time per step. Nsight Compute would give achieved bandwidth too and does not run on a rented pod, so this measures which region the time is in rather than how close each is to the memory limit. Recording events costs something, so read the proportions and not the absolute total.
| Region | ms/step | Share | with GQA-shared attention | change |
|---|---|---|---|---|
embedding | 0.013 | 0.0% | 0.012 | 1.06x |
rmsnorm | 0.307 | 0.8% | 0.308 | 1.00x |
qkv_proj | 1.074 | 3.0% | 1.017 | 1.06x |
rope+store_kv | 0.226 | 0.6% | 0.228 | 0.99x |
attention | 31.564 | 87.5% | 19.432 | 1.62x |
o_proj+residual | 0.320 | 0.9% | 0.331 | 0.97x |
mlp | 2.060 | 5.7% | 2.121 | 0.97x |
head | 0.524 | 1.5% | 0.522 | 1.00x |
| total on device | 36.087 | 23.970 | 1.51x |
The second kernel reads each position's K and V once per GQA group instead of once per query head. It was 1.33x *slower* at its first block width: one block per (token, kv head) rather than per (token, query head) also cuts the grid from 448 blocks to 64, and 64 blocks do not fill this card's 84 SMs. Widening the block from 128 to 512 threads recovered the lost parallelism and turned the regression into the figures above.
Chunked prefill
Four streams decoding while a 2,048-token prompt is injected mid-flight. The worst gap is what a user watching tokens appear actually feels; p95 over a few hundred samples hides a single long stall.
| Chunk size | ITL p50 | ITL p95 | Worst gap | Injected prompt TTFT |
|---|---|---|---|---|
| 2048 | 13 ms | 16 ms | 48 ms | 1.36 s |
| 512 | 13 ms | 13 ms | 37 ms | 1.38 s |
| 128 | 13 ms | 13 ms | 37 ms | 1.46 s |