Skip to content

Instantly share code, notes, and snippets.

@davipatti
Last active July 30, 2018 03:05
Show Gist options
  • Save davipatti/16403a2a13ae8234c971a67f4d764250 to your computer and use it in GitHub Desktop.
Save davipatti/16403a2a13ae8234c971a67f4d764250 to your computer and use it in GitHub Desktop.
Compiling TensorFlow with GPU support on Mac

Compiling TensorFlow with GPU support on Mac

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:

Install this software

$ 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

Disable SIP

Set these global environment variables:

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

Run these commands

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

Some useful threads

Related to dyld: Library not loaded: @rpath/libcudart.9.2.dylib

  1. tensorflow/tensorflow#6729 (comment)
  2. tensorflow/tensorflow#9082
  3. 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.

Related to no such package '@grpc//'

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.


Extra info

Crude speed comparisons

(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

My graphics card:

NVIDIA GeForce GT 750M 2048 MB Compute capability = 3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment