Abstract
Sparse matrix-matrix multiplication (SpGEMM) is a widely used kernel in various graph, scientific computing, and machine learning algorithms. It is well known that SpGEMM is a memory-bound operation, and its peak performance is expected to be bound by the memory bandwidth. Yet, existing algorithms fail to saturate the memory bandwidth, resulting in suboptimal performance under the Roofline model. In this paper, we characterize existing SpGEMM algorithms based on their memory access patterns and develop practical lower and upper bounds for SpGEMM performance. We then develop an SpGEMM algorithm based on outer product matrix multiplication. The newly developed algorithm, called PB-SpGEMM, saturates memory bandwidth by using the propagation blocking technique and by performing in-cache sorting and merging. For many practical matrices, PB-SpGEMM runs 20%-50% faster than the state-of-the-art heap and hash SpGEMM algorithms on modern multicore processors. Most importantly, PB-SpGEMM attains performance predicted by the Roofline model, and its performance remains stable with respect to matrix size and sparsity.
Introduction: The Memory Bandwidth Gap
SpGEMM is a fundamental building block for diverse applications, ranging from graph analytics (e.g., triangle counting) to machine learning (e.g., spectral clustering). Because sparse matrices consist mostly of zeros, the computational challenge lies in efficiently identifying and multiplying non-zero elements.
This characteristic makes SpGEMM inherently memory-bound: its execution speed is limited by the rate at which data moves between RAM and the CPU, rather than the CPU's raw floating-point performance. However, a significant performance gap exists: standard algorithms—such as those based on heaps or hash tables—often fail to utilize the full available memory bandwidth. These methods suffer from irregular access patterns, causing the CPU to stall while waiting for scattered data. This research introduces PB-SpGEMM, an algorithm designed to hit the "Roofline," the theoretical maximum performance achievable given a system's bandwidth.
Methods: PB-SpGEMM and Outer Product Streaming
The authors depart from the traditional "column-by-column" approach, opting instead for an algorithm based on the outer product of matrices. PB-SpGEMM follows an "expand-sort-compress" paradigm with several key innovations.
By using an outer product formulation, the algorithm can stream input matrices from memory just once, ensuring high spatial locality. The core contribution, Propagation Blocking (PB), addresses the issue of intermediate product management. Instead of generating all intermediate products at once—which would overwhelm the cache—the algorithm "bins" these results into partially-sorted buckets based on their row indices.
These bins are sized to fit precisely into the CPU's L2 or L3 cache. Once a bin is full, the algorithm performs a Radix Sort and a merge (compression) step entirely within the cache. This strategy circumvents the "memory wall" by ensuring that the most data-intensive shuffling occurs where bandwidth is highest. Additionally, thread-local buffering ensures that writes to main memory are efficient by aggregating data into full cache lines before flushing.
Performance Analysis and Results
The authors evaluated PB-SpGEMM on a diverse set of synthetic (Erdos-Renyi, R-MAT) and real-world matrices from the SuiteSparse Matrix Collection, using high-end Intel Skylake-SP and IBM POWER9 hardware.
Key Results:
- Bandwidth Saturation: PB-SpGEMM achieved a sustained bandwidth of ~55 GB/s on a single-socket Skylake, matching the results of the industry-standard STREAM benchmark.
- Significant Speedup: The algorithm consistently outperformed state-of-the-art heap and hash-based SpGEMM methods by 20% to 50%.
- Stability and Scalability: Unlike previous algorithms, PB-SpGEMM’s performance remained stable across varying matrix sizes and densities. It also demonstrated excellent strong scaling, achieving a 16x speedup on 24 cores for Erdos-Renyi matrices.
Insights and Limitations
A key insight from this work is the importance of regularity over complexity. While hash tables are mathematically elegant, they create random memory lookups. PB-SpGEMM favors sorting because it can be implemented as a highly regular, streaming operation that hardware prefetchers can optimize.
However, the algorithm does have limitations. It is most effective when the "compression factor" (the ratio of intermediate products to final non-zero outputs) is less than 4. For very high compression factors, the overhead of sorting massive amounts of intermediate data can make hash-based methods more efficient. Future work will address challenges such as NUMA-related memory traffic on multi-socket systems and load imbalances in highly skewed matrices.
Summary updated