I had quite a pain trying to compile Tensorflow so here is a guide including patches.
First off, you need clang 3.8 or later (That means you need FreeBSD 11.0-RELEASE or later)
Guide last updated 2017-06-05 to work with Tensorflow 1.1.0
First off, you need clang 3.8 or later (That means you need FreeBSD 11.0-RELEASE or later)
Guide last updated 2017-06-05 to work with Tensorflow 1.1.0
- Let's start by switching your pkg repo to latest instead of quarterly:
Open up /etc/pkg/FreeBSD.conf and change URL to
Code:url: "pkg+http://pkg.FreeBSD.org/${ABI}/latest",
Runpkg update -f && pkg upgrade
to get you up to date.
- Now, lets install all the dependencies:
pkg install bazel protobuf re2 python27 py27-pip py27-protobuf py27-numpy py27-wheel py27-mock py27-werkzeug git
- Download Tensorflow
cd ~
git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow
git checkout v1.1.0
- We can now run configure:
./configure
- Not quite out of the woods yet, now we need to apply some changes.
We have to symlink our python2.7 binary to python
cd /usr/local/bin
ln -s python2.7 python
Now let's start a build run so bazel extracts all dependencies:
cd ~/tensorflow
bazel build --jobs 8 -c opt //tensorflow/tools/pip_package:build_pip_package --verbose_failures
Note that --jobs 8 is the number of cores my CPU has, please adjust this to match your server, do note that they will all be utilized 100% for a few moments during the build.
At this point you will get a error, thats okay, bazel has now extracted all the dependencies so we can apply the needed changes.
- In your tensorflow folder you now have a bazel-tensorflow folder (that is if you have followed this guide, if you named your git clone target to something else, the folder will be named bazel-<yournameofthefolder>
Now let's make the needed changes- Open bazel-tensorflow/external/grpc/include/grpc/impl/codegen/port_platform.h and delete all rows stating
Code:
#define GPR_HAVE_IP_PKTINFO 1
- Apply all protobuf patches from ports:
cd bazel-tensorflow/external/protobuf
fetch "https://svnweb.freebsd.org/ports/head/devel/protobuf/files/patch-src-google-protobuf-compiler-plugin.pb.cc?revision=432762&view=co&pathrev=439752"
fetch "https://svnweb.freebsd.org/ports/head/devel/protobuf/files/patch-src-google-protobuf-compiler-plugin.pb.h?revision=432762&view=co&pathrev=439752"
fetch "https://svnweb.freebsd.org/ports/head/devel/protobuf/files/patch-src-google-protobuf-testing-zcgunzip.cc?revision=428734&view=co&pathrev=439752"
fetch "https://svnweb.freebsd.org/ports/head/devel/protobuf/files/patch-src-google-protobuf-testing-zcgzip.cc?revision=428734&view=co&pathrev=439752"
fetch "https://svnweb.freebsd.org/ports/head/devel/protobuf/files/patch-src-google-protobuf-stubs-atomicops.h?revision=428734&view=co&pathrev=439752"
patch < patch-src-google-protobuf-compiler-plugin.pb.cc\?revision\=432762\&view\=co\&pathrev\=439752
patch < patch-src-google-protobuf-compiler-plugin.pb.h\?revision\=432762\&view\=co\&pathrev\=439752
patch < patch-src-google-protobuf-stubs-atomicops.h\?revision\=428734\&view\=co\&pathrev\=439752
patch < patch-src-google-protobuf-testing-zcgunzip.cc\?revision\=428734\&view\=co\&pathrev\=439752
patch < patch-src-google-protobuf-testing-zcgzip.cc\?revision\=428734\&view\=co\&pathrev\=439752
- Open bazel-tensorflow/external/grpc/include/grpc/impl/codegen/port_platform.h and delete all rows stating
- We can now restart the build and this time it will finish
cd ~/tensorflow
bazel build --jobs 8 -c opt //tensorflow/tools/pip_package:build_pip_package --verbose_failures
- Now let's build the pip package
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
- Last part, su to root and install the pip package
su
pip install /tmp/tensorflow_pkg/tensorflow-1.1.0-cp27-cp27mu-freebsd_11_0_RELEASE_p9_amd64.whl
Note that the filename is based on what version of FreeBSD you are running so match the filename to the one thats present in your /tmp/tensorflow_pkg/ folder.
Last edited: