taichi icon indicating copy to clipboard operation
taichi copied to clipboard

Feature request: Official Rust bindings

Open Milo123459 opened this issue 4 years ago • 6 comments

Concisely describe the proposed feature A clear and concise description of what you want. For example,

Add official bindings to the Rust Programming Language

Describe the solution you'd like (if any) A clear and concise description of what you want to achieve and implement. Add official bindings, and publish it to crates.io Additional comments Add any other context or screenshots about the feature request here. N/A

Milo123459 avatar May 20 '21 14:05 Milo123459

Hi, would you roughly describe what's your need? We currently have no expertise on Rust. But if you are interested, it might be possible for us to work out a solution together. Thanks :-)

k-ye avatar May 27 '21 13:05 k-ye

Hi! I'd love to help add Taichi to Rust, so I'm here to help! Taichi is deeply embedded into Python, so can we embed it deeply into Rust is my question.

Milo123459 avatar May 27 '21 13:05 Milo123459

Hi! I'd love to help add Taichi to Rust, so I'm here to help! Taichi is deeply embedded into Python, so can we embed it deeply into Rust is my question.

Sounds great!

A significant part of Taichi is actually written in C++ and compiled to a shared library. While only a few developers might understand what's going on internally, it shouldn't be too much work to wrap this part into Rust.

Another option is to use the LLVM bitcode that is JIT compiled by taichi. #2355 requests a similar feature and we're actually working on it.

Either way, I'd suggest to try the following steps to quickly get yourself familiar with Taichi:

  1. Install the developer installation: https://taichi.readthedocs.io/en/latest/dev_install.html
  2. Life of a taichi kernel: https://taichi.readthedocs.io/en/stable/compilation.html
  3. Write a very simple kernel, then use ti.init(print_preprocessed=True) to see how your @ti.kernel source code gets translated into C++ calls. These calls are used to construct an AST. Taichi uses pybind11 to expose the C++ interfaces that are used in Python. These interfaces are defined in https://github.com/taichi-dev/taichi/blob/master/taichi/python/export_lang.cpp.

k-ye avatar May 27 '21 13:05 k-ye

Hey,

Have there been any updates on this?

Milo123459 avatar Jul 15 '22 15:07 Milo123459

@PENGUINLIONG recently added a C-API binding for Taichi in https://github.com/taichi-dev/taichi/tree/master/c_api/include/taichi. Might be a good start to try these in Rust :-) ?

k-ye avatar Jul 15 '22 15:07 k-ye

I wonder how much you want to to work on the Rust language binding. Taichi basically has two parts: a compiler and a language runtime. Currently we have a host-language agnostic C-API for deployment, corresponding to the runtime portion. It would be easy to generate a Rust counterpart with bindgen.

But if you want to embed the Taichi compiler into Rust by, probably, procedural macro, then I think there exists a major blocker, that we don't have a common interface for grammar input. So, we might not be able to go that far, but the runtime interface could be a good starter. :)

PENGUINLIONG avatar Jul 16 '22 02:07 PENGUINLIONG