TL;DR
CodegenBench is a new benchmark designed to test if Large Language Models (LLMs) can generate not just correct, but efficient parallel code for diverse CPU architectures like x86_64, Sunway, and Kunpeng. The study reveals that while LLMs excel at ubiquitous architectures like x86, they suffer significant performance hits and frequently "hallucinate" specialized hardware instructions when tasked with domain-specific supercomputing platforms.
What Problem Does This Paper Address?
Most LLM code generation benchmarks focus on functional correctness in high-level languages (like Python) or mainstream GPU environments (like CUDA). However, in the world of High-Performance Computing (HPC), code must be meticulously tuned for specific CPU architectures to be useful.
The authors identify a "performance gap" where LLMs might produce code that runs, but fails to leverage architectural features like vector extensions or specialized memory hierarchies. This is particularly difficult for non-mainstream architectures like Sunway (used in the TaihuLight supercomputer) and Kunpeng (ARM-based HPC), where training data is scarce compared to the mountain of x86 code available on GitHub.
Methods
The researchers developed an automated evaluation framework that handles the entire lifecycle of code generation and testing:
- Data Pre-processing: Extracting function signatures and context from raw HPC code.
- Prompt Generation: Providing the LLM with a "Target Kernel" (the signature), "Context/Reference" (a naive implementation), and an "Architecture Prompt" (specific optimization instructions).
- Automated Build & Run: The framework compiles the generated code using platform-specific compilers (like
swgccfor Sunway) and runs it against a test harness. - Metric Scoring: Beyond standard correctness (Pass@k), they introduce Fast1@1, which measures the percentage of correct generations that actually achieve a speedup over the naive baseline.
Datasets
The authors introduced CodegenBench, which consists of:
- BLAS (106 routines): A baseline of standard Basic Linear Algebra Subprograms across three levels of complexity (vector, matrix-vector, and matrix-matrix operations).
- LeetSunway (20 kernels): Specialized computational kernels tailored for the unique master-slave core paradigm of the Sunway SW26010 processor.
- LeetKunpeng (20 kernels): The same 20 kernels but targeting Kunpeng’s ARM-based features like Scalable Vector Extensions (SVE).
Key Insights and Ideas
- The Data Scarcity Wall: LLM performance drops off a cliff when moving from x86 to Sunway. This isn't just because the tasks are harder, but because the models haven't seen enough proprietary or domain-specific code to "understand" the hardware.
- Complexity vs. Efficiency: Interestingly, while complex tasks (like matrix-matrix multiplication) are harder for LLMs to get correct, they are actually easier to optimize. Level 1 BLAS routines are often memory-bound, leaving little room for algorithmic cleverness, whereas Level 3 routines allow LLMs to shine by implementing cache blocking and vectorization.
- Syntactic Hallucinations: When pushed to use specialized hardware intrinsics (like ARM SVE), models often "hallucinate" API calls—generating code that looks syntactically plausible but calls functions that don't exist in the actual hardware libraries.
- Token Efficiency: The Claude series (specifically Opus 4.7) proved to be the most "concise" optimizer, requiring significantly fewer tokens to produce correct, high-performance results compared to open-source competitors like DeepSeek or Qwen.
Key Results
The evaluation of 9 state-of-the-art LLMs showed a clear hierarchy:
- x86 Dominance: On x86 BLAS tasks, Claude Opus 4.7 led the pack with a Pass@1 of 0.74. DeepSeek V4 Pro was the strongest open-source contender at 0.53.
- The Sunway Slump: On the specialized LeetSunway benchmark, Pass@1 rates plummeted. Most open-source models scored 0.00, while Claude Opus 4.7 managed 0.48.
- Speedup Success: When models did manage to produce correct code for Kunpeng and Sunway, the speedups were often massive (e.g., 1.6x for attention kernels) because the baseline was unoptimized CPU code.
Limitations and Future Work
The authors acknowledge that 20 kernels per specialized architecture is a relatively small sample size that may not capture the full breadth of HPC workloads. Furthermore, the benchmark currently omits other significant architectures like SPARC or PowerPC.
Future work will focus on expanding the dataset and exploring how to improve LLM performance on data-scarce architectures, perhaps through better retrieval-augmented generation (RAG) or fine-tuning on architectural documentation.
Summary updated