TL;DR
Sgap introduces a new theoretical framework called "atomic parallelism" and a compiler abstraction called "segment group" to optimize sparse tensor algebra on GPUs. By breaking the traditional compiler assumption that reduction operations must be serial, Sgap enables sparse compilers to generate code that is up to 1.2x faster than the original TACO compiler and boosts state-of-the-art libraries like dgSPARSE by up to 2.3x.
What Problem Does This Paper Address?
Sparse tensor algebra—operations involving tensors where most elements are zero—is the backbone of modern machine learning, graph processing, and scientific computing. While sparse compilers (like TACO) offer a way to automatically generate code for these complex operations, they often struggle to match the performance of hand-optimized GPU libraries.
The bottleneck is usually reduction: the process of summing up products (like in matrix multiplication). Current sparse compilers have two major flaws when targeting GPUs:
- Static Synchronization Granularity: They often assume a fixed 32-thread "warp" for synchronization. If the data doesn't perfectly fit this 32-thread window, parallelism is wasted.
- Serial Assumptions: Most compiler theories assume code executes serially. On a GPU, reduction can be parallel, segmented, or atomic. Forcing a serial mental model onto a parallel hardware architecture limits the "optimization space"—the range of possible ways the compiler can arrange the work to be faster.
Methods
The authors propose a two-pronged solution called Sgap:
- Atomic Parallelism: This is a formal model used to analyze the optimization space. It defines the "minimal data" a thread can process and how those threads are synchronized. It allows researchers to mathematically define why certain algorithms (like Row-Block vs. Element-Block) perform differently based on data dynamics.
- Segment Group: This is a new abstraction implemented within the compiler. It explicitly separates tiling (how data is partitioned) from synchronization (how results are combined).
- In the Front-end, they added a
GPUGroupunit to the scheduling language. - In the Middle-end, they introduced "zero extension," allowing the compiler to perform "out-of-bounds" reductions that are actually faster when handled by specialized GPU warp primitives.
- In the Back-end, they emit modular "macro instructions" (like
segReduceWarp) that utilize NVIDIA’s Cooperative Groups API to allow flexible synchronization sizes (2, 4, 8, 16, or 32 threads).
Datasets
The authors evaluated Sgap using:
- Sparse Matrices: A collection of matrices from the SuiteSparse Matrix Collection (referenced via the DA-SpMM paper [19]), covering various densities and structures.
- Hardware: Testing was performed across three generations of NVIDIA GPUs: RTX 3090 (Ampere), RTX 2080 (Turing), and Tesla V100 (Volta).
Key Insights and Ideas
- The "Serial Code" Fallacy: The most profound insight is that the "sparse iteration theory" used by compilers is built on the assumption that code runs serially. By breaking this assumption and allowing "zero extension" (calculating slightly more than needed to fit hardware primitives), the compiler can access much faster GPU instructions.
- Flexible Granularity: Not every sparse row needs 32 threads. By allowing the compiler to choose smaller group sizes (e.g., 4 or 8 threads), Sgap significantly reduces "wasted parallelism" where threads sit idle waiting for a large warp to sync.
- Separation of Concerns: By treating the "reduction strategy" as a distinct optimization choice from the "data layout," the authors opened up a new dimension of the design space that previous compilers simply couldn't express.
Key Results
- Compiler Improvement: When integrated into the TACO compiler, Sgap achieved a 1.1x to 1.2x speedup on SpMM (Sparse Matrix-Matrix Multiplication) kernels.
- Library Boosting: The authors applied the insights from atomic parallelism to dgSPARSE, a state-of-the-art hand-optimized library. By tuning the library using Sgap’s principles, they achieved a 1.6x to 2.3x speedup.
- Robustness: The performance gains were consistent across different GPU architectures, proving that the abstractions capture fundamental hardware truths rather than just "gaming" a specific chip.
Limitations and Future Work
- Workload Focus: The current study focuses primarily on SpMM with a small number of dense columns (less than 8). These are "balance-intensive" workloads. The authors note that "workload-intensive" scenarios (more than 128 columns) require different tiling and shared memory strategies not fully explored here.
- Implementation Details: The atomic parallelism model currently treats shared memory and grid-level mapping as "implementation details" rather than core components of the theory.
- Future Directions: The authors plan to expose atomic parallelism as a high-level auto-tuning API, allowing users to automatically find the best reduction strategy for any given sparse-dense hybrid operation without writing a single line of CUDA.
Summary updated