Could not load dynamic library 'libcudnn.so.8' in ubuntu

Viewed 2548

i am using Ubuntu 20.04.3 and trying to install tensorflow. Nvidia driver version is Driver Version: 470.63.01. First, i have installed cuda 11.0 and checked it installation via following command

cat /usr/local/cuda/version.txt

It output CUDA Version 11.0.207.

Next i installed cudnn

tar -xzvf cudnn-11.0-linux-x64-v8.0.5.39
sudo cp cuda/include/cudnn*.h /usr/local/cuda/include 
sudo cp -P cuda/lib64/libcudnn* /usr/local/cuda/lib64 
sudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn*

I also checked cuda files with this command ls /usr/local |grep cuda which result in

cuda cuda-11.0

Cudnn files are tested by

ls /usr/local/cuda-11.0/lib64/libcudnn.so.8*

and output is

/usr/local/cuda-11.0/lib64/libcudnn.so.8
/usr/local/cuda-11.0/lib64/libcudnn.so.8.0.5

Then i installed tensorflow pip install tensorflow==2.4.0 but when i run

import tensorflow as tf
tf.config.list_physical_devices('GPU')

It did not get GPU and error is Could not load dynamic library 'libcudnn.so.8'; dlerror: libcudnn.so.8: cannot open shared object file: No such file or directory

1 Answers

I just faced the same issue. From your code snippet I see that you are referencing two different CUDA locations:

  • /usr/local/cuda/
  • /usr/local/cuda-11.0/

So you might double-check if that causes an issue.

From here I learned that TF reads the system information about available CUDA from LD_LIBRARY_PATH. Multiple CUDA versions are installed on the system I am using. Thus, exporting these paths explicitly fixed the issue for me:

export LD_LIBRARY_PATH=/usr/local/cuda-11.0/lib64:$LD_LIBRARY_PATH
export CUDA_HOME=/usr/local/cuda-11.0

Of course, you would need to adapt the path to your specific situation.

Related