Skip to content
Français
Conteneurs & Orchestration medium

GPU in Incus: passing an NVIDIA card to a container or a VM

10 min de lecture

Read this page in French

incus logo

Running inference or GPU compute inside an Incus instance, without dedicating a whole machine, is exactly what the gpu device allows. For a container, Incus shares the host GPU and injects the NVIDIA userspace by itself (nothing to install inside); for a virtual machine, it is an exclusive PCI passthrough. This guide covers both, including the driver version trap. Tested with an NVIDIA H100 on Incus 7.0.

What you will learn

  • The difference between a container (sharing) and a VM (exclusive passthrough).
  • Attach an NVIDIA GPU to a container with nvidia.runtime.
  • Filter the right GPU on a multi-card machine.
  • The driver version traps.

Prerequisites

  • A host with an NVIDIA GPU and its kernel driver installed (nvidia-smi works on the host).
  • Incus installed: see installing Incus.
  • For automatic injection into containers: nvidia-container-toolkit (the libnvidia-container package) on the host.

Container or VM: two different mechanisms

This is the point to grasp first. The gpu device does not do the same thing depending on the instance type.

TypeMechanismSharingDriver inside the instance
ContainerShares the host /dev/nvidia* devicesYes, across instancesInjected by nvidia.runtime
Virtual machinePCI passthrough (VFIO)No, exclusive to the VMInstalled inside the VM

For inference shared across several environments, the container is the more flexible route. For strong isolation or a different guest operating system, the virtual machine takes the GPU exclusively.

Passing a GPU to a container

The elegant part of Incus: with nvidia.runtime=true, it mounts the host NVIDIA userspace (libraries and nvidia-smi) into the container. No CUDA package to install inside.

  1. Launch a container with the NVIDIA runtime enabled:

    Fenêtre de terminal
    incus launch images:debian/13 gpu-lab -c nvidia.runtime=true
  2. Attach the GPU with a gpu device:

    Fenêtre de terminal
    incus config device add gpu-lab gpu0 gpu
    # Device gpu0 added to gpu-lab
  3. Check inside the container, with nothing installed in it:

    Fenêtre de terminal
    incus exec gpu-lab -- nvidia-smi -L
    GPU 0: NVIDIA H100 PCIe (UUID: GPU-ada5ffa8-3c66-...)

The host GPU is seen as it is inside the container, with the /dev/nvidia0 and /dev/nvidiactl nodes exposed. Since this is sharing, several containers can receive the same GPU.

Targeting the right GPU

On a machine with several cards, the gpu device without a filter exposes all of them. You restrict it with filtering properties.

Fenêtre de terminal
# by card identifier
incus config device add gpu-lab gpu0 gpu id=0
# by PCI address
incus config device add gpu-lab gpu0 gpu pci=0000:81:00.0

You can also filter by vendorid and productid. This is essential to dedicate one card to an instance and leave others free for the host or for other instances.

GPU in a virtual machine

For a virtual machine, the gpu device triggers a PCI passthrough: the card is detached from the host and attached to the VM, exclusively. The host can no longer use it while the VM runs.

Fenêtre de terminal
incus launch images:debian/13 gpu-vm --vm
incus config device add gpu-vm gpu0 gpu

The driver version trap

The most frequent problem in containers is a version mismatch between the host kernel driver and the injected userspace. Since nvidia.runtime mounts the host userspace, the two are aligned by construction here. If, however, you install NVIDIA packages by hand inside the container, they can conflict with the host kernel driver (Failed to initialize NVML: Driver/library version mismatch). The rule: in a container, let nvidia.runtime manage the userspace and install no driver inside.

Key points

  • The gpu device means sharing in a container and an exclusive PCI passthrough in a virtual machine.
  • In a container, nvidia.runtime=true injects the NVIDIA userspace: nothing to install inside.
  • Injection requires libnvidia-container (nvidia-container-toolkit) on the host.
  • Target a specific card with id=, pci= or vendorid and productid.
  • In a virtual machine: the driver goes in the guest, and IOMMU is required on the host.

FAQ: common questions about GPU in Incus

Next steps

Is this site useful to you?

Fewer than 1% of readers support this site.

I maintain more than 700 free guides, with no ads and no tracking. Any support, even a symbolic one, helps cover hosting and keeps these resources free. Thank you for the help.

The form does not show? Open Ko-fi in a new tab.

Subscribe and follow my DevSecOps work on LinkedIn