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.hqwc.cn/news/212668.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【Docker】从零开始:9.Docker命令:Push推送仓库(Docker Hub,阿里云)

【Docker】从零开始&#xff1a;9.Docker命令:Push推送仓库 知识点1.Docker Push有什么作用&#xff1f;2.Docker仓库有哪几种2.1 公有仓库2.2 第三方仓库2.3 私有仓库2.4 搭建私有仓库的方法有哪几种 3.Docker公有仓库与私有仓库的优缺点对比 Docker Push 命令标准语法操作参数…

浅谈 Guava 中的 ImmutableMap.of 方法的坑

作者&#xff1a;明明如月学长&#xff0c; CSDN 博客专家&#xff0c;大厂高级 Java 工程师&#xff0c;《性能优化方法论》作者、《解锁大厂思维&#xff1a;剖析《阿里巴巴Java开发手册》》、《再学经典&#xff1a;《EffectiveJava》独家解析》专栏作者。 热门文章推荐&…

40、Flink 的Apache Kafka connector(kafka source 和sink 说明及使用示例) 完整版

Flink 系列文章 1、Flink 部署、概念介绍、source、transformation、sink使用示例、四大基石介绍和示例等系列综合文章链接 13、Flink 的table api与sql的基本概念、通用api介绍及入门示例 14、Flink 的table api与sql之数据类型: 内置数据类型以及它们的属性 15、Flink 的ta…

Python中match-case语法: 引领新的模式匹配时代

更多Python学习内容&#xff1a;ipengtao.com Python在其最新的版本中引入了match-case语法&#xff0c;这是一项强大的功能&#xff0c;为开发者提供了更加灵活和直观的模式匹配方式。本文将深入探讨match-case的各个方面&#xff0c;并通过丰富的示例代码&#xff0c;帮助大家…

【数据结构(C语言)】浅谈栈和队列

目录 文章目录 前言 一、栈 1.1 栈的概念及结构 1.2 栈的实现 1.2.1. 支持动态增长的栈的结构 1.2.2 初始化栈 1.2.3 入栈 1.2.4 出栈 1.2.5 获取栈顶元素 1.2.6 获取栈中有效元素个数 1.2.7 检查栈是否为空 1.2.8 销毁栈 二、队列 2.1 队列的概念及结构 2.2 队…

实用工具推荐 | 在线制作电子书

​随着互联网的发展&#xff0c;越来越多的人开始关注知识的传播和分享。而电子书作为一种方便携带、易于分享的形式&#xff0c;越来越受到人们的青睐。今天&#xff0c;就为大家推荐一款实用的工具——FLBOOK在线制作电子杂志平台&#xff0c;让你轻松在线制作电子书&#xf…

【SpringBoot3+Vue3】五【完】【实战篇】-前端(配合后端)

目录 一、环境准备 1、创建Vue工程 2、安装依赖 2.1 安装项目所需要的vue依赖 2.2 安装element-plus依赖 2.2.1 安装 2.2.2 项目导入element-plus 2.3 安装axios依赖 2.4 安装sass依赖 3、目录调整 3.1 删除部分默认目录下文件 3.1.1 src/components下自动生成的…

多线程 02

1.线程的常见构造方法 方法说明Thread()创建线程对象Thread(Runnable target)使用 Runnable 对象创建线程对象Thread(String name)创建线程对象&#xff0c;并命名Thread(Runnable target, String name)使用 Runnable 对象创建线程对象&#xff0c;并命名【了解】Thread(Threa…

【Java SE】类和对象(上)

目录 一. 面向对象的初步认知 1.1 什么是面向对象 1.2 面向对象与面向过程 二. 类定义和使用 2.1 简单认识类 2.2 类的定义格式 三. 类的实例化 3.1 什么是实例化 3.2 实例化对象 四. this引用(重点&#xff09; 4.1 为什么要有this引用 4.2 this的使用 4.3 this引…

Rust 语言常见的一些概念(上)

目录 1、变量的可变性 常量 隐藏 2、数据类型 2.1 标量类型 整型 浮点型 数值运算 布尔型 字符类型 复合类型 元组类型 数组类型 1、变量的可变性 变量默认是不可改变的&#xff08;immutable&#xff09;。这是 Rust 提供给你的众多优势之一&#xff0c;让你得以…

大数据分析与应用实验任务九

大数据分析与应用实验任务九 实验目的 进一步熟悉pyspark程序运行方式&#xff1b; 熟练掌握pysaprkRDD基本操作相关的方法、函数&#xff0c;解决基本问题。 实验任务 进入pyspark实验环境&#xff0c;打开命令行窗口&#xff0c;输入pyspark&#xff0c;完成下列任务&am…

远端WWW服务支持TRACE请求

安全扫描的时候&#xff0c;扫出来的问题&#xff0c;这里不分享如何处理&#xff0c;就只分享下&#xff0c;如何找到有问题的端口。 通过命令 curl -v -X TRACE -I ip:port&#xff0c;这里的ip和端口就是扫描出有问题的服务器地址ip以及开放的服务端口。 观察返回值&#x…