用领域语言引导生成华为NPU高效核函数,正确率超90%
AscendCraft: Automatic Ascend NPU Kernel Generation via DSL-Guided Transcompilation
- 通过轻量领域语言抽象复杂性,分步生成并转译核函数
- 在七类算子上达98.1%编译成功率、90.4%功能正确率
- 适合想快速部署NPU优化算子的开发者和研究者
深度学习模型性能高度依赖高效核函数实现,但为专用加速器开发高性能核函数仍耗时且需专业知识。尽管大语言模型(LLMs)可生成正确高效的GPU核函数,但由于领域特有编程模型、公开案例少及文档稀疏,针对神经处理单元(NPUs)的核函数生成仍不充分。直接用LLMs生成AscendC核函数正确率极低,凸显了GPU与NPU核生成间的巨大差距。本文提出AscendCraft,一种基于领域语言(DSL)引导的自动AscendC核函数生成方法。AscendCraft引入轻量级DSL,抽象非必要复杂性,显式建模Ascend特定执行语义。核函数先在DSL中生成,利用类别特异专家样本,再通过结构化、约束驱动的LLM降阶步骤转译为AscendC。在MultiKernelBench上对七类算子评估,AscendCraft实现98.1%编译成功率和90.4%功能正确率。此外,46.2%的生成核函数达到或超过PyTorch eager执行性能,证明DSL引导转译可使LLMs生成既正确又具备竞争力的NPU核函数。除基准测试外,AscendCraft还成功生成两个新提出的mHC架构的正确核函数,性能显著优于PyTorch eager执行。
原文摘要 · Abstract (English)
The performance of deep learning models critically depends on efficient kernel implementations, yet developing high-performance kernels for specialized accelerators remains time-consuming and expertise-intensive. While recent work demonstrates that large language models (LLMs) can generate correct and performant GPU kernels, kernel generation for neural processing units (NPUs) remains largely underexplored due to domain-specific programming models, limited public examples, and sparse documentation. Consequently, directly generating AscendC kernels with LLMs yields extremely low correctness, highlighting a substantial gap between GPU and NPU kernel generation. We present AscendCraft, a DSL-guided approach for automatic AscendC kernel generation. AscendCraft introduces a lightweight DSL that abstracts non-essential complexity while explicitly modeling Ascend-specific execution semantics. Kernels are first generated in the DSL using category-specific expert examples and then transcompiled into AscendC through structured, constraint-driven LLM lowering passes. Evaluated on MultiKernelBench across seven operator categories, AscendCraft achieves 98.1% compilation success and 90.4% functional correctness. Moreover, 46.2% of generated kernels match or exceed PyTorch eager execution performance, demonstrating that DSL-guided transcompilation can enable LLMs to generate both correct and competitive NPU kernels. Beyond benchmarks, AscendCraft further demonstrates its generality by successfully generating two correct kernels for newly proposed mHC architecture, achieving performance that substantially surpasses PyTorch eager execution.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。