Table of Contents
Fetching ...

Tutoring LLM into a Better CUDA Optimizer

Matyáš Brabec, Jiří Klepl, Michal Töpfer, Martin Kruliš

TL;DR

The paper investigates whether reasoning LLMs can generate optimized CUDA kernels for well known tasks and how tutoring prompts affect performance. Three CUDA assignments are used to evaluate code correctness, optimization strategies, and the impact of interactive tutoring. Results show that LLMs can produce correct CUDA kernels, but achieving high performance requires tutoring with detailed algorithmic prompts, especially for complex parallel patterns like inter thread communication in kNN. Interactive tutoring and autotuning considerations emerge as important for improving reliability and performance, and the work highlights the need for structured feedback loops when using LLMs for HPC kernel development.

Abstract

Recent leaps in large language models (LLMs) caused a revolution in programming tools (like GitHub Copilot) that can help with code generation, debugging, and even performance optimization. In this paper, we focus on the capabilities of the most recent reasoning models to generate optimized CUDA code for predefined, well-known tasks. Our objective is to determine which types of code optimizations and parallel patterns the LLMs can perform by themselves and whether they can be improved by tutoring (providing more detailed hints and guidelines in the prompt). The generated solutions were evaluated both automatically (for correctness and speedup) and manually (code reviews) to provide a more detailed perspective. We also tried an interactive approach where the LLM can fix its previous mistakes within a session. The results indicate that LLMs are quite skilled coders; however, they require tutoring to reach optimized solutions provided by parallel computing experts.

Tutoring LLM into a Better CUDA Optimizer

TL;DR

The paper investigates whether reasoning LLMs can generate optimized CUDA kernels for well known tasks and how tutoring prompts affect performance. Three CUDA assignments are used to evaluate code correctness, optimization strategies, and the impact of interactive tutoring. Results show that LLMs can produce correct CUDA kernels, but achieving high performance requires tutoring with detailed algorithmic prompts, especially for complex parallel patterns like inter thread communication in kNN. Interactive tutoring and autotuning considerations emerge as important for improving reliability and performance, and the work highlights the need for structured feedback loops when using LLMs for HPC kernel development.

Abstract

Recent leaps in large language models (LLMs) caused a revolution in programming tools (like GitHub Copilot) that can help with code generation, debugging, and even performance optimization. In this paper, we focus on the capabilities of the most recent reasoning models to generate optimized CUDA code for predefined, well-known tasks. Our objective is to determine which types of code optimizations and parallel patterns the LLMs can perform by themselves and whether they can be improved by tutoring (providing more detailed hints and guidelines in the prompt). The generated solutions were evaluated both automatically (for correctness and speedup) and manually (code reviews) to provide a more detailed perspective. We also tried an interactive approach where the LLM can fix its previous mistakes within a session. The results indicate that LLMs are quite skilled coders; however, they require tutoring to reach optimized solutions provided by parallel computing experts.
Paper Structure (24 sections, 2 figures)

This paper contains 24 sections, 2 figures.

Figures (2)

  • Figure 1: Performance of His1--7 on Lorem-ipsum (left) and Hexdump (right) inputs
  • Figure 2: Performance of GoL1--6 on a 16,384$\times$16,384 grid over 200 iterations.