virtio-nvgpu README

The project's README from github.com/nestrilabs/virtio-nvgpu. As one markdown file: README.md.

virtio-nvgpu

Share one NVIDIA GPU across several VMs, at bare-metal speed.

Run NVIDIA's own unmodified drivers (Vulkan, NVENC, and CUDA) inside multiple microVMs, while the host keeps the card. No vGPU licenses or VFIO passthrough needed.

Why

  1. Passthrough locks the whole GPU to one VM.
  2. vGPU costs real money and only works on datacenter cards.
  3. API forwarding (Venus, virgl) is hella slow, and doesn't support NVENC or CUDA.

virtio-nvgpu forwards the NVIDIA driver instead of the graphics API. The guest builds its own GPU commands and writes them straight to GPU memory, so a frame being drawn doesn't cross the VM boundary. Nothing gets serialized and replayed on the host the way Venus and virgl do it.

How fast

On an RTX 3060:

[!NOTE] 12 is what we tested, not a hard cap. Like containers, you're limited by:

  1. VRAM. A game needs gigabytes, so this usually runs out first. Cap each guest with --vram-limit-mib.
  2. Host CPU and RAM for each guest.
  3. NVENC's 12-session cap on GeForce cards. Our Nestri capture layer encodes with Vulkan Video, which doesn't count against it (16 at once worked fine).

Numbers and method →

Who it's for

People who stream games or GPU apps from headless VMs (cloud gaming, remote desktops, CI with a real GPU, selfhosted "serverless" AI) on consumer NVIDIA cards.

Before you use it

Learn more

Inspired by gVisor's nvproxy, and kayfabe by Reindert Pelsma.

virtio-nvgpu (nestrilabs/virtio-nvgpu)

Searching Database…

What is this?A virtio device that shares one NVIDIA GPU across several KVM virtual machines at near-bare-metal speed, by forwarding kernel-driver ioctls instead of translating graphics APIs. The target use case is headless streaming: the guest renders and encodes on the GPU, and only compressed video leaves.
Does this get installed in the VM, on the host, or both?Both sides: a guest kernel module registers /dev/nvidia and forwards ioctl and mmap over the virtqueues, while a Rust device crate implements the device on the host inside your VMM. The crate itself depends on no particular VMM.
How do I get a VM running on the shared GPU?There is no one-click path yet: you load the guest kernel module inside a Linux KVM guest, and your host VMM adopts the device crate by implementing a small trait set (descriptor chains, an event queue, guest and host memory mapping). Optional capabilities degrade rather than fail to build, so a VMM can adopt it before supporting every feature.
Which NVIDIA drivers and cards does it work with?Kernel drivers are matched by ABI range: profiles are shipped for 535.129.03, 580.178.04 and 595.71.05, and anything older is refused. Numbers come from an RTX 3060 on driver 595.99.02; an RTX A2000 on 615.71.09 renders but is not benchmarked.
What is not working or not built yet?No display scanout (frames leave as video, not pixels), no MIG or SR-IOV, no cudaMallocManaged unified memory, and CUDA is untested beyond enumeration. More than four guests on one card has not been tried, and the sandboxed per-guest isolate is a design note, not code.
How is the code licensed?The split is deliberate: the guest kernel driver is GPL-2.0, the virtio device crate is Apache-2.0, and the shared protocol headers are dual-licensed BSD-3-Clause OR GPL-2.0+ so both halves can include them.
How close to bare metal does a guest actually get?For game-like frames of 2 ms or more, a guest is within 2% of bare metal and burns the same CPU — 0.37 s vs the host's 0.40 s over a 12-second unpaced run. Only very light frames (0.5 ms and below) drop off, to 93–71% of bare metal.
Can several VMs really share one card at the same time?Four guests on one RTX 3060 rendered 103.7 fps combined against 102.9 for a single guest, with frame-time splits even to four decimals — and all four encoded H.264 at once at 60 Hz without hitting an NVENC session limit. Four is what was run, not a limit found.
Why not just use VFIO passthrough or virtio-gpu with Venus?VFIO passthrough gives native speed but dedicates the whole GPU to one VM. Venus serializes every API call — thousands per frame — and leaves no practical path to guest-side NVENC. virtio-nvgpu crosses the boundary per ioctl, and a render loop issues none because submission is a write to mapped memory.
What can a guest actually do with the shared GPU?Vulkan rendering with presentation to a compositor inside the guest, headless-EGL OpenGL, CUDA device memory allocation with zero-copy CUDA↔Vulkan/GL interop, plus NVENC encoding from CUDA device pointers and NVDEC decoding.
Creator
nestrilabs
Size
5.6 MB
Stars
462
Age
8mo
Commits · 90 Days