How to setup CUDA on WSL

Linux/Windows dual boot works fine, but there are cases where this is not feasible. A computer may have to do most of its work under Windows because of certain application. When Linux is required, the Windows Subsystem for Linux works great. I use it for running Machine Learning/AI projects that require a Linux environment on Windows workstations.

An important part is being able to use the computer’s GPU(s) for processing, which is especially important for AI applications that gain a huge performance boost from using a GPU. Most academic code that I’ve encountered is built upon the PyTorch library and expects an Nvidia GPU and it CUDA programming interface. Installing CUDA is relatively straightforward, but differs a bit from “real” Linux.

Nvidia offers special CUDA packages for WSL. The installation is described here. The description is for the latest version of CUDA (12.3 at the time of writing), but you can easily apply it to earlier versions by changing the version numbers in the commands.If afterwards you run into errors with libraries not being found, you’ll have to fix some links as explained here.

The memory available to WSL is limited by default to leave enough memory for Windows. If this causes issues on a system with plenty of RAM, you can increase the limit as described here.

From there on you probably want to install Miniconda, create a new environment, and then install the Python packages that you need.

 

Leave a comment

Your email address will not be published. Required fields are marked *