Skip to main content
QUICK REVIEW

[Paper Review] Tenspiler: A Verified Lifting-Based Compiler for Tensor Operations (Extended Version)

Jie Qiu, C.R. Cai|arXiv (Cornell University)|Jan 1, 2024
Parallel Computing and Optimization TechniquesComputer Science3 citations
TL;DR

Tenspiler is a verified lifting-based compiler that translates sequential C++ or Python code into optimized tensor operations using a novel, unified intermediate language called Tensir. By formulating code translation as a syntax-guided program synthesis problem and leveraging theorem proving for correctness, Tenspiler achieves an average 105× kernel speedup and 9.65× end-to-end speedup across 69 real-world benchmarks on six software and hardware backends.

ABSTRACT

Tensor processing infrastructures such as deep learning frameworks and specialized hardware accelerators have revolutionized how computationally intensive code from domains such as deep learning and image processing is executed and optimized. These infrastructures provide powerful and expressive abstractions while ensuring high performance. However, to utilize them, code must be written specifically using the APIs / ISAs of such software frameworks or hardware accelerators. Importantly, given the fast pace of innovation in these domains, code written today quickly becomes legacy as new frameworks and accelerators are developed, and migrating such legacy code manually is a considerable effort. To enable developers in leveraging such DSLs while preserving their current programming paradigm, we introduce Tenspiler, a verified lifting-based compiler that uses program synthesis to translate sequential programs written in general-purpose programming languages (e.g., C++ or Python code) into tensor operations. Central to Tenspiler is our carefully crafted yet simple intermediate language, named TensIR, that expresses tensor operations. TensIR enables efficient lifting, verification, and code generation. Currently, Tenspiler already supports $ extbf{six}$ DSLs, spanning a broad spectrum of software and hardware environments. Furthermore, we show that new backends can be easily supported by Tenspiler by adding simple pattern-matching rules for TensIR. Using 10 real-world code benchmark suites, our experimental evaluation shows that by translating code to be executed on $ extbf{6}$ different software frameworks and hardware devices, Tenspiler offers on average 105$ imes$ kernel and 9.65$ imes$ end-to-end execution time improvement over the fully-optimized sequential implementation of the same benchmarks.

Motivation & Objective

  • Address the challenge of legacy code portability in tensor computing by enabling automatic translation from general-purpose code to domain-specific language (DSL) targets.
  • Overcome the limitations of pattern-matching compilers and LLM-based code generation, which are brittle, error-prone, and lack correctness guarantees.
  • Design a unified, extensible intermediate representation (Tensir) that abstracts tensor operations for efficient synthesis and verification.
  • Enable seamless support for new backends by adding simple pattern-matching rules to Tensir, reducing the effort of porting to new frameworks or accelerators.

Proposed method

  • Formulate the code translation task as a syntax-guided program synthesis (SGS) problem, where the input program is lifted to an equivalent Tensir program.
  • Use a theorem prover to verify semantic equivalence between the input and synthesized Tensir program, ensuring correctness.
  • Design Tensir as a minimal, tensor algebra-based IR that captures common vector and matrix operations, enabling efficient synthesis and verification.
  • Apply optimization techniques such as operator restriction and program state restriction to reduce search space and improve scalability.
  • Generate target code from the verified Tensir program using a user-provided code generator, supporting multiple backends including MLX, Gemmini, and Gaudi.
  • Leverage expression trees and vectorization heuristics to guide the synthesis of efficient, vectorized operations in higher-dimensional tensors.

Experimental results

Research questions

  • RQ1Can a verified lifting-based approach enable correct and efficient compilation of general-purpose code to diverse tensor DSLs and hardware backends?
  • RQ2How effective is a unified intermediate representation (Tensir) in enabling scalable synthesis and verification across heterogeneous tensor processing targets?
  • RQ3To what extent can Tenspiler’s synthesis and verification pipeline scale to real-world, complex benchmarks involving 1D, 2D, and 3D tensor operations?
  • RQ4How does Tenspiler’s performance compare to fully optimized sequential implementations in terms of kernel and end-to-end execution time?
  • RQ5Can Tenspiler be easily extended to support new backends with minimal engineering effort?

Key findings

  • Tenspiler achieves an average of 105× speedup in kernel execution time and 9.65× speedup in end-to-end execution time compared to fully optimized sequential implementations across 69 real-world benchmarks.
  • The synthesis process scales effectively, with artificial 3D tensor benchmarks of depth 5 taking 184 seconds to synthesize, well within a 1-hour timeout.
  • Tenspiler successfully transpiles code to six distinct backends—including MLX, Gemmini, and Gaudi—demonstrating broad compatibility with both open-source and commercial frameworks.
  • The implementation of Tenspiler for the newly released MLX framework required less than 200 lines of code, highlighting the extensibility of the Tensir IR.
  • LLM-generated code for the same benchmarks was consistently incorrect and non-functional, underscoring the limitations of LLMs in generating verified code for unfamiliar DSLs.
  • The use of Tensir enables efficient verification and code generation, with optimizations such as operator restriction and program state restriction significantly reducing the search space for synthesis.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.