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.
| Layer | Binary | Location | Required | Role |
|---|---|---|---|---|
| CUDA Runtime | libcudart.so | User Space (bundled in container image) | Optional | High-level convenience APIs (cudaMalloc, cudaLaunchKernel) delegating to libcuda.so |
| CUDA Driver | libcuda.so | User Space (mounted from host via CDI) | Required | Command packet assembly, PTX JIT, stream/pool management, and MMIO writes (HAMi-core hook target) |
| Kernel Module | nvidia.ko, nvidia-uvm.ko | Kernel Space (/dev/nvidia*) | Required | Physical VRAM allocation, GPU MMU page tables, PCIe BAR/MMIO mmap, and interrupt handling |
- GPU workloads can invoke
libcuda.sodirectly without linkinglibcudart.so. libcuda.soandnvidia.komust 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 viaioctlandmmap): User Space processes lack privileges to manipulate physical addresses or hardware page tables. Using kernel privileges,nvidia.koallocates 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 viammap.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 (cuMemcpyAsyncon pinned memory) are likewise executed directly over PCIe by the GPU’s hardware Copy Engine (DMA).- Exceptions where
nvidia.kois 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 noioctl. Observing only the syscall boundary cannot see kernel launches or grid dimensions, making SM compute throttling (CUDA_DEVICE_SM_LIMIT) impossible. - Unstable internal
ioctlABI:ioctlstruct layouts betweenlibcuda.soandnvidia.kochange across minor driver releases, whereas thelibcuda.soC API maintains backward compatibility. - User Space memory pools and
cuMemGetInfosemantics: 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 Managerioctlpayloads 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.
| Aspect | Standard Container + HAMi-core | gVisor (nvproxy) | Kata Containers (VFIO) |
|---|---|---|---|
| Goal | Soft compute and memory slicing on a shared GPU | GPU execution inside a host-kernel-isolating sandbox | GPU execution inside a hardware-isolated MicroVM |
| Interception boundary | User Space libcuda.so symbols (LD_PRELOAD) | Sentry /dev/nvidia* ioctl and mmap proxy | PCIe hardware pass through (vfio-pci + IOMMU) |
nvidia.ko location | Shared host kernel | Shared host kernel (via nvproxy) | Loaded inside the guest MicroVM kernel |
| Driver version coupling | Low (stable CUDA C ABI) | High (only versions registered in nvproxy) | Low (only guest VM driver and libcuda must match) |
gVisor(nvproxy):gVisorblocks arbitrary deviceioctlcalls by default, so it implements a dedicatednvproxypackage insideSentry.nvproxymodels the per-versionioctlstruct tree from NVIDIA/open-gpu-kernel-modules, validates setupioctlandmmapcalls before forwarding them to the hostnvidia.ko, and lets subsequentcuLaunchKernelcalls 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 hostnvidia.koand passed through as a raw PCIe device via Linuxvfio-pciand IOMMU, and the guest VM kernel loads its ownnvidia.ko.