TensorFlow 을 mac 환경에 설치해보겠습니다.
TensorFlow 을 설치하는 몇 가지 방법 중
Installing from sources: Install TensorFlow by building a pip wheel that you then install using pip
위 방법을 사용해보겠습니다.
1.
$ git clone https://github.com/tensorflow/tensorflow
2. HomeBrew 설치
3.
$ brew install bazel
$ brew install bazel
$ brew install bazel
4.
$ sudo easy_install -U six
$ sudo easy_install -U numpy
$ sudo easy_install wheel
5.
$ sudo easy_install ipython
6.
$ brew install coreutils
7.
$ brew tap caskroom/cask
$ brew cask install cuda
8. 환경 변수 추가. open -e .bash_profile
export CUDA_HOME=/usr/local/cuda
export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:$CUDA_HOME/lib"
export PATH="$CUDA_HOME/bin:$PATH"
9. jdk 설치 되지 않았을 경우 설치. 이후 환경 변수 추가
ex) export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home
10. https://developer.nvidia.com/cudnn 다운로드
11.
$ sudo mv include/cudnn.h /Developer/NVIDIA/CUDA-8.0/include/
$ sudo mv lib/libcudnn* /Developer/NVIDIA/CUDA-8.0/lib
$ sudo ln -s /Developer/NVIDIA/CUDA-8.0/lib/libcudnn* /usr/local/cuda/lib/
12. xcode-select --install (설치되지 않았을 경우)
13. GPU 가 CUDA 를 지원하는지 확인을 하기 위해 아래와 같이 실행 후 CUDA Capability Major/Minor version number 이 3.0 이상이여야 GPU 모드를 사용할 수 있습니다.
$ pushd ~/cuda-samples
$ make
$ popd
$ ~/cuda-samples/bin/x86_64/darwin/release/deviceQuery
14. TensorFlow 루트 저장소에서
$./configure
JK-MacBook-Pro-L:tensorflow jkchoi$ ./configure
Please specify the location of python. [Default is /usr/bin/python]:
Do you wish to build TensorFlow with Google Cloud Platform support? [y/N] n
No Google Cloud Platform support will be enabled for TensorFlow
Do you wish to build TensorFlow with Hadoop File System support? [y/N] n
No Hadoop File System support will be enabled for TensorFlow
Found possible Python library paths:
/Library/Python/2.7/site-packages
Please input the desired Python library path to use. Default is [/Library/Python/2.7/site-packages]
Using python library path: /Library/Python/2.7/site-packages
Do you wish to build TensorFlow with OpenCL support? [y/N] n
No OpenCL support will be enabled for TensorFlow
Do you wish to build TensorFlow with CUDA support? [y/N] y
CUDA support will be enabled for TensorFlow
Please specify which gcc should be used by nvcc 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]:
Please specify the location where CUDA 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]:
Please specify the location where cuDNN library is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:
libcudnn.dylib resolves to libcudnn.dylib
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"]:
Killed non-responsive server process (pid=1596)
..
INFO: Starting clean (this may take a while). Consider using --expunge_async if the clean takes more than several minutes.
15. TensorFlow 로컬 저장소에서 (//은 주석이 아닙니다)
$ bazel build -c opt //tensorflow/tools/pip_package:build_pip_package
# To build with GPU support:
$ 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
# The name of the .whl file will depend on your platform.
$ sudo pip install /tmp/tensorflow_pkg/tensorflow-0.12.1-py2-none-any.whl
(GPU 지원을 위해서는 bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
을 실행시켜야 되는데 저같은 경우 dyld: Library not loaded: @rpath/libcudart.8.0.dylib 와 같은 에러가 발생하여
결국 빌드된 package 을 받아서 설치했습니다. 빌드된 package 로 설치할 경우 16번은 하지 않으셔야 됩니다.
sudo pip install --upgrade https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-0.12.1-py2-none-any.whl
or sudo pip install --upgrade https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-0.12.1-py3-none-any.whl
그리고 빌드된 package 로 설치한다 하더라도 제 경우에는 gpu 버전을 사용하기 위해서는 Rootless 을 비활성화 해야만 됬습니다)
16.
mkdir _python_build
cd _python_build
ln -s ../bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles/org_tensorflow/* .
ln -s ../tensorflow/tools/pip_package/* .
sudo python setup.py develop
17. 모든 것이 잘 되었는지 확인을 해볼 시간입니다.
$ python
...
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
Hello, TensorFlow!
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print(sess.run(a + b))
42
>>>