Skip to content

Latest commit

 

History

History
110 lines (74 loc) · 3.7 KB

CUDA_in_WSL.md

File metadata and controls

110 lines (74 loc) · 3.7 KB

You can now use CUDA (PyTorch/Tensorflow) under Windows Subsystem Linux (WSL)! Although the CUDA under WSL does not have the full capacity as it is in an ordinary Linux (e.g., Ubuntu), it is still worth using now that gaming laptops are very common.

You can read the full instruction on NV's doc here.

Summary of Procedures

  1. Join Windows Insider Program.
  2. Install a special version of nVidia Driver for WSL.
  3. Install WSL 2
  4. Install CUDA toolkit in WSL


Join Windows Insider Program

First, click on the button on the lower left to register for the Windows Insider Program.

register-for-wip



Then, click Windows Key > Settings > Update & Security > Windows Insider Program. Sign in and join the Dev Channel. register-for-wip

register-for-wip

Make sure you turn on Diagnostic data
register-for-wip

After registration, remember to update your Windows. It will take a about 20 minutes and several automatic reboots.



Install a special version of nVidia Driver for WSL

Download NVIDIA Drivers for CUDA on WSL, including DirectML Support. You will most likely be using GeForce. You will need to register for an nVidia account first.

register-for-wip

Download the driver and install it. This special version has the same GUI as the ordinary one, except that it enables CUDA under WSL 2.



Install WSL 2

See the procedures here. Note that it has to be WSL 2

Install CUDA toolkit in WSL

Open your Ubuntu terminal and the following (you will need su first, or sudo every line of the commands). Here I am following NV's doc which installs CUDA 11.

apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub

sh -c 'echo "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/cuda.list'

apt-get update

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


Verify your CUDA on WSL 2

Finally (but optionally), you should verify your CUDA installation.

cd /usr/local/cuda/samples/4_Finance/BlackScholes

# sudo
make

./BlackScholes

If you see a Test passed message, you can enjoy your CUDA with WSL 2! Install your conda environment give Pytorch a try on your gaming laptop!

Here's what it looks like training a simple model on MNIST using PyTorch. Training looks good. gpustat is running although it cannot show the user/process using GPU RAM. Note that you need to use nvidia-smi.exe in WSL instead.

register-for-wip


Trouble-shooting

Q: CUDA has been working fine, but now torch.cuda.is_avalable() returns False.
A: Reset (disable and then enable) your GPU driver in the Device Manager. See this thread.

reset-driver


Q: Temporary failure in name resolution. Internet connection lost?! (Can't use github, wget, etc)
A: sudo vim /etc/resolv.conf
Add this line:

nameserver 8.8.8.8

(Here I use Google's DNS; you can use any other DNS resolver.)