安装Ubuntu驱动
查看可安装Ubuntu驱动列表
sudo ubuntu-drivers devices
安装指定驱动
选择带有“recommended”标记的驱动程序即可,更高版本的是最新版,可能存在兼容问题。
apt-get install nvidia-driver-535
安装cuda
有几种方法可以做到这一点,但这里我们将按照CUDA工具包进行安装
https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=22.04&target_type=deb_local
添加环境变量
export PATH=$PATH:/usr/local/cuda-12.1/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-12.1/lib64
安装效果
$ nvidia-smi
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.67 Driver Version: 550.67 CUDA Version: 12.4 |
|-----------------------------------------+------------------------+----------------------+
| 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 NVIDIA GeForce RTX 3060 ... Off | 00000000:01:00.0 On | N/A |
| N/A 54C P8 15W / 80W | 138MiB / 6144MiB | 33% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+
+-----------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=========================================================================================|
| 0 N/A N/A 2650 G /usr/lib/xorg/Xorg 133MiB |
+-----------------------------------------------------------------------------------------+
$nvcc -v
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Thu_Mar_28_02:18:24_PDT_2024
Cuda compilation tools, release 12.4, V12.4.131
Build cuda_12.4.r12.4/compiler.34097967_0
安装cuDNN
从下面的页面中选择要安装的版本和设备的组合文件。后面会解释,请注意,它在一定程度上受到tensorRT版本的约束。这次,8.9.7选择 。
https://developer.nvidia.com/rdp/cudnn-archive
下载必要的文件后,我运行了安装命令,如下所示。这只是一个示例,因此请按照屏幕上的说明进行操作。 (EA好像是Early access,GA是Stable版本,所以如果你有GA就选择GA)
安装deb文件
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt-get update
sudo apt-get -y install cudnn-cuda-12
安装torch
https://pytorch.org/get-started/previous-versions/