Abstract
The "CUDA Moat" remains a formidable barrier in high-performance computing (HPC), hindering the portability of NVIDIA-optimized code to alternative architectures. This paper presents HPCTransCompile, a framework that leverages the TVM AI compiler to automatically generate a dataset of 20,000 high-performance CUDA-to-CPU code pairs. By fine-tuning Large Language Models (LLMs) on this synthetic data, we achieve an average performance boost of 43.8% in transpiled code. Our findings demonstrate that LLMs, when trained on compiler-verified expert data, can effectively bridge the performance gap between disparate hardware paradigms, transforming them from simple translators into hardware-aware optimizers.
Introduction
Porting CUDA code to CPUs or non-NVIDIA GPUs typically involves a trade-off between manual effort and execution efficiency. Existing source-to-source compilers often produce suboptimal code that fails to exploit target hardware features like cache hierarchies or vector units. While LLMs have shown potential in general programming, their performance in specialized HPC transpilation is limited by a lack of high-quality, paired training data. HPCTransCompile addresses this scarcity by using an AI compiler as a "data factory" to produce clean, optimized, and verified code pairs.
Methodology
The HPCTransCompile pipeline automates the entire lifecycle of dataset creation and model evaluation.
The process begins with Automated Code Generation, where TVM’s auto-scheduler (Ansor) identifies the most efficient implementations for various mathematical operators. To ensure the dataset reflects real-world complexity, we employ Graph-Based Augmentation to fuse individual operators into multi-stage kernels. A critical step is Useless Dependency Removal, which strips compiler-specific boilerplate to yield portable C code. Finally, Hardware-Aware Labeling annotates the data with optimization strategies like loop unrolling and vectorization, teaching the LLM the rationale behind high-performance implementations.
Datasets and Benchmarking
We introduce two primary resources:
- HPCTransData: A training set comprising 20,000 high-performance CUDA/CPU code pairs.
- HPCTransEval: A benchmark suite containing 100 standalone operators, 100 computation graphs, and 10 deep learning building blocks.
Generalization is further tested using KernelBench_c, which includes manually implemented CUDA versions of 250 neural network tasks to evaluate how well models handle PyTorch-style operations.
Results and Discussion
Fine-tuning models such as Qwen2.5-Coder-14B and DeepSeek-Coder-V2-Lite on HPCTransData yielded significant improvements in both code correctness and execution speed.
As shown in the performance analysis, fine-tuned models consistently outperformed their base versions, often exceeding the performance of standard PyTorch implementations. For instance, the fine-tuned Qwen model achieved a 132.8% improvement in speedup ratio for basic operations. Qualitatively, the models transitioned from naive translations to hardware-specific optimizations, such as replacing CUDA-style shared memory patterns with cache-friendly nested loops on the CPU. Beyond raw speed, the "Compile Pass" and "Execute Pass" rates also saw double-digit increases, indicating higher syntactic and logical reliability.
Conclusion
HPCTransCompile proves that synthetic data generated by expert systems can overcome the data scarcity in specialized domains like HPC. By providing LLMs with high-quality, hardware-optimized examples, we can significantly enhance their ability to perform complex code transpilation tasks. Future research will focus on expanding the framework to support AMD and Intel accelerators and increasing the diversity of the kernel library to include more niche HPC operations.
Summary updated