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.

ConfigBackendTokens/sTTFT p50TTFT p95ITL p50ITL p95runs
HF transformers, batch 1reference floornot measurednot measurednot measurednot measurednot measured-
HF transformers, padded batch 32naive batchingnot measurednot measurednot measurednot measurednot measured-
engine, static batchingCPU backend · hardware not recorded38.913,673 ms14,696 ms94.9 ms117.1 ms1
engine, continuous batchingCPU backend · hardware not recorded57.12,330 ms2,522 ms106.7 ms122.5 ms1
engine, static batchingCUDA backend · NVIDIA A40 / pod isx98c0564.43,993 ms7,628 ms23.1 ms37.4 ms3
engine, continuous batchingCUDA backend · NVIDIA A40 / pod isx98c0770.975 ms83 ms39.1 ms42.0 ms3
engine, + prefix cachingCUDA backendnot measurednot measurednot measurednot measurednot measured-
engine, + fused kernelsCUDA backend · NVIDIA A40 / pod isx98c0979.857 ms62 ms29.4 ms31.4 ms3
engine, + CUDA graphsCUDA backendnot measurednot measurednot measurednot measurednot measured-
vLLM, same model and GPUreference · NVIDIA A40 / pod b0flqxf5,927.531 ms173 ms3.5 ms8.7 ms3

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.

StrategySlot utilizationKV wasteResident seqsDecoding seqsPreemptions
contiguous (reserve maxmodellen)1.7%98.3%2.01.30
contiguous (reserve prompt + max_tokens)35.2%64.8%42.08.40
contiguous (reserve prompt + max_tokens)54.8%45.2%20.220.20
paged, static batching98.6%1.4%63.811.70
paged, continuous batching99.0%1.0%23.122.90

Prefix caching

32 requests sharing a 512-token system prompt with a 128-token tail each.

MetricCache offCache onChange
TTFT p501,627.1 ms112.8 ms14.4x faster
TTFT p953,698.4 ms1,823.2 ms2.0x faster
end-to-end p505.4 s0.6 s8.5x faster
wall clock44.0 s7.8 s5.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.

Regionms/stepSharewith GQA-shared attentionchange
embedding0.0130.0%0.0121.06x
rmsnorm0.3070.8%0.3081.00x
qkv_proj1.0743.0%1.0171.06x
rope+store_kv0.2260.6%0.2280.99x
attention31.56487.5%19.4321.62x
o_proj+residual0.3200.9%0.3310.97x
mlp2.0605.7%2.1210.97x
head0.5241.5%0.5221.00x
total on device36.08723.9701.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 sizeITL p50ITL p95Worst gapInjected prompt TTFT
204813 ms16 ms48 ms1.36 s
51213 ms13 ms37 ms1.38 s
12813 ms13 ms37 ms1.46 s