cuda切换脚本 与好用的AI云平台推荐 xl.hzxingzai.cn

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, 2018


set -e


# ensure that the script has been sourced rather than just executed
if [[ "${BASH_SOURCE[0]}" = "${0}" ]]; then
echo "Please use 'source' to execute switch-cuda.sh!"
exit 1
fi

INSTALL_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} ]]; then
echo "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; do
echo "* ${line}"
done
set +e
return
# otherwise, check whether there is an installation of the requested CUDA version
elif [[ ! -d "${INSTALL_FOLDER}/cuda-${TARGET_VERSION}" ]]; then
echo "No installation of CUDA ${TARGET_VERSION} has been found!"
set +e
return
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[@]}"; do
if [[ ! ${p} =~ ^${INSTALL_FOLDER}/cuda ]]; then
new_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[@]}"; do
if [[ ! ${p} =~ ^${INSTALL_FOLDER}/cuda ]]; then
new_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}"
export PATH="${PATH}:${new_path}"
echo "Switched to CUDA ${TARGET_VERSION}."

set +e
return

使用方法

查看系统有几个cuda版本
source switch-cuda.sh 
切换cuda
source switch-cuda.sh 9.0
source switch-cuda.sh cuda版本

🚀 探索未来的计算力:星鸾云平台 🚀
寻找一处归属你的GPU计算力殿堂?星鸾云平台热情欢迎您的到来!
作为一家致力于为用户提供高性能GPU显卡机器的领先平台,我们引以为傲的不仅仅是卓越的硬件产品,更是我们对服务品质的不懈追求。
🌟 平台支持多样化 🌟
无论您是centos、debian还是ubuntu的忠实用户,星鸾云平台都能为您提供完美支持,确保您在使用我们产品时拥有无与伦比的便捷体验。
🔥 强大的显卡支持 🔥
搭载着A800显卡的机器将为您带来超乎想象的计算性能,让您的任务如虎添翼。而更令人期待的是,我们即将推出的4090 L4显卡,将再次颠覆您对计算能力的认知!
💰 优惠活动,登陆即享 💰
现在就登录星鸾云平台,即可获得价值200元的无门槛优惠券!立即行动,开启您GPU计算之旅的新篇章!
👉 登录星鸾云平台xl.hzxingzai.cn,掌握未来计算的钥匙!👈
无论您是科学研究、深度学习还是数据分析领域的从业者,星鸾云平台都将为您提供最专业、最可靠的计算支持。加入我们,让我们一同创造更加美好的未来!

  • 34
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
在Ubuntu22.04上安装多个版本的CUDA并进行版本切换,可以按照以下步骤操作。 1. 安装CUDA 首先,需要从官网上下载所需版本的CUDA,可以选择deb、runfile等不同的安装包。 运行.deb安装包时,可以使用以下命令: $ sudo dpkg -i cuda-repo-ubuntuXX-XX.deb $ sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntuXX-XX/7fa2af80.pub $ sudo apt-get update $ sudo apt-get install cuda 运行.runfile安装包时,可以使用以下命令: $ sudo sh cuda_XX.XX.XX_XXXXX_linux.run 2. 配置环境变量 安装完CUDA后,需要将环境变量配置好,以便系统能够正确识别CUDA的安装路径和版本信息。 可以使用以下命令配置环境变量: $ export PATH=$PATH:/usr/local/cuda-XX.X/bin $ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-XX.X/lib64 3. 切换CUDA版本 如果需要切换CUDA的版本,可以通过更改环境变量来实现。假设系统中安装了两个版本的CUDA,分别为CUDA8.0和CUDA9.0,可以使用以下命令进行版本切换: $ export PATH=/usr/local/cuda-8.0/bin:$PATH $ export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH 或者 $ export PATH=/usr/local/cuda-9.0/bin:$PATH $ export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64:$LD_LIBRARY_PATH 通过以上步骤,您可以在Ubuntu22.04上成功安装多版本的CUDA并进行版本切换。注意,为避免环境变量混乱,建议在更改环境变量前先备份现有的.profile或.bashrc文件,以便出现问题时可以恢复到原来的状态。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

(~ ̄▽ ̄)~凤凰涅槃

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值