Skip to content

Instantly share code, notes, and snippets.

  • Star 21 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save geekcui/d0800d62e377e0103b1cc2b889ed1128 to your computer and use it in GitHub Desktop.
macOS High Sierra 10.13.3 install TensorFlow 1.5.0 with GPU support

New compile referrence for TensorFlow 1.11.0:

macOS: 10.13.3

WebDriver: 387.

CUDA Toolkit: 9.1.128

cuDNN: 7

NVDAEGPUSupport: 6

XCode: 8.2

Bazel: 0.9.0

OpenMP: latest

Python: 3.6

TensorFlow: 1.5.0

eGPU part

1 Remove/undo any Info.plist modifications (they aren’t needed anymore and might conflict).

2 Disable SIP

  • Restart holding command + r
  • Execute 'csrutil disable’
  • Restart

3 Install WebDriver with

git clone
sudo ./ -u

4 Enable SIP

  • Restart holding command + r
  • Execute 'csrutil enable --without kext’
  • Restart

5 Install nvidia-egpu

6 Check eGPU status

  • Reboot
  • Attach the egpu
  • Login
  • Check whether the GPU is recognized


1 Download packages




2 Install packages

  1. Install cuda_9.1.128_mac.dmg with default options

  2. Install cudadriver_387.128_macos.dmg with default options

  3. Install cuDNN

tar -zxf cudnn-9.1-osx-x64-v7-ga.tgz
cd cuda
sudo cp -RPf include/* /Developer/NVIDIA/CUDA-9.1/include/
sudo cp -RPf lib/* /Developer/NVIDIA/CUDA-9.1/lib/
sudo ln -s /Developer/NVIDIA/CUDA-9.1/lib/libcudnn* /usr/local/cuda/lib/

3 Add environment variables

vim ~/.zshrc
#if you use bash, this should be ~/.bash_profile
  export CUDA_HOME=/usr/local/cuda
  export PATH=$CUDA_HOME/bin:$PATH
source ~/.zshrc

3 Verify CUDA works fine

cd /Developer/NVIDIA/CUDA-9.1/samples/1_Utilities/deviceQuery
sudo make 

Homebrew part

1 Install homebrew

/usr/bin/ruby -e "$(curl -fsSL"

2 Install coreutils

brew install coreutils

3 Install OpenMP

brew install cliutils/apple/libomp

4 Install bazel

cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
git checkout bd8bba7e7 Formula/bazel.rb
brew remove bazel —force
brew install bazel
bazel version

5 Install anaconda

brew install anaconda
vim ~/.zshrc
#If you use bash, this should be ~/.bash_profile
  export PATH=/usr/local/anaconda3/bin:$PATH
source ~/.zshrc

Install XCode 8.2

sudo xcode-select -s /Applications/

You need restore xcode configuration or remove later, since it will break homebrew

sudo xcode-select -s /Applications/

Install TensorFlow

1 Add virtualenv and activate virtualenv

conda create --p egpu python=3.6
source activate egpu
pip install six numpy wheel

2 Clone TensorFlow code

git clone -b v1.5.0

3 Modify the code, to make it compatible with macOS

cd tensorflow
sed -i -e "s/ __align__(sizeof(T))//g" tensorflow/core/kernels/
sed -i -e "s/ __align__(sizeof(T))//g" tensorflow/core/kernels/
sed -i -e "s/ __align__(sizeof(T))//g" tensorflow/core/kernels/

4 Compile the code

  #Please specify the location of python.: Accept the default option
	#Please input the desired Python library path to use.:  Accept the default option
	#Do you wish to build TensorFlow with Google Cloud Platform support? [Y/n]: n
	#Do you wish to build TensorFlow with Hadoop File System support? [Y/n]: n
	#Do you wish to build TensorFlow with Amazon S3 File System support? [Y/n]: n
	#Do you wish to build TensorFlow with XLA JIT support? [y/N]: n
	#Do you wish to build TensorFlow with GDR support? [y/N]: n
	#Do you wish to build TensorFlow with VERBS support? [y/N]: n
	#Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: n
	#Do you wish to build TensorFlow with CUDA support? [y/N]: y
	#Please specify the CUDA SDK version you want to use, e.g. 7.0.: 9.1
	#Please specify the location where CUDA 9.1 toolkit is installed.: Accept the default option
	#Please specify the cuDNN version you want to use.: 7
	#Please specify the location where cuDNN 7 library is installed.: Accept the default option
	##Please specify a list of comma-separated Cuda compute capabilities you want to build with.
	##You can find the compute capability of your device at: (GTX10X0: 6.1, GTX9X0: 5.2)
	#Please note that each additional compute capability significantly increases your build time and binary size.: 6.1
	#Do you want to use clang as CUDA compiler? [y/N]: n
	#Please specify which gcc should be used by nvcc as the host compiler.: Accept the default option
	#Do you wish to build TensorFlow with MPI support? [y/N]: n
	#Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified:  Accept the default option
	#Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: n

export CUDA_HOME=/usr/local/cuda
export DYLD_LIBRARY_PATH=/usr/local/cuda/lib:/usr/local/cuda/extras/CUPTI/lib 

#bazel clean --expunge
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

5 Build the wheel and install

bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
sudo pip install /tmp/tensorflow_pkg/tensorflow-1.5.0-cp36-cp36m-macosx_10_7_x86_64.whl



gpu_options = tf.GPUOptions(allow_growth=True) 
with tf.Session(config=tf.ConfigProto(gpu_options=gpu_options)) as sess:

import keras.backend as K
config =
config.gpu_options.allow_growth = True
session =

2 PyCharm Library not loaded: @rpath/libcudnn.7.dylib

Add environment variables to python default configuration:




Copy link

Well written.! Thank you so much and it works perfectly

Copy link

andrediamant commented Mar 22, 2018

Hello! During the final bazel build, I get this:
"Closure Rules requires Bazel >=0.4.5 but was 0.11.1-homebrew".

I figure this may be an issue with 0.11, rather than the 0.9 that you used? Unfortunately, brew search bazel does not have any old versions to download.

Is there something else I'm missing? Thank you very much!

(I should point out that this command did not work: git checkout bd8bba7e7 Formula/bazel.rb)

Copy link

@andrediamant, this should answer your question...
tensorflow/tensorflow#16654 (comment)

Copy link

@aaronpenne Thank you for your help! This certainly enabled me to begin the compilation step.

Unfortunately, the compilation process itself now fails. Along with a wealth of warnings, this is the final error text. Any chance it is meaningful to you?

`INFO: From Compiling tensorflow/contrib/rnn/kernels/
external/eigen_archive/unsupported/Eigen/CXX11/../../../Eigen/src/Core/arch/CUDA/Half.h(508): error: explicit specialization of class "std::__1::numeric_limitsEigen::half" must precede its first use (
(388): here)

1 error detected in the compilation of "/var/folders/vh/rw8my97n7w763hqfd3v6c3fr0000gn/T//".
ERROR: /Users/andrediamant/tensorflow/tensorflow/contrib/rnn/BUILD:240:1: output 'tensorflow/contrib/rnn/_objs/python/ops/_gru_ops_gpu/tensorflow/contrib/rnn/kernels/' was not created
ERROR: /Users/andrediamant/tensorflow/tensorflow/contrib/rnn/BUILD:240:1: not all outputs were created or valid
Target //tensorflow/tools/pip_package:build_pip_package failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 387.735s, Critical Path: 30.51s
FAILED: Build did NOT complete successfully`

Copy link

It might worth mentioning that you'd probably need to disable SIP during compilation.

Copy link

the download link for nvidia egpu support is broken. The link to the original post is here

Copy link

@andrediamant I bumped into the same issue with you but there doesn't seem to be a solution yet though. Please refer to tensorflow/tensorflow/issues/17493

Copy link

Epic, thank you so much. this got my system working finally. 2012 MacBook Pro

Copy link

During compilation, I am getting a lot of errors like this:

./tensorflow/core/util/gpu_device_functions.h(868): error: calling a constexpr __host__ function("imag") from a __device__ function("operator*") is not allowed. The experimental flag '--expt-relaxed-constexpr' can be used to allow this.

where can I set the '--expt-relaxed-constexpr' flag?

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