我在我的设置中尝试使用Pytorch中的Cuda,但它无法被检测到,让我感到困惑。
torch.cuda.is_available()
返回 False
。更深入地挖掘,
torch._C._cuda_getDeviceCount()
返回 0。例如,使用版本 1.5。
$ pip freeze | grep torch
torch==1.5.0
我尝试写了一个小型的C程序以实现相同的功能,例如:
#include <stdio.h>
#include <cuda_runtime_api.h>
int main() {
int count = 0;
cudaGetDeviceCount(&count);
printf("Device count: %d\n", count);
return 0;
}
输出为1,这表明Cuda运行时可以找到设备。同时,运行nvidia-smi
命令:
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 435.21 Driver Version: 435.21 CUDA Version: 10.1 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce GTX 106... Off | 00000000:02:00.0 On | N/A |
| 0% 41C P8 9W / 200W | 219MiB / 6075MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
那么我的 Cuda 设备在 Python 中去哪儿了呢?
pip uninstall torch torchvision
命令外,我还需要在运行链接文档中的命令之前运行pip cache purge
命令。 - crypdick