Skip to content

Instantly share code, notes, and snippets.

@uetchy
Last active June 14, 2017 06:13
Show Gist options
  • Save uetchy/568d86da5ce555e9bc6618f59391f9cd to your computer and use it in GitHub Desktop.
Save uetchy/568d86da5ce555e9bc6618f59391f9cd to your computer and use it in GitHub Desktop.
CUDA on macOS
# install CUDA 8.0
brew cask install cuda
## add alias for libcuda.dylib to suppress the issue related to TensorFlow - https://github.com/tensorflow/tensorflow/issues/3263
sudo ln -s /usr/local/cuda/lib/libcuda.dylib /usr/local/cuda/lib/libcuda.1.dylib
# install cuDNN 5.1
# get cuDNN from https://developer.nvidia.com/rdp/cudnn-download
tar xzf cudnn-8.0-osx-x64-v5.1.tgz
sudo cp cuda/include/cudnn.h /Developer/NVIDIA/CUDA-8.0/include
sudo cp cuda/lib/libcudnn* /Developer/NVIDIA/CUDA-8.0/lib
sudo ln -s /Developer/NVIDIA/CUDA-8.0/lib/libcudnn* /usr/local/cuda/lib/
pip install -U tensorflow-gpu
git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow/
brew install coreutils swig bazel
pip install -U six numpy wheel
# You also need to change its config vars to fit to your environment
PYTHON_BIN_PATH=$HOME/.pyenv/shims/python \
CUDA_TOOLKIT_PATH="/usr/local/cuda" \
CUDNN_INSTALL_PATH="/usr/local/cuda" \
GCC_HOST_COMPILER_PATH="/usr/bin/gcc" \
TF_NEED_GCP=0 \
TF_NEED_CUDA=1 \
TF_CUDA_COMPUTE_CAPABILITIES="5.2" \
TF_CUDNN_VERSION="5.1" \
TF_CUDA_VERSION="8.0" \
TF_CUDA_VERSION_TOOLKIT="8.0" \
./configure
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 -U --ignore-installed /tmp/tensorflow_pkg/tensorflow-*.whl
# You must leave tensorflow/ dir to avoid import error "ImportError: cannot import name 'pywrap_tensorflow'"
cd /path/to/somewhere
python -c "import tensorflow"
#I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcublas.dylib locally
#I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcudnn.dylib locally
#I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcufft.dylib locally
#I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcuda.1.dylib locally
#I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcurand.dylib locally
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment