rust icon indicating copy to clipboard operation
rust copied to clipboard

rust target wasm32-wasi support?

Open chaozju opened this issue 5 years ago • 4 comments

I imported tensorflow modules for a detection demo.

In Cargo.toml

[dependencies]
tensorflow = "0.15.0"
tensorflow-sys = "0.18.0"

After cargo build --target=wasm32-wasi

error: linking with `rust-lld` failed: exit code: 1
  |
  = note: <long rust-lld instructions>
  = note: rust-lld: error: unable to find library -ltensorflow_framework
               rust-lld: error: unable to find library -ltensorflow

chaozju avatar Jul 26 '20 09:07 chaozju

This might be possible by using TensorFlow.js. It's not as simple as just targeting WASM, though.

adamcrume avatar Jul 26 '20 18:07 adamcrume

Hi @chaozju You might be interested in this article https://medium.com/wasm/ai-on-a-cloud-native-webassembly-runtime-wasmedge-part-i-3bf3714a64ea If you skip to the end you see that you can write Rust source code and compile to .Wasm and/or an Ahead Of Time (AOT) optimised version of your Rust/Wasm. This is not official WASI implementation. Instead, the Second State Wasm VM extends the WASI model to support access to native Tensorflow libraries from WebAssembly programs. You can read more about it here https://www.secondstate.io/articles/wasi-tensorflow/

I realise this does not answer your question in the context of this repo, however. I thought you might find this Wasm related information useful nonetheless.

Kind regards Tim

tpmccallum avatar Jul 18 '21 22:07 tpmccallum

Is it a pipe dream to compile TensorFlow to wasi? Ideally, I'd like to run my models at the edge in both Go and Rust and it seems easiest if I could just write wasm bindings instead of c bindings.

I was able to compile the TensorFlow Wasm JS backend to wasi without too much headache, but that just gives me access to some pretty low-level functions like FusedConv2D and Conv3DBackpropInputV2, rather than an API that I could actually use to load and invoke a tflite model. I assume much of this comes from the TensorFlow.js frontend library.

clarkmcc avatar May 12 '23 22:05 clarkmcc

It's not a pipe dream, but it would be an enormous undertaking. The underlying API is completely different, so it would basically require rewriting this entire library, and to be honest, I don't have the time for that. If someone is willing to take that on, I'd be happy to help design bits, review code, etc. This is the sort of project that would require an explicit up-front design.

adamcrume avatar May 30 '23 19:05 adamcrume