You can edit almost every page by Creating an account. Otherwise, see the FAQ.

Taichi Lang

From EverybodyWiki Bios & Wiki

Script error: No such module "Draft topics". Script error: No such module "AfC topic".

Taichi Lang is an open-source domain-specific language (DSL) designed for high-performance parallel computing.[1]. It is embedded in Python and uses its own intermediate representation (IR) to just-in-time (JIT) compile compute-intense Python code to native GPU or CPU instructions. It adopts the imperative programming paradigm.

The language was invented by Yuanming Hu in 2019 to reduce the burden of learning close-to-hardware languages for computer graphics researchers.[2] The design philosophies center around friendly syntax (similar to Python), high performance, and strong portability.

Three years into its inception, the open-source project has grown into a general parallel programming language and found applications in many fields, including physical simulation, image processing, and visual effects.

History[edit]

In January 2019, Hu, who was a doctoral student at MIT at the time, began to work on a brand new programming language. He noticed that the traditional close-to-hardware languages face a dissatisfying trade-off between performance and productivity when performing visual computing workloads. He set two high-level goals for his project later known as Taichi Lang: To simplify the process of high-performance visual computing system development and deployment, and to explore novel language abstractions and compilation approaches for visual computing. He introduced Taichi in a paper published on SIGGRAPH Asia 2019, which proves that Taichi achieves 4.55x higher performance in 1/10 lines of code than hand-optimized reference implementations[2].

In 2020, Hu moved Taichi's frontend from C++ to Python to take advantage of the latter's friendly syntax and lower the learning barrier to suit a wider user base. He also enabled differentiable programming in Taichi (DiffTaichi) and shared the results of the DiffTaichi project at ICLR 2020.[3]

On April 13, 2022, Taichi v1.0.0, the first milestone, was released[4]. Starting from the v1.2.0 release announced on October 25, 2022, Taichi follows semantic versioning.

As of November 2022, Taichi had around 200 contributors from around the world.

Features[edit]

JIT compilation[edit]

The JIT compilation pipeline first transforms the Python Abstract Syntax Tree (AST) of a given Python function into the Taichi "Front-end AST", which is then auto-parallelized and transformed into an IR developed by Taichi. It is under CHI-IR that the Taichi compiler performs all the domain-specific optimizations. Afterwards, the optimized CHI-IR is sent to the "Taichi backend", where it is compiled into executable GPU kernels[5].

High-performance parallel computing[edit]

Taichi offers a decorator ti.kernel as the entry point from which Taichi's runtime takes over compute-intensive tasks from Python.

The high performance of Taichi programs boils down to three reasons:

  • Taichi's compiler compilers kernels directly to machine code[6].
  • The outermost for loops in a kernel are automatically parallelized[7].
  • The same code can be deployed to various backends[8].

Integration with Python ecosystem[edit]

Users can import Taichi (import taichi as ti) as they do with other Python libraries and write Taichi code the same way as they write Python except for a few extra rules. Taichi is part of the Python ecosystem and can interact with mainstream computing frameworks embedded in Python, such as NumPy and PyTorch.

Taichi provides various interfaces for data transfer between Taichi fields and NumPy arrays/PyTorch tensors/Paddle tensors[9].

Spatially sparse data structures[edit]

High-resolution 2D/3D grids are often used in large-scale spatial computation, such as physical simulation, rendering, and 3D reconstruction. However, dense data structures often consume a huge amount of memory space and computation. While a programmer may allocate a large dense grid to store spatial data, they often only care about a small fraction of this dense grid since the rest may be empty space (vacuum or air). Taichi provides spatially sparse data structures to avoid wasted computation for empty space. Users can access a spatially sparse data structure in the same way they do with a dense data structure. This feature decouples computation and data structures, allowing users to experiment with different data arrangements and tailor high-performance data structures for specific computational tasks[10].

As spatially sparse programming imposes analysis and optimization complexities, Taichi provides a state-flow formulation for performance analysis and an asynchronous execution engine for optimization. The optimized Taichi kernels are then just-in-time compiled in parallel, and dispatched to parallel devices such as multithreaded CPU and massively parallel GPUs[11].

SNode system[edit]

Taichi adopts a Structural Node (SNode) tree system, which is the key to decoupling computation from data structures[10]. SNodes can be used to compose a hierarchical multi-dimensional field (Taichi's data container). The system allows users to experiment with different memory layouts without rewriting code.

GUI & GGUI[edit]

Taichi has a built-in GUI system for visualizing simulation data in data containers like Taichi fields or NumPy ndarrays. It also has limited support for drawing primitive geometries[12].

Starting from v0.8.0, Taichi has added a new UI system GGUI[13]. The name was derived from the fact that the system uses GPU for rendering, making it faster to render 3D scenes.

Objective data-oriented programming[edit]

Taichi adopts a data-oriented programming (DOP) scheme that separates computation from data layouts so that users can experiment with different layouts for memory access optimization without rewriting the code. Considering that DOP makes modularization difficult, Taichi borrows some concepts from the object-oriented programming (OOP) design and calls the hybrid scheme objective data-oriented programming (ODOP)[14].

ODOP allows users to organize data and methods in a class and call the methods to manipulate the data in the Taichi scope.

Quantization[edit]

High-resolution simulations can deliver great visual quality, but are often limited by the capacity of the onboard memory, GPU memory in particular. To reduce the memory footprint of programs, Taichi provides quantized data types. This feature allows users to store data of arbitrarily low precision bits without changing the code for computation. In some cases, Taichi's quantized data types can reduce the use of GPU memory by up to 8x[2].

Autodiff[edit]

Differentiable programming is an important advanced feature of Taichi (DiffTaichi)[2][15]. Taichi supports two modes of automatic differentiation (autodiff): reverse mode and forward mode.

When implementing reverse-mode autodiff, Taichi generates gradient kernels at compile time with the built-in Source Code Transformation (SCT) mechanism and then uses the lightweight tape in the Python scope to record the launched kernels and replay them in reverse order. Since v.1.1.0, Taichi has enabled forward-mode autodiff, which computes Jacobian-vector product (Jvp) when evaluating derivatives. Forward-mode autodiff is more efficient than reverse mode if the number of a function's outputs is greater than its inputs[16].

Efficient mesh-based operations[edit]

Mesh-based operations are usually slow due to unstructured memory access patterns. Taichi designs a compiler MeshTaichi to handle such operations in a more efficient way. The compiler provides an intuitive programming model that allows users to write mesh-based operations using reference-style neighborhood queries. It also decouples optimization from computation, making it possible to explore different localized data attributes and different memory orderings without modification of the computation code[17].

Ahead-of-time (AOT) module[edit]

Though choosing Python as the frontend, Taichi is not subject to the restrictions of Python's heavy virtual machine design when it comes to deployment. To facilitate deployment in real-life industrial scenarios, Taichi provides a built-in ahead-of-time (AOT) system for exporting Python code as binary/shader files, which can then be called in C/C++ and run without the Python environment[5].

In August 2022, a series of 3D physical simulation wallpapers co-developed by OPPO and Taichi Lang was officially launched[18], and Taichi AOT provides the key technical support behind.

Applications[edit]

Accelerate Python[edit]

Taichi differs from Python in the following aspects[19]:

Taichi can take over compute-intensive tasks from Python with two decorators @ti.func and @ti.kernel. Its JIT compiler compiles the decorated functions to machine code, and all subsequent calls to these functions are executed on multi-core CPUs or GPUs.

Accelerate PyTorch[edit]

PyTorch is an open-source deep learning framework. Taichi can complement PyTorch in data preprocessing and ML operator customization in that it provides finer control over parallelization and enables element-level operations[20].

Physical simulation[edit]

A typical example showing Taichi's advantages in physical simulation is Taichi Elements[21], which is a high-performance multi-material continuum physics engine applicable to multi-threaded CPUs and massively parallel GPUs.

In Fall 2021, the Computer Graphics Laboratory (CGL) at ETH Zurich offered a course on physically-based simulation, and most of the student groups chose Taichi for real-time physical simulation[22].

Differentiable programming in Taichi also optimizes neural network controllers efficiently with brute-force gradient descent, significantly boosting the performance and productivity of differentiable physical simulators[23][3]. Given that the simulation process normally does not provide gradients for planning and control optimizations, a differentiable physics benchmark, PasticineLab, was devised, which supports differentiable elastic and plastic deformation using the DiffTaichi system[24].

Image processing[edit]

Python is widely used for image processing due to fast algorithm prototyping and verification. OpenCV, a popular image processing library, also provides a Python encapsulation so that users can write Python code to call underlying C++ algorithms and get performance gains. However, some image processing algorithms are not supported by OpenCV, and iterating over pixels in Python can be slow. Taichi can complement OpenCV and accelerate image processing in Python based on its automatic parallelization mechanism and ability to switch between CPU and GPU execution[25].

Computational fluid dynamics (CFD)[edit]

CFD is a branch of fluid mechanics that endeavors to precisely reproduce the behavior of liquid/gas flows and their interaction with solid boundaries. The most compute-intensive step in CFD is the discretization of differential equations, which involves massive operations of 2D or 3D data arrays. Taichi's data container makes the representation of a flow field intuitive, and the automatic parallelization mechanism saves computational time[26].

Rendering[edit]

Taichi is also used for rendering, including path tracing, because of its cross-platform compatibility. For example, bsavery implemented Ray Tracing in One Weekend using Python and Taichi[27]

References[edit]

  1. taichi-dev/taichi, Taichi Developers, 2022-12-21, retrieved 2022-12-21
  2. 2.0 2.1 2.2 2.3 Hu, Yuanming (June 2021). The Taichi High-Performance and Differentiable Programming Language for Sparse and Quantized Visual Computing (Thesis). Massachusetts Institute of Technology. hdl:1721.1/139327.
  3. 3.0 3.1 Hu, Yuanming; Anderson, Luke; Li, Tzu-Mao; Sun, Qi; Carr, Nathan; Ragan-Kelley, Jonathan; Durand, Frédo (2019-10-01). "DiffTaichi: Differentiable Programming for Physical Simulation". arXiv:1910.00935.
  4. "Releases · taichi-dev/taichi". GitHub. Retrieved 2022-12-22.
  5. 5.0 5.1 Cao, Cheng (May 13, 2022). "Compatibility, Maintainability, and Portability Improvements to the Taichi Graphics Programming Frameworks" (PDF). Electrical Engineering and Computer Sciences University of California, Berkeley. Retrieved December 22, 2022.
  6. "Why a New Programming Language | Taichi Docs". docs.taichi-lang.org. Retrieved 2022-12-22.
  7. "Kernels and Functions | Taichi Docs". docs.taichi-lang.org. Retrieved 2022-12-22.
  8. "Hello, World! | Taichi Docs". docs.taichi-lang.org. Retrieved 2022-12-22.
  9. "Interacting with External Arrays | Taichi Docs". docs.taichi-lang.org. Retrieved 2022-12-22.
  10. 10.0 10.1 Hu, Yuanming; Li, Tzu-Mao; Anderson, Luke; Ragan-Kelley, Jonathan; Durand, Frédo (2019-11-08). "Taichi: a language for high-performance computation on spatially sparse data structures". ACM Transactions on Graphics. 38 (6): 201:1–201:16. doi:10.1145/3355089.3356506. ISSN 0730-0301. Unknown parameter |s2cid= ignored (help)
  11. Hu, Yuanming; Xu, Mingkuan; Kuang, Ye; Durand, Frédo (2021-06-22). "AsyncTaichi: On-the-fly Inter-kernel Optimizations for Imperative and Spatially Sparse Programming". arXiv:2012.08141.
  12. "GUI System | Taichi Docs". docs.taichi-lang.org. Retrieved 2022-12-22.
  13. "A New UI system: GGUI | Taichi Docs". docs.taichi-lang.org. Retrieved 2022-12-22.
  14. "Objective Data-oriented Programming | Taichi Docs". docs.taichi-lang.org. Retrieved 2022-12-22.
  15. Hu, Yuanming; Anderson, Luke; Li, Tzu-Mao; Sun, Qi; Carr, Nathan; Ragan-Kelley, Jonathan; Durand, Frédo (2020-02-14). "DiffTaichi: Differentiable Programming for Physical Simulation". arXiv:1910.00935.
  16. "Release v1.1.0 · taichi-dev/taichi". GitHub. Retrieved 2022-12-22.
  17. Yu, Chang; Xu, Yi; Kuang, Ye; Hu, Yuanming; Liu, Tiantian (2022-11-30). "MeshTaichi: A Compiler for Efficient Mesh-Based Operations". ACM Transactions on Graphics. 41 (6): 252:1–252:17. doi:10.1145/3550454.3555430. ISSN 0730-0301. Unknown parameter |s2cid= ignored (help)
  18. "OPPO to Showcase Technology Innovations Including Ray Tracing and Heterogeneous Computing at SIGGRAPH 2022 | OPPO Global". OPPO. Retrieved 2022-12-22.
  19. Hu, Yuanming (2022-08-22). "Accelerate Python code 100x by import taichi as ti". Medium. Retrieved 2022-12-22.
  20. "Accelerate PyTorch with Taichi | Taichi Docs". docs.taichi-lang.org. Retrieved 2022-12-22.
  21. Taichi Elements, Taichi Developers, 2022-12-22, retrieved 2022-12-22
  22. "CGL @ ETHZ - Physically-based Simulation - AS 21". cgl.ethz.ch. Retrieved 2022-12-22.
  23. "Taichi: A Brand New Programming Language, "Frozen" in 99 Lines of Code". FineReport. 2020-02-05. Retrieved 2022-12-22.
  24. Huang, Zhiao; Hu, Yuanming; Du, Tao; Zhou, Siyuan; Su, Hao; Tenenbaum, Joshua B.; Gan, Chuang (2021-04-07). "PlasticineLab: A Soft-Body Manipulation Benchmark with Differentiable Physics". arXiv:2104.03311.
  25. Hu, Yuanming (2022-11-14). "How Taichi Fuels GPU-accelerated Image Processing: A Beginner to Expert Guide". Parallel-Programming-in-Python. Retrieved 2022-12-22.
  26. Bao, Qian (2022-12-01). "Can Taichi play a role in CFD?". Medium. Retrieved 2022-12-22.
  27. bsavery (2022-12-12), ray-tracing-one-weekend-taichi, retrieved 2022-12-22


This article "Taichi Lang" is from Wikipedia. The list of its authors can be seen in its historical and/or the page Edithistory:Taichi Lang. Articles copied from Draft Namespace on Wikipedia could be seen on the Draft Namespace of Wikipedia and not main one.