背景:
本人要在服务器上跑一份别人的pytorch的代码。流程大概是先:
python setup.py
编译所需的可执行文件,然后再
bash xxxx/xxxx.sh
进行训练。
这个服务器上有几张V100(较强的卡)和几张K80(较弱的卡)。因为V100一直是满的,所以我们就要在K80上跑。我成功编译,但每次运行都会报错:
RuntimeError: CUDA error: no kernel image is available for execution on the device
后来研究了一下显卡、compute capacity、CUDA driver、CUDA toolkit、pytorch等等之间的关系。这篇NVIDIA自己的说明不错:https://docs.nvidia.com/deploy/cuda-compatibility/index.html
之后忽然想到,会不会是CUDA检测到服务器上有V100,编译的时候就没有考虑对K80的适配性。于是找到了这篇帖子:
https://runebook.dev/zh-CN/docs/pytorch/cpp_extension
在它的指导下,编译时显式地指定了对compute capacity的适配性:
CUDA_ARCH_LIST=“3.7” python setup.py
这样编译之后,就能成功地运行了。
最后,引用一段话:
In the world of software management there exists a dreaded place called “dependency hell.” The bigger your system grows and the more packages you integrate into your software, the more likely you are to find yourself, one day, in this pit of despair.