Compiling TensorFlow on a mac with GPU is no longer officially supported. But it's still possible and a lot of fun(!) to compile.
I mainly followed this repo:
Here is a run down of everything I did:
- CUDA 9.2. See https://developer.nvidia.com/cuda-downloads?target_os=MacOSX&target_arch=x86_64&target_version=1013&target_type=dmgnetwork
- CUDNN 9.2. See https://docs.nvidia.com/deeplearning/sdk/cudnn-install/#installmac for setup.
- bazel 0.9.0. See https://github.com/bazelbuild/bazel/releases/tag/0.9.0
- Command line tools for XCode 8.3.2
$ gcc -v
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin17.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
- Suggested by users on this thread tensorflow/tensorflow#6729 (comment)
- How to: https://apple.stackexchange.com/questions/208478/how-do-i-disable-system-integrity-protection-sip-aka-rootless-on-macos-os-x
set -x CUDA_HOME /usr/local/cuda
set -x DYLD_LIBRARY_PATH $CUDA_HOME/lib $CUDA_HOME/extras/CUPTI/lib
set -x LD_LIBRARY_PATH $DYLD_LIBRARY_PATH
set -x PATH $DYLD_LIBRARY_PATH $PATH
vf new -p python3 tf-gpu-env
git clone git@github.com:xlvecle/tensorflow-macOS-gpu.git
cd tensorflow-macOS-gpu
pip install six wheel numpy
configure # See below for config file
bazel build --config=cuda \
--config=opt \
--action_env PATH \
--action_env LD_LIBRARY_PATH \
--action_env DYLD_LIBRARY_PATH \
//tensorflow/tools/pip_package:build_pip_package
- tensorflow/tensorflow#6729 (comment)
- tensorflow/tensorflow#9082
- https://stackoverflow.com/questions/39865212/dyld-library-not-loaded-rpath-libcudart-8-0-dylib-while-building-tensorflow?rq=1
Fixed by checking global environment variables set correctly, and disabling SIP (1 and 2).
Also did steps outlined in answer to 3.
Fixed by manually git cloning the offending packages.
Related to target '//tensorflow/contrib/learn:learn' depends on deprecated target '//tensorflow/contrib/session_bundle:exporter': No longer supported. Switch to SavedModel immediately.
Fixed by bazel clean
before running bazel build ...
again.
Related to ERROR: /private/var/tmp/_bazel_david/09b68378ff3e3379749d03980bf5893e/external/local_config_python/BUILD:143:1: declared output 'external/local_config_python/numpy_include/numpy/ndarrayobject.h' is a dangling symbolic link
Fixed by pip install --no-cache-dir --upgrade --force-reinstall numpy
.
(Was it worth the effort?!)
pip install tensorflow
- 1.52 x 10^3 steps per hour
Compiled from source:
- 1.49 x10^3 steps per hour
NVIDIA GeForce GT 750M 2048 MB Compute capability = 3.0