Using CUDA with WSL on Windows 11

A short introduction to CUDA on WSL: GPU in Windows Subsystem for Linux (WSL) | NVIDIA Developer.

Installing WSL

Following the user guide provided by NVIDIA: CUDA on WSL User Guide — CUDA on WSL 13.0 documentation, you can install WSL by:

wsl.exe --install

and update it by:

wsl.exe --update

If you have any problems installing WSL by the default way, you can also download WSL from GitHub: Releases · microsoft/WSL and install the pre-compiled binaries.

Basic operations of WSL:

# List all installed distros
wsl -l -v

# List all available distros online
wsl --list --online

# Check WSL status
wsl --status

# Check WSL version
wsl --version

Enabling Hyper-V and Setting Network Mode

You need to enable Hyper-V for WSL by:

打开”控制面板“并选择”程序和功能>”启用或关闭 Windows 功能“。
选中“Hyper-V”,单击“确定”
For reference: 用电脑自带Hyper-V安装虚拟机(超详细版) – 知乎

You need to set the network mode of WSL as Mirrored:

WSL Settings->网络->网络模式->”Mirrored”.

Installing build-essential

The CUDA Toolkit installation requires compilation tools such as GCC and etc. which can be installed by:

sudo apt install build-essential

Installing CUDA Toolkit

Warning: You should NOT install CUDA Driver again in the Linux sub-system.

You can download the CUDA Toolkit for WSL-Ubuntu from: CUDA Toolkit 13.0 Update 2 Downloads | NVIDIA Developer

Running something like:

wget https://developer.download.nvidia.com/compute/cuda/13.0.2/local_installers/cuda_13.0.2_580.95.05_linux.run
sudo sh cuda_13.0.2_580.95.05_linux.run

Now check if CUDA Toolkit is well-installed by:

nvcc -V