GPU Semiring Primitives for Sparse Neighborhood Methods

Corey J. Nolet, Divye Gala, Edward Raff, Joe Eaton, Brad Rees, Tim Oates

TL;DR

This paper introduces a flexible and efficient GPU primitive for computing pairwise distances on sparse data, unifying various distance measures under a single "semiring" framework. This approach significantly speeds up neighborhood-based machine learning tasks on GPUs, outperforming existing methods and offering a more memory-efficient solution.

What Problem Does This Paper Address?

Machine learning and information retrieval often deal with high-dimensional, sparse data. While GPUs excel at dense matrix operations, efficiently handling sparse data, especially for distance calculations crucial for nearest-neighbor searches, has lagged behind. Existing GPU solutions for sparse operations are often specialized, difficult to adapt to new distance metrics, and can be memory-intensive. This paper aims to bridge this gap by providing a unified, flexible, and performant GPU primitive for sparse distance computations.

Methods

The core of this work is a novel GPU primitive based on the concept of semirings. Semirings provide a mathematical framework for defining and computing operations like inner products using two operations (a "product" and a "sum"). The authors leverage this to generalize various distance measures, including those that go beyond the standard dot product.

They propose a Load-Balanced Hybrid CSR+COO SPMV (Sparse Matrix-Vector Multiplication) approach. This method combines the strengths of Compressed Sparse Row (CSR) and Coordinate (COO) formats. Key aspects include:

  • Hybrid CSR+COO: Using COO for one matrix to aid load balancing and CSR for the other.
  • Shared Memory Optimization: Loading vectors into shared memory to reduce global memory accesses.
  • Hash Table for Sparsity: Employing a hash table to efficiently store and look up sparse vector elements in shared memory, especially for high-degree columns.
  • Two-Pass Execution: For distances requiring a non-annihilating multiplicative monoid (NAMM), a two-pass approach is used to compute the full union of non-zero elements.

Datasets

The authors evaluated their approach using several real-world sparse datasets:

  • MovieLens Large: User ratings data.
  • scRNA: Gene expression data from a human cell atlas.
  • NY Times BOW: TF-IDF vectors for document similarity.
  • SEC Edgar: TF-IDF vectors for string matching (n-grams).

They note that these datasets were chosen to represent typical scenarios for neighborhood methods, differing from datasets often used for general sparse linear algebra benchmarks (e.g., square connectivity graphs).

Key Insights and Ideas

  • Semirings as a Unifying Framework: The paper demonstrates that semirings are a powerful abstraction for unifying a wide range of distance computations on sparse data, moving beyond the limitations of simple dot products.
  • The Challenge of Non-Annihilating Monoids (NAMM): Distances that don't have a multiplicative annihilator (like Manhattan distance) require a more complex computation over the union of non-zero elements, not just the intersection, posing a significant implementation challenge for efficiency.
  • GPU Architecture Trade-offs: Achieving high performance on GPUs requires careful consideration of thread divergence, memory coalescing, and shared memory usage. Naive implementations often struggle with these.
  • Hash Tables for Sparse Data on GPU: Using hash tables in shared memory is an effective strategy for handling high-degree columns in sparse vectors, though it introduces its own trade-offs with memory usage and potential lookup collisions.
  • Hybrid CSR+COO for Load Balancing: Combining CSR and COO formats, along with smart memory management, is crucial for achieving both efficient data access and balanced workload distribution across GPU cores.

Key Results

  • Significant Speedups: The proposed RAFT library implementation achieved an average speedup of 28.78x for dot-product-based distances and 29.17x for non-annihilating distances compared to CPU baselines (Scikit-learn).
  • Competitive Performance: The RAFT implementation was competitive with, and often faster than, the baseline cuSPARSE for supported distances.
  • Memory Efficiency: The approach is designed to be more memory-efficient than some existing GPU solutions, particularly for datasets where cuSPARSE's output can be very dense.
  • Broad Support: The primitive supports a wider range of distance measures than many existing GPU libraries.

Limitations and Future Work

  • Hash Table Optimization: The authors acknowledge that their hash table implementation, while effective, could be further optimized with better collision resolution strategies and potentially Bloom filters for certain scenarios.
  • Block-Sparse Formats: Support for block-sparse formats is a future direction, which could further improve performance by grouping nonzeros.
  • Dataset-Specific Optimizations: The paper notes that different sparse implementations perform better on different datasets, suggesting that future work might explore adaptive strategies based on data characteristics.
  • New Benchmarks: The authors established a new baseline using datasets relevant to neighborhood methods, highlighting the need for benchmarks that reflect these specific use cases.

Summary updated

Abstract

High-performance primitives for mathematical operations on sparse vectors must deal with the challenges of skewed degree distributions and limits on memory consumption that are typically not issues in dense operations. We demonstrate that a sparse semiring primitive can be flexible enough to support a wide range of critical distance measures while maintaining performance and memory efficiency on the GPU. We further show that this primitive is a foundational component for enabling many neighborhood-based information retrieval and machine learning algorithms to accept sparse input. To our knowledge, this is the first work aiming to unify the computation of several critical distance measures on the GPU under a single flexible design paradigm and we hope that it provides a good baseline for future research in this area. Our implementation is fully open source and publicly available as part of the RAFT library of GPU-accelerated machine learning primitives (https://github.com/rapidsai/raft).
BibTeX
@inproceedings{nolet2022gpu,
  author = {Corey J. Nolet and Divye Gala and Edward Raff and Joe Eaton and Brad Rees and Tim Oates},
  title = {{GPU Semiring Primitives for Sparse Neighborhood Methods}},
  booktitle = {MLSys},
  year = {2022},
  url = {https://openreview.net/forum?id=uyXveYFCkAa},
}
Figure