In this repo you can find a couple examples in Taichi regarding the computation of Julia sets and solving the Gray-Scott equations in 2d.
Find out more! Here's a link to a blog post going more in detail.
Taichi is a compiler and a library. The library adds python bindings to C++ to allow the programmer for transparent use of advanced parallelization and GPGPU; whereas the compiler let's you compile said python code with llvm and reap the benefits of:
- coding in a high-level, high-productivity language like python
- running in a optimized framework for parallel CPU, GPU computing.
In other words, Taichi sort of extends the Python language and overloads it with high-performance parallel capabilities.
The main change Taichi will make in your code is: you get for
loops back!
Numba is very similar in purpose and interface to Taichi. Both are "extension languages" to base Python using decorators to allow for easy parallelization, and both target GPU and CPU parallelization.
I'm not familiar with Numba, to be honest. However, some benchmarks seem to indicate that Taichi is more efficient, in fact, Taichi code usually outperforms native CUDA (which is impressive); plus, Taichi lets you target CPU and GPU with a single kernel (instead of having to write different functions as in Numba). Finally, Taichi has autodiff out of the box.
In my opinion, Taichi is a more modern, and seemingly better, option than Numba for the use case of high-performance computing.
I was interested in Taichi because I do ML, and it offered potential for integration with Pytorch, with interesting use cases for computer vision, LiDAR and hybridizing mathematical optimization with DL.
As a first contact with the language, I decided to follow the "hello world" example to compute Julia sets and then attempt to (by myself) code a simple solver for the Gray Scott system of equations, adapting the code from a previous numpy code I had.
disclaimer: you can find another G-S implementation in the Taichi blog, which I didn't know of at the time of writing my first Taichi implementation. Upon discovering it, it influenced my code somewhat.
It's basically a 1:1 writing of the mentioned "hello world" example. A result can be seen here:
To run the code, use:
ti run src/fractals/julia_ti.py
I adapted the code from a previous one I had which used numpy, then explored the Object-Oriented capabilities of Taichi to refactor the code into something (marginally) better.
You can see the results here:
and run the code using:
ti run src/sim/gray_scott_ti.py
The original numpy code can be inspected, too: original.
This is merely a simple initial contact with Taichi. I have liked the library a lot and would like to use it more, so I probably will.
If you have any comment, open a discussion in the repository!