Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

running nvidia-docker on Windows 10 + WSL2

I saw several Q&As on this topic and tried both approaches. Any advice on how to proceed with either route are appreciated:

Running nvidia-docker from within WSL2

I followed NVIDIA docs and this tutorial. Everything installs and docker command runs from within Ubuntu 20.04. However, sudo service docker start returns:
docker: unrecognized service

Update: this turns to be a known issue. I was able to install and run docker on Ubuntu following these instructions. However, next I am running into an issue like this

$docker run --gpus all nvcr.io/nvidia/k8s/cuda-sample:nbody nbody -gpu -benchmark
Status: Downloaded newer image for nvcr.io/nvidia/k8s/cuda-sample:nbody
docker: Error response from daemon: OCI runtime create failed: container_linux.go:370: starting container process caused: process_linux.go:459: container init caused: Running hook #0:: error running hook: exit status 1, stdout: , stderr: nvidia-container-cli: initialization error: nvml error: driver not loaded: unknown.
ERRO[0065] error waiting for container: context canceled
  • there is a similar issue for WSL1 here, where advice is well to install WSL2. I am running into the same thing under WSL2.

Running NVIDIA docker from Windows:

Another school of thought suggest removing docker from WSL Ubuntu and running Windows docker instead. Then one can connect to it from WSL. Well, I am not able to run nvidia-docker from Windows at all:

$ docker run --gpus all nvcr.io/nvidia/k8s/cuda-sample:nbody nbody -gpu -benchmark
Unable to find image 'nvcr.io/nvidia/k8s/cuda-sample:nbody' locally
nbody: Pulling from nvidia/k8s/cuda-sample
...
docker: Error response from daemon: could not select device driver "" with capabilities: [[gpu]].
  • there are tips on how to fix it here, but it is all about docker running from within Linux. Which does not work (See above).

Additionally, after removing docker from ubuntu I can still run docker from Ubuntu20.04 or when I run wsl from Powershell:

$ which docker
/mnt/c/ProgramData/DockerDesktop/version-bin/docker
$ docker 
The command 'docker' could not be found in this WSL 2 distro.
We recommend to activate the WSL integration in Docker Desktop settings.

See https://docs.docker.com/docker-for-windows/wsl/ for details.

I have definitely enabled WSL2-based engine and integration for Ubuntu 20.04 enabled in two different tabs in Docker settings.

System

Windows 10
WSL 2
Ubuntu 20.04 within WSL2
Windows Docker with WSL2-based engine and integration enabled

Any help how to diagnose it further is much appreciated

like image 348
Dima Lituiev Avatar asked Dec 14 '20 19:12

Dima Lituiev


Video Answer


1 Answers

I think the best way to get nVidia GPU (CUDA) running on WSL2 is to follow the tutorial from nVidia documentation CUDA on WSL. There are three thing you need do them correctly and in order:

  1. First, check your windows if there is an updates, update if there is any. Then you need to subscribe in Microsoft Windows Insider Program, specifically subscribe in Dev Channel (Fast ring). Make sure that is set to Dev channel not Beta Channel nor Release Preview Channel. Here was the tricky part for me, after you select Dev channel check your windows version by running (winver) program (search for it in the search bar of windows) if it's below 20145 go re-check your windows for an update (you will see in the update discription version above 20145 is availble). You nedd to install it, here you need to be patient because it take while to download and install the update, it will ask you for windows restart. After the restart you're good to go (you will also notice some design diffrence between the two version of windows). Check again your windows version with (winver) to find it, it's indeed above 20145.
  2. Next, install the NVIDIA preview driver for WSL 2, it's pretty straight forward process.
  3. Finally, install WSL2 from tutorial, this is also pretty straight forward process. Personaly, i follewed this youtube tutorial from David Bombal channel.

After these three steps preformed correctly, you can follow along the nVidia tutorial from Setting up CUDA Toolkit. Here is another nVidia document stating the same issue you're facing in Chapter 8. They claim that This error usually indicates that the right Microsoft Windows Insider Preview Builds, WSL 2, NVIDIA drivers and NVIDIA Container Toolkit may not be installed correctly.

For me, it was my Windows Insider Preview Builds version not properly set to version 20145 or higher.

like image 196
Khalil Meftah Avatar answered Oct 23 '22 13:10

Khalil Meftah