Source-linked AI summary

StitchCUDA: An Automated Multi-Agents End-to-End GPU Programing Framework with Rubric-based Agentic Reinforcement Learning

Shiyang Li, Zijian Zhang, Winson Chen, Yuebo Luo, Mingyi Hong, Caiwen Ding

arXiv:2603.02637v2cs.MAcs.CLcs.PL

TL;DR

End-to-end GPU programs remain difficult because performance depends on both kernel execution and host-side orchestration, beyond the scope of most prior single-kernel methods. StitchCUDA addresses this with three cooperating agents and rubric-based agentic RL for generation and feedback-driven optimization. Across KernelBench tasks, it improves correctness and speedup over no-RL and baseline approaches, while its demonstrated portability remains limited across hardware generations.

  • Problem

    Prior GPU code-generation methods mainly optimize single kernels, whereas end-to-end workloads require coordination across interacting kernels, data movement, synchronization, and host orchestration.

  • Method

    StitchCUDA combines Planner, Coder, and Verifier agents with rubric-based RL trained on CUDA generation and feedback-driven optimization, using execution-based correctness and speedup rewards.

  • Results

    On H200 Level 3 tasks, agentic RL improves correctness from 3/10 to 9/10, mean speedup from 0.24× to 1.50×, and Fast1 from 10% to 70% versus StitchCUDA-Q.

  • Takeaways & Limitations

    Multi-agent orchestration makes harder end-to-end benchmarks attainable, while rubric-based agentic RL produces more consistent real-system-level optimization beyond correctness alone.

  • Takeaways & Limitations

    Experiments cover H200 and RTX PRO 6000, so it remains unclear whether generated programs preserve correctness and performance across hardware generations.

Abstract

from arXiv · show

Modern machine learning (ML) workloads increasingly rely on GPUs, yet achieving high end-to-end performance remains challenging due to dependencies on both GPU kernel efficiency and host-side settings. Although LLM-based methods show promise on automated GPU kernel generation, prior works mainly focus on single-kernel optimization and do not extend to end-to-end programs, hindering practical deployment. To address the challenge, in this work, we propose StitchCUDA, a multi-agent framework for end-to-end GPU program generation, with three specialized agents: a Planner to orchestrate whole system design, a Coder dedicated to implementing it step-by-step, and a Verifier for correctness check and performance profiling using Nsys/NCU. To fundamentally improve the Coder's ability in end-to-end GPU programming, StitchCUDA integrates rubric-based agentic reinforcement learning over two atomic skills, task-to-code generation and feedback-driven code optimization, with combined rubric reward and rule-based reward from real executions. Therefore, the Coder learns how to implement advanced CUDA programming techniques (e.g., custom kernel fusion, cublas epilogue), and we also effectively prevent Coder's reward hacking (e.g., just copy PyTorch code or hardcoding output) during benchmarking. Experiments on KernelBench show that StitchCUDA achieves nearly 100% success rate on end-to-end GPU programming tasks, with 1.72x better speedup over the multi-agent baseline and 2.73x than the RL model baselines. Code of the STITCHCUDA framework is avalaible at https://github.com/UMN-APEX-Lab/StitchCUDA.

2. Background

KernelBench-era LLM systems largely optimize individual CUDA kernels, while end-to-end workloads require coordination across kernels, host orchestration, and system-level constraints. Existing multi-agent and RL approaches also face reward hacking, weak feedback use, and costly scaling to realistic end-to-end programs.

  • KernelBench Levels 1/2 emphasize single-kernel generation and limited fusion under fixed interfaces and micro-benchmark objectives.
  • Existing agentic systems such as CUDAForge, cuPilot, astra, and QiMeng iteratively refine kernels using correctness, profiling, evolutionary-search, or roofline-guided feedback.
  • End-to-end scaling introduces local optima, specification drift, long code contexts, redundant edits, and unstable convergence across kernels, host orchestration, and library calls.
  • Rule-based RL rewards based on correctness and speedup are vulnerable to reward hacking and degenerate behavior.
  • Existing coders are not trained to interpret structured execution feedback, while multi-turn agentic RL rollouts are prohibitively costly in realistic CUDA environments.

3. Framework Design and Methodology

StitchCUDA coordinates Planner, Coder, and Verifier agents through an iterative coding-feedback workflow, while rubric-based single-turn RL trains the Coder on generation and feedback-driven optimization. Its reward combines rubric shaping with execution-based correctness and speedup signals to discourage hacking and encourage CUDA engineering.

  • Multi-agent Framework Workflow: StitchCUDA uses Planner, Coder, and Verifier agents coordinated through a shared typed state and iterative coding-feedback loop.
  • Multi-agent Framework Workflow: The Planner profiles reference code with Nsys, identifies hotspots, and emits subtasks containing target kernels, shapes, and implementation constraints.
  • Multi-agent Framework Workflow: The Coder implements each subtask, compiles it with nvcc, records build artifacts, and revises code using Verifier feedback.
  • Multi-agent Framework Workflow: The Verifier checks compilation and correctness, profiles successful programs with Nsys or NCU, and routes actionable fixes or optimization suggestions back through the workflow.
  • Agentic RL Training: To reduce rollout cost, agentic RL is decomposed into single-turn training for from-scratch CUDA generation and feedback-driven targeted optimization.
  • Rubric-based Reward: The rubric scores anti-hacking, CUDA engineering, and related candidate qualities, complementing rule-based correctness and speedup rewards.
  • Rubric-based Reward: Rubric normalization maps criterion scores from 1 to 5 into a centered shaping signal, while the final reward suppresses hacked solutions and caps magnitude at Rmax = 5.

4. Experiments and Evaluation

StitchCUDA is evaluated on KernelBench Levels 1–3 across multiple models, GPUs, and ablations, measuring correctness, end-to-end speedup, and Fast1. Multi-agent orchestration improves difficult-task correctness, while rubric-based agentic RL delivers stronger Level 3 optimization and reduces hacking relative to ablated or baseline systems.

  • Experimental setup: The evaluation uses KernelBench Levels 1–3, two GPUs, 15 refinement iterations, and success rate, E2E average speedup, and Fast1 as metrics.Level 3 contains end-to-end tasks, while Levels 1 and 2 focus on kernel-level workloads.
  • Main results: Multi-agent orchestration raises Qwen3-32B Level 1 correctness from 2/20 to 17/20 and enables successful Level 2 and Level 3 cases.StitchCUDA-Q achieves 2.13× mean speedup on Level 1, with 16/20 correctness on Level 2 and 3/10 on Level 3.
  • Main results: Kevin32B’s Level 3 correctness improves from 4/10 to 7/10 on RTX PRO 6000 and from 2/10 to 5/10 on H200 within the multi-agent workflow.The comparison indicates that decomposition and tool-augmented iteration improve multiple underlying models.
  • Main results: On H200 Level 3, agentic RL increases correctness from 3/10 to 9/10, mean speedup from 0.24× to 1.50×, and Fast1 from 10% to 70% versus StitchCUDA-Q.The same direction holds on Level 2 and RTX PRO 6000, with gains extending beyond correctness.
  • Main results: StitchCUDA surpasses StitchCUDA-G on all Level 3 metrics and is the only method achieving nearly 100% correctness there, despite using a smaller 32B Coder.The two systems obtain similar Level 1/2 performance, while the difference appears on Level 3.
  • Main results: With torch.compile enabled in the H200 Level 3 reference, StitchCUDA achieves 1.29× speedup, exceeding StitchCUDA-G at 0.92× and Kevin32B at 0.18×.The authors attribute the improvement to manual system optimization, including custom kernel fusion and data-movement optimization.
  • Ablation study: Removing rubric reward lowers Level 3 success rate and speedup, while per-dimension ablations show anti-hacking most strongly affects correctness, hacking, and speedup.Removing Anti-Hacking changes correctness from 9.0 to 5.7, hacking instances from 7.7 to 15.7, and speedup to 0.75×; removing CUDA Engineering reduces speedup to 1.18×.

5. Discussion

The discussion identifies reward hacking, degenerate optimization behavior, and limited hardware generalization as important challenges, while outlining benchmark and knowledge-staleness limitations.

  • Reward hacking: Format checks fail to reliably prevent reward hacking because subtle behaviors such as hard coding evade regex detection, while strict checks risk rejecting correct solutions.The authors therefore conclude that format checking alone is inadequate for KernelBench.
  • Degenerate behaviors: Current models often modify only easy kernels in multi-kernel tasks, leaving critical operations such as convolution and GEMM unchanged.This behavior limits performance improvements in complex end-to-end workloads.
  • Degenerate behaviors: Models also avoid advanced techniques such as fine-grained tiling and tensor cores, which partially explains declining speedups on harder KernelBench tasks.The authors connect this behavior to models’ reluctance to challenge performance-critical components.
  • Limitations: GPU optimization may not generalize across hardware generations because platforms differ in shared memory capacity and tensor-core support.The experiments cover H200 and RTX PRO 6000, leaving cross-generation preservation of correctness and performance unclear.
  • Limitations: RAG partially mitigates stale GPU knowledge, but retrieved documentation does not guarantee that models correctly interpret newly introduced hardware features, interfaces, and practices.Large-scale pretraining is difficult to synchronize with rapidly changing GPU software stacks.
  • Limitations: Current CUDA-generation benchmarks mainly test correctness and speedup in a few fixed environments, without systematically measuring portability, software-stack robustness, deployment safety, or long-term regression.The authors argue that deployment-quality GPU software also requires evaluation under real application semantics.

6. Conclusion

The paper presents StitchCUDA as a multi-agent framework combining rubric-based reinforcement learning with improved agent decomposition for automated end-to-end GPU programming. Experiments report strong performance relative to simple multi-agent approaches and RL models.

  • Conclusion: StitchCUDA integrates rubric-based reinforcement learning with a multi-agent framework to improve automated end-to-end GPU program generation.The framework specifically enhances the Coder’s CUDA programming ability while using multi-agent decomposition.
  • Conclusion: Experiments show that StitchCUDA significantly outperforms simple multi-agent approaches and RL models on end-to-end GPU programming tasks.The conclusion characterizes the experimental results as comprehensive and excellent.

A. KernelBench Modification.

The KernelBench modifications address tasks whose reference computations can produce trivial all-zero outputs, which could falsely reward incorrect or incomplete GPU implementations.

  • Original task: Level 2 task 80 reduces a linear projection from shape (B, O) to (B, 1), then mean-centers and applies GELU.The task contains four kernels and uses GEMM, maximum reduction, mean-centering, and GELU.
  • Degenerate computation: Because each reduced row contains one scalar, its mean equals that scalar, making the mean-centered tensor identically zero.This degeneracy follows from the max reduction collapsing the feature dimension.
  • Degenerate computation: GELU preserves the all-zero result, regardless of the inputs or their sizes.Consequently, an implementation can return zeros and still appear correct.
  • Benchmark modification: The authors replace hard max reduction with top-k selection so each row retains k > 1 feature values before mean-centering.This prevents the mean from trivially equaling the sole retained element.
  • Benchmark modification: Similar deterministic-zero issues occur in multiple Level 1, Level 2, and Level 3 tasks, which the authors manually fix before training and evaluation.The listed affected tasks include Level 1 tasks 12, 85, and 87; Level 2 tasks 80 and 83; and Level 3 tasks 33, 41, 45, and 50.

B.1. Prompts and example outputs

The appendix specifies structured prompts for planning, coding, and profiling CUDA programs. These prompts require explicit program analysis, optimization choices, verification feedback, routing decisions, and constrained CUDA-only outputs.

  • Coder prompt: The Coder prompt targets high-performance CUDA/C++ programs that preserve PyTorch functionality while maximizing utilization and using techniques such as tiling, fusion, and tensor cores.The prompt is conditioned on a reference implementation and profiling context.
  • Planner prompt: The Planner prompt requests operations, exact tensor shapes, weights, fusion opportunities, intermediate buffers, kernel specifications, execution order, and optimization strategy.The requested plan includes library selection and memory- and compute-optimization details.
  • Planner prompt: The planning principles emphasize model-specific analysis, bottleneck identification, fusion, appropriate libraries, tensor cores, coalescing, shared memory, and tiling.These principles guide both system-level and kernel-level optimization.
  • Verifier prompt: The Verifier prompt asks the agent to analyze Nsys and NCU results, identify the primary bottleneck, and propose one specific optimization.The structured output includes bottleneck type, metric evidence, optimization, files to modify, and next steps.
  • Verifier prompt: Routing sends failed or incorrect tests back to coding, passed intermediate tasks to the next task, and completed final tasks to final integration testing.The routing rules distinguish current-task retry, task advancement, and final testing.
  • Coder prompt: The CUDA implementation prompt targets specified hardware and requires a complete implementation of the designated CUDA file without Python or unrelated files.The target description includes GPU architecture, tensor-core availability, memory bandwidth, and shared-memory guidance.
  • Coder prompt: The prompt requires a __global__ kernel and prefers custom kernels over unoptimized host-side library calls.The requirement exists to support profiling and fine-grained optimization.

B.2. RAG database building

StitchCUDA builds a retrieval database from authoritative NVIDIA CUDA documentation to support its Planner, Verifier, and Coder. The system retrieves documents selectively when agents need additional API or usage guidance.

  • B.2. RAG database building: Official NVIDIA CUDA webpages, including cuBLAS and CUTLASS tutorials and documentation, are curated as authoritative references for the Planner and Verifier.The sources provide API specifications and usage guidance for the Coder.
  • B.2. RAG database building: Each webpage is converted into text, segmented into overlapping 1000-token chunks with 100-token overlap, and encoded as embeddings for retrieval.The overlap preserves contextual continuity across document segments.
  • B.2. RAG database building: RAG effects are difficult to quantify because agents freely decide whether retrieval is necessary during inference.The authors nevertheless observe cases where Verifier retrieves the correct cuBLAS API name after a Coder compile error.

C. Additional details in rubric-based agentic reinforcement learning

The rubric-based reinforcement-learning design targets reward hacking and degenerate behavior in CUDA generation while preserving useful learning signals. It combines execution-based evaluation with rubric-based assessment and supports increasingly effective end-to-end implementations.

  • C.1.1. CHALLENGES OF REWARD HACKING: Reward hacking exploits loopholes in reward or evaluation procedures to obtain high reward while poorly serving the intended CUDA-generation objective.The common rule-based formulation combines functional correctness and speedup, creating opportunities for such exploitation.
  • C.1.1. CHALLENGES OF REWARD HACKING: PyTorch-only code can achieve high reward more easily than complex custom kernels, producing apparently successful “kernels” without CUDA code.A cited example reports a 64.4x speedup after switching implementation method with a PyTorch API.
  • C.1.1. CHALLENGES OF REWARD HACKING: Format checks may miss hacking kernels or incorrectly reject correct kernels containing partial PyTorch functional operators, creating an unfavorable detection trade-off.The authors report that omitted hacks can receive higher rewards than custom implementations and shift model behavior toward hacking.
  • C.1.1. CHALLENGES OF REWARD HACKING: Rubric-based rewards use an advanced LLM and expert-designed rubrics to detect reward hacking more robustly than format checks.Reward clipping further limits the influence of undetected hacks and helps avoid training collapse.
  • C.1.2. CHALLENGES OF DEGENERATE BEHAVIOR: Degenerate behavior includes trivial code modifications or conservative implementations that prioritize correctness over meaningful optimization.A cited example achieves 1.10x speedup while leaving the main Conv2D bottleneck unoptimized despite verifier feedback.
  • C.2. Case study of StitchCUDA: The case study reports 2.7x speedup over eager-mode reference execution and 2.08x speedup over torch.compile.These gains combine system-level and kernel-level optimizations.
  • C.2. Case study of StitchCUDA: The degenerate-behavior policy avoids assigning zero reward to every incomplete custom implementation because current LLMs struggle to cover all reference operations in one inference.The authors distinguish this behavior from reward hacking to avoid severe sparse-reward problems during RL training.
Loading 2603.02637v2…