Auto-installer for CUDA Toolkit inside WSL2
This file contains 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
#! /usr/bin/env bash | |
# | |
# Auto-installer for CUDA Toolkit inside Windows Subsystem for Linux. | |
# | |
if [ -z "${BASH_VERSINFO[0]}" ] || [ ${BASH_VERSINFO[0]} -lt 4 ] | |
then | |
echo "ERROR: Only tested on Bourne-Again SHell v4/v5." | |
exit 1 | |
fi >&2 | |
main() { | |
installcuda | |
} | |
installcuda() { | |
cudakeyring 1.0-1 | |
cudatoolkit 12-0 | |
# and some extra dev stuff suggested by deps above? | |
#sudo apt install autoconf automake libtool flex bison gdb | |
} | |
cudakeyring() { | |
local rev="$1" | |
! dpkg-query --list cuda-keyring ||return 0 | |
local ckrdeb="cuda-keyring_${rev}_all.deb" | |
wget -N "https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/$ckrdeb" | |
sudo dpkg --install "$ckrdeb" | |
rm "$ckrdeb" | |
} | |
cudatoolkit() { | |
local rev="$1" | |
local repometa=(/var/lib/apt/lists/developer.download.nvidia.com_compute_cuda_repos_wsl-ubuntu_*) | |
if [ "${#repometa[@]}" -eq 0 ] | |
then sudo apt update | |
fi | |
#sudo apt install cuda | |
# DANGER! do not install cuda pacakge as it contains driver that will break WSL2's stub libcuda.so | |
# just the CUDA Toolkit and dependencies | |
! dpkg-query --list "cuda-toolkit-$rev" ||return 0 | |
sudo apt install "cuda-toolkit-$rev" | |
} | |
return 2>/dev/null ||: | |
shopt -s nullglob | |
set -ex | |
main | |
exit 0 | |
# After reading all the crap on https://docs.nvidia.com/cuda/wsl-user-guide/index.html#cuda-support-for-wsl2 | |
# I gave up on all the silly steps below and wrote the much smarter script above. | |
#wget -N https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-wsl-ubuntu.pin | |
#wget -N https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin | |
# both above are the same duh? | |
# why is this massive beast needed? | |
#wget -N https://developer.download.nvidia.com/compute/cuda/12.0.0/local_installers/cuda-repo-wsl-ubuntu-12-0-local_12.0.0-1_amd64.deb | |
#wget -N https://developer.download.nvidia.com/compute/cuda/12.0.0/local_installers/cuda_12.0.0_525.60.13_linux.run | |
#sudo mv cuda-wsl-ubuntu.pin /etc/apt/preferences.d/cuda-repository-pin-600 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment