Efficient Sparse Matrix Kernels based on Adaptive Workload-Balancing and Parallel-Reduction

Guyue Huang, Guohao Dai, Yu Wang, Yufei Ding, Yuan XiearXiv 2021

Introduction

Sparse matrix operations, particularly Sparse Matrix-Vector (SpMV) and Sparse Matrix-Matrix (SpMM) multiplication, are fundamental to modern computational tasks ranging from scientific simulations to Graph Neural Networks (GNNs). However, the irregular distribution of non-zero elements in sparse matrices presents significant challenges for GPU acceleration.

Two primary inefficiencies plague these operations on GPUs:

  1. Workload Imbalance: Irregular row lengths lead to thread divergence and hardware idling.
  2. Inefficient Memory Access: Standard reduction techniques often fail to maximize memory bandwidth or data reuse.

While workload-balancing and parallel-reduction are established design principles, existing implementations often fail to integrate them effectively or adapt to varying matrix "widths" ($N$, the number of columns in the dense matrix). This research addresses these gaps by exploring the implementation space and providing an adaptive framework for kernel selection.

Mapping of research contributions across implementation and data spaces for SpMV and SpMM kernels.

Proposed Methods

The researchers introduce three specialized optimizations designed to cover the implementation gaps in sparse kernels:

Vectorized Segment Reduction (VSR)

VSR unifies workload balancing with parallel reduction. Instead of the traditional row-per-warp assignment—which is inefficient for short rows—VSR assigns a fixed number of non-zero elements to each warp. It leverages SIMD-shuffle primitives to perform high-speed reductions across row boundaries.

Vector-type Dense-row Loading (VDL)

Optimized for SpMM with small widths (e.g., $N \in \{2, 4\}$), VDL utilizes vectorized memory instructions (such as float2 or float4). This approach allows for the simultaneous loading of multiple dense matrix elements, significantly boosting memory throughput.

Coalesced Sparse-row Caching (CSC)

For larger widths ($N > 32$), the performance bottleneck shifts from reduction to memory access. CSC addresses this by caching sparse matrix elements in the GPU's shared memory (scratchpad). This enables efficient, coalesced memory loads while utilizing a sequential reduction method that is better suited for large dense matrices.

Adaptive Selection Strategy

A key contribution of this work is an automated selection mechanism that chooses the most efficient kernel based on the input matrix's characteristics and the target hardware.

Decision tree for the adaptive selection of optimal sparse kernels based on matrix characteristics.

The strategy uses low-cost metrics, such as average row length and the standard deviation of row lengths, to navigate a decision tree. This ensures that the system avoids the significant performance penalties associated with using a sub-optimal kernel for a specific matrix distribution.

Evaluation and Results

The suite of kernels was evaluated using the SuiteSparse Matrix Collection and synthetic R-MAT matrices across multiple GPU architectures, including the Tesla V100, RTX 2080, and RTX 3090.

Performance Gains

The proposed kernels consistently outperformed NVIDIA’s cuSPARSE library, achieving speedups between 1.07× and 1.57×. When compared to ASpT, a state-of-the-art research implementation, the new kernels achieved up to a 1.21× speedup for SpMM tasks.

Robustness of Selection

The adaptive strategy proved highly effective. While choosing the wrong kernel could result in an 86% performance loss, the rule-based selection remained within 5-12% of the theoretical optimal performance for any given matrix.

Conclusion and Future Work

By effectively combining workload-balancing and parallel-reduction, this research provides a comprehensive suite of kernels that significantly improve the efficiency of sparse matrix operations on GPUs. Future work involves automating the tuning of hardware-specific parameters to ensure portability across emerging GPU architectures. These optimizations are currently being integrated into graph learning frameworks like CogDL and DGL to accelerate GNN training in production environments.

Summary updated

BibTeX
@misc{huang2021efficient,
  author = {Guyue Huang and Guohao Dai and Yu Wang and Yufei Ding and Yuan Xie},
  title = {{Efficient Sparse Matrix Kernels based on Adaptive Workload-Balancing and Parallel-Reduction}},
  year = {2021},
  eprint = {2106.16064},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2106.16064},
}
Figure