当前位置: 首页 > news >正文

ubuntu20.04安装多版本cuda,切换版本

1. 安装cuda toolkit:

下载网站 https://developer.nvidia.com/cuda-11.3.0-download-archive

选择版本,这里选择11.3
在这里插入图片描述

wget https://developer.download.nvidia.com/compute/cuda/11.3.0/local_installers/cuda_11.3.0_465.19.01_linux.run

给cuda权限:

chmod +x cuda_11.3.0_465.19.01_linux.run

运行安装文件:

sudo sh cuda_11.3.0_465.19.01_linux.run

利用上下键以及enter,选中,只安装CUDA Toolkit,
选择Options并进入,然后我们需要修改Toolkit Options 、Library install path这两项的路径,把路径都设为/usr/local/cuda-11.3/,
其他项都不选择
最后点击Install,等待一段时间,会出现如下所示安装信息,说明安装成功

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

同样的步骤,可以安装其他版本cuda

2.切换cuda版本以应对不同的pytorch版本

在已存在多种版本cuda的情况下,切换cuda版本以应对不同的pytorch版本
如cd /usr/local $ls
可以看到有cuda-11.1 cuda-11.3

切换脚本:
参考https://github.com/phohenecker/switch-cuda/blob/master/README.md

vim switch-cuda.sh
#!/usr/bin/env bash# Copyright (c) 2018 Patrick Hohenecker
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.# author:   Patrick Hohenecker <mail@paho.at>
# version:  2018.1
# date:     May 15, 2018set -e# ensure that the script has been sourced rather than just executed
if [[ "${BASH_SOURCE[0]}" = "${0}" ]]; thenecho "Please use 'source' to execute switch-cuda.sh!"exit 1
fiINSTALL_FOLDER="/usr/local"  # the location to look for CUDA installations at
TARGET_VERSION=${1}          # the target CUDA version to switch to (if provided)# if no version to switch to has been provided, then just print all available CUDA installations
if [[ -z ${TARGET_VERSION} ]]; thenecho "The following CUDA installations have been found (in '${INSTALL_FOLDER}'):"ls -l "${INSTALL_FOLDER}" | egrep -o "cuda-[0-9]+\\.[0-9]+$" | while read -r line; doecho "* ${line}"doneset +ereturn
# otherwise, check whether there is an installation of the requested CUDA version
elif [[ ! -d "${INSTALL_FOLDER}/cuda-${TARGET_VERSION}" ]]; thenecho "No installation of CUDA ${TARGET_VERSION} has been found!"set +ereturn
fi# the path of the installation to use
cuda_path="${INSTALL_FOLDER}/cuda-${TARGET_VERSION}"# filter out those CUDA entries from the PATH that are not needed anymore
path_elements=(${PATH//:/ })
new_path="${cuda_path}/bin"
for p in "${path_elements[@]}"; doif [[ ! ${p} =~ ^${INSTALL_FOLDER}/cuda ]]; thennew_path="${new_path}:${p}"fi
done# filter out those CUDA entries from the LD_LIBRARY_PATH that are not needed anymore
ld_path_elements=(${LD_LIBRARY_PATH//:/ })
new_ld_path="${cuda_path}/lib64:${cuda_path}/extras/CUPTI/lib64"
for p in "${ld_path_elements[@]}"; doif [[ ! ${p} =~ ^${INSTALL_FOLDER}/cuda ]]; thennew_ld_path="${new_ld_path}:${p}"fi
done# update environment variables
export CUDA_HOME="${cuda_path}"
export CUDA_ROOT="${cuda_path}"
export LD_LIBRARY_PATH="${new_ld_path}"
export PATH="${new_path}"echo "Switched to CUDA ${TARGET_VERSION}."set +e
return

查看都有哪些cuda版本

source switch-cuda.sh 

我这里会显示有两个版本的cuda

The following CUDA installations have been found (in '/usr/local'):
* cuda-11.1
* cuda-11.3

2.2 当切换到11.3时

切换指令

source switch-cuda.sh 11.3 

查看当先cuda指令:

nvcc -V

显示

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Sun_Mar_21_19:15:46_PDT_2021
Cuda compilation tools, release 11.3, V11.3.58
Build cuda_11.3.r11.3/compiler.29745058_0

2.3 当切换到11.1时

切换指令

source switch-cuda.sh 11.1 

查看当先cuda指令:

nvcc -V

显示

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Mon_Oct_12_20:09:46_PDT_2020
Cuda compilation tools, release 11.1, V11.1.105
Build cuda_11.1.TC455_06.29190527_0
http://www.lryc.cn/news/240886.html

相关文章:

  • 网络渗透测试(wireshark 抓取QQ图片)
  • gRPC之gRPC负载均衡(客户端负载均衡)(etcd)
  • 语音识别技术paddlespeech的安装和使用
  • 【机器学习】034_多层感知机Part.2_从零实现多层感知机
  • 2023年中职“网络安全“—Web 渗透测试①
  • Android——资源IDnonFinalResIds和“Attribute value must be constant”错误
  • 批量创建表空间数据文件(DM8:达梦数据库)
  • 简单聊聊加密和加签的关系与区别
  • 视频转码方法:多种格式视频批量转FLV视频的技巧
  • 【Java 进阶篇】Redis 数据结构:轻松驾驭多样性
  • 东用科技智能公交识别系统无线传输方案
  • Django批量插入数据及分页器
  • PHP 语法||PHP 变量
  • 【python基础(四)】if语句详解
  • Spring Boot中常用的参数传递注解
  • Quartz .Net 的简单使用
  • 面试Java笔试题精选解答
  • 使用Python画一棵树
  • nginx学习(4)Nginx 负载均衡
  • WSL登录时提示nsenter: cannot open /proc/320/ns/time: No such file or directory的解决办法
  • git修改远程分支名称
  • Django 入门学习总结7-静态文件管理
  • 游戏开发引擎Cocos Creator和Unity如何对接广告-AdSet聚合广告平台
  • 振南技术干货集:制冷设备大型IoT监测项目研发纪实(4)
  • Android线程优化——整体思路与方法
  • 论防火墙的体系结构
  • BeansTalkd 做消息队列服务
  • csv文件添加文件内容和读取
  • 关于禅道的安装配置以及项目管理、团队协同工作
  • 使用Wireshark提取流量中图片方法