Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/CUDApp/blob/main/evidence/NVML-2026-11-07/seeded/BRIDGE-EXTENSION.md # CUDApp CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / evidence / NVML-2026-11-07 / seeded / BRIDGE-EXTENSION.md` 147 lines · 14402 bytes Raw Blame History Rendered 1 # NVML C ABI emitter extension 2 3 Status: PROPOSED, not an existing Omega syntax claim. Owner of integration: Main. Consumer: aien-dev/CUDApp#365, branch feat/omega-nvml-replacement, baseline `4bf58894d1985d41240736145de7b5fe03e377ee`. Compiler: omega-mv `e5b32567`, omc SHA256 `2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f`. CUDApp bridge lock: `bc11b30b1faa9af8b875ae6fec24e5f49cf03ac4`. Current newer bridge documentation at `d8174edd` still refuses globals/text/host words in public native ABI with exit 110. This extension does not authorize weakening those existing modes: add an explicit library-emission mode. 4 5 ## Current boundary and work available 6 7 `compat/nvml/cudapp_nvml.c` is 167 physical lines, not 167 lines of pure ABI marshalling. Its handle mapping (43–47), requested-action/call protocol (49–100), wrappers (102–148), and string cache (150–167) remain in the production path. `tests/nvml/host.om` is 942 physical lines: its lines 225–444 port the action/call protocol, wrappers and cache; lines 144–223 port the fake transport; the remaining code contains test state, helpers and the same 476 checks. This is an exercised model port, not a deployed .so. Do not describe the production C protocol as already removed. 8 9 Observed CPU behavior: pure Omega host has the same 476 passing checks and the same failure/check counts for all 22 source mutants as the prior C caller. The new seeded conductor additionally retains generated-source equality, CUDA-header ABI comparison, thin-shell guard and oracle negative control. Live RM, concurrent ABI calls and the generated .so remain NOT_RUN. 10 11 The deliverable of this extension is removal of the production C file, not generated boilerplate around that handwritten file. Lift the exercised protocol into `native/nvml/api.om`; bind its transport operations to the existing `native/nvrm/transport.om` functions in production and `rmfake.om` in the device-free gate. Keep the same NVML state machine, codes, copy decisions and fake faults. The bridge must lower the resulting program-mode globals and calls; it must not translate a C protocol into a second handwritten implementation. 12 13 ## Declaration format 14 15 Use ordinary seeded `.om` declarations plus machine-readable `note cabi` metadata. Every file remains accepted by the pinned compiler because these are notes; the new bridge mode must validate and consume them. Unknown or incomplete `cabi` notes must be refused, not silently ignored in library mode. The following grammar is the proposed build contract, not already implemented: 16 17 ```text 18 note cabi library libnvidia-ml.so.1 header nvml.h 19 note cabi lock NvLock process mutex 20 note cabi status nvmlReturn_t int32 valid 0..30,999 trap 999 21 note cabi enum nvmlTemperatureSensors_t uint32 22 note cabi handle nvmlDevice_t nvmlDevice_st pool NvDev count 8 invalid `18446744073709551615` lock NvLock 23 note cabi record nvmlMemory_t size 24 align 8 total:u64:0 free:u64:8 used:u64:16 24 note cabi record nvmlUtilization_t size 8 align 4 gpu:u32:0 memory:u32:4 25 note cabi record nvmlProcessInfo_t size 24 align 8 pid:u32:0 usedGpuMemory:u64:8 gpuInstanceId:u32:16 computeInstanceId:u32:20 26 note cabi state NvState process lock NvLock 27 note cabi state NvBytes process lock NvLock 28 note cabi state NvTexts process lock NvLock 29 note cabi state NvReady process lock NvLock 30 note cabi cstr NvTexts slots 32 width 64 fallback "Unknown Error" lock NvLock 31 note cabi export nvmlInit_v2 nv_init status nvmlReturn_t lock NvLock 32 note cabi export nvmlDeviceGetCount_v2 nv_count status nvmlReturn_t lock NvLock 33 note cabi arg nvmlDeviceGetCount_v2 deviceCount nullable out uint32 commit 0 34 note cabi export nvmlDeviceGetName nv_name status nvmlReturn_t lock NvLock 35 note cabi arg nvmlDeviceGetName device handle nvmlDevice_t 36 note cabi arg nvmlDeviceGetName name nullable out char length length commit 0 37 note cabi arg nvmlDeviceGetName length uint32 38 note cabi export nvmlErrorString nv_error cstr NvTexts lock NvLock 39 note cabi arg nvmlErrorString result signed int32 40 ``` 41 42 Types refer to existing Omega `uint`, `ulong`, `uchar`, `global`, `text` and bounded array parameters. No raw pointer enters Omega. Public names are metadata and need not satisfy the seeded eight-character local-name limit. The generator owns header and ELF export-list emission; headers are generated, not hand-edited. All remaining NVML entry points in `compat/nvml/nvml.h` use these same constructs: status, nullable scalar in/out, fixed record out, counted record-array out, handle in/out and cstr return. Add `nullable inout uint32` for `infoCount` and `nullable out nvmlProcessInfo_t count infoCount commit 1` for `infos`. Read an inout value only when non-null. Preserve input/output on errors unless Omega's commit bit explicitly allows a write (notably the count on INSUFFICIENT_SIZE). 43 44 ### Explicit lowering contract 45 46 The bridge derives a bounded call frame from declarations. The implementation entry points use normal seeded signatures: 47 48 ```text 49 global NvState ulong 128 50 global NvBytes uchar 83296 51 global NvTexts uchar 2048 52 global NvReady uchar 32 53 54 note Frame for nv_init: [status, commit_bits], no output bytes. 55 fn nv_init frame edit ulong 2 to ulong 56 note BODY is the existing exercised protocol port, not a new C body. 57 end 58 59 note Frame for nv_count: [status, commit_bits, count]. present is 0 or 1. 60 fn nv_count present ulong frame edit ulong 3 to ulong 61 end 62 63 note Frame for nv_name: [device_index, present, length, status, commit_bits, bytes_to_copy]. 64 note bytes receives at most 6144 bytes. The state machine decides required length/error codes. 65 fn nv_name frame edit ulong 6 bytes edit uchar 6144 to ulong 66 end 67 68 note Frame for nv_error: [signed-code-bits, slot, string_length]. 69 note Writes/checks NvTexts/NvReady in Omega and returns success 0; slot 32 means fallback. 70 fn nv_error frame edit ulong 3 to ulong 71 end 72 ``` 73 74 These signature sketches deliberately omit bodies: the bridge owner must connect the exercised implementations, not commit these empty sketches. Return value 0 means the Omega protocol completed; a nonzero return or a compiler trap becomes the declared NVML trap status without process abort. The emitter's generated checked call uses the existing `omega_*` status convention underneath. Frames are private, initialized, and never exposed to the foreign caller. The generator must document and enforce field indices above so metadata and Omega implementation cannot disagree silently. 75 76 Nullable out pointers lower to a presence flag and scratch memory. They are never eagerly dereferenced and never converted to integer pointers inside Omega. Only declared commit bits permit publication. Required span/capacity checks and successful scalar narrowing precede *all* publication, preventing partially modified caller outputs on adapter failure. A `NULL` buffer with a nonzero length is passed as `present=0`, not dereferenced or given fake capacity. 77 78 Opaque handles are addresses of immutable library-issued table entries. The generated adapter compares pointer identity with table addresses without dereferencing foreign pointers. Unknown/NULL handles lower to UINT64_MAX; Omega decides the NVML return status. Handle outputs validate the returned index before publishing a table address. No arbitrary pointer arithmetic or dereference of an untrusted handle. 79 80 Process globals are zero-initialized once per loaded library and persist across calls. A generated process mutex serializes *all* entries sharing the state and string cache. Library unload follows normal dlclose caller obligations. Error strings live in process-global static storage and cannot be freed or reused; returned pointer identity stays stable across repeated calls, init/shutdown and other error-string requests. No per-call allocation is required. `pthread_mutex_t` is an explicit temporary host dependency, with exact libc/toolchain versions recorded by the consumer; the production replacement is an Omega process-lock host primitive. This proposal must not silently adopt it as Omega implementation. 81 82 ## Required generated C goldens 83 84 The following are expected output shapes, not handwritten source files to ship. Boilerplate helpers are generated once by the bridge. `nv_ok_status` checks the declared enum domain. `nv_handle_index` performs safe table-identity mapping. `omega_nv_*` denotes bridge-generated checked implementations of the seeded Omega entry points, including process-global storage. No call to the former handwritten `nvml_run` or `nvml_act` is permitted. 85 86 ```c 87 /* GENERATED by omega-bridge ; source SHA256 . */ 88 nvmlReturn_t nvmlDeviceGetCount_v2(unsigned int *deviceCount) { 89 uint64_t frame[3] = {999, 0, 0}, done = 1; 90 nvmlReturn_t result = NVML_ERROR_UNKNOWN; 91 if (pthread_mutex_lock(&NvLock) != 0) return result; 92 uint32_t st = omega_nv_count(&done, deviceCount != NULL, frame, 3); 93 if (st == OMEGA_OK && done == 0 && nv_ok_status(frame[0]) && 94 (frame[1] & ~UINT64_C(1)) == 0 && 95 (!(frame[1] & 1) || (deviceCount != NULL && frame[2] <= UINT32_MAX))) { 96 if (frame[1] & 1) *deviceCount = (unsigned int)frame[2]; 97 result = (nvmlReturn_t)frame[0]; 98 } 99 pthread_mutex_unlock(&NvLock); 100 return result; 101 } 102 103 nvmlReturn_t nvmlDeviceGetName(nvmlDevice_t device, char *name, unsigned int length) { 104 uint64_t frame[6] = {nv_handle_index(device), name != NULL, length, 999, 0, 0}; 105 uint8_t bytes[6144] = {0}; 106 uint64_t done = 1; 107 nvmlReturn_t result = NVML_ERROR_UNKNOWN; 108 if (pthread_mutex_lock(&NvLock) != 0) return result; 109 uint32_t st = omega_nv_name(&done, frame, 6, bytes, sizeof bytes); 110 if (st == OMEGA_OK && done == 0 && nv_ok_status(frame[3]) && 111 (frame[4] & ~UINT64_C(1)) == 0 && 112 (!(frame[4] & 1) || (frame[5] <= length && frame[5] <= sizeof bytes && 113 (frame[5] == 0 || name != NULL)))) { 114 if ((frame[4] & 1) && frame[5]) memcpy(name, bytes, (size_t)frame[5]); 115 result = (nvmlReturn_t)frame[3]; 116 } 117 pthread_mutex_unlock(&NvLock); 118 return result; 119 } 120 121 const char *nvmlErrorString(nvmlReturn_t code) { 122 uint64_t frame[3] = {(uint64_t)(int64_t)code, 32, 0}, done = 1; 123 const char *result = "Unknown Error"; 124 if (pthread_mutex_lock(&NvLock) != 0) return result; 125 uint32_t st = omega_nv_error(&done, frame, 3); 126 if (st == OMEGA_OK && done == 0 && frame[1] < 32 && frame[2] < 64 && 127 NvTexts[frame[1] * 64 + frame[2]] == 0) 128 result = (const char *)&NvTexts[frame[1] * 64]; 129 pthread_mutex_unlock(&NvLock); 130 return result; 131 } 132 ``` 133 134 This is the minimal readable golden, not a required inefficient code shape: do not zero the entire byte scratch if the checked Omega writer can establish the written range before publication. Preserve the semantics and bounds; use compiler lifetime/initialization analysis to avoid avoidable copies/initialization. `NvTexts` is generated static state and the checked Omega function must address that same object, not a duplicate array. All generated C exports have default visibility; all internal Omega/helper symbols are hidden. Emit a version script enumerating precisely the 11 symbols currently declared in the NVML header, and link with `-Wl,-soname,libnvidia-ml.so.1`. Reject duplicate/unknown symbols and any source drift against the manifest. The test checks the actual symbol list rather than trusting the link command. 135 136 ## Smallest acceptance and negative controls 137 138 1. Add a seeded `.om` bridge fixture defining the declarations and three complete functions for count/name/error-string, with no NVML RM access. Compile it with the pinned seeded compiler; emit C/header/export map twice and require byte equality and source/generator provenance. Build an isolated shared library with the exact soname and only declared exports. Verify metadata/exports using pinned readelf/nm as read-only oracles. 139 2. Use an Omega test driver to generate/build and invoke a generated foreign caller for the fixture. It must check null out-pointers, untouched error outputs, length-minus-one/exact/oversized buffers with sentinels, forged handles without dereference, signed negative enum inputs, repeated stable error-string pointers and process-state persistence. Emit the foreign caller through omega-bridge too; do not introduce a handwritten C driver. Until the callback/caller emitter exists, the existing CUDApp C caller remains an explicitly labelled ORACLE only. 140 3. Integrate the full API `.om` protocol against the existing RM fake. The generated .so/header must pass the original C-ABI ORACLE's 476 checks, the 55 CUDA-header ABI facts, compile against NVIDIA prototypes, and reject all 22 identical source mutants with identical failure/check counts. The same pure-Omega model must retain those counts. Run in a /dev-isolated CPU-only sandbox; no GPU is needed. 141 4. Mandatory generated-wrapper negative control: remove the `deviceCount != NULL` publication guard in a *generated-output copy* and force `commit_bits=1` with a null output. The subprocess must fail; a separate mutant suppressing the count publication with a non-null pointer must fail the observable count test without crashing. A surviving mutant makes the gate fail. Neither compiler failure nor exec failure counts as a caught behavioral mutant. 142 5. Declaration-refusal negative controls: undeclared global, duplicate export, unknown lock, invalid record offset/size, unsupported raw-pointer result, out-span lacking a length, and cstr offset/length outside the declared storage. Each must refuse before writing a usable .so; never silently generate a partial library. 143 6. Concurrency is a separate ABI gate: overlapping calls must preserve state and immutable string pointers; label NOT_RUN until a real generated concurrent caller is available. The previous 476 checks are not concurrency evidence. Live hardware is separately QUALIFIED only under an authorized GPU window. 144 145 ## Extension completion contract 146 147 The bridge owner returns the exact source revision, new emitter invocation and generated-artifact hashes; CUDApp repins it, removes `compat/nvml/cudapp_nvml.c`, removes the handwritten header in favor of the generated header, and rewires all library callers/build paths. Only then is the pure-Omega HOLD cleared. A compile-only implementation, three-entry fixture alone, stale generated code, or leaving nvml_run/nvml_act handwritten does not complete #365.