interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / docs / numeric / OMEGA_GPU_NATIVE_BOUNDARY.md

284 lines · 20986 bytes Raw Blame History Rendered
1# Omega GPU native boundary: dependency map and freestanding link target
2
3Native v1 P07 cut A, A.2 and the session part of cut C (omega#419 for A.2,
4omega#421 for cut C session part). Tracks aienos#286 and aien-architecture#190.
5Companion of `docs/numeric/OMEGA_GPU_ENGINE.md` (the engine contract) and
6`src/omega_gpu_platform.h` (the platform contract this cut adds).
7
8Status words used here: DONE (host evidence in this repo's CI), NOT_RUN (no
9evidence; needs the physical Spark in an attended window), PLANNED (a later
10cut). NOT_RUN is never PASS.
11
12## 1. What this cut claims, and what it does not
13
14Claimed (host evidence, `make test-gpu-engine-freestanding`):
15
16- Eight files of the first-compute path build with `-ffreestanding -fno-builtin`
17 and `OMEGA_GPU_NO_POSIX`, and their partial link leaves only `memcpy`,
18 `memset`, `strcmp` and `strlen` undefined: `src/omega_gpu_engine.c`,
19 `src/omega_gpu_platform.c`, `src/omega_blackwell_encoder.c`,
20 `src/omega_blackwell_codegen.c` and `src/omega_blackwell_matmul.c` (cut A.2),
21 `src/omega_blackwell_qmd.c`, `src/omega_blackwell_realize.c`, and the SHA-256
22 (`src/sha256.c` at cut A; since the OM-2 cutover #747 the freestanding binding
23 `src/omega_om_units_fs.c` that `om/units.sh` generates from `om/sha256/sha256-om2.om`,
24 `make test-sha256-freestanding-parity`).
25 No Linux header, no `errno`, no `clock_gettime`, no `printf`, no `malloc`,
26 no `pthread_*`, no `nvrm_*`, no `m16_*`. The make target fails on any other
27 undefined symbol.
28- The engine contract test (`tests/test_omega_gpu_engine.c`, 50 cases) passes
29 linked against the freestanding engine object, with one added case: with no
30 platform clock installed, every job is refused at `STEP_CLOCK_CHECK` before
31 any backend call.
32- The platform contract (`src/omega_gpu_platform.h`) has a test
33 (`tests/test_omega_gpu_platform.c`, 7 cases in ABI 1.1) reaching every refusal name.
34- The engine mutation sweep still kills all 49 mutants (`make test-gpu-engine-mutants`).
35- Cut A.2 (`make test-codegen-freestanding`): code generation runs without an
36 allocator. The caller supplies the code buffer and its capacity
37 (`omega_blackwell_kernel_encode_into`); a buffer one byte short, of size 0 or
38 NULL is refused before any byte is written, and nothing is written past the
39 reported code size. The hosted allocating generators keep their names and
40 caps and encode through the same function. The instruction streams of 14
41 fixtures (integer, K=16 tensor, looped, decode fragment and blocked prefill
42 kernels; 24,448 code bytes) are byte-identical between the hosted and the
43 freestanding build (`cmp` of the two dumps). The golden-word fixture
44 verifiers pass on the freestanding object. The freestanding
45 `omega_fp32_to_bf16` rounds in integer form (the `__bf16` cast needs libgcc
46 `__truncsfbf2`) and equals the hosted cast on all 2^32 inputs. A control
47 links a `malloc` caller into the freestanding object and requires the `nm -u`
48 check to refuse it.
49- Cut C, session part (`make test-gpu-session-platform`): the persistent GPU
50 session, the serving allocator and the matmul and attention tensor APIs run
51 over `OmegaGpuPlatform` (ABI 1.1) instead of calling `physics/nvrm` and
52 `physics/m16` directly. The freestanding closure grows from 8 to 14 files:
53 `src/omega_gpu_session.c`, `src/omega_gpu_serving.c`,
54 `src/omega_gpu_matmul_api.c`, `src/omega_gpu_attention_api.c`,
55 `src/omega_gpu_wait.c` and the new bounded formatter `src/omega_gpu_fmt.c`
56 (the session's only text path; it replaces `snprintf`/`strncpy` and a test
57 compares it to `snprintf` on every format the session uses). The partial link
58 still leaves only `memcpy`, `memset`, `strcmp` and `strlen` undefined.
59 - Typed resources: every session buffer is an `OmegaGpuMem` carrying an
60 `OmegaGpuBufferHandle` (index + generation), its kind (DATA, CODE, QUEUE),
61 CPU view, GPU VA and size. `omega_gpu_session.h` no longer names `NvrmMem`.
62 - Same allocations as before, in the same order and sizes (ring, marker,
63 method block, scratch), all GPU-uncached; the marker is `HOST_POLLED`. The
64 GB10 completion-flag rule (section 2) is enforced by the platform check,
65 not by convention.
66 - Completion is polling and says so: `OmegaGpuPlatform.poll_word` (renamed
67 from `wait_word`), `omega_gpu_session_completion_mode()` returns
68 `OMEGA_GPU_COMPLETION_POLLING`, and neither the session nor the Linux
69 reference claims `OMEGA_GPU_SVC_IRQ`.
70 - Cancel, timeout and uncertain completion: a cancel before submit refuses
71 with nothing in flight and no latch; a cancel or timeout after the doorbell
72 latches the session as uncertain and parks (never frees) every buffer the
73 device may still touch; a free of a latched buffer parks it; close, reopen
74 and platform install are refused while latched. Parked bytes and counts are
75 reported.
76 - Stale handles: after close and reopen, a handle from the earlier
77 incarnation is refused and counted (`stale_refusals`), never reused.
78 - Explicit visibility: the old `dsb` barriers become
79 `omega_gpu_session_sync_to_gpu` / `sync_to_cpu` calls on named buffers.
80 - The Linux driver path is a separate reference implementation,
81 `src/omega_gpu_platform_linux.c` (reference only, hosted only, excluded from
82 the freestanding closure, with its own test
83 `tests/test_omega_gpu_platform_linux.c`, 6 cases including "same driver
84 calls in the same order as before"). Hosted builds install it by default;
85 the freestanding build has no default platform and refuses until one is
86 installed.
87 - Tests: session platform 13 of 13 cases (fork-isolated), Linux reference 6
88 of 6, six session mutants all killed (`make test-gpu-session-mutants`),
89 serving-alloc output byte-identical to main in all six modes apart from
90 test line numbers, matmul-api host-only 171/0, attention host-only 107/0
91 and simulator 219/0, engine 50/0, platform 7/0.
92
93Not claimed:
94
95- No whole-project independence from Linux. Section 3 lists every file that
96 still calls the Linux RM/UVM driver through `physics/nvrm` and `physics/m16`,
97 and which cut migrates it.
98- No device ownership. Nothing in this cut opens, discovers, maps or resets a
99 GPU. Device discovery, bounded MMIO/DMA/IRQ ownership and the SMMU path are
100 cut B, and their evidence is NOT_RUN until an attended hardware window
101 (native v1 gate N4; the B7b one-page SMMU probe is not GPU compute).
102- No native GPU backend yet. Cut C's session part moves the dependency onto
103 `OmegaGpuPlatform`; the only platform that drives a real GB10 today is the
104 Linux reference. Native GB10 execution through any of this is NOT_RUN.
105- The elementwise API, the numeric launchers, the vector executor and the
106 resident runtime still depend on Linux (section 3).
107- No production use of the test-only hooks. `omega_gpu_engine_test_set_clock`
108 remains test-only; the production time service is
109 `omega_gpu_engine_set_clock`, which the native platform calls once at init.
110
111## 2. Driver-provided responsibilities: who owns each today and later
112
113Today every row is served by the Linux RM/UVM driver (nvidia-open 580.173.02)
114through `physics/nvrm/nvrm.c` and `physics/m16/m16_native.c`, called from the
115files in section 3.
116
117| Responsibility | Linux path today | Native owner | Cut | Status |
118|---|---|---|---|---|
119| Device discovery, bounded ownership (MMIO/DMA/IRQ capabilities) | RM device open (`nvrm_open`, `m16_native_open`) | Aienux PCI/SMMU layer + `OmegaGpuPlatform` MMIO/DMA services | B | NOT_RUN |
120| Device and firmware initialization (GSP, falcons) | RM boot inside the kernel module | Aienux GB10 firmware lifecycle (P08) | B/P08 | NOT_RUN |
121| Context / address space creation | RM client + VA space objects (`nvrm_mthd`) | native context object behind `OmegaGpuDeviceHandle` | B | NOT_RUN |
122| Memory allocation with cache attributes | `nvrm_alloc`, `nvrm_alloc_gpu_uncached` | `OmegaGpuPlatform.dma_alloc` with `OmegaGpuBufferDesc` (kind, rights, cache policy) | B | contract DONE, device NOT_RUN |
123| GPU page tables / mapping | UVM + RM map | Aienux page tables, GPU VA through `OmegaGpuVa` | B | NOT_RUN |
124| Bus addresses / SMMU translation | kernel DMA API inside RM | Aienux SMMU, `OmegaGpuBusAddr` (no raw physical address type exists) | B | NOT_RUN |
125| Channel / queue creation (GPFIFO, USERD) | `m16_native_create_channel`, `nvrm_channel` | native queue behind `OmegaGpuQueueHandle`, ring is a `BUF_QUEUE` buffer | B/C | NOT_RUN |
126| Submit token / doorbell | `m16_native_submit_methods`, `nvrm_enqueue`, `nvrm_ring` | `OmegaGpuPlatform.mmio_write32` on the doorbell region | C | NOT_RUN |
127| Completion (marker words, semaphores) | `m16_native_wait_marker*`, host polling | `OmegaGpuPlatform.poll_word` (polling, ABI 1.1) on a HOST_POLLED, GPU-uncached buffer | C | contract and session DONE (cut C), device NOT_RUN |
128| Interrupts | RM interrupt handling (not used by Omega's launchers: they poll) | `OMEGA_GPU_SVC_IRQ` only when a real interrupt wait exists; polling never claims it | B | NOT_RUN |
129| Visibility / cache maintenance | L2 flush mem-op + uncached marker (C3 block) | `OmegaGpuPlatform.sync_*` plus the same mem-op sequence in the encoder | C | NOT_RUN |
130| Time, waiting, locking | `clock_gettime`, `usleep`, pthread | `OmegaGpuPlatform.time_now_ms`, `wait_ms`, `lock`/`unlock` | A (contract) | DONE |
131| Reset / recovery of a hung device | RM channel teardown, process exit | native quiesce path (P03 lifecycle), no `ck_reset`-style shortcut | P08 | NOT_RUN |
132| Resource numbering across incarnations | per-process RM handles | aienos#285 resource incarnations, before any domain-1 number is persisted | P05/#285 | PLANNED |
133
134Rule carried over from the 2026-10-02 E1 stall: anything the CPU polls for a
135device write is `OMEGA_GPU_RIGHT_HOST_POLLED` and must be
136`OMEGA_GPU_CACHE_GPU_UNCACHED`. Source: nvidia-open 580.173.02
137`src/common/sdk/nvidia/inc/nvos.h`, `NVOS32_ATTR2_GPU_CACHEABLE_YES`: "For
138system memory this will not be coherent with direct CPU mappings." The
139platform contract refuses a cached host-polled buffer
140(`OMEGA_GPU_PLAT_REFUSED_CACHE_POLICY`).
141
142## 3. File inventory: Linux driver and libc dependencies, migrating cut
143
144Counts are `grep -c` of `nvrm_` and `m16_` on 2026-10-12 at omega main
145536870f1. "Linux headers" lists hosted headers the file includes. "Cut" is
146where the file stops depending on them. "Host tooling" means the file is
147development-host measurement or gating and is not part of the native product
148(the plan separates development hosts from the delivered runtime).
149
150| File | nvrm_ | m16_ | Linux headers | Cut | Note |
151|---|---|---|---|---|---|
152| `src/omega_gpu_engine.c` | 0 | 0 | none (errno/time only on the host build) | A | DONE: `OMEGA_GPU_NO_POSIX` build, clock refusal |
153| `src/omega_gpu_platform.c` | 0 | 0 | none | A | DONE: new, contract checks and handle table |
154| `src/omega_blackwell_encoder.c` | 0 | 0 | none (stdio removed in A) | A | DONE |
155| `src/omega_blackwell_qmd.c` | 0 | 0 | none | A | DONE |
156| `src/omega_blackwell_realize.c` | 0 | 0 | none | A | DONE |
157| `src/omega_om_units_fs.c` | 0 | 0 | none (generated, freestanding OM-2 binding) | A | DONE: replaces `src/sha256.c`; the hosted binding `src/omega_om_units.c` needs pthread TLS, mmap and abort and stays out of the link |
158| `src/omega_blackwell_codegen.c` | 0 | 0 | none in the freestanding build (stdio, stdlib only in the hosted build) | A.2 | DONE: caller-provided code buffer (`omega_blackwell_kernel_encode_into`); allocating generators, diagnostics and the printing variation self-test are hosted only |
159| `src/omega_blackwell_matmul.c` | 0 | 0 | none in the freestanding build (stdlib only in the hosted build) | A.2 | DONE: `omega_blackwell_kernel_free` and the dispatcher hosted only; integer bf16 rounding in the freestanding build |
160| `src/omega_gpu_wait.c` | 0 | 0 | none in the freestanding build (time only in the hosted build) | C | DONE (session part): freestanding has no default clock and refuses without `cfg->now_ns` |
161| `src/omega_gpu_serving.c` | 0 | 0 | none | C | DONE (session part): in the freestanding closure |
162| `src/omega_gpu_matmul_api.c` | 0 | 0 | none (string.h only for mem*/str*) | C | DONE (session part): host memory and clock from the session, code encoded in place into a CODE buffer, explicit sync calls |
163| `src/omega_gpu_attention_api.c` | 0 | 0 | none (stdio only under `OMEGA_ATTN_DEBUG`) | C | DONE (session part): same as matmul API |
164| `src/omega_gpu_session.c` | 0 | 0 | none in the freestanding build (pthread only for the hosted default install) | C | DONE (session part): every device call through `OmegaGpuPlatform` ABI 1.1; header names `OmegaGpuMem`, not `NvrmMem` |
165| `src/omega_gpu_fmt.c` | 0 | 0 | none (stdarg) | C | new: bounded formatter for session and API text |
166| `src/omega_gpu_platform_linux.c` | 13 | 15 | pthread, stdio, stdlib, time | reference only | new: the Linux RM/UVM implementation of `OmegaGpuPlatform`, hosted only, never in the freestanding closure; its own test |
167| `src/omega_gpu_elementwise_api.c` | 0 | 0 | stdio, stdlib, time | C (later part) | uses `OmegaGpuMem` from the session; still hosted |
168| `src/omega_blackwell_engine.c` | 19 | 13 | errno, stdio, time | stays Linux-private | the Linux backend of `OmegaGpuBackend`; a sibling native backend over `OmegaGpuPlatform` arrives in B/C |
169| `src/omega_numeric_gb10.c` | 21 | 2 | stdio, stdlib, errno, time | C/D | numeric launchers follow the engine Phase B order |
170| `src/omega_numeric_divsqrt_gb10.c` | 20 | 2 | stdio, stdlib, errno, time | C/D | same |
171| `src/omega_numeric_reduce_gb10.c` | 17 | 2 | stdio, stdlib, errno, time | C/D | same |
172| `src/omega_numeric_ldst_gb10.c` | 16 | 2 | stdio, stdlib | C/D | same |
173| `src/omega_blackwell_submit.c` | 41 | 34 | stdio, stdlib, time, unistd | D | vector executor; sha256-pinned by the M17/M18 gates, re-sealed on chip |
174| `src/runtime/rx_resident_gpu.c` | 18 | 9 | pthread, stdio, stdlib, unistd | D | resident runtime seat |
175| `src/omega_world_gates.c` | 60 | 2 | stdio, stdlib, time, unistd | host tooling | gates and measurement, stays on Linux |
176| `src/omega_accelerator_world.c` | 38 | 9 | stdio, stdlib, time, unistd, sys/mman | host tooling | stays on Linux |
177| `src/omega_blackwell_gates.c` | 0 | 1 | stdio, stdlib, time | host tooling | stays on Linux |
178
179Headers that still expose a Linux driver type and must lose it before the cut
180that migrates their users: `src/omega_numeric_native.h` (C/D), `src/forge_realization.h`,
181`src/omega_evidence.h`, `src/omega_accelerator_world.h`,
182`src/omega_physics_dir.h` (host tooling; they keep it). `src/omega_gpu_session.h` lost `NvrmMem` in cut C (session part).
183
184Distinct driver entry points in use (count of call sites, same snapshot):
185`nvrm_mthd` 188, `m16_native_close` 46, `nvrm_alloc` 33,
186`nvrm_alloc_gpu_uncached` 30, `m16_native_submit_methods` 11,
187`m16_native_create_channel` 10, `nvrm_free` 6, `m16_native_open` 6,
188`nvrm_retire` 5, `m16_native_wait_marker` 4, `nvrm_enqueue` 2,
189`nvrm_channel_destroy` 2, `nvrm_channel` 2, `m16_native_wait_marker_ge` 2,
190`nvrm_ring`, `nvrm_open`, `nvrm_close` 1 each. The 188 `nvrm_mthd` sites are
191RM control calls (class allocation, VA space, channel setup); each maps to a
192row of section 2, and none of them exists in the native path by design: the
193native backend talks to the device through the platform services, not through
194an RM method table.
195
196## 4. The freestanding link target
197
198`mk/omega-gpu-engine.mk`, targets `gpu-engine-freestanding` and
199`test-gpu-engine-freestanding`, run by the `gpu-engine` job of
200`.github/workflows/host-suites-2.yml`.
201
202- Flags: `-std=gnu11 -O2 -Wall -Wextra -Werror -ffreestanding -fno-builtin
203 -fno-stack-protector -U_FORTIFY_SOURCE -DOMEGA_GPU_NO_POSIX -DOMEGA_NUMERIC_CPU_ONLY`.
204 `-U_FORTIFY_SOURCE` (cut C) keeps glibc from redirecting `memcpy` to
205 `__memcpy_chk` when a distribution compiler enables fortify by default.
206- The fourteen objects (eight from A and A.2, six from cut C) are partially linked (`gcc -r -nostdlib`); `nm -u` on the
207 result may show only `memcpy|memmove|memset|memcmp|strlen|strcmp` (and the
208 GOT symbol). Anything else fails the build with the symbol named.
209- `OMEGA_GPU_NO_POSIX` in `src/omega_gpu_engine.c`: `err_no` is recorded as 0
210 (there is no errno), there is no default clock, and `omega_gpu_execute`
211 refuses with `INTERNAL_INVARIANT` at `STEP_CLOCK_CHECK` until
212 `omega_gpu_engine_set_clock` installed one. The host build is unchanged
213 (errno captured, `CLOCK_MONOTONIC` default), and the 15 errno pass-through
214 expectations of the contract test become 0 under the freestanding build.
215- The same 49-mutant sweep runs on the host build; the mutation that removes
216 the poison fill now matches the `ERRNO_CLEAR()` spelling.
217
218## 5. The platform contract in one page
219
220`src/omega_gpu_platform.h`, ABI 1.1 (1.0 in cut A; 1.1 adds the session services in cut C).
221
222- Handles: `OmegaGpuDeviceHandle`, `OmegaGpuBufferHandle`, `OmegaGpuQueueHandle`,
223 each `index + generation`; generation 0 is never issued; a closed handle is
224 stale and refused; a handle of the wrong kind is refused.
225- Addresses: `OmegaCpuView` (pointer + length), `OmegaGpuVa`, `OmegaGpuBusAddr`
226 are three distinct struct types. No raw physical address type.
227- Buffers: `OmegaGpuBufferDesc` carries kind (DATA, CODE, QUEUE), explicit
228 `bytes`, `rights`, cache policy and alignment. Code is CPU-written and
229 GPU-executed, never GPU-written; a queue is CPU-written and device-read; a
230 host-polled word is CPU-read, GPU-written and GPU-uncached.
231- Services: TIME, WAIT, LOCK, MMIO, DMA, SYNC, COMPLETION are required for
232 v1; IRQ is optional and claimed only by a real interrupt wait.
233 `omega_gpu_platform_check` refuses a claimed service without a function and
234 refuses a function that no claimed service declares (a hidden path is a
235 silent fallback).
236- ABI 1.1 (cut C, session part): services DEVICE (open, close, driver text of
237 the last failure), QUEUE (open, submit, retire, close over a `BUF_QUEUE`
238 ring), CLOCK_NS and HOST_MEM, required together as
239 `OMEGA_GPU_SVC_REQUIRED_SESSION` (no MMIO, no IRQ) and checked by
240 `omega_gpu_platform_check_for`. COMPLETION is `poll_word` (renamed from
241 `wait_word`): reached in serial-number order, `OMEGA_GPU_POLL_TIMED_OUT` when
242 not, and a timeout says nothing about the device. New refusal
243 `OMEGA_GPU_PLAT_REFUSED_DEVICE`. Handle slots raised from 64 to 1024 (a
244 serving session holds one buffer per weight tensor). A refused
245 `queue_submit` rang no doorbell, so nothing of it is in flight.
246- Limits and concurrency: `OmegaGpuPlatformCaps` carries device, buffer,
247 queue, in-flight, per-buffer and total byte limits;
248 `omega_gpu_platform_negotiate` refuses a required set the platform does not
249 meet; `OmegaGpuHandleTable` enforces per-kind slot limits and byte totals.
250- Refusals: thirteen named codes, no silent fallback to Linux, CPU or a
251 remote device anywhere in the contract.
252
253## 6. Next cuts
254
255- A.2: DONE (see section 1): caller-provided code buffers for
256 `omega_blackwell_codegen.c` and `omega_blackwell_matmul.c`, both in the
257 freestanding target. The kernels each API builds for itself
258 (`omega_gpu_attention_api.c`, `omega_gpu_elementwise_api.c`) still malloc
259 their code and move with the session in cut C (the attention API moved in
260 cut C session part; the elementwise API has not).
261- B (needs an attended window, native v1 gate order N1 then N4): Aienux-side
262 discovery and bounded device ownership through the platform services; a
263 discovery-only run makes zero configuration writes; SMMU/DMA resolved;
264 polling does not claim IRQ. Implement aienos#285 before any domain-1
265 resource number is reused or persisted. The arch#163 native-order conflict
266 is resolved explicitly in that cut, not implied here.
267- C, session part: DONE (see section 1): session, serving, matmul and
268 attention APIs and the bounded wait run over `OmegaGpuPlatform` ABI 1.1 and
269 are in the freestanding closure; the Linux driver path is the separate
270 reference `src/omega_gpu_platform_linux.c`.
271- C, remaining: a native implementation of `OmegaGpuPlatform` and a native
272 backend of `OmegaGpuBackend` (both need cut B device ownership first); the
273 elementwise API (`omega_gpu_elementwise_api.c`) joins the closure.
274- D: vector executor (sha256 pin re-sealed on chip), numeric launchers,
275 resident runtime.
276
277Pre-existing, unrelated to this cut: `make test-gpu-serving-alloc` fails its
278`bounds` mode on omega main 536870f1 ("in-bounds paged calls touched the
279driver (1 allocs)"), reproduced on an untouched checkout on 2026-10-12. It
280belongs to the matmul serving lane (cut I, omega#414), and is reported there.
281On main 4d0bb36 its `sweep` mode fails 130 checks as well; cut C leaves both
282failures unchanged (the output of all six modes is identical to main apart
283from test line numbers). `gpu_attention_test --hd 128 --host-only` fails 16
284of 107 on main 4d0bb36 and on this branch with the same list.