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.
- Join Windows Insider Program.
- Install a special version of nVidia Driver for WSL.
- Install WSL 2
- Install CUDA toolkit in WSL
First, click on the button on the lower left to register for the Windows Insider Program.
Then, click Windows Key > Settings > Update & Security > Windows Insider Program. Sign in and join the Dev Channel.
After registration, remember to update your Windows. It will take a about 20 minutes and several automatic reboots.
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.
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.
See the procedures here. Note that it has to be WSL 2
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
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.
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.
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.)