You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I am glad to use this convenient script. I would like to use it by using a function, which I think maybe easy to use. Maybe I can pull a request.
# FROM https://github.com/phohenecker/switch-cuda/blob/master/switch-cuda.shcudas() {
set -e
INSTALL_FOLDER="/usr/local"
TARGET_VERSION=${1}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]+$"|whileread -r line;doecho"* ${line}"doneset +e
returnelif [[ !-d"${INSTALL_FOLDER}/cuda-${TARGET_VERSION}" ]];thenecho"No installation of CUDA ${TARGET_VERSION} has been found!"set +e
returnfi
cuda_path="${INSTALL_FOLDER}/cuda-${TARGET_VERSION}"
path_elements=(${PATH//:/ })
new_path="${cuda_path}/bin"forpin"${path_elements[@]}";doif [[ !${p}=~ ^${INSTALL_FOLDER}/cuda ]];then
new_path="${new_path}:${p}"fidone
ld_path_elements=(${LD_LIBRARY_PATH//:/ })
new_ld_path="${cuda_path}/lib64:${cuda_path}/extras/CUPTI/lib64"forpin"${ld_path_elements[@]}";doif [[ !${p}=~ ^${INSTALL_FOLDER}/cuda ]];then
new_ld_path="${new_ld_path}:${p}"fidoneexport 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
}
_cudas_autocomplete() {
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"# Directly place the logic for getting CUDA versions here
INSTALL_FOLDER="/usr/local"
opts=$(ls -l "${INSTALL_FOLDER}"| egrep -o "cuda-[0-9]+\\.[0-9]+$"| awk -F- '{print $2}')
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
}
complete -F _cudas_autocomplete cudas
The text was updated successfully, but these errors were encountered:
tunakasif
added a commit
to tunakasif/dotfiles
that referenced
this issue
Dec 24, 2023
Add a simplified version of the switch-cuda script as function,
where the path update instructions are simplified with `awk`.
Refs: phohenecker/switch-cuda#2
Hello, I am glad to use this convenient script. I would like to use it by using a function, which I think maybe easy to use. Maybe I can pull a request.
The text was updated successfully, but these errors were encountered: