Skip to content

Enhanced version of tensorflow/contrib/cmake. It provides cmake support for linux/mac compiling, cross-compiling for Arm.

License

Notifications You must be signed in to change notification settings

qfgaohao/tensorflow

 
 



If you compile for host linux, make sure you have cmake (version >= 3.10.2), gcc (version >= 6.3). If you also compile for arm, make sure your toolchain's attribute CMAKE_SYSTEM_PROCESSOR contains "arm", "Arm", or "ARM", as I use this attribute to detect cross-compiling. It's been tested for linux host, armv8-a.

Compile for host Linux

cd tensorflow/contrib/cmake
mkdir x86    # if you also want to cross-compile later, do NOT change the directory name.
cd x86
cmake ..  -DCMAKE_BUILD_TYPE=Release -Dtensorflow_BUILD_PYTHON_BINDINGS=OFF -Dtensorflow_BUILD_SHARED_LIB=ON
make -j$(nproc)

The output is in the directory "x86". The shared library is libtensorflow.so. The protoc tool sits in the sub-folder "protobuf/src/protobuf". If you want to use the C++ api, you need to run several times of protoc commands to generate source files. The following cross-compiling process will also invoke this command to generate source files.

Cross-Compile

Make sure you have finished the last step and have the compiled results in the directory "x86".

cd tensorflow/contrib/cmake
mkdir arm
cd arm
cmake ..  -DCMAKE_BUILD_TYPE=Release -Dtensorflow_BUILD_PYTHON_BINDINGS=OFF -Dtensorflow_BUILD_SHARED_LIB=ON -DCMAKE_TOOLCHAIN_FILE=<YOU TOOLCHAIN FILE>
make -j$(nproc)

Others

For both of the above cmake commands, you may also pass in "-Dtensorflow_BUILD_CONTRIB_KERNELS=OFF", if you don't need it in your library.

Details

  1. changed the executable programs for cross-compling.
  2. added "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}" for third-party dependences that use cmake to build.
  3. added "--host=aarch64-linux-gnu" for third-party dependences that use autoconfig/make to build.
  4. changed the urls of the some third-party dependences to the ones bazel currently uses for building tensorflow.

TODO

  1. make a minimum runtime library for inference.

About

Enhanced version of tensorflow/contrib/cmake. It provides cmake support for linux/mac compiling, cross-compiling for Arm.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 47.8%
  • Python 40.8%
  • HTML 5.7%
  • Jupyter Notebook 2.4%
  • Go 1.3%
  • Java 0.7%
  • Other 1.3%