AscendKernelGen: A Systematic Study of LLM-Based Kernel Generation for Neural Processing Units

Xinzi Cao, Jianyang Zhai, Pengfei Li, Zhiheng Hu, Yan Cen, Bingxu Mu, Guo Hua Fang, Bin She, Jiayu Li, Yihan Su, Dongyang Tao, Xiansong Huang, Fan Xu, Feidiao Yang, Yao Lu, Chang‐Dong Wang, Yutong Lu, Weicheng Xue, Bin Zhou, Yonghong Tian

Abstract

To meet the ever-increasing demand for computational efficiency, Neural Processing Units (NPUs) have become critical in modern AI infrastructure. However, unlocking their full potential requires developing high-performance compute kernels using vendor-specific Domain-Specific Languages (DSLs), a task that demands deep hardware expertise and is labor-intensive. While Large Language Models (LLMs) have shown promise in general code generation, they struggle with the strict constraints and scarcity of training data in the NPU domain. Our preliminary study reveals that state-of-the-art general-purpose LLMs fail to generate functional complex kernels for Ascend NPUs, yielding a near-zero success rate. To address these challenges, we propose AscendKernelGen, a generation-evaluation integrated framework for NPU kernel development. We introduce Ascend-CoT, a high-quality dataset incorporating chain-of-thought reasoning derived from real-world kernel implementations, and KernelGen-LM, a domain-adaptive model trained via supervised fine-tuning and reinforcement learning with execution feedback. Furthermore, we design NPUKernelBench, a comprehensive benchmark for assessing compilation, correctness, and performance across varying complexity levels. Experimental results demonstrate that our approach significantly bridges the gap between general LLMs and hardware-specific coding. Specifically, the compilation success rate on complex Level-2 kernels improves from 0% to 95.5% (Pass@10), while functional correctness achieves 64.3% compared to the baseline's complete failure. These results highlight the critical role of domain-specific reasoning and rigorous evaluation in automating accelerator-aware code generation.

Introduction

To keep up with the massive computational demands of modern AI, the industry relies heavily on specialized hardware accelerators like Neural Processing Units (NPUs)—such as Huawei’s Ascend platform. However, to get maximum performance out of an NPU, engineers must write "compute kernels" using highly specialized Domain-Specific Languages (DSLs) like AscendC.

Writing this code is a significant challenge, requiring deep expertise in hardware architecture, manual memory management, and asynchronous pipeline programming. While researchers aim to use Large Language Models (LLMs) to automate this, state-of-the-art models have almost zero exposure to these proprietary DSLs in their training data. When asked to write AscendC kernels, general-purpose LLMs hallucinate APIs and fail to understand hardware constraints, resulting in a near 0% success rate for anything beyond trivial math operations.

Baseline performance of general-purpose LLMs on NPU kernel tasks, showing near-zero success rates for complex operations.

Methodology: The AscendKernelGen Framework

To bridge the gap between general LLMs and hardware-specific coding, we developed AscendKernelGen, an end-to-end framework featuring a custom Chain-of-Thought (CoT) dataset and a specialized training pipeline. The approach relies on three main pillars:

  1. Domain-Specific Reasoning Data: Instead of just scraping code, we built the Ascend-CoT dataset that explicitly models expert reasoning. It converts official documentation and real-world code into structured prompts explaining memory tiling, pipeline orchestration, and API constraints.
  2. Two-Stage Domain-Adaptive Training:
    • Error-Derived Supervised Fine-Tuning (SFT): We fine-tuned a base model (Qwen3-32B) on correcting real compilation and numerical errors, teaching it to avoid common API misuses.
  3. Execution-Guided Reinforcement Learning (RL): Using Direct Preference Optimization (DPO), we refined the model by rewarding code that compiles and executes correctly on actual hardware.
  4. Hardware-Grounded Evaluation: We designed NPUKernelBench, an automated pipeline to compile, run, and benchmark generated code directly on NPU hardware.
The two-stage AscendKernelGen pipeline, illustrating data construction and domain-adaptive training for NPU kernels.

Key Insights and Results

Our study reveals that syntax is rarely the bottleneck; rather, the failure of general LLMs stems from an inability to reason about hardware constraints like manual memory tiling. Explicit CoT reasoning is mandatory for success in this domain. Furthermore, we found that full fine-tuning significantly outperforms parameter-efficient methods like LoRA for hardware-aware generation.

Experimental Performance

  • Massive Correctness Jump: On Level-2 (medium complexity) kernels, where baseline models achieved 0%, our pipeline reached a 95.5% compilation rate and a 64.3% execution correctness rate (Pass@10).
  • Performance Speedups: The generated kernels achieved an average 1.86x speedup compared to expert-written vendor baselines on Level-2 tasks.
  • Error Reduction: Purely syntactic errors dropped to just 3.7% of failures, shifting the remaining challenges to highly complex API signature mismatches.

Conclusion and Future Work

While AscendKernelGen successfully conquers Level 1 and 2 tasks, Level 3 kernels (e.g., Matrix Multiplication with complex control flow) remain a hurdle, with only a 1.67% success rate. Future work will focus on these complex global dependencies and integrating performance-aware reward models into the RL stage to maximize hardware utilization. We also aim to generalize this framework to other emerging AI accelerators beyond the Ascend platform.

Summary updated

BibTeX
@misc{cao2026ascendkernelgen,
  author = {Xinzi Cao and Jianyang Zhai and Pengfei Li and Zhiheng Hu and Yan Cen and Bingxu Mu and Guo Hua Fang and Bin She and Jiayu Li and Yihan Su and Dongyang Tao and Xiansong Huang and Fan Xu and Feidiao Yang and Yao Lu and Chang‐Dong Wang and Yutong Lu and Weicheng Xue and Bin Zhou and Yonghong Tian},
  title = {{AscendKernelGen: A Systematic Study of LLM-Based Kernel Generation for Neural Processing Units}},
  year = {2026},
  eprint = {2601.07160},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2601.07160},
}
Figure