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
CUDApp / native / nvml / README.md
| 1 | <!-- SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception --> |
| 2 | # native/nvml: the Omega side of the CUDA++ NVML subset |
| 3 | |
| 4 | Two pure Omega units carry RM request/reply policy and error-string encoding. |
| 5 | `api.om` is the C ABI library unit: call orchestration, transport dispatch, copy |
| 6 | bounds, handle mapping, the string cache and the process lock. The omega-bridge#83 |
| 7 | emitter generates `compat/nvml/` from it; see `compat/nvml/README.md`. |
| 8 | |
| 9 | | Unit | Sources (composed in this order, each followed by a newline) | Export | |
| 10 | | --- | --- | --- | |
| 11 | | `nvml_step` | `nvml.om`, `query.om`, `step.om` | `omega_nvml_step(result, s[128 ulong], b[83296 uchar])` | |
| 12 | | `nvml_errstr` | `errstr.om` | `omega_nvml_errstr(result, code, o[64 uchar])` | |
| 13 | |
| 14 | `om/units.sh` lowers both through omega-bridge (`bridge-seeded`, pinned |
| 15 | omc e5b32567) into the committed `src/cudapp_om_nvml_step.c` and |
| 16 | `src/cudapp_om_nvml_errstr.c`; their prototypes are in `src/cudapp_native.h` |
| 17 | and their identities in `src/cudapp_om_nvml_*.ident` and |
| 18 | `src/cudapp_om_units.ident`. Never edit the generated C; edit the `.om` and |
| 19 | rerun `om/units.sh`. `tests/nvml/gate.om` refuses a stale generated file. |
| 20 | |
| 21 | ## The step protocol |
| 22 | |
| 23 | A pure unit cannot touch the OS, so `nvml_step` is a resumable state machine. |
| 24 | `api.om` stores the op (s0) and its arguments (s1..s4), then loops: |
| 25 | |
| 26 | 1. call `omega_nvml_step`; |
| 27 | 2. if s8 asks for an action (1 ioctl, 2 open, 3 close), perform exactly that |
| 28 | action through `omega2_nvrm_ioctl`, `omega2_nvrm_open_file` or |
| 29 | `omega2_nvrm_close_file` (`native/nvrm/transport.om`, aien-dev/CUDApp#281) |
| 30 | with the fd, nr, header length and params length the step chose, write the |
| 31 | transport result into s14 and its omega2 status into s15; |
| 32 | 3. stop when s8 is 0; s6 is the `nvmlReturn_t`, s7 the output bytes at OO, s5 |
| 33 | the scalar output and s27 whether to store it. |
| 34 | |
| 35 | The full slot map is the header comment of `nvml.om`. Transport results are a |
| 36 | `long` carried as its two's-complement bits in a ulong (−1 is 2^64−1). |
| 37 | |
| 38 | ## What each op asks the resource manager |
| 39 | |
| 40 | All layouts are cited in the sources to open-gpu-kernel-modules 580.173.02 |
| 41 | (commit 20e4e6e1), `src/common/sdk/nvidia/inc`. |
| 42 | |
| 43 | | NVML call | RM traffic | |
| 44 | | --- | --- | |
| 45 | | `nvmlInit_v2` (op 1) | open `/dev/nvidiactl`; `NV_ESC_CARD_INFO` (nr 200); root client (`NV01_ROOT_CLIENT`, nr 43); per GPU: `GET_ID_INFO_V2` (0x205), open `/dev/nvidia<minor>`, `NV_ESC_REGISTER_FD` (nr 201), device (0x80) and subdevice (0x2080) alloc, `CLASSLIST_V2` (0x800292) to find `BLACKWELL_COMPUTE_B` (0xCEC0). Reference counted. | |
| 46 | | `nvmlShutdown` (op 2) | last reference only: free subdevices, devices, the root client; close every fd. | |
| 47 | | `GetName` (op 5) | `GPU_GET_NAME_STRING` (0x20800110), ASCII flavour. | |
| 48 | | `GetUUID` (op 6) | `GPU_GET_GID_INFO` (0x2080014a), binary SHA-1 form, printed `GPU-8-4-4-4-12`. | |
| 49 | | `GetTemperature` (op 7) | two `THERMAL_SYSTEM_EXECUTE_V2` (0x20800513) passes: enumerate targets and sensors, then read the first sensor on a GPU-type target. | |
| 50 | | `GetMemoryInfo` (op 8) | `FB_GET_INFO_V2` (0x20801303): TOTAL_RAM_SIZE, HEAP_FREE (KiB), IS_ZERO_FB (NOT_SUPPORTED when set). | |
| 51 | | `GetUtilizationRates` (op 9) | `PERF_GET_GPUMON_PERFMON_UTIL_SAMPLES_V2` (0x20802096): newest sample of the 72-entry ring. | |
| 52 | | `GetComputeRunningProcesses_v3` (op 10) | `GPU_GET_PIDS` (0x2080018d) for class 0xCEC0, then `GPU_GET_PID_INFO` (0x2080018e) in chunks of at most 200 for video-memory usage. | |
| 53 | |
| 54 | Error policy (`nvml.om`): an omega2 status other than 0 is UNKNOWN; ioctl |
| 55 | EPERM/EACCES is NO_PERMISSION, other errnos UNKNOWN; open ENOENT/ENXIO/ENODEV |
| 56 | is DRIVER_NOT_LOADED; RM status 0x1B is NO_PERMISSION, 0x0F GPU_IS_LOST, |
| 57 | 0x56 NOT_SUPPORTED, anything else UNKNOWN. A failed `nvmlInit_v2` tears down |
| 58 | everything it opened and leaves the refcount at 0. |
| 59 | |
| 60 | ## Known limits |
| 61 | |
| 62 | - At most 8 GPUs; more is UNKNOWN at init. |
| 63 | - `GetUtilizationRates` sends 55888 bytes of params. The pinned omc e5b32567 |
| 64 | bounds program-mode `devcall` at 16383 bytes; whether the lowered #281 |
| 65 | transport can carry this control is NOT_RUN (live RM is not authorized). The |
| 66 | program-mode `cudapp-smi` needs aien-dev/omega-mv#1048 for the same control. |
| 67 | - A trap inside the teardown after a failed init can leave descriptors open; |
| 68 | the library then reports UNKNOWN. |
| 69 | - Live resource-manager behavior is NOT_RUN: every test runs against |
| 70 | `tests/nvml/rmfake.om`. |
| 71 | |
| 72 | Constants: `evidence/NVML-2026-11-06/wolfram.txt`. Tests: `tests/nvml/gate.om` |
| 73 | (`make test-nvml`). The 476 checks run twice: in `tests/nvml/host.om`, a pure |
| 74 | Omega port of the protocol, and through the generated `libnvidia-ml.so.1` with |
| 75 | the C caller `tests/nvml/nvml_test.c`; both against the fake transport. |