TL;DR
CUDAPERF is a novel reinforcement learning framework that significantly boosts the ability of Large Language Models (LLMs) to generate highly optimized CUDA kernels. By combining traditional execution-based feedback (correctness and speedup) with a "structure-aware" reward system that evaluates code properties like memory coalescing and thread occupancy, CUDAPERF achieves up to a 5X speedup improvement over state-of-the-art baselines.
What Problem Does This Paper Address?
Writing high-performance GPU code in CUDA is notoriously difficult. It requires developers to simultaneously reason about functional correctness and complex, low-level hardware parallelization strategies. While LLMs have become adept at standard code generation, they struggle to produce efficient parallel kernels.
Recent attempts have used Reinforcement Learning with Verifiable Rewards (RLVR) to bridge this gap, but these approaches rely almost entirely on outcome-based signals—simply checking if the code compiles, passes tests, or runs faster. This black-box approach ignores the underlying structural properties of the code (the "why" behind performance), leaving the model blind to expert-level optimization techniques like efficient memory access patterns or minimizing thread divergence.
Methods
CUDAPERF introduces a two-stage, reflective reinforcement learning framework that blends execution feedback with structural code analysis:
- Offline Pairwise Ranking: The authors identify a core set of parallel code features critical to GPU performance (e.g., memory coalescing strides, arithmetic intensity, threads-per-block occupancy, control divergence, and data transfer overhead). A lightweight Multi-Layer Perceptron (MLP) ranker is trained on these extracted features using a contrastive pairwise loss, learning to score optimized CUDA kernels higher than inefficient ones. This provides a dense, execution-free Structural Reward.
- Online RL Training: Using Group Relative Policy Optimization (GRPO), a base model (Qwen-3-32B) is fine-tuned using a composite reward signal: the learned Structural Reward plus a Verifiable Reward (derived from compilation success, test case pass rates, and log-scaled execution speedups).
To push performance further, CUDAPERF employs Multi-turn Iterative Refinement. If a generated kernel fails or runs slowly, the framework feeds structured compiler and profiling feedback back into the model over up to 5 turns, using an auxiliary LLM to summarize the history and prevent context explosion.
Datasets
The authors curated a diverse dataset to train and evaluate their framework, which includes:
- CUDAPERF Dataset (Ours): A newly introduced dataset consisting of 2,903 C → CUDA and 1,013 PyTorch → CUDA programs. Each sequential program is paired with multiple valid CUDA variations demonstrating different optimization strategies and randomized test inputs.
- BabelTower: An existing benchmark used to evaluate C → CUDA translation.
- KernelBench: A benchmark consisting of 250 PyTorch programs representing real-world machine learning workloads.
Key Insights and Ideas
- White-Box vs. Black-Box Learning: Purely execution-based RL treats code optimization as a black box. Incorporating structural features introduces a strong inductive bias, teaching the model why certain parallel structures run faster.
- Structural Rewards as a Dense Proxy: Execution rewards can be noisy (due to hardware variance) or sparse (if code fails to compile). Structural rewards provide a dense, stable signal that guides the model even before the code runs successfully.
- The Synergy of Both Rewards: Ablation studies revealed that removing either reward mechanism severely harms performance. Without structural rewards, speedups drop significantly; without verifiable rewards, functional correctness plummets.
Key Results
CUDAPERF consistently outperformed both general-purpose LLMs (like OpenAI's o4-mini and Qwen-3-32B) and specialized, task-specific code generation agents:
- C → CUDA Translation: On the CUDAPERF dataset, it achieved an 11.02X geometric mean speedup and 89% correctness, compared to Qwen-3-32B's 6.2X speedup and 72% correctness.
- PyTorch → CUDA Translation: Evaluated on KernelBench, CUDAPERF achieved a 6.41X speedup and 93% correctness, vastly outperforming the state-of-the-art CUDA Agent baseline, which only managed a 3.09X speedup and 86% correctness.
Limitations and Future Work
Despite its impressive performance, CUDAPERF has a few notable limitations:
- High Computational Overhead: The online RL phase requires repeatedly compiling and benchmarking thousands of candidate GPU kernels, making the training process highly time- and resource-intensive.
- Bounded Optimization Strategies: Because the structural reward ranker relies on a predefined set of expert-guided parallel features, the framework's ability to discover entirely novel, unconventional optimization strategies outside of these patterns remains limited.
Summary updated