Last active
April 19, 2019 02:20
-
-
Save planetceres/24c0f3c6618585a5311c463745f45f89 to your computer and use it in GitHub Desktop.
CUDA Activate version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Activate CUDA | |
cuda_activate () { | |
if [[ ":$PATH:" == *":/usr/local/cuda"* ]]; then | |
echo "CUDA already set in PATH. Deactivate before activating another version." | |
return 1 | |
fi | |
DEFAULT_CUDA_PATH=$(readlink /usr/local/cuda) | |
DEFAULT_CUDA=${DEFAULT_CUDA_PATH##*-} | |
echo "" | |
echo "Installed CUDA versions:" | |
cudas=() | |
for cuda_install_path in `ls -d /usr/local/cuda-*` | |
do | |
cudas+=("${cuda_install_path##*-}") | |
echo ${cuda_install_path##*-} | |
done | |
echo "" | |
# If argument provided for CUDA version use it if valid | |
[[ ${cudas[@]} =~ (^|[[:space:]])"$1"($|[[:space:]]) ]] && CUDA_SET=$1 || read -p "Cuda version [default=$DEFAULT_CUDA]: " CUDA_SET | |
CUDA_SET_VERSION=$CUDA_SET | |
[[ ${cudas[@]} =~ (^|[[:space:]])"$CUDA_SET"($|[[:space:]]) ]] && echo 'Setting CUDA to version:' || echo 'Not a valid CUDA installation' | |
[[ ${cudas[@]} =~ (^|[[:space:]])"$CUDA_SET"($|[[:space:]]) ]] && echo $CUDA_SET_VERSION || return | |
export ORIGINAL_PATH=$PATH | |
export PATH=/usr/local/cuda-$CUDA_SET/bin:$PATH | |
export ORIGINAL_LD_LIBRARY_PATH=$LD_LIBRARY_PATH | |
export LD_LIBRARY_PATH=/usr/local/cuda-$CUDA_SET/lib64:/usr/local/cuda-$CUDA_SET/extras/CUPTI/lib64:/lib/nccl/cuda-$CUDA_SET:$LD_LIBRARY_PATH | |
sudo rm /usr/local/cuda | |
sudo ln -s /usr/local/cuda-$CUDA_SET /usr/local/cuda | |
echo "" | |
echo "Version info for CUDA $CUDA_SET:" | |
echo "" | |
echo "$(nvcc -V)" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment