Skip to content
DAH

Kernel autotuning and automated kernel generation

Searching tile sizes, pipeline depths and schedules by measurement or learned cost models, and now asking language models to write kernels, scored against hand-written baselines.

On this page15 sections
Why other work relies on it

Almost every fast kernel ships with tuned parameters per shape and GPU; search-based tuning (TVM, Ansor, Triton autotune) and the new LLM kernel-writing benchmarks set how much expert time kernels need.

Finding the fastest settings for a GPU program by trying many, and teaching AI to write such programs.

  1. 1Best settings differ per size and chip
  2. 2Try settings and time each one
  3. 3Learned models predict fast settings
  4. 4AI models write programs for a benchmark
  5. 5Checks stop cheating

Why tuning exists. A GPU kernel has knobs: the tile size (how big a block of the matrix each group of threads handles), how many tiles to load ahead of time, and how many threads work on each tile. The best setting depends on the matrix sizes, the number format and the GPU model, and a setting that is best for a 4096 × 4096 multiply can be poor for a 1 × 4096 one.

A worked count. Suppose there are 3 tile heights, 3 tile widths, 4 tile depths, 4 load-ahead depths and 3 thread counts. That gives 3⋅3⋅4⋅4⋅3=4323 \cdot 3 \cdot 4 \cdot 4 \cdot 3 = 432 configurations. If each took half a second to compile and a tenth of a second to time, trying them all would take about four minutes, for one shape on one GPU. A serving system that meets hundreds of shapes cannot afford that while users wait.

Approaches.

  • Grid search. Triton's @triton.autotune decorator times each configuration in a list the programmer supplies and caches the winner for each shape. Reliable, but every new shape costs compile and run time.
  • Learned cost models. TVM and Ansor generate candidate programs, use a model trained on earlier measurements to predict which will be fast, and time only the promising ones, improving them by evolutionary search (keep good candidates, change them slightly, repeat). Ansor reports up to 1.7× speedups on NVIDIA GPUs over the best systems of its time.
  • Vendor heuristics. cuBLAS and CUTLASS choose among precompiled kernels using rules and tables.

Analogy: choosing bicycle gears by test-riding every combination on the race course, versus asking an experienced coach to guess. The coach (the cost model) is far quicker, but can be wrong on an unfamiliar course (a new GPU).

Language models writing kernels. KernelBench (Ouyang et al., 2025) gives a language model 250 PyTorch programs and asks it to write faster GPU kernels. Its score is fastp=tasks whose kernel is correct and more than p times faster than PyTorchall tasks.\mathrm{fast}_p = \frac{\text{tasks whose kernel is correct and more than } p \text{ times faster than PyTorch}}{\text{all tasks}}. With p=1p = 1, any correct kernel that is not slower counts. The paper reports that frontier models matched the PyTorch baseline in under 20% of tasks out of the box, and did better when shown compiler errors, test results and profiler output and allowed to try again.

Why it is checkable, and the catch. Correctness (compare the outputs with a reference) and speed (time it) are measured by a program, so no human judge is needed. That invites reward hacking: a generator may learn to pass weak tests, for example by returning cached answers or by timing incorrectly. Test harnesses therefore have to be designed as if an adversary were trying to fool them.

Limits. No method yet predicts a kernel's speed reliably without running it, tuned settings transfer imperfectly to new shapes and GPUs, and compile time often dominates the search.

Go deeper

The full technical text.

Why tuning exists

For a given operator the best tile shape, number of pipeline stages, warps per block and loop order depend on tensor sizes, data types and the GPU model. Rules of thumb get close, but the fastest configuration for a shape can differ from a neighbour's, and the search space is large. Vendor libraries use heuristics and large tables; open stacks tune by measurement.

Search-based approaches

  • Exhaustive or grid autotuning. Triton's @triton.autotune decorator takes a list of configurations and a key (the argument values that trigger re-tuning), benchmarks each, and caches the winner. Simple and reliable, but each new shape costs compile and run time.
  • Learned cost models and search. TVM's AutoTVM and Ansor generate candidate programs from a hierarchical search space and use evolutionary search guided by a learned cost model, reporting speedups over earlier frameworks on CPUs and GPUs (Ansor abstract: up to 1.7x on NVIDIA GPU against the state of the art at the time).
  • Heuristic selection in libraries. cuBLAS and CUTLASS profilers rank precompiled kernels per problem.

Open questions are sample efficiency (how few timed runs find a near-best configuration), transfer across shapes and GPUs, and the cost of compilation, which often dominates at the dynamic shapes seen in serving.

Generating kernels with language models

KernelBench (Ouyang et al., 2025) asks language models to write GPU kernels for 250 PyTorch workloads and scores them with fast_p: the fraction of generated kernels that are correct and at least a factor p faster than the PyTorch baseline. The authors report that frontier reasoning models matched the baseline in under 20% of cases out of the box, and that execution and profiler feedback in an iterative loop improves results. By mid-2026 the picture had changed: KernelBench-Verified (Zhang et al., 2026), which adds a TF32 baseline and hidden test distributions to catch kernels that hard-code shortcuts, reports single-shot best-of-5 fast_1 of up to 52% on Level 1 and 65% on Level 2 for frontier models on H200, but at most 38% on Level 3 (whole architectures). Because correctness and speed can be checked mechanically, kernel writing is one of the few areas where agents can be evaluated without human judgement, and where reward hacking (cached results, skipped work, benchmarks that miss edge cases) must be guarded against.

What depends on it

Compilers that auto-tune determine whether researchers can write a new operator in a day and still get hardware-level speed; any agent that proposes kernels needs a trusted harness and baselines like these.

Words on this page (11)
Words on this page
autotuning
Trying many settings automatically, timing each, and keeping the fastest.
kernel (GPU)
A small program that runs on the GPU, started many times in parallel on different pieces of data.
compiler
A program that translates code written by people into instructions a chip can run.
benchmark
A fixed test that measures how fast or how good something is, so different systems can be compared fairly.
evolutionary search
Trying many candidates, keeping the best, and mutating them to make new candidates.
reward hacking
When a system finds a way to score well on a test without doing the intended task.
large language model
An AI model trained on huge amounts of text to predict and generate language.
PyTorch
The most widely used open-source library for building and training AI models.
tiling
Splitting a large matrix computation into small blocks that fit in fast on-chip memory, so each loaded number is reused many times.
profiler
A tool that measures where a program spends its time and which hardware resources it uses.
speedup
The ratio of the old running time to the new one; a speedup of 2 means twice as fast.
New to this? Read first (3)
New to this? Read first

Understanding map

map of the whole wiki →

What to read before Kernel autotuning and automated kernel generation (left), and what builds on it: entries that depend on it and its open problems (right). Every box links to its page.

  1. Start with
  2. Step 2
  3. Step 3
  4. Step 4
  5. Then

Open problems & questions

Progress timeline

  1. Jun 26, 2026
    Levels 1 and 2 pass fast_1 = 0.5 under hardened checks
    Related to: LLM-written kernels that beat PyTorch on half of KernelBench Level 3 under hardened checks

    KernelBench-Verified reports single-shot best-of-5 fast_1 of 52.0% (Level 1) and 64.9% (Level 2) on H200, but at most 38.0% on Level 3 (preprint).

    source
  2. Feb 14, 2025
    KernelBench released
    Related to: LLM-written kernels that beat PyTorch on half of KernelBench Level 3 under hardened checks

    Baseline results show frontier models matching PyTorch in under 20% of tasks (preprint).

    source
  3. Feb 1, 2025
    KernelBench

    A 250-task benchmark and the fast_p metric for LLM-written GPU kernels (arXiv preprint, February 2025).

    source
  4. Jun 1, 2020
    Ansor

    Hierarchical search space plus evolutionary search and learned cost model (arXiv, June 2020).

    source
  5. Feb 1, 2018
    TVM

    End-to-end optimising compiler with learned cost-model tuning for deep learning (arXiv, February 2018).

    source