TL;DR
This paper introduces MSKernelBench, a diverse benchmark for GPU kernel optimization that moves beyond standard deep learning operators to include sparse matrix and scientific computing tasks. To tackle these challenges, the authors developed CUDAMaster, a multi-agent system that uses hardware profiling data to guide LLMs, achieving a 35% performance boost over previous state-of-the-art methods and occasionally outperforming hand-tuned libraries like cuBLAS.
What Problem Does This Paper Address?
Optimizing CUDA kernels is a "black art" typically reserved for high-priced performance engineers. While Large Language Models (LLMs) have shown promise in automating code generation, existing benchmarks like KernelBench focus almost exclusively on common deep learning operators (like those found in PyTorch). These operators often have regular memory access patterns and highly public optimization paths, which might allow LLMs to succeed through simple "recall" rather than genuine reasoning.
Furthermore, real-world high-performance computing (HPC) involves irregular memory access and sparse data structures that existing automated tools struggle to optimize. There is a significant gap between generic LLM-generated code and the "speed of light" performance achieved by expert-tuned, closed-source libraries.
Methods
The authors propose a two-part solution: a rigorous benchmark and a profile-guided multi-agent framework.
1. MSKernelBench
A new benchmark consisting of 50 tasks across nine categories, including sparse linear algebra, stencil computations, and numerical methods. Unlike previous benchmarks, it evaluates performance across scalable data sizes and uses a complexity-weighted speedup metric to ensure that improvements on large, computationally expensive workloads are prioritized.
2. CUDAMaster
This is a multi-agent system designed to mimic the iterative workflow of a human expert. The system consists of four specialized agents:
- Planner Agent: Analyzes hardware profiles to propose high-level optimization strategies (e.g., tiling, loop unrolling).
- Coder Agent: Implements the strategies into executable CUDA code.
- Compiler Agent: Manages the build process and fine-tunes compiler flags.
- Debug Agent: Diagnoses and fixes functional errors or memory leaks.
The "secret sauce" is the Hardware Analysis Filter. Instead of overwhelming the LLM with thousands of raw metrics from NVIDIA Nsight Compute, CUDAMaster classifies the kernel's bottleneck (Compute-Bound, Memory Latency-Bound, or Memory Bandwidth-Bound) and provides the agents with only the 4–5 most relevant metrics for that specific bottleneck.
Datasets
The primary dataset is the newly introduced MSKernelBench, which curates 50 tasks from authoritative sources like the NVIDIA CUDA samples, cuBLAS, and cuSPARSE. The tasks are implemented in pure C/C++ to avoid framework overhead and support both FP32 and BF16 precisions.
Key Insights and Ideas
- Bottleneck-Awareness is Key: LLMs perform significantly better when they understand why a kernel is slow. By distilling complex profiling data into targeted insights (e.g., "L2 cache hit rate is low"), the Planner Agent can suggest specific architectural fixes like shared memory tiling.
- Beyond Deep Learning: The inclusion of sparse matrix operations (SpMV, SpMM) forces the system to handle irregular memory indices, a much harder task than optimizing dense matrix multiplication.
- Iterative Refinement: The study shows that a "Single Run" approach is far inferior to an iterative "Plan-Code-Debug" loop. Systematic debugging is indispensable for achieving functional correctness in complex GPU programming.
- Model Comparison: The authors found that OpenAI’s o4-mini consistently outperformed DeepSeek-V3.2 in generating successful optimizations, particularly at higher speedup thresholds.
Key Results
CUDAMaster demonstrates that LLMs can indeed rival human experts when given the right tools:
- General Speedup: It outperformed the previous state-of-the-art framework, Astra, by an average of 35%.
- Library Rivalry: In several cases, CUDAMaster generated kernels that matched or exceeded the performance of industry-standard libraries. For example, it achieved a 2.96x speedup on Sparse Matrix-Vector Multiplication (SpMV) compared to the naive baseline, surpassing cuSPARSE (2.23x).
- Efficiency: The filtered profiling approach reduced API costs by up to 32% and token usage by 30-40% compared to providing full, unfiltered hardware profiles, without sacrificing optimization quality.
Limitations and Future Work
While impressive, the authors note a few areas for growth:
- Hardware Specificity: The current results are primarily benchmarked on the NVIDIA RTX 4090. Performance characteristics might shift on different architectures (e.g., H100 or AMD GPUs).
- Kernel Fusion: The current tasks are largely individual operators. Future work could explore the automated optimization of long sequences of fused kernels, which presents even more complex synchronization challenges.
- Search Space: While the multi-agent system is effective, it still operates within a relatively bounded number of iterations (R=3). Exploring evolutionary strategies over longer durations might yield even higher "peak" performance.
Summary updated