GPU & AI in WSL

Unlock GPU passthrough, CUDA, and machine-learning frameworks inside WSL 2 for local AI development.

GPU Passthrough in WSL 2

WSL 2 supports GPU paravirtualization through the vGPU driver model. Your Windows GPU driver automatically exposes the GPU inside every WSL distro — no extra guest driver required.

NVIDIA: Install the latest Game Ready or Studio driver on Windows — CUDA support is included automatically.

AMD: Use the Adrenalin driver with DirectML support for inference workloads.

Intel: Arc and integrated GPUs work via the Intel GPU driver with DirectML and oneAPI support.

Ubuntu (WSL)
# Verify GPU is visible inside WSL
user@wsl:~$ nvidia-smi
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 560.x Driver Version: 560.x CUDA Version: 12.6 |
| GPU Name ... |
| 0 NVIDIA GeForce RTX 4090 ... |
+-----------------------------------------------------------------------------------------+

CUDA Toolkit Installation

With the Windows driver providing GPU access, you only need the CUDA toolkit inside WSL — not a separate Linux GPU driver.

Important: Do not install a separate NVIDIA Linux driver inside WSL. The Windows host driver handles all GPU communication. Installing a Linux driver will break GPU passthrough.

Ubuntu (WSL)
# Add NVIDIA CUDA repository
user@wsl:~$ wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-wsl-ubuntu.pin
user@wsl:~$ sudo mv cuda-wsl-ubuntu.pin /etc/apt/preferences.d/cuda-repository-pin-600
# Install CUDA toolkit (without the driver)
user@wsl:~$ sudo apt update && sudo apt install -y cuda-toolkit-12-6
# Add CUDA to your PATH
user@wsl:~$ echo 'export PATH=/usr/local/cuda/bin:${PATH}' >> ~/.bashrc
user@wsl:~$ echo 'export LD_LIBRARY_PATH=/usr/local/cuda/lib64:${LD_LIBRARY_PATH}' >> ~/.bashrc
Ubuntu (WSL)
# Verify CUDA installation
user@wsl:~$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Cuda compilation tools, release 12.6, V12.6.x

PyTorch & TensorFlow Setup

Both frameworks detect CUDA inside WSL automatically. Use a virtual environment to keep your system Python clean.

PyTorch with CUDA

Ubuntu (WSL)
# Create a virtual environment
user@wsl:~$ python3 -m venv ~/ai-env && source ~/ai-env/bin/activate
# Install PyTorch with CUDA support
(ai-env) user@wsl:~$ pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
# Verify GPU is available
(ai-env) user@wsl:~$ python3 -c "import torch; print(torch.cuda.is_available(), torch.cuda.get_device_name(0))"
True NVIDIA GeForce RTX 4090

TensorFlow with CUDA

Ubuntu (WSL)
# Install TensorFlow (GPU support included by default)
(ai-env) user@wsl:~$ pip install tensorflow
# Verify GPU detection
(ai-env) user@wsl:~$ python3 -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]

Jupyter Notebooks in WSL

Run Jupyter Lab inside WSL and access it from your Windows browser. VS Code's Jupyter extension also connects to WSL kernels seamlessly.

Ubuntu (WSL)
# Install JupyterLab
(ai-env) user@wsl:~$ pip install jupyterlab ipykernel
# Register the virtual environment as a Jupyter kernel
(ai-env) user@wsl:~$ python3 -m ipykernel install --user --name=ai-env --display-name "AI Environment"
# Launch JupyterLab (opens in Windows browser automatically)
(ai-env) user@wsl:~$ jupyter lab --no-browser --ip=0.0.0.0 --port=8888
http://127.0.0.1:8888/lab?token=abc123...

VS Code tip: Open VS Code with the Remote - WSL extension, then open any .ipynb file. VS Code will detect your Jupyter kernels inside WSL automatically.

Performance Tips

Store datasets on the Linux filesystem

Keep training data under /home/user/data instead of /mnt/c/. Cross-filesystem I/O is significantly slower and can bottleneck data-loading pipelines.

Allocate enough memory in .wslconfig

Large models need RAM. Set memory=16GB (or more) in %USERPROFILE%\.wslconfig to avoid out-of-memory crashes during training.

Use Docker with GPU support

Docker Desktop with the WSL 2 backend passes through GPUs. Use docker run --gpus all to run containers with CUDA access — great for reproducible ML pipelines.