无法创建cudnn句柄:CUDNN_STATUS_INTERNAL_ERROR

Shi*_*ano 11 tensorflow cudnn

我在配备GeForce GT 750M的Macbook Pro上安装了tensorflow 1.0.1 GPU版本.还安装了CUDA 8.0.71和cuDNN 5.1.我运行的tf代码可以很好地处理非CPU张量流,但是在GPU版本上,我得到了这个错误(曾经有一段时间它也有效):

name: GeForce GT 750M
major: 3 minor: 0 memoryClockRate (GHz) 0.9255
pciBusID 0000:01:00.0
Total memory: 2.00GiB
Free memory: 67.48MiB
I tensorflow/core/common_runtime/gpu/gpu_device.cc:906] DMA: 0 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 0:   Y 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GT 750M, pci bus id: 0000:01:00.0)
E tensorflow/stream_executor/cuda/cuda_driver.cc:1002] failed to allocate 67.48M (70754304 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY
Training...

E tensorflow/stream_executor/cuda/cuda_dnn.cc:397] could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR
E tensorflow/stream_executor/cuda/cuda_dnn.cc:364] could not destroy cudnn handle: CUDNN_STATUS_BAD_PARAM
F tensorflow/core/kernels/conv_ops.cc:605] Check failed: stream->parent()->GetConvolveAlgorithms(&algorithms) 
Abort trap: 6
Run Code Online (Sandbox Code Playgroud)

这里发生了什么?这是张量流中的错误吗?请帮忙.

当我运行python代码时,这是GPU内存空间:

Device 0 [PCIe 0:1:0.0]: GeForce GT 750M (CC 3.0): 83.477 of 2047.6 MB (i.e. 4.08%) Free
MacBook-Pro:cuda-smi-master xxxxxx$ ./cuda-smi
Device 0 [PCIe 0:1:0.0]: GeForce GT 750M (CC 3.0): 83.477 of 2047.6 MB (i.e. 4.08%) Free
MacBook-Pro:cuda-smi-master xxxxxx$ ./cuda-smi
Device 0 [PCIe 0:1:0.0]: GeForce GT 750M (CC 3.0): 83.477 of 2047.6 MB (i.e. 4.08%) Free
MacBook-Pro:cuda-smi-master xxxxxx$ ./cuda-smi
Device 0 [PCIe 0:1:0.0]: GeForce GT 750M (CC 3.0): 1.1016 of 2047.6 MB (i.e. 0.0538%) Free
MacBook-Pro:cuda-smi-master xxxxxx$ ./cuda-smi
Device 0 [PCIe 0:1:0.0]: GeForce GT 750M (CC 3.0): 1.1016 of 2047.6 MB (i.e. 0.0538%) Free
MacBook-Pro:cuda-smi-master xxxxxx$ ./cuda-smi
Device 0 [PCIe 0:1:0.0]: GeForce GT 750M (CC 3.0): 1.1016 of 2047.6 MB (i.e. 0.0538%) Free
MacBook-Pro:cuda-smi-master xxxxxx$ ./cuda-smi
Device 0 [PCIe 0:1:0.0]: GeForce GT 750M (CC 3.0): 1.1016 of 2047.6 MB (i.e. 0.0538%) Free
MacBook-Pro:cuda-smi-master xxxxxx$ ./cuda-smi
Device 0 [PCIe 0:1:0.0]: GeForce GT 750M (CC 3.0): 91.477 of 2047.6 MB (i.e. 4.47%) Free
MacBook-Pro:cuda-smi-master xxxxxx$ ./cuda-smi
Device 0 [PCIe 0:1:0.0]: GeForce GT 750M (CC 3.0): 22.852 of 2047.6 MB (i.e. 1.12%) Free
MacBook-Pro:cuda-smi-master xxxxxx$ ./cuda-smi
Device 0 [PCIe 0:1:0.0]: GeForce GT 750M (CC 3.0): 22.852 of 2047.6 MB (i.e. 1.12%) Free
MacBook-Pro:cuda-smi-master xxxxxx$ ./cuda-smi
Device 0 [PCIe 0:1:0.0]: GeForce GT 750M (CC 3.0): 36.121 of 2047.6 MB (i.e. 1.76%) Free
MacBook-Pro:cuda-smi-master xxxxxx$ ./cuda-smi
Device 0 [PCIe 0:1:0.0]: GeForce GT 750M (CC 3.0): 71.477 of 2047.6 MB (i.e. 3.49%) Free
MacBook-Pro:cuda-smi-master xxxxxx$ ./cuda-smi
Device 0 [PCIe 0:1:0.0]: GeForce GT 750M (CC 3.0): 67.477 of 2047.6 MB (i.e. 3.3%) Free
MacBook-Pro:cuda-smi-master xxxxxx$ ./cuda-smi
Device 0 [PCIe 0:1:0.0]: GeForce GT 750M (CC 3.0): 67.477 of 2047.6 MB (i.e. 3.3%) Free
MacBook-Pro:cuda-smi-master xxxxxx$ ./cuda-smi
Device 0 [PCIe 0:1:0.0]: GeForce GT 750M (CC 3.0): 67.477 of 2047.6 MB (i.e. 3.3%) Free
Run Code Online (Sandbox Code Playgroud)

ave*_*evu 35

在 Tensorflow 2.0 中,通过设置内存增长解决了我的问题。ConfigProto 在 TF 2.0 中已弃用,我使用了 tf.config.experimental。我的电脑规格是:

  • 操作系统:Ubuntu 18.04
  • GPU:GeForce RTX 2070
  • 英伟达驱动:430.26
  • 张量流:2.0
  • 库恩:7.6.2
  • CUDA:10.0

我使用的代码是:

physical_devices = tf.config.experimental.list_physical_devices('GPU')
assert len(physical_devices) > 0, "Not enough GPU hardware devices available"
config = tf.config.experimental.set_memory_growth(physical_devices[0], True)
Run Code Online (Sandbox Code Playgroud)


Fél*_* Fu 17

我已经设法通过删除我的主文件夹中的.nv文件夹来使其工作:

sudo rm -rf ~/.nv/
Run Code Online (Sandbox Code Playgroud)

  • 这解决了我的问题,但您需要在没有 sudo 的情况下运行。 (4认同)
  • 该目录是 ~/.nv 我相信它正在缓存一些二进制文件,当您更新 cudnn 头文件时,仍会从缓存中获取旧的二进制文件,这是导致此问题的一个原因。 (3认同)
  • 不知道这是怎么回事,但这个解决方案也解决了我的问题! (2认同)
  • 我很想知道为什么这有效。 (2认同)

小智 9

添加以下代码对我有用:

config = tf.ConfigProto()
config.gpu_options.allow_growth = True
sess = tf.Session(config=config)
Run Code Online (Sandbox Code Playgroud)

在我的环境中,CuDNN 和 Cuda 版本之间没有不匹配。操作系统:ubuntu-18.04;张量流:1.14;CuDNN:7.6;cuda:10.1 (418.87.00)。


小智 7

对我来说,第四个可以很好地解决问题。 https://blog.csdn.net/comway_Li/article/details/102953634?utm_medium=distribute.pc_relevant.none-task-blog-baidujs-2

1.
    config = tf.ConfigProto()
    config.gpu_options.per_process_gpu_memory_fraction = 1.0
    session = tf.Session(config=config, ...)

2.
    config = tf.ConfigProto() 
    config.gpu_options.allow_growth = True 
    sess = tf.Session(config=config)

3.
    sudo rm -f ~/.nv 

4.
    from tensorflow.compat.v1 import ConfigProto
    from tensorflow.compat.v1 import InteractiveSession
    #from tensorflow import ConfigProto
    #from tensorflow import InteractiveSession
    config = ConfigProto()
    config.gpu_options.allow_growth = True
    session = InteractiveSession(config=config)
Run Code Online (Sandbox Code Playgroud)


小智 6

就我而言,检查cuDNN和CUDA版本后,我发现我的GPU内存不足watch -n 0.1 nvidia-smi在另一个bash终端中使用的那一刻2019-07-16 19:54:05.122224: E tensorflow/stream_executor/cuda/cuda_dnn.cc:334] Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR起就是GPU内存即将满的那一刻。 屏幕截图

因此,我为tnsorflow配置了使用我的GPU的限制。在使用tf.keras模块时,我将以下代码添加到程序的开头:

config = tf.ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction = 0.9
tf.keras.backend.set_session(tf.Session(config=config));
Run Code Online (Sandbox Code Playgroud)

然后,问题解决了!

您可以更改您batch_size的训练数据或使用更智能的方法来输入您的训练数据(例如tf.data.Dataset和使用缓存)。我希望我的回答可以帮助其他人。


goo*_*cow 6

这对我有用:

export TF_FORCE_GPU_ALLOW_GROWTH='true'


kso*_*all 5

听起来可能有些奇怪,请尝试重新启动计算机并重新运行模型。如果模型运行良好,则问题在于您的GPU内存分配和该可用内存的张量流管理。在Windows 10上,我有两个打开和关闭终端,一个解决了我的问题。可能有开放线程(僵尸)仍在保留内存。


Hel*_*ack 5

对于在Jupyter Notebook中遇到此问题的任何人:

我正在运行两个 jupyter 笔记本。关闭其中一个后问题就解决了。


小智 2

我也遇到同样的错误,我解决了这个问题。我的系统属性如下:

  • 操作系统:Ubuntu 14.04
  • 显卡:GTX 1050Ti
  • 英伟达驱动程序:375.66
  • 张量流:1.3.0
  • Cudnn:6.0.21(cudnn-8.0-linux-x64-v6.0.deb)
  • 库达:8.0.61
  • 喀拉斯:2.0.8

我解决这个问题的方法如下:

  1. 我将 cudnn 文件复制到适当的位置(/usr/local/cuda/include/usr/local/cuda/lib64

  2. 我将环境变量设置为:

    * export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64"
    * export CUDA_HOME=/usr/local/cuda
    
    Run Code Online (Sandbox Code Playgroud)
  3. 我还运行sudo ldconfig -v command来缓存运行时链接器的共享库。