环境
软件环境:
macOS Sierra 10.13.6
GPU Driver: WebDriver-387.10.10.10.40.108
CUDA Driver: cudadriver_396.148_macos
CudaToolkit: cuda_9.2.148_mac
CUDNN: cudnn-9.2-osx-x64-v7.2.1.38
硬件环境:
Mac 2018 15'
GPU:技嘉Gaming Box 1070
零、显卡驱动安装
2018 Macbook pro 15(10.13.6)安装Nvidia 1070(Aorus Gaming Box)显卡驱动
安装好驱动之后,可以在系统偏好设置-->NVIDIA Driver Manager查看显卡驱动版本。此电脑的版本。
一、安装CUDA
CUDA Driver与NVIDIA GPU Driver的版本必须一致,才能让CUDA找到显卡。
在mac上安装CUDA最麻烦的事情就是版本匹配问题,这个版本匹配指的是MacOS版本和CUDA Driver、GPU Driver的版本都要匹配。这个网站提供了详细的版本对照:http://www.macvidcards.com/drivers.html
1、安装CUDA Driver
在CUDA Driver页面http://www.nvidia.com/object/mac-driver-archive.html,找到和GPU driver匹配的版本,笔者用的是这个(cudadriver_396.148_macos),然后下载,傻瓜式安装。
链接:https://pan.baidu.com/s/1k2uw2TsEjcv-as_ForLTWA 密码:84br
2、安装CUDA Toolkit
在CUDA Toolkit页面https://developer.nvidia.com/cuda-toolkit-archive,下载、安装CUDA Toolkit(笔者安装的是cuda_9.2.148_mac),同时也要下载补丁。
注意先安装基础的安装包(cuda_9.2.148_mac.dmg)百度网盘,在安装补丁(cuda_9.2.148.1_mac.dmg)百度网盘。
基础包:链接:https://pan.baidu.com/s/1eZXbp-nHCrxPxsQ8d40X4g 密码:iowe
补丁:链接:https://pan.baidu.com/s/1h26vyVcbWhclV-HfFaj2dw 密码:tmpc
注意安装补丁
3.配置CUDA环境
编辑 ~/.bash_profile 文件,在终端
cd ~
open -e .bash_profile
在文件末尾加入
export CUDA_HOME=/usr/local/cuda
export DYLD_LIBRARY_PATH="$CUDA_HOME/lib:$CUDA_HOME/extras/CUPTI/lib"
export LD_LIBRARY_PATH=$DYLD_LIBRARY_PATH
export PATH=$DYLD_LIBRARY_PATH:$PATH
export flags="--config=cuda --config=opt"
export PATH="/Developer/NVIDIA/CUDA-9.2/bin:$PATH"
执行命令重启bash_profile
. ~/.bash_profile
4.测试CUDA能否正常运行
cd /usr/local/cuda/samples
sudo make -C 1_Utilities/deviceQuery
./bin/x86_64/darwin/release/deviceQuery
如果最后的结果Result=PASS,那么CUDA就能够正常工作了。
如果编译的过程报这个错误:nvcc fatal : The version ('10.0') of the host compiler ('Apple clang') is not supportedGithub相同错误的解决办法
那么需要重新安装另外的版本的Command Line Tools
(1)下载Command Line Tools工具 https://developer.apple.com/downloads/ ,笔者下载的是Command_Line_Tools_macOS_10.13_for_Xcode_9.2
链接:https://pan.baidu.com/s/11w1vxTASgvKUaTXlb0MGcg 密码:eebc
(2)安装Command Line Tools
(3)执行命令
sudo xcode-select --switch /Library/Developer/CommandLineTools
(4)查看clang版本 clang --version
(5)重新编译应该就能成功了
二、安装cuDNN
去https://developer.nvidia.com/rdp/cudnn-archive下载cuDNN,笔者下载的是cuDNN v7.2.1
链接:https://pan.baidu.com/s/1eIO_FBM2hQKAXJ0hchnLJw 密码:xvt4
1.安装 cuDNN英伟达官方安装教程
your CUDA directory path is referred to as /usr/local/cuda/
your cuDNN directory path is referred to as <installpath>
Navigate to your <installpath> directory containing cuDNN.
Unzip the cuDNN package.
$ tar -xzvf cudnn-9.0-osx-x64-v7.tgz
Copy the following files into the CUDA Toolkit directory, and change the file permissions.
$ sudo cp cuda/include/cudnn.h /usr/local/cuda/include
$ sudo cp cuda/lib/libcudnn* /usr/local/cuda/lib
$ sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib/libcudnn*
Set the following environment variables to point to where cuDNN is located.
$ export DYLD_LIBRARY_PATH=/usr/local/cuda/lib:$DYLD_LIBRARY_PATH
Verifying
$ echo -e '#include"cudnn.h"\n void main(){}' | nvcc -x c - -o /dev/null -I/usr/local/cuda/include -L/usr/local/cuda/lib -lcudnn
三、测试
1.查看CUDA的版本信息
nvcc -v应该也是可以用的,之前已经加入到环境变量了
cat /usr/local/cuda/version.txt
2.查看cuDNN的版本
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
至此CUDA,cuDNN安装全部完成。
Reference
1、https://blog.youkuaiyun.com/wz22881916/article/details/78807993