Enabing GPU passthrough on Proxmox for GPU enabled containers

I just purchased two GPUs for my Proxmox host and want to play with GPU enabled containers. I found that it can be a challenge to setup but I ultimately succeeded after a few tries. This is what I did:

Note: Before you get started with the Proxmox configuration, make sure your GPUs are in the right 16x PCI bus and that the primary GPU for your host video is assigned in the Bios. The Dell 5820 uses Slot 2 and Slot 4.

Proxmox Configuration

To set up dual GPU passthrough in Proxmox with one GPU for the host, you need to enable IOMMU in BIOS, configure GRUB to isolate the passthrough GPU (Nvidia card), blacklist Nvidia drivers, bind the target GPU to VFIO, update initramfs, and then add the isolated Nvidia card as a PCI device to your VM in Proxmox, checking options like Primary GPU and PCI Express for direct access. Remember to connect your VM’s console (like via SPICE/VNC initially) before passing the GPU, as the virtual console stops working after passthrough. 

Pre-requisites: Hardware & BIOS

  1. Check PCIe Lanes: Ensure your motherboard supports bifurcating PCIe lanes if needed, or has enough lanes for two GPUs, ideally running at x8/x8 or better, not just x1/x2, for performance.
  2. Enable IOMMU: In your motherboard’s BIOS/UEFI settings, enable:
  3. Intel VT-d or AMD-Vi (IOMMU)
  4. Intel VT-x or AMD-V (Virtualization)
  5. SR-IOV (if available). 

Host Configuration (Proxmox Shell)

  1. Identify GPUs: Run lspci -nn to find the PCI IDs (e.g., 10de:1b80) of the Nvidia GPU you want to pass through and its associated audio device.
  2. Edit GRUB:
  3. Edit /etc/default/grub and add intel_iommu=on (Intel) or amd_iommu=on (AMD) and iommu=pt to GRUB_CMDLINE_LINUX_DEFAULT.
  4. For Nvidia cards, you often need to hide them from the host: add pci=assign-bdf or specific vfio-pci.ids=… to the GRUB line to bind them to VFIO early.
  1. Load VFIO Modules: Create /etc/modules and add: vfio, vfio_iommu_type1, vfio_pci, vfio_virqfd.
  2. Blacklist Drivers: Create /etc/modprobe.d/blacklist-nvidia.conf with:
  3. blacklist nouveau
  4. blacklist nvidia
  5. blacklist nvidia_long
  6. blacklist nvidia_modeset

Also, create /etc/modprobe.d/vfio.conf to bind your GPU IDs to VFIO:

options vfio-pci ids=YOUR_GPU_ID,YOUR_AUDIO_ID disable_vga=1

  1. Update & Reboot: Run update-initramfs -u and then reboot.
  2. Verify Binding: After reboot, run lspci -k. Your GPU should show Kernel driver in use: vfio-pci. 

VM Configuration (Proxmox Web UI)

  1. Stop VM: Ensure the target VM is off.
  2. Add PCI Device: Go to VM -> Hardware -> Add -> PCI Device.
  3. Select GPU: Choose your Nvidia GPU from the dropdown.
  4. Check Options: Enable “Primary GPU”, “All Functions”, “ROM-Bar”, and “PCI Express”.
  5. Add Audio: Also add the GPU’s audio device (e.g., HDA controller) as another PCI device.
  6. Start VM: Boot the VM and install Nvidia drivers inside. 

Now your VM has direct control over the Nvidia GPU, while Proxmox uses the other for its display.

For AI/Deep Learning

Docker: Use nvidia-container-toolkit within Docker containers for GPU access.  

Guest OS: Use a Linux VM (Ubuntu/Debian) for better CUDA/TensorFlow/PyTorch support.

Install CUDA Toolkit: Install the appropriate CUDA toolkit in the guest for GPU acceleration.