本次主要记录一些自己遇到的问题的解决方案
CUDA、cuDNN
大致流程参照 2018 MAC安装CUDA、cuDNN(Gaming Box1070)
顺序是:GPU Driver、CUDA Driver、CUDA Toolkit、cuDNN
安装驱动时要注意:
MacOS与NVIDIA GPU Driver的版本要匹配,才能驱动显卡
CUDA Driver与NVIDIA GPU Driver的版本要一致,CUDA才能找到显卡
关键地址:
- MAC - NVIDIA GPU Driver对照表:http://www.macvidcards.com/drivers.html
- CUDA Driver:http://www.nvidia.com/object/mac-driver-archive.html
- CUDA Toolkit:https://developer.nvidia.com/cuda-toolkit-archive
- cuDNN:https://developer.nvidia.com/rdp/cudnn-archive
我自己安装好后的配置是:
- GPU Driver Version: 387.10.10.10.40.105
- CUDA Driver Version: 418.105
- CUDA:10.1.105
- cuDNN:7.4.2
版本查看方式:
cat $CUDA_HOME/version.txt # CUDA
cat $CUDA_HOME/include/cudnn.h | grep CUDNN_MAJOR -A 2 #cuDNN
Pytorch with CUDA
Pytorch官方 说的很清楚:
MacOS Binaries dont support CUDA, install from source if CUDA is needed
目前要with CUDA
有两个方式:从源码安装、安装第三方pip包
从源码安装
参照:https://github.com/pytorch/pytorch#from-source
这条路我没走通。虽然成功编译了pytorch,但执行import torch
时遇到了错误:
ModuleNotFoundError: No module named 'torch._C'
按照google结果,我应该在 torch
目录的以下两个文件复制:
cp _C.cpython-37m-darwin.so _C.so
cp _dl.cpython-37m-darwin.so _dl.so
但我的 torch
目录下没有这两个文件
第三方pip包
参照:https://github.com/TomHeaven/pytorch-osx-build
我下载的是:pytorch-1.0-py27-py37-cuda10-cudnn74
这是别人编译好的pip包,下载后用pip安装即可:
pip install torch-1.0-cp37-cp37m-macosx_10_13_x86_64.whl
No module named ‘torch._C’
Library not loaded: @rpath/xxxx.10.0.dylib
在运行 import torch
时报的错,比如:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/jerry/anaconda3/lib/python3.7/site-packages/torch/__init__.py", line 84, in <module>
from torch._C import *
ImportError: dlopen(/Users/jerry/anaconda3/lib/python3.7/site-packages/torch/_C.cpython-37m-darwin.so, 9): Library not loaded: @rpath/libcufft.10.0.dylib
Referenced from: /Users/jerry/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_python.dylib
Reason: image not found
libcufft
是cuda的库,这里只是文件名没找到而已,而库文件其实是在 $CUDA_HOME/lib
下的,所以手动链接一下就行,下面是对同类错误的库进行统一处理:
sudo ln -s $CUDA_HOME/lib/libcufft.10.dylib $CUDA_HOME/lib/libcufft.10.0.dylib
sudo ln -s $CUDA_HOME/lib/libcurand.10.dylib $CUDA_HOME/lib/libcurand.10.0.dylib
sudo ln -s $CUDA_HOME/lib/libcublas.10.dylib $CUDA_HOME/lib/libcublas.10.0.dylib
sudo ln -s $CUDA_HOME/lib/libcudart.dylib $CUDA_HOME/lib/libcudart.10.0.dylib
sudo ln -s $CUDA_HOME/lib/libnvrtc.dylib $CUDA_HOME/lib/libnvrtc.10.0.dylib
sudo ln -s $CUDA_HOME/lib/libcusparse.10.dylib $CUDA_HOME/lib/libcusparse.10.0.dylib
参考引用
[1] 2018 MAC安装CUDA、cuDNN(Gaming Box1070), 2019-04-12.