Skip to main content

GPU Passthrough

HYPR supports GPU passthrough for running GPU-accelerated workloads in VMs.

Platform Support

Linux: VFIO Passthrough

On Linux, GPUs are passed through using VFIO (Virtual Function I/O), which provides direct hardware access to the VM.

Prerequisites

  1. IOMMU Enabled: Add to kernel command line:
    • Intel: intel_iommu=on
    • AMD: amd_iommu=on
  2. VFIO Modules: Ensure modules are loaded:

List Available GPUs

Output:
Status values:
  • available - GPU can be used for passthrough
  • vfio-ready - GPU is already bound to vfio-pci driver
  • boot-vga - GPU is the primary display (cannot unbind without —force)

Run with GPU

This:
  1. Validates the PCI address
  2. Checks IOMMU group isolation
  3. Binds the GPU to vfio-pci driver
  4. Passes the GPU to the VM
  5. Restores the original driver when VM stops

IOMMU Groups

All devices in an IOMMU group must be passed through together. HYPR validates this automatically. If validation fails:
Pass all devices in the group:

Boot VGA Protection

The boot VGA device (primary GPU driving the display) is protected by default. Unbinding it can hang the system. To override (use with caution):

NVIDIA-Specific Notes

Driver Installation in VM: The VM needs NVIDIA drivers. Use an image with drivers pre-installed:
SR-IOV (Virtual Functions): Some enterprise GPUs (A100, H100) support SR-IOV for sharing a GPU across multiple VMs. HYPR will detect and use virtual functions when available.

macOS: Metal GPU

On Apple Silicon Macs, HYPR uses Metal GPU virtualization via the Venus Vulkan driver.

How It Works

  1. libkrun creates a VM with virtio-gpu device
  2. Guest uses Venus driver (Vulkan over virtio-gpu)
  3. Host translates Vulkan to Metal
  4. GPU operations run on Apple GPU

Enable Metal GPU

No PCI address needed - the integrated GPU is used automatically.

List GPU

Output:

Performance

Metal passthrough achieves approximately 60-80% of native performance, depending on workload:
  • Compute (matrix ops): ~75-80%
  • Graphics rendering: ~60-70%
  • Memory bandwidth: ~70-75%

Supported Frameworks

Frameworks using Metal Compute or MPS work automatically:
  • TensorFlow with Metal plugin
  • PyTorch with MPS backend
  • MLX
  • Core ML

Troubleshooting

Linux: GPU Not Available

IOMMU not enabled:
Should show IOMMU initialization. If not, check kernel command line. VFIO module not loaded:
Load manually: sudo modprobe vfio-pci GPU in use by host: Stop display manager and unload GPU driver:

macOS: Metal Not Working

Check libkrun-efi version:
Requires libkrun-efi with Metal support. Verify macOS version: Metal GPU requires macOS 14 (Sonoma) or later. Check VM configuration: GPU must be enabled at VM creation. Cannot be hot-added.

Check GPU Usage in VM

NVIDIA (Linux):
AMD (Linux):
Metal (macOS guest):

Compose with GPU

Define GPU access in compose files:
On Linux, specify the GPU:
On macOS Apple Silicon, GPU access is automatic when Metal is enabled:

Best Practices

  1. Use pre-built GPU images with drivers included
  2. Test GPU access before deploying workloads
  3. Monitor GPU memory to avoid OOM errors
  4. Restore drivers after VM shutdown (automatic)
  5. Isolate IOMMU groups for reliable passthrough