Skip to main content

Development tips

This section gives you some tips on the Taichi compiler development. Please make sure you have gone through developer installation.

Workflow of the Taichi compiler#

Life of a Taichi kernel is a good place to get started, which explains the whole compilation process step by step.

Folder structure#

Key folders: (the following chart can be generated by tree . -L 2)

.โ”œโ”€โ”€ benchmarks              # Performance benchmarksโ”œโ”€โ”€ docs                    # Documentationโ”œโ”€โ”€ examples                # Examplesโ”œโ”€โ”€ external                # External librariesโ”œโ”€โ”€ misc                    # Random yet useful filesโ”œโ”€โ”€ python                  # Python frontend implementationโ”‚ย ย  โ”œโ”€โ”€ core                # Loading & interacting with Taichi coreโ”‚ย ย  โ”œโ”€โ”€ lang                # Python-embbed Taichi language & syntax (major)โ”‚ย ย  โ”œโ”€โ”€ snode               # Structure nodesโ”‚ย ย  โ”œโ”€โ”€ tools               # Handy end-user toolsโ”‚ย ย  โ””โ”€โ”€ misc                # Miscellaneous utilitiesโ”œโ”€โ”€ taichi                  # The core compiler implementation: C++ source of libtaichi_core.soโ”‚ย ย  โ”œโ”€โ”€ analysis            # Static analysis passesโ”‚ย ย  โ”œโ”€โ”€ backends            # Device-dependent code generators/runtime environmentsโ”‚ย ย  โ”œโ”€โ”€ codegen             # Code generation base classesโ”‚ย ย  โ”œโ”€โ”€ common              # Common headersโ”‚ย ย  โ”œโ”€โ”€ gui                 # GUI systemโ”‚ย ย  โ”œโ”€โ”€ inc                 # Small definition files to be included repeatedlyโ”‚ย ย  โ”œโ”€โ”€ ir                  # Intermediate representationโ”‚ย ย  โ”œโ”€โ”€ jit                 # Just-In-Time compilation base classesโ”‚ย ย  โ”œโ”€โ”€ llvm                # LLVM utilitiesโ”‚ย ย  โ”œโ”€โ”€ math                # Math utilitiesโ”‚ย ย  โ”œโ”€โ”€ platform            # Platform supportsโ”‚ย ย  โ”œโ”€โ”€ program             # Top-level constructsโ”‚ย ย  โ”œโ”€โ”€ python              # C++/Python interfacesโ”‚ย ย  โ”œโ”€โ”€ runtime             # LLVM runtime environmentsโ”‚ย ย  โ”œโ”€โ”€ struct              # Struct compiler base classesโ”‚ย ย  โ”œโ”€โ”€ system              # OS-related infrastructureโ”‚ย ย  โ”œโ”€โ”€ transforms          # IR transform passesโ”‚ย ย  โ””โ”€โ”€ util                # Miscellaneous utilitiesโ””โ”€โ”€ tests                   # Functional tests    โ”œโ”€โ”€ cpp                 # Python tests (major)    โ””โ”€โ”€ python              # C++ tests

C++ and Python standards#

The C++ part of the Taichi compiler is written in C++17, and the Python part in 3.6+. You can assume that C++17 and Python 3.6 features are always available.

Efficient code navigation across Python/C++#

If you are working on the language frontend (Python/C++ interface), you may want to navigate across Python/C++ code. ffi-navigator allows you to jump from Python bindings to their definitions in C++. Please follow their README to set up your editor.

Printing IRs in different stages#

When creating a Taichi program using ti.init(arch=desired_arch, **kwargs), pass in the following parameters to make the Taichi compiler print out IRs in different stages:

  • print_ir=True: print the Taichi IR transformation process of kernel (excluding accessors) compilation.
  • print_accessor_ir=True: print the IR transformation process of data accessors, which are special and simple kernels. This is rarely used, unless you are debugging the compilation of data accessors.
  • print_struct_llvm_ir=True: save the emitted LLVM IR by Taichi struct compilers.
  • print_kernel_llvm_ir=True: save the emitted LLVM IR by Taichi kernel compilers.
  • print_kernel_llvm_ir_optimized=True: save the optimized LLVM IR of each kernel.
  • print_kernel_nvptx=True: save the emitted NVPTX of each kernel (CUDA only).

Data accessors in Python-scope are implemented as special Taichi kernels. For example, x[1, 2, 3] = 3 will call the writing accessor kernel of x, and print(y[42]) will call the reading accessor kernel of y.


See Benchmarking and regression tests if your work involves IR optimization.