[PYTHON] Talk about installing CUDA on WSL2

Preface

It seems that WSL2 finally supports CUDA. Not only can I run unix on Windows, but I'm very happy to be able to run heavy machine learning algorithms on CUDA. Your study is progressing. Right now, it seems that only users who participated in the Windows Insider Program and applied the Dev channel to their PCs, but I just hope that a stable version will come out later.

So, I would like to install Ubuntu with WSL2 and install an environment that can execute PyTorch and Tensorflow via CUDA. Confirmation of installation is done by GPU calculation of PyTorch.

Caution

This procedure is current as of July 18, 2020 and is likely to change with future Windows Updates. In addition, the operating environment may become unstable because the Preview version of Windows Update is implemented. ** We cannot guarantee the execution at all, so please do it at your own risk. ** It takes a lot of time and there are many steps.

Advance preparation

--Create a Microsoft account --Create an Nvidia account --Windows Update and reboot

Installation procedure

Part 1: Installation of WSL2

Step 1. Enable the following functions in "Turn Windows functions on or off".

  1. Open "Settings" in the Windows menu
  2. Open "Apps"
  3. Open "Programs and Features"
  4. Open "Turn Windows features on or off"

Step 2. Restart your PC

Step 3. Run PowerShell as an administrator (cannot be run at the command prompt)

Step 4. Enable Windows Subsystem for Linux

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

Step 4. Enable the optional components of the virtual machine platform

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

Step 5. Download the latest Linux kernel update package from the following site and update the kernel.

-WSL 2 Linux Kernel Update

Step 6. Set the default version of WSL to 2.

wsl --set-default-version 2

Part 2: Install Ubuntu 18.04 on WSL2

Step 1. Open "Microsoft Store"

Step 2. Enter "Ubuntu" in the search window

Step 3. Install Ubuntu 18.04 (CUDA does not yet support 20.04)

Step 4. Start Ubuntu 18.04 with PowerShell and complete the initial settings (register user name and password).

wsl -d Ubuntu-18.04

Step 5. Do apt update & upgrade.

sudo apt update
sudo apt upgrade -y

Step 6. Log out of Ubuntu and check if the WSL version is 2.

wsl -l -v

Step 7. Check if the WSL version is 121 or higher

wsl -d Ubuntu-18.04 uname -r
#For example, 4.19.121-microsoft-standard,Is displayed
  1. Open "Advanced Options" on the "Windows Update" settings screen.
  2. Enable "Receive updates for other Microsoft products when updating Windows"
  3. Perform Windows Update and restart your PC
  4. Update wsl
wsl -d Ubuntu-18.04 --update

Part 3: Perform windows update for Dev channel

** * Be careful as it takes a long time for the first time **

Step 1. Open Windows "Settings"

Step 2. Open "Update and Security"

Step 3. Open the "Windows Insider Program" and register for an account. At this time, select "Dev channel"

Step 4. Perform Windows Update and restart according to the instructions on the screen.

Part 4: Install the Preview version of the NVIDIA driver on Windows

** * Install on Windows, not Ubuntu **

Step 1. Download the Preview version of the NVIDIA driver for your GPU

Step 2. Execute the downloaded file and install it ()

Part 5: Install CUDA Toolkit on Ubuntu

Step 1. Download the CUDA Toolkit

** * Install on Ubuntu, not Windows, and be careful about OS selection **

** * Install the version that matches PyTorch or Tensorflow that you want to execute later (here, v10.1) **

Step 2. Install CUDA according to the web page display procedure.

Part 6: Install PyTorch

Step 1. Start Ubuntu with WSL2

wsl -d Ubuntu-18.04

Step 2. Install pyenv (or python3)

-Talk about installing pyenv on ubuntu 20.04 [Updated on 2020/07/18]

Step 3. Install PyTorch.

-PyTorch official website

Step 4. Confirm execution in CUDA

-How to check if GPU is available in Pytorch

References

It was very helpful. Thank you very much. -Waiting for CUDA on WSL2 -[Use GPU with WSL 2 (Run CUDA, PyTorch and TensorFlow 2.2 GPU version on WSL 2 Ubuntu. Do not use Docker, use Windows 10 Insider Program, Ubuntu on WSL 2)](https: // www.kkaneko.jp/tools/wsl/wsl_tensorflow2.html) -Installation of WSL 2, installation and use of Ubuntu 20.04, 18.04

Recommended Posts

Talk about installing CUDA on WSL2
[Go] Procedure for installing Go on WSL2
Install python on WSL
Linux (WSL) on Windows
Notes on installing PycURL
Installing pandas on python2.6
Installing pyenv on ubuntu 16.04
Questions about installing chromedriver-binary
Notes on installing dlib on mac
Notes on installing Python on Mac
wsl Install PostgreSQL on Ubuntu 18.04
Notes on installing pipenv on Mac
Install Docker on WSL Ubuntu 18.04
Notes on installing Anaconda 3 on Windows
Linux environment construction (on WSL environment)
Notes on installing Python on CentOS
Use Linux on Windows 10 (WSL2)