Abstract
GPU kernel optimization is fundamental to modern deep learning but remains a highly specialized task requiring deep hardware expertise. Despite strong performance in general programming, large language models (LLMs) remain uncompetitive with compiler-based systems such as torch.compile for CUDA kernel generation. Existing CUDA code generation approaches either rely on training-free refinement or fine-tune models within fixed multi-turn execution-feedback loops, but both paradigms fail to fundamentally improve the model's intrinsic CUDA optimization ability, resulting in limited performance gains. We present CUDA Agent, a large-scale agentic reinforcement learning system that develops CUDA kernel expertise through three components: a scalable data synthesis pipeline, a skill-augmented CUDA development environment with automated verification and profiling to provide reliable reward signals, and reinforcement learning algorithmic techniques enabling stable training. CUDA Agent achieves state-of-the-art results on KernelBench, delivering 100%, 100%, and 92% faster rate over torch.compile on KernelBench Level-1, Level-2, and Level-3 splits, outperforming the strongest proprietary models such as Claude Opus 4.5 and Gemini 3 Pro by about 40% on the hardest Level-3 setting.
The Challenge of CUDA Optimization
Writing high-performance CUDA kernels is often described as a "black art," requiring deep expertise in GPU microarchitecture, memory hierarchies, and specialized profiling tools. While Large Language Models (LLMs) excel at general programming, they struggle with the hardware-level nuances of CUDA. Most LLM-generated kernels are functionally correct but significantly slower than those produced by compiler-based systems like torch.compile.
Existing approaches typically fall into two camps: training-free refinement (prompting the model to fix its own mistakes) or fine-tuning within fixed loops. Both fail to improve the model's intrinsic understanding of hardware-level optimization. CUDA Agent bridges this gap by treating CUDA optimization as a reinforcement learning (RL) problem where the agent learns to navigate the vast search space of hardware-specific optimizations.
Methods and Framework
The CUDA Agent system is built upon three core pillars:
- Agentic RL Framework: The model follows a "ReAct" paradigm, interleaving reasoning with action. It is equipped with a suite of tools (Bash, Read/Write, Profiling) and a structured workflow (
SKILL.md) that guides it through analyzing bottlenecks, implementing custom operators, and iterative refinement. - Stable Training Pipeline: Training RL agents on long-context trajectories (up to 128k tokens) is notoriously unstable. To prevent "policy collapse," the authors developed a multi-stage warm-up involving Single-Turn RL, Rejection Fine-Tuning (RFT) to establish a behavioral prior, and Value Pretraining for the critic network.
- Robust Reward Scheduling: Instead of rewarding raw speedup, which can be noisy, the system uses a milestone-based system. The agent receives discrete rewards for passing correctness checks, beating PyTorch "Eager" mode, and finally surpassing the
torch.compilebaseline.
Data Synthesis and Datasets
To overcome the scarcity of CUDA code in standard pretraining data (less than 0.01%), the researchers introduced CUDA-Agent-Ops-6K. This dataset contains 6,000 curated operator-level tasks created by crawling seed operators from PyTorch and using LLMs to synthetically fuse them into complex, multi-operator tasks. Evaluation is conducted on KernelBench, which spans three difficulty levels from basic sequences to realistic model components.
Key Results and Performance
CUDA Agent sets a new benchmark for automated kernel generation. It consistently outperforms both static compilers and the most advanced proprietary LLMs.
- Faster Rate: It produced kernels faster than
torch.compilein 100% of Level-1 and Level-2 cases, and 92% of Level-3 cases. - Speedups: On the hardest Level-3 tasks, it achieved a 1.52x geometric mean speedup over
torch.compile. - Competitive Edge: It outperformed Claude Opus 4.5 and Gemini 3 Pro by approximately 40% on the hardest settings.
Insights into Hardware Awareness
The agent's success stems from its ability to discover non-trivial "operator fusion" patterns—combining multiple operations into a single kernel to minimize global memory access. Through RL, CUDA Agent learns to leverage specific hardware features like Tensor Cores (TF32), vectorized loads (float4), and shared memory tiling. It even develops sophisticated strategies like folding BatchNorm parameters into weights to optimize computation time.
Limitations and Future Work
While CUDA Agent demonstrates remarkable performance, it requires significant compute resources, utilizing a pool of 128 NVIDIA H20 GPUs for training. Future work will focus on more resource-efficient training strategies and expanding the agent's toolbox to include more sophisticated hardware-specific profiling signals. Additionally, expanding comparisons to specialized compilers like TVM remains a goal for future iterations.
Summary updated