给 linux 的 NVIDIA GPU 安装 CUDA Toolkit

拿到电脑后,我先一个 ubuntu-drivers devices 查看可用的驱动版本

╰─➤  ubuntu-drivers devices

ERROR:root:aplay command not found
== /sys/devices/pci0000:ae/0000:ae:00.0/0000:af:00.0 ==
modalias : pci:v000010DEd00001EB8sv000010DEsd000012A2bc03sc02i00
vendor   : NVIDIA Corporation
model    : TU104GL [Tesla T4]
driver   : nvidia-driver-470-server - distro non-free
driver   : nvidia-driver-418-server - distro non-free
driver   : nvidia-driver-535-server - distro non-free
driver   : nvidia-driver-535 - distro non-free recommended
driver   : nvidia-driver-470 - distro non-free
driver   : nvidia-driver-525-server - distro non-free
driver   : nvidia-driver-525 - distro non-free
driver   : nvidia-driver-450-server - distro non-free
driver   : xserver-xorg-video-nouveau - distro free builtin

参考:

因为我是 ubuntu server 版本,而不是 Desktop 版本,所以我要安装带 -server 后缀的

然后我想安装最新的,最新的是 535,那就选他了

sudo apt install -y nvidia-driver-535-server

安装好了之后,重启电脑

sudo reboot

等电脑重启好了,输入 nvidia-smi 查看显卡信息

╰─➤  nvidia-smi                                                                                                                                                                                                                                                                                                                                            130 ↵
Mon Sep 18 14:30:16 2023       
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.54.03              Driver Version: 535.54.03    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 T4                       Off | 00000000:AF:00.0 Off |                    0 |
| N/A   47C    P0              27W /  70W |      2MiB / 15360MiB |      6%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+
                                                                                         
+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|  No running processes found                                                           |
+---------------------------------------------------------------------------------------+

可以看到,此时已经可以读取到显卡了

说明这个显卡已经可以使用了


那么此时我们只安装了 driver,但是没有显性的安装 CUDA Toolkit,那么此时,我们有 CUDA Toolkit吗?比如可能安装 driver 的时候,自动安装了 CUDA Toolkit?

答案是不会

此时你的终端输入 nvcc --version

╰─➤  nvcc --version

zsh: command not found: nvcc

放回是 not found

所以,怎么安装 CUDA Toolkit?

nv 显卡安装驱动以及周边日志
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-ubuntu2204.pin
sudo mv cuda-ubuntu2204.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/12.2.2/local_installers/cuda-repo-ubuntu2204-12-2-local_12.2.2-535.104.05-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu2204-12-2-local_12.2.2-535.104.05-1_amd64.deb
sudo cp /var/cuda-repo-ubuntu2204-12-2-local/cuda-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cuda

你可能感兴趣的:(linuxnvidiacuda)