Ubuntu multi-CUDA version installation and switching

Multiple CUDA versions can be installed in /usr/localthe path at the same time, using soft links to switch versions

1. View the installed CUDA version

All installed CUDA versions are saved in /usr/localthe path by default, cd to this path and use lsthe command to view:
insert image description here
the folder cuda-11.0indicates that CUDA11.0 version is installed on the current computer.

2. View the currently used CUDA version

View the currently used CUDA version /usr/localthrough the command in the path: the above figure shows that the current soft link is established on the directory, indicating that the current version is CUDA11.0.stat cuda
[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-PAPXqaD5-1623847509060) (C:\Users\Guoych\AppData\Roaming\Typora\typora-user-images\ image-20210616155245897.png)]
cuda-11.0

Use cat cuda/version.txtto reconfirm:
[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-Px68G75T-1623847509061) (C:\Users\Guoych\AppData\Roaming\Typora\typora-user-images\ image-20210616155840449.png)]

3. Install the new CUDA version - CUDA10.0

1. Download the corresponding version of the CUDA installation package (select to download the runfile file)
[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-1g7iCK62-1623847509064) (C:\Users\Guoych\AppData\Roaming\Typora\typora-user-images\ image-20210616163904377.png)]
2. In the directory of the downloaded file, sudo sh cuda_10.0.130_410.48_linux.runinstall it through the command. The options during the installation process are as follows:

#..一堆协议说明...
#直接按q退出协议说明.
accept/decline/quit: accept  #接受协议
 
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 410.48? 
y)es/(n)o/(q)uit: n  #是否显卡驱动包,由于已经安装显卡驱动,选择n
 
Install the CUDA 10.0 Toolkit?
(y)es/(n)o/(q)uit: y #是否安装工具包,选择y
 
Enter Toolkit Location
[ default is /usr/local/cuda-10.0 ]: #工具包安装地址,默认回车即可
 
Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: n #添加链接**注意这个连接,如果之前安装过另一个版本的cuda,除非你确定想要用这个新版本的cuda,否则这里就建议选no,因为指定该链接后会将cuda指向这个新的版本**
 
Install the CUDA 10.0 Samples?
(y)es/(n)o/(q)uit: n #不安装样例

After installation, in /usr/localthe path, use lsthe command to check whether there is a newly installed CUDA directory:
[External link image transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the image and upload it directly (img-nPwUnrYS-1623847509066) (C:\Users\Guoych\AppData\Roaming\Typora\typora-user-images\ image-20210616171321140.png)]
it can be seen that the newly installed CUDA10.0 already exists in this directory.

Fourth, install the corresponding cuDNN (version 7.4)

After installing the new version of CUDA, the corresponding cuDNN must also be installed.

1. First download the corresponding version of cuDNN
[External link image transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the image and upload it directly (img-5CORbvKz-1623847509068) (C:\Users\Guoych\AppData\Roaming\Typora\typora-user-images\ image-20210616165014497.png)]
2. cd to the folder where cudnn is located to decompress and other operations:

tar -zxvf cudnn-10.0-linux-x64-v7.4.2.24.tgz
sudo cp cuda/include/cudnn.h /usr/local/cuda-10.0/include/ 
sudo cp cuda/lib64/libcudnn* /usr/local/cuda-10.0/lib64/ 
sudo chmod a+r /usr/local/cuda-10.0/include/cudnn.h /usr/local/cuda-10.0/lib64/libcudnn*
     
cd /usr/local/cuda-10.0/lib64/
sudo ln -sf libcudnn.so.7.4.2 libcudnn.so.7

Five, CUDA version switching

1. Delete the original version of cuda soft link

sudo rm -rf /usr/local/cuda

2. Establish a new soft connection pointing to cuda-10.0

sudo ln -s /usr/local/cuda-10.0 /usr/local/cuda

3. Check the current CUDA version again

[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-biJrOkmU-1623847509069) (C:\Users\Guoych\AppData\Roaming\Typora\typora-user-images\ image-20210616175518876.png)]
Show that the currently used CUDA version has been converted to CUDA10.0

Replenish

Confirm whether cuda has been added to the environment variable, and use the following command to open the configuration file on the command line:

sudo gedit ~/.bashrc

At the end, confirm whether there are the following lines

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

If not, add it to ~/.bashrcthe end of the , then run the command

source ~/.bashrc

Make the configured environment variables take effect.

Guess you like

Origin blog.csdn.net/qq_43673118/article/details/117966752