[Article] About GPU support for Windows Subsystem for Linux 2 (WSL2) [1/3]

■ This is an article posted on June 2020, 8, so the content of the information may be out of date.

In recent years, GPGPUs that use GPUs as parallel computing processing, simulations, and AI platforms are becoming more widespread, and we are receiving many inquiries regarding computers for this purpose.

In this case, the problem is the OS environment of the computer. "I usually use a Windows computer, but the intended use is often done on Linux, so I think it is necessary to prepare a separate Linux computer." Isn't it?

This time is one of the ways to run a binary for Linux on WindowsWindows Subsystem for LinuxI will show you the procedure to execute GPGPU code for Linux using.

 

Let's use Linux in a virtual environment

Windows 10 (and Windows Server 2016 and later) has a compatibility layer "Windows Subsystem for Linux (WSL)" that runs binaries for Linux on Windows.Currently, version 2 of WSL has been released (WSL2), and from this version it is possible to run a nearly intact Linux kernel on Windows.

At present, upgrading to WSL2 requires a few steps, but the corresponding Linux distribution can be downloaded from the Windows store, making it relatively easy to test the Linux environment on Windows.

Execute CUDA program from Linux kernel on WSL

first

As of July 2020, the preview version of WSL7 released in the Windows Insider Program for developers for Windows validation enabled GPU support on WSL. This time, I'd like to use this Preview version to verify that the CUDA program is executed from the Linux kernel on WSL.

In order to run the CUDA program, you need to enable "Dev Channel *" in the "Windows Insider Program" and get the latest Preview version.Since the Preview version is updated frequently, the functions introduced in this article may not work properly depending on the version.Also, because it is a Dev channel that offers the earliest build in the development cycle, we do not guarantee that it will retain the same functionality when it is officially released.Please note.

* Windows Insider Program is a Windows validation service for developers, and developers can try out the latest version (OS) at different development stages from three channels ``Dev'' ``Beta'' ``Release Preview'' I can do it.

Dev channel: Provides the fastest build in the development cycle (frequent updates, unstable elements)
beta: Post-branch build (for early adopters, relatively reliable and stable OS)
Release preview: Build close to release (most reliable and stable OS before release)

Windows Insider Program Documentation
https://docs.microsoft.com/ja-jp/windows-insider/

 

1. Preparation for WSL setup

1-1. Install NVIDIA graphics driver on Windows

This article assumes the use of a computer equipped with an NVIDIA GPU that supports CUDA, but install the corresponding graphics driver to run CUDA on WSL2. As of 2020/7/22, driver version 455.41 or later supports CUDA execution on WSL2.

* Please install the graphic driver only on Windows. After that, if you install the Linux version driver on WSL to be set up, CUDA may not operate normally.

1-2. Activate Windows Insider Program

Enable the Dev channel in the Windows Insider Program from the Windows 10 settings Update & Security. If enabled, the Dev channel build will be downloaded via Windows Update, so apply this to update the Windows 10 build.

2. WSL setup

As of 2020/7/22, WSL2 is not set as default version, so you have to manually deploy WSL2. I will omit the explanation of the specific procedure in this article, but please see here as the procedure is published on the Microsoft official website.

Installation Guide for Windows Subsystem for Linux for Windows 10
https://docs.microsoft.com/ja-jp/windows/wsl/install-win10

Below, we will proceed with the explanation based on the state where WSL2 setup is completed and Ubuntu 18.04 is installed as a distribution.

3. Setting up CUDA Toolkit

3-1. Install CUDA Toolkit* on Ubuntu 18.04.

*Please note that at the time of writing this article, only CUDA Toolkit 2 supports GPGPU on WSL11.0.

3-2. CUDA Toolkit is downloaded and installed on Ubuntu via NVIDIA repository*.

*See the NVIDIA official website for repository registration procedures.

CUDA Toolkit 11.0 Download
https://developer.nvidia.com/cuda-downloads

In addition, there are several meta packages including CUDA Toolkit in the repository. As mentioned above, installing the graphics driver on Ubuntu may cause problems, so the package name should be specified so that only the CUDA Toolkit is installed, as shown below.

$ sudo apt-get install cuda-toolkit-11-0

4. Executing the sample program

Once the CUDA Toolkit is installed, you can run the CUDA program on Ubuntu. In the standard installation, the CUDA Toolkit directory is located under /usr/local/cuda/ as in the native environment. The sample file is saved under sample/.

We will post the result of compiling and executing the nbody program for our operation confirmation.

Next time, in the second installment, we plan to measure the performance of the GPGPU calculation executed on WSL2.

Person who wrote this article : Engineering Department Wada
The date this article was written : 2020.7.22
2020/11/13 Update:
[Article] About GPU support of Windows Subsystem for Linux 2 (WSL2) [2/3] has been released!