2024年6月20日 星期四

在 Ubuntu 20.04 上安裝 cudnn

我的測試環境 

Ubuntu 20.04

NVIDIA-SMI 535.183.01             Driver Version: 535.183.01   CUDA Version: 12.2

用以下的方法,可以確保版本正確的問題

1. **Add NVIDIA package repositories**:
   Ensure you have the CUDA repository added to your system. Follow these steps:

   ```sh
   sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/3bf863cc.pub
   sudo sh -c 'echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64 /" > /etc/apt/sources.list.d/cuda.list'
   sudo sh -c 'echo "deb https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu2004/x86_64 /" > /etc/apt/sources.list.d/cuda_learn.list'
   ```

2. **Update the package list**:

   ```sh
   sudo apt update
   ```

3. **Install CUDA**:
   Ensure you have CUDA installed. You can install a specific version if needed.

   ```sh
   sudo apt install cuda-12-0
   ```

4. **Install cuDNN**:
   Install the cuDNN package for CUDA 12.

   ```sh
   sudo apt install libcudnn8=8.9.7.29-1+cuda12.2
   sudo apt install libcudnn8-dev=8.9.7.29-1+cuda12.2
   sudo apt install libcudnn8-samples=8.9.7.29-1+cuda12.2
   ```

   Replace `8.x.x.x-1+cuda12.0` with the actual version available in the repository. You can check for the available versions using:

   ```sh
   apt-cache policy libcudnn8
   ```

5. **Verify the installation**:
   Ensure CUDA and cuDNN are installed correctly.

   ```sh
   nvcc --version
   ```

   For cuDNN, you can check the version as follows:

   ```sh
   cat /usr/include/cudnn_version.h | grep CUDNN_MAJOR -A 2
   ```

參考:
https://chatgpt.com/share/cbe6f18b-d8af-4621-8355-874f205f6a86

https://medium.com/@scofield44165/ubuntu-20-04%E4%B8%AD%E5%AE%89%E8%A3%9Dnvidia-driver-cuda-11-4-2%E7%89%88-cudnn-install-nvidia-driver-460-cuda-11-4-2-cudnn-6569ab816cc5