Skip to content
daniel@cosenza:~/blog
WSLHow-To August 18, 2026 2 min read

How to Set Up GPU-Accelerated CUDA Workloads in WSL2

A complete walkthrough getting an NVIDIA GPU working for CUDA-accelerated machine learning workloads inside WSL2 — driver setup, verification, and running an actual PyTorch or TensorFlow workload against it.

Getting CUDA workloads running inside WSL2, using your actual NVIDIA GPU, depends on WSL2’s GPU paravirtualization mechanism — this walks through the actual setup steps.

Step 1: install the Windows-side NVIDIA driver, not a Linux-side one

Download and install the current NVIDIA driver for Windows,
  specifically one supporting WSL2 (most current drivers do)

This is a critical, frequently-missed detail: you do not install an NVIDIA driver inside your WSL distro at all — the driver installed on the Windows side is what WSL2’s GPU paravirtualization mechanism uses, and installing a conflicting Linux-side driver inside WSL2 can actually break GPU access.

Step 2: verify WSL2 itself is up to date

wsl --update

Step 3: verify the GPU is visible from inside WSL

nvidia-smi

If your NVIDIA GPU is correctly recognized, this shows GPU utilization, memory, and driver version information from inside your WSL distro — confirming the paravirtualization path is working before installing anything CUDA-specific.

Step 4: install the CUDA toolkit inside your WSL distro

# following NVIDIA's WSL-specific CUDA installation
# instructions for your specific distro

NVIDIA publishes WSL-specific CUDA toolkit installation instructions distinct from their general Linux installation guide — using the WSL-specific instructions matters, since they account for the driver already being provided by the Windows side.

Step 5: verify CUDA itself is working

nvcc --version

Step 6: install a machine learning framework with GPU support

pip install torch torchvision torchaudio
# or
pip install tensorflow

Step 7: verify the framework actually sees the GPU

import torch
print(torch.cuda.is_available())
print(torch.cuda.get_device_name(0))

This is the actual, meaningful verification — confirming your ML framework of choice detects and can use the GPU, not just that nvidia-smi runs successfully.

Step 8: run a small benchmark to confirm real acceleration

import torch
import time

x = torch.randn(5000, 5000).cuda()
start = time.time()
y = x @ x
torch.cuda.synchronize()
print(f"GPU matmul: {time.time() - start:.4f}s")

Comparing this against the same operation run on CPU (x = torch.randn(5000, 5000) without .cuda()) confirms genuine GPU acceleration is actually happening, not just that no error was raised.

Step 9: consider DirectML as an alternative for non-NVIDIA GPUs

pip install tensorflow-directml

For AMD or Intel GPUs, or for a more hardware-vendor-neutral path generally, DirectML provides an alternative GPU acceleration route that doesn’t require CUDA specifically.

Why the “don’t install a Linux GPU driver” step trips people up

Everyone setting up GPU compute on a bare-metal Linux machine is used to installing the GPU driver directly on that same Linux system — WSL2’s architecture inverts this specifically, with the driver living on the Windows host and being made available to the Linux environment through paravirtualization, which is the single most common point of confusion for anyone approaching WSL2 GPU setup with conventional Linux GPU-setup habits already in mind.