hans

hans

【WSL】Configuring WSL2 to Utilize GPU in WIN10


It took me a few days to figure it out, but I couldn't successfully use the GPU in WSL. I've read through all the official tutorials, but couldn't find a solution. In the end, on the verge of madness, I saw a netizen saying that in order to use GPU with WSL on WIN10, the system must be version 21H2. I entered "winver" in WIN+R and checked that mine was 20H2, so I found the problem. Now looking back, the official tutorial is really crap. They ask you to join the Insider Program, but they don't tell you that you have to manually update the system version. I stupidly researched it for several days.

Here is a rough configuration process:

  1. Register for the Insider Program [https://insider.windows.com/en-us/getting-started#register];

  2. In Settings → Update & Security → Windows Update, find and update the system to 21H2.

  3. Download and install the CUDA driver for WSL in the Windows system [https://developer.nvidia.com/cuda/wsl/download].

  4. Install and update WSL to version 2 [https://docs.microsoft.com/en-us/windows/wsl/install-manual].

  5. Search for Ubuntu in the Microsoft Store, install it, and open it to start a container. Set a username and password.

  6. Run the following command in Windows PowerShell to confirm that the Ubuntu container version is 2:

    wsl -l -v
    
  7. Install CUDA inside the container. Note that you do not need to install the driver inside the container [https://docs.nvidia.com/cuda/wsl-user-guide/index.html#installing-nvidia-drivers]. Start from section 4.2.6 "Building Your Own GPU-accelerated Application on WSL 2".

  8. Add environment variables:

    vim ~/.bashrc
    
    export CUDA_HOME=/usr/local/cuda
    export LD_LIBRARY_PATH=${CUDA_HOME}/lib64
    export PATH=${CUDA_HOME}/bin:${PATH}
    
    source ~/.bashrc
    
  9. At this point, you should be able to use the following commands:

    nvcc --version
    nvidia-smi
    

If you didn't update the system in the second step, nvidia-smi will prompt that it cannot access the GPU device due to system restrictions.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.