[PYTHON] Notes on setting up tensorflow-gpu on MacBook Pro (Mid 2012)

Overview

Some models of iMac and MacBook Pro seem to have an NVIDIA graphics board. I had an NVIDIA GeForce GT 650M on my MacBook Pro (Retina, 2012 MID). I set up tensorflow-gpu to take advantage of the GPU.

Caution

--This is an article as of February 12, 2017. -CUDA GPUs is required.

environment

setup

Basically, follow the official Download and Setup (https://www.tensorflow.org/versions/r0.12/get_started/os_setup.html). In addition, the command is almost Reference article It is the same.

Cuda

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

cuDNN Obtained from NVIDIA's Download Page. User registration required.

This time I downloaded cuDNN v5.1 Library for OS X.

Move the contents to / user / local / cuda / lib and / user / local / cuda / include respectively.

I got an error when I ran it later, so I also put a symbolic link.

$ cd /usr/local/cuda/lib
$ sudo ln -s libcuda.dylib libcuda.1.dylib

The description of the path is finally as follows.

.bashrc


export CUDA_HOME=/usr/local/cuda
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib"
export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:$CUDA_HOME/lib"
export PATH="$CUDA_HOME/bin:$PATH"

tensorflow-gpu

$ brew install bazel
$ brew install tensorflow-gpu==0.12.1

After installation, please configure.

Operation check

Let's run a sample that uses tensorflow. It is OK if there is no import error. It's written in the official Using GPUs, but you can also pass a config.

sample.py


import tensorflow as tf
...
# for tensorflow-gpu
config = tf.ConfigProto()
config.log_device_placement = True
config.gpu_options.allow_growth = True
...
sess = tf.Session(config=config)
sess.run(c)

At run time, the device information will be displayed as shown below.

I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 0 with properties: 
name: GeForce GT 650M
major: 3 minor: 0 memoryClockRate (GHz) 0.9
pciBusID 0000:01:00.0
Total memory: 1023.69MiB
Free memory: 833.14MiB

at the end

I was quite addicted to it on the way. Also, if the free memory is low, it fell after execution. At first I thought the setup failed, but shutting down other applications such as Chrome worked. Compared to the CPU version of tensorflow, I feel that the processing is considerably faster. If you have problems with memory capacity, it may be better to use another machine or an external graphics card.

Reference article

-Set up TensorFlow for macOS 10.12 + CUDA 8.0 --Qiita -[Is it explosive !?] Setup for using the GPU version of Tensorflow on OS X

Recommended Posts

Notes on setting up tensorflow-gpu on MacBook Pro (Mid 2012)
Notes for setting up pydicom on macOS
OpenPose on MacBook Pro
Setting up grub on CentOS 8
OpenPose on MacBook Pro Part 2
Setting up OpenSSH on Arch Linux
Notes on using dict in python [Competition Pro]
Can't get PyAutoGUI coordinates correctly on MacBook Pro?
Notes on Flask
Notes on apps and development environment installed on macbook air Mid2013 (php, ruby, node.js, python, etc.)