How to Enable GPU Acceleration in Windows Containers
Windows Server 2019 and Windows 10 version 1809 brought with them some new features for Windows Containers. Including support for hardware devices and Graphical Processing Unit (GPU) acceleration. Because containers are often used for Internet of Things (IoT) workloads, applications need to be able to connect to sensors and other peripheral devices. But until now, that wasn’t possible with Windows Containers. At present, Windows Containers has limited hardware support for simple buses, like COM and I2C, but it is likely that Microsoft will expand this support in the future.
But the need for GPU acceleration in Windows Containers might seem less clear. The first point is that Linux Docker and LXD containers already support GPU acceleration, so Windows needed to step up to that challenge. Secondly, there are certain types of applications that benefit from the parallel processing power offered by GPUs, enabling organizations to reduce costs and speed up their apps. One example that comes to mind is machine learning (ML).
Accelerated Direct X and Windows ML
Windows Containers now support GPU-accelerated DirectX in Windows Server 2019. DirectX isn’t just for games. It provides developers with a set of APIs that can be used for multimedia, computation, and simulation. DirectX is the go-to API for accelerated graphics, compute, and artificial intelligence (AI) on Windows, so it made sense for Microsoft to start there. And a nice side effect is that frameworks built on DirectX also benefit, like Windows ML, which is a set of APIs for AI.
Before you can enable GPU acceleration in Windows Containers, the host system needs to meet the following requirements:
- Running Windows Server 2019 or Windows 10 version 1809, or later.
- The container base image must be microsoft.com/windows:1809 or later. Server Core and Nano images aren’t supported.
- Hyper-V isolation mode isn’t supported.
- The host must have WDDM 2.5 display drivers or newer.
- The host must be using Docker 19.03 or later.
You can check the driver model for your system’s display drivers by running the DirectX Diagnostic Tool (dxdiag.exe). Run the tool and then click on the Display tab. On the right under Drivers, you will see the driver model installed on your system.
Start Container with GPU Acceleration
Assuming the host device meets the requirements set out above, all you need to do is start a container and specify the –device option as shown below, replacing windows-test-image with the Docker image you want to use.
docker run --isolation process --device class/5B45201D-F2F2-4F3B-85BB-30FF1F953599 windows-test-image
For more information about working with Windows Containers, see First Steps: Docker and Containers in Windows Server 2016 on Petri.
Microsoft says that enabling GPU acceleration in Windows Containers schedules GPU resources dynamically between the host and containers, like they are scheduled when you have several different DirectX apps running on one device.
While Windows Containers are unlikely to usurp Linux containers any time soon, improving device support is clearly important for Microsoft so that it can offer a range of capabilities for Windows workloads using Azure IoT Edge.