Ubuntu server安装CUDA以及cuDNN
![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/e4b0573b6a044350b723581a87b095b7.webp#pic_center)
前面的文章提及了显卡驱动安装
查看所需要的CUDA版本
在终端查看英伟达驱动信息
nvidia-smi
终端演示
xxxx@xxx:~$ nvidia-smi
Sat Aug 10 05:08:45 2024
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.183.01 Driver Version: 535.183.01 CUDA Version: 12.2 |
|-----------------------------------------+----------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+======================+======================|
| 0 Tesla P100-PCIE-16GB Off | 00000000:03:00.0 Off | 1 |
| N/A 38C P0 ERR! / 250W | 0MiB / 16384MiB | 0% Default |
| | | N/A |
+-----------------------------------------+----------------------+----------------------+
| 1 Tesla P100-PCIE-16GB Off | 00000000:82:00.0 Off | 1 |
| N/A 34C P0 ERR! / 250W | 0MiB / 16384MiB | 0% Default |
| | | N/A |
+-----------------------------------------+----------------------+----------------------+
+---------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=======================================================================================|
| No running processes found |
+------------------------------------------------------------------
里面有所对应的CUDA的版本,可以对CUDA以下的版本兼容,这里是12.2,可以通过官网去找 也可以直接去看下面
链接:CUDA Toolkit - Free Tools and Training | NVIDIA Developer
安装CUDA工具包
安装CUDA之前确保更新系统,避免出现依赖问题
sudo apt-get update
sudo apt-get upgrade
更新系统后,安装CUDA
sudo apt-get update
sudo apt-get install nvidia-cuda-toolkit
验证安装
nvcc --version
安装cuDNN
cuDNN官网:https://developer.nvidia.com/cudnn
可以根据官网的方法安装
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt-get update
根据对应版本选择(这里选择12)
sudo apt-get -y install cudnn-cuda12
ls /usr/lib/x86_64-linux-gnu/libcudnn*
配置库路径
将CUDA和cuDNN的库路径添加到环境变量
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
echo 'export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
然后重新加载.bashrc文件或者重新打开一个新的端口
source ~/.bashrc