Skip to content

Instantly share code, notes, and snippets.

@ptheywood
Created December 18, 2017 11:29
Show Gist options
  • Save ptheywood/80640eafbd3a9bfcb5a8a5ed7b731898 to your computer and use it in GitHub Desktop.
Save ptheywood/80640eafbd3a9bfcb5a8a5ed7b731898 to your computer and use it in GitHub Desktop.
function activate_cuda(){
if [ $# -ne 1 ] ; then
echo "Usage: active_cuda <version>"
echo " i.e. activate_cuda 8.0"
else
CUDA_VER=$1
CUDA_SRC="/usr/local/cuda-$CUDA_VER"
CUDA_DST="/usr/local/cuda"
if [ -d "$CUDA_SRC" ]; then
echo "Activating CUDA $CUDA_VER intalled at $CUDA_SRC"
if [ -L "$CUDA_DST" ]; then
# Dst is a symbollic link which exists - update
sudo ln -sfn $CUDA_SRC $CUDA_DST
else
if [ ! -e "$CUDA_DST" ]; then
# If dst does not exist, create the symlink.
sudo ln -s $CUDA_SRC $CUDA_DST
else
# File exists and is not a symlink. error.
echo "Error: $CUDA_DST exists but is not a symlink."
echo " Aborting."
return
fi
fi
else
echo "Error: CUDA Version $CUDA_VER is not installed at $CUDA_SRC"
echo " Using existing cuda version"
fi
echo ""
# Get the cuda version and output.
NVCC_MAJOR=$(nvcc --version | sed -n -r 's/.*(V([0-9]+).([0-9]+).([0-9]+))/\2/p')
NVCC_MINOR=$(nvcc --version | sed -n -r 's/.*(V([0-9]+).([0-9]+).([0-9]+))/\3/p')
NVCC_PATCH=$(nvcc --version | sed -n -r 's/.*(V([0-9]+).([0-9]+).([0-9]+))/\4/p')
echo "Current CUDA Version: $NVCC_MAJOR.$NVCC_MINOR.$NVCC_PATCH"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment