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 # 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,掌握未来计算的钥匙!👈
无论您是科学研究、深度学习还是数据分析领域的从业者,星鸾云平台都将为您提供最专业、最可靠的计算支持。加入我们,让我们一同创造更加美好的未来!