Abstract
Hardware accelerators like systolic arrays offer significant performance gains for deep learning but are hindered by a "software infrastructure gap" in non-standard domains. This paper presents a two-phase workflow leveraging Large Language Models (LLMs) to automate the compilation of high-level code into optimized assembly for custom hardware. By combining structured prompting, in-context learning, and iterative repair, the proposed method achieves high success rates in translating complex robotics kernels and delivers up to 8x performance speedups through automated scheduling.
Introduction
Tensor Accelerators (TAs) provide massive energy efficiency and performance benefits for deep learning. However, utilizing these accelerators for other domains—such as robotics, finance, or graph processing—remains difficult. Developers must often manually write low-level code or build custom compilers from scratch, creating a bottleneck that slows hardware-software co-design. This research explores LLMs as an agile alternative to traditional compiler development, bridging the gap between high-level algorithms and specialized hardware instructions.
Methodology
The researchers propose a two-phase workflow designed to ensure both functional correctness and hardware-specific optimization:
- Functional Translation: Source code (e.g., C++) is converted into a functionally correct implementation in the target Domain-Specific Language (DSL) or Instruction Set Architecture (ISA).
- Performance Optimization: The generated code is refined using a cost-model-driven search or LLM-guided scheduling to maximize hardware utilization.
Key technical components include Structured Prompting, which provides the LLM with a dictionary of the target ISA, and In-Context Learning (ICL), which uses annotated examples to guide the model's logic. To address arithmetic errors in memory offsets, a Multi-step Repair technique identifies "uncertainty holes" for the LLM to fill iteratively. Finally, LLM-driven Autoscheduling suggests loop transformations (tiling, unrolling) for the Exo scheduling library, ensuring optimizations remain semantics-preserving.
Experimental Evaluation
The approach was evaluated using kernels relevant to robotics and linear algebra, including TinyMPC (quadrotor control), Riccati Recursion (LQR solvers), and the PolyBench doitgen kernel. All experiments targeted Gemmini, an academic systolic array accelerator.
Results and Key Insights
The study revealed that providing the ISA specification is mandatory; without it, the model cannot reason about available operators. Furthermore, moving from zero-shot to one-shot examples drastically improved performance.
Key findings include:
- High Success Rates: For matrix-vector multiplications, GPT-4 achieved a 46% pass@1 rate, rising to nearly 100% at pass@50.
- Complex Logic Handling: The system successfully generated correct code for 5 out of 6 complex matrix-matrix functions in the Riccati recursion suite.
- Performance Gains: In autoscheduling experiments, LLM-optimized code improved performance from 5.64 GFLOPS to 43.33 GFLOPS—a nearly 8x improvement—by identifying optimal tiling and unrolling strategies.
While LLMs excel at logic, they struggle with complex index calculations in nested loops, often requiring the multi-step repair process to resolve arithmetic bottlenecks.
Conclusion and Future Work
LLMs demonstrate significant potential in automating the compilation process for specialized hardware. Future work will focus on integrating formal verification to guarantee equivalence between source and generated code, addressing arithmetic limitations in nested loops, and exploring the use of smaller, fine-tuned models to reduce the costs associated with high-end LLMs like GPT-4.
Summary updated