Heuristic Adaptability to Input Dynamics for SpMM on GPUs

Guohao Dai, Guyue Huang, Shang Yang, Zhongming Yu, Hengrui Zhang, Yufei Ding, Yuan Xie, Huazhong Yang, Yu Wang

Abstract

Sparse Matrix-Matrix Multiplication (SpMM) is a fundamental component in various domains, including Graph Neural Networks (GNNs) and Large Language Models (LLMs). While GPUs provide high bandwidth and parallelism, static SpMM designs often fail to maintain optimal performance across diverse input data, sometimes resulting in over 85% performance loss. We propose DA-SpMM, a data-aware heuristic GPU kernel that adaptively optimizes execution by analyzing input dynamics. By extracting orthogonal design principles through a novel three-loop model and employing a LightGBM-based heuristic, DA-SpMM achieves significant speedups—averaging 1.26x to 1.37x over NVIDIA’s cuSPARSE and up to 5.59x end-to-end speedup for GNN applications.

Introduction: The Challenge of Input Dynamics

SpMM involves multiplying a sparse matrix $A$ by a dense matrix $X$ to produce a dense matrix $Y$. Despite the high theoretical throughput of modern GPUs, the performance of SpMM is notoriously "brittle." The optimal execution strategy depends heavily on the "fingerprint" of the input data, including sparsity levels, row-length distribution (imbalance), and the width of the dense matrix ($N$).

Current industry-standard libraries, such as NVIDIA cuSPARSE, often rely on static heuristics or a limited set of algorithms. As shown in Figure 1, the performance of various algorithms (Alg0-Alg9) varies significantly across different GPU architectures and matrix widths. A single static choice can lead to substantial performance degradation compared to the theoretical upper bound.

Performance variability of different SpMM algorithms across various GPUs and matrix widths (N), highlighting the lack of a single "best" algorithm for all scenarios.

Methodology: Orthogonal Design and the Three-Loop Model

To address the challenge of input dynamics, we decompose the SpMM operation into a three-loop model (Figure 2). This model allows us to identify orthogonal design principles that form a comprehensive algorithm space.

The three-loop model for SpMM, illustrating the M-loop (workload balance), N-loop (memory access), and K-loop (parallelism efficiency) and their impact on data access patterns.

The design space consists of eight distinct algorithms based on three key choices:

  1. $M$-Loop (Workload Balance): Choosing between Row Balance (assigning rows to workers) or Element Balance (distributing non-zero elements evenly to mitigate row-length imbalance).
  2. $N$-Loop (Memory Access): Choosing between Row Major (optimized for wide dense matrices via coalesced loading) or Column Major (optimized for narrow matrices via improved locality).
  3. $K$-Loop (Parallelism Efficiency): Choosing between Sequential Reduction (high utilization for large matrices) or Parallel Reduction (maximizing parallelism for small matrices).

Implementing this space required novel techniques such as conditional reduction to handle thread races in parallel reduction and shared memory caching to optimize sparse element reuse.

DA-SpMM: A Data-Aware Heuristic

DA-SpMM uses a machine learning-based dispatcher to select the optimal algorithm from the design space at runtime. We trained a LightGBM model using four primary features: the number of non-zeros, matrix dimensions, the standard deviation of row lengths, and the dense matrix width. This heuristic approach incurs negligible overhead (microseconds) while ensuring that the chosen kernel matches the input characteristics.

Experimental Results

We evaluated DA-SpMM across three GPU generations (RTX 3090, RTX 2080, Tesla V100) using the SuiteSparse Matrix Collection.

  • Performance vs. cuSPARSE: DA-SpMM consistently outperformed the best NVIDIA cuSPARSE algorithms, achieving average speedups of 1.26x to 1.37x.
  • GNN Acceleration: In end-to-end tests using the Deep Graph Library (DGL) on GCN and GraphSAGE models, DA-SpMM provided speedups between 5.27x and 5.59x.
  • Adaptability: DA-SpMM achieved over 98% of the theoretical peak performance (the "upper bound" of choosing the best algorithm for every matrix), a significant improvement over static designs which often fall below 70%.

Conclusion

DA-SpMM demonstrates that heuristic adaptability is crucial for high-performance sparse operations on GPUs. By combining a structured three-loop design space with a lightweight machine learning model, we can overcome the performance brittleness of static SpMM implementations. This methodology offers a promising path for optimizing other sparse kernels in the evolving landscape of AI workloads.

Summary updated

BibTeX
@inproceedings{dai2022heuristic,
  author = {Guohao Dai and Guyue Huang and Shang Yang and Zhongming Yu and Hengrui Zhang and Yufei Ding and Yuan Xie and Huazhong Yang and Yu Wang},
  title = {{Heuristic Adaptability to Input Dynamics for SpMM on GPUs}},
  booktitle = {DAC},
  year = {2022},
  doi = {10.1145/3489517.3530508},
}
Figure