Skip to content

Instantly share code, notes, and snippets.

@lewkoo
Created March 9, 2023 15:08
Show Gist options
  • Save lewkoo/e3f08a02ad0cd23f3d3b82edd7f483e0 to your computer and use it in GitHub Desktop.
Save lewkoo/e3f08a02ad0cd23f3d3b82edd7f483e0 to your computer and use it in GitHub Desktop.
Scripts determines the currently installed CUDA version
#!/bin/bash
# Determine CUDA installation
if nvcc --version 2&> /dev/null; then
# Determine CUDA version using default nvcc binary
CUDA_VERSION=$(nvcc --version | sed -n 's/^.*release \([0-9]\+\.[0-9]\+\).*$/\1/p');
elif /usr/local/cuda/bin/nvcc --version 2&> /dev/null; then
# Determine CUDA version using /usr/local/cuda/bin/nvcc binary
CUDA_VERSION=$(/usr/local/cuda/bin/nvcc --version | sed -n 's/^.*release \([0-9]\+\.[0-9]\+\).*$/\1/p');
elif [ -f "/usr/local/cuda/version.txt" ]; then
# Determine CUDA version using /usr/local/cuda/version.txt file
CUDA_VERSION=$(cat /usr/local/cuda/version.txt | sed 's/.* \([0-9]\+\.[0-9]\+\).*/\1/')
elif [ -f "/usr/local/cuda/version.json" ]; then
# Determine CUDA version using /usr/local/cuda/version.json file
CUDA_VERSION=$(python3 -c "import sys, json; print(json.load(open('/usr/local/cuda/version.json', 'r'))['cuda']['version'].rsplit('.', 1)[0])")
else
CUDA_VERSION=""
fi
if [ "$CUDA_VERSION" = "" ]; then
MOD="";
else
MOD="cu${CUDA_VERSION/./}";
fi
echo $CUDA_VERSION
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment