環境
軟件環境:
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.csdn.net/wz22881916/article/details/78807993