当前位置:   article > 正文

ubuntu22.04多版本安装cuda及快速切换(cuda11.1和11.8)_ubuntu切换cuda版本

ubuntu切换cuda版本

自己学习使用,用以记录,以防遗忘。也希望对大家有所帮助。

(默认已安装anaconda、显卡驱动)

1.官网下载cudaCUDA Toolkit Archive | NVIDIA Developer

默认已下载cuda11.1,如下图所示选择相应版本(ubuntu向下兼容,22.04可选20.04版本的cuda

注意选择runfile方法

在服务器终端输入:

  1. wget https://developer.download.nvidia.com/compute/cuda/11.1.0/local_installers/cuda_11.1.0_455.23.05_linux.run
  2. sudo sh cuda_11.1.0_455.23.05_linux.run

进行安装即可。

接着下载cuda11.8!版本选择按照上述图片进行选择,如果你选择11.8.0,可直接按照我下面的代码进行安装。(输入后会卡一下,耐心等待)

  1. wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run
  2. sudo sh cuda_11.8.0_520.61.05_linux.run

安装过程中

        第一步:选择accept

        第二步:第一项不选(回车取消选择),已安装显卡驱动

选择后小键盘移动到:install  回车

        第三步:应该是a symbol ...什么什么的  选择 no(不要选择yes!!

等待....

出现和下面的类似代码表示安装成功!

  1. ===========
  2. = Summary =
  3. ===========
  4. Driver: Not Selected
  5. Toolkit: Installed in /usr/local/cuda-11.8/
  6. Please make sure that
  7. - PATH includes /usr/local/cuda-11.8/bin
  8. - 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
  9. To uninstall the CUDA Toolkit, run cuda-uninstaller in /usr/local/cuda-11.8/bin
  10. ***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.
  11. To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file:
  12. sudo <CudaInstaller>.run --silent --driver
  13. Logfile is /var/log/cuda-installer.log

2.配置环境变量

2.1为cuda11.1配置环境变量

编辑.bashrc文件:

nano ~/.bashrc

在文件末尾添加以下内容(已有可跳过,版本号根据自身情况修改):

  1. export PATH=/usr/local/cuda-11.1/bin${PATH:+:${PATH}}
  2. export LD_LIBRARY_PATH=/usr/local/cuda-11.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

保存并退出后,更新环境变量:

source ~/.bashrc

 2.2为cuda11.8配置环境变量

编辑.bashrc文件:

nano ~/.bashrc

在文件末尾添加以下内容(已有可跳过,版本号根据自身情况修改):

  1. export PATH=/usr/local/cuda-11.8/bin${PATH:+:${PATH}}
  2. export LD_LIBRARY_PATH=/usr/local/cuda-11.8/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

保存并退出后,更新环境变量:

source ~/.bashrc

3.编写快速切换脚本文件

3.1 创建切换到CUDA 11.1的脚本:

创建脚本文件:

sudo nano /usr/local/bin/switch_cuda_11.1.sh

添加以下内容:

  1. #!/bin/bash
  2. export PATH=/usr/local/cuda-11.1/bin${PATH:+:${PATH}}
  3. export LD_LIBRARY_PATH=/usr/local/cuda-11.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
  4. echo "Switched to CUDA 11.1"

保存并退出,赋予执行权限:

sudo chmod +x /usr/local/bin/switch_cuda_11.1.sh

 3.2 创建切换到CUDA 11.8的脚本:

创建脚本文件:

sudo nano /usr/local/bin/switch_cuda_11.8.sh

添加以下内容:

  1. #!/bin/bash
  2. export PATH=/usr/local/cuda-11.8/bin${PATH:+:${PATH}}
  3. export LD_LIBRARY_PATH=/usr/local/cuda-11.8/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
  4. echo "Switched to CUDA 11.8"

保存并退出,赋予执行权限:

sudo chmod +x /usr/local/bin/switch_cuda_11.8.sh

4.cuda版本切换方法

切换到cuda11.1

source /usr/local/bin/switch_cuda_11.1.sh

切换到cuda11.8

source /usr/local/bin/switch_cuda_11.8.sh

每次切换后可使用

nvcc -V

验证。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/998831
推荐阅读
相关标签
  

闽ICP备14008679号