1. 程式人生 > >安裝多版本 cuda ,多版本之間切換

安裝多版本 cuda ,多版本之間切換

1. cuda 的下載與安裝方法選擇

CUDA Toolkit Download 下載所需版本,以 cuda_9.0.176_384.81_linux.run為例:
這裡寫圖片描述

建議選擇使用 .run 檔案安裝,因為使用 .deb可能會將已經安裝的較新的顯示卡驅動替換。

2. cuda 安裝

進入到放置 cuda_9.0.176_384.81_linux.run 的目錄:

sudo chmod +x cuda_9.0.176_384.81_linux.run # 為 cuda_9.0.176_384.81_linux.run 新增可執行許可權
./cuda_9.0.176_384.81
_linux.run # 安裝 cuda_9.0.176_384.81_linux.run

在安裝過程中擷取其中比較重要的幾個選擇:

Do you accept the previously read EULA?
accept/decline/quit: accept

Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 384.81?
(y)es/(n)o/(q)uit: n # 如果在這之前已經安裝好更高版本的顯示卡驅動就不需要再重複安裝,如果需要重複安裝就選擇 yes,此外還需要關閉圖形介面。

Install the CUDA 9.0
Toolkit? (y)es/(n)o/(q)uit: y Enter Toolkit Location [ default is /usr/local/cuda-9.0 ]: # 一般選擇預設即可,也可以選擇安裝在其他目錄,在需要用的時候指向該目錄或者使用軟連線 link 到 /usr/local/cuda。 /usr/local/cuda-9.0 is not writable. Do you wish to run the installation with 'sudo'? (y)es/(n)o: y Please enter your password: Do you want to install a symbolic link at
/usr/local/cuda? # 是否將安裝目錄通過軟連線的方式 link 到 /usr/local/cuda,yes or no 都可以,取決於你是否使用 /usr/local/cuda 為預設的 cuda 目錄。 (y)es/(n)o/(q)uit: n Install the CUDA 9.0 Samples? (y)es/(n)o/(q)uit: n

前面選擇的一些彙總:

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

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

To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-9.0/bin

Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-9.0/doc/pdf for detailed information on setting up CUDA.

***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 384.00 is required for CUDA 9.0 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

安裝完成後可以在 /usr/local 目錄下看到:

cuda-8.0 # 筆者之前安裝的cuda-8.0
cuda-9.0 # 剛剛安裝的cuda-9.0
cuda # cuda-8.0 的軟連線

3. 多個 cuda 版本之間進行切換

將~/.bashrc 或 ~/.zshrc 下與cuda相關的路徑都改為 /usr/local/cuda/ 而不使用 /usr/local/cuda-8.0/ 或/usr/local/cuda-9.0/。

#在切換cuda版本時
rm -rf /usr/local/cuda#刪除之前建立的軟連結
sudo ln -s /usr/local/cuda-8.0/ /usr/local/cuda/
nvcc --version #檢視當前 cuda 版本

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Mon_Jan_23_12:24:11_CST_2017
Cuda compilation tools, release 8.0, V8.0.62

#cuda8.0 切換到 cuda9.0 
rm -rf /usr/local/cuda
sudo ln -s /usr/local/cuda-9.0/ /usr/local/cuda/
nvcc --version