如何在WSL2上的Ubuntu中安装cuDNN?

4
我在Windows 10上运行Tensorflow 2时遇到了问题(只运行一个epoch),因此我正在尝试通过WSL2在Ubuntu上安装cuda和Tensorflow 2。我已经按照以下指南进行操作:https://ubuntu.com/tutorials/enabling-gpu-acceleration-on-ubuntu-on-wsl2-with-the-nvidia-cuda-platform#5-enjoy-ubuntu-on-wsl,这与Nvidia的指南非常相似,只是我安装了cuda版本11.4而不是最新的cuda 11.7:https://docs.nvidia.com/cuda/wsl-user-guide/index.html#installing-wsl2
我现在不确定是否需要安装cuDNN以及应该安装哪个版本,是Windows还是Linux?(https://docs.nvidia.com/deeplearning/cudnn/install-guide/index.html)。当我运行笔记本时,出现了缺少cuDNN的问题。
> physical_devices = tf.config.list_physical_devices('GPU')
> physical_devices
> 2022-06-03 18:30:28.966198: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudnn.so.8'; dlerror: libcudnn.so.8: cannot open shared object file: No such file or directory
> 2022-06-03 18:30:28.966233: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1850] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
> Skipping registering GPU devices...

My specs:
Ubuntu 20.04 via WSL2
Windows 10 21H2
Nvidia latest driver, 512.95 compatible with GeForce RTX 3060
Cuda Driver Version/ Runtime Version 11.6/11.4( can update this to 11.7?)
Tensorflow 2.9.1
Python 3.9.7.

请给予建议?
话虽如此,我在 Windows 上直接安装了 NVIDIA 驱动程序 / CUDA / cuDNN / TensorFlow 2 兼容设置,但有一天我在训练我的一些模型时遇到了问题(参见我的其他 stackoverflow 帖子)。
非常感谢。
2个回答

7

我不能告诉你确切的做法,但你可以在WSL中执行以下操作来查找库:

sudo find / -name 'libcudnn.so.8'

然后使用您找到的路径并设置环境变量:

export LD_LIBRARY_PATH=<PATH_OF_LIBRARY_FROM_ABOVE_CODE>:$LD_LIBRARY_PATH

那是我为使其运行所做的事情。 顺便说一下,我使用conda安装了cudnn和cudatoolkit:

conda install -c conda-forge cudatoolkit=11.2 cudnn=8.1.0

PS:为使您的更改持久化,您可以将其添加到 .bashrc 中进行导出。


1
根据NVIDIA的指示这里
  1. 从这里下载CuDNN: https://developer.nvidia.com/rdp/cudnn-archive

  2. 运行以下命令。请注意,您需要替换版本号和路径。

sudo dpkg -i /path/to/cudnn-local-repo-ubuntu2204-8.6.0.163_1.0-1_amd64.deb`
sudo cp /var/cudnn-local-repo-*/cudnn-local-*-keyring.gpg /usr/share/keyrings/`
sudo apt-get update
sudo apt-get install libcudnn8=8.6.0.163-1+cuda11.8
sudo apt-get install libcudnn8-dev=8.6.0.163-1+cuda11.8

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接