LLM能自动生成高效CUDA代码,速度比人工写快179倍
CUDA-LLM: LLMs Can Write Efficient CUDA Kernels
- 用强化学习优化LLM生成的CUDA代码,兼顾正确性和性能
- 在目标GPU上实测,生成代码最快达人工代码179倍加速
- 适合需要高性能GPU编程的开发者和自动化工具研究者
大语言模型在通用代码生成方面表现强劲,但在生成高度依赖硬件、架构感知且性能关键的代码(尤其是大规模并行GPU)方面仍面临挑战。本文探索利用LLM自动生成与优化CUDA程序,目标是生成能充分挖掘硬件潜力的高性能GPU内核。为此提出新框架FSR(特征搜索与强化),联合优化编译正确性、功能正确性与运行时性能,通过大量多样测试用例验证,并以目标GPU上的实际内核执行延迟为指标。该方法使LLM不仅能生成语法语义正确的CUDA代码,还能迭代优化效率,适配特定GPU架构。在典型CUDA内核(涵盖AI任务与计算密集型算法)上评估,结果显示增强后的LLM始终保证高正确率,且自动生成内核执行速度最高可达人工通用代码的179倍。这表明结合LLM与性能强化可有效实现面向硬件特性的高性能编程自动化。
原文摘要 · Abstract (English)
Large Language Models (LLMs) have demonstrated strong capabilities in general-purpose code generation. However, generating the code which is deeply hardware-specific, architecture-aware, and performance-critical, especially for massively parallel GPUs, remains a complex challenge. In this work, we explore the use of LLMs for the automated generation and optimization of CUDA programs, with the goal of producing high-performance GPU kernels that fully exploit the underlying hardware. To address this challenge, we propose a novel framework called \textbf{Feature Search and Reinforcement (FSR)}. FSR jointly optimizes compilation and functional correctness, as well as the runtime performance, which are validated through extensive and diverse test cases, and measured by actual kernel execution latency on the target GPU, respectively. This approach enables LLMs not only to generate syntactically and semantically correct CUDA code but also to iteratively refine it for efficiency, tailored to the characteristics of the GPU architecture. We evaluate FSR on representative CUDA kernels, covering AI workloads and computational intensive algorithms. Our results show that LLMs augmented with FSR consistently guarantee correctness rates. Meanwhile, the automatically generated kernels can outperform general human-written code by a factor of up to 179$\times$ in execution speeds. These findings highlight the potential of combining LLMs with performance reinforcement to automate GPU programming for hardware-specific, architecture-sensitive, and performance-critical applications.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。