OptiML: An End-to-End Framework for Program Synthesis and CUDA Kernel Optimization

Arijit Bhattacharjee, Heng Ping, Son Vu Le, Paul Bogdan, Nesreen K. Ahmed, Ali JannesariarXiv 2026

TL;DR

OptiML is an end-to-end framework that bridges the gap between writing functionally correct CUDA code and achieving peak hardware performance. By combining a collaborative "Mixture-of-Thoughts" LLM generator with a hardware-aware Monte Carlo Tree Search (MCTS) optimizer, it automatically synthesizes and refines CUDA kernels based on real-time hardware profiler feedback.

What Problem Does This Paper Address?

Writing high-performance CUDA kernels for GPUs is notoriously difficult. The optimization space is combinatorial and non-smooth: a tiny change in loop structure, tiling size, or memory staging can drastically alter register pressure and occupancy, shifting a kernel from being compute-bound to memory-bound.

While modern Large Language Models (LLMs) are great at generating functionally correct code, they often fail to compile or leave massive amounts of performance on the table when tasked with writing complex parallel code. Existing approaches either treat code generation and optimization as completely separate problems or rely on black-box autotuning that ignores the underlying hardware bottlenecks.

Methods

OptiML solves this with a decoupled, two-stage framework: OptiML-G (Generation) and OptiML-X (Optimization).

Figure 1. Overview of OptiML. OptiML-G (left) routes inputs through multiple experts with latent-space collaboration to generate initial kernels. OptiML-X (right) optimizes kernels via MCTS with hardware-aware rewards.
  1. OptiML-G (Mixture-of-Thoughts Generator): When given a natural language prompt, OptiML-G routes the intent through a pool of frozen, pre-trained expert models (Qwen2.5-Coder-7B, HPC-Coder-V2, and StarCoder2). Instead of just picking one model, it allows them to collaborate in a shared latent space across multiple transformer layers. This produces a structurally strong, "optimization-ready" initial CUDA kernel.
  2. OptiML-X (Search-Based Optimizer): This module takes the initial kernel (or user-provided code) and uses Monte Carlo Tree Search (MCTS) to explore multi-step program transformations (like tiling, vectorization, and unrolling).

Crucially, OptiML-X is not searching blindly. It compiles and runs each variant on actual hardware, collecting metrics from the NVIDIA Nsight Compute profiler. An LLM-as-a-Judge evaluates these metrics against a composite reward function that balances execution time, hardware utilization proxies (SM/DRAM occupancy), and strict guardrails against regressions (like register spilling).

Datasets

The authors evaluated OptiML using two primary setups:

  • ParEval: A benchmark designed to measure an LLM's ability to generate correct parallel CUDA code from natural language specifications.
  • CUDA-LLM Task Suite: A diverse set of 20 representative CUDA kernels, including Matrix Multiplication, Max Pooling 3D, Multi-Head Self-Attention, ReLU Activation, and Categorical Cross-Entropy Loss.

Key Insights and Ideas

  • Latent-Space Collaboration Beats Ensembling: Fusing the hidden representations of behaviorally distinct code models at multiple depths yields structurally superior code compared to simply picking the best single model output.
  • Profiler-Guided Search is Sample-Efficient: Rather than treating optimization as a black box, OptiML adapts its reward weights based on the dominant bottleneck. If Nsight Compute signals that a kernel is memory-bound, the system dynamically upweights rewards for reducing L1 sector traffic and DRAM bytes.
  • The Generation-Optimization Synergy: A better starting point drastically reduces search distance. OptiML-G provides a clean macro-structure (like a baseline tiling skeleton), allowing the MCTS optimizer to immediately focus on fine-grained micro-optimizations rather than wasting its budget fixing compilation errors or basic indexing bugs.

Key Results

OptiML consistently outperformed strong LLM baselines in both code correctness and execution speed on an NVIDIA A100 GPU.

On the standalone code generation benchmark (ParEval), OptiML-G achieved a 12.17% Pass@1, outperforming GPT-5.1 (10.46%) and specialized models like HPC-Coder-V2 (4.74%).

Table 2. Performance comparison on ParEval benchmark (%).

When evaluating the full pipeline (Gen + X) on complex workloads, the benefits became even clearer. Many baseline LLMs completely failed to compile (marked as CF) on tasks like Max Pooling 3D and Multi-Head Self-Attention. OptiML not only successfully generated working kernels for these tasks but also delivered substantial speedups across the board, achieving a 1.30× geometric mean speedup at Pass@10.

Table 3. Pass@{1,5,10} and Speedup@{1,5,10} on the 5-task subset under best-of-k selection. Speedup is geometric mean over solved tasks with per-task baseline: GPT 5.1 when available, else GPT 5.1+OptiML-X when GPT 5.1 is CF.

Limitations and Future Work

Despite its success, the authors note several limitations:

  • Profiler Noise & Small Kernels: For very short kernels, profiling signals can be noisy due to caching and launch overheads, which can occasionally mislead the MCTS exploration.
  • Local vs. Global Redesign: The framework excels at local code edits (tiling, vectorization) but can struggle if a kernel requires a massive, top-down algorithmic redesign.
  • Scope: The current implementation optimizes single kernels in isolation.

Future Directions: The authors plan to extend OptiML to support whole-application optimization (enabling cross-kernel fusion and scheduling), integrate static analysis cost models to reduce reliance on expensive hardware profiling, and expand the backend to support other programming models like Triton, HIP/ROCm, and SYCL.

Summary updated

BibTeX
@misc{bhattacharjee2026optiml,
  author = {Arijit Bhattacharjee and Heng Ping and Son Vu Le and Paul Bogdan and Nesreen K. Ahmed and Ali Jannesari},
  title = {{OptiML: An End-to-End Framework for Program Synthesis and CUDA Kernel Optimization}},
  year = {2026},
  eprint = {2602.12305},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2602.12305},
}
Figure