Program Generation for Linear Algebra Using Multiple Layers of DSLs

Daniele G. Spampinato, Diego Fabregat-Traver, Markus Püschel, Paolo BientinesiarXiv 2019

Abstract

This paper introduces a program generator designed to automatically translate high-level linear algebra expressions into highly optimized, vectorized C code. By stacking multiple layers of Domain-Specific Languages (DSLs), the system effectively bridges the gap between abstract mathematical notation and low-level hardware optimizations. The approach significantly outperforms industry-standard libraries, such as Intel MKL, particularly for small-to-medium-sized matrix problems common in specialized domains like control systems and signal processing.

Introduction

High-performance linear algebra has traditionally relied on general-purpose libraries like BLAS and LAPACK. While these are the "gold standard" for large-scale computations, they face two significant challenges:

  1. Suboptimal Performance for Small Scales: These libraries are tuned for matrices with hundreds or thousands of elements. For smaller computations, the overhead of general-purpose routines becomes a bottleneck.
  2. Rigid Interfaces: Standard libraries often lack the flexibility to handle unique matrix structures or non-standard operation sequences efficiently, forcing developers to adapt their problems to the library's constraints.

The authors address these issues by automating the creation of "bespoke" linear algebra routines tailored to specific matrix sizes, properties, and hardware architectures.

System Architecture and Methodology

The core of the proposed framework is a pipeline that integrates two specialized tools: CL1CK for high-level algorithm synthesis and LGen for low-level code generation. This integration is managed through four distinct layers of DSLs.

The multi-layered DSL pipeline for program generation, transitioning from abstract linear algebra expressions to optimized C code.

The process begins with Algorithm Synthesis, where mathematical expressions (e.g., $X^T X = A$) are transformed into Partitioned Matrix Expressions (PMEs). The system identifies loop invariants to construct a family of mathematically equivalent algorithms using DSLs like p-LA (partitioned linear algebra) and lp-LA (loop-based linear algebra).

Following synthesis, the Implementation Optimization phase utilizes lower-level DSLs (LL and $\Sigma$-LL) to address hardware-specific concerns. This includes "tiling"—breaking matrices into cache-sized blocks—and "vectorization" using SIMD instructions (e.g., AVX). Finally, an Autotuning feedback loop benchmarks several generated variants to select the most efficient implementation for the target CPU.

Experimental Evaluation

The generator was evaluated on an Intel Sandy Bridge CPU using AVX instructions, focusing on double-precision floating-point math for matrix sizes ($n$) ranging from 4 to 116. The benchmarks included Cholesky decomposition and the solution of continuous-time Lyapunov and Sylvester equations, with Intel Math Kernel Library (MKL) 11.2 serving as the baseline.

Key Results

The generated code demonstrated impressive efficiency, often approaching the theoretical peak performance of the processor.

Extracted figure from page 2 of Program Generation for Linear Algebra Using Multiple Layers of DSLs
  • Cholesky Decomposition: The generated code matched the performance of the highly-tuned MKL.
  • Lyapunov Equations: The generator significantly outperformed MKL, achieving speedups of 4x to 4.8x.
  • Sylvester Equations: Performance gains ranged from 2x to 2.5x over the MKL baseline.

Discussion and Insights

The success of this approach stems from three key insights:

  • Layered Abstraction: Using multiple DSLs allows optimizations to occur at the most appropriate level, from algorithmic choices to register-level details.
  • Algorithm Families: By exploring multiple mathematically equivalent algorithms, the generator can identify the optimal approach for a specific matrix size or architecture.
  • Specialization: Unlike general-purpose libraries, generating code for a fixed matrix size (e.g., exactly $20 \times 20$) allows for the elimination of branches, loop unrolling, and perfect memory alignment.

Conclusion and Future Work

While the current system provides substantial performance benefits, the authors note opportunities for further refinement. Future work will focus on reducing memory overhead caused by temporary submatrices and improving vectorization for matrix sizes that are not multiples of the hardware's vector length. Additionally, moving from empirical autotuning to a "model-based" prediction approach could significantly reduce the time required to generate optimal code.

Summary updated

BibTeX
@misc{spampinato2019program,
  author = {Daniele G. Spampinato and Diego Fabregat-Traver and Markus Püschel and Paolo Bientinesi},
  title = {{Program Generation for Linear Algebra Using Multiple Layers of DSLs}},
  year = {2019},
  eprint = {1906.08613},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1906.08613},
}
Figure