Cheat Sheet - Linux: /linux/ - CLI: /linux/cli/ - locate vs type vs which vs whereis: /linux/cli/locate-vs-type-vs-which-vs-whereis/ - make: /linux/cli/make/ - awk: /linux/cli/awk/ - find: /linux/cli/find/ - grep: /linux/cli/grep/ - pgrep: /linux/cli/pgrep/ - ps: /linux/cli/ps/ - pstree: /linux/cli/pstree/ - trap: /linux/cli/trap/ - xargs: /linux/cli/xargs/ - Shell: /linux/shell/ - BASH_SOURCE: /linux/shell/bash-source/ - Redirection: /linux/shell/redirection/ - Special Variables: /linux/shell/special-variables/ - Scripting Tips: /linux/shell/script-tips/ - set -o vi: /linux/shell/bash-vi-mode/ - Shell Processing Order: /linux/shell/process-order/ - What are Interactive and Login Shells?: /linux/shell/interactive-login/ - Double Quote Expansion: /linux/shell/shell-expansion/ - System Programming: /linux/system-programming/ - File I/O: /linux/system-programming/file-io/ - Process: /linux/system-programming/process/ - Shared Libraries: /linux/system-programming/shared-libraries/ - Kernel: /linux/kernel/ - Go: /programming/go/ - Concurrency: /programming/go/concurrency/ - CSP (Communicating Sequential Processes) and Channels: /programming/go/concurrency/csp/ - Channel: /programming/go/concurrency/channel/ - Select: /programming/go/concurrency/select/ - sync: /programming/go/concurrency/sync/ - Concurrency Patterns: /programming/go/concurrency/patterns/ - Goroutines and the Go Runtime: /programming/go/concurrency/runtime/ - Standard Library: /programming/go/std/ - os: /programming/go/std/os/ - context: /programming/go/std/context/ - io: /programming/go/std/io/ - json: /programming/go/std/json/ - net/http: /programming/go/std/net-http/ - slog: /programming/go/std/slog/ - testing: /programming/go/std/testing/ - time: /programming/go/std/time/ - Ellipsis (...): /programming/go/ellipsis/ - error: /programming/go/error/ - Function: /programming/go/function/ - Go Tool: /programming/go/tool/ - Interface: /programming/go/interface/ - Map: /programming/go/map/ - Package and Module: /programming/go/package-module/ - Pointer: /programming/go/pointer/ - Slice: /programming/go/slice/ - String: /programming/go/string/ - Switch: /programming/go/switch/ - Comparison: /programming/go/comparison/ - defaultdict: /programming/python/collections/defaultdict/ - heapq: /programming/python/collections/heapq/ - @cache: /programming/python/cache/ - abc: /programming/python/abc/ - bisect: /programming/python/bisect/ - Type Hints: /programming/python/type-hints/ - Passing Mechanism: /programming/python/passing-mechanism/ - uv: /programming/python/uv/ - *args and **kwargs: /programming/python/args-kwargs/ - re: /programming/python/re/ - C: /programming/c/ - Pointers and Arrays: /programming/c/pointer/ - Syntax Basics: /programming/c/syntax-basics/ - static: /programming/c/static/ - Bit Manipulation: /programming/c/bit-manipulation/ - C vs C++: /programming/c/c-vs-cpp/ - stdatomic: /programming/c/stdatomic/ - C++: /programming/cpp/ - RAII (Resource Acquisition Is Initialization): /programming/cpp/raii/ - Copy Elision & Move Semantics: /programming/cpp/copy-elision-and-move-semantics/ - Most Vexing Parse & In-Class Initializer: /programming/cpp/most-vexing-parse/ - C++ Keywords Reference: /programming/cpp/keywords/ - C++ Primer: /programming/cpp/primer/ - Variables and Basic Types: /programming/cpp/primer/variables-and-basic-types/ - Expressions: /programming/cpp/primer/expressions/ - Type Conversions and Casts: /programming/cpp/primer/type-conversions-and-casts/ - Statements: /programming/cpp/primer/statements/ - Functions: /programming/cpp/primer/functions/ - Classes: /programming/cpp/primer/classes/ - The IO Library: /programming/cpp/primer/io-library/ - STL: /programming/cpp/primer/stl/ - Lambda Expressions: /programming/cpp/primer/lambda/ - Smart Pointers: /programming/cpp/primer/smart-pointers/ - Copy Control: /programming/cpp/primer/copy-control/ - Overloaded Operations and Conversions: /programming/cpp/primer/operator-overloading/ - Object-Oriented Programming (OOP): /programming/cpp/primer/oop/ - Templates and Generic Programming: /programming/cpp/primer/templates/ - Namespaces: /programming/cpp/primer/namespaces/ - Pointers to Class Member: /programming/cpp/primer/pointers-to-class-member/ - Advanced: /programming/cpp/advanced/ - Error Handling: /programming/cpp/advanced/error-handling/ - Concurrency & Threading: /programming/cpp/advanced/concurrency/ - Unit Testing: /programming/cpp/advanced/unit-testing/ - Comparison: /programming/comparison/ - Kubernetes: /cloud-devops/kubernetes/ - Fleet: /cloud-devops/kubernetes/gke/fleet/ - Kustomize vs Helm: /cloud-devops/kubernetes/kustomize-vs-helm/ - API Extension: /cloud-devops/kubernetes/api-extension/ - Concept: /cloud-devops/kubernetes/kueue/concept/ - DRA: /cloud-devops/kubernetes/dra/ - Secret Manager: /cloud-devops/terraform/google-secret-manager/ - Knowledge: /network/knowledge/ - PDU: /network/knowledge/osi-model/ - curl: /network/cli/curl/ - Concurrency Concepts: /cs/concurrency-and-parallelism/concepts/ - Concurrency vs Parallelism: /cs/concurrency-and-parallelism/concurrency-vs-parallelism/ - Mutex vs Atomic: /cs/concurrency-and-parallelism/mutex-vs-atomic/ - Regular Expression: /cs/regular-expression/ - Multiplexer vs Dispatcher: /cs/multiplexer-vs-dispatcher/ - Driver and Runtime: /ai-ml/gpu/driver-and-runtime/ - Serving: /ai-ml/serving/ - Dotfiles: /dotfiles/ - Git: /dotfiles/git/ - Cheat Sheet: /dotfiles/git/cheat-sheet/ - revisions: /dotfiles/git/revisions/ - Submodule vs Worktree: /dotfiles/git/submodule-vs-worktree/ - checkout, reset -> switch, restore: /dotfiles/git/checkout-switch-restore-reset/ - rebase: /dotfiles/git/rebase/ - Branching and Merging: /dotfiles/git/branching-merging/ - Vim: /dotfiles/vim/ - Plugin: /dotfiles/vim/plugin/ - auto-pairs: /dotfiles/vim/plugin/auto-pairs/ - vim-commentary: /dotfiles/vim/plugin/vim-commentary/ - vim-easymotion: /dotfiles/vim/plugin/vim-easymotion/ - vim-surround: /dotfiles/vim/plugin/vim-surround/ - Marks: /dotfiles/vim/tips/marks/ - vimrc: /dotfiles/vim/vimrc/ - lf: /dotfiles/lf/ # 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]({{< relref "/cloud-devops/kubernetes/dra.md" >}}) 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.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](https://github.com/Project-HAMi/HAMi-core) (`libvgpu.so`) hook `libcuda.so` symbols via [`LD_PRELOAD`]({{< relref "/linux/system-programming/shared-libraries.md#2-dynamic-loading-api-dlopen--dlsym-tlpi-ch-42" >}}) 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. | 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](https://github.com/gvisor/gvisor/blob/master/pkg/sentry/devices/nvproxy/README.md))**: `gVisor` blocks arbitrary device `ioctl` calls by default, so it implements a dedicated [`nvproxy`](https://github.com/gvisor/gvisor/blob/master/pkg/sentry/devices/nvproxy/nvproxy.go) package inside `Sentry`. `nvproxy` models the per-version `ioctl` struct tree from [NVIDIA/open-gpu-kernel-modules](https://github.com/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`.