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)
(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:
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:
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:
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:
- Download file here:
- Execute:
gcc -c -fPIC nccl_ops.cc -o hello_world.o
- Execute:
gcc hello_world.o -shared -o _nccl_ops.so
- 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: [email protected]
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
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?