Virtual GPU (vGPU) with SR-IOV (VFIO)¶
Overview¶
Virtual GPU (vGPU) is a graphics virtualisation solution that gives virtual machines simultaneous access to physical GPUs hosted on hypervisors. The nova-compute-nvidia-vgpu charm exposes NVIDIA vGPUs to guests with the NVIDIA vendor-specific VFIO framework, which is used with NVIDIA vGPU software 17.x and newer on SR-IOV capable GPUs.
Note
This page explains vGPU with SR-IOV only. Users who want to use mdev (mediated devices) should read Virtual GPU (vGPU).
With the VFIO framework the physical GPU exposes its virtual functions (VFs).
Each VF is a vGPU and exposes an nvidia/ directory under
/sys/bus/pci/devices/<VF address>/. The SR-IOV mode is available on Ubuntu
24.04 LTS (Noble), and on Ubuntu 22.04 LTS (Jammy) with the Linux HWE kernel
6.8 or newer.
This page explains how to prepare a cloud for the VFIO mode and how the charm selects the mode.
Warning
The enablement of the vGPU feature will require a reboot of all affected compute nodes.
Pre-requisites¶
The vGPU mode that a compute node supports depends on the NVIDIA vGPU software version and the Ubuntu series:
NVIDIA vGPU software |
Driver branch |
vGPU mode |
Ubuntu series |
|---|---|---|---|
17.x and newer |
R550 and newer |
VFIO |
Noble, Jammy with kernel 6.8 or newer |
20.x |
R595 |
VFIO |
Noble |
The following requirements must be met in order to use the VFIO mode:
Ubuntu 24.04 LTS, or Ubuntu 22.04 LTS with a Linux kernel 6.8 or newer (HWE)
OpenStack 2024.1 (Caracal) or newer
a GPU that supports SR-IOV (Ampere or newer)
NVIDIA vGPU software 17.x (R550) or newer
The NVIDIA vGPU software is supplied to the nova-compute-nvidia-vgpu charm as a charm resource. Consult the NVIDIA vGPU Ubuntu support matrix for the supported driver and Ubuntu combinations, and the NVIDIA vGPU user guide for the details of the vGPU software. See the Virtual GPU (vGPU) page for the deployment steps and the attaching of the resource. For the available charm channels and tracks, see Charm delivery.
Important
Users who want vGPU with SR-IOV on jammy-caracal (Ubuntu 22.04 Jammy with
OpenStack 2024.1) must use a Linux kernel 6.8 or newer, that is, the Linux
HWE kernel (package linux-generic-hwe-22.04).
Important
Users of noble-caracal (OpenStack 2024.1 on Ubuntu 24.04) must install the
patched packages from the PPA, named
ppa:canonical-openstack/charmed-openstack-noble-caracal, before
enabling the VFIO mode. The PPA carries patched Nova and Placement packages
that the VFIO mode depends on.
The PPA must be installed on the nova-compute, nova-cloud-controller, and
placement units. The nova-common package must be at version
3:29.2.0-0ubuntu1.8+vgpu1 or later.
Add the PPA to all three applications:
juju exec -a nova-compute -a nova-cloud-controller -a placement -- \
sudo add-apt-repository -y \
ppa:canonical-openstack/charmed-openstack-noble-caracal
Then upgrade the nova and placement packages on those units:
juju exec -a nova-compute -a nova-cloud-controller -a placement -- \
sudo apt-get update
Install the newer versions of the nova and placement packages that are present on each unit (for example, sudo apt install --only-upgrade nova-common nova-compute).
The charm checks the nova-common version at runtime. On Caracal, when an
older nova-common is found, the charm only logs a warning and does not
block the unit. On releases earlier than Caracal the unit is blocked.
VFIO activation conditions¶
The charm does not check the Ubuntu series. It detects the mode from sysfs
(see Mode selection with vgpu-mode). The VFIO mode is detected when NVIDIA
vGPU software 17.x (R550) or newer is installed on a Noble or Jammy host and
the GPU
supports SR-IOV. On Jammy, the Linux HWE kernel 6.8 or newer is also needed.
The charm itself only checks the GPU and its VFs, and detects the VFIO mode
when the nvidia/ directory is present under
/sys/bus/pci/devices/<address>/ of the GPU or of any of its VFs.
In addition, in VFIO mode the unit stays blocked, with a status message,
until PCI-in-Placement reporting is enabled on the nova-compute application.
See the section titled PCI-in-Placement, further down this page.
Mode selection with vgpu-mode¶
The vgpu-mode option selects how the vGPUs are exposed. The values are:
autoThe charm detects the framework from sysfs. This is the default.
vfioForces the SR-IOV framework (NVIDIA vGPU software 17.x or newer, with SR-IOV capable GPUs).
On a host that uses VFIO, GPUs that do not support SR-IOV are not configured for vGPU.
For example, to force the VFIO mode:
juju config nova-compute-nvidia-vgpu vgpu-mode=vfio
Configuring vGPUs¶
Listing vGPU types¶
The list-vgpu-types action is aware of the mode in use. List the vGPU
types of a compute node by querying the corresponding
nova-compute-nvidia-vgpu unit:
juju run nova-compute-nvidia-vgpu/0 list-vgpu-types
In VFIO mode each output line has the form
<profile id>, <vf pci address>, <profile name>. A VF that already has a
profile is listed with that profile followed by the suffix (assigned):
<profile id>, <vf pci address>, <profile name> (assigned)
<profile id>, <vf pci address>, <profile name>
gpu-profiles (VFIO)¶
The gpu-profiles option applies to the VFIO mode only. It is a JSON or
YAML dictionary that maps the PCI address of each GPU to a list that holds
a single entry made of type, count, and an optional policy. For
example, to give each of two GPUs one profile:
juju config nova-compute-nvidia-vgpu gpu-profiles='{
"0000:41:00.0": [{"type": "A40-4Q", "count": 12}],
"0000:81:00.0": [{"type": "A40-2Q", "count": 4, "policy": "fail"}]}'
The entries are as follows:
type: a profile name as reported by thelist-vgpu-typesaction. The name is accepted with or without theNVIDIAprefix.count: the number of VFs that get the profile.policy:ignore(the default) creates as many vGPUs as possible and logs a warning when the request cannot be met;failblocks the unit until the request can be met or the policy is changed toignore.
A malformed value, or more than one profile for a GPU, blocks the unit.
Note
Each GPU takes a single profile. Nova reports all the VFs of a GPU as one
Placement resource provider with a single resource class, and a mix of
classes raises PlacementPciMixedResourceClassException. To offer
several vGPU types on one compute node, give each GPU a different profile.
Deterministic assignment and the state file¶
A VF keeps its profile for as long as that profile is still requested. The
remaining requested vGPUs are assigned to the remaining VFs in virtfn
order. The result is stored in /etc/nvidia-vgpu-state.yaml:
vfs:
- pf_pci_address: '0000:41:00.0'
index: 0
profile:
id: <profile id>
name: <profile name>
Profiles are applied at boot¶
The nvidia-vgpu-host-setup service applies the profiles. It runs before
nova-compute starts. The charm never changes the type of a VF at runtime, so a
change to gpu-profiles takes effect after a reboot of the compute node.
A new compute node needs two reboots. The first loads the driver and enables the VFs. The second applies the profiles.
The unit can report the following status messages:
N vGPU profile assignment(s) pending, manual reboot requiredVFIO host setup failed: <error> (see journalctl -u nvidia-vgpu-host-setup)gpu-profiles cannot be satisfied: <reason>vGPU heterogeneous mode enabled on <gpu>, manual reboot required to disable it
To troubleshoot, read the journal of the service:
juju exec --unit nova-compute-nvidia-vgpu/0 -- \
journalctl -u nvidia-vgpu-host-setup
PCI-in-Placement¶
The VFIO mode relies on Nova tracking PCI devices in Placement. Enable it in this order:
Enable the reporting on the compute nodes:
juju config nova-compute pci-report-in-placement=true
The option maps to
[pci]report_in_placementin nova.conf. Once it is enabled on a compute host, Nova does not support disabling it. Enable it on all relevant compute hosts and verify their PCI resource providers before the next step.Enable scheduling and claiming of PCI devices using Placement on the controllers, only after all relevant compute nodes report:
juju config nova-cloud-controller pci-in-placement=true
The option maps to
[filter_scheduler]pci_in_placementin nova.conf.
Until [pci]report_in_placement is true in nova.conf, the
nova-compute-nvidia-vgpu unit is blocked with a status message that begins
with VFIO mode requires PCI-in-Placement reporting.
Populating the Placement trees takes time. The scheduler does not consider a compute node ready for instances until all of its resources are populated. See the Nova documentation (Attaching physical PCI devices to guests) for upstream information.
Placement performance tuning¶
PCI devices create child resource providers under the compute node resource provider, which results in wide provider trees. Two upstream Placement options help with large trees:
[workarounds]optimize_for_wide_provider_trees[placement]allocation_candidates_generation_strategy: thebreadth-firstvalue is more efficient with many non-nested providers
Aliases on nova-cloud-controller¶
The charm generates one PCI alias for each profile in use, with these properties:
device_type:type-VFresource_class:CUSTOM_NVIDIA_<profile id>name: the profile name
Configure the aliases on nova-cloud-controller with the pci-alias option.
For example, for a profile with the illustrative id 560:
juju config nova-cloud-controller pci-alias='[{"device_type": "type-VF",
"resource_class": "CUSTOM_NVIDIA_560", "name": "A40-4Q"}]'
Note
The nova-cloud-controller application does not receive the aliases from the nova-compute-nvidia-vgpu charm. The operator must configure them.
Flavors¶
A VFIO vGPU is requested through a PCI alias. The alias name is the profile
name. For example, to have a flavor request one A40-4Q vGPU:
openstack flavor set <flavor-name> \
--property "pci_passthrough:alias"="A40-4Q:1"
To verify the result, list the resource providers with openstack
resource provider list. The compute node has child providers for its PCI
devices. The inventory of such a provider (openstack resource
provider inventory list <uuid>) shows the CUSTOM_NVIDIA_<profile id>
resource class, and its used value increases with each instance that
uses the flavor.
Scheduler coexistence¶
Compute nodes that use mediated devices (see the Virtual GPU (vGPU) page) advertise
the VGPU resource class, while compute nodes that use SR-IOV advertise
CUSTOM_NVIDIA_<profile id>. Placement keeps the two apart, so no scheduler
filter change is needed. Create separate flavors for each class of compute
node.
Limitations¶
Live migration of VFIO-backed instances is not supported on Caracal. Cold migration works. The charm sets
live_migration_permit_post_copytoFalse.Only one vGPU type is available per GPU.
All NVIDIA GPUs on a host use the same framework. GPUs without SR-IOV support are not configured for vGPU on a VFIO host.
The charm does not convert
resources:VGPU=1flavors topci_passthrough:aliasflavors, nor does it rebuild instances.NVIDIA MIG and NVLink are not supported.
Multiple vGPUs per VM are not supported.