Interface for Sparse Linear Algebra Operations

Ahmad Abdelfattah, Willow Ahrens, Hartwig Anzt, Chris Armstrong, Ben Brock, Aydin Buluç, Federico Busato, Terry Cojean, Timothy A. Davis, Jim Demmel, Grace Dinh, David Gardener, Jan Fiala, Mark Gates, Azzam Haider, Toshiyuki Imamura, Pedro Valero-Lara, José E. Moreira, Xiaoye Sherry Li, Piotr Luszczek, Max Melichenko, Jose Moeira, Yvan Mokwinski, Riley Murray, Spencer Patty, Slaven Peles, Tobias Ribizel, E. Jason Riedy, Siva Rajamanickam, Piyush Sao, Manu Shantharam, Keita Teranishi, Stan Tomov, Yu-Hsiang Tsai, Heiko K. WeicheltarXiv 2024 · DOI

Abstract

This paper presents a standardized C++ API for Sparse Basic Linear Algebra Subroutines (Sparse BLAS), aiming to resolve the long-standing fragmentation in sparse computation libraries. While dense linear algebra has benefited from the interoperability of the original BLAS standard for decades, sparse operations have remained fragmented due to diverse storage formats and hardware-specific optimizations. The proposed interface introduces a hardware-portable framework that supports common storage formats (CSR, CSC, COO) and modern execution models. By utilizing non-owning views, opaque handles, and multi-stage execution patterns, this specification provides a foundation for high-performance, vendor-neutral sparse linear algebra.

Introduction

In high-performance computing (HPC), the dense BLAS (Basic Linear Algebra Subroutines) standard is a foundational success. It allows developers to write code once and achieve high efficiency across diverse hardware architectures. However, sparse linear algebra has historically lacked such a unified standard, resulting in a "Wild West" of proprietary and incompatible libraries.

Standardizing sparse operations is inherently more complex than dense operations for three primary reasons:

  1. Storage Diversity: Sparse matrices can be represented in dozens of formats (e.g., Compressed Sparse Row, Compressed Sparse Column, Coordinate), and different hardware architectures (CPUs vs. GPUs) favor different structures.
  2. Unknown Output Sizes: Operations such as sparse-matrix-sparse-matrix multiplication (SpGEMM) result in an output whose number of non-zero entries is unknown until the symbolic computation is performed.
  3. Fragmented Ecosystem: Major hardware vendors—including NVIDIA, Intel, AMD, and ARM—have developed proprietary libraries (e.g., cuSPARSE, oneMKL) that are not mutually compatible.

This paper details a two-year, cross-institutional effort to bridge these gaps through a unified C++ interface inspired by the std::linalg proposal for C++26.

The Proposed C++ API

The proposed specification leverages modern C++ features to balance ease of use with low-level performance optimization. Key technical components include:

Non-owning Views

Following the design of C++23’s mdspan, the API utilizes lightweight "views" to describe data. These views do not take ownership of memory, allowing users to pass existing buffers directly to the library without unnecessary allocations or data copies.

Opaque Handles and the "Inspect" Phase

To enable vendor-specific optimizations, the API introduces a matrix_handle. This handle allows libraries to store hidden, hardware-optimized versions of a matrix (such as a GPU-friendly internal format) that can be reused across multiple operations. This is complemented by an optional "Inspect" phase, where the library analyzes a matrix's structure to select the most efficient algorithm. This is particularly valuable for iterative solvers where the matrix structure remains constant while values change.

Multi-Stage Execution

For operations where the output size is not known a priori (like SpGEMM), the API adopts a multi-stage pattern:

  1. Compute: Determine the size and structure of the result.
  2. Allocate: The user provides the necessary memory based on the computed size.
  3. Fill: Perform the actual numerical computation.

Key Design Principles

Flexibility vs. Performance

The API supports both a "transparent" mode (using raw pointers and views for simplicity) and an "opaque" mode (using handles for maximum optimization). This allows developers to choose the level of abstraction that best fits their performance requirements.

Symbolic/Numeric Split

By separating the computation into symbolic (structure) and numeric (values) phases, the API enables significant speedups in applications where the matrix values are updated frequently but the underlying sparsity pattern remains static.

Modern Naming and Reproducibility

Departing from the cryptic Fortran-style naming conventions (e.g., dgemm), the proposal uses descriptive English names like multiply. Additionally, the authors address the challenge of floating-point non-associativity by proposing a "Conditional Numerical Reproducibility" (CNR) property, allowing users to request bit-wise identical results across different runs at the potential cost of some performance.

Scope of Operations

The specification defines a comprehensive suite of sparse kernels, including:

  • Basic Math: Scaling, norms, and additions.
  • Matrix-Vector and Matrix-Matrix Products: Standard SpMV and SpMM operations.
  • Advanced Kernels: Triangular solves and Sampled Dense-Dense Matrix Multiplication (SDDMM), the latter being a critical component in modern machine learning workloads.
  • Format Conversion: Standardized methods for converting between the "Big Three" formats: CSR, CSC, and COO.

Limitations and Future Work

The initial version of the proposal focuses on the most common formats (CSR, CSC, COO) to ensure a manageable first release, leaving specialized formats like Block CSR (BSR) for future iterations. While the core specification is in C++, the authors intend to develop bindings for C, Fortran, Python, and Julia.

Furthermore, while the current design is optimized for 2D matrices, extending the standard to support sparse tensors (higher-dimensional arrays) remains a significant area for future research. The ultimate success of this standard depends on its adoption and implementation by hardware vendors within their respective math libraries.

Summary updated

Abstract

The standardization of an interface for dense linear algebra operations in the BLAS standard has enabled interoperability between different linear algebra libraries, thereby boosting the success of scientific computing, in particular in scientific HPC. Despite numerous efforts in the past, the community has not yet agreed on a standardization for sparse linear algebra operations due to numerous reasons. One is the fact that sparse linear algebra objects allow for many different storage formats, and different hardware may favor different storage formats. This makes the definition of a FORTRAN-style all-circumventing interface extremely challenging. Another reason is that opposed to dense linear algebra functionality, in sparse linear algebra, the size of the sparse data structure for the operation result is not always known prior to the information. Furthermore, as opposed to the standardization effort for dense linear algebra, we are late in the technology readiness cycle, and many production-ready software libraries using sparse linear algebra routines have implemented and committed to their own sparse BLAS interface. At the same time, there exists a demand for standardization that would improve interoperability, and sustainability, and allow for easier integration of building blocks. In an inclusive, cross-institutional effort involving numerous academic institutions, US National Labs, and industry, we spent two years designing a hardware-portable interface for basic sparse linear algebra functionality that serves the user needs and is compatible with the different interfaces currently used by different vendors. In this paper, we present a C++ API for sparse linear algebra functionality, discuss the design choices, and detail how software developers preserve a lot of freedom in terms of how to implement functionality behind this API.
BibTeX
@misc{abdelfattah2024interface,
  author = {Ahmad Abdelfattah and Willow Ahrens and Hartwig Anzt and Chris Armstrong and Ben Brock and Aydin Buluç and Federico Busato and Terry Cojean and Timothy A. Davis and Jim Demmel and Grace Dinh and David Gardener and Jan Fiala and Mark Gates and Azzam Haider and Toshiyuki Imamura and Pedro Valero-Lara and José E. Moreira and Xiaoye Sherry Li and Piotr Luszczek and Max Melichenko and Jose Moeira and Yvan Mokwinski and Riley Murray and Spencer Patty and Slaven Peles and Tobias Ribizel and E. Jason Riedy and Siva Rajamanickam and Piyush Sao and Manu Shantharam and Keita Teranishi and Stan Tomov and Yu-Hsiang Tsai and Heiko K. Weichelt},
  title = {{Interface for Sparse Linear Algebra Operations}},
  year = {2024},
  eprint = {2411.13259},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2411.13259},
}
Figure