Let's compile TensorFlow ourselves with AVX vector instruction to speed up inference on a CPU.
https://www.tensorflow.org/install/install_sources#prepare_environment_for_mac_os tensorflow/tensorflow#12979
- fix checksum in tensorflow/workspace.bzl
- e5fdeee6b28cf6c38d61243adff06628baa434a22b5ebb7432d2a7fbabbdb13d but wanted 6d43b9d223ce09e5d4ce8b0060cb8a7513577a35a64c7e3dad10f0703bf3ad93
- comment the sha256 checksums tensorflow/tensorflow#6729
brew install bazel
export CUDA_HOME=/usr/local/cuda
export DYLD_LIBRARY_PATH=/usr/local/cuda/lib:/usr/local/cuda/extras/CUPTI/lib
export LD_LIBRARY_PATH=$DYLD_LIBRARY_PATH
export PATH=$DYLD_LIBRARY_PATH:$PATH
bazel build --config=opt --config=cuda --action_env PATH --action_env LD_LIBRARY_PATH --action_env DYLD_LIBRARY_PATH //tensorflow/tools/pip_package:build_pip_package
error: ld: library not found for -lgomp (missing OpenMP) tensorflow/tensorflow#9072
still:
ld: warning: cannot export hidden symbol std::__1::__vector_base<tensorflow::graph_transforms::OpTypePattern, std::__1::allocator<tensorflow::graph_transforms::OpTypePattern> >::__destruct_at_end(tensorflow::graph_transforms::OpTypePattern*) from bazel-out/local_darwin-py3-opt/bin/tensorflow/tools/graph_transforms/libtransforms_lib.pic.lo
Let's build it without CUDA (on OSX we don't need it anyway).
bazel clean
./configure
bazel build --config=opt --action_env PATH --action_env LD_LIBRARY_PATH --action_env DYLD_LIBRARY_PATH //tensorflow/tools/pip_package:build_pip_package
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
pip install /tmp/tensorflow_pkg/tensorflow-1.3.0-py3-none-any.whl
In the end it worked on OSX without CUDA. It doesn't show SSE/AVX warnings, but no observable speedup.
install both libcudnn6 and libcudnn6
git clone https://github.com/tensorflow/tensorflow
cd tensorflow
git checkout r1.3
export CUDA_HOME=/usr/local/cuda
./configure
- cuda: y
- cudnn path: /usr/lib/x86_64-linux-gnu
- select python version you're be using the pip package with (eg. 3.5 vs. 3.6!)
- otherwise: tensorflow-1.3.0-cp35-cp35m-linux_x86_64.whl is not a supported wheel on this platform.
bazel build --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
pip install /tmp/tensorflow_pkg/tensorflow-1.3.0-py3-none-any.whl
# avoid ImportError: No module named 'tensorflow.python.pywrap_tensorflow_internal'
cd
# test installation
python -c 'import tensorflow'
Elapsed time: 3163.185s, Critical Path: 126.07s INFO: Build completed successfully, 4559 total actions