Abstract
Optimizing GPU kernels is critical for AI performance but remains a "dark art" requiring deep hardware expertise. We introduce STARK, a multi-agent LLM framework that mimics expert engineers by separating planning, coding, and debugging roles while using a strategic tree search to explore the optimization space. STARK dramatically outperforms existing single-agent baselines, generating correct and highly optimized CUDA kernels that run up to 16x faster than those produced by previous LLM methods.
The Challenge of GPU Kernel Optimization
At the core of modern AI are GPU kernels—low-level implementations of fundamental operations like matrix multiplication and convolution. Writing and optimizing these kernels in CUDA requires deep knowledge of memory hierarchies, thread scheduling, and hardware-specific quirks.
While Large Language Models (LLMs) have shown promise in code generation, current LLM-based kernel optimizers often fail due to three major issues:
- Local Optima: Linear refinement processes often forget past failures and get stuck in narrow performance basins.
- Role Conflict: A single agent struggles to balance the creativity needed for strategy brainstorming with the strict precision required for valid C++ code.
- The Planning-Implementation Gap: High-level optimization ideas (e.g., "apply shared-memory tiling") often fail to translate into valid low-level CUDA code.
The STARK Framework: A Multi-Agent Approach
To address these challenges, STARK (Strategic Team of Agents for Refining Kernels) introduces four key innovations:
- Multi-Agent Design (MAD): STARK splits the workload into three specialized roles. A Plan agent (high temperature, $\tau=0.8$) creatively brainstorms strategies. A Code agent and a Debug agent (low temperature, $\tau=0.1$) ensure precise implementation and repair.
- Strategic Search with Tree Memory: Instead of linear trial-and-error, STARK maintains a search tree of all past attempts. It uses an adapted $\epsilon$-greedy policy to balance exploitation of fast kernels with exploration of new branches, utilizing domain-specific heuristics like "root throttling" to manage compute.
- Grounded Instruction: The Plan agent inserts explicit, machine-checkable anchors (e.g.,
<<<IMPROVE BEGIN>>>) directly into the source code, guiding the Code agent on exactly where to apply optimizations. - Dynamic Context Windows: STARK curates agent-specific histories. The Plan agent sees global top performers, while the Code agent sees "cousin" nodes to learn successful micro-optimizations and avoid repeating syntax errors.
Experimental Setup: KernelBench
The framework was evaluated on KernelBench, a benchmark designed for LLM-based GPU kernel optimization across three difficulty levels:
- Level 1: Common operators (e.g., matmul, convolution).
- Level 2: Fused operators with complex dataflows.
- Level 3: Full ML architectures (e.g., ResNet, LSTM) with irregular computations.
Performance and Results
STARK achieved a 100% success rate in generating compiled, functionally correct kernels across all levels, whereas baselines like Sampling and Reflexion dropped to 15-28% on Level 3 tasks.
In terms of performance, STARK consistently outperformed existing methods and standard compilers. It achieved up to a 16x runtime speedup over the Reflexion baseline on Level 2 tasks and 10.7x over the Sampling baseline on Level 1. Furthermore, STARK outperformed torch.compile (max-autotune), achieving up to 3.03x speedups over Torch Eager on Level 1 operators.
Conclusion and Future Work
STARK demonstrates that role specialization and structured search are essential for complex code optimization tasks. While the Code agent's reliability remains a bottleneck, future work involving agent-specific post-training and expansion to broader hardware architectures promises even greater gains in automated kernel engineering.
Summary updated