TL;DR
HIERA is a hierarchical search-space planning framework that automates GPU kernel optimization by dynamically choosing the best implementation granularity—ranging from high-level PyTorch operators to low-level custom CUDA code. By combining contract-augmented task specifications with expert-guided pruning and hardware profiling feedback, HIERA significantly outperforms existing training-free LLM approaches and matches or beats specialized training-based methods without requiring any model retraining.
What Problem Does This Paper Address?
Writing high-performance GPU kernels is notoriously difficult, requiring deep hardware expertise and significant engineering effort. While Large Language Models (LLMs) have shown promise in automating code generation, existing LLM-based kernel optimizers suffer from a "Goldilocks problem" regarding their implementation space:
- Too High-Level: If they restrict themselves to high-level abstractions (like PyTorch operators or vendor libraries), they miss out on low-level optimization tricks like custom kernel fusion or shape specialization.
- Too Low-Level: If they jump straight into raw, low-level CUDA code, the search space explodes. LLMs often waste their budget generating code that fails compilation or correctness checks.
Furthermore, existing systems cannot dynamically determine if they are operating at the right level of abstraction for a given workload. HIERA addresses this limitation by treating implementation granularity as an explicit, workload-aware planning decision.
Methods
HIERA introduces a structured, coarse-to-fine optimization workflow consisting of four main stages:
- Contract-Augmented Task Specification: Instead of asking the LLM to generate a full executable program from scratch (including boilerplate host-side wrappers, bindings, and verification logic), HIERA fixes these components. The LLM only focuses on generating the core performance-critical code (
cuda_source.cu). - Cross-Granularity Search-Space Planning: A Search-Space Decision Agent (SSDA) dynamically selects the right level of abstraction based on the workload—choosing between nested spaces: pure CUDA, CUDA libraries (like cuBLAS), or CUDA libraries + PyTorch operators.
- Domain-Guided Optimization-Direction Pruning: To avoid a brute-force search, HIERA uses expert knowledge to score and prune the search space into five core optimization directions: control-flow specialization (C), parallelism (P), memory efficiency (M), data reuse/pipelining (R), and Tensor Core utilization (T).
- Feedback-Driven Iteration: Generated candidates are compiled, verified for correctness, and profiled using hardware-level metrics from NVIDIA Nsight Compute (NCU) to guide the next round of refinement.
Datasets
The authors evaluated HIERA using KernelBench, a benchmark containing 250 PyTorch workloads divided into three complexity levels:
- Level 1: 100 operator-level tasks.
- Level 2: 100 fused-operator tasks.
- Level 3: 50 model-level workloads.
Additionally, they tested HIERA on a specialized 2D box stencil computation from scientific computing to demonstrate its generalizability beyond standard deep learning workloads.
Key Insights and Ideas
- Granularity is an Optimization Decision: The choice of where to optimize (at the framework level, library level, or hardware level) shouldn't be predefined. Different workloads thrive at different granularities, and letting an agent choose this space dynamically prevents the model from reinventing the wheel for complex composite workloads.
- Structure Beats Raw Generation: Forcing an LLM to write boilerplate code wastes its token budget and increases the chance of syntax errors. "Contracts" keep the LLM focused strictly on algorithmic logic, drastically improving implementation validity.
- Expert Knowledge + Profiling Feedback = Sample Efficiency: Purely data-driven or trial-and-error code generation struggles with CUDA. By explicitly structuring the feedback loop around hardware bottlenecks (like memory transaction efficiency or instruction underutilization), the framework can make massive performance leaps in just a few iterations.
Key Results
- Superior Sample Efficiency: Under a strict budget (e.g., $B=18$ candidates), HIERA achieved a significantly higher fraction of valid and accelerated implementations compared to baselines like KernelBench-Caesar and CUDAForge.
- Outperforming Training-Based Methods: HIERA consistently outperformed the training-based method CUDA-L1 on Level 1 and Level 2 tasks, despite being completely training-free.
- Scientific Computing Speedup: In the 2D box stencil case study, HIERA discovered a custom kernel that achieved a 1.53× speedup over a highly optimized vendor baseline (cuDNN
cudnnConvolutionForward), reducing runtime by 65.6% compared to the first-round candidate.
Limitations and Future Work
- Hardware & Precision Constraints: The evaluation was strictly limited to NVIDIA A100 GPUs. KernelBench tasks were evaluated in FP32, while the stencil case study used FP64. Performance across other architectures (like AMD or Apple Silicon), multi-GPU setups, and mixed-precision formats (FP16/BF16/INT8) remains to be investigated.
- Static Planning Heuristics: The current implementation relies on fixed expert heuristics and scoring rubrics for direction pruning. The authors note that future work will explore self-improving planning mechanisms that learn directly from accumulated optimization trajectories.
Summary updated