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 / runtime / API.md

577 lines · 40065 bytes Raw Blame History Rendered
1# Omega Runtime API v0
2
3Omega Runtime API version: 0.1
4
5Status: first written version, 2026-10-19 (slice R1, omega-mv#594, tracking #593). Source of truth is the C headers in
6`src/`. This file describes them; `docs/runtime/omega_runtime_api.manifest` lists them; `make test-runtime-api` checks the
7list against the headers (a host check, no GPU). Review state: the first version was reviewed by Opus 5.5 on 2026-10-22 (L386).
8The sections changed for main 62d1d0d6 (head 2908f13a) were reviewed again by a separate review lane (ApiReview594); its
9findings F1-F7 and N1-N5 are fixed in this version. Those fixes were reviewed at head 7be2c6f7 (Rev955), and its six
10findings are fixed too; `docs/runtime/API-REVIEW.md` records both reviews. The fixes of the second review have not been
11reviewed again. The check proves the list and every quoted C signature match the headers; prose is checked by review.
12
13The version number lives in one header, `src/omega_runtime_api.h` (`OMEGA_RUNTIME_API_VERSION_MAJOR`, `_MINOR`).
14
15## 1. What this is
16
17Omega is a GPU compute runtime that does not use CUDA. This file is the written contract for the part a program calls
18directly: find and open the GPU, get memory, copy data in and out, run a kernel, run many kernels in one submission, run a
19packaged job, and read errors. It covers what exists on the main branch today, on one machine type (GB10, the DGX Spark),
20through the Linux open-driver backend. Nothing here claims more than that.
21
22How to read an entry:
23
24| Tier | Meaning |
25| --- | --- |
26| **STABLE** | Used by other code in the project, covered by chip results, and kept compatible under the rule in section 2. Has its own `####` section below. |
27| **EXPERIMENTAL** | Works and is listed, but may change in any minor version, because the design is still moving or only one use of it exists. Listed in tables with the reason. |
28| **INTERNAL** | Exists in a header for the project's own libraries or tests. Not part of the API; not in the manifest; may change or disappear any time. Every one declared in a manifest header is named in section 10, so nobody builds on it by accident (the check enforces that list). |
29
30Every C signature in this file is copied from the header it names. `tools/runtime_api_check.sh` re-checks every quoted
31signature against the headers on every run.
32
33## 2. Version and compatibility rule
34
35The version is MAJOR.MINOR, currently **0.1**. It is a property of the list of entries and their behaviour, not of the
36library build.
37
38**A MINOR bump (0.1 to 0.2) is allowed to:**
39- add a function, a constant, an enum value at the end of an existing enum, or a new struct;
40- add an EXPERIMENTAL entry, change or remove an EXPERIMENTAL entry, or move an entry from EXPERIMENTAL to STABLE;
41- fix a STABLE function that did not do what this file says (the fix makes it match);
42- add a new failure name for the same call to report (callers must treat an unknown failure code or stage text as a failure).
43
44**It needs a MAJOR bump (0.x to 1.0, then 1.x to 2.0) to:**
45- remove or rename a STABLE function, struct, field or constant;
46- change a STABLE function's argument or return types, a STABLE struct's size, field order or field offsets, or the value
47 of a STABLE constant or enum value;
48- change documented behaviour of a STABLE entry: what the lock covers, what a latch does, which buffers get parked, what
49 a return value means;
50- move a STABLE entry down to EXPERIMENTAL or INTERNAL;
51- raise the platform contract's major number (section 9.2).
52
53MAJOR 0 means "the first written version", not "anything goes": the rule above already binds STABLE entries in 0.x. What
540 adds is a warning: the project may promote entries to STABLE freely until 1.0 (moving a STABLE entry down still needs a
55MAJOR bump, as above), and the first 1.0 will be cut only when
56section 8 (what v0 does not have) has been looked at again.
57
58How it is enforced: a header change that moves any listed entry fails `make test-runtime-api` until the manifest line is
59edited on purpose (`tools/runtime_api_check.sh --bless` refreshes the numbers; the diff is reviewed). A reviewer then decides
60MINOR or MAJOR using the rule above and edits the version macros and the `Omega Runtime API version:` line in this file;
61the check fails if the three disagree. The check cannot tell whether the bump was the right size. That is a review duty.
62
63The platform contract has its own number (`OMEGA_GPU_PLATFORM_ABI_MAJOR` 1, `OMEGA_GPU_PLATFORM_ABI_MINOR` 2, set in
64`src/omega_gpu_platform.h`). A platform minor bump needs at least a runtime MINOR bump; a platform major bump needs a runtime MAJOR bump.
65
66## 3. How the pieces fit (plain English)
67
68**Device and platform.** Omega talks to the GPU through a small "platform" layer: a table of services (a clock, a lock,
69device-visible memory, a submission queue, a way to poll for completion). Today one platform exists, the Linux reference
70(`src/omega_gpu_platform_linux.c`), which uses NVIDIA's open kernel driver. The contract is written so a second backend
71(WSL2 on Windows, or Aienux with no Linux driver) can fill the same table. A program normally never touches the platform:
72the first call that needs the GPU installs the Linux reference by itself. There is **one device, one channel per process**.
73There is no call to ask the device its name, SM count or memory size yet (section 8).
74
75**Memory.** You ask the session for a buffer and get an `OmegaGpuMem`: a handle, a CPU pointer, a GPU address and a size.
76Every ordinary buffer is GPU-uncached, because the CPU writes inputs the chip reads and polls markers the chip writes.
77You make CPU writes visible to the GPU with `omega_gpu_session_sync_to_gpu` and GPU writes visible to the CPU with
78`omega_gpu_session_sync_to_cpu`. Code (the machine code of a kernel) lives in a separate kind of buffer
79(`omega_gpu_session_alloc_code`): the CPU writes it once, the GPU only executes it. Handles carry a generation number, so a
80handle from a closed device or an already freed buffer is refused instead of silently reused. A buffer you mean to reuse and
81grow, such as staging space, can be an `OmegaGpuScratch`. For read-only weights there is a GPU-cached allocation
82(`omega_gpu_session_alloc_cached`, EXPERIMENTAL). There is no async copy and no unified memory in v0.
83
84**Launch.** One kernel launch is an `OmegaGpuLaunch`: where the code is, how many registers, the block and grid size, the
85argument words, shared memory, and a timeout. `omega_gpu_session_launch` submits it and waits for the chip to finish (it
86is synchronous). The wait is by polling a completion word, never by an interrupt.
87
88**Command lists.** `omega_gpu_cmdlist_*` records many launches and submits them as one unit with one completion wait. By
89default each launch is preceded by a barrier so dependent launches cannot overlap; a launch can be marked independent.
90EXPERIMENTAL: streams, events and dependency-ordered execution are being built on top of it (omega-mv#580), so its options
91and statistics will grow.
92
93**Job engine.** `omega_gpu_execute` runs one already-built job (today only a 1-D vector job: two inputs, one output) through
94named states and returns success or exactly one named failure. EXPERIMENTAL.
95
96**Errors, the latch and parked buffers.**
97- A failing call returns a non-zero value and names its stage in text: `omega_gpu_session_last_error()`. A device-open failure
98 carries the driver's own text. Do not read a bare return code as the cause.
99- If the chip's completion cannot be confirmed (a completion wait ran out of time, the completion poll was refused, or a launch was cancelled after submit),
100 the work may still be running and still be reading or writing your buffers. The process then **latches**:
101 `omega_gpu_session_is_blocked()` returns 1 for the rest of the process, every later launch is refused, close and reopen are
102 refused, and nothing is returned to the platform.
103- After the latch, every buffer freed through `omega_gpu_session_free` is **parked**: kept allocated, counted by
104 `omega_gpu_session_parked`, never released. Handles stay valid for inspection (`omega_gpu_session_is_parked`).
105- Recovery in the same process is EXPERIMENTAL (section 9.1; cut C5, `evidence/C5-ISOLATION/`): `omega_gpu_session_recover`
106 runs the on-close hooks while still latched, closes the device through the platform, and only then lifts the latch. If
107 the close is refused or reports a driver teardown fault, the process stays latched for good and must exit (header).
108 That ordering is checked on the host with a fake platform (`evidence/C5-ISOLATION/02-session-platform.log`). What the
109 Linux reference's close does on the chip is intended, not shown: its RM client close is meant to destroy this process's
110 channels, and with them any grid still running, and to release the driver objects. The chip run of this path has not
111 been done (`evidence/C5-ISOLATION/README.md`: NO RESULT, then NOT RUN). The reference does not unmap buffers the caller
112 did not free (`src/omega_gpu_platform_linux.c:198-199`), so whether each recovery leaks CPU mappings is not known.
113 Every handle and command list of the old device is stale afterwards. A latch held only by the command lists also
114 counts: `omega_gpu_session_is_blocked()` is then 0 while `omega_gpu_cmdlist_is_latched()` is 1, so check both.
115
116**Threads.** One process-wide lock (the platform LOCK service, lock id `OMEGA_GPU_SESSION_LOCK_ID`, which is 0). A call
117sequence that touches the device (open, alloc, launch, readback) is done between `omega_gpu_session_lock()` and
118`omega_gpu_session_unlock()`. Threads therefore take turns on the one channel. The Linux reference lock is a plain
119(non-recursive) pthread mutex (`locks[id]`, `src/omega_gpu_platform_linux.c:45` and `:141`), so taking it twice from one thread
120deadlocks. These take the lock themselves and must be called without it: `omega_gpu_session_close`, `omega_gpu_session_recover`,
121`omega_gpu_cmdlist_create`, `omega_gpu_cmdlist_free`, and the section 9.5 calls that touch the device or a library cache
122(the compute and upload calls, `omega_gpu_tensor_free`, `omega_gpu_matmul_cache_clear`, `omega_gpu_matmul_set_cta_budget`,
123`omega_gpu_matmul_prepare`, `omega_gpu_attention_pool_alloc`, `omega_gpu_attention_pool_free`, the serving reserve, seal and
124release calls, and `omega_gpu_device_close` through `omega_gpu_session_close`). The section 9.5 accessors do not take the lock:
125`omega_gpu_matmul_cta_budget`, `omega_gpu_tensor_shape`, `omega_gpu_matmul_rc_name`, `omega_gpu_matmul_last_error`,
126`omega_gpu_elementwise_rc_name`, `omega_gpu_attention_rc_name`, `omega_gpu_attention_last_error` and
127`omega_gpu_matmul_is_blocked` (an atomic read); neither does the INTERNAL `omega_gpu_elementwise_last_error` (section 10).
128`omega_gpu_matmul_cta_budget` reads without the lock the value that
129`omega_gpu_matmul_set_cta_budget` writes under it (`src/omega_gpu_matmul_api.c:146-153`), so calling the two from different
130threads at once is a data race.
131`omega_gpu_session_cancel` may be called from any thread without the lock (header). `omega_gpu_session_is_blocked` reads the latch with an atomic load (`src/omega_gpu_session.c:173`), so it is safe without the lock too.
132`omega_gpu_session_last_error` returns a pointer into one process-wide text buffer: read it under the lock, before the next call.
133
134### 3.1 A minimal sequence (sketch)
135
136```c example
137omega_gpu_session_lock();
138OmegaGpuSession *s = omega_gpu_session_open(); /* NULL: see omega_gpu_session_last_error() */
139OmegaGpuMem in, code;
140omega_gpu_session_alloc(bytes, &in); /* GPU-uncached data buffer */
141omega_gpu_session_alloc_code(code_size, &code); /* write the machine code to code.cpu */
142omega_gpu_session_sync_to_gpu(&in);
143OmegaGpuLaunch L = { .code_va = code.va, .timeout_ms = 1000, /* gpr_count, threads_*, grid_*, args, n_args ... */ };
144uint64_t elapsed_ns = 0; uint32_t marker = 0; /* launch adds to elapsed_ns: start it at 0 */
145int rc = omega_gpu_session_launch(&L, &elapsed_ns, &marker);
146omega_gpu_session_sync_to_cpu(&in);
147omega_gpu_session_free(&in);
148omega_gpu_session_unlock();
149```
150
151This is a shape sketch, not a worked example (the worked example is slice R2).
152
153## 4. Session: device, lock and state
154
155#### `omega_gpu_session_lock`
156STABLE: used by every library API and chip-proven; the lock model is the documented one.
157```c
158void omega_gpu_session_lock(void);
159```
160Takes the process-wide session lock (platform LOCK service, id `OMEGA_GPU_SESSION_LOCK_ID`). Does not touch the device.
161In the hosted build the first call installs the Linux reference platform (`pthread_once`, `src/omega_gpu_session.c:109-115`),
162so it takes a real mutex. Freestanding build only: with no platform installed it does nothing, and the open that follows refuses.
163
164#### `omega_gpu_session_unlock`
165STABLE: pairs with the lock.
166```c
167void omega_gpu_session_unlock(void);
168```
169
170#### `omega_gpu_session_open`
171STABLE: used by every library API and chip-proven. Treat the returned pointer as "the device is open"; the fields of
172`OmegaGpuSession` are EXPERIMENTAL (the session's own launch buffers) and a caller needs none of them.
173```c
174OmegaGpuSession *omega_gpu_session_open(void);
175```
176Caller holds the lock. Opens the device on first use. Returns NULL when the process is latched, no platform is installed or the
177open failed; the stage is in `omega_gpu_session_last_error()`.
178
179#### `omega_gpu_session_is_open`
180STABLE: simple state query.
181```c
182bool omega_gpu_session_is_open(void);
183```
184
185#### `omega_gpu_session_is_blocked`
186STABLE: the latch query that every caller needs.
187```c
188int omega_gpu_session_is_blocked(void);
189```
190Returns 1 once an uncertain completion has latched this process, else 0. Any thread.
191
192#### `omega_gpu_session_close`
193STABLE: the only way to close the device; its refusal after a latch is part of the error model.
194```c
195void omega_gpu_session_close(void);
196```
197Closes the device and frees every session buffer. **Takes the lock itself.** Refused (a no-op) after an uncertain completion.
198The next open reopens; every handle of the closed device is stale from then on.
199
200#### `omega_gpu_session_open_count`
201STABLE: diagnostic with a fixed meaning.
202```c
203uint32_t omega_gpu_session_open_count(void);
204```
205Device opens so far in this process (a persistent session shows 1).
206
207#### `omega_gpu_session_set_spin_us`
208STABLE: used by sovereign-core's binding; fixed meaning and limit.
209```c
210int omega_gpu_session_set_spin_us(uint32_t us);
211```
212Process-wide marker-poll spin window, used by every launch whose own `spin_us` is 0. 0 (the default) keeps the platform's
213sleep-poll. Returns 0 on success, -1 above `OMEGA_GPU_SESSION_MAX_SPIN_US` (setting unchanged).
214
215#### `omega_gpu_session_spin_us`
216STABLE: reads the setting above.
217```c
218uint32_t omega_gpu_session_spin_us(void);
219```
220
221## 5. Session: memory
222
223All allocation calls need the caller to hold the lock with the device open.
224
225#### `OmegaGpuMem`
226STABLE: the buffer type every API passes around.
227A device buffer: a typed handle, its kind, the CPU view, the GPU virtual address and the size. A `cpu` of NULL means there is no CPU view.
228
229| Field | Meaning (from `src/omega_gpu_session.h`) |
230| --- | --- |
231| `handle` | `OmegaGpuBufferHandle`: index and generation |
232| `kind` | `OMEGA_GPU_HANDLE_BUF_DATA`, `_BUF_CODE` or `_BUF_QUEUE` |
233| `cpu` | CPU view |
234| `va` | GPU virtual address |
235| `size` | bytes of both views |
236
237#### `OmegaGpuBufferHandle`
238STABLE: a field of `OmegaGpuMem`, so its layout is part of it.
239`{ uint32_t index; uint32_t generation; }`. Generation 0 is never issued, so a zeroed handle means "none".
240A handle is valid only while its slot generation matches; a closed handle is refused.
241
242#### `OmegaGpuDeviceHandle`
243STABLE: same shape and rule as the buffer handle; named in the platform contract.
244`{ uint32_t index; uint32_t generation; }`.
245
246#### `OmegaGpuQueueHandle`
247STABLE: same shape and rule as the buffer handle; named in the platform contract.
248`{ uint32_t index; uint32_t generation; }`.
249
250#### `omega_gpu_session_alloc`
251STABLE: the ordinary buffer call, used by every library.
252```c
253int omega_gpu_session_alloc(size_t bytes, OmegaGpuMem *out);
254```
255A GPU-uncached DATA buffer, CPU and GPU read/write, rounded up to a page. Returns 0 on success; non-zero with the stage named on
256failure (the driver can refuse, for example with no memory; the refusal is counted in `OmegaGpuAllocStats.alloc_failures`).
257
258#### `omega_gpu_session_alloc_code`
259STABLE: the only way to place kernel code; chip-proven.
260```c
261int omega_gpu_session_alloc_code(size_t code_size, OmegaGpuMem *out);
262```
263A CODE buffer (CPU writes, GPU executes, GPU never writes) for `code_size` bytes plus the 2 KB instruction-prefetch tail
264(`src/omega_gpu_code_alloc.h`), the tail zero-filled. The caller writes the code to `out->cpu`. A size of 0 still gets one page (`omega_gpu_code_alloc_bytes` rounds up to at least one page).
265
266#### `omega_gpu_session_free`
267STABLE: the release call; its latch behaviour is part of the error model.
268```c
269void omega_gpu_session_free(OmegaGpuMem *m);
270```
271Releases `m` to the platform and zeroes `*m`. **Latched: `m` is parked instead (never released).** A stale handle (from a
272closed device) or a closed session is refused: nothing is released, the refusal is counted
273(`OmegaGpuAllocStats.stale_refusals`) and `*m` is zeroed.
274
275#### `omega_gpu_session_sync_to_gpu`
276STABLE: the visibility rule for CPU writes.
277```c
278int omega_gpu_session_sync_to_gpu(const OmegaGpuMem *m);
279```
280Makes CPU writes to the whole buffer visible to the device (platform SYNC). Returns 0, also for a buffer with no CPU view;
281-1 with the stage named when refused or when there is no device.
282
283#### `omega_gpu_session_sync_to_cpu`
284STABLE: the visibility rule for GPU writes.
285```c
286int omega_gpu_session_sync_to_cpu(const OmegaGpuMem *m);
287```
288Makes device writes to the whole buffer visible to the CPU. Same return values as `sync_to_gpu`.
289
290#### `OmegaGpuScratch`
291STABLE: the staging-buffer type the library APIs use.
292A caller-owned staging buffer that grows to its high-water mark: `mem` (an `OmegaGpuMem`), `cap` (usable bytes), `high_water`
293(largest request so far) and `reserved` (a serving reservation is active, see `omega_gpu_session_scratch_reserve`).
294Zero-initialise it before first use. This is required: `omega_gpu_session_scratch` reads `reserved`, `cap`, `mem.cpu` and
295`high_water` before it writes them (`src/omega_gpu_session.c:315-321`).
296
297#### `omega_gpu_session_scratch`
298STABLE: used by every library API.
299```c
300int omega_gpu_session_scratch(OmegaGpuScratch *s, size_t bytes);
301```
302Makes `s->mem` at least `bytes` long (reallocated when it grows; **contents are not kept**). Returns 0 or -1; with a
303reservation active, a request past the reserved size returns `OMEGA_GPU_SESSION_SCRATCH_RESERVED` (-2) and allocates nothing.
304
305#### `omega_gpu_session_scratch_free`
306STABLE: the matching release.
307```c
308void omega_gpu_session_scratch_free(OmegaGpuScratch *s);
309```
310
311#### `OmegaGpuAllocStats`
312STABLE: used by sovereign-core's binding to show that serving asks the driver for nothing.
313Counters of driver allocations made through `omega_gpu_session_alloc` since the process started: `allocs`, `alloc_bytes`
314(page-rounded), `alloc_failures`, `frees`, `stale_refusals`. Covers the session layer only.
315
316#### `omega_gpu_session_alloc_stats`
317STABLE: reads the counters above.
318```c
319void omega_gpu_session_alloc_stats(OmegaGpuAllocStats *out);
320```
321
322## 6. Session: launch
323
324#### `OmegaGpuLaunch`
325STABLE: the launch descriptor; chip-proven by every library.
326One launch: a kernel already resident at `code_va`, argument words for constant bank 0 at 0x380 (buffer addresses, then
327parameters), and the grid.
328
329Argument layout and the checks `omega_gpu_session_launch` makes (`src/omega_gpu_session.c:525-537`):
330- a 64-bit GPU address takes two words, the low word first, then the high word;
331- `L` is not NULL, `n_args` is 1 to `OMEGA_GPU_SESSION_MAX_ARGS`, `args` is not NULL, `threads_x`, `grid_x` and `grid_y`
332 are not 0 (a `threads_y` of 0 means 1), and `spin_us` is at most `OMEGA_GPU_SESSION_MAX_SPIN_US` (1000000); otherwise the
333 launch is refused with "launch arguments" and nothing runs;
334- `gpr_count` is rounded up to a multiple of 8, and to at least 64;
335- `elapsed_ns` is added to, not set: start it at 0.
336What the kernel itself may read in constant bank 0 besides these words, and where GB10 machine code comes from, is slice
337R2 (`examples/hello_gpu`, README "Run your first kernel").
338
339| Field | Meaning (from `src/omega_gpu_session.h`) |
340| --- | --- |
341| `code_va` | GPU address of the kernel code |
342| `gpr_count` | registers the QMD (the launch descriptor the hardware reads) declares; multiple of 8, at least 64 in practice |
343| `threads_x`, `threads_y` | block size |
344| `grid_x`, `grid_y` | grid size |
345| `num_elements` | QMD config num_elements (kept per API for identical words) |
346| `args`, `n_args` | `n_args` words written at constant bank + 0x380; `n_args` at most `OMEGA_GPU_SESSION_MAX_ARGS` (32) |
347| `timeout_ms` | completion poll limit, applied to each of the launch's two markers in turn (so a launch can wait up to twice this); past it the completion is uncertain and **the process latches**. Do not pass 0: the marker is then polled once (after the spin window, if any) and the launch latches unless the grid had already finished |
348| `shared_bytes` | shared memory per block; 0 = the default (1024) |
349| `spin_us` | spin-poll window before the platform's sleep-poll; 0 = the process-wide setting; at most `OMEGA_GPU_SESSION_MAX_SPIN_US` |
350
351#### `omega_gpu_session_launch`
352STABLE: the single-kernel launch; chip-proven.
353```c
354int omega_gpu_session_launch(const OmegaGpuLaunch *L, uint64_t *elapsed_ns, uint32_t *marker_out);
355```
356Caller holds the lock, device open, not latched. Submits one launch and polls for both completion markers, so it returns when
357the chip is done. 0 on success; -1 with the stage named on failure; `OMEGA_GPU_SESSION_CANCELLED` (-3) when a cancel request
358was seen. A marker timeout latches the process. `elapsed_ns` (submit to second marker) is added to when the pointer is given;
359`marker_out` receives the first marker word observed.
360
361## 7. Session: errors, the latch, parked buffers
362
363#### `omega_gpu_session_last_error`
364STABLE: the error-model entry point.
365```c
366const char *omega_gpu_session_last_error(void);
367```
368The stage of the most recent failure, `""` if none. Shared by every API. Points into one process-wide buffer: read it under
369the lock, before the next call.
370
371#### `OmegaGpuParkStats`
372STABLE: the parked-buffer report.
373`buffers` (parked, listed plus untracked), `untracked` (parked past the listed `OMEGA_GPU_SESSION_PARK_MAX` = 512) and
374`bytes`.
375
376#### `omega_gpu_session_parked`
377STABLE: how a caller sees what the latch kept.
378```c
379void omega_gpu_session_parked(OmegaGpuParkStats *out);
380```
381Buffers parked after an uncertain completion: kept allocated, never returned to the platform. The session's own launch
382buffers (ring, constant bank, marker, QMD page) are parked at the latch and every later free parks too.
383
384#### `omega_gpu_session_is_parked`
385STABLE: per-handle form of the above.
386```c
387int omega_gpu_session_is_parked(OmegaGpuBufferHandle h);
388```
3891 if this handle is parked and listed.
390
391## 8. Not in v0 (so nobody assumes it)
392
393Each line is a gap named in `docs/runtime/ROADMAP.md` section 1 (on branch `runtime/roadmap`, not yet merged); the gaps themselves are not in the manifest.
394- A device query (name, SM count, memory): there is no API call for it.
395- More than one device in a process; sharing the GPU between processes (a second channel failed under load: omega-mv#523).
396 Extra queues on the one device (`omega_gpu_session_extra_queue`, `omega_gpu_cmdlist_submit_pair`) are EXPERIMENTAL (9.1, 9.3).
397- A STABLE recovery contract: `omega_gpu_session_recover` is EXPERIMENTAL in v0 (section 9.1).
398- Async copy, streams, events, host callbacks (omega-mv#580 is building ordering on command lists).
399- Cached read-write buffers; unified memory.
400- Launches with more than the 32 argument words, or an asynchronous single launch.
401- A second real backend (WSL2 `/dev/dxg` is on branch `rig/gb20x`; native Aienux is planned), so the platform contract has only been exercised by one.
402- A runtime function that reports the version of the linked library (the version is a compile-time macro only).
403
404## 9. EXPERIMENTAL entries
405
406Listed in the manifest, may change in any minor version. Signatures are in the manifest and the headers; the names are
407checked there. The reason is why each is not STABLE yet.
408
409### 9.1 Session extras (`src/omega_gpu_session.h`, `src/omega_gpu_mem_cached.h`)
410
411| Entry | Reason it is EXPERIMENTAL |
412| --- | --- |
413| `omega_gpu_session_alloc_cached` | GPU-cached memory is correct only for write-once, never-polled, GPU-read-only weights; the API cannot enforce that (the caller must). |
414| `omega_gpu_session_scratch_reserve`, `omega_gpu_session_scratch_unreserve` | Serving-daemon feature (no driver call after warm-up); one user. |
415| `omega_gpu_session_cancel` | A cancel after submit cannot stop the chip: it latches the process. Semantics may tighten as recovery matures. |
416| `omega_gpu_session_recover`, `omega_gpu_session_recoveries` | C5 recovery after a latch (`evidence/C5-ISOLATION/`): new on main after this API was first drafted; its device-close path is one backend's (Linux RM client close) behaviour and has no chip run yet (section 3). `recover` returns 0 when the latch is lifted, -1 with the reason named when nothing was latched (neither the process nor the command lists), no device is open, or the close was refused (then the process stays latched). |
417| `omega_gpu_session_extra_queue` | Queues 1..3 past the session queue, each with its own 64 KB ring; granted only when the device was opened with `AIEN_OMEGA_GPU_CHANNELS` > i. Work on different queues is not ordered. One backend, one user (the command-list pair). |
418| `omega_gpu_session_set_platform`, `omega_gpu_session_platform`, `omega_gpu_session_submit_prefix_words`, `omega_gpu_session_completion_mode`, `omega_gpu_session_now_ns` | Tied to the platform contract, which has one real backend. |
419| `omega_gpu_host_alloc`, `omega_gpu_host_calloc`, `omega_gpu_host_free` | CPU-only memory from the platform HOST_MEM service; the freestanding build needs them, hosted code can use malloc. |
420| `OmegaGpuSession` | The session's own launch buffers; a caller needs none of its fields. |
421
422### 9.2 Platform contract (`src/omega_gpu_platform.h`, ABI 1.2)
423
424Types: `OmegaGpuPlatform` (the service table), `OmegaGpuPlatformCaps`, `OmegaGpuBufferDesc`, `OmegaCpuView`, `OmegaGpuVa`,
425`OmegaGpuBusAddr`, `OmegaGpuHandleTable`. Functions: `omega_gpu_platform_refusal_name`, `omega_gpu_platform_negotiate`,
426`omega_gpu_platform_check`, `omega_gpu_platform_check_for`, `omega_gpu_platform_check_buffer`, `omega_gpu_handles_init`,
427`omega_gpu_handles_open`, `omega_gpu_handles_check`, `omega_gpu_handles_close`. Enums and constants: the handle kinds,
428rights (`OMEGA_GPU_RIGHT_*`), cache policy, services (`OMEGA_GPU_SVC_*`) and refusal names (`OMEGA_GPU_PLAT_*`).
429
430Reason: the contract is written for three backends but only the Linux reference has run; the second backend (`rig/gb20x`) and
431the native one will likely force changes. What it already promises (from the header): resources are typed handles with a
432generation; every byte range carries a length and rights; anything the CPU polls is `OMEGA_GPU_RIGHT_HOST_POLLED` and must be
433GPU-uncached; polling a word is never claimed as interrupt support; a missing service is refused, never emulated.
434
435### 9.3 Command lists (`src/omega_gpu_cmdlist.h`)
436
437Types: `OmegaGpuCmdListOpts`, `OmegaGpuCmdListStats`, the opaque `OmegaGpuCmdList`. Functions: `omega_gpu_cmdlist_create`
438(takes the lock itself), `omega_gpu_cmdlist_free`, `omega_gpu_cmdlist_reset`, `omega_gpu_cmdlist_count`,
439`omega_gpu_cmdlist_add`, `omega_gpu_cmdlist_mark_independent`, `omega_gpu_cmdlist_submit`, `omega_gpu_cmdlist_is_latched`,
440`omega_gpu_cmdlist_stamps`, `omega_gpu_cmdlist_barrier_name`, `omega_gpu_cmdlist_submit_pair` (list a on the session queue
441and list b on extra queue 1, both submitted before either is waited; caller holds the lock), `omega_gpu_cmdlist_wait_for`
442(C4 event: the next launch added waits on the chip for a launch of the other list of the pair). Up to
443`OMEGA_GPU_CMDLIST_MAX_LAUNCHES` (4096) launches per list. A list made before `omega_gpu_session_recover` is refused after it.
444
445Reason: omega-mv#580 is building pipelined and dependency-ordered execution on this module, so the options, statistics
446and barrier modes will grow. The measured extra cost of each launch in a list is about 30 us with a wait-for-idle barrier
447(`evidence/OWN30B-LAUNCH-COST-20261014T0120Z/r1/receipt.json`, verdict FAIL on 4 of 11 checks). A timeout latches the list;
448the session latches as well only if the 1 ms check launch queued behind the list also times out
449(`src/omega_gpu_cmdlist.c:233-240`, section 3). The `OMEGA_GPU_CMDLIST_BARRIER_NONE` mode and `skip_launch` option are test-only.
450`OmegaGpuCmdListOpts.first_barrier_none` (C4 streams) drops the WAIT_FOR_IDLE and the shader-cache invalidate before launch 0
451of a list. The caller must make sure the code, constant banks and QMDs that launch 0 reads are not in a stale cache line
452(fresh slots or unchanged contents), or launch 0 may read old bytes (`src/omega_gpu_cmdlist.h:85-87`). 0 keeps the barrier.
453
454### 9.4 Job engine (`src/omega_gpu_engine.h`)
455
456Types: `OmegaGpuJob`, `OmegaGpuResult`, `OmegaGpuTimeouts`, `OmegaGpuBackend`, `OmegaGpuBackendDiag`. Functions:
457`omega_gpu_execute`, `omega_gpu_engine_set_backend`, `omega_gpu_engine_is_blocked`, `omega_gpu_engine_set_clock`,
458`omega_gpu_engine_failure_name`, `omega_gpu_engine_state_name`, `omega_gpu_engine_wait_name`, `omega_gpu_engine_step_name`. One failure name per run
459(`OMEGA_GPU_ENGINE_*`), states `INITIAL` to `SUCCESS`, the failed step recorded, and an uncertain completion blocks every
460later `omega_gpu_execute` in the process with `UNCERTAIN_COMPLETION_BLOCKED`.
461
462Reason: accepts one job shape (`OMEGA_GPU_LAYOUT_VECTOR_1D`); #580 widens it; the chip receipt for the vector-add job is on an
463unmerged branch (`hive/DEEP2-A3-gpu-engine-impl`). Note: the status paragraph at the top of `omega_gpu_engine.h` says only a
464fake backend exists; `src/omega_blackwell_engine.c` is on main and `src/omega_blackwell_submit.c` installs it, so that
465paragraph is out of date (whether it is chip-qualified on main is UNVERIFIED here).
466
467### 9.5 Libraries (matmul, elementwise, attention, serving)
468
469The entries carried over from aien-sovereign-core's manifest: `src/omega_gpu_matmul_api.h`, `omega_gpu_elementwise_api.h`,
470`omega_gpu_attention_api.h`, `omega_gpu_serving.h` (the functions and structs after the `libraries` comment in the
471manifest). Reason: shapes and formats follow one model (Qwen3-30B); there is no general any-shape GEMM yet
472(`docs/runtime/ROADMAP.md` 1.3, branch `runtime/roadmap`). They are the surface sovereign-core's Rust binding uses today. They are not described entry by entry in v0;
473their headers are the description. One value differs from sovereign-core's pinned copy: `OMEGA_GPU_MATMUL_MAX_CTAS` is 1024 in
474the header (changed by omega #473, commit 98cecadc), 64 in their manifest. Omega's manifest is canonical; R12 brings theirs level.
475
476
477### 9.6 Library entries (manifest spelling)
478
479Types are the manifest's Rust spelling (`*const`, `*mut`, `u32`, ...); the headers hold the C. Every entry here is EXPERIMENTAL.
480
481| Entry | Signature |
482| --- | --- |
483| `OmegaGpuMatmulInfo` | struct, 160 bytes (fields in the manifest) |
484| `OmegaGpuServingBounds` | struct, 44 bytes (fields in the manifest) |
485| `OmegaGpuEwInfo` | struct, 120 bytes (fields in the manifest) |
486| `OmegaGpuAttnInfo` | struct, 176 bytes (fields in the manifest) |
487| `OmegaGpuKvLayout` | struct, 64 bytes (fields in the manifest) |
488| `omega_gpu_matmul_bf16` | `fn(u32, u32, u32, *const u16, *const u16, *mut f32, *mut OmegaGpuMatmulInfo) -> i32` |
489| `omega_gpu_matmul_f32` | `fn(u32, u32, u32, *const f32, *const f32, *mut f32, *mut OmegaGpuMatmulInfo) -> i32` |
490| `omega_gpu_matmul_rc_name` | `fn(i32) -> *const c_char` |
491| `omega_gpu_matmul_cache_clear` | `fn() -> ()` |
492| `omega_gpu_tensor_upload_bf16` | `fn(u32, u32, *const u16, *mut *mut OmegaGpuTensor) -> i32` |
493| `omega_gpu_tensor_upload_f32` | `fn(u32, u32, *const f32, *mut *mut OmegaGpuTensor) -> i32` |
494| `omega_gpu_tensor_free` | `fn(*mut OmegaGpuTensor) -> ()` |
495| `omega_gpu_tensor_shape` | `fn(*const OmegaGpuTensor, *mut u32, *mut u32) -> ()` |
496| `omega_gpu_matmul_resident_bf16` | `fn(u32, *const u16, *const OmegaGpuTensor, *mut f32, *mut OmegaGpuMatmulInfo) -> i32` |
497| `omega_gpu_matmul_resident_f32` | `fn(u32, *const f32, *const OmegaGpuTensor, *mut f32, *mut OmegaGpuMatmulInfo) -> i32` |
498| `omega_gpu_matmul_last_error` | `fn() -> *const c_char` |
499| `omega_gpu_matmul_is_blocked` | `fn() -> i32` |
500| `omega_gpu_device_close` | `fn() -> ()` |
501| `omega_gpu_matmul_set_cta_budget` | `fn(u32) -> ()` |
502| `omega_gpu_matmul_cta_budget` | `fn() -> u32` |
503| `omega_gpu_reserve_serving` | `fn(*const OmegaGpuServingBounds) -> i32` |
504| `omega_gpu_serving_release` | `fn() -> ()` |
505| `omega_gpu_matmul_prepare` | `fn(u32, u32, u32) -> i32` |
506| `omega_gpu_serving_seal` | `fn() -> ()` |
507| `omega_gpu_rmsnorm_f32` | `fn(u32, u32, *const f32, *const f32, f32, *mut f32, *mut OmegaGpuEwInfo) -> i32` |
508| `omega_gpu_rope_f32` | `fn(u32, u32, *const f32, *const f32, *const f32, *mut f32, *mut OmegaGpuEwInfo) -> i32` |
509| `omega_gpu_swiglu_f32` | `fn(u32, *const f32, *const f32, *mut f32, *mut OmegaGpuEwInfo) -> i32` |
510| `omega_gpu_elementwise_rc_name` | `fn(i32) -> *const c_char` |
511| `omega_gpu_gqa_attention_f32` | `fn(*const f32, *const f32, *const f32, u32, u32, u32, u32, *mut f32, *mut OmegaGpuAttnInfo) -> i32` |
512| `omega_gpu_gqa_attention_rows_f32` | `fn(*const f32, *const f32, *const f32, u32, u32, u32, u32, u32, *mut f32, *mut OmegaGpuAttnInfo) -> i32` |
513| `omega_gpu_attention_pool_alloc` | `fn(usize, *mut *mut c_void) -> i32` |
514| `omega_gpu_attention_pool_free` | `fn() -> ()` |
515| `omega_gpu_paged_attention_bf16` | `fn(*const f32, *const c_void, *const OmegaGpuKvLayout, *const u32, u32, u32, u32, u32, u32, u32, *mut f32, *mut OmegaGpuAttnInfo) -> i32` |
516| `omega_gpu_paged_attention_batch_bf16` | `fn(*const f32, *const c_void, *const OmegaGpuKvLayout, *const i32, *const i32, u32, u32, u32, u32, u32, u32, *mut f32, *mut OmegaGpuAttnInfo) -> i32` |
517| `omega_gpu_attention_rc_name` | `fn(i32) -> *const c_char` |
518| `omega_gpu_attention_last_error` | `fn() -> *const c_char` |
519
520## 10. INTERNAL (not part of the API)
521
522Not in the manifest; may change or vanish without notice. Every external function a manifest header declares is either
523a manifest `fn` or named below as one of the leading names of a bullet (the names before any other text; names in the
524prose after them do not count); `make test-runtime-api` fails on any other, and on a name that is both (section 11).
525
526Session (`src/omega_gpu_session.h`):
527- `omega_gpu_session_set_error` (library code names its failure stage through it).
528- `omega_gpu_session_on_close` (lets a library drop its resident kernels before the session closes; up to 8 hooks).
529- `omega_gpu_session_latch_uncertain`, `omega_gpu_session_note_module_latch` (a module such as the command lists tells the session it latched).
530
531Job engine (`src/omega_gpu_engine.h`):
532- `omega_gpu_engine_test_reset_block`, `omega_gpu_engine_test_force_block`, `omega_gpu_engine_test_set_clock`: TEST ONLY. A blocked process must stay blocked because the GPU may still be running.
533
534Matmul (`src/omega_gpu_matmul_api.h`):
535- `omega_gpu_matmul_reserve`, `omega_gpu_matmul_unreserve`, `omega_gpu_matmul_seal` (the serving reservation; callers use `omega_gpu_reserve_serving`, `omega_gpu_serving_seal` and `omega_gpu_serving_release`).
536- `omega_gpu_tensor_update_bf16`, `omega_gpu_tensor_update_f32` (rewrite a resident B in place).
537- `omega_gpu_matmul_last_stages`, `omega_gpu_matmul_set_oracle` (per-stage timing of the last call; host oracle on the non-resident calls).
538- `omega_gpu_matmul_test_set_mutant`, `omega_gpu_matmul_test_set_unroll`, `omega_gpu_matmul_test_a_row0_hits`: TEST ONLY.
539
540Elementwise (`src/omega_gpu_elementwise_api.h`):
541- `omega_gpu_elementwise_cache_clear`, `omega_gpu_elementwise_last_error`.
542- `omega_gpu_elementwise_codegen`, `omega_gpu_elementwise_codegen_ir` (build a kernel without launching it, for offline disassembly and the host IR simulator).
543- `omega_gpu_ex2_f32`, `omega_gpu_shared_xchg_u32`, `omega_gpu_reconv_probe_u32` (chip probes).
544- `omega_gpu_elementwise_test_set_mutant`, `omega_gpu_elementwise_test_set_mutant_level`: TEST ONLY.
545
546Attention (`src/omega_gpu_attention_api.h`):
547- `omega_gpu_attention_cache_clear`, `omega_gpu_attention_heads_per_cta`, `omega_gpu_attention_mutant_name`.
548- `omega_gpu_attention_reserve`, `omega_gpu_attention_reserve_rows`, `omega_gpu_attention_unreserve` (the serving reservation; callers use `omega_gpu_reserve_serving`).
549- `omega_gpu_attention_codegen`, `omega_gpu_attention_codegen_hd` (build a kernel without launching it).
550- `omega_gpu_attention_test_set_mutant`, `omega_gpu_attention_test_set_divergent`, `omega_gpu_attention_test_set_dedupe`, `omega_gpu_attention_test_set_split`, `omega_gpu_attention_test_set_simulator`, `omega_gpu_attention_test_shared_bytes`, `omega_gpu_attention_test_resident_fits`: TEST ONLY.
551
552Everything else under `src/omega_gpu_*` and `src/omega_blackwell_*` in headers the manifest does not list (kernel builder, encoder, per-model APIs, launch helpers).
553
554## 11. Checking this file
555
556`make test-runtime-api` runs `tools/runtime_api_check.sh` on the real headers and then `tools/runtime_api_negative.sh`, which breaks a
557copy of the headers, the manifest or this file in sixteen ways and requires the check to fail each time: a removed function (twice: a STABLE one and the EXPERIMENTAL `omega_gpu_session_recover`), a missing version macro, a
558changed function signature, a changed struct, a changed constant, a version line in this file that disagrees with the macro, a quoted signature in this file that no header has, a quoted
559signature that only appears inside a longer one (`int32_t` inside `uint32_t`), a STABLE entry with no section here, a removed
560struct field the manifest lists (`OmegaGpuCmdListOpts.first_barrier_none`), a new function in a manifest header with no
561manifest line, the same for a function that returns a function pointer, an INTERNAL function dropped from section 10, a
562manifest `fn` dropped from the manifest while section 10's prose still mentions it (`omega_gpu_serving_seal`), and a
563manifest `fn` also listed as INTERNAL. It needs no GPU and no physics checkout. It checks: every manifest function against its header
564with exact types; sizes, offsets and constants against a compiled probe; the version macros against the manifest and this file;
565that every STABLE entry has a `####` section here and every EXPERIMENTAL one is named here; that every C signature quoted
566in this file appears verbatim in a header; and, with gcc's `-aux-info`, that every external function a manifest header
567declares is either a manifest `fn` or a leading name of a section-10 bullet, never both, and every such name is still
568declared (another compiler fails
569the check with "needs a compiler with -aux-info"). It does not check that the prose is true. Not seen: a new struct or
570constant (nothing to compare it with), a field added inside padding that the manifest does not list, a field that changes
571type but keeps its size, and a constant value quoted in prose.
572
573Where it runs: the gate `OMEGA-RUNTIME-API` (`tests/gates/omega-runtime-api.gate`, requires `portable`) runs
574`make test-runtime-api` through `tests/gates/run.sh runtime-api`. The Spark judge runs it on a pull request that touches
575its inputs. The hosted AIEN Checks job runs the portable gates it finds on main (`.github/workflows/aien-verification.yml`),
576so it runs there from the first pull request after the gate file is on main. It needs gcc (for `-aux-info`), make, perl,
577sed and a POSIX awk.