Last active
June 23, 2024 07:59
-
-
Save neggles/f24627c82519815e57fdac7d8f4201e5 to your computer and use it in GitHub Desktop.
WSL2 ubuntu 22.04 CUDA setup
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
#!/usr/bin/env bash | |
set -euo pipefail | |
# please don't run this script as an actual script. it's not remotely error checked. paste command blocks in one by one | |
# and make sure the output looks vaguely sane. | |
# remove this once you've read below! | |
echo "You didn't actually read the instructions, did you?"; exit 1 | |
# first up, `sudo nano /etc/wsl.conf` and add this: | |
[boot] | |
systemd = true | |
# there might already be a [boot] section so there's no simple way to automate that. do it manually! | |
# after that's done, close all your WSL terminals and do a `wsl --shutdown` in PowerShell and wait 30s | |
# then open WSL2 again and proceed with the below. | |
# make sure you have some deps | |
sudo apt-get -y install ca-certificates curl gnupg | |
## ok we do cuda | |
# get nvidia signing key | |
curl -fsSL 'https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/3bf863cc.pub' | sudo gpg --dearmor -o /usr/share/keyrings/cuda-archive-keyring.gpg | |
# add apt repos | |
echo 'deb [signed-by=/usr/share/keyrings/cuda-archive-keyring.gpg] https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/ /' | sudo tee /etc/apt/sources.list.d/cuda-wsl-ubuntu-x86_64.list | |
echo 'deb [signed-by=/usr/share/keyrings/cuda-archive-keyring.gpg] https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/ /' | sudo tee /etc/apt/sources.list.d/cuda.list | |
# add apt pins | |
curl -fsSL 'https://gist.githubusercontent.com/neggles/f24627c82519815e57fdac7d8f4201e5/raw/cuda-repository-pin-600' | sudo tee /etc/apt/preferences.d/cuda-repository-pin-600 >/dev/null | |
curl -fsSL 'https://gist.githubusercontent.com/neggles/f24627c82519815e57fdac7d8f4201e5/raw/cuda-wsl-pin-700' | sudo tee /etc/apt/preferences.d/cuda-wsl-pin-700 >/dev/null | |
# update apt cache | |
sudo apt-get update | |
# install the keyring package for auto-update reasons | |
sudo apt-get -y install cuda-keyring | |
# install cuda12.1 packages | |
sudo apt-get -y install cuda-libraries-dev-12-1 cuda-minimal-build-12-1 cuda-compiler-12-1 'libcudnn8-dev=*cuda12.1' 'libcudnn8=*cuda12.1' | |
# hold the cudnn8 package so it doesn't update to cuda12.2 and make you sad | |
sudo apt-mark hold libcudnn8 libcudnn8-dev | |
## now we do docker | |
# add apt key | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker.gpg | |
# add repo | |
echo \ | |
"deb [arch="$(dpkg --print-architecture)" signed-by=/usr/share/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ | |
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \ | |
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null | |
sudo apt-get update | |
# install | |
sudo apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin | |
# give your user docker access | |
sudo usermod -aG docker "$(whoami)" | |
## now we do nvidia container toolkit | |
# add apt key | |
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg | |
# add repo | |
curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list \ | |
| sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' \ | |
| sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list | |
sudo apt-get update | |
# install toolkit | |
sudo apt-get -y install nvidia-container-toolkit | |
# initialize config | |
sudo nvidia-ctk runtime configure --runtime=docker | |
# restart docker | |
systemctl restart docker | |
# test all of the above | |
docker run --rm --runtime=nvidia --gpus all ubuntu nvidia-smi |
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
Package: nsight-compute | |
Pin: origin *ubuntu.com* | |
Pin-Priority: -1 | |
Package: nsight-systems | |
Pin: origin *ubuntu.com* | |
Pin-Priority: -1 | |
Package: * | |
Pin: release l=NVIDIA CUDA | |
Pin-Priority: 600 |
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
Package: * | |
Pin: origin "developer.download.nvidia.com" | |
Pin-Priority: 600 | |
Package: * | |
Pin: release o=NVIDIA,l=NVIDIA CUDA | |
Pin-Priority: 995 | |
Package: nsight-compute nsight-systems | |
Pin: release o=Ubuntu,l=Ubuntu | |
Pin-Priority: -1 | |
Package: /nvidia/ | |
Pin: release o=Ubuntu,l=Ubuntu | |
Pin-Priority: -1 | |
Package: cuda /cuda-drivers/ /cuda-[0-9]-[0-9]/ | |
Pin: origin "developer.download.nvidia.com" | |
Pin-Priority: -1 |
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
[boot] | |
systemd = true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment