failed call to cuInit: CUDA_ERROR_NO_DEVICE: no CUDA-capable device is detected 排坑指南

时间:2023-11-21 13:28:08

训练maskrcnn时,出现了

failed call to cuInit: CUDA_ERROR_NO_DEVICE: no CUDA-capable device is detected

一开始以为是自己没有把cuda安装好,在排查安装问题,发现没有问题后重启电脑,运行

import tensorflow as tf
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

这个是测试代码,可以查看GPU是否能正常运行

重启电脑后的第一次GPU是可以正常运行的,说明GPU的配置是没有问题的

但是当再一次运行要调用GPU的程序时,会报错

 failed call to cuInit: CUDA_ERROR_NO_DEVICE: no CUDA-capable device is detected

failed call to cuInit: CUDA_ERROR_NO_DEVICE: no CUDA-capable device is detected 排坑指南

这就有点奇怪了,刚开始以为是程序停止了但GPU还被占用,于是用nvidia-smi查看了一下,发现报错

 Unable to determine the device handle for GPU 0000:01:00.0: GPU is lost.  Reboot the system to recover this GPU
GPU已经丢失了。。。需要重启。。。重启之后GPU又可以使用,但用GPU一次以后又会出现该问题
经过百度和google发现大概是因为显存占用过高,导致GPU 离线,通过降低batch_size可能可以解决问题。可以考虑从减少训练过程显存占用这个方面入手,修改部分模型训练参数,有待实验
failed call to cuInit: CUDA_ERROR_NO_DEVICE: no CUDA-capable device is detected 排坑指南

至此问题并未解决,从根本解决问题后会及时更新