Skip to content

Instantly share code, notes, and snippets.

@huafengw
Created February 23, 2017 07:01
Show Gist options
  • Save huafengw/79602dedb922ddcc0413061ae7274446 to your computer and use it in GitHub Desktop.
Save huafengw/79602dedb922ddcc0413061ae7274446 to your computer and use it in GitHub Desktop.
Build Tensorflow native shared library
# How to build Tensroflow native shared library
1. Download Tensorflow's source code to dicrectory ${TENSORFLOW_HOME}.
2. Prepare the build environemnt following the instructions from https://www.tensorflow.org/install/install_sources
3. Adding following code into file ${TENSORFLOW_HOME}/tensorflow/core/distributed_runtime/rpc/BUILD
```
cc_binary(
name = "libgrpc_tensorflow_server.so",
linkshared = 1,
srcs = [
"grpc_tensorflow_server.cc",
],
deps = [
":grpc_server_lib",
"//tensorflow/core:all_kernels",
"//tensorflow/core:core_cpu",
"//tensorflow/core:framework_internal",
"//tensorflow/core:lib",
"//tensorflow/core:protos_all_cc",
"//tensorflow/core/distributed_runtime:server_lib",
"@grpc//:grpc++_unsecure",
],
)
```
4. Enter dircetory ${TENSORFLOW_HOME}, then run following command
```
bazel build -c opt //tensorflow/core/distributed_runtime/rpc:libgrpc_tensorflow_server.so
```
5. Then we will get a shared library `libgrpc_tensorflow_server.so` located at ${TENSORFLOW_HOME}/bazel-bin/tensorflow/core/distributed_runtime/rpc
# How to build Tensorflow's JNI shared library
1. Get the source code of Tensorflow on Yarn project from https://github.com/Intel-bigdata/HDL
2. Build the library using command:
```
g++ -std=c++11 -shared -o libbridge.so -fPIC -I${JDK_HOME}/include -I${JDK_HOME}/include/linux/ -I${TENSORFLOW_HOME}/bazel-genfiles/ -I${TENSORFLOW_HOME} -L${TENSORFLOW_HOME}/bazel-bin/tensorflow/core/distributed_runtime/rpc -lgrpc_tensorflow_server ${HDL_HOME}/hadoop-deeplearning-project/YARN-TensorFlow/tensorflow-bridge/src/main/native/org_tensorflow_bridge_TFServer.cpp ${HDL_HOME}/hadoop-deeplearning-project/YARN-TensorFlow/tensorflow-bridge/src/main/native/exception_jni.cc
```
Please note when building against the latest Tensorflow 1.0, protoc 3.2 may be needed in your build environent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment