Making LLMs Optimize Multi-Scenario CUDA Kernels Like Experts
Organizations: Tsinghua University · Proxseer Inc.
Abstract
Optimizing GPU kernels manually is a challenging and time-consuming task. With the rapid development of LLMs, automated GPU kernel optimization is gradually becoming a tangible reality. However, current LLM-driven automated optimization methods narrowly focus on machine learning applications, such as PyTorch operator optimization, while overlooking broader domains like sparse matrix operations in scientific computing. Extending to these broader applications brings new challenges for the benchmark and algorithm. Therefore, developing a general-purpose automated kernel optimization method becomes our primary focus. In this paper, we address the absence of systematic evaluation for multi-scenario settings by introducing MSKernelBench, which spans multiple scenarios, including fundamental algebraic operations, common LLM kernels, sparse matrix operators, and scientific computing routines, each supporting both FP32 and BF16 precision. Building on this benchmark, we introduce CUDAMaster, a multi-agent, hardware-aware system for kernel optimization that leverages profiling information and automatically constructs the full compilation and execution toolchain. Experimental results demonstrate that CUDAMaster achieves significant speedups across most operators, outperforming Astra by about 35%. In several cases, its performance matches or surpasses that of highly optimized, closed-source libraries such as cuBLAS. A demo showcasing the original and optimized code for each operator is available at https://hanyx2021.github.io/MSKernelBenchDemo/.
Figures & tables
| Bottleneck Type | Classification Rule | Filtered Metrics |
| Compute Bound | Compute.Th > 30% | Compute (SM) Throughput, Issue Slots Busy, Executed Ipc Active, SM Busy |
| Memory Latency Bound | Compute.Th < 30%, DRAM.Th < 30% and Memory.Th < 30 % | L2 Hit Rate, L1/TEX Hit Rate, Executed Ipc Elapsed, Mem Busy |
| Memory Bandwidth Bound | Compute.Th < 30%, DRAM.Th > 30% or Memory.Th > 30 % | DRAM Throughput, Memory Throughput, Max Bandwidth, Mem Pipes Busy |
| Model | parameters | ||||
| Full | N.D. | S.I. | S.R. | ||
| OpenAI o4-mini | 0 | 100% | 90% | 96% | 90% |
| 1 | 94% | 77% | 74% | 77% | |
| 2 | 60% | 50% | 46% | 50% | |
| 4 | 47% | 35% | 35% | 35% | |
| 8 | 25% | 19% | 17% | 19% | |
| Model | Profile Pattern | |||
| Filtered | No Prof. | Full Prof. | ||
| OpenAI o4-mini | 0 | 100% | 99% | 100% |
| 1 | 94% | 90% | 94% | |
| 2 | 60% | 56% | 62% | |
| 4 | 47% | 43% | 47% | |
| 8 | 25% | 22% | 25% | |
| Configuration | Average Cost | Average Tokens |
| OpenAI o4-mini | ||
| Filtered Profile | $0.2707 | 123,036 |
| No Profile | $0.2120 | 96,373 |
| Full Profile | $0.3804 | 172,917 |
| DeepSeek-V3.2 | ||
| Filtered Profile | $0.0310 | 223,294 |
Appendix figures & tables6 assets
Supplementary material from the paper’s appendix.
Appendix
| Profiling Section | Analysis Focus | Filtered Key Metrics |
| Compute Workload Analysis | Computational Efficiency | Executed Ipc Active, Executed Ipc Elapsed, Issue Slots Busy, Issued Ipc Active, SM Busy |
| GPU Speed Of Light | Throughput & Utilization | Compute (SM) Throughput, DRAM Throughput, Duration, Memory Throughput |
| Memory Workload Analysis | Memory Subsystem | L1/TEX Cache Throughput, L1/TEX Hit Rate, L2 Cache Throughput, L2 Hit Rate, Max Bandwidth, Mem Busy, Mem Pipes Busy |
| Occupancy | Hardware Resource Usage | Achieved Active Warps Per SM, Achieved Occupancy |
| Scheduler Statistics | Instruction Scheduler | Active Warps Per Scheduler, Eligible Warps Per Scheduler, Issued Warp Per Scheduler, No Eligible, One or More Eligible |
| Warp State Statistics | Warp Execution | Warp Cycles Per Executed Instruction, Warp Cycles Per Issued Instruction |
| ID | Task Type | Task Name | Prompt for Task Description | Input Data Size & Complexity |
|---|---|---|---|---|
| 1 | Dense Linear Algebra | Dot Product | For two vectors and , both of length , compute their dot product : | |
| 2 | Dense Linear Algebra | Vector Add | Add two vectors and of length into vector . | |
| 3 | Dense Linear Algebra | Square Matrix Mul | Given two square matrices and with size , calculate the result of matrix multiplication and write it into matrix . | |
| 4 | Dense Linear Algebra | Matrix Scalar Mul | Given a matrix and a scalar , calculate the result of matrix and scalar multiplication and write it into matrix , where matrix has a shape of . | |
| 5 | Dense Linear Algebra | Matrix Mul | Given two matrices and , calculate the result of matrix multiplication and write it into matrix , where matrix has a shape of , matrix has a shape of , and matrix has a shape of . | |
| 6 | Dense Linear Algebra | Matrix Power | Given a square matrix with size , calculate matrix power of . |