当前位置:   article > 正文

WSL2 安装教程 CUDA 配置 自测已成功_$ docker run --rm -it --gpus=all nvcr.io/nvidia/k8

$ docker run --rm -it --gpus=all nvcr.io/nvidia/k8s/cuda-sample:nbody nbody
Install Windows 10 Insiders Dev Channel

Windows Insider
在这里插入图片描述
Consult the Windows Insider documentation for more information on registering as an Insider, enrolling your device, and upgrading your machine to the Dev Channel.

Enable WSL 2

In future updates to Windows you will simply need to use the following to enable WSL:

wsl --install
  • 1

For now, open PowerShell as Administrator.

First enable WSL 1:

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

在这里插入图片描述
Then enable WSL 2:

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

在这里插入图片描述
Restart Windows 10:

Restart-Computer
  • 1

This step will become redundant in the future after WSL 2 becomes the default, but for now return to PowerShell and make WSL 2 your default before installing Ubuntu:

wsl.exe --set-default-version 2
  • 1

在这里插入图片描述
To read more about Ubuntu on WSL, visit ubuntu.com/wsl. For a more detailed look at enabling WSL on Windows, check out our tutorial. To convert existing WSL 1 installs to WSL 2, see my blog on the general availability of WSL 2.

Install Ubuntu on WSL

Install Ubuntu from the Microsoft Store:
在这里插入图片描述
For other ways to install Ubuntu on WSL, see our WSL wiki.

Install Windows Terminal

Optionally, you may install the new Windows Terminal from the Microsoft Store. It is has many features, such as GPU acceleration and customizability, that improves the Ubuntu experience on WSL over the traditional Windows console.
在这里插入图片描述
Windows Terminal can also be installed from the project’s GitHub page.

Setup Ubuntu on WSL

Open Ubuntu from the Windows Start Menu and configure your WSL user. This user is separate from your Windows user:
在这里插入图片描述
If you downloaded Windows Terminal you can then close the old console and re-open Ubuntu from the drop-down options in the new Terminal:
在这里插入图片描述
Now check to make sure you are running the correct WSL 2 Linux kernel.

In Ubuntu:

uname -r
  • 1

在这里插入图片描述
You will need kernel 4.19.121 or higher. If you do not have kernel 4.19.121, first try:

wsl.exe --update
  • 1

If that does not work, make sure you have ‘Receive updates for other Microsoft products when you update Windows’ checked:
在这里插入图片描述
And then re-run Windows updates:
在这里插入图片描述

Install Nvidia Drivers on Windows 10

在这里插入图片描述
Next, download the appropriate driver for your GeForce or Quadro Nvidia card.

In the next few months, the NVIDIA driver will be distributed via Windows Update, which will manually downloading and installing the driver unnecessary.

You will need to join the Nvidia Developer Program for early access to the driver for now. You can read more about CUDA on WSL on the Nvidia Developer blog.

Install Docker in WSL
# sudo apt -y install docker.io
curl https://get.docker.com | sh
  • 1
  • 2

在这里插入图片描述

Install Nvidia Container Toolkit

Set the distribution variable, import the Nvidia repository GPG key, and then add the Nvidia repositories to the Ubuntu apt package manager:

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

在这里插入图片描述
Refresh the Ubuntu apt repositories and then install the Nvidia runtime:

sudo apt update && sudo apt install -y nvidia-docker2
  • 1

在这里插入图片描述
Close all open terminals of Ubuntu, open a PowerShell terminal, and manually shutdown Ubuntu:

wsl.exe --shutdown Ubuntu
  • 1

在这里插入图片描述

Test GPU Compute

Open a new Ubuntu terminal and start Docker:

sudo service docker stop
sudo service docker start
  • 1
  • 2

在这里插入图片描述

And then run:

docker run --gpus all nvcr.io/nvidia/k8s/cuda-sample:nbody nbody -gpu -benchmark
  • 1

If everything is configured correctly, the output should resemble:
在这里插入图片描述
在这里插入图片描述

Start A TensorFlow Container

Open a new Ubuntu terminal and run:

docker run -u $(id -u):$(id -g) -it --gpus all -p 8888:8888 tensorflow/tensorflow:latest-gpu-py3-jupyter
  • 1

在这里插入图片描述
在这里插入图片描述

Open a second Ubuntu terminal, type wslview, copy and paste the notebook URL, but then edit the URL from 127.0.0.1 to localhost:

wslview http://localhost:8888/?token=a83a1ad288a7bf1bd1deb694c8a7f19223c8d0baa7d5fb3c
  • 1

Your default browser on Windows will launch with a GPU-accelerated Jupyter notebook:
在这里插入图片描述
You are now all set to begin using TensorFlow with CUDA on Ubuntu WSL.

Test PyTorch CUDA

在这里插入图片描述


干掉Linux桌面,微软Win10带来重大更新

Ref
  1. Getting started with CUDA on Ubuntu on WSL 2
  2. 如何在WSL2中安装CUDA
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/128512
推荐阅读
相关标签
  

闽ICP备14008679号