<a id="devices-gpu"></a>

# Type: `gpu`


            <p class="youtube_link">
              <a href="https://www.youtube.com/watch?v=T0aV2LsMpoA" target="_blank">
                <span title="LXD and the NVIDIA A100" class="play_icon">▶</span>
                <span title="LXD and the NVIDIA A100">Watch on YouTube</span>
              </a>
            </p>
        
GPU devices make the specified GPU device or devices appear in the instance.

#### NOTE
For containers, a `gpu` device may match multiple GPUs at once.
For VMs, each device can match only a single GPU.

The following types of GPUs can be added using the `gputype` device option:

- [`physical`](#gpu-physical) (container and VM): Passes an entire GPU through into the instance.
  This value is the default if `gputype` is unspecified.
- [`mdev`](#gpu-mdev) (VM only): Creates and passes a virtual GPU (vGPU) through into the instance.
- [`mig`](#gpu-mig) (container only): Creates and passes a MIG (Multi-Instance GPU) through into the instance.
- [`sriov`](#gpu-sriov) (VM only): Passes a virtual function of an SR-IOV-enabled GPU into the instance.

The available device options depend on the GPU type and are listed in the tables in the following sections.

<a id="gpu-physical"></a>

## `gputype`: `physical`

#### NOTE
The `physical` GPU type is supported for both containers and VMs.
It supports hotplugging only for containers, not for VMs.

A `physical` GPU device passes an entire GPU through into the instance.

### Device options

GPU devices of type `physical` have the following device options:

<!-- Include content from [../metadata.txt](../metadata.txt) -->

<a id="device-gpu-physical-device-conf:gid"></a>
`gid`

GID of the device owner in the container

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#device-gpu-physical-device-conf:gid)

| **Key:**       | `gid`     |
|----------------|-----------|
| **Type:**      | integer   |
| **Default:**   | `0`       |
| **Condition:** | container |

<a id="device-gpu-physical-device-conf:id"></a>
`id`

ID of the GPU device

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#device-gpu-physical-device-conf:id)

| **Key:**    | `id`   |
|-------------|--------|
| **Type:**   | string |

The ID can either be the DRM card ID of the GPU device (container or VM) or a fully-qualified Container Device Interface (CDI) name (container only).
Here are some examples of fully-qualified CDI names:

- `nvidia.com/gpu=0`: Instructs LXD to operate a discrete GPU (dGPU) pass-through of brand NVIDIA with the first discovered GPU on your system. You can use the `nvidia-smi` tool on your host to find out which identifier to use.
- `nvidia.com/gpu=1833c8b5-9aa0-5382-b784-68b7e77eb185`: Instructs LXD to operate a discrete GPU (dGPU) pass-through of brand NVIDIA with a given GPU unique identifier. This identifier should also appear with `nvidia-smi -L`.
- `nvidia.com/igpu=all`: Instructs LXD to pass all the host integrated GPUs (iGPU) of brand NVIDIA. The concept of an index does not currently map to iGPUs. It is possible to list them with the `nvidia-smi -L` command. A special `nvgpu` mention should appear in the generated list to indicate a device to be an iGPU.
- `nvidia.com/gpu=all`: Instructs LXD to pass all the host GPUs of brand NVIDIA through to the container.

<a id="device-gpu-physical-device-conf:mode"></a>
`mode`

Mode of the device in the container

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#device-gpu-physical-device-conf:mode)

| **Key:**       | `mode`    |
|----------------|-----------|
| **Type:**      | integer   |
| **Default:**   | `0660`    |
| **Condition:** | container |

<a id="device-gpu-physical-device-conf:pci"></a>
`pci`

PCI address of the GPU device

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#device-gpu-physical-device-conf:pci)

| **Key:**    | `pci`   |
|-------------|---------|
| **Type:**   | string  |

<a id="device-gpu-physical-device-conf:productid"></a>
`productid`

Product ID of the GPU device

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#device-gpu-physical-device-conf:productid)

| **Key:**    | `productid`   |
|-------------|---------------|
| **Type:**   | string        |

<a id="device-gpu-physical-device-conf:uid"></a>
`uid`

UID of the device owner in the container

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#device-gpu-physical-device-conf:uid)

| **Key:**       | `uid`     |
|----------------|-----------|
| **Type:**      | integer   |
| **Default:**   | `0`       |
| **Condition:** | container |

<a id="device-gpu-physical-device-conf:vendorid"></a>
`vendorid`

Vendor ID of the GPU device

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#device-gpu-physical-device-conf:vendorid)

| **Key:**    | `vendorid`   |
|-------------|--------------|
| **Type:**   | string       |

### Configuration examples

Add all GPUs from the host system as a `physical` GPU device to an instance:

```none
lxc config device add <instance_name> <device_name> gpu gputype=physical
```

Add a specific GPU from the host system as a `physical` GPU device to an instance by specifying its PCI address:

```none
lxc config device add <instance_name> <device_name> gpu gputype=physical pci=<pci_address>
```

See [Configure devices](https://canonical.com/lxd/docs/default/howto/instances_configure/index.html.md#instances-configure-devices) for more information.

#### CDI mode

#### NOTE
The CDI mode is currently not supported on `armhf` architectures.

Add a specific GPU from the host system as a `physical` GPU device to an instance using the [Container Device Interface](https://github.com/cncf-tags/container-device-interface) (CDI) notation through a fully-qualified CDI name:

```none
lxc config device add <instance_name> <device_name> gpu gputype=physical id=<fully_qualified_CDI_name>
```

For example, add the first available NVIDIA discrete GPU on your system:

```none
lxc config device add <instance_name> <device_name> gpu gputype=physical id=nvidia.com/gpu=0
```

If your machine has an NVIDIA iGPU (integrated GPU) located at index 0, you can add it like this:

```none
lxc config device add <instance_name> <device_name> gpu gputype=physical id=nvidia.com/igpu=0
```

For a complete example on how to use a GPU CDI pass-through, see [How to pass an NVIDIA GPU to a container](https://canonical.com/lxd/docs/default/howto/container_gpu_passthrough_with_docker/index.html.md#container-gpu-passthrough-with-docker).

<a id="gpu-mdev"></a>

## `gputype`: `mdev`

#### NOTE
The `mdev` GPU type is supported only for VMs.
It does not support hotplugging.

An `mdev` GPU device creates and passes a virtual GPU (vGPU) through into the instance.
You can check the list of available `mdev` profiles by running [`lxc info --resources`](https://canonical.com/lxd/docs/default/reference/manpages/lxc/info/index.html.md#lxc-info-md).

### Device options

GPU devices of type `mdev` have the following device options:

<!-- Include content from [../metadata.txt](../metadata.txt) -->

<a id="device-gpu-mdev-device-conf:id"></a>
`id`

DRM card ID of the GPU device

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#device-gpu-mdev-device-conf:id)

| **Key:**    | `id`   |
|-------------|--------|
| **Type:**   | string |

<a id="device-gpu-mdev-device-conf:mdev"></a>
`mdev`

The `mdev` profile to use

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#device-gpu-mdev-device-conf:mdev)

| **Key:**      | `mdev`   |
|---------------|----------|
| **Type:**     | string   |
| **Default:**  | `0`      |
| **Required:** | yes      |

For example: `i915-GVTg_V5_4`

<a id="device-gpu-mdev-device-conf:pci"></a>
`pci`

PCI address of the GPU device

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#device-gpu-mdev-device-conf:pci)

| **Key:**    | `pci`   |
|-------------|---------|
| **Type:**   | string  |

<a id="device-gpu-mdev-device-conf:productid"></a>
`productid`

Product ID of the GPU device

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#device-gpu-mdev-device-conf:productid)

| **Key:**    | `productid`   |
|-------------|---------------|
| **Type:**   | string        |

<a id="device-gpu-mdev-device-conf:vendorid"></a>
`vendorid`

Vendor ID of the GPU device

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#device-gpu-mdev-device-conf:vendorid)

| **Key:**    | `vendorid`   |
|-------------|--------------|
| **Type:**   | string       |

### Configuration examples

Add an `mdev` GPU device to an instance by specifying its `mdev` profile and the PCI address of the GPU:

```none
lxc config device add <instance_name> <device_name> gpu gputype=mdev mdev=<mdev_profile> pci=<pci_address>
```

See [Configure devices](https://canonical.com/lxd/docs/default/howto/instances_configure/index.html.md#instances-configure-devices) for more information.

<a id="gpu-mig"></a>

## `gputype`: `mig`

#### NOTE
The `mig` GPU type is supported only for containers.
It does not support hotplugging.

A `mig` GPU device creates and passes a MIG compute instance through into the instance.
Currently, this requires NVIDIA MIG instances to be pre-created.

### Device options

GPU devices of type `mig` have the following device options:

<!-- Include content from [../metadata.txt](../metadata.txt) -->

<a id="device-gpu-mig-device-conf:id"></a>
`id`

DRM card ID of the GPU device

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#device-gpu-mig-device-conf:id)

| **Key:**    | `id`   |
|-------------|--------|
| **Type:**   | string |

<a id="device-gpu-mig-device-conf:mig.ci"></a>
`mig.ci`

Existing MIG compute instance ID

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#device-gpu-mig-device-conf:mig.ci)

| **Key:**    | `mig.ci`   |
|-------------|------------|
| **Type:**   | integer    |

<a id="device-gpu-mig-device-conf:mig.gi"></a>
`mig.gi`

Existing MIG GPU instance ID

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#device-gpu-mig-device-conf:mig.gi)

| **Key:**    | `mig.gi`   |
|-------------|------------|
| **Type:**   | integer    |

<a id="device-gpu-mig-device-conf:mig.uuid"></a>
`mig.uuid`

Existing MIG device UUID

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#device-gpu-mig-device-conf:mig.uuid)

| **Key:**    | `mig.uuid`   |
|-------------|--------------|
| **Type:**   | string       |

You can omit the `MIG-` prefix when specifying this option.

<a id="device-gpu-mig-device-conf:pci"></a>
`pci`

PCI address of the GPU device

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#device-gpu-mig-device-conf:pci)

| **Key:**    | `pci`   |
|-------------|---------|
| **Type:**   | string  |

<a id="device-gpu-mig-device-conf:productid"></a>
`productid`

Product ID of the GPU device

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#device-gpu-mig-device-conf:productid)

| **Key:**    | `productid`   |
|-------------|---------------|
| **Type:**   | string        |

<a id="device-gpu-mig-device-conf:vendorid"></a>
`vendorid`

Vendor ID of the GPU device

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#device-gpu-mig-device-conf:vendorid)

| **Key:**    | `vendorid`   |
|-------------|--------------|
| **Type:**   | string       |

You must set either [`mig.uuid`](#device-gpu-mig-device-conf:mig.uuid) (NVIDIA drivers 470+) or both [`mig.ci`](#device-gpu-mig-device-conf:mig.ci) and [`mig.gi`](#device-gpu-mig-device-conf:mig.gi) (old NVIDIA drivers).

### Configuration examples

Add a `mig` GPU device to an instance by specifying its UUID and the PCI address of the GPU:

```none
lxc config device add <instance_name> <device_name> gpu gputype=mig mig.uuid=<mig_uuid> pci=<pci_address>
```

See [Configure devices](https://canonical.com/lxd/docs/default/howto/instances_configure/index.html.md#instances-configure-devices) for more information.

<a id="gpu-sriov"></a>

## `gputype`: `sriov`

#### NOTE
The `sriov` GPU type is supported only for VMs.
It does not support hotplugging.

An `sriov` GPU device passes a virtual function of an SR-IOV-enabled GPU into the instance.

### Device options

GPU devices of type `sriov` have the following device options:

<!-- Include content from [../metadata.txt](../metadata.txt) -->

<a id="device-gpu-sriov-device-conf:id"></a>
`id`

DRM card ID of the parent GPU device

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#device-gpu-sriov-device-conf:id)

| **Key:**    | `id`   |
|-------------|--------|
| **Type:**   | string |

<a id="device-gpu-sriov-device-conf:pci"></a>
`pci`

PCI address of the parent GPU device

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#device-gpu-sriov-device-conf:pci)

| **Key:**    | `pci`   |
|-------------|---------|
| **Type:**   | string  |

<a id="device-gpu-sriov-device-conf:productid"></a>
`productid`

Product ID of the parent GPU device

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#device-gpu-sriov-device-conf:productid)

| **Key:**    | `productid`   |
|-------------|---------------|
| **Type:**   | string        |

<a id="device-gpu-sriov-device-conf:vendorid"></a>
`vendorid`

Vendor ID of the parent GPU device

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#device-gpu-sriov-device-conf:vendorid)

| **Key:**    | `vendorid`   |
|-------------|--------------|
| **Type:**   | string       |

### Configuration examples

Add a `sriov` GPU device to an instance by specifying the PCI address of the parent GPU:

```none
lxc config device add <instance_name> <device_name> gpu gputype=sriov pci=<pci_address>
```

See [Configure devices](https://canonical.com/lxd/docs/default/howto/instances_configure/index.html.md#instances-configure-devices) for more information.

## Related topics

- [How to pass an NVIDIA GPU to a container](https://canonical.com/lxd/docs/default/howto/container_gpu_passthrough_with_docker/index.html.md#container-gpu-passthrough-with-docker)
- [Why does my VM stop responding when I try to pass through a GPU?](https://canonical.com/lxd/docs/default/faq/index.html.md#faq-gpu-passthrough-stop)
