Now Available: CUDA on WSL Public Preview

Correct. You do NOT need to install any version of the driver within the WSL2 container. You only have to have the proper (display) driver installed on the Windows host.

Thank you for posting the dxdiag. I believe CUDA should work fine in WSL2 on your system.
Was their any problem you noticed when you followed the installation steps from User Guide? Did any workload not work that you have to try to re-install the linux driver (which was not the right step, btw) ?

No problem, and btw going through the cuda-samples I can see which ones failing due to the known limitations.

While following the User Guide I made the mistake of starting with WLS version 1 and midway made the swich to WLS 2 using wsl --set-version command. I was mainly testing the docker examples, I was having trouble keeping the daemon up.
Sorry I can’t really point out a specific issue, maybe the version switch cause some corner case. This was my first time using docker too!

GPU will not be there in the WSL container with WSL 1. The container must be switched to WSL 2 mode in order to get CUDA to work there.

We believe we have root caused the issue and have a fix that is going through some internal testing. We hope to be able to publish a patched driver after it passes required validation.
Stay tuned and thanks again for reporting the issue in this forum.

2 Likes

Fantastic - thanks for the quick turn around - really excited to try this out. Let me know if there’s any third party testing I can help with.

We have just released and published and updated driver with a fix that we think may be addressing you issue. Please give it a try when you have a chance: https://developer.nvidia.com/cuda/wsl/download. It would be much appreciated if you could confirm whether the issue is fixed on your side or not. And thanks again for helping us to make CUDA work great in WSL 2 !

1 Like
(base) ~/cuda-samples/bin/x86_64/linux/release [master *]$ ./matrixMul
[Matrix Multiply Using CUDA] - Starting...
GPU Device 0: "Turing" with compute capability 7.5

MatrixA(320,320), MatrixB(640,320)
Computing result using CUDA Kernel...
done
Performance= 75.16 GFlop/s, Time= 1.744 msec, Size= 131072000 Ops, WorkgroupSize= 1024 threads/block
Checking computed result for correctness: Result = PASS

NOTE: The CUDA Samples are not meant for performancemeasurements. Results may vary when GPU Boost is enabled.

Fantastic! Now let me try Tensorflow in the docker container…

Can I follow up: Do I need a fresh WSL install to access the drivers, or are they simply loaded with the kernel?

No, you don’t see to reinstall WSL2 or any distro you have running there. However, it is recommended to restart the container if you happened to reinstall the driver. You can do that by shutting down all running distro’s (command: wsl --shutdown) and then starting the distro you need.

Thank you. One more quick question, is it possible to install the Ubuntu CUDA libraries for development without overwriting the WSL driver?

As long as you don’t install any NVidia driver within the WSL2 container itself, you should be fine.

(the driver to support CUDA in WSL comes from the Windows host)

Just as a side note if you install the NVIDIA CUDA Toolkit. Install it via the runfile (and uncheck the Driver Installation). Don’t use the .deb file as it will install the Native driver without giving you the choice and you might have to manually purge this package.

1 Like

I have quick question, if I am using dockerd in WSL2/Ubuntu then do I still need to start Docker Desktop ?

You mean Docker Desktop on Windows host? No, you don’t need to.
Please only start the dockerd service in the WSL2 container.

Thank you @kmorozov . Another question please. I am using VS Code for development and without Docker Desktop I am not able to connect to the Docker container that is running inside WSL2/Ubuntu. I can use the Remote-WSL extension to connect to Ubuntu but how do I attach VS Code to the container that is running within Ubuntu. Any ideas ?

This question is about VSCode support for docker in WSL. I would recommend you to post it to Issues · microsoft/WSL · GitHub forum.

Some related links where you can start as well:
https://code.visualstudio.com/remote-tutorials/wsl/run-in-wsl

For installing with deb file without installing the driver, just do:

sudo apt-get install -y cuda-toolkit-11-0

I successfully installed CUDA 11 with this method on WSL2.
Reference document: CUDA on WSL :: CUDA Toolkit Documentation (check “Setting up CUDA Toolkit” session)

Thanks @kmorozov. I managed to connect VS Code to the container inside WSL\Ubuntu with below 2 steps :

  1. In WSL/Ubuntu I used the -H flag to open port 2375:
    sudo dockerd -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375
  2. And in VS Code settings.json, added this line :
    "docker.host":"tcp://localhost:2375"

I have documented entire process that I followed in my blog post How to run Tensorflow using NVIDIA CUDA and Docker on Windows 10 WSL . Hope it helps the community.

Also, I had one question. Currently, we cannot use Docker Desktop for Windows right ? In the future, can we expect this to change ?

1 Like

we cannot use Docker Desktop for Windows right

This is correct since you have the docker support inside the full Linux guest of WSL2 container.

And thank you for documenting how to use VS Code for WSL2 development. Very useful blog post of yours.