This is fully functional version of Tensorflow with GPU on macOS 10.13 it also works on 10.13.1 I hope it helps.
- OS - High Sierra 10.13
- Tensorflow - 1.4
- Xcode command line tools - 8.2 (Download from here: Xcode - Support - Apple Developer & Switch to different clang version: sudo xcode-select --switch/Library/Developer/CommandLineTools & check version: clang -v)
- Cmake - 3.7
- Bazel - 0.7.0
- CUDA - 9
- cuDNN - 7
Clone tensorflow.
git clone --recurse-submodules https://github.com/tensorflow/tensorflow
- sudo pip install six numpy wheel
- sudo pip install --upgrade setuptools
- brew install coreutils
-
tensorflow/core/kernels/depthwise_conv_op_gpu.cu.cc
-
tensorflow/core/kernels/split_lib_gpu.cu.cc
-
tensorflow/core/kernels/concat_lib_gpu_impl.cu.cc
For example,
extern __shared__ __align(sizeof(T)) unsigned char smem[];
=>extern __shared__ unsigned char smem[];
-
Disable SIP (in recovery mode enter command: csrutil disable)
-
./configure (Find CUDA compute value from https://developer.nvidia.com/cuda-gpus)
Smit-Shilu:tensorflow-build smitshilu$ ./configure You have bazel 0.7.0-homebrew installed. Please specify the location of python. [Default is /Users/smitshilu/anaconda3/bin/python]: Found possible Python library paths: /Users/smitshilu/anaconda3/lib/python3.6/site-packages Please input the desired Python library path to use. Default is [/Users/smitshilu/anaconda3/lib/python3.6/site-packages] 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. Do you wish to build TensorFlow with Amazon S3 File System support? [Y/n]: n No Amazon S3 File System support will be enabled for TensorFlow. Do you wish to build TensorFlow with XLA JIT support? [y/N]: n No XLA JIT support will be enabled for TensorFlow. Do you wish to build TensorFlow with GDR support? [y/N]: n No GDR support will be enabled for TensorFlow. Do you wish to build TensorFlow with VERBS support? [y/N]: n No VERBS support will be enabled for TensorFlow. 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 the CUDA SDK version you want to use, e.g. 7.0. [Leave empty to default to CUDA 8.0]: 9.0 Please specify the location where CUDA 9.0 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 default to cuDNN 6.0]: 7 Please specify the location where cuDNN 7 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 Do you want to use clang as CUDA compiler? [y/N]: nvcc will be used as CUDA compiler. Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]: Do you wish to build TensorFlow with MPI support? [y/N]: No MPI support will be enabled for TensorFlow. Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native]: Add "--config=mkl" to your bazel command to build with MKL support. Please note that MKL on MacOS or windows is still not supported. If you would like to use a local MKL instead of downloading, please set the environment variable "TF_MKL_ROOT" every time before build. Configuration finished
-
Add following paths:
- export CUDA_HOME=/usr/local/cuda
- export DYLD_LIBRARY_PATH=/Users/$USER/lib:/usr/local/cuda/lib:/usr/local/cuda/extras/CUPTI/lib
- export LD_LIBRARY_PATH=$DYLD_LIBRARY_PATH
- export PATH=$DYLD_LIBRARY_PATH:$PATH
-
nano tensorflow/third_party/gpus/crosstool/CROSSTOOL_nvcc.tpl
- search for "cxx_flag"
- found 2 of them
- added cxx_flag: "-D_MWAITXINTRIN_H_INCLUDED" after both cxx_flag: "-std=c++11" entries
- cat -n third_party/gpus/crosstool/CROSSTOOL_nvcc.tpl |grep D_MWAITXINTRIN_H_INCLUDED
- 53 cxx_flag: "-D_MWAITXINTRIN_H_INCLUDED"
- 173 cxx_flag: "-D_MWAITXINTRIN_H_INCLUDED"
-
flag -lgomp is not needed as it is in built in LLVM now.
-
remove line
linkopts = ["-lgomp"],
from following files- third_party/gpus/cuda/BUILD.tpl
- third_party/toolchains/gpus/cuda/BUILD
-
from file tensorflow/contrib/cmake/tf_stream_executor.cmake
- replace set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lgomp")
- with set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
The line numbers correspond to where I added the current entries.
- bazel build --config=cuda --config=opt --action_env PATH --action_env LD_LIBRARY_PATH --action_env DYLD_LIBRARY_PATH //tensorflow/tools/pip_package:build_pip_package
- bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
- sudo pip install /tmp/tensorflow_pkg/tensorflow-1.4.0rc1-cp36-cp36m-macosx_10_7_x86_64.whl (File name depends on tensorflow version and python version)
Now go Out side of this directory and test this
> python
import tensorflow as tf
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
The output will show the device name on which the tensorflow is running. Mine is as follows.
2017-11-24 02:27:09.336265: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:864] OS X does not support NUMA - returning NUMA node zero
2017-11-24 02:27:09.336842: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1062] Found device 0 with properties:
name: GeForce GT 750M major: 3 minor: 0 memoryClockRate(GHz): 0.9255
pciBusID: 0000:01:00.0
totalMemory: 2.00GiB freeMemory: 1.61GiB
2017-11-24 02:27:09.336871: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1152] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: GeForce GT 750M, pci bus id: 0000:01:00.0, compute capability: 3.0)
Device mapping:
/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: GeForce GT 750M, pci bus id: 0000:01:00.0, compute capability: 3.0
2017-11-24 02:27:10.103507: I tensorflow/core/common_runtime/direct_session.cc:297] Device mapping:
/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: GeForce GT 750M, pci bus id: 0000:01:00.0, compute capability: 3.
Congratulations! You are awesome :)