CUDA-Harness: Harnessing Agentic CUDA Kernel Generation and Optimization from Natural Language
CUDA-Harness: Harnessing Agentic CUDA Kernel Generation and Optimization from Natural Language
CUDA-Harness:利用自然语言实现代理式 CUDA 内核生成与优化
Developing high-performance CUDA kernels demands specialized knowledge in algorithm implementation, correctness validation, and hardware-aware parallel optimization, creating a substantial expertise barrier and making generating CUDA kernels directly from natural language (Text2CUDA) essential.
开发高性能 CUDA 内核需要算法实现、正确性验证以及硬件感知并行优化方面的专业知识,这构成了巨大的专业门槛,使得直接从自然语言生成 CUDA 内核(Text2CUDA)变得至关重要。
Meanwhile, the general-purpose code generation capability of Large Language Models (LLMs) prompts a series of works exploring LLM-based CUDA kernel generation. They mainly focus on transpilation from high-level frameworks such as PyTorch to CUDA (Torch2CUDA) rather than Text2CUDA, where models must understand the high-level input semantics and handle low-level kernel implementation and validation.
与此同时,大语言模型(LLM)的通用代码生成能力促使了一系列探索基于 LLM 的 CUDA 内核生成的研究。这些研究主要集中在从 PyTorch 等高级框架到 CUDA 的转译(Torch2CUDA),而非 Text2CUDA;在 Text2CUDA 中,模型必须理解高级输入语义,并处理底层的内核实现与验证。
Additionally, these methods are vulnerable to reward hacking due to reliance on predefined test inputs. In this paper, we propose CUDA-Harness, a framework for harnessing agentic CUDA kernel generation and optimization from natural language.
此外,由于依赖预定义的测试输入,这些方法容易受到奖励欺骗(reward hacking)的影响。在本文中,我们提出了 CUDA-Harness,这是一个用于利用自然语言进行代理式 CUDA 内核生成与优化的框架。
Specifically, we introduce Intermediate-Structured Generation to connect high-level semantic understanding with low-level kernel generation. To dilute reward hacking in Text2CUDA, we construct Synthesis-Based Verification to provide isolated test data and progressive validation.
具体而言,我们引入了“中间结构化生成”(Intermediate-Structured Generation)来连接高级语义理解与底层内核生成。为了削弱 Text2CUDA 中的奖励欺骗,我们构建了“基于合成的验证”(Synthesis-Based Verification),以提供隔离的测试数据和渐进式验证。
Furthermore, we propose Feedback-Adaptive Evolution, a kernel evolution strategy that prioritizes correctness while optimizing performance. Finally, through extensive experiments, we demonstrate the effectiveness of CUDA-Harness, with further evaluations illustrating generalization across LLMs, hardware platforms, and to C-to-CUDA transpilation.
此外,我们提出了“反馈自适应演化”(Feedback-Adaptive Evolution),这是一种在优化性能的同时优先考虑正确性的内核演化策略。最后,通过广泛的实验,我们证明了 CUDA-Harness 的有效性,进一步的评估展示了其在不同 LLM、硬件平台以及 C 转 CUDA 转译任务中的泛化能力。