NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

LoopStack: a Lightweight Tensor Algebra Compiler Stack

Bram Wasti, José Pablo Cambronero, Benoit Steiner, Hugh Leather, Aleksandar ZlateskiarXiv 2022 · DOI

Abstract

LoopStack is an ultra-lightweight tensor compiler designed for high-performance deep learning on mobile and embedded devices. With a binary footprint of just 245KB, it bypasses heavy analysis frameworks like LLVM in favor of user-defined loop schedules and Einstein notation. This approach enables compilation speeds orders of magnitude faster than traditional tools while matching the performance of hand-tuned libraries.

Introduction

Modern deep learning relies on high-performance tensor operations like matrix multiplication and convolutions. Currently, developers must choose between hand-optimized libraries, which are fast but massive and difficult to maintain, or heavyweight compilers like TVM and Halide. These compilers often rely on LLVM, resulting in binary sizes exceeding 300MB and compilation times that hinder real-time auto-tuning. LoopStack targets the "missing middle": a compiler small enough for IoT devices, fast enough to compile in milliseconds, and powerful enough to match hand-tuned assembly.

Methods: LoopTool and LoopNest

LoopStack is split into two main components that prioritize predictability and speed:

  • LoopTool (Frontend): A Python-embedded DSL that utilizes Einstein notation to represent tensor contractions. It represents computations as a dataflow graph (DFG) where dimensions are symbolic. Users provide loop order annotations to guide the compiler's traversal of the data.
Dataflow graph representation in LoopTool using symbolic dimensions for tensor operations.
  • LoopNest (Backend): A "what-you-see-is-what-you-get" code generator. Unlike traditional compilers that attempt to infer optimal reordering, LoopNest strictly follows the user's specified schedule. It focuses on low-level hardware optimizations such as vectorization (AVX, NEON), register blocking, and software pipelining. By trusting the user's schedule, it avoids expensive dependency analysis, generating optimized machine code for X86 and ARM in milliseconds.

Key Insights and Results

A core philosophy of LoopStack is that predictability is a feature. Traditional compilers act as "black boxes," but LoopStack provides immediate feedback. If performance is poor, a user can adjust the schedule and re-compile nearly instantly. This interactive loop allows for rapid optimization that matches or exceeds the performance of highly tuned libraries like Intel's MKL-DNN.

Interactive loop scheduling and performance feedback showing achieved Gflops and compilation metrics.

Key performance metrics include:

  • Compilation Speed: LoopNest is 100x to 1000x faster than LLVM at generating code for identical schedules.
  • Hardware Efficiency: On AVX512 systems, manual tuning via LoopStack achieved 88.5% of peak theoretical performance for matrix multiplication.
  • Extreme Portability: The entire binary is only 245KB, roughly 1,400x smaller than LLVM-based stacks. This small codebase allowed the authors to add support for new hardware extensions, like the Apple M1's fp16, in less than 10 days.

Evaluation and Benchmarks

The authors evaluated LoopStack across various hardware targets, including Intel Xeon, AMD Epyc, ARM Cortex, and Apple M1. Benchmarks included standard operator tests (GEMM, convolutions) and neural network workloads like MobileNetV3. In these tests, LoopStack's scripted tuning consistently matched the performance of vendor-specific optimized libraries.

Limitations and Future Work

Currently, LoopStack focuses on single-threaded performance for dense tensor algebra. While multi-threading can be implemented on top of the stack, it is not yet a native feature of the core compiler. Additionally, the system relies on either an expert human or an external search script to find the optimal schedule, as it does not automatically solve the optimization problem for the user. Future work may address sparse operations and native multi-core support.

Summary updated

BibTeX
@misc{wasti2022loopstack,
  author = {Bram Wasti and José Pablo Cambronero and Benoit Steiner and Hugh Leather and Aleksandar Zlateski},
  title = {{LoopStack: a Lightweight Tensor Algebra Compiler Stack}},
  year = {2022},
  eprint = {2205.00618},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2205.00618},
}
Figure