$ show amd/MxGPU-Virtualization
This repository implements AMD's MxGPU virtualization solution, providing SR-IOV support for AMD GPUs (MI200, MI300, Navi32). It consists of a kernel module (GIM) that manages virtual functions, a core library (libgv) for hardware abstraction and RAS, and a user-space system management interface (SMI) with CLI and Python bindings. The architecture is layered: the kernel driver (gim/) communicates with hardware and exposes IOCTLs; libgv/ provides hardware-specific implementations via function pointer tables; smi-lib/ provides a unified API for monitoring, partitioning, RAS, and NIC management. Key entry points include the GIM kernel module (gim/gim_shim/gim_drv.c), the SMI CLI (smi-lib/cli/cpp/src/smi_cli_main.cpp), and the SMI library (smi-lib/src/amdsmi.c). Data flows involve PF-VF mailbox communication, RAS error logging via CPER, and telemetry collection through SMU firmware interfaces. External dependencies include Linux kernel headers, DKMS, and optional NIC libraries. The codebase is large and professionally structured, with extensive hardware abstraction layers, unit tests, and packaging scripts, though it carries maintenance risks from ASIC-specific duplication and embedded firmware blobs.
The LLM identified 5 files worth highlighting for reuse:
Self-contained RAS error decoder that converts raw ACA hardware registers into structured JSON output with bank, severity, category, and error type. Demonstrates clean C API design with no internal dependencies beyond standard libraries, making it reusable for any project needing AMD GPU error decoding.
OS abstraction layer wrapping kernel operations (PCI config, DMA, interrupts, timers, locks, threads) into a unified interface. Enables portability across Linux, Windows, and ESXi. The pattern of function pointer structs for OS services is reusable for any driver or low-level library needing cross-platform support.
Generic chained hash table implementation with mutex protection and pluggable hash function. Used for device handle lookups in the SMI driver. The code is self-contained, well-structured, and can be extracted for any project needing a simple, thread-safe hash table in C.
Lightweight JSON object construction library in C supporting null, bool, number, string, object, and array types. No external dependencies. Demonstrates careful memory management and a clean API for building JSON output, reusable in any C project requiring minimal JSON generation.
Abstracts Linux system calls (ioctl, poll, open, aligned_alloc) behind a wrapper interface, enabling unit testing via link-time mocking. The pattern is directly reusable for any project that needs to test code interacting with kernel or hardware interfaces without real devices.