KernelBench: Can LLMs Write Efficient GPU Kernels?

Anne Ouyang, Simon Guo, Simran Arora, Alex L. Zhang, William Hu, Christopher R'e, Azalia Mirhoseini

arXiv:2502.10517 · 2026-07-27 공개 · arXiv · PDF

llm-evaluation llm-reasoning execution-feedback gpu-acceleration pytorch kernel-generation speedup-metric ml-optimization

Abstract

Efficient GPU kernels are crucial for building performant machine learning architectures, but writing them is a time-consuming challenge that requires significant expertise; therefore, we explore using language models (LMs) to automate kernel generation. We introduce KernelBench, an open-source framework for evaluating LMs' ability to write fast and correct kernels on a suite of 250 carefully selected PyTorch ML workloads. KernelBench represents a real-world engineering environment and making progress on the introduced benchmark directly translates to faster practical kernels. We introduce a new evaluation metric fast_p, which measures the percentage of generated kernels that are functionally correct and offer a speedup greater than an adjustable threshold p over baseline. Our experiments across various state-of-the-art models and test-time methods show that frontier reasoning models perform the best out of the box but still fall short overall, matching the PyTorch baseline in less than 20% of the cases. While we show that results can improve by leveraging execution and profiling feedback during iterative refinement, KernelBench remains a challenging benchmark, with its difficulty increasing as we raise speedup threshold p.

한국어 요약

한 줄 요약

KernelBench는 LLM이 효율적인 GPU 커널을 생성할 수 있는지 평가하는 오픈소스 프레임워크로, 250개 PyTorch 워크로드에서 기능적 정확성과 속도 향상을 측정한다.

핵심 기여도

핵심 아이디어

KernelBench는 AI 엔지니어의 실제 작업 흐름을 반영하여 LLM이 GPU 커널을 생성하고 최적화하는 능력을 평가하는 환경을 구축했다. 모델은 PyTorch 기준 코드를 입력으로 받아, 어떤 연산을 최적화할지, 어떻게 최적화할지를 스스로 결정할 수 있다. 이는 컴파일러 피드백, 프로파일링 정보, 하드웨어 특성 등을 포함한 다양한 정보를 모델에 제공하는 것을 가능하게 한다.

핵심 통찰은 LLM이 단순히 코드를 생성하는 것이 아니라, **하드웨어 효율성**(예: 테일링, 퓨전)과 **알고리즘 최적화**(예: 스파스성 활용)를 고려한 커널을 생성할 수 있는지 여부이다. 그러나 CUDA는 훈련 데이터에서 상대적으로 희소(0.073%)하여, 모델이 정확한 커널을 생성하는 데 어려움이 있다.

기술적 접근법

주요 결과

의의 및 한계

KernelBench는 LLM이 실제 AI 엔지니어링 환경에서 커널을 생성하고 최적화하는 능력을 평가하는 첫 번째 프레임워크로, **성능 향상과 에너지 절감**에 직접적인 영향을 미친다. 또한, PyTorch 기반으로 하드웨어 플랫폼에 따라 유연하게 평가 가능하며, **fast_p 메트릭은 시간이 지남에 따라 더 진보한 기준에 맞춰 조정 가능**하다.

하지만, **CUDA는 훈련 데이터에서 희소**하여 모델이 정확한 커널을 생성하는 데 어려움이 있으며, **복잡한 최적화**(예: 텐서 코어 wmma)를 시도하면 오류가 증가하는 trade-off가 존재한다. 또한, **기능적 정확성**(functional correctness)은 여전히 큰 도전 과제이다.

실용적 활용

KernelBench는 **AI 하드웨어 개발자**, **모델 최적화 엔지니어**, **LLM 기반 코드 생성 연구자**에게 유용한 평가 도구로 활용될 수 있다. 특히, **새로운 GPU 플랫폼에 맞춘 커널 최적화**, **LLM이 생성한 커널의 성능과 정확성 검증**, **하드웨어 특화 최적화 기법 연구**에 적용 가능하다.