Locality-Aware Automatic Differentiation on the GPU for Mesh-Based Computations

Ahmed H. Mahmoud, Jonathan Ragan-Kelley, Justin Solomon · DOI

Introduction

In computer graphics, physical simulation, and engineering, many algorithms rely on optimizing a functional defined over a mesh—for example, minimizing the energy of a stretching cloth. Efficiently solving these problems requires derivatives: gradients for first-order methods and Hessians for second-order methods like Newton’s solver. However, general-purpose automatic differentiation (AD) frameworks like PyTorch and JAX, designed for dense tensor operations in machine learning, struggle with the sparse and irregular nature of mesh data.

Researchers from MIT have developed a GPU-accelerated AD system specifically tailored for mesh-based computations. By exploiting the local nature of mesh connectivity and keeping calculations within high-speed GPU registers and shared memory, this system transforms derivative evaluation from a major bottleneck into a negligible cost, outperforming general-purpose frameworks by orders of magnitude.

The Challenge of Mesh-Based AD

Mesh data is inherently sparse; each vertex typically interacts only with its immediate neighbors. When these problems are forced into standard ML frameworks, they suffer from massive memory overhead and redundant computations. Researchers often have to hand-derive complex derivatives or avoid second-order solvers entirely because computing a Hessian is computationally prohibitive. Consequently, many settle for slower first-order solvers.

A Locality-Aware Approach

The proposed system treats the GPU as a first-class target for mesh-specific mathematics through several key technical innovations:

  • Per-element Forward-mode AD: Unlike the reverse-mode (backpropagation) used in ML, which requires recording a global computation graph, this system uses forward-mode on small, local elements. This allows all intermediate derivative values to stay in fast GPU registers.
  • Patch-based Execution: Utilizing the RXMesh data structure, the system partitions the mesh into small "patches." Data for local computations is loaded into shared memory once and reused, maximizing memory bandwidth.
  • Atomic Assembly: Global sparse Jacobians and Hessians are assembled directly on the GPU using atomic operations, avoiding the "CPU-GPU round trip" that slows down other sparse AD tools.
  • Dynamic Sparsity Handling: For simulations involving collisions, the sparsity pattern changes every frame. The system includes a GPU-resident pipeline to update these sparse matrix structures on the fly without involving the CPU.

Datasets and Applications

The system's versatility was evaluated across seven diverse geometry and physics applications, including cloth simulation, mesh parameterization, and ARAP (As-Rigid-As-Possible) deformation. One notable test involved a massive simulation of 700 "Spot" cows (2.1 million vertices) falling and colliding.

Large-scale simulation of 700 colliding 'Spot' cows (2.1M vertices), where derivative computation is no longer the bottleneck.

Key Results and Insights

The primary insight of this research is that memory locality, rather than mathematical complexity, is the real bottleneck in mesh AD. By confining differentiation to registers and shared memory, the system bypasses the "memory wall" that slows down global graph-based AD.

Comparison of computation time between PyTorch and the proposed system, showing a dramatic reduction in differentiation overhead.

Key performance metrics include:

  • Massive Speedups: On cloth simulation, the system achieved a 5.1x speedup over IndexedSum (a sparse PyTorch extension) and was over 100x faster than naive PyTorch.
  • Scaling to Millions: In the 2.1-million-vertex cow simulation, derivative computation and assembly accounted for only 12.2% of the total runtime. Previously, this stage would have been the dominant bottleneck.
  • Efficiency in First-Order Tasks: Even for simple gradient descent, the system was 8.87x faster than PyTorch and 1.71x faster than a hand-coded, highly optimized CUDA baseline.

Conclusion

By making Hessians "cheap" to compute, high-quality second-order solvers—which converge much faster than gradient descent—are now practical even for meshes with millions of elements. Future work will focus on extending the system to volumetric discretizations (like tetrahedral meshes) and implementing kernel fusion to further reduce memory traffic.

Summary updated

BibTeX
@article{mahmoud2026locality,
  author = {Ahmed H. Mahmoud and Jonathan Ragan-Kelley and Justin Solomon},
  title = {{Locality-Aware Automatic Differentiation on the GPU for Mesh-Based Computations}},
  journal = {ACM Trans. Graphics},
  year = {2026},
  doi = {10.1145/3811338},
}
Figure