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).
note
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
.
Benchmarkingâ
See Benchmarking and regression tests if your work involves IR optimization.