install wsl2
prerequisites
Windows 10 version 2004 and later (build 19041 and later) or Windows 11
通过按 Windows 徽标键 + R ---输入winver,单击确定,检查你的 Windows 版本
Please upgrade if the internal version is lower than required . Log in to your windows account and upgrade windows to the preview version, (the process may take 1-2 hours)
After the upgrade is complete, verify whether the internal version is lower than 19041. If it is still lower , it means that you have selected the wrong upgrade channel. Be sure to choose the Dev channel, the latest channel, and get the latest version
Install preview nvdia driver
GPU in Windows Subsystem for Linux (WSL) | NVIDIA Developer
You need to log in to your nvidia account to download. After logging in to your account, download the nvidia version that suits you.
Enable windows subsystem features
Install WSL2
1. Administrator PowerShell
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Restart the computer
2. Admin PowerShell sets WSL2 as the default version
wsl --set-default-version 2
Prompt "WSL 2 needs to update its kernel components". Download and install the WSL2 Llinx kernel
3. Then enter the Microsoft store to download and install the corresponding ubuntu version. Or go here to choose a specific Linux version
Two ways to log in to wsl2
If the system cannot enter and reports an error , you need to download and install the WSL2 Llinx kernel
Make sure the linux kernel of WSL2 is 4.19.121+
uname -a
verify-wsl2
↓↓↓↓↓↓↓↓↓↓↓ Windows Administrator PowerShell
wsl --list --verbose
As long as this version is 2, the wsl2 installation is successful. (Only 2 can call the GPU)
install docker
The following code is executed line by line
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
Install nvidia-docker
Use nvdia-docker directly, the current system does not need to install cuda
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
curl -s -L https://nvidia.github.io/libnvidia-container/experimental/$distribution/libnvidia-container-experimental.list | sudo tee /etc/apt/sources.list.d/libnvidia-container-experimental.list
sudo apt-get update
sudo apt-get install -y nvidia-docker2
restart docker
sudo service docker stop
sudo service docker start
Verify that nvidia-docekr can call GPU
Create a tensorflow container
sudo docker run --runtime=nvidia --rm -it --name tensorflow-1.14.0 tensorflow/tensorflow:1.14.0-gpu-py3
If an error is reported, it is because the latest version of nvidia-docker has a BUG (2022-2-10 re-test this bug has been resolved)
docker: Error response from daemon: OCI runtime create failed: container_linux.go:367: starting container process caused: process_linux.go:495: container init caused: Running hook #1:: error running hook: exit status 1, stdout: , stderr: nvidia-container-cli: initialization error: driver error: failed to process request: unknown.
Downgrade some packages
sudo apt-get install nvidia-docker2:amd64=2.5.0-1 \
libnvidia-container-tools:amd64=1.3.3-1 \
nvidia-container-runtime:amd64=3.4.2-1 \
libnvidia-container1:amd64=1.3.3-1 \
nvidia-container-toolkit:amd64=1.4.2-1
run the container again
sudo docker run --runtime=nvidia --rm -it --name tensorflow-1.14.0 tensorflow/tensorflow:1.14.0-gpu-py3
Test if the GPU is available
python
import tensorflow as tf
print(tf.test.is_gpu_available())
Windows wsl operation skills and commands
Windows wsl operation skills and commands_SUNbrightness' Blog-CSDN Blog_wsl Skills
reference link
CUDA on WSL :: CUDA Toolkit Documentation
nvidia-docker 2.6.0-1 - not working on Ubuntu WSL2 · Issue #1496 · NVIDIA/nvidia-docker · GitHub