Improving HPC Code Generation Capability of LLMs via Online Reinforcement Learning with Real-Machine Benchmark Rewards
Ryo Mikasa, Shun-ichiro Hayashi, Daichi Mukunoki, Tetsuya Hoshino, Takahiro Katagiri
TL;DR
The paper tackles the challenge of translating LLM-generated code into high-performance HPC kernels by using online reinforcement learning with real-device rewards. It combines GRPO with a Staged Quality-Diversity strategy to explore diverse optimization pathways under constraint, enabling the model to learn performance-oriented code as it interacts with actual hardware. Across two experiments on a GEMM kernel with a 256^3 problem size, the approach yields significant gains over baseline prompts, including a peak of around 549 GFLOPS, and reveals that guidance via staged constraints can stabilize learning and reveal robust optimization patterns. The work demonstrates a viable path toward performance-aware code generation in realistic HPC environments and points to future work on generalization, broader kernels, and cross-architecture portability.
Abstract
Large language models (LLMs) have demonstrated strong code generation capabilities, yet the runtime performance of generated code is not guaranteed, and there have been few attempts to train LLMs using runtime performance as a reward in the HPC domain. We propose an online reinforcement learning approach that executes LLM-generated code on a supercomputer and directly feeds back the measured runtime performance (GFLOPS) as a reward. We further introduce a Staged Quality-Diversity (SQD) algorithm that progressively varies the permitted optimization techniques on a per-problem basis, enabling the model to learn code optimization from diverse perspectives. We build a distributed system connecting a GPU training cluster with a CPU benchmarking cluster, and train Qwen2.5 Coder 14B on a double-precision matrix multiplication task using Group Relative Policy Optimization (GRPO). Through two experiments, we show that reinforcement learning combining runtime performance feedback with staged optimization can improve the HPC code generation capability of LLMs.
