Design Principles for Sparse Matrix Multiplication on the GPU

Carl Yang, Aydin Buluç, John D. Owens

Introduction

Sparse Matrix-Dense Matrix Multiplication (SpMM), defined as $C = AB$ where $A$ is sparse and $B$ is a "tall-skinny" dense matrix, is a cornerstone of modern computational workloads. From pruning deep neural networks to graph analysis and iterative solvers, the efficiency of SpMM directly impacts system performance. However, the standard Compressed Sparse Row (CSR) format, while memory-efficient, presents significant challenges for GPU parallelization due to extreme variations in row lengths. This irregularity leads to severe load imbalance and uncoalesced memory access patterns, where GPU cores either sit idle or perform inefficient global memory fetches.

Algorithmic Strategies

The authors propose a hybrid approach combining two distinct algorithmic strategies, governed by a smart heuristic to navigate the trade-offs between workload regularity and memory efficiency.

1. Row-splitting SpMM

This method assigns rows to GPU warps. Its primary innovation is a memory access strategy that ensures coalesced access by assuming the dense matrix $B$ is in row-major order. By employing "thread coarsening," the algorithm increases Instruction-Level Parallelism (ILP). This allows individual threads to issue multiple independent memory requests, effectively hiding the high latency of global memory.

2. Merge-based SpMM

Adapted from Sparse Matrix-Vector (SpMV) techniques, this method treats the multiplication as a 2D merge path. It explicitly balances the workload by ensuring every GPU thread processes an equal number of non-zero elements, regardless of row length. This eliminates "Type 1" load imbalance—the uneven distribution of work across different warps.

Comparison of load balancing strategies: Row split, Nonzero split, and Merge path.

The Heuristic Switching Logic

The researchers identified that Row-splitting excels on matrices with long rows, while Merge-based is superior for short, irregular rows. They implemented an $O(1)$ heuristic: if the average number of non-zeroes per row is less than 9.35, the system selects the Merge-based kernel; otherwise, it uses Row-splitting. This simple rule achieved 99.3% accuracy in choosing the fastest kernel compared to an ideal oracle.

Performance Analysis

The proposed approach was evaluated against NVIDIA’s cuSPARSE library using 195 real-world datasets from the SuiteSparse Matrix Collection.

SpMV and SpMM performance across varying mean row lengths.

Key findings include:

  • Speedup: A geometric mean speedup of 31.7% over cuSPARSE, with peak gains reaching 4.1x on specific datasets.
  • Sparsity Threshold: The SpMM implementation remains faster than standard dense GEMM until the sparse matrix reaches approximately 9% density. Beyond this point, the overhead of managing sparsity outweighs the benefits of the specialized kernels.
  • ILP vs TLP: The results suggest that Instruction-Level Parallelism (more work per thread) is often more effective than Thread-Level Parallelism for hiding memory latency in SpMM.

Conclusion

This work demonstrates that optimizing SpMM requires a nuanced understanding of load balancing and memory access patterns. By leveraging ILP to hide latency and employing a robust heuristic to navigate the trade-offs between row-splitting and merge-based strategies, the authors provide a high-performance alternative to industry-standard libraries. Future work aims to incorporate 2D tiling for denser matrices and abstract these load-balancing techniques into general-purpose GPU libraries like CUB.

Summary updated

BibTeX
@inproceedings{yang2018design,
  author = {Carl Yang and Aydin Buluç and John D. Owens},
  title = {{Design Principles for Sparse Matrix Multiplication on the GPU}},
  booktitle = {Euro-Par},
  year = {2018},
  doi = {10.1007/978-3-319-96983-1\_48},
}
Figure