GithubHelp home page GithubHelp logo

dsseng / rust-tf-pluggabledevice Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 43 KB

A reference TensorFlow PluggableDevice implementation, in Rust

Rust 95.83% Python 2.85% C++ 1.32%
tensorflow2 ffi-bindings rust tensorflow tpu tpu-acceleration

rust-tf-pluggabledevice's Introduction

Rust TensorFlow PluggableDevice

Ported over from tensorflow/community#352

The tfp-bindings crate mostly provides unsafe bindings to all TensorFlow C APIs required by plug-ins via libtensorflow_framework.so.2 library (yes, and currently in only supports Linux and Python 3.10). It also has some should-be-safe bindings to main functions required by compute kernels and their registration. Its safety mostly relies on validating data, checking result codes and asserts in debug mode to prevent common plug-in issues like unterminated strings.

Plugin itself (tfp-plugin) should link to that library via its build.rs script and implement SE_InitPlugin and TF_InitKernel functions with proper types (these are excluded from bindgen). It may also include optimizer, but it is not yet implemented in this repository.

Requirements

  • Linux, tested on Fedora 36, any should work fine.
  • MSRV not yet specified, I use nightly. No strict limits are being set.
  • Python 3 for test script. pip3 and venv to install TensorFlow
  • clang for binding generation via bindgen

Usage in other packages

You can import the bindings crate by using such a dependency string. There are environment variables you can use to point the paths to TensorFlow library:

  • TF_INCLUDE_PATH
  • TF_LIBRARY_PATH

They could be set, for example, by Cargo project config

Cargo.toml example. Replace x by needed commit hash.

tfp-bindings = { git = "https://github.com/sh7dm/rust-tf-pluggabledevice", rev = "x" }

Try it out

python3.10 -m venv venv
source venv/bin/activate
pip3 install --no-cache-dir tf-nightly-cpu # or tensorflow-cpu
# https://github.com/tensorflow/tensorflow/issues/55497
mv venv/lib64 venv/_lib64
cargo build
mkdir venv/lib/python3.10/site-packages/tensorflow-plugins/
cp target/debug/libtfp.so venv/lib/python3.10/site-packages/tensorflow-plugins/
python3 test.py
import tensorflow as tf
tf.config.list_physical_devices()

Running tests

Specifying LD_LIBRARY_PATH manually is necessary as of rust-lang/cargo#4044

LD_LIBRARY_PATH=$(pwd)/venv/lib/python3.10/site-packages/tensorflow cargo test

rust-tf-pluggabledevice's People

Contributors

dsseng avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.