interplane.Get Omega
Read in your language

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

branch main Branches Tags History

CUDApp / nvrm / README.md

208 lines · 13687 bytes Raw Blame History Rendered
1# NVRM client: Omega boundary
2
3The library uses `nvrm/nvrm.c` through `m16/m16_native.c`. It talks directly
4to the pinned NVIDIA 580.173.02 open kernel ABI; it does not load libcuda.
5The 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
22The standalone `context.om` is not substituted for the library client: its
23singleton tables do not implement the library's independent contexts or its
244096 live allocations per context.
25
26`CUDAPP_MIGRATION_PENDING_C_NVRM=0` is the default. Request serialization and
27the actual open/close, RM/UVM ioctl, reserve/bind/map/drop operations are Omega.
28The checked native bridge calls the compiled transport, not a C syscall shim.
29Setting the switch to 1 retains the original C transport and C request
30construction as the differential oracle. The existing fake-driver fixture
31selects `CUDAPP_NVRM_TEST_TRANSPORT=1` explicitly to interpose its C syscall
32boundary while retaining Omega request construction. Defining `ioctl` or
33`mmap` macros alone never selects C; a separate link control checks that their
34forbidden symbol names are not referenced. Production has no fallback.
35High-level lifecycle policy and vendor class-specific parameter values still
36originate 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,
39counter and packet units. Set it to 1 only for the retained original C oracle.
40The free-range table is borrowed in place, with explicit layout assertions:
41no table copy or host allocation is introduced. C retains file reads, slot
42lock/CAS effects, error reporting and mapped-pointer construction. All four
43new entries are strong references; a missing entry fails to link. The public
44method-header signature and the #281 vendor header baseline are unchanged.
45Portable generation uses the existing `om/units.sh` digests, not the newer
46converter in an arbitrary bridge checkout.
47
48Each client owns a native mapping context with 4098 slots: 4096 live
49allocations, the usermode page and one transient reservation. Only an owned
50reservation can be replaced by a fixed mapping. A Linux bind failure retires
51the reservation; a trap does not prove retirement. Failed cleanup retains its
52token and quarantines its VA. Callers must serialize each complete
53reserve/bind/transfer/cleanup transaction, not only individual bridge calls.
54
55The hosted transport uses omega-bridge `689777c13b351b7450de1a2641cb4af9c97209ce`
56(draft #68, stacked on context draft #67 and device-word draft #66; the original
57function-mode device-word dependency was #29). It requires compiler drafts
58omega-mv #1043 and #1046. These dependencies need Drake's approval and merge;
59the existing host-x86 gate must be green before this client can merge.
60No live RM qualification is claimed by host serialization, real CPU mappings
61or fake-driver tests.
62
63Regenerate the hosted binding with `sh native/nvrm/units.sh`, separately from
64the portable wire units. It requires `OMEGA_NVRM_BRIDGE` at the revision and
65source/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
71superseded: they do not quarantine a failed bind whose cleanup also fails.
72The script invokes `tools/native --host` independently for each target and
73commits architecture-guarded payloads behind the same C ABI; instruction
74streams 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
79With `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
83bwrap --dev-bind / / --dev /dev --proc /proc -- taskset -c 10-14 nice -n 10 sh om/units.sh
84bwrap --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
85bwrap --dev-bind / / --dev /dev --proc /proc -- taskset -c 10-14 nice -n 10 ./build/test_nvrm_va_slots
86bwrap --dev-bind / / --dev /dev --proc /proc -- taskset -c 10-14 nice -n 10 make -j3 test-nvrm-alloc
87```
88
89The wire gate compares whole buffers, including padding, against independent
90vendored C structures with varying full-width scalar values and UUIDs. It
91checks fake replies with nonzero RM statuses, invalid operations, byte mutants,
92and a deliberately wrong serializer that must be rejected. UVM serialization
93covers INITIALIZE, MM_INITIALIZE, GPU/VA-space/channel register and unregister,
94external-range create, external-allocation map and free.
95The Ampere fake driver exercises allocation, control, mapping and cleanup
96without opening a GPU. These are **HOST_ONLY**, not chip receipts.
97`test-nvrm-differential` also compiles that lifecycle fixture with the retained
98C oracle explicitly enabled and compares its complete output with the Omega
99default; both binaries must satisfy the same internal assertions.
100
101The allocation gate compares exact operation results, active free ranges,
102counts, bump position, fault state and error text against the original C
103across seeded random alloc/free sequences and source-derived edge classes.
104It also covers recycled slots, method field spill/truncation edges, complete
105packet streams (including the maximum public word-count neighborhood),
106decimal overflow/sign/token classes, a changed-result red control, ten
107compiled source mutants and four missing-entry link controls.
108See `evidence/nvrm-alloc-20261106/README.md` for receipts and the unrun chip plan.
109
110The native fixture executes the compiled Omega syscall path. In a child only,
111a seccomp filter traps ioctl calls to deliberately unopened fd 12345. A SIGSYS
112oracle compares every request number and payload byte to the independent C
113vendor layout, injects nonzero status replies, and verifies RM parameter
114copyback. A wrong-request mutant must fail. No driver node is opened.
115Separate native tests exercise ordinary files, errno results, exact-VA
116reservation, failed-bind retirement, cleanup, all 4098 slots, independent
117contexts, stale/foreign handles, refusal to bind an existing data mapping, and
118the explicit envelope errors below. These are **HOST_ONLY**, not RM proofs.
119The cleanup fixture denies the first real `munmap` after a failed fixed bind.
120The caller must retain the quarantined owner, reject rebinding and destruction,
121and succeed when cleanup is retried. Only its child process installs the
122syscall filter; the second cleanup is forwarded to the real Linux syscall.
123
124## Native admission envelope and extension proposal
125
126There is no silent C fallback. The transport returns `-EFBIG` (Linux errno 27)
127before invoking mapping words when an extent exceeds 64 GiB or a fixed span
128would 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
130negative fixtures; zero extents are `EINVAL`. Positive fixtures reserve and
131release exactly 64 GiB of `PROT_NONE` VA and the final admissible page below
1321 TiB, without allocating backing memory. The compiler gate is unchanged.
133
134Source-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
146The largest head-shape allocation leaves 67696066560 bytes below the 64-GiB
147extent cap. Two 4-GiB context strides from the initial 64-GiB base leave
1481022202216448 bytes below 1 TiB before allocation-driven slot growth.
149As a deliberately conservative modeled bound, all model payloads plus the
15064-layer K/V maximum plus 4096 worst-case page-alignment gaps consume
15154652488544 bytes per context. Even two such clients plus two slot strides
152above the initial base leave 912897239360 bytes below 1 TiB. This is not a
153complete measured serving allocation trace or an unlimited-context guarantee.
154Existing arbitrary external callers can exceed the envelope and are refused.
155
156WolframLanguageEvaluator 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
173Concrete compiler extension proposal, **PROPOSED, not implemented**: admit a
174configurable fixed-VA ceiling up to the architecture's canonical 47-bit user
175range, or raise the current fixed-span cap after an explicit safety review.
176Retain checked nonwrapping address-plus-length arithmetic, page alignment,
177`MAP_FIXED_NOREPLACE` plus returned-address verification, the 64-GiB
178per-extent bound unless separately justified, and ownership-checked whole-
179reservation-only `MAP_FIXED`. Test both sides of every ceiling, occupied and
180adjacent spans, stale/foreign tokens, failed-bind retirement and unchanged
181neighbor mappings. Do not conflate a larger admitted virtual range with
182physical-memory availability, device addressability or hardware qualification.
183
184## Live RM runbook — NOT_RUN
185
186Only Drake's current exclusive-window authorization permits these commands.
187Do not acquire or modify the GPU lock, stop a service or open `/dev/nvidia*`
188outside that procedure. First resolve omega-bridge#29 and record the exact
189compiler/bridge identities used to regenerate and link the native transport.
190
191In the authorized window, use `AGENTS.md` and the existing lifecycle and M16
192qualification procedures, with a separate new output directory; never replace
193historical `evidence/` receipts:
194
195```sh
196taskset -c 10-14 nice -n 10 env CUDAPP_MIGRATION_PENDING_C_NVRM=0 bash tests/run_nvrm_lifecycle_gates.sh
197taskset -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```
199These scripts must be run according to their documented GPU-window and
200receipt-durability preconditions. Run the same lifecycle workload with a
201separately built `CUDAPP_MIGRATION_PENDING_C_NVRM=1` oracle, recording the build
202flags, compiler identity, RM statuses and allocation/free accounting. Compare
203request bytes before calling the kernel; pointer fields must name the same
204parameter span, not a fabricated fixed address. Include injected UVM-free and
205RM-free failures, stale/duplicate frees, independent concurrent contexts and
206mapping-capacity exhaustion. A negative control must fail rather than be
207reported as a clean teardown. Preserve uncertain cleanup state and quarantine
208its VA. Report the live tier **NOT_RUN** until a new authorized receipt exists.