GPU recognition with docker using WSL2 (August 2020)

Introduction

This is the nth decoction, but it is an article that was made GPU-recognized by Docker with WSL2 when I bought a PC with Windows OS. There was a difference from the existing technical article, so I made a new article.

Summary

First, I will write a summary. As for what to do

--Step 1: Update Windows --Step 2: Install WSL2 --Step ③: Install Ubuntu --Step ④: Install Cuda driver for WSL (not for Linux) --Step ⑤: Docker installation on WSL2 Ubuntu --Step ⑥: Install CudaToolKit on WSL2 Ubuntu --Step ⑦: Confirm GPU recognition

is.

The parts that differ from the existing articles are ① and ⑥, so if it doesn't work, please deal with only those parts.

Step 1: Update Windows

How to make GPU recognized by WSL Windows Subsystem Kernel Release Notes for Linux It is described in

image.png

You need to update to the version of. Many tech articles say that Windows Insider Preview Fast should be selected and updated, but be aware that on June 15, 2020, Windows Insider was redesigned and became a Dev / Beta / Release Preview channel. please.

It is written in this article [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) Update by method, but not fast image.png Select a Dev channel and update. I think it will take a while.

Also, many technical articles describe how to update after installing WSL, but as of August 29, 2020, the wsl --update and wsl.exe --update commands exist. Otherwise, an error will occur at runtime, so please update Windows itself.

↓ The wsl --update and wsl.exe --update commands described in these articles do not exist, so you need to update the main unit first. It seems that you can finally run WSL2 + docker + GPU, so I will try it [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)

Step ② ~ Step ⑥

I referred to this article. Waiting for CUDA on WSL2 However, I installed CudaToolKit on Ubuntu of WSL2 in step ⑥, but I entered the sudo apt-get install -y cuda-toolkit-11-0 command, but it was said that it does not exist (August 2020). As of 29th of March) I tried sudo apt-get install -y cuda-toolkit and it was installed. I am also suspicious here, so if it does not work, please refer to other technical articles.

The technical article of Waiting CUDA on WSL2 is basically the official NVIDIA official article CUDA on WSL User Guide It is a Japanese translation of .nvidia.com/cuda/wsl-user-guide/index.html), so if the reference article does not work, please refer to the official as well.

Step ⑦: Confirm GPU recognition

You can check it on Ubuntu with this command. docker run --gpus all nvcr.io/nvidia/k8s/cuda-sample:nbody nbody -gpu -benchmark image.png

You can see that GeForce is recognized.

Confirm GPU recognition with TensorFlow

The details of Docker are not described here, but as soon as you complete up to ⑦, you can execute TensorFlow in the GPU environment, so I will also write how to do it.

First, create a directory on Ubuntu for application.

mkdir test
cd test

So we use the latest-gpu-py3-jupyter tag for tensorflow / tensorflow images.

docker run --rm --gpus all --privileged -it -p 8888:8888 -v "$PWD":/tf/notebook tensorflow/tensorflow:latest-gpu-py3-jupyter

image.png

Although it is not a Docker article, if you explain the command briefly, this -v" $ PWD ": / tf / notebook part is called a bind mount, and the directory and container are linked. So the files created in the container will be saved in this current directory, here the test directory.

Then access your browser on port 8888. Enter http: // localhost: 8888 in your browser URL. You will be asked for a password, so enter the token. When you do docker run, token is also displayed on the screen, so copy it.

image.png

Also, make sure you really recognize the GPU. Create a notebook and enter the following command.

from tensorflow.python.client import device_lib
device_lib.list_local_devices()

image.png

I was able to confirm that the GPU is recognized.

Although it is a created file, you can confirm that the file is created in the test directory on the host side. In this case, check it with another Ubuntu Window or Explorer.

in conclusion

I was able to use the GPU like Linux even on Windows OS. Personally, I think Linux is fine for everything.

Remarks

My PC is Pro, not Home. In addition, the version when GPU recognition is possible is the following version. image.png

Reference article

-Windows Subsystem Kernel Release Notes for Linux -[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) -Waiting for CUDA on WSL2

Recommended Posts

GPU recognition with docker using WSL2 (August 2020)
Explode Docker with WSL2
Comfortable development life with WSL2 + Docker Desktop + GPU
Docker autostart settings with wsl2
Build docker environment with WSL
Using PlantUml with Honkit [Docker]
Using Docker on Windows10 Home WSL2
Use cuda11.0 with pytorch using Docker
GPU environment construction with Docker [October 2020 version]
Using JupyterLab + Java with WSL on Windows 10
I tried using Scalar DL with Docker
Proxy server with squid using docker image
Image flew when updating Docker with WSL2
Try using Kong + Konga with Docker Compose.
Install Docker with WSL2 Memo ([Part 2] Docker introduction)
Specify ClassPath when using jupyter + Java with WSL
Make Volume faster when using Docker with vscode.
Try using another Servlet container Jetty with Docker
Feel free to try Elasticsearch cluster with WSL2 + Docker
Build Java development environment with WSL2 Docker VS Code
Comfortable Docker environment created with WSL2 CentOS7 and Docker Desktop
Create Chisel development environment with Windows10 + WSL2 + VScode + Docker
Using Pair with OpenJDK
Rails deploy with Docker
Run Pico with docker
Use Puphpeteer with Docker
Operate Emby with Docker
Use ngrok with Docker
Run Payara with Docker
[Docker] Connection with MySQL
Php settings with Docker
Getting Started with Docker
Disposable PHP with Docker
Docker installation on WSL2
Install Composer with Docker
Register your own Docker image with ECR using AWS CLI
Measures for permissions when building MySQL with Docker on WSL2