--- license: apache-2.0 --- # KBench — GPU kernel-generation benchmark **400 tasks.** Each hands the agent a correct-but-slow reference implementation and an empty stub; the agent writes a fast GPU kernel. ``` reward = 0 if the submission is incorrect reward = achieved TFLOP/s or GB/s otherwise, UNCAPPED ``` Correctness is the **gate**; speed is the **reward**. There is no oracle and no gold solution — the score is an absolute hardware metric, so it is hardware-portable by construction and nothing has to be re-benchmarked when the hardware changes. ## Layout ``` tasks/// instruction.md what the agent reads task.toml metadata (timeouts, GPUs, keywords) environment/ Dockerfile, reference.py, the stub the agent edits, measure.py tests/ the grader (verify_env.py) + test.sh tools/ the generators that produce these tasks agent/ a kernel-optimization skill + subagents for solving these tasks ``` ## Running one task ```bash cd tasks// docker build -t mytask environment docker run --rm --gpus device=0 -v $PWD/tests:/tests:ro mytask bash /tests/test.sh ``` The grader writes `reward.json` / `details.json` to `/logs/verifier/`. Running it as above with the untouched stub scores 0; that is the intended starting point. ## Families | family | tasks | what it covers | |---|---|---| | [`megakernel`](tasks/megakernel/) | 26 | Whole-model decode fused into one persistent kernel, plus the primitives that make it possible. | | [`image-flux-sd3-mmdit`](tasks/image-flux-sd3-mmdit/) | 16 | FLUX. | | [`video-cogvideox-mochi-ltx`](tasks/video-cogvideox-mochi-ltx/) | 14 | Video DiTs with structurally different designs from Wan and HunyuanVideo: CogVideoX's separate LayerNorm experts for text vs video, Mochi's asymmetric joint attention over unequal per-stream head dims, and LTX's very high compression VAE. | | [`video-wan-dit`](tasks/video-wan-dit/) | 15 | Wan 2. | | [`video-hunyuanvideo-mmdit`](tasks/video-hunyuanvideo-mmdit/) | 15 | HunyuanVideo's MMDiT: dual-stream blocks (separate QKV/norm/FFN for text and video, joint attention) then single-stream. | | [`video-3d-causal-vae`](tasks/video-3d-causal-vae/) | 22 | The 3D causal VAE / tokenizer both Wan and HunyuanVideo use — 4x8x8 compression, one-sided temporal padding, tiled decode. | | [`video-sparse-attention`](tasks/video-sparse-attention/) | 26 | Published sparse-attention schemes for video diffusion: Sliding Tile Attention, Sparse VideoGen head routing, Radial Attention, and block-sparse / caching variants. | | [`diffusion-sampling`](tasks/diffusion-sampling/) | 14 | Flow-matching and DPM-Solver++ steps, TeaCache-style skip decisions, latent blending. | | [`multimodal-audio`](tasks/multimodal-audio/) | 16 | Vision encoders, multimodal RoPE, and audio/speech synthesis kernels. | | [`linear-attention-ssm`](tasks/linear-attention-ssm/) | 48 | Linear-attention and state-space architectures: Gated DeltaNet, Mamba-2, RWKV-7, GLA, GSA, Comba, MesaNet, TTT, Titans and relatives. | | [`attention-text-llm`](tasks/attention-text-llm/) | 28 | Attention variants from text LLMs: MLA, NSA, MoBA, DSA, cascade, chunked prefill. | | [`quantization-gemm`](tasks/quantization-gemm/) | 44 | FP8, MXFP4, NVFP4, AWQ, GPTQ, INT8 and INT4 GEMM and quantisation kernels. | | [`moe`](tasks/moe/) | 20 | Mixture-of-experts routing, permutation, grouped GEMM and combine. | | [`kv-cache-paging`](tasks/kv-cache-paging/) | 25 | Paged KV allocation, append, compaction, eviction and quantisation. | | [`training-optimizer-rl`](tasks/training-optimizer-rl/) | 34 | Backward passes, fused optimisers, and RLHF / distillation losses. | | [`sampling-speculative-decoding`](tasks/sampling-speculative-decoding/) | 10 | Top-k/top-p/min-p filtering, beam search, and speculative decoding. | | [`norm-rope-fusion`](tasks/norm-rope-fusion/) | 7 | RMSNorm / LayerNorm and RoPE fusions. | | [`distributed-multi-gpu`](tasks/distributed-multi-gpu/) | 8 | Two-GPU tasks. | | [`raw-cuda`](tasks/raw-cuda/) | 12 | Raw-CUDA tasks. | `CATALOG.json` has the same information machine-readably: family, metric, roofline, GPU count and keywords for every task. ## How tasks are graded **Correctness** is checked against a private copy of the reference embedded in the grader, so editing `environment/reference.py` cannot affect the score. Every timed repetition runs on freshly generated inputs and the last one is re-validated, so memoising a result and replaying it fails the gate instead of posting an inflated number. **Work** is attributed by a formula that depends only on the shape, never on the implementation, so every submission is credited identically and the ranking is a pure speed ranking. **Tolerances are measured, not guessed.** Each one is set from the relative error between the reference and an independent correct implementation (the numerical floor), and checked against a variant that ignores the task's distinguishing feature. The measured numbers are written into each task's precision section. **Sizing.** Every task's roofline time at its largest graded shape is above 250 us, so the kernel dominates rather than launch overhead. ## Toolchain Tasks are offline: no internet at run time, and no flashinfer, vLLM, flash-attn or TensorRT-LLM is installed. Agents are expected to write CUDA C++ (nvcc and CUTLASS are present) or Triton. `torch` is available for setup and where there is no efficient direct alternative. Nothing scans submitted source — restrictions are enforced by what is installed and, for the megakernel family, by measuring how the submission actually executes.