Abstract
KernelBand is a novel framework designed to bridge the gap between Large Language Model (LLM) code generation and low-level GPU hardware optimization. By framing kernel optimization as a Contextual Multi-Armed Bandit (MAB) problem, KernelBand incorporates hardware-aware pruning and trace-driven clustering to guide LLMs toward high-performance implementations. Evaluated on the TritonBench-G benchmark, KernelBand achieves a 1.91× geometric mean speedup on NVIDIA A100 GPUs, significantly outperforming existing unguided LLM agents.
Introduction
Writing high-performance GPU kernels is a specialized task requiring deep hardware expertise. While domain-specific languages like Triton have simplified the process of writing functional code, achieving peak hardware utilization remains a "black magic" challenge. Recent attempts to use LLMs for automation often fail because these models lack "hardware intuition," leading to inefficient search paths and suboptimal code. LLMs are excellent at implementing strategies but mediocre at choosing which ones to apply based on physical hardware constraints.
System Architecture and Methodology
KernelBand addresses these limitations by decoupling strategy selection from code generation. The system treats optimization as a search problem within a Multi-Armed Bandit framework, acting as a "navigator" for the LLM "coder."
The pipeline consists of four main stages: (1) Profiling and Clustering, where kernels are grouped by runtime behavior; (2) Hardware-Constrained Bandit selection, which chooses the best optimization strategy; (3) LLM Code Generation; and (4) Hardware Evaluation. Two key mechanisms drive this efficiency:
- Hardware-Aware Pruning: The system uses NVIDIA Nsight Compute to profile resource usage (SM, DRAM, and L2 cache throughput). If a resource is near saturation (e.g., >75%), the bandit masks optimization strategies that target that resource, preventing the LLM from wasting attempts on physically impossible gains.
- Trace-Driven Clustering: Kernels are grouped into clusters based on a 5D feature vector of runtime behavior (including execution time, register usage, and occupancy). This allows the system to share knowledge across similar kernels—leveraging the theoretical "Lipschitz continuity" of kernels, where similar runtime signatures respond predictably to specific optimizations.
Experimental Evaluation
The researchers evaluated KernelBand using TritonBench-G, a benchmark comprising 183 kernels across 13 functional categories (e.g., Attention, MatMul, Normalization) and 5 difficulty levels. Testing was conducted on three distinct NVIDIA architectures: RTX 4090, H20, and A100.
As shown in the performance summary, KernelBand consistently outperformed state-of-the-art methods like GEAK and Best-of-N (BoN) sampling. Key results include:
- Speedup: Achieved a 1.91× geometric mean speedup on the A100 GPU.
- Success Rate: Improved the Fast@1 metric (the probability of finding an optimized kernel in one attempt) by 39% to 140% over baselines.
- Cost Efficiency: Delivered 35–50% higher speedup per dollar spent on LLM API calls compared to unguided approaches.
- Model Robustness: The performance gains were consistent across various underlying LLMs, including DeepSeek-V3, GPT-5, Claude 4.5, and Gemini 3 Flash.
Conclusion and Future Work
KernelBand demonstrates that hardware-aware guidance is essential for LLM-based code optimization. By using hardware limits as search bounds, the framework turns physical bottlenecks into a mathematical advantage for pruning the search space. While currently optimized for NVIDIA environments, future work will focus on adapting the hardware signature logic for other accelerators (like AMD ROCm) and exploring Reinforcement Learning (RL) for multi-step, long-horizon optimization trajectories.
Summary updated