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:
- 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.
- 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.
- 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:
- Compute: Determine the size and structure of the result.
- Allocate: The user provides the necessary memory based on the computed size.
- 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