Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antoniopioricciardi/240921b16e32dcc67a779e11dfaade1d to your computer and use it in GitHub Desktop.
Save antoniopioricciardi/240921b16e32dcc67a779e11dfaade1d to your computer and use it in GitHub Desktop.

Tensorflow GPU 1.8 with MacOS 10.13.6

A guide to install and make work an already compiled version of Tensorflow 1.8 - GPU on MacOS 10.13.6.

PREREQUISITE: Having an Nvidia GPU or EGPU (already working)

These are the required steps:

(note: follow the guide at your own risk.
note2: Big part of this guide is taken from this other guide):

1. Install Homebrew:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install wget

2. Install Nvidia Web Drivers:

https://images.nvidia.com/mac/pkg/387/WebDriver-387.10.10.10.40.105.pkg

3. Install Nvidia Cuda Drivers:

https://www.nvidia.com/object/macosx-cuda-387.178-driver.html

4. Download Xcode 8.2.xip and Xcode 9.4.xip, extract both .app files, rename them to Xcode8.2.app and Xcode9.4 respectively and move then to Applications folder:

https://developer.apple.com/download/more/

You need to search for them there, they're about 4.2GB and 5.2GB. V9.4 will be needed to install OpenMP, which suggests to install that version. I don't know if latest Xcode version works instead of 9.4, if you already have latest, you could try to use that. V8.2 is essential, anyway.

5. Set Xcode8.2 as default:

sudo xcode-select -s /Applications/Xcode8.2.app

6. Install bazel:

brew install bazel

7. Install cuda 9.1.128:

https://developer.nvidia.com/cuda-91-download-archive?target_os=MacOSX&target_arch=x86_64&target_version=1013&target_type=dmglocal

8. Download and install nccl 1.3.4:

https://storage.googleapis.com/74thopen/tensorflow_osx/nccl_osx_1.3.4.tar.gz

unarchive it, open a terminal window into the extracted folder and move it into /usr/local/nccl by performing:

sudo mkdir -p /usr/local/nccl
cd nccl_2.1.15-1+cuda9.1_x86_64
sudo mv * /usr/local/nccl
sudo mkdir -p /usr/local/include/third_party/nccl
sudo ln -s /usr/local/nccl/include/nccl.h /usr/local/include/third_party/nccl

9. Edit ~/.bash_profile by inserting:

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:/Developer/NVIDIA/CUDA-9.1/bin

in it.

10. Compile CUDA samples to test if GPU is working correctly:

cd /Developer/NVIDIA/CUDA-9.1/samples
chown -R $(whoami) *
make -C 1_Utilities/deviceQuery
./bin/x86_64/darwin/release/deviceQuery

You should get this result at the bottom of the terminal:

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 9.1, CUDA Runtime Version = 9.1, NumDevs = 1Result = PASS

11. Register here and download cuDNN 7.0.5:

https://developer.nvidia.com/compute/machine-learning/cudnn/secure/v7.0.5/prod/9.1_20171129/cudnn-9.1-osx-x64-v7-ga

Perform:

tar -xzvf cudnn-9.1-osx-x64-v7-ga.tgz
sudo cp cuda/include/cudnn.h /usr/local/cuda/include
sudo cp cuda/lib/libcudnn* /usr/local/cuda/lib
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib/libcudnn*

to extract and copy required files into CUDA install folder.

12. Download and install Python 3.6.4:

https://www.python.org/ftp/python/3.6.4/python-3.6.4-macosx10.6.pkg

Now this is where i stopped following the guide.

13. Install Tensorflow 1.8 (other versions HERE):

pip3 install  https://storage.googleapis.com/74thopen/tensorflow_osx/tensorflow-1.8.0-cp36-cp36m-macosx_10_13_x86_64.whl 

14. Set Xcode9.4 as default:

sudo xcode-select -s /Applications/Xcode9.4.app

15. Install OpenMP:

brew install cliutils/apple/libomp

16. Finally, test the whole installation: Run in terminal:

python

then

>>> import tensorflow as tf
>>> tf.Session()

you should get some messages about your GPU, memory and others (### i will insert the exact returned message ###).

17. If you get -ncclAllReduce issue:

  1. Download file here:

https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/nccl/kernels/nccl_ops.cc

  1. Execute:
gcc -c -fPIC nccl_ops.cc -o hello_world.o
  1. Execute:
gcc hello_world.o -shared -o _nccl_ops.so  
  1. Replace generated file "nccl_ops.so" at Path:
tensorflow/contrib/nccl/python/ops

To find where TF is installed:

pip3 show tensorflow

you will get:

Name: tensorflow

Version: 1.8.0

Summary: TensorFlow helps the tensors flow

Home-page: https://www.tensorflow.org/

Author: Google Inc.

Author-email: opensource@google.com

License: Apache 2.0

Location: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages

Requires: grpcio, tensorboard, wheel, astor, gast, protobuf, termcolor, numpy, six, absl-py

Required-by:

Then repeat step 16, if everything works, congratulations, you have tensorflow 1.8 with GPU support installed!

Moreover, if you want to test a sample code to be sure everything really works, then download and run

https://github.com/antoniopioricciardi/Tensorflow-MacOS-10.13.6-eGPU/blob/master/TFtest.py
@antoniopioricciardi
Copy link
Author

Hi, I updated the guide.
First try to run this sample program::
https://github.com/antoniopioricciardi/Tensorflow-MacOS-10.13.6-eGPU/blob/master/TFtest.py

Does it terminate correctly?

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