Error using tensorflow GPU: could not create cudnn handle: cudnn_STATUS_NOT_INITIALIZED

Error in using Tensorflow-GPU:
Error

Could not create cudnn handle: CUDNN_STATUS_NOT_INITIALIZED
***Error: Failed to get convolution algorithm. This is probably because cuDNN Failed to initialize, so try looking to see if a warning log message was printed above.

The error mainly points to cudnn, but the CUDA version and cudnn version are in line with the current tensorflow requirements (meaning there is no need to change the CUDA version and cudnn version)
, so it can only be caused by GPU use problem (meaning it is not the fault caused by the program needs to call GPU for many times)
The solution: **
Set GPU on-demand allocation mode
Tensorflow – GPU 2.3.1(be aware of the version of TensorFlow)****

config= tf.compat.v1.ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction = 0.7 #0.7parameter, meaning the percentage allocated to gpu-memory.
sess=tf.compat.v1.Session(config=config)

Older version of TensorFlow-GPU

`config= tf.ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction = 0.7 #0.7parameter, meaning the percentage allocated to gpu-memory.
sess=tf.Session(config=config)`

* Set GPU to apply video memory dynamically
Tensorflow – GPU 2.3.1(be aware of the version of TensorFlow)****

config = tf.compat.v1.ConfigProto()
config.gpu_options.allow_growth = True
session = tf.compat.v1.Session(config=config)

Older version of TensorFlow-GPU

`config = tf.ConfigProto()
config.gpu_options.allow_growth = True
session = tf.Session(config=config)

Please insert the above code into the front of any part of the program to solve the problem

Read More: