You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, is it possible to integrate Taichi into JAX?
Taichi is able to generate highly optimized operators, and it is very suitable to implement operators involving sparse computations. If Taichi kernels can be used in a JAX program, it will be interesting for broad programmers.
I think the key to the integration is the address of the compiled kernel in Taichi. There are examples that launch a GPU kernel compiled by Triton in JAX. Maybe it is straightforward for Taichi too.
Reacted by McCoy R. Becker, Mingrui Zhang, Jeroen Van Goey, Aman Salykov, Firas Al-Hafez and Jesse Farebrother
Reacted by Sharad Vikram, McCoy R. Becker, soraros, Chaoming Wang and Firas Al-Hafez
@chaoming0625 I'm by no means a JAX expert so my guess could be wrong. IIUC JAX device arrays don't give a raw ptr to storage in memory as PyTorch does, which making a torch-like integration (zero-copy) with Taichi for JAX kinda hard. Then if you have to copy the device array from JAX, copying it to numpy arrays or torch tensors so that Taichi can operate on those pretty efficiently, this could be a possible way to workaround?
Note taichi's sparse computation requires a specific datalayout (depending on your snode structure) in a root buffer managed by Taichi, dense numpy arrays/torch tensors are still the recommended way to interact with other librarys for those sparse fields.
This could make a zero-copy from JAX data to PyTorch tensor. This PyTorch tensor can then be used in Taichi kenerls. Finally, the tensors returned from the Taichi kernel can also be zero-copied to JAX.
I think this may be one possible solution.
Reacted by Ailing Zhang, mhr, Firas Al-Hafez and Christian Kothe
I just wanted to ask if there is any update on this issue or an alternative solution to @chaoming0625's. Do you plan to implement support for jax arrays via taichi.ndarray as it was done for pytorch?
@chaoming0625 Can you provide any more detailed examples / documentation of the function of braintaichi for fusing taichi and JAX? Is autograd still supported?
How about to support integration with JAX/tensorflow/pytorch via PJRT, which is a OpenXLA API for integration. I believe this can make taichi to work with existed machine learning model easier since the major frameworks are support to dump model to HLO.
Activity
ailzhang commentedon Oct 28, 2022
@chaoming0625 I'm by no means a JAX expert so my guess could be wrong. IIUC JAX device arrays don't give a raw ptr to storage in memory as PyTorch does, which making a torch-like integration (zero-copy) with Taichi for JAX kinda hard. Then if you have to copy the device array from JAX, copying it to numpy arrays or torch tensors so that Taichi can operate on those pretty efficiently, this could be a possible way to workaround?
Note taichi's sparse computation requires a specific datalayout (depending on your snode structure) in a root buffer managed by Taichi, dense numpy arrays/torch tensors are still the recommended way to interact with other librarys for those sparse fields.
chaoming0625 commentedon Oct 29, 2022
Dear @ailzhang , one way to interoperate JAX data with Taichi is using
dlpack:This could make a zero-copy from JAX data to PyTorch tensor. This PyTorch tensor can then be used in Taichi kenerls. Finally, the tensors returned from the Taichi kernel can also be zero-copied to JAX.
I think this may be one possible solution.
chaoming0625 commentedon Oct 30, 2022
We are just wondering where can get the address of the Taichi compiled kernels. Thanks.
ailzhang commentedon Oct 31, 2022
@chaoming0625 Sounds good! Taichi ndarrays are just contiguous memory so it should be pretty straightforward to support dl_pack format (although it doesn't yet).
Taichi compiled kernels are https://github.com/taichi-dev/taichi/blob/master/python/taichi/lang/kernel_impl.py#L574.
chaoming0625 commentedon Nov 1, 2022
Dear @ailzhang , that's wonderful. Thanks very much!
salykova commentedon May 9, 2023
Hi @ailzhang
I just wanted to ask if there is any update on this issue or an alternative solution to @chaoming0625's. Do you plan to implement support for jax arrays via taichi.ndarray as it was done for pytorch?
maedoc commentedon Oct 11, 2023
Also curious about this, since I'd like to use some packages written for Jax (numpyro specifically) and try out the taichi ad system.
jarmitage commentedon Dec 1, 2023
As further motivation, I would love to be able to tap into these JAX projects with Taichi:
chaoming0625 commentedon Dec 12, 2023
See examples in brainpy/BrainPy#553
westurner commentedon Jan 1, 2025
Would Taichi support in JAX create opportunities for e.g. JAX autograd in the Genesis simulation platform, which is built on Taichi?
https://github.com/Genesis-Embodied-AI/Genesis
chaoming0625 commentedon Jan 1, 2025
See https://github.com/chaobrain/braintaichi
lstrgar commentedon Sep 19, 2025
@chaoming0625 Can you provide any more detailed examples / documentation of the function of braintaichi for fusing taichi and JAX? Is autograd still supported?
link89 commentedon Jan 21, 2026
How about to support integration with JAX/tensorflow/pytorch via PJRT, which is a OpenXLA API for integration. I believe this can make taichi to work with existed machine learning model easier since the major frameworks are support to dump model to HLO.