/WSL2-CUDA

Configuration for WSL2 + Ubuntu + CUDA + CuDNN

Primary LanguageShell

Configure Deep Learning Environment with WSL2

Last Update: 27 July 2021

GET WSL2 READY

Check the official blog first: https://docs.microsoft.com/en-us/windows/wsl/install-win10

ENSURE THAT YOUR WINDOWS VERSION IS SUPPORTED

  • Open PowerShell as Administrator and run:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
  • You may also need to enable Hyper-V by:
  1. Right-clicking uninstall on any classic programs installed, which will jump you to the classic programs & functionalities panel.
  2. Look to the left. Click on "Activate or Deactivate Windows Functionalities"
  3. Tick Hyper-V and Apply.
wsl --set-default-version 2

GET Ubuntu READY w/ NVIDIA Support

NOTE: mindless updates to the driver may cause trouble

After Ubuntu installation, initialize the system by clicking on the Ubuntu application icon in the Start menu.

With the help of the navigation panel on the left of Explorer, clone the sh files in this repo to somewhere inside your created /home/.

  • Run Windows Terminal. Use the downward arrow button to initialize a terminal with Ubuntu.

  • cd to the folder where the .sh files are at.

  • Install dos2unix in case of any trouble:

sudo apt install dos2unix
  • Then convert the .sh files to unix encoding:
dos2unix *.sh
  • Get CUDA, CuDNN and python-3.8 configured by:
sudo bash WSL2_init.sh

Key-in your password. This would install cuda 10.2 and 11.2 with their corresponding cudnns. Modify to suit your needs.

OPTIONAL: GET TensorFlow and PyTorch in a virtual Python environment

Optionally, create a virtual environment at ~/ENV/ by

bash WSL2_python.sh

No sudo this time. Then:

source ~/ENV/bin/activate
pip install --upgrade pip
pip install --upgrade tensorflow # get tensorflow + cuda 11
pip install torch torchvision torchaudio # get pytorch + cuda 10.2

Change the corresponding versions of cuda for the libraries if you would like. Test with:

source ~/ENV/bin/activate
python

When in Python:

import tensorflow as tf, torch
tf.zeros(1)
torch.zeros(1).cuda()

Check for errors. If none, enjoy!

BONUS: for tensorflow's libcusolver.so.11 not found error

sudo ln -s /usr/local/cuda-11.2/targets/x86_64-linux/lib/libcusolver.so.11 ~/ENV/lib/python3.8/site-packages/tensorflow/python/libcusolver.so.11