A High-Performance Sparse Tensor Algebra Compiler in Multi-Level IR

Ruiqin Tian, Luanzheng Guo, Jiajia Li, Bin Ren, Gokcen KestorarXiv 2021

Introduction

Tensors, or multidimensional arrays, serve as the fundamental data structures for modern scientific computing and machine learning. However, real-world datasets—ranging from social network graphs to scientific simulations—are often "sparse," meaning the vast majority of their entries are zero. To optimize memory usage, researchers have developed a plethora of specialized storage formats, such as Compressed Sparse Row (CSR), Coordinate (COO), and Compressed Sparse Fiber (CSF).

The primary challenge in sparse tensor algebra is the "combinatorial explosion" of possible implementations. The performance of a single operation, such as a tensor-times-matrix (TTM) multiplication, varies wildly depending on the specific storage formats of the inputs and the target hardware architecture. Manually authoring optimized kernels for every combination is infeasible. This paper introduces COMET, a domain-specific language (DSL) and compiler infrastructure built on the Multi-Level Intermediate Representation (MLIR) framework to automate the generation of high-performance sparse kernels.

The COMET Infrastructure

COMET addresses the complexity of sparse algebra through a progressive lowering approach. By leveraging MLIR, the compiler can perform domain-specific optimizations at high levels of abstraction before gradually translating the code into hardware-specific instructions.

The COMET compiler pipeline leveraging MLIR for progressive lowering and optimization.

As shown in the architecture diagram, the process begins with a high-level DSL using Einstein notation (e.g., C[a,c] = A[a,b] * B[b,c]). This is lowered into a Tensor Algebra Abstract Syntax Tree (TA AST) and subsequently into various MLIR dialects. This multi-level approach allows COMET to separate the mathematical logic from the physical storage representation and the final execution model, whether sequential or parallel.

Handling Diverse Storage Formats

A key innovation in COMET is its "attribute-based" description of storage formats. Rather than hard-coding support for monolithic formats like CSR or DCSR, COMET describes each dimension of a tensor using four primary attributes:

  • Dense (D): All elements are stored.
  • Compressed_Unique (CU): Only non-zero elements are stored, and coordinates are unique.
  • Compressed_Nonunique (CN): Non-zero elements are stored, but coordinates may repeat.
  • Singleton (S): Used for formats like COO where each entry is stored with its full coordinate.
Examples of sparse matrix and tensor storage formats supported by COMET's attribute-based system.

By mixing and matching these attributes, COMET can represent virtually any known sparse format modularly. This flexibility allows the compiler to generate efficient code for "mixed-format" operations without requiring specialized, hand-written libraries for every edge case.

Advanced Optimizations: Locality and Parallelism

Beyond format support, COMET introduces two critical optimizations to overcome the irregular nature of sparse data:

  1. Data Reordering (LexiOrder): Sparse data often suffers from poor memory locality, leading to frequent cache misses. COMET integrates the LexiOrder algorithm, which reshuffles non-zero elements to cluster them together. This ensures that when the CPU fetches data, it is more likely to find subsequent required elements in the fast cache, resulting in speedups of up to 7.14x for parallel kernels.
  2. Asynchronous Parallelism: Traditional threading models like OpenMP often introduce significant overhead for the "spiky," irregular workloads characteristic of sparse algebra. COMET utilizes an asynchronous task-based model powered by LLVM co-routines. This lightweight approach reduces synchronization overhead and improves performance for small or highly irregular datasets.

Performance Evaluation

The researchers evaluated COMET against TACO, the previous state-of-the-art sparse tensor compiler, using over 2,800 sparse matrices from the SuiteSparse collection and large-scale tensors from the FROSTT and BIGtensor datasets.

Key results include:

  • SpMV (Sparse Matrix-Vector Multiplication): Achieved up to a 20.92x improvement in parallel execution over TACO.
  • SpMM (Sparse Matrix-Matrix Multiplication): Demonstrated up to a 6.39x speedup.
  • TTM (Tensor-Times-Matrix): Outperformed existing tools by up to 13.9x.

Conclusion and Future Work

COMET demonstrates that a multi-level IR approach can effectively solve the combinatorial explosion in sparse tensor algebra. By abstracting storage formats into per-dimension attributes and employing advanced reordering and asynchronous execution, it significantly outperforms existing compilers.

Future iterations of COMET will focus on addressing load imbalances that can arise during data reordering and extending the infrastructure to support heterogeneous architectures, including GPUs. The goal is to create a truly universal compiler for sparse computing across all modern hardware platforms.

Summary updated

BibTeX
@misc{tian2021high,
  author = {Ruiqin Tian and Luanzheng Guo and Jiajia Li and Bin Ren and Gokcen Kestor},
  title = {{A High-Performance Sparse Tensor Algebra Compiler in Multi-Level IR}},
  year = {2021},
  eprint = {2102.05187},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2102.05187},
}
Figure