1 全新安装

如果环境中没安装过cuda版本, 这种情况下比较简单。 直接在https://developer.nvidia.com/cuda-toolkit-archive选择对应版本下载安装即可。

如下为安装cuda toolkit 11.8.
在这里插入图片描述

2 环境中已经存在其他版本

这种情况下比较复杂一些。 首先要确认最高支持的版本,通过nvidia-smi查看,
在这里插入图片描述
这里显示cuda版本是11.8, 这里显示的是驱动的版本。由于驱动是向下兼容的,因此只要cuda toolkit版本小于等于这个即可。

安装时为了避免更新驱动导致其他问题, 在执行sudo sh cuda_11.8.0_520.61.05_linux.run安装过程中, 我们把驱动这一项去掉, 只安装cuda toolkit.
在这里插入图片描述

安装完成后提示信息如下:

(leo_py39) pinefield@edge-gpu-01:/data/$ sudo sh cuda_11.8.0_520.61.05_linux.run
===========
= Summary =
===========

Driver:   Not Selected
Toolkit:  Installed in /usr/local/cuda-11.8/

Please make sure that
 -   PATH includes /usr/local/cuda-11.8/bin
 -   LD_LIBRARY_PATH includes /usr/local/cuda-11.8/lib64, or, add /usr/local/cuda-11.8/lib64 to /etc/ld.so.conf and run ldconfig as root

To uninstall the CUDA Toolkit, run cuda-uninstaller in /usr/local/cuda-11.8/bin
***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 520.00 is required for CUDA 11.8 functionality to work.
To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file:
    sudo <CudaInstaller>.run --silent --driver

Logfile is /var/log/cuda-installer.log

由于安装时没有删除掉旧版本 ,因此现在环境中应该会存在多个cuda toolkit版本, 并且默认还是旧版本, 可以通过nvcc -V命令查看。

(leo_py39) pinefield@edge-gpu-01:/usr/local$ nvcc -V 
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Thu_Nov_18_09:45:30_PST_2021
Cuda compilation tools, release 11.5, V11.5.119
Build cuda_11.5.r11.5/compiler.30672275_0

多版本切换

设置PATHLD_LIBRARY_PATH两个环境变量, 把需要用到的版本路径加到最前面, 那么就会优先用到对应的版本。

 export PATH=/usr/local/cuda-11.8/bin:$PATH
 export LD_LIBRARY_PATH=/usr/local/cuda-11.8/lib64:$LD_LIBRARY_PATH

设置好之后再通过nvcc -V查看, 发现切换到新版本了:

(leo_py39) pinefield@edge-gpu-01:/usr/local$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Sep_21_10:33:58_PDT_2022
Cuda compilation tools, release 11.8, V11.8.89
Build cuda_11.8.r11.8/compiler.31833905_0

另外一种方式是通过修改软链接的方式。

Logo

更多推荐