A Nonlinear Hash-based Optimization Method for SpMV on GPUs

Chen Yan, Boyu Diao, Hangda Liu, Zhulin An, Yongjun Xu

TL;DR

This paper introduces the Hash-based Partition (HBP) format, a lightweight approach designed to accelerate Sparse Matrix-Vector Multiplication (SpMV) on GPUs. By replacing expensive sorting and dynamic programming routines with a novel nonlinear hash function, HBP achieves up to a 3.67× speedup in preprocessing and up to a 3.32× speedup in SpMV execution compared to traditional formats.

What Problem Does This Paper Address?

Sparse Matrix-Vector Multiplication (SpMV) is a foundational computational workload powering everything from graph analytics to neural networks. However, because sparse matrices are mostly filled with zeros, storing and computing them efficiently on GPUs is notoriously difficult.

Traditional formats like Compressed Sparse Row (CSR) suffer from severe load imbalance: if one GPU thread gets a row with hundreds of non-zero elements and another gets a row with two, the second thread sits idle waiting for the first to finish.

To fix this, researchers use 2D-partitioning, which breaks the matrix into smaller blocks to improve memory locality.

The two-step SpMV pipeline using 2D-partitioning

However, balancing the workload within these blocks usually requires sorting the rows or using dynamic programming during a preprocessing step. This preprocessing is slow, runs serially, and often relies on "zero-padding" (adding fake zeros to make rows equal length), which wastes memory and introduces parallel dependencies.

Methods

The authors propose a three-pronged solution to eliminate the preprocessing bottleneck while maintaining excellent GPU utilization:

  1. Hash-based Partition (HBP) Format: A new storage format that eliminates zero-padding entirely. It uses a specialized metadata array (add_sign) to track the distance to the next non-zero element within a row, allowing rows to be packed tightly without wasting space.
  2. Nonlinear Hash-based Reordering: Instead of sorting rows by their number of non-zero elements (which creates a parallel bottleneck), HBP applies a lightweight, nonlinear hash function directly to the non-zero count of each row.
Fig. 3. The format of nonlinear hash.

The hash function consists of three stages:

  • Aggregation: Groups rows with similar non-zero counts together using low-cost bit-shift operations.
  • Dispersion: Spreads the aggregated groups across the hash table to prevent thread divergence.
  • Linear Mapping: Fine-tunes positions using modulo operations to minimize collisions.
  • Mixed Execution Allocation: To balance workloads between different matrix blocks, the authors split the matrix into fixed parts and competitive parts. Warps (groups of 32 GPU threads) are statically assigned to fixed blocks on the same column to maximize shared memory reuse. Once a warp finishes its fixed allocation, it dynamically competes for remaining blocks using atomic ticket locks.
Fig. 2. An example of HBP format. We assume that the warp consists of 4 threads. col and data are stored in the order after hash transformation. zero row and begin ptr are used to find the first element that the current thread needs to calculate. add sign represents the distance from the current element to the next element within the same row.

Datasets

The method was evaluated using 14 large-scale sparse matrices from the University of Florida Sparse Matrix Collection (SuiteSparse). These matrices span various real-world domains, including circuit simulation, graph problems, and structural engineering (e.g., ASIC_680k, kron_g500-logn18, rajat30).

Key Insights and Ideas

  • Hashing Over Sorting: The core "aha!" moment is realizing that perfect sorting isn't necessary for load balancing. A cheap nonlinear hash function can group rows of similar computational density well enough to eliminate thread divergence, without the global data dependencies that make sorting slow on parallel hardware.
  • Ditching Zero-Padding for Parallelism: Avoiding zero-padding means the exact storage length of each block can be computed independently. This allows the entire format conversion process to be offloaded to parallel GPU threads, turning a traditional serial bottleneck into a parallel strength.
  • "Those Who Are Capable Work Harder": Relying purely on static block allocation fails when matrix density is highly irregular. By introducing a competitive queue for the remaining blocks, faster warps naturally absorb the excess workload of slower, denser blocks.

Key Results

The authors tested their approach on an edge AI platform (Nvidia Jetson AGX Orin) and a high-end desktop GPU (Nvidia RTX 4090):

  • Preprocessing Speedup: HBP's hash-based reordering achieved an average speedup of 3.53× compared to standard sorting (sort2D) and 3.67× compared to the dynamic programming approach used in Regu2D.
  • SpMV Performance:
  • On the Jetson Orin, HBP achieved up to a 3.32× speedup (1.64× average) over the standard CSR format.
  • On the RTX 4090, HBP achieved up to a 3.01× speedup (1.61× average) over CSR.
  • Memory Throughput: By leveraging shared memory and contiguous read-write patterns, HBP increased average memory throughput dramatically on the RTX 4090—for instance, jumping from 2.85 GB/s to 145.12 GB/s on the ASIC_320k matrix.

Limitations and Future Work

Despite the impressive speedups, the authors note a few key limitations:

  • Memory Overhead During Conversion: The process of converting a standard matrix into the HBP format requires significant temporary storage. On the RTX 4090, this caused Out-of-Memory (OOM) errors when attempting to convert some of the largest matrices (m4 through m7).
  • The "Combine" Bottleneck: In 2D-partitioning, partial results from different blocks must eventually be merged. As matrix sizes scale up, this merge step scales poorly and becomes the primary bottleneck, which HBP does not yet optimize.
  • Hash Collision Tuning: More complex hash functions could improve load distribution further, but the authors warn that the overhead of handling collisions could easily negate those gains. Refining this balance remains an open challenge.

Summary updated

BibTeX
@misc{yan2025nonlinear,
  author = {Chen Yan and Boyu Diao and Hangda Liu and Zhulin An and Yongjun Xu},
  title = {{A Nonlinear Hash-based Optimization Method for SpMV on GPUs}},
  year = {2025},
  eprint = {2504.08860},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2504.08860},
}
Figure