Skip to content

Instantly share code, notes, and snippets.

@akiatoji
Forked from smitshilu/Tensorflow_Build_GPU.md
Last active January 9, 2018 01:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akiatoji/7211cf9d3fecd1b9b014f935542bce23 to your computer and use it in GitHub Desktop.
Save akiatoji/7211cf9d3fecd1b9b014f935542bce23 to your computer and use it in GitHub Desktop.
Tensorflow 1.4 Mac OS High Sierra 10.13 GPU Support

Tensorflow

This allows my Convolutional Neural Network to be trained tad little faster on 2013 MacBookPro15 (4core i7/16GB + NVidia GT750M/2GB) than a 2016 MacPro (6Core Xeon/32GB).

System information

  • OS - High Sierra 10.13
  • Tensorflow - 1.4
  • Xcode command line tools - 8.2 (Download from Xcode - Support - Apple Developer) sudo xcode-select --switch /Library/Developer/CommandLineTools & clang -v
  • Cmake - 3.7
  • Bazel - 0.9.0 via Homebrew
  • CUDA - 9
  • cuDNN - 7

Requirements

  • sudo pip install six numpy wheel
  • brew install coreutils

Step-by-step guide

Remove all align(sizeof(T)) from following files:

  • 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[];

Steps:

  • 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]: y
    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]: y
    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]6.1
    
    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/USERNAME/lib:/usr/local/cuda/lib:/usr/local/cuda/extras/CUPTI/lib (Replace USERNAME with your machine username)
    • export LD_LIBRARY_PATH=$DYLD_LIBRARY_PATH
    • export PATH=$DYLD_LIBRARY_PATH:$PATH
  • Start build
    Note the use of `--incompatible_load_argument_is_label=false` which is needed with Bazel 0.9 and Tensorflow r1.4
    bazel build --config=cuda --config=opt --action_env PATH --action_env LD_LIBRARY_PATH --action_env DYLD_LIBRARY_PATH --incompatible_load_argument_is_label=false //tensorflow/tools/pip_package:build_pip_package
    
  • Generate a wheel for installation
    bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
    
  • Install tensorflow wheel
    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)
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment