NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

KernelBench: Can LLMs Write Efficient GPU Kernels?

Anne Ouyang, Simon Guo, Simran Arora, Alex L Zhang, William Hu, Christopher Re, Azalia Mirhoseini

TL;DR

The authors introduce KernelBench, a new open-source benchmark consisting of 250 PyTorch workloads designed to test if Large Language Models (LLMs) can write functionally correct and high-performance GPU kernels. The study finds that while frontier reasoning models like OpenAI o1 and DeepSeek-R1 show flashes of brilliance, they still struggle to outperform expert-optimized baselines, matching PyTorch performance in less than 20% of cases without iterative feedback.

The Challenge of GPU Optimization

In the current "Cambrian explosion" of AI architectures, hardware is evolving faster than humans can optimize for it. Writing efficient GPU kernels—the low-level code that handles operations like matrix multiplication—is a specialized "black art." It requires deep knowledge of hardware architecture, memory hierarchies, and parallel programming.

Currently, there is a massive lag between the proposal of a new model architecture and the release of its optimized kernels (e.g., FlashAttention took years to be fully ported to new hardware). If LLMs could automate this process, we could see immediate performance gains and energy savings across the industry. However, existing code generation benchmarks focus on general-purpose languages like Python, ignoring the unique performance-critical constraints of CUDA and Triton.

Introducing KernelBench

To address this gap, the researchers built KernelBench, a framework that mimics the workflow of a real-world performance engineer.

KernelBench Evaluation Pipeline
  1. Task Format: The model is given a PyTorch reference implementation and tasked with writing a custom CUDA or Triton kernel to replace it.
  2. Evaluation Pipeline: The framework automatically verifies functional correctness using randomized input tensors and measures wall-clock performance against two baselines: PyTorch Eager and torch.compile.
  3. The $\text{fast}_p$ Metric: The authors introduce a strict new metric where a model only "succeeds" if the kernel is correct and achieves a speedup greater than a threshold $p$ over the baseline.
  4. Test-Time Strategies: The study explores "one-shot" generation, "repeated sampling" (generating many versions and picking the best), and "iterative refinement," where the model receives compiler errors and profiler feedback to fix its own code.

The Dataset

The KernelBench dataset contains 250 tasks partitioned into three levels of difficulty:

  • Level 1 (100 tasks): Single primitive operations (e.g., convolutions, matmuls, activations).
  • Level 2 (100 tasks): Sequences of 3–6 operations, testing the model's ability to perform "operator fusion" (combining multiple steps into one to save memory bandwidth).
  • Level 3 (50 tasks): Full end-to-end architectures sourced from popular GitHub repositories like transformers and timm (e.g., AlexNet, MiniGPT).

Key Insights and Results

Performance across speedup thresholds
  • Reasoning is the Secret Sauce: Frontier reasoning models (o1, R1) significantly outperform standard LLMs. This suggests that writing kernels isn't just about syntax; it requires the model to "reason" about parallel execution and memory access patterns.
  • Baseline Performance Falls Short: Out of the box, even the best models match the PyTorch Eager baseline in fewer than 20% of cases. As the required speedup threshold ($p$) increases, performance drops precipitously across all difficulty levels.
  • The Feedback Loop is Essential: Providing models with compiler errors and profiler data dramatically improves results. For example, DeepSeek-R1’s success rate on Level 2 tasks jumped from 36% to 72% when allowed 10 turns of iterative refinement.
  • Algorithmic "Aha!" Moments: In some cases, LLMs won not by being better at CUDA, but by finding algorithmic shortcuts. Claude 3.5 Sonnet achieved a 13x speedup on a diagonal matrix multiplication by realizing it didn't need to construct the full matrix at all—a classic "work smarter, not harder" engineering move.
  • Fusion Failures: While models are good at identifying what to fuse in Level 2 tasks, their actual implementation of the fused components is often so inefficient that it negates the benefits of reduced memory access.
  • Low-Resource Language Barrier: CUDA makes up only 0.073% of popular code corpora like "The Stack." This scarcity of training data makes kernel writing a much harder "low-resource" task for LLMs compared to Python or Java.

Limitations and Future Work

The authors acknowledge several limitations in the current benchmark. The study focused almost exclusively on NVIDIA GPUs, highlighting a need to expand to other accelerators like AMD and TPUs. Surprisingly, models performed worse when writing Triton (a higher-level language) than raw CUDA, likely due to even less Triton code being available in training sets. Finally, while the current iterative refinement is a simple loop, the authors suggest that more sophisticated "AI Agents" capable of autonomously running experiments and interpreting profiler traces represent the next frontier for automated kernel engineering.

Summary updated

BibTeX
@inproceedings{ouyang2025kernelbench,
  author = {Anne Ouyang and Simon Guo and Simran Arora and Alex L Zhang and William Hu and Christopher Re and Azalia Mirhoseini},
  title = {{KernelBench: Can LLMs Write Efficient GPU Kernels?}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=yeoN1iQT1x},
}
Figure