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.
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
The parts that differ from the existing articles are ① and ⑥, so if it doesn't work, please deal with only those parts.
How to make GPU recognized by WSL Windows Subsystem Kernel Release Notes for Linux It is described in
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 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.
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)
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.
You can check it on Ubuntu with this command.
docker run --gpus all nvcr.io/nvidia/k8s/cuda-sample:nbody nbody -gpu -benchmark
You can see that GeForce is recognized.
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
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.
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()
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.
I was able to use the GPU like Linux even on Windows OS. Personally, I think Linux is fine for everything.
My PC is Pro, not Home. In addition, the version when GPU recognition is possible is the following version.
-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