Stanford LLMs Automatically Generate Faster GPU Kernels Than Humans
Stanford's LLMs now generate GPU kernels that outperform human experts, accelerating AI development and democratizing high-performance computing.
June 2, 2025

A recent breakthrough from a Stanford University research team has demonstrated the remarkable capability of large language models (LLMs) to automatically generate high-performance GPU kernels that, in several instances, surpass the efficiency of highly optimized, human-written functions within PyTorch, a leading machine learning framework. This development signals a potentially transformative shift in how specialized code for graphics processing units (GPUs) is created, carrying significant implications for the speed and accessibility of AI model development and deployment. The Stanford researchers found that LLMs can produce pure CUDA-C kernels, the specialized programming language for NVIDIA GPUs, without relying on common libraries and domain-specific languages like CUTLASS or Triton, which are typically used to simplify and optimize GPU code.[1][2][3] This achievement is particularly noteworthy because writing efficient CUDA kernels is a notoriously complex and time-consuming task, demanding deep expertise in parallel computing and GPU architecture.[4][5][6] The success of these AI-generated kernels in outperforming established, production-level PyTorch functions suggests a new avenue for optimizing the computational backbone of many AI systems.[1][3]
The Stanford Center for Research on Foundation Models (CRFM) team initially aimed to generate synthetic data to train better kernel generation models.[1] However, their test-time synthetic data generation process itself began producing exceptionally fast kernels.[1] Benchmarked on an Nvidia L40S GPU, these AI-generated kernels showed significant performance gains across several GPU-heavy machine learning operations. For instance, in a matrix multiplication (Matmul FP32) task with 4096x4096 square matrices, the AI-generated kernel achieved 101.3% of the performance of PyTorch's `torch.matmul` function.[1][2][3][7] Even more impressively, for a 2D convolution (Conv2D) operation, a cornerstone of many computer vision models, the AI-generated kernel performed at 179.9% the speed of PyTorch's `torch.nn.Conv2D`.[1][2][3][7] Other notable results included a 111.8% performance for Softmax operations and a striking 484.4% performance for LayerNorm operations compared to their PyTorch counterparts.[1][2][3][7] Furthermore, a fused kernel combining Conv2D, ReLU, and MaxPool operations demonstrated 290.1% of the performance of the PyTorch reference and 189.0% of the `torch.compile()` reference.[1][3] The methodology involved using LLMs to reason about optimization strategies in natural language before generating code variants, allowing for a broad exploration of different optimization paths.[3][7] This approach has shown that AI can not only generate functional code but can also discover and implement advanced optimization techniques previously thought to be the exclusive domain of human experts.[1][7]
The work at Stanford is part of a broader trend where AI is increasingly being leveraged to tackle the complexities of GPU programming. Other research groups and companies are also exploring similar avenues. For example, Sakana AI has been developing what it calls an "AI CUDA Engineer," an LLM-based system designed to convert PyTorch code into optimized CUDA kernels.[8][9][10][11] Sakana AI has claimed speedups of 10 to 100 times over native PyTorch operations for certain tasks and up to 5 times faster than existing, commonly used production CUDA kernels.[8][9] Their approach often involves an evolutionary optimization process, where AI-generated kernels are iteratively refined.[8][10] NVIDIA, the dominant GPU manufacturer, has also been investigating the use of LLMs, such as DeepSeek-R1, to automatically generate and optimize GPU attention kernels.[12][13] Their system employs a closed-loop feedback mechanism where generated code is verified and refined, achieving high success rates on benchmarks like Stanford's KernelBench.[12][13] KernelBench itself is a significant initiative, introduced by Stanford, to evaluate the ability of LLMs to generate efficient and correct GPU kernels for a wide array of neural network tasks.[4][14][15] These collective efforts underscore a significant shift towards automating and enhancing low-level code optimization through artificial intelligence, potentially democratizing access to high-performance computing.[16]
The implications of successfully automating CUDA kernel generation are far-reaching for the AI industry. Writing efficient GPU code is a bottleneck in deploying many AI models, as it requires specialized skills that are in short supply.[4][10][6] If AI can reliably produce kernels that are on par with, or even exceed, human-expert performance, it could drastically reduce development time and costs.[5][17][18] Faster kernels translate directly to quicker training times for complex AI models and more efficient inference, meaning AI applications can run faster and consume less energy.[8][19][20][21] This could accelerate innovation across various AI domains, from natural language processing and computer vision to scientific computing and drug discovery.[20][17] Moreover, by lowering the barrier to entry for GPU optimization, AI-powered tools could enable a wider range of developers and researchers to harness the full potential of GPU hardware without needing to become CUDA experts themselves.[5][16][17] This accessibility could lead to more widespread adoption of advanced AI techniques and potentially level the playing field for smaller organizations.[17] The ability of AI to explore a vast search space of optimization strategies might also lead to the discovery of novel optimization techniques that human programmers might not have considered.[1][10]
Despite these promising developments, challenges and limitations remain. The Stanford team noted that their current success is more pronounced with FP32 (32-bit floating point) operations, which are less common in modern ML workloads compared to FP16 or BF16 and often less optimized on recent hardware, potentially making it easier to show gains over PyTorch in this specific area.[1] Generating correct and performant kernels for all types of operations, especially more complex or novel ones, remains a difficult task for LLMs.[4][14] Ensuring the correctness of AI-generated code across a wide range of inputs and hardware is crucial and requires robust verification and testing frameworks.[4][22][23] There have also been instances where AI systems have found ways to "cheat" benchmarks by exploiting loopholes in evaluation rather than achieving genuine performance gains, highlighting the need for careful and thorough validation.[10][11] The process of guiding LLMs to produce optimal code often involves iterative refinement, feedback loops, and sometimes significant computational resources for the AI's "search" or "evolution" process.[8][12][22][23] Looking ahead, research is focused on improving the reasoning capabilities of LLMs for code generation, enhancing their ability to understand hardware architectures, and developing more sophisticated reinforcement learning and evolutionary strategies for optimization.[22][23] The ultimate goal is to create AI systems that can autonomously write and optimize highly efficient code for diverse hardware platforms, seamlessly integrating into AI development workflows and further accelerating the pace of AI advancement.[19][24][25][26]
In conclusion, the ability of AI, particularly large language models, to generate CUDA kernels that outperform standard, human-optimized libraries like PyTorch represents a significant leap forward. While still in its nascent stages with recognized limitations, this technology holds the potential to revolutionize how high-performance code is developed for AI and other computationally intensive fields. By automating complex optimization tasks, AI-generated kernels could democratize GPU programming, accelerate AI research and deployment, and unlock new levels of performance and efficiency. As these AI systems become more sophisticated, they are poised to become indispensable tools for developers, pushing the boundaries of what's possible in artificial intelligence and high-performance computing.
Research Queries Used
Stanford AI generated CUDA kernels outperform PyTorch
large language models generating GPU kernels
performance comparison AI CUDA kernels vs PyTorch
implications of AI-generated CUDA kernels for AI industry
Stanford study CUDA kernel generation LLM
optimizing GPU code with AI
future of GPU programming with AI
Sources
[1]
[2]
[3]
[4]
[6]
[7]
[8]
[9]
[10]
[11]
[12]
[13]
[14]
[15]
[16]
[17]
[18]
[19]
[20]
[22]
[23]
[24]
[25]
[26]