Introduction: Bridging the "Ninja Gap"
The rapid evolution of specialized AI hardware, such as Tensor Processing Units (TPUs) and systolic arrays, has created a significant "Ninja Gap." While these chips offer immense theoretical performance, extracting that potential requires expert programmers with deep knowledge of specific Instruction Set Architectures (ISAs) and complex memory hierarchies. Traditional compilers often lag behind new hardware releases, and existing domain-specific languages still place the burden of scheduling optimizations on the developer.
Autocomp addresses this challenge by leveraging the reasoning capabilities of Large Language Models (LLMs) to automate hardware-specific code optimization. Unlike previous ML-based approaches that require massive training datasets, Autocomp uses a "plan-then-implement" strategy combined with real-time hardware feedback to achieve superhuman performance across diverse platforms.
Methodology: Plan-then-Implement and Iterative Search
Autocomp's core innovation is its two-phase prompting strategy, which separates high-level optimization planning from low-level code generation.
1. Plan-then-Implement Workflow
Instead of asking an LLM to write optimized code in a single step, Autocomp decomposes the task into two distinct phases:
- Phase 1: Planning: The LLM selects an optimization (e.g., loop tiling, double buffering) from a domain-knowledge menu. The prompt includes the hardware's ISA and performance metrics from previous runs.
- Phase 2: Implementation: The LLM generates semantically equivalent code based on the selected plan.
This decomposition significantly reduces syntactic errors, a common issue when LLMs generate code for low-resource hardware languages. To further enhance performance, Autocomp employs Optimization Menu Dropout to encourage exploration, LLM Ensembling to leverage diverse model strengths, and Schedule Reuse to apply successful optimization sequences from one workload to similar ones.
2. Iterative Beam Search with Hardware Feedback
Autocomp explores the optimization space using a beam search. In each iteration, it samples multiple candidate plans and implementations, evaluating them through actual hardware simulation or execution.
This hardware-in-the-loop feedback is crucial. Since LLMs cannot accurately predict performance on specialized hardware zero-shot, providing real-world cycle counts and memory utilization allows the model to "realize" when a strategy is inefficient and pivot accordingly.
Evaluation and Key Results
The framework was evaluated across three backends: Berkeley’s Gemmini systolic array, AWS Trainium, and NVIDIA L40S GPUs. Autocomp demonstrated "superhuman" capabilities across all platforms:
- Gemmini: Autocomp achieved a 5.6× speedup over vendor libraries and outperformed expert-level hand-tuned code by 1.4×, reaching over 90% hardware utilization.
- AWS Trainium: The system reduced the runtime of hand-optimized kernels by an average of 1.9×, with a peak speedup of 17.3× on 1D depthwise convolution.
- NVIDIA GPU: It outperformed TVM’s ML-based cost model by 3.8× and standard PyTorch implementations by 2×.
Conclusion
Autocomp demonstrates that LLMs can bridge the gap between high-level algorithms and low-level hardware performance without extensive retraining. By combining structured planning with empirical hardware feedback, it provides a portable and highly effective solution for optimizing code on next-generation AI accelerators. Future work will focus on multi-kernel optimizations and reducing the computational cost of the iterative search process.
Summary updated