Getting started with CUDA on Ubuntu on WSL 2

栏目: IT技术 · 发布时间: 4年前

内容简介:At Build 2020 Microsoft announcedThis guide will walk early adopters through the steps on turning their Windows 10 devices into a CUDA development workstation with Ubuntu on WSL.For our purposes we will be setting up Jupyter Notebook in Docker with CUDA on

At Build 2020 Microsoft announced support for GPU compute on Windows Subsystem for Linux 2 . Ubuntu is the leading Linux distribution for WSL and a sponsor of WSLConf . Canonical, the publisher of Ubuntu, provides enterprise support for Ubuntu on WSL throughUbuntu Advantage.

This guide will walk early adopters through the steps on turning their Windows 10 devices into a CUDA development workstation with Ubuntu on WSL.

For our purposes we will be setting up Jupyter Notebook in Docker with CUDA on WSL. These instructions can be adapted to set up other CUDA GPU compute workloads on WSL.

Getting started with CUDA on Ubuntu on WSL 2

Install Windows 10 Insiders Dev Channel

To begin, we need the latest Windows 10 Insider build released today, June 17, 2020. You will need to register as a Windows Insider if you have not already, enroll your device in the Dev Channel (previously known as the ‘Fast Ring’), and then upgrade to Windows 10 build number 20150 or above.

Getting started with CUDA on Ubuntu on WSL 2

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

For now, open PowerShell as Administrator.

First enable WSL 1:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
Getting started with CUDA on Ubuntu on WSL 2

Then enable WSL 2:

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Getting started with CUDA on Ubuntu on WSL 2

Restart Windows 10:

Restart-Computer

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
Getting started with CUDA on Ubuntu on WSL 2

To read more about Ubuntu on WSL, visitubuntu.com/wsl. For a more detailed look at enabling WSL on Windows, check out ourtutorial. 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 :

Getting started with CUDA on Ubuntu on WSL 2

For other ways to install Ubuntu on WSL, see ourWSL 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.

Getting started with CUDA on Ubuntu on WSL 2

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:

Getting started with CUDA on Ubuntu on WSL 2

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:

Getting started with CUDA on Ubuntu on WSL 2

Now check to make sure you are running the correct WSL 2 Linux kernel.

In Ubuntu:

uname -r
Getting started with CUDA on Ubuntu on WSL 2

You will need kernel 4.19.121 or higher. If you do not have kernel 4.19.121, first try:

wsl.exe --update

If that does not work, make sure you have ‘Receive updates for other Microsoft products when you update Windows’ checked:

Getting started with CUDA on Ubuntu on WSL 2

And then re-run Windows updates:

Getting started with CUDA on Ubuntu on WSL 2

Install Nvidia Drivers on Windows 10

Getting started with CUDA on Ubuntu on WSL 2

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
Getting started with CUDA on Ubuntu on WSL 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
Getting started with CUDA on Ubuntu on WSL 2

Refresh the Ubuntu apt repositories and then install the Nvidia runtime:

sudo apt update && sudo apt install -y nvidia-docker2
Getting started with CUDA on Ubuntu on WSL 2

Close all open terminals of Ubuntu, open a PowerShell terminal, and manually shutdown Ubuntu:

wsl.exe --shutdown Ubuntu
Getting started with CUDA on Ubuntu on WSL 2

Test GPU Compute

Open a new Ubuntu terminal and run:

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

If everything is configured correctly, the output should resemble:

Getting started with CUDA on Ubuntu on WSL 2

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
Getting started with CUDA on Ubuntu on WSL 2

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

Your default browser on Windows will launch with a GPU-accelerated Jupyter notebook:

Getting started with CUDA on Ubuntu on WSL 2

You are now all set to begin using TensorFlow with CUDA on Ubuntu WSL.


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

精通正则表达式

精通正则表达式

Jeffrey E. F. Friedl / 余晟 / 电子工业出版社 / 2007 / 75

随着互联网的迅速发展,几乎所有工具软件和程序语言都支持的正则表达式也变得越来越强大和易于使用。本书是讲解正则表达式的经典之作。本书主要讲解了正则表达式的特性和流派、匹配原理、优化原则、实用诀窍以及调校措施,并详细介绍了正则表达式在Perl、Java、.NET、PHP中的用法。 本书自第1 版开始着力于教会读者“以正则表达式来思考”,来让读者真正“精通”正则表达式。该版对PHP的相关内容、Ja......一起来看看 《精通正则表达式》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具