WSL GPU Passthrough: How It Works
In this article
WSL GPU passthrough lets Windows Subsystem for Linux (WSL) access your computer's graphics processing unit (GPU) for compute tasks, not for displaying a desktop. In practice, this means you can run Linux tools like PyTorch, TensorFlow, or Blender inside WSL and use your NVIDIA or AMD GPU for acceleration, without dual-booting or setting up a virtual machine.
What GPU Passthrough Means in WSL
In a traditional virtual machine, the guest OS often cannot see the host's GPU directly; the hypervisor intercepts graphics calls, which is slow for compute. WSL2, the current version, runs a real Linux kernel in a lightweight utility VM. Microsoft added a feature called GPU paravirtualization (often called GPU-PV) that lets that Linux kernel talk to the host GPU through a virtual driver. The GPU is not physically passed through; instead, the Linux side sends commands to the Windows driver, which executes them on the physical GPU. This design keeps the system secure and stable while giving near-native performance for compute workloads.
Requirements for WSL GPU Passthrough
To use GPU acceleration in WSL, you need:
- Windows 11 or a recent Windows 10 version (build 19044 or later).
- WSL2 installed (check with
wsl --status). - An NVIDIA GPU with a driver that supports CUDA, or an AMD GPU with a driver that supports DirectML, or an Intel GPU with the appropriate driver.
- For NVIDIA, you must install the Windows driver that includes the WSL support (the standard Game Ready or Studio driver works).
- Inside WSL, install the Linux version of the CUDA toolkit or the ROCm stack (for AMD) or the DirectML backend for frameworks.
You do not need to install a separate Linux driver; the Windows driver handles the GPU, and WSL passes the calls through. This is a major difference from dual-booting.
How to Enable GPU Access in WSL
Here is the typical process:
- Open PowerShell or Command Prompt as Administrator and run
wsl --installif you have not set up WSL yet. This installs WSL2 and a default Linux distribution (usually Ubuntu). - Restart your PC if prompted.
- Update WSL to the latest version:
wsl --update. - Launch your Linux distribution and update its packages:
sudo apt update && sudo apt upgrade. - For NVIDIA, install the CUDA toolkit inside WSL by following the official instructions from NVIDIA (they provide a WSL-specific installer). For AMD, install ROCm (if supported) or use the DirectML backend for frameworks like PyTorch.
- Test with a simple command like
nvidia-smi(NVIDIA) orrocm-smi(AMD) to see if the GPU is visible.
If you see your GPU listed, you are ready to run compute workloads.
Common Problems and Fixes
Many users run into issues when setting up GPU passthrough. Here are typical problems:
- GPU not visible in WSL: Make sure you have the latest Windows driver and WSL version. Also, check that you are using WSL2, not WSL1 (you can convert with
wsl --set-version).2 - CUDA not working: Install the CUDA toolkit inside WSL using the specific instructions for WSL; the standard Linux installer may not work correctly.
- Performance is poor: Ensure you are not running an older driver that lacks WSL support. Also, close heavy GPU applications on Windows that might compete for resources.
- Out of memory: WSL2 has a default memory limit; you can increase it by creating a
.wslconfigfile in your Windows user folder with[wsl2]andmemory=8GB(adjust as needed).
GPU Passthrough vs. Dual Booting vs. Virtual Machines
There are three common ways to run Linux with GPU acceleration:
- Dual booting: You install Linux on a separate partition and reboot to use it. This gives full native performance and full driver support, but you cannot run Windows and Linux simultaneously.
- Virtual machine with GPU passthrough (e.g., using KVM/QEMU): You assign a physical GPU to the VM, which requires a second GPU for the host and often advanced configuration. Performance is near-native, but setup is complex and hardware-dependent.
- WSL2 GPU paravirtualization: This is the easiest method. It shares the GPU with Windows, so you can run Linux tools alongside Windows apps. Performance is slightly lower than native due to the translation layer, but for most compute tasks it is within a few percent of native.
WSL2 is the best choice for developers who need to run Linux tools occasionally without leaving Windows. If you need maximum performance or require full Linux graphics stack (like a desktop environment), dual booting or a VM might be better.
Performance and Limitations
GPU performance in WSL is generally excellent for compute. Benchmarks from various sources show that CUDA workloads run at near-native speed, often within 5-10% of a native Linux installation. However, there are limitations:
- You cannot use the GPU for display output inside WSL (no X11 or Wayland directly on the GPU). You can run GUI apps via WSLg, but they use a virtual GPU, not the physical one.
- Some GPU features like video encoding or decoding might not be fully exposed, depending on the driver and application.
- Multiple GPUs are supported, but you may need to configure them explicitly.
- CUDA versions must be compatible with the Windows driver; NVIDIA provides a compatibility matrix.
Frequently Asked Questions
Can I play games inside WSL using GPU passthrough?
No. WSL does not support running Windows games or Linux games that need a full GPU stack for rendering. The GPU is only for compute tasks like machine learning, data processing, and rendering (via headless tools like Blender in background mode). For gaming, use Windows natively or a virtual machine with GPU passthrough.
Does WSL GPU passthrough work with AMD GPUs?
Yes, AMD GPUs are supported through the DirectML backend, which works with frameworks like PyTorch and TensorFlow. However, native ROCm support inside WSL is limited; you may need to use the DirectML plugin. Check the official documentation for your specific GPU model.
Do I need to install Linux drivers inside WSL?
No. The Windows driver handles the GPU, and WSL uses a virtual driver to communicate with it. Installing Linux drivers can cause conflicts and is not recommended.
How do I check if my GPU is accessible in WSL?
For NVIDIA, run nvidia-smi in the WSL terminal. If it shows your GPU, the setup is working. For AMD, try rocm-smi or check if your framework detects the GPU (e.g., torch.cuda.is_available() in PyTorch).
Is WSL GPU passthrough safe for my system?
Yes, it is a Microsoft-supported feature. It does not require you to open your PC or modify hardware. However, always keep your Windows and GPU drivers up to date to avoid security issues.