The driver client, call by call
This is what replaces libcuda: nvrm/nvrm.c (about 900 lines) and the qualification programs in m16/. They talk to NVIDIA's open kernel module, version 580.173.02, through the ioctls its public headers define (third_party/nvidia-open-580.173.02/, MIT, unchanged). Line numbers below are for nvrm/nvrm.c on the commit that added this file.
The three device files
| File | Opened by | Used for |
|---|---|---|
/dev/nvidiactl | nvrm_open() | The resource manager (RM): every object is created with NV_ESC_RM_ALLOC, configured with NV_ESC_RM_CONTROL and destroyed with NV_ESC_RM_FREE. |
/dev/nvidia<minor> | open_dev_fd() (line 231), registered with NV_ESC_REGISTER_FD | CPU mappings of memory and of the usermode register page (NV_ESC_RM_MAP_MEMORY, then mmap). |
/dev/nvidia-uvm, opened twice | nvrm_open() | The unified-memory driver, which owns the GPU page tables of the address space. |
1. Open: nvrm_open() (line 293)
In order:
- Reserve a slot of virtual addresses for this process, then open
/dev/nvidiactland/dev/nvidia-uvm. RM_ALLOC NV01_ROOT_CLIENT: the root handle. Everything below hangs off it and is freed with it.UVM_INITIALIZE, thenUVM_MM_INITIALIZEon the second UVM file (a failure there is tolerated, aslibcudatolerates it).NV_ESC_CARD_INFOlists the GPUs; take the first valid one and open its device file.RM_CONTROL NV0000_CTRL_CMD_GPU_GET_ID_INFO_V2gives the device instance.RM_ALLOC NV01_DEVICE_0, thenNV20_SUBDEVICE_0, thenNV01_MEMORY_VIRTUAL(the GPU address range).RM_CONTROL NV0080_CTRL_CMD_GPU_GET_CLASSLIST, called twice (count, then list). The client looks for three classes and refuses to go on without them:BLACKWELL_COMPUTE_B,BLACKWELL_CHANNEL_GPFIFO_AandHOPPER_USERMODE_A.RM_ALLOC HOPPER_USERMODE_Aunder the subdevice and map 64 KiB of it. The doorbell is the word atNVC361_NOTIFY_CHANNEL_PENDINGinside that page.RM_CONTROL NV2080_CTRL_CMD_GR_GET_INFOreads the SM version (sm_121 on the GB10).RM_ALLOC FERMI_VASPACE_Awith page faulting on andIS_EXTERNALLY_OWNED, so the unified-memory driver manages it.RM_CONTROL NV2080_CTRL_CMD_GPU_GET_GID_INFOreads the GPU UUID, thenUVM_REGISTER_GPUandUVM_REGISTER_GPU_VASPACEhand the GPU and the address space to UVM.
2. Memory: nvrm_alloc() (line 546) and nvrm_free() (line 624)
The GB10 has no separate video memory; the CPU and GPU share one LPDDR5X memory. Each buffer is:
- a range taken from the process's free list and reserved on the CPU side with
mmap(MAP_FIXED_NOREPLACE), so nothing else can land there; RM_ALLOC NV01_MEMORY_SYSTEM(non-contiguous, PCI location, GPU-cacheable or not);- mapped for the CPU at exactly that address (
NV_ESC_RM_MAP_MEMORYandmmap); - mapped for the GPU at the same address:
UVM_CREATE_EXTERNAL_RANGE,NV_ESC_RM_MAP_MEMORY_DMA,UVM_MAP_EXTERNAL_ALLOCATION(line 498).
So the CPU pointer and the GPU address of a buffer are the same number. Nothing is copied between a "host" and a "device" copy, because there is only one copy.
nvrm_alloc_gpu_uncached() (line 554) makes the GPU skip its L2 cache for the buffer. Anything the CPU polls while the GPU writes it (completion markers, semaphores, the command ring) must be allocated this way; the platform contract refuses a host-polled buffer that is not (src/omega_gpu_platform.h).
nvrm_free() undoes the four steps in reverse and returns the range to the free list. It refuses a stale or duplicate handle without calling the driver. If any step fails half way, the allocation is quarantined rather than reused, because the driver's state is then unknown.
3. The channel: nvrm_channel() (line 695)
RM_ALLOC KEPLER_CHANNEL_GROUP_Aon the graphics/compute engine, thenFERMI_CONTEXT_SHARE_Abound to the address space.- One GPU-uncached 64 KiB buffer holds the command ring (1,024 entries of 8 bytes) followed by its USERD control page; a 1 MiB buffer receives channel errors.
RM_ALLOC BLACKWELL_CHANNEL_GPFIFO_Awith the ring, USERD and error buffer.RM_ALLOC BLACKWELL_COMPUTE_Bunder the channel. This one allocation needs one free, physically contiguous 2 MiB block of host memory for the channel's context buffer. On a long-running host that block can be missing for a few hundred milliseconds, soNV_ERR_NO_MEMORYhere, and only here, is retried: 50 times at 100 ms (NVRM_CHANNEL_NO_MEMORY_RETRIES, omega#523). Every other error is final at once.RM_CONTROL NVC36F_CTRL_CMD_GPFIFO_GET_WORK_SUBMIT_TOKEN: the number the doorbell is rung with.UVM_REGISTER_CHANNELwith 64 MiB of address space for the channel's context buffers, thenRM_CONTROL NVA06C_CTRL_CMD_GPFIFO_SCHEDULEswitches the channel on.
4. Submitting work: nvrm_enqueue() (line 818) and nvrm_ring() (line 840)
A ring entry is 8 bytes (nvrm_gp_entry(), line 810): the pushbuffer's GPU address in the low bits and its length in 32-bit words from bit 42. To submit:
- refuse if the ring would overrun entries that have not been seen to finish (Blackwell's USERD reports no read pointer, so the client counts:
putandretired); - write the entry,
dsb sy, write the newGPPutinto USERD,dsb sy; - ring the doorbell: one 32-bit store of the work-submit token to the usermode page.
There is no system call on this path. The pushbuffer itself is a list of method headers (nvrm_mthd() in nvrm/nvrm.h) and data words; what goes in it for a kernel launch is in src/omega_gpu_cmdlist.c and src/omega_blackwell_submit.c.
5. Waiting: m16/m16_gpu_wait.c
Completion is a word in GPU-uncached memory that the GPU writes with a semaphore release. The one wait primitive has two kinds (an exact value, or a counter that has reached a target, correct across wrap-around) and two bounds: a hard deadline that is never extended and a stall deadline that restarts only when a watched word changes. A memory barrier runs before every read. A wait that times out is reported as uncertain: the session then keeps every buffer and refuses all further GPU work in the process, because the GPU may still be running.
6. Proof on the chip: m16/
m16_requalify.c: queue a semaphore release without ringing the doorbell and check the marker stays 0 for 100 ms; ring it and check the marker becomes0x16c0ffee; read/proc/self/mapsto prove nolibcudawas loaded. Receipt:evidence/m16-blackwell-native-path-requalification-receipt.json.m16_concurrent.c: two independent channels; ringing one never runs the other's work.nvrm/lifecycle_gates.c:nvrm_free()on the real chip (address reuse, stale and duplicate handles, CPU unmap) and the counter wait.nvrm/submission_visibility_gates.c: ring entries and rewritten command buffers published by the CPU are seen by the GPU on the second submission too (before the fix, the second submission stalled on the GB10).
7. Above and below the client
Above it, src/omega_gpu_platform.h is the contract the runtime is written against: typed handles instead of file descriptors, explicit rights and kinds for every buffer, polling named as polling, and no silent fallback. src/omega_gpu_platform_linux.c implements it on this client. The C reference of Aien's own GB10 driver (L332, aienux#441) implements the same contract in a simulator. src/omega_gpu_platform_aien.c is that driver's user-space side (section 8): migration-pending C, compiled only for its host test.
Below it, today, NVIDIA's open kernel module (nvidia.ko, nvidia-uvm.ko) does the rest: it boots the GPU's GSP firmware, builds page tables and schedules channels. Aien's own GB10 driver replaces that module (aien-dev/aien-gpu, aien-dev/omega-gpu-driver, aienux#441; BUILDING in ROADMAP.md, nothing run on the GB10 yet). This client speaks NVIDIA's ioctl interface, so it has to move onto that driver's interface; that move is PROPOSED. The firmware stays NVIDIA's; the chip checks its signature.
8. The second implementation: aien-gpu.ko (src/omega_gpu_platform_aien.c)
Evidence level: IMPLEMENTED, host-tested on a simulated device. Hardware NOT_RUN: it has never opened a real /dev/aien-gpu. The shipped path stays NVIDIA's open kernel module (section 7) until the move onto Aien's own driver lands.
Migration-pending C: the definition exists only when built with CUDAPP_MIGRATION_PENDING_AIEN_GPU=1, which only the host test and its mutants set; libomega_gpu.a and every other build leave it OFF. Its decisions and request bytes are now seeded Omega, native/aiengpu/context.om (aien-dev/CUDApp#128), called through the generated src/cudapp_om_aiengpu.c (omega_aiengpu): the AGPU_INFO verdict, buffer size and VA-window search, the AGPU_MEM_ALLOC/MEM_FREE/CHAN_CREATE/CHAN_DESTROY request bytes and RM verdict, the cache policy, poll and range checks, the serial compare, the GPFIFO entry and the submit plan (length and ring-full refusals, omega #457 prefix, ring slot, GPPut). The C rules they replaced stay behind CUDAPP_MIGRATION_PENDING_C_PLATFORM_AIEN (OFF) as the oracle: make test-gpu-platform-aien requires the simulated-device traces of both (every ioctl's bytes in and out, map arguments, final ring, USERD GPPut, pushbuffer and doorbell) to be byte-identical, and make test-gpu-platform-aien-om-mutants compiles mutant context.om files with the pinned omc. Open, ioctl, mmap, the ordered ring/USERD/doorbell stores, the diagnostic text and the function table stay C: function-mode Omega has no devctl for AGPU ('A') requests, no maphold/mapbind (refused in function mode at omega-mv#1040), no text constants and no C function-table export (aien-dev/omega-bridge#29).
aien-gpu.ko is Aien's own GB10 kernel module (aien-dev/aien-gpu, L332, aienux#441); in place of nvidia.ko and nvidia-uvm.ko it exposes a small compute interface of its own, third_party/aien-gpu-abi1/aien_gpu_uapi.h (ABI 1). The platform fills the same table with the same caps and refusals as the Linux reference, except that it drives one queue where the reference can open extra channels, so the session, command list and libraries run on it unchanged:
device_open: open/dev/aien-gpuandAGPU_INFO; anything but ABI 1 in stateRM_READYis a REFUSED_DEVICE with the state named. A missing node is a REFUSED_DEVICE naming the path.dma_alloc: reserve a CPU range in [64 GiB, 1 TiB) withMAP_FIXED_NOREPLACE(a GPFIFO entry carries 40 address bits),AGPU_MEM_ALLOCat that address (AGPU_MEM_GPU_UNCACHEDunless a device-private DATA buffer asked for GPU_CACHED), then map the objectMAP_FIXED|MAP_SHAREDover the reservation. The GPU address is the CPU address.queue_open: one GPU-uncached buffer with the 1024-entry ring and USERD after it, an error notifier,AGPU_CHAN_CREATE, and a mapping of the usermode page.queue_submit: the three steps of section 4 (entry fromomega_gpu_aien_gp_entry, bit for bitnvrm_gp_entry;GPPutatNvc96fControl.GPPut; the token stored at +0x90).queue_retire,poll_wordand the omega #457 L2 invalidate prefix work as in the Linux reference.device_closefrees every buffer and the channel (a mapping keeps an aien-gpu object alive pastclose).
What selects it: a program built with the switch ON calls omega_gpu_session_set_platform(omega_gpu_platform_aien(&caps), &caps) before the first session open; the hosted session still installs the Linux reference by default. CUDAPP_AIEN_GPU_DEV names another device node. make test-gpu-platform-aien runs tests/test_omega_gpu_platform_aien.c against a simulated /dev/aien-gpu and a simulated GPU that executes the semaphore releases from the ring, plus six mutants that must fail it.