CUDA/caffe ERROR:cudaGetDeviceCount returned 30/35,Check failed: error == cudaSuccess (30/35 vs. 0)

解决方法

在双显卡系统中,cuda运行时NVIDAI显卡必须是当前使用的显卡,否则无法获取GPU设备,cudaGetDeviceCount函数会报错,错误码35。
使用nvidia-prime切换到N卡时,如果只是按照提示logout,再重新login是不行的,必须重启系统,否则会报错,错误码30。
caffe的问题也是同样的道理,因为caffe也要调用cuda的cudaGetDeviceCount函数获取GPU设备。

问题解决过程

环境:ubuntu16+nvidia-378 driver+cuda8.0+cudnn5.1+GTX965M显卡
成功安装cuda 8.0,也正常编译了Caffe以后,执行mnist训练程序来测试一下,然鹅报错了:

$ ./build/tools/caffe train –solver=examples/mnist/lenet_solver.prototxt
I0312 22:15:25.125078 2171 caffe.cpp:217] Using GPUs 0
I0312 22:15:25.126852 2171 caffe.cpp:222] GPU 0: 0 cg�
F0312 22:15:25.127008 2171 common.cpp:151] Check failed: error == cudaSuccess (35 vs. 0) CUDA driver version is insufficient for CUDA runtime version
* Check failure stack trace: *
@ 0x7f1bb831c5cd google::LogMessage::Fail()
@ 0x7f1bb831e433 google::LogMessage::SendToLog()
@ 0x7f1bb831c15b google::LogMessage::Flush()
@ 0x7f1bb831ee1e google::LogMessageFatal::~LogMessageFatal()
@ 0x7f1bb8882192 caffe::Caffe::SetDevice()
@ 0x40c950 train()
@ 0x4088e8 main
@ 0x7f1bb6a51830 __libc_start_main
@ 0x4091b9 _start
@ (nil) (unknown)
已放弃 (核心已转储)

显然是cuda的问题,于是执行cuda samples程序中的deviceQuery,果然也是报错,,错误码35:

$ ./NVIDIA_CUDA-8.0_Samples/bin/x86_64/linux/release/deviceQuery
./NVIDIA_CUDA-8.0_Samples/bin/x86_64/linux/release/deviceQuery Starting…

CUDA Device Query (Runtime API) version (CUDART static linking)

cudaGetDeviceCount returned 35
-> CUDA driver version is insufficient for CUDA runtime version
Result = FAIL

CUDA/caffe ERROR:cudaGetDeviceCount returned 30/35,Check failed: error == cudaSuccess (30/35 vs. 0)_第1张图片
笔记本电脑是双显卡(i7 cpu有集成显卡),猜测应该是NVIDIA显卡没启用,执行nvidia-setting,在PRIME profile中果然显示当前使用的是Intel 集成显卡,于是切换到nvidia显卡。
CUDA/caffe ERROR:cudaGetDeviceCount returned 30/35,Check failed: error == cudaSuccess (30/35 vs. 0)_第2张图片

PRIME切换到nvidia显卡时提示要logout才能生效,于是登出再重新登录,再执行上面的mnist训练,还是报错,执行deviceQuery也报错,不过这次错误不一样了,错误代码30。

$ ./build/tools/caffe train –solver=examples/mnist/lenet_solver.prototxt
I0312 22:17:46.619762 3469 caffe.cpp:217] Using GPUs 0
I0312 22:17:46.639750 3469 caffe.cpp:222] GPU 0:  1(�
F0312 22:17:46.639799 3469 common.cpp:151] Check failed: error == cudaSuccess (30 vs. 0) unknown error
* Check failure stack trace: *
@ 0x7fe1702315cd google::LogMessage::Fail()
@ 0x7fe170233433 google::LogMessage::SendToLog()
@ 0x7fe17023115b google::LogMessage::Flush()
@ 0x7fe170233e1e google::LogMessageFatal::~LogMessageFatal()
@ 0x7fe170797192 caffe::Caffe::SetDevice()
@ 0x40c950 train()
@ 0x4088e8 main
@ 0x7fe16e966830 __libc_start_main
@ 0x4091b9 _start
@ (nil) (unknown)
已放弃 (核心已转储)

$ ./NVIDIA_CUDA-8.0_Samples/bin/x86_64/linux/release/deviceQuery
./NVIDIA_CUDA-8.0_Samples/bin/x86_64/linux/release/deviceQuery Starting…

CUDA Device Query (Runtime API) version (CUDART static linking)

cudaGetDeviceCount returned 30
-> unknown error
Result = FAIL

CUDA/caffe ERROR:cudaGetDeviceCount returned 30/35,Check failed: error == cudaSuccess (30/35 vs. 0)_第3张图片

要想到切换显卡时没有重启系统,是不是这个原因生成的呢?于是sudo reboot重启电脑,再次进入,执行deviceQuery就正常了
CUDA/caffe ERROR:cudaGetDeviceCount returned 30/35,Check failed: error == cudaSuccess (30/35 vs. 0)_第4张图片

再执行mnist训练也正常了。
尼玛这PRIME的提示妥妥的是坑爹嘛,你直接提示切换显卡要reboot不就成了嘛 ,logout显然不管用嘛。

你可能感兴趣的:(deeplearning)