AsyncTaichi: Whole-Program Optimizations for Megakernel Sparse Computation and Differentiable Programming

Yuanming Hu, Mingkuan Xu, Ye Kuang, Frédo Durand

Abstract

AsyncTaichi introduces an asynchronous execution engine and a novel "State-Flow Graph" (SFG) to enable automatic inter-kernel optimizations for sparse programming. By buffering kernels and analyzing data dependencies alongside sparsity patterns, the system achieves up to a 1.87× speedup on GPUs and reduces kernel launches by 4×. Crucially, these performance gains are achieved without requiring developers to modify their original imperative code, preserving modularity while delivering the efficiency of manually fused megakernels.

The Challenge of Eager Execution

In high-performance 3D graphics and physical simulations, developers rely on spatially sparse data structures (such as VDB or SPGrid) to concentrate computation on active regions, like the surface of a fluid. The current state-of-the-art compiler for this domain, Taichi, traditionally uses an "eager" execution model, launching kernels immediately upon invocation.

While effective for intra-kernel optimization, this eager approach prevents inter-kernel optimizations. It leads to significant overhead, such as redundant re-generation of active voxel lists and unnecessary memory checks between steps. Manually fusing these into "megakernels" is a common but error-prone workaround that destroys code modularity.

The AsyncTaichi Approach

AsyncTaichi shifts from eager to lazy execution to unlock a wider window for global optimization. The system accumulates kernels in a buffer, allowing the compiler to analyze future tasks before execution begins.

Figure 1: Comparison between traditional eager execution and AsyncTaichi's asynchronous model, showing the transition to fewer, more efficient kernels and resulting performance gains across various benchmarks.

The State-Flow Graph (SFG)

The core of this system is the State-Flow Graph (SFG), a novel intermediate representation. Unlike standard data-flow graphs that only track numerical values, the SFG treats the topological structure of sparse data—including masks (active voxels) and lists (iteration metadata)—as first-class states.

Figure 6: The State-Flow Graph (SFG) representation, illustrating how the compiler tracks dependencies between writer and reader tasks through data-flow and dependency edges.

Using the SFG, the compiler performs several key optimization passes:

  1. List Generation Removal: Skips rebuilding active element lists if the sparsity pattern is unchanged.
  2. Activation Demotion: Removes redundant checks for voxel activation guaranteed by previous kernels.
  3. Task Fusion: Automatically merges multiple kernels to improve data locality and reduce launch overhead.
  4. Dead Store Elimination: Identifies and removes memory writes that are never read by subsequent tasks.

Evaluation and Key Results

The system was evaluated across a suite of benchmarks, including Eulerian fluid advection, MLS-MPM simulations, and Multigrid solvers.

  • Performance: AsyncTaichi achieved a 1.87× geometric mean speedup on GPU benchmarks and a 1.33× speedup on x64 CPUs.
  • Efficiency: The number of launched GPU kernels was reduced by 4.02×.
  • Latency: A parallel JIT compiler, which compiles buffered kernels in the background while the GPU is active, reduced program startup time by 2.43× in complex solvers.
  • Comparison to JAX: In texture manipulation tasks, AsyncTaichi outperformed JAX by 3.3× even when JAX's fusion was active, thanks to Taichi's more efficient megakernel structure.

Insights and Future Work

The fundamental insight of AsyncTaichi is that "sparsity is state." By delaying execution, the compiler transforms isolated local decisions into a global optimization problem. This allows researchers to write clean, modular code while the compiler handles the complex task of megakernel fusion under the hood.

Future work aims to address current limitations, such as the memory footprint of intermediate fields and the requirement for static data structure topology. The authors also suggest that exploiting more specific kernel metadata, such as checkerboard patterns in solvers, could unlock further domain-specific optimizations.

Summary updated

BibTeX
@misc{hu2020asynctaichi,
  author = {Yuanming Hu and Mingkuan Xu and Ye Kuang and Frédo Durand},
  title = {{AsyncTaichi: Whole-Program Optimizations for Megakernel Sparse Computation and Differentiable Programming}},
  year = {2020},
  eprint = {2012.08141},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2012.08141},
}
Figure