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.
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.
PyTorch & TensorFlow Setup
Both frameworks detect CUDA inside WSL automatically. Use a virtual environment to keep your system Python clean.
PyTorch with CUDA
TensorFlow with CUDA
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.
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.
Next Steps
Development Setup
Set up full dev environments with Docker, VS Code, and language runtimes.
WSL Configuration
Fine-tune .wslconfig for memory, CPU, and networking to optimize GPU workloads.
Networking Deep Dive
Configure port forwarding to expose Jupyter and model endpoints to your network.
Troubleshooting
Fix common GPU detection issues and CUDA version mismatches.