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/nvrm/README.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 / nvrm / README.md` 208 lines · 13687 bytes Raw Blame History Rendered 1 # NVRM client: Omega boundary 2 3 The library uses `nvrm/nvrm.c` through `m16/m16_native.c`. It talks directly 4 to the pinned NVIDIA 580.173.02 open kernel ABI; it does not load libcuda. 5 The proprietary kernel/module replacement is not part of this client change. 6 7 ## Source map 8 9 | Responsibility | Source | 10 | --- | --- | 11 | Lifecycle effects, VA slot atomics, quarantine and channel policy | `nvrm/nvrm.c`, `nvrm/nvrm.h` | 12 | Library adapter and completion waits | `m16/m16_native.c`, `m16/m16_gpu_wait.c` | 13 | NVOS21, NVOS54, NVOS00, NVOS33+fd, NVOS46, NVOS47, register-fd bytes and reply decoding | `native/nvrm/wire.om`, `wire_pack.om` | 14 | NVOS32 heap-information request bytes | `native/nvrm/heap_wire.om` | 15 | All UVM requests used by this client, including the complete external-allocation attribute array | `native/nvrm/uvm_wire.om`, `uvm_map_wire.om` | 16 | Checked file, RM, UVM and owned mapping operations | `native/nvrm/transport.om`, generated `src/cudapp_om_nvrm_transport.c` | 17 | Earlier standalone program-mode context, with its own smaller resource tables | `native/nvrm/context.om` | 18 | VA first-fit/split/coalesce, recycled-slot stack and counter successor | `native/nvrm/alloc.om`, `alloc_scalar.om` | 19 | `/proc` decimal parsing and counter reductions; method-header encoding | `native/nvrm/counts.om`, `alloc_scalar.om` | 20 | Ampere packet envelope validation, composed with existing method/class admission | `native/nvrm/alloc_push.om`, `om/encoder/amp_runtime.om` | 21 22 The standalone `context.om` is not substituted for the library client: its 23 singleton tables do not implement the library's independent contexts or its 24 4096 live allocations per context. 25 26 `CUDAPP_MIGRATION_PENDING_C_NVRM=0` is the default. Request serialization and 27 the actual open/close, RM/UVM ioctl, reserve/bind/map/drop operations are Omega. 28 The checked native bridge calls the compiled transport, not a C syscall shim. 29 Setting the switch to 1 retains the original C transport and C request 30 construction as the differential oracle. The existing fake-driver fixture 31 selects `CUDAPP_NVRM_TEST_TRANSPORT=1` explicitly to interpose its C syscall 32 boundary while retaining Omega request construction. Defining `ioctl` or 33 `mmap` macros alone never selects C; a separate link control checks that their 34 forbidden symbol names are not referenced. Production has no fallback. 35 High-level lifecycle policy and vendor class-specific parameter values still 36 originate in C; this is not a claim that every line of the library is Omega. 37 38 `CUDAPP_MIGRATION_PENDING_C_NVRM_ALLOC=0` selects the seeded allocation, 39 counter and packet units. Set it to 1 only for the retained original C oracle. 40 The free-range table is borrowed in place, with explicit layout assertions: 41 no table copy or host allocation is introduced. C retains file reads, slot 42 lock/CAS effects, error reporting and mapped-pointer construction. All four 43 new entries are strong references; a missing entry fails to link. The public 44 method-header signature and the #281 vendor header baseline are unchanged. 45 Portable generation uses the existing `om/units.sh` digests, not the newer 46 converter in an arbitrary bridge checkout. 47 48 Each client owns a native mapping context with 4098 slots: 4096 live 49 allocations, the usermode page and one transient reservation. Only an owned 50 reservation can be replaced by a fixed mapping. A Linux bind failure retires 51 the reservation; a trap does not prove retirement. Failed cleanup retains its 52 token and quarantines its VA. Callers must serialize each complete 53 reserve/bind/transfer/cleanup transaction, not only individual bridge calls. 54 55 The hosted transport uses omega-bridge ``689777c13b351b7450de1a2641cb4af9c97209ce`` 56 (draft #68, stacked on context draft #67 and device-word draft #66; the original 57 function-mode device-word dependency was #29). It requires compiler drafts 58 omega-mv #1043 and #1046. These dependencies need Drake's approval and merge; 59 the existing host-x86 gate must be green before this client can merge. 60 No live RM qualification is claimed by host serialization, real CPU mappings 61 or fake-driver tests. 62 63 Regenerate the hosted binding with `sh native/nvrm/units.sh`, separately from 64 the portable wire units. It requires `OMEGA_NVRM_BRIDGE` at the revision and 65 source/tool digests recorded in `src/cudapp_om_nvrm_transport.ident`, 66 `OMEGA_NATIVE_OMC` at ``734f0a39319fbfa930bcc62cb30dbf06d47d78e126372b74f5baf478e6126b61``, 67 `OMEGA_NATIVE_OMC2` at ``d1a3047153e14676c4baf9248fa2b88bb1b68c37cfeb71d76f30f5230c7d2765`` 68 (omega-mv ``ce35b351``, pending #1043), and `OMEGA_NATIVE_X86_OMC` at 69 ``cf4fcbbb4752c5dd0652b426c0f2d08f82e380e8fc6f5114acf51a4c077bb579`` 70 (omega-mv ``6f60fec9``, pending #1046). Old ``68a5d7fa`` context binaries are 71 superseded: they do not quarantine a failed bind whose cleanup also fails. 72 The script invokes `tools/native --host` independently for each target and 73 commits architecture-guarded payloads behind the same C ABI; instruction 74 streams are never mixed in one generation. Set `OMEGA_NVRM_CC_AARCH64` and 75 `OMEGA_NVRM_CC_X86` to the respective C compilers when the defaults do not fit. 76 77 ## Host gates 78 79 With `OMEGA_OMC`, `OMEGA_BRIDGE` and `OMEGA_SEED` set to the pinned toolchain 80 (`OMEGA_SEED` is the baseline compiler required by existing freest units): 81 82 ```sh 83 bwrap --dev-bind / / --dev /dev --proc /proc -- taskset -c 10-14 nice -n 10 sh om/units.sh 84 bwrap --dev-bind / / --dev /dev --proc /proc -- taskset -c 10-14 nice -n 10 make -j3 test-nvrm-wire test-nvrm-native test-nvrm-boundary test-nvrm-differential test-nvrm-struct test-ampere-runtime test-streams-submit build/test_nvrm_va_slots 85 bwrap --dev-bind / / --dev /dev --proc /proc -- taskset -c 10-14 nice -n 10 ./build/test_nvrm_va_slots 86 bwrap --dev-bind / / --dev /dev --proc /proc -- taskset -c 10-14 nice -n 10 make -j3 test-nvrm-alloc 87 ``` 88 89 The wire gate compares whole buffers, including padding, against independent 90 vendored C structures with varying full-width scalar values and UUIDs. It 91 checks fake replies with nonzero RM statuses, invalid operations, byte mutants, 92 and a deliberately wrong serializer that must be rejected. UVM serialization 93 covers INITIALIZE, MM_INITIALIZE, GPU/VA-space/channel register and unregister, 94 external-range create, external-allocation map and free. 95 The Ampere fake driver exercises allocation, control, mapping and cleanup 96 without opening a GPU. These are **HOST_ONLY**, not chip receipts. 97 `test-nvrm-differential` also compiles that lifecycle fixture with the retained 98 C oracle explicitly enabled and compares its complete output with the Omega 99 default; both binaries must satisfy the same internal assertions. 100 101 The allocation gate compares exact operation results, active free ranges, 102 counts, bump position, fault state and error text against the original C 103 across seeded random alloc/free sequences and source-derived edge classes. 104 It also covers recycled slots, method field spill/truncation edges, complete 105 packet streams (including the maximum public word-count neighborhood), 106 decimal overflow/sign/token classes, a changed-result red control, ten 107 compiled source mutants and four missing-entry link controls. 108 See `evidence/nvrm-alloc-`20261106`/README.md` for receipts and the unrun chip plan. 109 110 The native fixture executes the compiled Omega syscall path. In a child only, 111 a seccomp filter traps ioctl calls to deliberately unopened fd 12345. A SIGSYS 112 oracle compares every request number and payload byte to the independent C 113 vendor layout, injects nonzero status replies, and verifies RM parameter 114 copyback. A wrong-request mutant must fail. No driver node is opened. 115 Separate native tests exercise ordinary files, errno results, exact-VA 116 reservation, failed-bind retirement, cleanup, all 4098 slots, independent 117 contexts, stale/foreign handles, refusal to bind an existing data mapping, and 118 the explicit envelope errors below. These are **HOST_ONLY**, not RM proofs. 119 The cleanup fixture denies the first real `munmap` after a failed fixed bind. 120 The caller must retain the quarantined owner, reject rebinding and destruction, 121 and succeed when cleanup is retried. Only its child process installs the 122 syscall filter; the second cleanup is forwarded to the real Linux syscall. 123 124 ## Native admission envelope and extension proposal 125 126 There is no silent C fallback. The transport returns `-EFBIG` (Linux errno 27) 127 before invoking mapping words when an extent exceeds 64 GiB or a fixed span 128 would leave the existing below-1-TiB range. The C ABI returns `-1` with 129 `errno=EFBIG`. Oversized extents, high addresses and an end-crossing range are 130 negative fixtures; zero extents are `EINVAL`. Positive fixtures reserve and 131 release exactly 64 GiB of `PROT_NONE` VA and the final admissible page below 132 1 TiB, without allocating backing memory. The compiler gate is unchanged. 133 134 Source-backed workload bounds, not live measurements: 135 136 | Workload | Bytes / bound | Source | 137 | --- | ---: | --- | 138 | Largest actual FP8-`95a723d0` model tensor, BF16 embed/lm_head `[248320,2048]` | `1017118720` | Local pinned model `outside.safetensors` headers | 139 | Larger in-tree head shape `[249856,2048]`, BF16 | `1023410176` | `tests/gpu_bf16_gemv_test.c:98` | 140 | All 64196 model tensor payloads, including vision/MTP | `37454789472` | Byte-offset bookkeeping over the pinned safetensors headers | 141 | Q36 K/V allocation per layer at the admitted maximum 131072 positions | `268451968` | `src/omega_gpu_decode_attn256_api.c:92-96`, shape 2 KV heads, row 512 bytes, slack from `omega_blackwell_codegen_attn256.h:61` | 142 | Actual 40-layer model's 10 full-attention K/V allocations | `2684519680` | Pinned model `config.json` layer types | 143 | Conservative 64-layer API maximum K/V payload | `17180925952` | `src/omega_gpu_decode_attn256_api.h:51-52`; separate allocations, not one extent | 144 | Explicitly simultaneous in-tree RM contexts | 2 | `m16/m16_concurrent.c:131,139`; the serving session is a singleton (`src/omega_gpu_session.c:363-365`) | 145 146 The largest head-shape allocation leaves `67696066560` bytes below the 64-GiB 147 extent cap. Two 4-GiB context strides from the initial 64-GiB base leave 148 `1022202216448` bytes below 1 TiB before allocation-driven slot growth. 149 As a deliberately conservative modeled bound, all model payloads plus the 150 64-layer K/V maximum plus 4096 worst-case page-alignment gaps consume 151 `54652488544` bytes per context. Even two such clients plus two slot strides 152 above the initial base leave `912897239360` bytes below 1 TiB. This is not a 153 complete measured serving allocation trace or an unlimited-context guarantee. 154 Existing arbitrary external callers can exceed the envelope and are refused. 155 156 WolframLanguageEvaluator queries (results in bytes except context counts): 157 158 ```text 159 {248320*2048*2,249856*2048*2,256*1024*2048, 160 2*(2*131072*512+(4*4*512+64)),2*(4*131072*512+(4*4*512+64)), 161 64*2*(2*131072*512+(4*4*512+64)),2^36-248320*2048*2, 162 2^36-249856*2048*2,2^36-2*(2*131072*512+(4*4*512+64)), 163 2^40-(16*2^32+2*2^32),2^40/2^32,Floor[(2^40-16*2^32)/2^32]} 164 -> {`1017118720`,`1023410176`,`536870912`,`268451968`,`536887424`,`17180925952`, 165 `67702358016`,`67696066560`,`68451024768`,`1022202216448`,256,240} 166 {10*2*(2*131072*512+(4*4*512+64)), 167 `37454789472`+64*2*(2*131072*512+(4*4*512+64))+4096*4095, 168 2^40-(16*2^32+2*(`37454789472`+64*2*(2*131072*512+(4*4*512+64))+4096*4095)+2*2^32), 169 2^36-`37454789472`,2^40-(16*2^32+2*2^32)} 170 -> {`2684519680`,`54652488544`,`912897239360`,`31264687264`,`1022202216448`} 171 ``` 172 173 Concrete compiler extension proposal, **PROPOSED, not implemented**: admit a 174 configurable fixed-VA ceiling up to the architecture's canonical 47-bit user 175 range, or raise the current fixed-span cap after an explicit safety review. 176 Retain checked nonwrapping address-plus-length arithmetic, page alignment, 177 `MAP_FIXED_NOREPLACE` plus returned-address verification, the 64-GiB 178 per-extent bound unless separately justified, and ownership-checked whole- 179 reservation-only `MAP_FIXED`. Test both sides of every ceiling, occupied and 180 adjacent spans, stale/foreign tokens, failed-bind retirement and unchanged 181 neighbor mappings. Do not conflate a larger admitted virtual range with 182 physical-memory availability, device addressability or hardware qualification. 183 184 ## Live RM runbook — NOT_RUN 185 186 Only Drake's current exclusive-window authorization permits these commands. 187 Do not acquire or modify the GPU lock, stop a service or open `/dev/nvidia*` 188 outside that procedure. First resolve omega-bridge#29 and record the exact 189 compiler/bridge identities used to regenerate and link the native transport. 190 191 In the authorized window, use `AGENTS.md` and the existing lifecycle and M16 192 qualification procedures, with a separate new output directory; never replace 193 historical `evidence/` receipts: 194 195 ```sh 196 taskset -c 10-14 nice -n 10 env CUDAPP_MIGRATION_PENDING_C_NVRM=0 bash tests/run_nvrm_lifecycle_gates.sh 197 taskset -c 10-14 nice -n 10 env EVIDENCE_DIR=/path/to/new-window/omega RECEIPT_FILE=/path/to/new-window/omega-receipt.json CUDAPP_MIGRATION_PENDING_C_NVRM=0 bash tests/run_m16_requalification.sh 198 ``` 199 These scripts must be run according to their documented GPU-window and 200 receipt-durability preconditions. Run the same lifecycle workload with a 201 separately built `CUDAPP_MIGRATION_PENDING_C_NVRM=1` oracle, recording the build 202 flags, compiler identity, RM statuses and allocation/free accounting. Compare 203 request bytes before calling the kernel; pointer fields must name the same 204 parameter span, not a fabricated fixed address. Include injected UVM-free and 205 RM-free failures, stale/duplicate frees, independent concurrent contexts and 206 mapping-capacity exhaustion. A negative control must fail rather than be 207 reported as a clean teardown. Preserve uncertain cleanup state and quarantine 208 its VA. Report the live tier **NOT_RUN** until a new authorized receipt exists.