前段时间折腾完AMD RX580,因为tensorflow不支持A家的显卡,毕竟TF还是AI的主流,MAC搭配Nvidia家GPU玩TF才是玩家想要的。所以笔者换了一张1060 6G的显卡开始折腾,折腾好久,终于完工了。
过程是很曲折的,容我慢慢道来,首先mac在10.14版本不支持N家的显卡,人工你的系统升级到Mojave的话,第一件事情就是降级OS,笔者花了好多天想在google上找到绕过降级的方案,最终尝试都失败了。
首先参考前面文章机器学习之硬件坑——老Mac搭配eGPU,怎样让N家的显卡能被Mac认识,具体来说,要参考egpu.io社区提供的purge-wrangler, github地址:https://github.com/mayankk2308/purge-wrangler,有什么问题可以留言
1.系统准备好后,就需要根据系统版本下载相应的web driver驱动并安装,查询链接如下
http://www.macvidcards.com/drivers.html
2.下载安装显卡对应的cuda driver,相关链接如下
https://www.nvidia.com/object/mac-driver-archive.html
3.下载两个版本的xode,8.2和9.4,因为前者是用来支持后面cuda 工具编译的,而后者是用来支持安装OpenMP的,下载链接
https://developer.apple.com/download/more/
安装完后,将两个版本都移入Application文件夹,将一个rename为Xcode8.2,并将8.2设为默认配置
sudo xcode-select -s /Applications/Xcode8.2.app/Contents/Developer/
4.安装 brew install bazel
5.安装Cuda9.1,建议不要装10.0
https://developer.nvidia.com/cuda-91-download-archive?target_os=MacOSX&target_arch=x86_64&target_version=1013&target_type=dmglocal
6.安装nccl 1.3.4
链接https://storage.googleapis.com/74thopen/tensorflow_osx/nccl_osx_1.3.4.tar.gz
sudo mkdir -p /usr/local/ncclcd nccl_1.3.4sudo mv * /usr/local/ncclsudo mkdir -p /usr/local/include/third_party/ncclsudo ln -s /usr/local/nccl/include/nccl.h /usr/local/include/third_party/nccl
7.编辑bash_profile
export CUDA_HOME=/usr/local/cuda
export DYLD_LIBRARY_PATH=/usr/local/cuda/lib:/usr/local/cuda/extras/CUPTI/lib
export LD_LIBRARY_PATH=$DYLD_LIBRARY_PATH
export PATH=$DYLD_LIBRARY_PATH:$PATH:/Developer/NVIDIA/CUDA-9.1/bin
8.编译cuda下的samples,检测GPU是否工作正常
cd /Developer/NVIDIA/CUDA-9.1/sampleschown -R $(whoami) *make -C 1_Utilities/deviceQuery./bin/x86_64/darwin/release/deviceQuery
上图就是1060显卡的状态
9.安装cuDNN7.0.5
https://developer.nvidia.com/compute/machine-learning/cudnn/secure/v7.0.5/prod/9.1_20171129/cudnn-9.1-osx-x64-v7-ga
执行以下命令
tar -xzvf cudnn-9.1-osx-x64-v7-ga.tgzsudo cp cuda/include/cudnn.h /usr/local/cuda/includesudo cp cuda/lib/libcudnn* /usr/local/cuda/libsudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib/libcudnn*
10.安装tensorflow-gpu-1.8,目前只有1.8测试ok
https://storage.googleapis.com/74thopen/tensorflow_osx/tensorflow-1.8.0-cp36-cp36m-macosx_10_13_x86_64.whl
11.将xcode9.4设为默认
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer/
12.安装openMP
brew install cliutils/apple/libomp
13.验证tensorflow是否运行正常
python3>>> import tensorflow as tf>>> tf.Session()