AsyncTaichi: On-the-fly Inter-kernel Optimizations for Imperative and Spatially Sparse Programming

Yuanming Hu, Mingkuan Xu, Ye Chow Kuang, Frédo Durand · DOI

Abstract

Leveraging spatial sparsity has become a popular approach to accelerate 3D computer graphics applications. Spatially sparse data structures and efficient sparse kernels are key to achieving high performance. Existing work focuses on improving performance within a single sparse computational kernel. We show that a system that looks beyond a single kernel, plus additional domain-specific sparse data structure analysis, opens up exciting new space for optimizing sparse computations. Specifically, we propose a domain-specific data-flow graph model of imperative and sparse computation programs, which describes kernel relationships and enables easy analysis and optimization. Combined with an asynchronous execution engine that exposes a wide window of kernels, the inter-kernel optimizer can then perform effective sparse computation optimizations, such as eliminating unnecessary voxel list generations and removing voxel activation checks. Without any computational code modification, our new system leads to $4.02\times$ fewer kernel launches and $1.87\times$ speed up on our GPU benchmarks, including computations on Eulerian grids, Lagrangian particles, meshes, and automatic differentiation.

Introduction

In high-performance graphics and physics simulations, spatially sparse data structures are essential for efficiency. Whether simulating smoke in a 3D grid or a cloud of moving particles, these systems only perform computations where data exists. While current frameworks like Taichi or CUDA excel at intra-kernel optimization (optimizing code within a single task), they typically follow an "eager" execution model. This model launches kernels sequentially, preventing the compiler from seeing relationships between consecutive tasks. For sparse data, this leads to significant overhead, as systems repeatedly rebuild "active" voxel lists or perform redundant activation checks. AsyncTaichi addresses this by introducing an asynchronous execution model that enables powerful inter-kernel optimizations.

Methods: The AsyncTaichi Architecture

AsyncTaichi shifts from eager execution to a "lazy" asynchronous model. By buffering kernel calls in a queue, the system creates a visibility window that allows the optimizer to analyze multiple kernels as a group.

System overview comparing eager execution with AsyncTaichi's asynchronous model.

The State-Flow Graph (SFG)

The core of the optimization engine is the State-Flow Graph (SFG), a novel Intermediate Representation (IR). Unlike standard data-flow graphs that only track numerical values, the SFG tracks four distinct states of sparse data:

  1. Value: The numerical data (e.g., density or velocity).
  2. Mask: The activation state of a voxel (on/off).
  3. List: The metadata used to iterate over active elements.
  4. Allocator: The state of the memory allocation system.

Inter-kernel Optimizations

By tracking these states, the system performs several "just-in-time" optimizations:

  • List Generation Removal: If the data mask hasn't changed between loops, the system skips re-generating the active voxel list.
  • Activation Demotion: Redundant activation checks are removed if a voxel is already known to be active from a previous step.
  • Kernel Fusion: Multiple small kernels are automatically merged into "megakernels" to reduce launch overhead and improve cache locality.

Key Results

AsyncTaichi was evaluated across a variety of benchmarks, including MacCormack Advection, Multigrid solvers (MGPCG), and hybrid particle-grid methods (MLS-MPM). The system achieved a geometric mean speedup of 1.87× on GPUs and 1.33× on CPUs.

Performance speedups achieved across different simulation domains.

Beyond raw speed, the efficiency gains were substantial. The number of launched kernels was reduced by an average of 4.02×. In the MGPCG benchmark specifically, the optimizer reduced the task count from over 1 million to approximately 224,000. Crucially, these performance gains were achieved on existing Taichi code without requiring any manual modifications from the user.

Conclusion and Future Work

AsyncTaichi demonstrates that treating sparsity as a first-class "state" in a compiler's IR allows for significant optimizations that were previously inaccessible. By using asynchrony as a lens to look ahead at future tasks, the system effectively eliminates the structural overhead inherent in sparse computations.

Future work aims to address current limitations, such as the automatic elimination of temporary intermediate storage and support for more dynamic field creation during runtime. Additionally, the authors suggest that extracting more complex domain-specific metadata, such as checkerboard patterns in solvers, could unlock further memory access optimizations.

Summary updated

Abstract

Leveraging spatial sparsity has become a popular approach to accelerate 3D computer graphics applications. Spatially sparse data structures and efficient sparse kernels (such as parallel stencil operations on active voxels), are key to achieve high performance. Existing work focuses on improving performance within a single sparse computational kernel. We show that a system that looks beyond a single kernel, plus additional domain-specific sparse data structure analysis, opens up exciting new space for optimizing sparse computations. Specifically, we propose a domain-specific data-flow graph model of imperative and sparse computation programs, which describes kernel relationships and enables easy analysis and optimization. Combined with an asynchronous execution engine that exposes a wide window of kernels, the inter-kernel optimizer can then perform effective sparse computation optimizations, such as eliminating unnecessary voxel list generations and removing voxel activation checks. These domain-specific optimizations further make way for classical general-purpose optimizations that are originally challenging to directly apply to computations with sparse data structures. Without any computational code modification, our new system leads to $4.02\times$ fewer kernel launches and $1.87\times$ speed up on our GPU benchmarks, including computations on Eulerian grids, Lagrangian particles, meshes, and automatic differentiation.
BibTeX
@misc{hu2020asynctaichi,
  author = {Yuanming Hu and Mingkuan Xu and Ye Chow Kuang and Frédo Durand},
  title = {{AsyncTaichi: On-the-fly Inter-kernel Optimizations for Imperative and Spatially Sparse Programming}},
  year = {2020},
  eprint = {2012.08141},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2012.08141},
}
Figure