taichi-dev / taichi

Productive, portable, and performant GPU programming in Python.
https://taichi-lang.org
Apache License 2.0
25.37k stars 2.27k forks source link

Feature request: Official Rust bindings #2357

Open Milo123459 opened 3 years ago

Milo123459 commented 3 years ago

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

k-ye commented 3 years ago

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 :-)

Milo123459 commented 3 years ago

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.

k-ye commented 3 years ago

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.
Milo123459 commented 2 years ago

Hey,

Have there been any updates on this?

k-ye commented 2 years ago

@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 :-) ?

PENGUINLIONG commented 2 years ago

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. :)