113
108

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

TensorflowでOSXのGPUが対応されたよ

Last updated at Posted at 2016-05-12

#2018/12/16追記
いつの間にかOSXのGPU公式サポートはなくなったみたいなので、それでもGPU使いたい方はこちらのドキュメントが参考になるかもしれません。
Tensorflow 1.6 on macOS High Sierra 10.13.3 with GPU Acceleration (without disabling SIP)

#2017/2/17追記
Tensorflow 1.0.0から簡単にインストールできるようになったので公式ドキュメントに従うことをおすすめします。
https://www.tensorflow.org/install/install_mac

#cuda8.0
$ brew upgrade
$ brew install coreutils
$ brew cask install cuda

#cuDNN v5.1 Library for OSXをダウンロードして 各/user/local/cuda/いかにコピー

##.bash_profile
#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"
#一応実行できるけどwarning出るのでリンク貼る
$ cd /usr/local/cuda/lib
$ sudo ln -s libcuda.dylib libcuda.1.dylib

$ easy_install --upgrade pip
$ easy_install --upgrade six 
$ pip install tensorflow-gpu

#以下、本記事

Tensorflow公式レポジトリでIssue#664commit: Enable building with CUDA support on Mac OS XがMergeされてました。

これで正式にMacでもGPUありが使えるはずなので、早速インストールしてみましょう。

※非公式のGPU版セットアップの時と大体同じです。
->【爆速なるか!?】OSXでTensorflowのGPU版を使うためのセットアップ
※※CUDA GPUsでないと使えません
-> https://developer.nvidia.com/cuda-gpus

参考:How to compile tensorflow with CUDA support on OSX (Updated 2nd May 2016)

$ brew update
$ brew cask info cuda 
cuda: 7.5.20
$ bazel version
Build label: 0.2.1-homebrew      

NVIDIAからcuDNNをダウンロード つhttps://developer.nvidia.com/cudnn
Tensorflowのversion0.8はcuDNN v5、 version 0.7以下はv4
私はcudnn-7.5-osx-x64-v5.0-rc.tgzをダウンロードしました。

ファイル解凍して、所定の位置に移動

$tar xzvf ~/Downloads/cudnn-7.5-osx-x64-v5.0-rc.tgz
$sudo mv -v cuda/lib/libcudnn* /usr/local/cuda/lib
$sudo mv -v cuda/include/cudnn.h /usr/local/cuda/include

.bash_profile
export DYLD_LIBRARY_PATH=/usr/local/cuda/lib:$DYLD_LIBRARY_PATH
を追加

$ cd Tensorflowのレポ
$ git pull
$ git checkout master
$ TF_UNOFFICIAL_SETTING=1 ./configure            
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 which gcc nvcc should use as the host compiler. [Default is /usr/bin/gcc]:
Please specify the Cuda SDK version you want to use, e.g. 7.0. [Leave empty to use system default]: 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. [Leave empty to use system default]: 5 
Please specify the location where cuDNN 5 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                                                                                                            
Setting up CUPTI include                                                                                                        
Setting up CUPTI lib64                                                                                                          
Configuration finished                                                                                                          

$ 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-0.8.0-py2-none-any.whl

こういうの買うのもありかもしれない。BizonBOX 2 (External Graphics Card for Mac)

113
108
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
113
108

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?