An Efficient Sparse Kernel Generator for O(3)-Equivariant Deep Networks

Vivek Bharadwaj, Austin Glover, Aydin Buluc, James Demmel

TL;DR

This paper introduces a high-performance GPU kernel generator for the Clebsch-Gordan (CG) tensor product, a critical but computationally expensive bottleneck in rotation-equivariant neural networks. By using Just-in-Time (JIT) compilation and aggressive memory management, the authors achieve over 10x speedup compared to standard libraries and even outperform NVIDIA’s specialized cuEquivariance package by up to 1.3x.

What Problem Does This Paper Address?

Rotation-equivariant neural networks (like NequIP, MACE, and AlphaFold 2) are the state-of-the-art for spatial tasks in computational chemistry and physics. Unlike standard networks, they guarantee that if you rotate the input (e.g., a molecule), the output (e.g., predicted forces) rotates accordingly.

The mathematical engine behind this is the Clebsch-Gordan (CG) tensor product. As shown in Figure 1, this operation contracts two dense feature vectors ($x$ and $y$) with a highly structured, block-sparse tensor ($P$) to produce an output ($z$), often followed by a weight matrix ($W$).

Figure 1: The CG tensor product, which contracts a block-sparse tensor P with two dense vectors to output a new vector. It is usually followed by multiplication with a structured weight matrix W , and by convention we use “CG tensor product” to refer to both operations in sequence. Each blue block is itself sparse (see Figure 2), and several blocks may share identical structure.

The challenge is that this operation is repeated millions of times during training and inference. Because the tensor $P$ is extremely sparse but has a complex structure, standard deep learning frameworks (like PyTorch or JAX) struggle to implement it efficiently. They either treat it as dense (wasting computation on zeros) or use generic sparse formats that incur heavy memory overhead.

Methods

The authors developed an open-source kernel generator that produces optimized CUDA/HIP code tailored to the specific sparsity patterns of a given model. Their approach relies on several key techniques:

  • Just-in-Time (JIT) Compilation: Instead of a one-size-fits-all library, they generate kernels at model compile-time. This allows them to "unroll" the sparse tensor contraction, emitting arithmetic instructions only for the non-zero entries of the CG tensor.
  • Static Analysis & Scheduling: Since the structure of the equivariant model is known beforehand, the generator performs a static analysis to plan how data moves between global memory, shared memory, and registers. This minimizes expensive global memory traffic.
  • Warp-Level Parallelism: The kernels are designed so that each GPU warp operates independently on distinct data. This avoids the need for costly synchronization points (like __syncthreads()) within a thread block, significantly boosting throughput.
  • Kernel Fusion: In many models, the CG tensor product is immediately followed by a graph convolution. The authors fused these operations into a single kernel. This reduces intermediate data storage and allows for better data reuse in the GPU's L2 cache.
  • Double-Backward Identity: To support the higher-order derivatives needed for training interatomic force fields, the authors derived a novel way to implement "double-backward" passes by linearly combining existing forward and backward kernels, avoiding massive engineering complexity.

Datasets

The authors evaluated their kernels using configurations from several prominent equivariant models:

  • MACE & NequIP: Leading models for interatomic potential calculations.
  • DiffDock: A generative model for molecular docking.
  • Allegro: A model for large-scale molecular dynamics.
  • Molecular Graphs: Benchmarks were performed on real-world structures, including human dihydrofolate reductase (DHFR), the SARS-COV-2 glycoprotein spike, and a carbon lattice.

Key Insights and Ideas

  • Sparsity as an Instruction Stream: The core "aha" moment is treating the sparse tensor not as a data structure to be traversed, but as a blueprint for a specific stream of arithmetic instructions. By hardcoding non-zero indices via JIT, they maximize instruction-level parallelism (ILP).
  • Memory-First Design: In modern GPUs, moving data is often more expensive than computing on it. The authors' focus on static scheduling to keep data in registers and shared memory as long as possible is what drives the majority of their performance gains.
  • The Power of Fusion: Fusing the tensor product with graph convolution (SpMM-like patterns) changes the memory write complexity from $O(|E|)$ (number of edges) to $O(|V|)$ (number of vertices). In dense graphs where $|E| \gg |V|$, this is a massive win.

Key Results

  • Vs. e3nn: The generator provides a >10x speedup over the widely used e3nn package on difficult configurations like NequIP-benzene (see Figure 5).
  • Vs. cuEquivariance: It achieves up to 1.3x speedup over NVIDIA’s closed-source cuEquivariance library for forward passes, particularly on DiffDock configurations (see Figure 6).
  • Real-World Impact: For the MACE foundation model in high-precision (FP64), the authors demonstrated a 6.2x inference-time speedup over the original unoptimized version.
  • Hardware Efficiency: Roofline analysis (Figure 8) shows that their kernels consistently hit high compute and bandwidth utilization, saturating at roughly 58% of the theoretical FP32 peak.
Figure 5: Throughput of CG tensor products, showing more than 10x improvement over e3nn on difficult configurations.

Limitations and Future Work

  • Hardware Specialization: The current implementation relies on standard SIMT cores. The authors note that future versions could leverage specialized Matrix-Multiply-Accumulate (MMA) units (Tensor Cores) for even faster low-precision calculations.
  • Numerical Stability: While the kernels are accurate, the authors suggest integrating Kahan summation into the fused convolution kernels to further reduce numerical roundoff errors during large-scale aggregations.
  • Hyperparameter Tuning: The current heuristic for selecting warp counts and shared memory allotment could be further refined through automated tuning.

Summary updated

BibTeX
@inproceedings{bharadwaj2025efficient,
  author = {Vivek Bharadwaj and Austin Glover and Aydin Buluc and James Demmel},
  title = {{An Efficient Sparse Kernel Generator for O(3)-Equivariant Deep Networks}},
  booktitle = {ACDA},
  year = {2025},
  doi = {10.1137/1.9781611978759.3},
}
Figure