WSL

WSL2 CUDA Installation

Guidance about install CUDA in WSL2

Posted by Huajian on August 5, 2022
Viewed times

Reference-1
Reference-2

Install CUDA driver for WSL

  • In Windows-Device Manager(设备管理器) find your GPU
  • In [here](https://developer.nvidia.com/cuda/wsl](https://developer.nvidia.com/cuda/ws) click Get CUDA Driver and choose driver same as your GPU
  • Downlaod and install driver as default.

Install WSL2 in Microsoft Store

  • use wsl -l -v in Powershell to make sure you correctly install WSL2 if not,use following commands set default version(e.g. Ubuntu-18.04):
    wsl -l
    wsl --set-version Ubuntu-18.04 2 
    wsl -l -v
    wsl --set-default-version 2
    

Install CUDA inside Ubuntu

  • Update & Upgrade
    $ sudo apt update 
    $ sudo apt upgrade
    
  • Install CUDA Toolkit, choose Install(Here we install with cudatollkit 11.2.0)
    wget https://developer.download.nvidia.com/compute/cuda/11.2.0/local_installers/cuda_11.2.0_460.27.04_linux.run
    sudo sh cuda_11.2.0_460.27.04_linux.run
    

  • Add PATH
    export PATH=/usr/local/cuda-11.2/bin${PATH:+:${PATH}} 
    export LD_LIBRARY_PATH=/usr/local/cuda-11.2/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
    

    you can also make them permanently effective by adding in ~/.bashrc:

  • vim ~/.bashrc
    add them into bottom of files
  • don’t forget source ~/.bashrc

  • Verify successful installation by nvcc -V

Test CUDA is available

Install Conda

  • Always input yes if need during install
    cd ~
    $ wget https://repo.anaconda.com/archive/Anaconda3-2022.05-Linux-x86_64.sh
    $ bash Anaconda3-2022.05-Linux-x86_64.sh
    $ source ~/. bashrc
    

Create Pytorch Environment

  • Create conda environment: conda create --name torch python=3.8

  • Activate environment: conda activate torch

  • Install Pytorch: conda install pytorch torchvision torchaudio cudatoolkit=11.6 -c pytorch

  • Verify:

      $ python
      >> import torch 
      >> torch.cuda.is_available()
    
      # return True if everyting okay
    

Top
Down