Physical GPU Passthrough Environment Preparation
Physical GPU passthrough in virtual machines refers to the process of directly allocating the actual Graphics Processing Unit (GPU) to a virtual machine within a virtualization environment. This allows the virtual machine to access and utilize the physical GPU directly, achieving graphics performance equivalent to that of running directly on a physical machine. It avoids performance bottlenecks caused by virtual graphics adapters, thus enhancing overall performance.
TOC
Constraints and Limitations
The physical GPU passthrough functionality requires the use of the kubevirt-gpu-device-plugin; however, there is currently no ARM64 image available for the kubevirt-gpu-device-plugin, which means this functionality cannot be used in an operating system with an ARM64 CPU architecture.
Prerequisites
Chart and Image Preparation
Obtain the following Chart and images and upload them to an image repository. This document uses build-harbor.example.cn as an example repository address. For the specific method of obtaining the Chart and images, please contact the relevant personnel.
Chart
- build-harbor.example.cn/example/chart-gpu-operator:v23 .9.1
Images
- build-harbor.example.cn/3rdparty/nvidia/gpu-operator:v23 .9.0
- build-harbor.example.cn/3rdparty/nvidia/cloud-native/gpu-operator-validator:v23 .9.0
- build-harbor.example.cn/3rdparty/nvidia/cuda:12 .3.1-base-ubi8
- build-harbor.example.cn/3rdparty/nvidia/kubevirt-gpu-device-plugin:v1 .2.4
- build-harbor.example.cn/3rdparty/nvidia/nfd/node-feature-discovery:v0 .14.2
Enabling IOMMU
The procedure for enabling IOMMU varies across different operating systems. Please refer to the documentation of the corresponding operating system. This document uses CentOS as an example, and all commands should be executed in the terminal.
-
Edit the
/etc/default/grubfile and addintel_iommu=on iommu=ptto theGRUB_CMDLINE_LINUXconfiguration option. -
Execute the following command to generate the
grub.cfgfile. -
Restart the server.
-
Run the following command to confirm if IOMMU has been successfully enabled. If the output contains
IOMMU enabled, then it indicates that it has been successfully enabled.
Operating Steps
Note: All commands below should be executed in the CLI tool on the corresponding cluster Master node unless otherwise specified.
Create Namespace
Execute the following command to create a namespace named gpu-system. If the output displays namespace/gpu-system created, it indicates that the creation was successful.
Deploy gpu-operator
-
Execute the following command to deploy the gpu-operator.
-
Execute the following command to check if the gpu-operator has synchronized. If
SYNCshows asSynced, it indicates that it has synchronized successfully.Output information:
-
Execute the following command to retrieve the names of all nodes and find the GPU node name.
-
Execute the following command to check if the GPU node has any pass-through capable GPU. If the output contains GPU information similar to
nvidia.com/GK210GL_TESLA_K80, it indicates that there are pass-through capable GPUs.Output information:
-
At this point, the gpu-operator has been successfully deployed.
Configure Kubevirt
-
Execute the following command to enable the DisableMDEVConfiguration feature. If a message similar to
hyperconverged.hco.kubevirt.io/kubevirt-hyperconverged patchedis returned, it indicates successful enabling. -
In the terminal of the GPU node, execute the following command to obtain the pciDeviceSelector. The
10de:102dpart in the output is the value of pciDeviceSelector. {#pciDeviceSelector}Output information:
-
Execute the following command to retrieve the names of all nodes and find the GPU node name.
-
Execute the following command to obtain the resourceName. The
nvidia.com/GK210GL_TESLA_K80part in the output is the value of resourceName.Output information:
-
Execute the following command to add the passthrough GPU.
Note: When replacing the <pci-devices-id> part in the command below with the pciDeviceSelector value obtained in Step 2, all letters in the pciDeviceSelector must be converted to uppercase. For example, if the pciDeviceSelector value obtained is
10de:102d, it should be replaced withexport DEVICE=10DE:102D.-
Adding a single GPU card
-
Adding multiple GPU cards
Note: When adding multiple GPU cards, each pciDeviceSelector value used to replace <pci-devices-id> must be unique.
-
Adding new GPU cards after already adding GPU cards
-
Result Verification
After completing the above configuration steps, if the corresponding physical GPU can be selected when creating the virtual machine, it indicates that the physical GPU passthrough environment has been successfully prepared.
Note: If physical GPU passthrough needs to be configured, please enable the relevant features in advance.
-
Go to Container Platform.
-
In the left navigation bar, click Virtualization > Virtual Machines.
-
Click Create Virtual Machine.
-
Configure the Physical GPU (Alpha) parameter for the virtual machine.
-
At this point, the physical GPU passthrough environment has been successfully prepared.
Related Operations
Delete the Virtual Machine with Passthrough GPU
-
Go to Container Platform.
-
In the left navigation bar, click Virtualization > Virtual Machines.
-
In the list page, click the ⋮ on the right side of the virtual machine to be deleted > Delete, or click the name of the virtual machine to be deleted to enter its detail information page, and click Actions > Delete.
-
Input the confirmation information to delete the virtual machine with passthrough GPU.
Remove GPU-related Configuration from KubeVirt
-
On the corresponding cluster Master node for the GPU, use the CLI tool to execute the following command to remove the GPU-related configuration from KubeVirt.
-
After deletion, if it is not possible to choose the corresponding physical GPU model when creating a virtual machine through Container Platform, it indicates that the deletion was successful. Please refer to Select Physical GPU Model for the specific steps to create a virtual machine.
Uninstall gpu-operator
-
Use the CLI tool on the corresponding cluster Master node for the GPU to execute the following command to uninstall the gpu-operator.
Output information:
-
Execute the command, and if you receive a response similar to the one below, it indicates that the gpu-operator has been successfully uninstalled.
Output information: