Integrating Performance Tools in Model Reasoning for GPU Kernel Optimization

Daniel Nichols, Konstantinos Parasyris, Charles F. Jekel, Abhinav Bhatele, Harshitha MenonarXiv 2025 · DOI

Abstract

Optimizing GPU kernels requires a deep understanding of hardware-specific factors like memory access patterns and register pressure. While Large Language Models (LLMs) excel at functional code generation, they often lack the "dynamic feedback" necessary for performance tuning. We introduce opt-r1, a reasoning-capable model that utilizes a custom toolset—including compilers and profilers—to iteratively optimize GPU code. By employing Group Relative Policy Optimization (GRPO), the model learns to hypothesize, test, and refine optimizations based on actual execution time. Our results on the RAJAPerf benchmark suite show significant performance gains, with the model achieving up to a 17% speedup on critical high-performance computing (HPC) kernels.

Introduction

The performance of a GPU kernel is frequently determined by "invisible" factors that are not apparent from the source code alone. Human engineers rely on a cycle of profiling and benchmarking to identify bottlenecks. Standard LLMs, being text-only, are forced to guess which optimizations might work, often leading to sub-optimal or even slower code. This research bridges the gap by providing LLMs with "hands-on" access to the hardware environment during their reasoning process.

Methodology

The core of our approach is the integration of a purpose-built toolset into the model's Chain-of-Thought (CoT) reasoning.

Tool-Integrated Reasoning

The model is equipped with tools such as benchmark_code for timing execution, compiler_analysis for inspecting register spills and occupancy, and file_viewer for context. This allows for an iterative optimization loop: Hypothesize → Edit → Compile → Measure → Iterate.

An example reasoning trace showing the model's iterative use of performance tools to refine a GPU kernel.

Reinforcement Learning and Distillation

We utilized Group Relative Policy Optimization (GRPO) to fine-tune a Llama-3-70B model. The reward function prioritizes both functional correctness and execution speedup over a baseline. To improve efficiency, the reasoning traces from the 70B model were distilled into an 8B variant (opt-r1-mini), which maintains robust optimization capabilities.

Experimental Evaluation

The models were trained on a combination of HeCBench kernels and 5,000 synthetic kernels generated by GPT-4o. Final evaluation was conducted on the RAJAPerf suite, representing real-world scientific applications.

Key Results

The opt-r1 models consistently outperformed the vanilla Llama-3 baseline. While the base model often produced code that was slower or failed to compile, opt-r1 achieved measurable speedups across Application, Algorithm, and PolyBench kernel categories.

Speedup comparison on RAJAPerf kernels, demonstrating that opt-r1 and its mini variant consistently outperform the baseline Llama-3 model.

In a specific case study on the Lulesh shock-hydrodynamics proxy application, the model optimized a critical kernel to achieve a 17% reduction in runtime, translating to a 3% overall application performance boost on NVIDIA H100 hardware.

Discussion and Conclusion

Ablation studies confirmed that the benchmark_code tool is the most critical component; without dynamic timing feedback, model performance degrades significantly. The model successfully learned high-impact strategies such as loop fusion and the use of __ldg for read-only caching.

Future work will address the latency of the reasoning chain and expand the model's scope to "agentic" refactoring of entire repositories, potentially unlocking even greater performance gains through global data layout optimizations.

Summary updated

BibTeX
@misc{nichols2025integrating,
  author = {Daniel Nichols and Konstantinos Parasyris and Charles F. Jekel and Abhinav Bhatele and Harshitha Menon},
  title = {{Integrating Performance Tools in Model Reasoning for GPU Kernel Optimization}},
  year = {2025},
  eprint = {2510.17158},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2510.17158},
}
Figure