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 rootTo 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 --driverLogfile 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
多版本切換
設置PATH
和LD_LIBRARY_PATH
兩個環境變量, 把需要用到的版本路徑加到最前面, 那么就會優先用到對應的版本。
export PATH=/usr/local/cuda-11.8/bin:$PATHexport 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
另外一種方式是通過修改軟鏈接的方式。