TL;DR
PTXBench is a new evaluation framework designed to measure and improve how well Large Language Models (LLMs) can write low-level, architecture-specific PTX code for GPU kernel optimization. Testing across NVIDIA Hopper (H100) and Blackwell (B200) architectures, the authors find that while top models can optimize simpler forward passes, they struggle significantly with complex backward workloads. Furthermore, the paper introduces Fixit, a repair-conditioned fine-tuning method that helps smaller models learn to exploit these specialized hardware mechanisms.
What Problem Does This Paper Address?
To squeeze maximum performance out of modern GPUs, developers often have to drop down to PTX (Parallel Thread Execution), the lowest-level programmable interface for NVIDIA hardware. Each new GPU generation introduces specialized PTX instructions—such as Hopper’s asynchronous memory copies (TMA) or Blackwell’s new tensor core pathways (TCGEN05).
While high-level kernel languages like Triton help bridge the portability gap, keeping them optimized requires continuous, massive compiler engineering. Can LLMs directly write inline PTX to exploit these cutting-edge hardware features? Existing benchmarks only measure end-to-end functional correctness or speed, meaning an LLM could "cheat" by falling back on generic CUDA or standard vendor libraries. PTXBench addresses this by isolating and verifying whether specific, architecture-defined low-level instructions are actually executing at runtime.
Methods
The authors developed MiniPTXAgent, a multi-turn agent loop that provides LLMs with an extensive architecture "knowledge pack" (20k–30k tokens detailing hardware parameters, wrappers, and memory contracts). The agent generates CUDA code with inline PTX and refines it iteratively based on compiler and runtime feedback.
To ensure the model isn't just writing dead code, PTXBench uses a two-stage verification process:
- Static Inspection: It checks the compiled GPU assembly (SASS) to ensure the target instruction family is present.
- Dynamic Profiling: It runs the kernel using NVIDIA Nsight Compute (NCU) to verify a positive, predicate-enabled thread count, proving the hardware mechanism actually ran under the evaluated workload.
For model adaptation, the paper introduces Fixit, a repair-conditioned Supervised Fine-Tuning (SFT) approach. Instead of training only on perfect code, Fixit samples failures from the target model, uses a strong teacher model (Gemini 3.1 Pro) to generate a corrected version, and employs another teacher (GLM-5.2) to synthesize a step-by-step reasoning rationale explaining the fix.
Datasets
PTXBench evaluates models using workloads built on the unified FlashInfer-Trace schema. The benchmark focuses on BF16 GEMM (General Matrix Multiply) and four critical attention variants:
- Multi-Head Attention Forward (MHA-Fwd)
- MHA-Fwd-Causal
- MHA Backward (MHA-Bwd)
- MHA-Bwd-Causal
To test generalization, the authors also included held-out attention workloads varying in head dimensions ($d=64, 96$) and Grouped-Query Attention (GQA) variants (including ragged/paged prefill and decode operations).
Key Insights and Ideas
- Instruction Execution $\neq$ High Performance: Just because an LLM successfully triggers a specialized hardware instruction does not mean the kernel will be fast. Proper memory layout, tiling, and instruction scheduling remain massive hurdles for AI coders.
- The "Backward" Wall: While frontier models achieve decent success rates on forward attention passes, their capabilities plummet on backward attention workloads. Managing the complex data dependencies and synchronization required for gradients proves incredibly difficult for current LLMs.
- In-Context Knowledge is Mandatory: Without the explicit 20k-30k token architecture contract in the prompt, models almost never attempt to use the requested PTX instructions. They do not inherently "know" how to program new hardware from their pre-training data alone.
- High-Level Languages Still Dominate New Tech: On the newer Blackwell (B200) architecture, generating Triton code yields significantly better performance than direct CUDA-PTX generation. This is likely due to the severe scarcity of Blackwell-specific PTX examples available during the models' pre-training.
Key Results
- Frontier Model Evaluation: Claude Opus 4.8 and Gemini 3.1 Pro achieved strong results on H100 GEMM and forward attention, occasionally matching or slightly exceeding frontier library baselines. However, no model consistently matched vendor libraries across the entire suite, especially on Blackwell.
- Fixit SFT Impact: Applying the Fixit recipe to Qwen3.6-27B (which initially had zero capability on Hopper workloads) successfully enabled it to generate correct, instruction-verified kernels across all five primary evaluation problems.
- Data Balance Beats Scale: When fine-tuning, data composition mattered more than raw volume. A smaller, carefully balanced dataset (recipe
s1) successfully trained the model to solve all five primary tasks, whereas a dataset 1.6× larger but unbalanced (recipes2) completely failed on complex backward causal attention.
Limitations and Future Work
The authors note two primary limitations. First, the adaptation experiments were restricted to a single 27B parameter base model using parameter-efficient LoRA tuning; the dynamics might shift during industry-scale, full-parameter post-training. Second, the benchmark currently focuses strictly on BF16 GEMM and attention workloads for H100 and B200 GPUs.
Because PTXBench decouples the workload schema from the evaluation pipeline, future work will focus on extending the benchmark to a wider variety of GPU operators, alternative precisions, and upcoming hardware architectures.
Summary updated