GPU Passthrough in OpenStack
My experience of deploying a virtual machine in OpenStack with GPU attached.
Kubeflow is an extraordinary framework essentially allowing the emergence of MLOps or ML as a Service (MLaaS) modalities. It is readily integrated into the overall concept, context and operations of Kubernetes, rendering a perfect match for ML engineers that need to have their ML pipelines scaled at cloud level. But, what happens in the context of hybrid clouds, when a graphics card is attached to a server not directly participating in a Kubernetes deployment?
In this series of blogs, I am going to describe my experience of having a GPU indirectly attached to Kubernetes, using an OpenStack VM as a carrier.
Deep Learning models can be trained faster by simply running all operations at the same time instead of one after the other. GPUs are optimized for training artificial intelligence and deep learning models as they can process multiple computations simultaneously.
Synelixis’s mini-cloud infrastructure consists of an on premises bare-metal Kubernetes cluster comprising multiple nodes accompanied by a disjoint OpenStack installation hosted on a single server (yes, VMs are really needed even nowadays 🙂). In the context of the IoT-NGIN project, we faced the need to introduce a new Kubernetes node with specialized hardware allowing Data Scientists and ML Engineers run workflows upon (effectively implementing MLaaS). Reading the documentation of Kubeflow & Kubernetes, everything seemed to be well thought of and straightforward, except for one thing; the GPU would need to be attached to a server-part of the Kubernetes cluster. In our case, however, this was not the case; the GPU was attached to the OpenStack server and could not be relocated. Consequently, we had to create a VM inside the OpenStack environment, with the GPU attached, then donate this VM to our hungry Kubernetes installation.
Our OpenStack hardware consisted of the following:
- 1 x Dell PowerEdge T630 Tower Server with 12 CPU cores, 192GB RAM and 4 TB HDD,
- 1 x Nvidia GeForce GTX TITAN X
Preparation
To pass a GPU through to virtual machines, you will want to enable VT-d extensions in the BIOS.
Next, update the grub configuration at /etc/default/grub to ensure IOMMU support is enabled.
$ sudo nano /etc/default/grub
...
GRUB_CMDLINE_LINUX_DEFAULT="intel_iommu=on"
...Refresh the grub configuration and reboot the server.
$ sudo update-grub
$ rebootOnce the host has been rebooted, the next step in preparing the GPU for passthrough is to ensure the proper drivers are configured. Run lspci command to get PCI bus ID, vendor ID and product ID.
$ sudo lspci -nn | grep NVIDIA
04:00.0 VGA compatible controller [0300]: NVIDIA Corporation GM200 [GeForce GTX TITAN X] [10de:17c2] (rev a1)
04:00.1 Audio device [0403]: NVIDIA Corporation GM200 High Definition Audio [10de:0fb0] (rev a1)In this example, the PCI bus ID is 04:00.0, the vendor ID is 10de and the product ID is 17c2.
The card now has the default driver.
$ sudo lspci -s 04:00.0 -k
04:00.0 VGA compatible controller: NVIDIA Corporation GM200 [GeForce GTX TITAN X] (rev a1)
Subsystem: NVIDIA Corporation GM200 [GeForce GTX TITAN X]
Kernel driver in use: nouveau
Kernel modules: nvidiafb, nouveau$ sudo lspci -s 04:00.1 -k
04:00.1 Audio device: NVIDIA Corporation GM200 High Definition Audio (rev a1)
Subsystem: NVIDIA Corporation GM200 High Definition Audio
Kernel driver in use: snd_hda_intel
Kernel modules: snd_hda_intel
Blacklist
In order to ensure the graphics drivers are not loaded, we need to blacklist them. Create and edit a dedicated blacklist file at /etc/modprobe.d/blacklist-nvidia.conf:
sudo nano /etc/modprobe.d/blacklist-nvidia.confand add the following contents:
blacklist nouveau
blacklist nvidiafbWhitelist
Next, we need to ensure that the vfio-pci driver gets loaded and binds the GPU.
sudo nano /etc/modprobe.d/vfio.confoptions vfio-pci ids=10de:17c2,10de:0fb0
Then, add the vfio-pci driver to the /etc/modules-load.d/modules.conf file to ensure it’s loaded:
...
vfio-pciNow, edit once again the grub config file.
$ sudo nano /etc/default/grub
...
GRUB_CMDLINE_LINUX_DEFAULT="intel_iommu=on vfio-pci.ids=10de:17c2,10de:0fb0 vfio_iommu_type1.allow_unsafe_interrupts=1 modprobe.blacklist=nvidiafb,nouveau"
...Refresh the grub configuration and reboot the server.
$ sudo update-grub
$ sudo rebootOnce the server has returned, you can verify the proper driver has been bound using the following lspci command:
$ sudo lspci -s 04:00.0 -nnk
04:00.0 VGA compatible controller: NVIDIA Corporation GM200 [GeForce GTX TITAN X] (rev a1)
Subsystem: NVIDIA Corporation GM200 [GeForce GTX TITAN X]
Kernel driver in use: vfio-pci
Kernel modules: nvidiafb, nouveau$ sudo lspci -s 04:00.1 -nnk
04:00.1 Audio device: NVIDIA Corporation GM200 High Definition Audio (rev a1)
Subsystem: NVIDIA Corporation GM200 High Definition Audio
Kernel driver in use: vfio-pci
Kernel modules: snd_hda_intel
Nova changes
This guild refers to openstack kolla installation.
Get Thomas Saltos’s stories in your inbox
Join Medium for free to get updates from this writer.
First, configure PCI passthrough whitelist on the compute node.
sudo nano /etc/kolla/nova-compute/nova.confThe configuration should be like the following:
[pci]
passthrough_whitelist: { "vendor_id": "10de", "product_id": "17c2" }Restart the nova compute service:
$ sudo docker restart nova-computeNext, configure nova.conf on the node API service.
sudo nano /etc/kolla/nova-api/nova.confThe configuration should be like the following:
[pci]
alias: { "vendor_id":"10de", "product_id":"17c2", "device_type":"type-PCI", "name":"geforce-gtx" }[filter_scheduler]
enabled_filters = PciPassthroughFilter
available_filters = nova.scheduler.filters.all_filters
Restart the nova API service:
$ sudo docker restart nova-apiLastly, ensure that the Nova scheduler has been configured with a PCI Passthrough filter.
sudo nano /etc/kolla/nova-scheduler/nova.confThe configuration should be like the following:
[filter_scheduler]
enabled_filters = PciPassthroughFilter
available_filters = nova.scheduler.filters.all_filtersRestart the nova scheduler service:
$ sudo docker restart nova-schedulerCreate a flavor
Create a flavor with the following command:
openstack flavor create \
--vcpus 8 \
--ram 16384 \
--disk 100 \
--property "pci_passthrough:alias"="geforce-gtx:1" \
8_16384_100_gpuThe pci_passthrough:alias property referencing the geforce-gtx alias we configured earlier. The number 1 instructs nova that a single GPU should be assigned.
Configure image
The image that will be used, should have hidden the hypervisor id, since NVIDIA drivers do not work in instances with KVM hypervisor signatures.
$ openstack image list$ openstack image set debdbe79-2191-46aa-bc19-fb2b2c09f1a0 --property img_hide_hypervisor_id=trueCreate an instance
openstack server create \
--flavor 8_16384_100_gpu \
--image Ubuntu 20.04 \
--network LAN \
--key-name key \
test-instanceLogin to the instance and verify the GPU is recognized:
ubuntu@test-instance:~$ lspci | grep NVIDIA
00:05.0 VGA compatible controller: NVIDIA Corporation GM200 [GeForce GTX TITAN X] (rev a1)Check the hypervisor id signature
ubuntu@test-instance:~$ sudo apt update
ubuntu@test-instance:~$ sudo apt install cpuid
ubuntu@test-instance:~$ cpuid|grep hypervisor_id
hypervisor_id = " "
hypervisor_id = " "
hypervisor_id = " "
hypervisor_id = " "
hypervisor_id = " "
hypervisor_id = " "
hypervisor_id = " "
hypervisor_id = " "Now install nvidia drivers
ubuntu@test-instance:~$ sudo apt install ubuntu-drivers-commonubuntu@test-instance:~$ ubuntu-drivers devices
WARNING:root:_pkg_get_support nvidia-driver-390: package has invalid Support Legacyheader, cannot determine support level
== /sys/devices/pci0000:00/0000:00:05.0 ==
modalias : pci:v000010DEd000017C2sv000010DEsd00001132bc03sc00i00
vendor : NVIDIA Corporation
model : GM200 [GeForce GTX TITAN X]
driver : nvidia-driver-455 - third-party non-free
driver : nvidia-driver-470 - third-party non-free recommended
driver : nvidia-driver-418-server - distro non-free
driver : nvidia-driver-450 - third-party non-free
driver : nvidia-driver-460 - third-party non-free
driver : nvidia-driver-465 - third-party non-free
driver : nvidia-driver-450-server - distro non-free
driver : nvidia-driver-460-server - distro non-free
driver : nvidia-driver-390 - distro non-free
driver : xserver-xorg-video-nouveau - distro free builtinubuntu@test-instance:~$ sudo apt install nvidia-driver-470
When the installation finishes reboot the instance:
ubuntu@test-instance:~$ sudo rebootAfter rebooting the instance, verify the new drivers have been installed and work correctly by typing nvidia-smi:
The driver works and we are ready to access the GPU.
I hope you have enjoyed this article, and any feedback will be very well received. In the next story, I will describe the Kubeflow installation. Many thanks! 😄








