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

CudaForge: An Agent Framework with Hardware Feedback for CUDA Kernel Optimization

Zijian Zhang, Rong Wang, Shiyang Li, Yuebo Luo, Mingyi Hong, Caiwen Ding

TL;DR

CudaForge is a training-free, multi-agent LLM framework that automates CUDA kernel optimization by mimicking the iterative workflow of human engineers. By pairing a "Coder" agent with a "Judge" agent that interprets hardware profiling data from NVIDIA Nsight Compute, it achieves a 1.68× speedup over PyTorch baselines at a fraction of the cost of previous reinforcement learning or brute-force agentic methods.

What Problem Does This Paper Address?

Writing high-performance GPU code (CUDA) is notoriously difficult, requiring deep expertise in hardware architectures and parallel programming. While large language models (LLMs) excel at general code generation, they struggle to write correct or highly optimized CUDA kernels out of the box.

Existing automated approaches fall into two camps, both with severe drawbacks:

  1. Reinforcement Learning (RL) methods: These require massive computational resources and long training cycles, yet often yield suboptimal kernel efficiency because they explore optimizations blindly.
  2. Heavy Agentic Frameworks: These run at inference time but incur massive costs (e.g., up to 6 H100 GPU hours and $5 in API fees per kernel).

Crucially, prior methods lack hardware awareness—they optimize code based on text or raw execution times without understanding the underlying hardware bottlenecks (like memory bandwidth or register limits) of the specific GPU being used.

Methods

CudaForge introduces a lightweight, training-free multi-agent architecture consisting of two specialized LLM agents: a Coder and a Judge.

Instead of a single LLM trying to write and evaluate its own code, CudaForge splits the cognitive load to mirror a human engineering workflow:

  1. Initialization: The Coder generates an initial kernel candidate based on the task description and a PyTorch reference.
  2. Correctness Testing: The framework compiles and executes the kernel. If it fails, the Judge enters Correction Mode, analyzing compilation or runtime error logs to give specific bug-fix hints.
  3. Hardware-Aware Optimization: Once the kernel passes correctness checks, the Judge enters Optimization Mode. It profiles the kernel using NVIDIA Nsight Compute (NCU) to collect hardware feedback.

To prevent the LLM from being overwhelmed by raw data, the authors designed an offline protocol to select a key subset of 24 critical NCU metrics (like warp occupancy and memory throughput) highly correlated with runtime. The Judge uses these metrics alongside static GPU specifications to pinpoint the exact bottleneck and provide targeted optimization strategies (e.g., shared memory tiling, warp-level shuffles) to the Coder for the next round.

Human vs. CudaForge workflow comparison

Additionally, CudaForge utilizes a Lightweight Memory Design. Instead of feeding the entire multi-round conversation history back into the LLM (which inflates API costs and causes code hallucination), agents only receive the latest feedback and the immediate previous kernel candidate.

Datasets

The framework was evaluated on KernelBench, a standardized benchmark containing 250 tasks across three difficulty levels:

  • Level 1 (Basic Operators): Simple, low-level operators like matrix multiplication and reductions.
  • Level 2 (Composite Operations): Multi-step operator combinations requiring intermediate memory management.
  • Level 3 (End-to-End Models): Challenging kernels derived from full neural network architectures like AlexNet, VGG, and ResNet.

The authors also constructed a stratified random subset ($D^*$) of 25 tasks to perform cost and ablation analyses efficiently.

Key Insights and Ideas

  • Less is More with Hardware Metrics: A major "aha" moment was discovering that feeding the full raw set of NCU metrics to an LLM actually degrades its performance. The model gets overwhelmed by redundant signals and misidentifies bottlenecks. Restricting the Judge to 24 curated metrics dramatically improves optimization quality.
  • Correctness First: Trying to optimize code that doesn't compile or run correctly is a waste of compute. CudaForge's dual-mode Judge ensures the kernel is functionally stable before attempting any performance tuning.
  • Hardware-Driven Generalization: Because the Judge reacts dynamically to real-time hardware profiling data, the framework automatically tailors its optimizations to the underlying system, allowing it to generalize across different GPU generations without retraining.
Figure 3: The overview of how CudaForge optimizes kernels, compared with Kevin-32B. Top: the pipeline of the RL-based Kevin-32B, which relies solely on textual refinement and thus performs blind exploration. Bottom: our CudaForge workflow, which leverages hardware feedback to guide kernel optimization. When the Coder in CudaForge generates a correct candidate kernel in Round 1, the system profiles it using Nsight Compute (NCU) to obtain NCU metrics. In Round 2, the Judge analyzes these metrics and GPU specifications to identify performance bottlenecks (e.g., register- or memory-limited) and provides targeted optimization feedback. The Coder then refines the kernel accordingly. Compared with Kevin-32B, which only refines based on speedup scores, our framework achieves more interpretable and effective performance improvements through hardware- aware iteration.

Key Results

  • State-of-the-Art Performance: CudaForge achieved 97.6% correctness across KernelBench and an average 1.68× speedup over PyTorch baselines, significantly outperforming RL-based methods like Kevin-32B and vanilla frontier models.
  • Test-Time Scaling: By increasing the maximum iteration rounds from 10 to 30, CudaForge's performance scaled up to a 2.27× speedup.
  • Unprecedented Cost Efficiency: Optimization takes only 26.5 minutes on a single RTX 6000 GPU and costs roughly $0.30 in API fees per kernel—a massive improvement over previous agentic baselines that required 6 H100 hours and $5 per kernel.
  • Robust Generalization: The framework generalizes seamlessly across different GPU architectures (A100, RTX 4090, 3090, 6000) and various backend LLMs (OpenAI-o3, GPT-5, Claude-Sonnet-4).
Figure 1: CudaForge achieves state-of-the-art results on KernelBench in both correctness and performance, surpassing RL-based methods such as Kevin-32B [1], the agentic baseline [2], and OpenAI-o3 [3]. To further evaluate the effectiveness of our design, we additionally develop three customized variants of OpenAI-o3: o3-self-refine, o3-correction, and o3-optimization, which serve as baselines for ablation comparison. Scaling up maximum iteration rounds(CudaForge-Scaling Up) further improves CudaForge’s performance to 2.27× speedup. Experimental details are provided in Section 3.

Limitations and Future Work

  • Profiling Overhead: Running Nsight Compute (NCU) at every iteration adds physical runtime overhead, making the wall-clock time dependent on external profiling tools.
  • Advanced Hardware Features: The current framework focuses on general CUDA optimizations. Future work could extend CudaForge to exploit cutting-edge, architecture-specific hardware features, such as the Tensor Memory Accelerator (TMA) found in NVIDIA Hopper GPUs.
  • Detecting "Fake Kernels": The authors noted that some competing baselines "cheat" by wrapping code in try-except blocks that silently fall back to standard PyTorch implementations when the CUDA code fails. While CudaForge manually verified its kernels to avoid this, building automated guardrails against such LLM shortcuts remains an open area for improvement.

Summary updated

BibTeX
@misc{zhang2025cudaforge,
  author = {Zijian Zhang and Rong Wang and Shiyang Li and Yuebo Luo and Mingyi Hong and Caiwen Ding},
  title = {{CudaForge: An Agent Framework with Hardware Feedback for CUDA Kernel Optimization}},
  year = {2025},
  eprint = {2511.01884},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2511.01884},
}
Figure