以12.4为例
参考
CUDA Toolkit 12.1 Downloads
https://developer.nvidia.cn/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=22.04&target_type=deb_network
需要root权限
wget https://developer.download.nvidia.com/compute/cuda/12.4.1/local_installers/cuda_12.4.1_550.54.15_linux.run sudo sh cuda_12.4.1_550.54.15_linux.run
接下来的步骤按需执行不一定都要,根据cuda安装方式的不同步骤有些可能不用。
安装完成后配置cuda环境
vim ~/.bashrc
在最后添加
export PATH=$PATH:/usr/local/cuda-12.4/bin export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-12.4/lib64 export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/cuda-12.4/lib64
nvcc -V 配置
sudo vi /usr/bin/nvcc
添加
exec /usr/local/cuda-12.4/bin/nvcc "$@"
然后wq
保存退出
输入nvcc -V
,如果出现-bash: /usr/bin/nvcc: Permission denied,检查权限
ls -l /usr/bin/nvcc
应该为可执行权限(如 -rwxr-xr-x),如果不是则
sudo chmod +x /usr/bin/nvcc
nvcc-v
检查配置成功
驱动更新
使用docker时发现nvidia-container-cli: requirement error: unsatisfied condition: cuda>=12.4, please update your driver to a newer version, or use an earlier cuda container: unknown.
查看nvidia-smi
中的Driver Version,CUDA 12.4 需要的最小驱动版本是 525.x,需要更新。理论上可以使用sudo apt-get install -y cuda-drivers
安装,但我一直出现The following packages have unmet dependencies: cuda-drivers : Depends: cuda-drivers-560 (= 560.35.03-1) but it is not going to be installedE: Unable to correct problems, you have held broken packages.
于是直接下载安装,具体版本和链接参考
Download The Latest Official NVIDIA Drivers
https://www.nvidia.com/en-us/drivers/
wget https://us.download.nvidia.com/XFree86/Linux-x86_64/550.107.02/NVIDIA-Linux-x86_64-550.107.02.run
下载完成后
chmod +x NVIDIA-Linux-x86_64-550.107.02.run
sudo ./NVIDIA-Linux-x86_64-550.107.02.run
NVIDIA Container Toolkit
如果使用docker的话还需要安装这个
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
sudo apt-get install -y nvidia-container-toolkit
在centos中由于一些源已经停止服务了,需要注释掉对应内容,只要nvidia-container能下载就行