Driver and Runtime#

How the 3-layer NVIDIA GPU driver stack operates in containers and how gVisor and Kata Containers expose GPUs to sandboxed workloads. See DRA for how Kubernetes discovers node GPUs and allocates them to containers.

3-Layer CUDA Stack#

Running a GPU workload inside a container involves two User Space libraries and one Kernel Space module.

LayerBinaryLocationRequiredRole
CUDA Runtimelibcudart.soUser Space (bundled in container image)OptionalHigh-level convenience APIs (cudaMalloc, cudaLaunchKernel) delegating to libcuda.so
CUDA Driverlibcuda.soUser Space (mounted from host via CDI)RequiredCommand packet assembly, PTX JIT, stream/pool management, and MMIO writes (HAMi-core hook target)
Kernel Modulenvidia.ko, nvidia-uvm.koKernel Space (/dev/nvidia*)RequiredPhysical VRAM allocation, GPU MMU page tables, PCIe BAR/MMIO mmap, and interrupt handling
  • GPU workloads can invoke libcuda.so directly without linking libcudart.so.
  • libcuda.so and nvidia.ko must match the exact same driver version.

Division of Labor Between nvidia.ko and libcuda.so#

nvidia.ko does not sit in the middle of every command and data transfer between CPU/RAM and GPU cores/VRAM. nvidia.ko establishes the initial memory mappings, after which libcuda.so drives execution directly via Kernel Bypass.

  • nvidia.ko (path setup via ioctl and mmap): User Space processes lack privileges to manipulate physical addresses or hardware page tables. Using kernel privileges, nvidia.ko allocates physical VRAM pages, sets up IOMMU mappings for pinned host memory (pin_user_pages), and maps the GPU command ring buffer (GPFIFO) and Doorbell MMIO registers directly into the process’s virtual address space via mmap.
  • libcuda.so (direct execution after mapping): Writing command packets into the mapped User Space buffer and ringing the Doorbell MMIO address submits work straight over PCIe to the GPU hardware scheduler without any syscall. Host-to-device and device-to-host transfers (cuMemcpyAsync on pinned memory) are likewise executed directly over PCIe by the GPU’s hardware Copy Engine (DMA).
  • Exceptions where nvidia.ko is invoked again: Fresh physical VRAM allocations or frees not served from an existing pool (cuMemAlloc_v2, cuModuleLoad), interrupt-driven blocking synchronization (cuEventSynchronize), and Unified Memory page faults (nvidia-uvm.ko).

Why Syscall Interception Cannot Control CUDA Calls#

Soft vGPU sharing tools such as HAMi-core (libvgpu.so) hook libcuda.so symbols via LD_PRELOAD rather than intercepting syscalls like gVisor for three reasons.

  • No syscall occurs during cuLaunchKernel: Because of Kernel Bypass, launching a GPU kernel invokes no ioctl. Observing only the syscall boundary cannot see kernel launches or grid dimensions, making SM compute throttling (CUDA_DEVICE_SM_LIMIT) impossible.
  • Unstable internal ioctl ABI: ioctl struct layouts between libcuda.so and nvidia.ko change across minor driver releases, whereas the libcuda.so C API maintains backward compatibility.
  • User Space memory pools and cuMemGetInfo semantics: Sub-allocators (cudaMallocAsync) and per-container virtual free-memory reporting (cuMemGetInfo_v2) are straightforward to control at the C function boundary, whereas intercepting raw Resource Manager ioctl payloads requires reverse-engineering and rewriting internal command packets.

How gVisor and Kata Containers Support GPUs#

Although syscall interception cannot implement soft GPU slicing, both gVisor and Kata Containers support GPU workloads because they pass through a full GPU (or hardware MIG instance) into an isolated sandbox or MicroVM rather than slicing it in software.

AspectStandard Container + HAMi-coregVisor (nvproxy)Kata Containers (VFIO)
GoalSoft compute and memory slicing on a shared GPUGPU execution inside a host-kernel-isolating sandboxGPU execution inside a hardware-isolated MicroVM
Interception boundaryUser Space libcuda.so symbols (LD_PRELOAD)Sentry /dev/nvidia* ioctl and mmap proxyPCIe hardware pass through (vfio-pci + IOMMU)
nvidia.ko locationShared host kernelShared host kernel (via nvproxy)Loaded inside the guest MicroVM kernel
Driver version couplingLow (stable CUDA C ABI)High (only versions registered in nvproxy)Low (only guest VM driver and libcuda must match)
  • gVisor (nvproxy): gVisor blocks arbitrary device ioctl calls by default, so it implements a dedicated nvproxy package inside Sentry. nvproxy models the per-version ioctl struct tree from NVIDIA/open-gpu-kernel-modules, validates setup ioctl and mmap calls before forwarding them to the host nvidia.ko, and lets subsequent cuLaunchKernel calls run at near-native speed over MMIO.
  • Kata Containers (VFIO): Boots a dedicated guest kernel inside a MicroVM per pod. The GPU is unbound from the host nvidia.ko and passed through as a raw PCIe device via Linux vfio-pci and IOMMU, and the guest VM kernel loads its own nvidia.ko.