Difference between revisions of "Compiling Tensorflow from sources"
Line 107: | Line 107: | ||
strip_files = "arm_linux_all_files", | strip_files = "arm_linux_all_files", | ||
supports_param_files = 1, | supports_param_files = 1, | ||
+ | ) | ||
+ | |||
+ | Add to the end of the file WORKSPACE: | ||
+ | |||
+ | new_local_repository( | ||
+ | name = 'toolchain_target_armv7l', | ||
+ | path = '/home/fabio/gcc-linaro-4.8-2015.06-x86_64_arm-linux-gnueabihf', | ||
+ | build_file = 'arm_compiler.BUILD' | ||
) | ) |
Revision as of 16:55, 21 July 2018
Compiling Tensorflow from sources
First of all, we need a clean Ubuntu VM. I installed an Ubuntu 18.04LTS x86_64 with 80GB HD, 4 CPUs and 4GB of RAM.
After installing and setting the network, update:
apt-get update apt-get upgrade
Then install basic tools:
apt-get install python3-numpy python3-dev python3-pip python3-wheel
Then, download and install Bazel:
wget https://github.com/bazelbuild/bazel/releases/download/0.15.2/bazel-0.15.2-linux-x86_64.deb apt-get install ./bazel-0.15.2-linux-x86_64.deb
Then, download and extract Tensorflow source code:
wget https://github.com/tensorflow/tensorflow/archive/v1.9.0.tar.gz tar xvfz v1.9.0.tar.gz cd tensorflow-1.9.0
and configure it:
./configure
During the configuration, specify the python location (in this case, /usr/bin/python3) and just accept the defaults.
After that, it's time to compile:
bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
during the compilation process, it may show many warnings.
The entire process will take about 2-3 hours.
To create a pip package:
./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
Under /tmp/tensorflow_pkg there will be the pip package: tensorflow-1.0-cp36-linux_x86_64.whl
It can be moved to the target machine and installed:
pip install /tmp/tensorflow_pkg/tensorflow-1.0-cp36-linux_x86_64.whl
Cross Compiling for Nanopi Neo (arm)
Download the toolchain gcc-linaro-arm.tar.xz from http://download.friendlyarm.com/nanopineo and uncompress it.
tar xvf gcc-linaro-arm.tar.xz
Then, since we are in a pure x64 architecture, we need to add i386 architecture:
dpkg --add-architecture i386 apt-get update apt-get install gcc-multilib apt-get install zlib1g:i386
so we are able to use the toolchain.
Ricordarsi:
apt-get install python-dev
bazel build --cpu=armv7l --crosstool_top=//:toolchain --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --config=opt //tensorflow/tools/pip_package:build_pip_package --verbose_failures
files (lasciato invariato l'arm compiler build)
bug da editare dopo il clean
File BUILD:
package(default_visibility = ["//visibility:public"]) cc_toolchain_suite( name = "toolchain", toolchains = { "armv7l|compiler": ":cc-compiler-armv7l", }, ) filegroup( name = "empty", srcs = [], ) filegroup( name = "arm_linux_all_files", srcs = [ "@toolchain_target_armv7l//:compiler_pieces", ], ) cc_toolchain( name = "cc-compiler-armv7l", all_files = ":arm_linux_all_files", compiler_files = ":arm_linux_all_files", cpu = "armv7l", dwp_files = ":empty", dynamic_runtime_libs = [":empty"], linker_files = ":arm_linux_all_files", objcopy_files = "arm_linux_all_files", static_runtime_libs = [":empty"], strip_files = "arm_linux_all_files", supports_param_files = 1, )
Add to the end of the file WORKSPACE:
new_local_repository( name = 'toolchain_target_armv7l', path = '/home/fabio/gcc-linaro-4.8-2015.06-x86_64_arm-linux-gnueabihf', build_file = 'arm_compiler.BUILD' )