跳到正文
DEV Community· Sanskriti Harmukh·· 3 小時前AI 評分45

Ubuntu 24.04 安裝支援 ROCm GPU 的 Docker 教學

Installing Docker with ROCm GPU Support on Ubuntu 24.04

AI 導讀

在已配置 AMD ROCm GPU 的 Ubuntu 24.04 系統上,指南示範從 Docker 官方套件庫安裝 Docker,並讓容器存取主機的 ROCm GPU 裝置。容器需使用 /dev/kfd 和 /dev/dri,並可執行 rocm-smi 確認 GPU 是否可用。操作以已配置 ROCm GPU 的伺服器為前提,並透過臨時容器驗證裝置存取。

正文

Cover image for Installing Docker with ROCm GPU Support on Ubuntu 24.04

Vultr profile image Sanskriti Harmukh

Docker is a platform that packages applications and their dependencies into isolated containers so they run consistently on any system. GPU-enabled containers extend this by giving containerized applications access to a machine's Graphics Processing Unit (GPU) for compute-heavy workloads such as machine learning or video processing. This guide installs Docker from Docker's official repository on a ROCm-supported Ubuntu 24.04 system and accesses ROCm devices from inside a Docker container, assuming a GPU-enabled server with an AMD ROCm-capable GPU already set up. By the end, you'll have Docker installed and a temporary container running with verified access to the host's ROCm GPU devices.


Install Docker

1. Add Docker's official GPG key to the system:

$ sudo apt-get update
$ sudo apt-get install ca-certificates curl
$ sudo install -m 0755 -d /etc/apt/keyrings
$ sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
$ sudo chmod a+r /etc/apt/keyrings/docker.asc

These commands ensure that packages downloaded from Docker's repository are authentic and secure, which is needed before adding Docker's repository and installing the Docker engine.

2. Add Docker's official repository to the system's APT sources list:

$ echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
    $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
    sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
$ sudo apt-get update

3. Install Docker and its components:

$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

This installs Docker Engine, the Docker CLI, Containerd, the Buildx plugin, and the Docker Compose plugin.

Understand the ROCm Devices Exposed to Containers

Two host devices need to be exposed to Docker containers for GPU-accelerated workloads:

  • /dev/kfd (Kernel Fusion Driver): Manages communication between user applications and AMD GPUs for compute tasks. It also handles GPU memory, scheduling, and execution of computational tasks like deep learning or scientific computing.
  • /dev/dri (Direct Rendering Infrastructure): Provides access to the GPU for graphics rendering, and is also used for 2D/3D rendering and video processing tasks.

Both devices are required for exposing GPU capabilities to Docker containers for GPU-accelerated tasks such as machine learning and rendering. Learn more.

Access ROCm Devices from a Container

1. Pull a lightweight ROCm terminal container image:

$ docker pull rocm/rocm-terminal:latest

2. Run a temporary container with access to the GPU devices:

$ docker run --rm -it --device=/dev/kfd --device=/dev/dri --security-opt seccomp=unconfined rocm/rocm-terminal 

This command runs a temporary container with access to the necessary GPU devices (/dev/kfd and /dev/dri) on the host system.

3. Verify GPU availability from inside the container:

$ rocm-smi

The output should display all the detected GPU devices along with their specifications.

4. Exit and destroy the container:

$ exit

Next Steps

  • Install a machine learning framework such as PyTorch or TensorFlow with ROCm acceleration inside a container.
  • Build a custom Dockerfile that layers your application on top of a ROCm base image.
  • Orchestrate multiple ROCm-enabled containers with a container orchestrator such as Kubernetes.
  • Monitor GPU utilization with rocm-smi while running production workloads.

For the full guide with additional tips, visit the original article on Vultr Docs.

來源:DEV Community · dev.to