Skip to content

Instantly share code, notes, and snippets.

@havran
Last active April 26, 2023 19:35
Show Gist options
  • Save havran/2be1e8b161f2f0b887fd2612b7c9286a to your computer and use it in GitHub Desktop.
Save havran/2be1e8b161f2f0b887fd2612b7c9286a to your computer and use it in GitHub Desktop.
2023-04-26 WSL2 docker-ce + NVIDIA CUDA support for tensorflow / pytorch GPU support

Steps:

  1. Install Ubuntu in WSL wsl --install Ubuntu
  2. Open Ubuntu prompt.
  3. Run sudo apt update && sudo apt upgrade -y
  4. Install CUDA Toolkit (https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=22.04&target_type=deb_network)
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.0-1_all.deb
sudo dpkg -i cuda-keyring_1.0-1_all.deb
sudo apt-get update
sudo apt-get -y install cuda
  1. Install docker-ce (https://docs.docker.com/engine/install/ubuntu/)
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo \
 "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/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
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

and test

sudo docker run hello-world
  1. Install nvidia-container-toolkit
distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \
      && curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
      && curl -s -L https://nvidia.github.io/libnvidia-container/$distribution/libnvidia-container.list | \
            sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
            tee /etc/apt/sources.list.d/nvidia-container-toolkit.list

apt-get update
apt-get install -y nvidia-container-toolkit
nvidia-ctk runtime configure --runtime=docker
service docker restart
  1. Pull nvidia-gpu-supported image and try use GPU in container (microsoft/WSL#9962 (comment))
docker run --rm --runtime nvidia --gpus all pytorch/pytorch:2.0.0-cuda11.7-cudnn8-runtime nvidia-smi
  1. You can test tensorflow in Jupyter in docker now
docker run -it --rm -v $(realpath ~/notebooks):/tf/notebooks -p 8888:8888 --runtime nvidia --gpus all tensorflow/tensorflow:latest-gpu-jupyter

Thanks for inspiration:

@havran
Copy link
Author

havran commented Apr 26, 2023

I also try Determined AI on this platform and seems work. https://www.determined.ai/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment