[Is it explosive !?] Setup for using the GPU version of Tensorflow on OS X

** * Added on May 12, 2016 This article is completely deprecated because it has been merged into the official Tensorflow repository. ** ** -> OSX GPU is now supported in Tensorflow Well, the installation method doesn't change much.

** * Because it is unofficial, we cannot take responsibility no matter what happens. ** **

I remembered that my Macbook Pro (Retina, 15-inch, Mid 2014) had a NVIDIA GeForce GT 750M in addition to the ʻIntel Iris Pro, so I said," 3.0 on Cuda. GPU on Tensorflow. I thought, and when I was looking for a way, there were people who were already doing it overseas, so I will leave the procedure when I referred to it. However, it returns to ver0.6.0 Since it uses bazel, those who have installedpip, Virtualenv , docker` may want to install it from the source first.

Maybe the kind you can go

Model number GPU
iMac (21-inch, Late 2012) NVIDIA GeForce GT 640M
iMac (21-inch, Late 2012) NVIDIA GeForce GT 650M
iMac (27-inch, Late 2012) NVIDIA GeForce GTX 660MX
iMac (27-inch, Late 2012) NVIDIA GeForce GTX 675MX
iMac (27-inch, Late 2012) NVIDIA GeForce GT 680M
iMac (21.5-inch, Late 2013) NVIDIA Geforce GT 750M
iMac (27-inch, Late 2013) NVIDIA Geforce GT 755M
iMac (27-inch, Late 2013) NVIDIA Geforce GTX 775M
iMac (27-inch, Late 2013) NVIDIA Geforce GTX 780M
MacBook Pro (15-inch, Mid 2012)
MacBook Pro (Mid 2012)
MacBook Pro (15-inch, Early 2013)
NVIDIA GeForce GT 650M
MacBook Pro (15-inch, Late 2013)
MacBook Pro (15-inch, Mid 2014)
NVIDIA GeForce GT 750M

setup

Reference source: Fabrizio Milo @ How to compile tensorflow with CUDA support on OSX

First, install Cuda. I was brew.

$ brew upgrade
$ brew install coreutils
$ brew cask install cuda

Check the version(7.5.Should be 20)
$ brew cask info cuda 

Download the library libCudnn from NVIDIA. (Registration required) https://developer.nvidia.com/cudnn. This is the version I downloaded: cudnn-7.0-osx-x64-v4.0-prod.tgz

Move the contents of the downloaded one to the corresponding location of lib and ʻinclude in / usr / local / cuda / `, respectively.

Add the path to .bash_profile

$ vim ~/.bash_profile
export DYLD_LIBRARY_PATH=/usr/local/cuda/lib:$DYLD_LIBRARY_PATH

Bring Pull Request # 644 to enable GPU on OS X in Tensorflow repository

$ cd tensorflow
$ git fetch origin pull/664/head:cuda_osx
$ git checkout cuda_osx

Reinstall Tensorflow

$ TF_UNOFFICIAL_SETTING=1 ./configure                                                                                                     
                                                                                                                                          
WARNING: You are configuring unofficial settings in TensorFlow. Because some external libraries are not backward compatible, these setting
s are largely untested and unsupported.                                                                                                   
                                                                                                                                          
Please specify the location of python. [Default is /usr/local/bin/python]:                                                                
Do you wish to build TensorFlow with GPU support? [y/N] Y                                                                                 
GPU support will be enabled for TensorFlow                                                                                                
Please specify the Cuda SDK version you want to use. [Default is 7.0]: 7.5                                                                
Please specify the location where CUDA 7.5 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:       
                                                                                                  
Please specify the Cudnn version you want to use. [Default is 6.5]: 4                                                                     
Please specify the location where cuDNN 4 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:        
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: https://developer.nvidia.com/cuda-gpus.                                            
Please note that each additional compute capability significantly increases your build time and binary size.                              
[Default is: "3.5,5.2"]: 3.0                                                                                                              
Setting up Cuda include                                                                                                                   
Setting up Cuda lib                                                                                                                       
Setting up Cuda bin                                                                                                                       
Setting up Cuda nvvm                                                                                                                      
Configuration finished   

$ bazel build -c opt --config=cuda //tensorflow/cc:tutorials_example_trainer

$ bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package

$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

$ pip install /tmp/tensorflow_pkg/tensorflow-In my tmp-whl

Confirmation test.py


import tensorflow as tf

# Creates a graph.
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)

# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

# Runs the op.
print sess.run(c)

If the error says Reason: image not found, it seems that the Cuda library cannot be found, so check the path.

$ export DYLD_LIBRARY_PATH=/usr/local/cuda/lib:$DYLD_LIBRARY_PATH

You should be able to go with this.

Let's try measuring the processing speed with the CNN of "Hiranaga MAIST".

。。。

That. heavy_breathing.jpg

I prepared the image considering the punch line **, but it got faster. ** **

About 52 minutes with CPU

CPU-MAIST.py


i 19900, training accuracy 1 cross_entropy 0.205204
test accuracy 0.943847
elapsed_time:3312.28295398[sec]

GPU-MAIST.py


i 19900, training accuracy 1 cross_entropy 0.0745807
test accuracy 0.945042                              
elapsed_time:1274.27083302[sec]

About 21 minutes with GPU.

If various other applications are running, the GPU memory may be quite small in the Free memory: part of the log that appears during execution. If it is too small, an error will occur due to insufficient memory. It's a laptop computer, so I can't help it. It will recover as soon as you drop the application or restart it, so that's right.

Recommended Posts

[Is it explosive !?] Setup for using the GPU version of Tensorflow on OS X
Until the Deep Learning environment (TensorFlow) using GPU is prepared for Ubuntu 14.04
[Is it explosive !?] Setup for using the GPU version of Tensorflow on OS X
Partially read parameters in old TensorFlow 1.x
Multivariate LSTM and data preprocessing in TensorFlow 2.x
Installing TensorFlow 0.11.0rc2 on OS X El Capitan (10.11.6)
Install LightGBM in an OS X virtualenv environment
TensorFlow 2.1 is here!
Easy 3 minutes TensorBoard in Google Colab (using TensorFlow 2.x)
When "ERROR: HTTP is not supported." Is displayed in mpsyt
Gtk-ERROR **: 04: 28: 17.451: GTK + 2.x symbols detected. Using GTK + 2.x and GTK + 3 in the same process is not supported error
Using multiple versions of Python on Mac OS X (2) Usage
I stumbled on TensorFlow (What is Out of GPU Memory)
Steps to install the latest version of OpenCV on OS X El Capitan without Homebrew
Using multiple versions of Python on Mac OS X (1) Multiple Ver installation
Install the latest version of Apache httpd 2.4 from source on Cent OS 8
June 2017 version to build Tensorflow / Keras environment on GPU instance of AWS
I installed TensorFlow (GPU version) on Ubuntu
I installed Pygame with Python 3.5.1 in the environment of pyenv on OS X
In Python, change the behavior of the method depending on how it is called
I tried object detection with YOLO v3 (TensorFlow 2.1) on the GPU of windows!
Use the latest version of PyCharm on Ubuntu
Installing TensorFlow 0.11.0rc2 on OS X El Capitan (10.11.6)
Notes for using TensorFlow on Bash on Ubuntu on Windows
I tried the MNIST tutorial for beginners of tensorflow.
Building an environment for "Tello_Video" on Mac OS X
Try using E-Cell 4 on Windows 7 or Mac OS X
A memo of installing Chainer 1.5 for GPU on Windows
Drawing on Jupyter using the plot function of pandas
Run GPU version tensorflow on AWS EC2 Spot Instances
The return value of len or unichr may change depending on whether it is UCS-2 or UCS-4.
Support for version upgrade migration of Amazon Linux, which is no longer supported (using Terraform)