CUDA-L2: Surpassing cuBLAS Performance for Matrix Multiplication through Reinforcement Learning
该论文提出了一种名为CUDA-L2的系统,通过结合大型语言模型和强化学习来自动优化矩阵乘法CUDA内核,显著超越了现有的优化方案,如cuBLAS。
更新于 2025-12-03。作者:Songqiao Su、Xiaofei Sun、Xiaoya Li、Albert Wang、Jiwei Li、Chris Shum。
中文摘要
在这篇论文中,我们提出了CUDA-L2系统,该系统结合了大型语言模型(LLMs)和强化学习(RL)来自动优化半精度通用矩阵乘法(HGEMM)CUDA内核。以CUDA执行速度作为RL奖励,CUDA-L2可以自动优化跨越1,000种配置的HGEMM内核。CUDA-L2系统性地超越了迄今为止的多数矩阵乘法基线,从广泛使用的{\it torch.matmul}到最先进的Nvidia闭源库,即{\it cuBLAS},{\it cuBLASLt}。在离线模式下,内核连续执行而不设时间间隔,CUDA-L2的平均性能比{\it torch.matmul}提升了+22.0\%;使用最佳布局配置(正常-正常NN和转置-正常TN)比{\it cuBLAS}提升了+19.2\%;比{\it cuBLASLt-heuristic}(该模式查询{\it cuBLASLt}库并根据启发式建议选择算法)提升了+16.8\%;比最具竞争力的{\it cuBLASLt-AutoTuning}模型(从{\it cuBLASLt}的建议中选择最快的算法,最多从100个候选算法中挑选)提升了+11.4\%。在服务器模式下,内核以随机间隔执行,模拟实时推理,速度提升进一步增加到分别为{\it torch.matmul}+28.7\%,{\it cuBLAS}+26.0\%,{\it cuBLASLt-heuristic}+22.4\%,{\it cuBLASLt-AutoTuning}+15.9\%。CUDA-L2表明,即使是性能关键、高度优化的内核如HGEMM,也可以通过LLM引导的RL自动化来提升,通过系统地探索对人类来说不切实际的范围的配置空间。项目和代码可在github.com/deepreinforce-ai/CUDA-L2找到。
英文摘要
In this paper, we propose CUDA-L2, a system that combines large language models (LLMs) and reinforcement learning (RL) to automatically optimize Half-precision General Matrix Multiply (HGEMM) CUDA kernels. Using CUDA execution speed as the RL reward, CUDA-L2 automatically optimizes HGEMM kernels across 1,000 configurations. CUDA-L2 systematically outperforms major matmul baselines to date, from the widely-used {\it torch.matmul} to state-of-the-art Nvidia's closed-source libraries, i.e., {\it cuBLAS}, {\it cuBLASLt}. In offline mode, where kernels are executed consecutively without time intervals, CUDA-L2 yields +22.0\% over {\it torch.matmul} on average; +19.2\% over {\it cuBLAS} using the optimal layout configuration (normal-normal NN and transposed-normal TN); +16.8\% over {\it cuBLASLt-heuristic}, which queries {\it cuBLASLt} library and selects the algorithm based on the heuristic's suggestion; and +11.4\% over the most competitive {\it cuBLASLt-AutoTuning} model, which selects the fastest algorithm from up to 100 candidates from {\it cuBLASLt}'s suggestions. In server mode, where kernels are executed at random intervals simulating real-time inference, the speedups further increase to +28.7\%, +26.0\%, +22.4\%, and +15.9\% for {\it torch.matmul}, {\it cuBLAS}, {\it cuBLASLt-heuristic}, and {\it cuBLASLt-AutoTuning} respectively. CUDA-L2 shows that even the most performance-critical, heavily-optimized kernels like HGEMM can be improved through LLM-guided RL automation by systematically exploring configuration spaces at scales impractical for humans. Project and code can be found at github.com/deepreinforce-ai/CUDA-L2
解读
一句话总结
该论文提出了一种名为CUDA-L2的系统,通过结合大型语言模型和强化学习来自动优化矩阵乘法CUDA内核,显著超越了现有的优化方案,如cuBLAS。
问题1:这篇论文想要解决什么具体问题?
- 问题背景:矩阵乘法是深度学习和LLM中最重要的操作之一,但手动优化不同尺寸矩阵的CUDA内核非常困难,因为不同的矩阵维度需要不同的优化策略,而且优化策略很少能在不同的GPU架构之间转换。
- 现有方案不足:现有的优化方法如torch.matmul和cuBLAS等,要么依赖于默认设置,要么需要大量的人工调整,无法满足大规模自动优化的需求。
- 研究目标:开发一个系统,能够自动优化矩阵乘法CUDA内核,并在不同的GPU架构和矩阵尺寸上实现性能提升。
问题2:论文的核心创新点是什么?
- 技术创新:结合了大型语言模型(LLM)和强化学习(RL)来自动优化CUDA内核。
- 方法改进:通过多阶段的RL训练,从通用内核优化到特定于矩阵乘法的优化,并利用检索增强的上下文来适应新的知识和架构特性。
- 优势:实现了比现有方法更高的性能,特别是在A100 GPU上,比cuBLASLt-AutoTuning提高了15.9%。
问题3:实验结果如何验证了方法的有效性?
- 关键实验:在1000种不同的配置下,CUDA-L2的性能与torch.matmul、cuBLAS、cuBLASLt-heuristic和cuBLASLt-AutoTuning进行了比较。
- 性能提升:在离线模式下,CUDA-L2的平均速度比torch.matmul快22.0%,比cuBLAS快19.2%,比cuBLASLt-heuristic快16.8%,比cuBLASLt-AutoTuning快11.4%。
- 对比结果:CUDA-L2在服务器模式下(模拟实时推理)的速度提升进一步增加。
问题4:这个研究的实际应用价值是什么?
- 应用场景:适用于需要高性能矩阵乘法的深度学习和LLM应用。
- 实施建议:将CUDA-L2扩展到其他GPU架构,如Ada Lovelace、Hopper和Blackwell。
- 局限与展望:当前的版本仅限于A100 GPU,未来将扩展到其他架构,并进一步提高性能。