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/omega-mv/blob/main/docs/runtime/API.md # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers 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 3 Omega Runtime API version: 0.1 4 5 Status: 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 7 list against the headers (a host check, no GPU). Review state: the first version was reviewed by Opus 5.5 on 2026-10-22 (L386). 8 The sections changed for main `62d1d0d6` (head `2908f13a`) were reviewed again by a separate review lane (ApiReview594); its 9 findings F1-F7 and N1-N5 are fixed in this version. Those fixes were reviewed at head `7be2c6f7` (Rev955), and its six 10 findings are fixed too; `docs/runtime/API-REVIEW.md` records both reviews. The fixes of the second review have not been 11 reviewed again. The check proves the list and every quoted C signature match the headers; prose is checked by review. 12 13 The version number lives in one header, `src/omega_runtime_api.h` (`OMEGA_RUNTIME_API_VERSION_MAJOR`, `_MINOR`). 14 15 ## 1. What this is 16 17 Omega is a GPU compute runtime that does not use CUDA. This file is the written contract for the part a program calls 18 directly: find and open the GPU, get memory, copy data in and out, run a kernel, run many kernels in one submission, run a 19 packaged job, and read errors. It covers what exists on the main branch today, on one machine type (GB10, the DGX Spark), 20 through the Linux open-driver backend. Nothing here claims more than that. 21 22 How 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 30 Every C signature in this file is copied from the header it names. `tools/runtime_api_check.sh` re-checks every quoted 31 signature against the headers on every run. 32 33 ## 2. Version and compatibility rule 34 35 The version is MAJOR.MINOR, currently **0.1**. It is a property of the list of entries and their behaviour, not of the 36 library 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 53 MAJOR 0 means "the first written version", not "anything goes": the rule above already binds STABLE entries in 0.x. What 54 0 adds is a warning: the project may promote entries to STABLE freely until 1.0 (moving a STABLE entry down still needs a 55 MAJOR bump, as above), and the first 1.0 will be cut only when 56 section 8 (what v0 does not have) has been looked at again. 57 58 How it is enforced: a header change that moves any listed entry fails `make test-runtime-api` until the manifest line is 59 edited on purpose (`tools/runtime_api_check.sh --bless` refreshes the numbers; the diff is reviewed). A reviewer then decides 60 MINOR or MAJOR using the rule above and edits the version macros and the `Omega Runtime API version:` line in this file; 61 the check fails if the three disagree. The check cannot tell whether the bump was the right size. That is a review duty. 62 63 The 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, 69 device-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: 72 the first call that needs the GPU installs the Linux reference by itself. There is **one device, one channel per process**. 73 There 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. 76 Every ordinary buffer is GPU-uncached, because the CPU writes inputs the chip reads and polls markers the chip writes. 77 You 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 80 handle from a closed device or an already freed buffer is refused instead of silently reused. A buffer you mean to reuse and 81 grow, 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 85 argument words, shared memory, and a timeout. `omega_gpu_session_launch` submits it and waits for the chip to finish (it 86 is 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 89 default each launch is preceded by a barrier so dependent launches cannot overlap; a launch can be marked independent. 90 EXPERIMENTAL: streams, events and dependency-ordered execution are being built on top of it (omega-mv#580), so its options 91 and 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 94 named 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 117 sequence 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 120 deadlocks. 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 124 release 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 130 threads 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 137 omega_gpu_session_lock(); 138 OmegaGpuSession *s = omega_gpu_session_open(); /* NULL: see omega_gpu_session_last_error() */ 139 OmegaGpuMem in, code; 140 omega_gpu_session_alloc(bytes, &in); /* GPU-uncached data buffer */ 141 omega_gpu_session_alloc_code(code_size, &code); /* write the machine code to code.cpu */ 142 omega_gpu_session_sync_to_gpu(&in); 143 OmegaGpuLaunch L = { .code_va = code.va, .timeout_ms = 1000, /* gpr_count, threads_*, grid_*, args, n_args ... */ }; 144 uint64_t elapsed_ns = 0; uint32_t marker = 0; /* launch adds to elapsed_ns: start it at 0 */ 145 int rc = omega_gpu_session_launch(&L, &elapsed_ns, &marker); 146 omega_gpu_session_sync_to_cpu(&in); 147 omega_gpu_session_free(&in); 148 omega_gpu_session_unlock(); 149 ``` 150 151 This 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` 156 STABLE: used by every library API and chip-proven; the lock model is the documented one. 157 ```c 158 void omega_gpu_session_lock(void); 159 ``` 160 Takes the process-wide session lock (platform LOCK service, id `OMEGA_GPU_SESSION_LOCK_ID`). Does not touch the device. 161 In the hosted build the first call installs the Linux reference platform (`pthread_once`, `src/omega_gpu_session.c:109-115`), 162 so 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` 165 STABLE: pairs with the lock. 166 ```c 167 void omega_gpu_session_unlock(void); 168 ``` 169 170 #### `omega_gpu_session_open` 171 STABLE: 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 174 OmegaGpuSession *omega_gpu_session_open(void); 175 ``` 176 Caller holds the lock. Opens the device on first use. Returns NULL when the process is latched, no platform is installed or the 177 open failed; the stage is in `omega_gpu_session_last_error()`. 178 179 #### `omega_gpu_session_is_open` 180 STABLE: simple state query. 181 ```c 182 bool omega_gpu_session_is_open(void); 183 ``` 184 185 #### `omega_gpu_session_is_blocked` 186 STABLE: the latch query that every caller needs. 187 ```c 188 int omega_gpu_session_is_blocked(void); 189 ``` 190 Returns 1 once an uncertain completion has latched this process, else 0. Any thread. 191 192 #### `omega_gpu_session_close` 193 STABLE: the only way to close the device; its refusal after a latch is part of the error model. 194 ```c 195 void omega_gpu_session_close(void); 196 ``` 197 Closes the device and frees every session buffer. **Takes the lock itself.** Refused (a no-op) after an uncertain completion. 198 The next open reopens; every handle of the closed device is stale from then on. 199 200 #### `omega_gpu_session_open_count` 201 STABLE: diagnostic with a fixed meaning. 202 ```c 203 uint32_t omega_gpu_session_open_count(void); 204 ``` 205 Device opens so far in this process (a persistent session shows 1). 206 207 #### `omega_gpu_session_set_spin_us` 208 STABLE: used by sovereign-core's binding; fixed meaning and limit. 209 ```c 210 int omega_gpu_session_set_spin_us(uint32_t us); 211 ``` 212 Process-wide marker-poll spin window, used by every launch whose own `spin_us` is 0. 0 (the default) keeps the platform's 213 sleep-poll. Returns 0 on success, -1 above `OMEGA_GPU_SESSION_MAX_SPIN_US` (setting unchanged). 214 215 #### `omega_gpu_session_spin_us` 216 STABLE: reads the setting above. 217 ```c 218 uint32_t omega_gpu_session_spin_us(void); 219 ``` 220 221 ## 5. Session: memory 222 223 All allocation calls need the caller to hold the lock with the device open. 224 225 #### `OmegaGpuMem` 226 STABLE: the buffer type every API passes around. 227 A 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` 238 STABLE: 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". 240 A handle is valid only while its slot generation matches; a closed handle is refused. 241 242 #### `OmegaGpuDeviceHandle` 243 STABLE: same shape and rule as the buffer handle; named in the platform contract. 244 `{ uint32_t index; uint32_t generation; }`. 245 246 #### `OmegaGpuQueueHandle` 247 STABLE: 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` 251 STABLE: the ordinary buffer call, used by every library. 252 ```c 253 int omega_gpu_session_alloc(size_t bytes, OmegaGpuMem *out); 254 ``` 255 A 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 256 failure (the driver can refuse, for example with no memory; the refusal is counted in `OmegaGpuAllocStats.alloc_failures`). 257 258 #### `omega_gpu_session_alloc_code` 259 STABLE: the only way to place kernel code; chip-proven. 260 ```c 261 int omega_gpu_session_alloc_code(size_t code_size, OmegaGpuMem *out); 262 ``` 263 A 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` 267 STABLE: the release call; its latch behaviour is part of the error model. 268 ```c 269 void omega_gpu_session_free(OmegaGpuMem *m); 270 ``` 271 Releases `m` to the platform and zeroes `*m`. **Latched: `m` is parked instead (never released).** A stale handle (from a 272 closed 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` 276 STABLE: the visibility rule for CPU writes. 277 ```c 278 int omega_gpu_session_sync_to_gpu(const OmegaGpuMem *m); 279 ``` 280 Makes 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` 284 STABLE: the visibility rule for GPU writes. 285 ```c 286 int omega_gpu_session_sync_to_cpu(const OmegaGpuMem *m); 287 ``` 288 Makes device writes to the whole buffer visible to the CPU. Same return values as `sync_to_gpu`. 289 290 #### `OmegaGpuScratch` 291 STABLE: the staging-buffer type the library APIs use. 292 A 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`). 294 Zero-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` 298 STABLE: used by every library API. 299 ```c 300 int omega_gpu_session_scratch(OmegaGpuScratch *s, size_t bytes); 301 ``` 302 Makes `s->mem` at least `bytes` long (reallocated when it grows; **contents are not kept**). Returns 0 or -1; with a 303 reservation active, a request past the reserved size returns `OMEGA_GPU_SESSION_SCRATCH_RESERVED` (-2) and allocates nothing. 304 305 #### `omega_gpu_session_scratch_free` 306 STABLE: the matching release. 307 ```c 308 void omega_gpu_session_scratch_free(OmegaGpuScratch *s); 309 ``` 310 311 #### `OmegaGpuAllocStats` 312 STABLE: used by sovereign-core's binding to show that serving asks the driver for nothing. 313 Counters 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` 317 STABLE: reads the counters above. 318 ```c 319 void omega_gpu_session_alloc_stats(OmegaGpuAllocStats *out); 320 ``` 321 322 ## 6. Session: launch 323 324 #### `OmegaGpuLaunch` 325 STABLE: the launch descriptor; chip-proven by every library. 326 One launch: a kernel already resident at `code_va`, argument words for constant bank 0 at 0x380 (buffer addresses, then 327 parameters), and the grid. 328 329 Argument 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. 336 What the kernel itself may read in constant bank 0 besides these words, and where GB10 machine code comes from, is slice 337 R2 (`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` 352 STABLE: the single-kernel launch; chip-proven. 353 ```c 354 int omega_gpu_session_launch(const OmegaGpuLaunch *L, uint64_t *elapsed_ns, uint32_t *marker_out); 355 ``` 356 Caller holds the lock, device open, not latched. Submits one launch and polls for both completion markers, so it returns when 357 the chip is done. 0 on success; -1 with the stage named on failure; `OMEGA_GPU_SESSION_CANCELLED` (-3) when a cancel request 358 was 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` 364 STABLE: the error-model entry point. 365 ```c 366 const char *omega_gpu_session_last_error(void); 367 ``` 368 The stage of the most recent failure, `""` if none. Shared by every API. Points into one process-wide buffer: read it under 369 the lock, before the next call. 370 371 #### `OmegaGpuParkStats` 372 STABLE: 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` 377 STABLE: how a caller sees what the latch kept. 378 ```c 379 void omega_gpu_session_parked(OmegaGpuParkStats *out); 380 ``` 381 Buffers parked after an uncertain completion: kept allocated, never returned to the platform. The session's own launch 382 buffers (ring, constant bank, marker, QMD page) are parked at the latch and every later free parks too. 383 384 #### `omega_gpu_session_is_parked` 385 STABLE: per-handle form of the above. 386 ```c 387 int omega_gpu_session_is_parked(OmegaGpuBufferHandle h); 388 ``` 389 1 if this handle is parked and listed. 390 391 ## 8. Not in v0 (so nobody assumes it) 392 393 Each 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 406 Listed in the manifest, may change in any minor version. Signatures are in the manifest and the headers; the names are 407 checked 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 424 Types: `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, 428 rights (`OMEGA_GPU_RIGHT_*`), cache policy, services (`OMEGA_GPU_SVC_*`) and refusal names (`OMEGA_GPU_PLAT_*`). 429 430 Reason: the contract is written for three backends but only the Linux reference has run; the second backend (`rig/gb20x`) and 431 the native one will likely force changes. What it already promises (from the header): resources are typed handles with a 432 generation; every byte range carries a length and rights; anything the CPU polls is `OMEGA_GPU_RIGHT_HOST_POLLED` and must be 433 GPU-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 437 Types: `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 441 and 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 445 Reason: omega-mv#580 is building pipelined and dependency-ordered execution on this module, so the options, statistics 446 and 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; 448 the 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 451 of 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 456 Types: `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 460 later `omega_gpu_execute` in the process with `UNCERTAIN_COMPLETION_BLOCKED`. 461 462 Reason: accepts one job shape (`OMEGA_GPU_LAYOUT_VECTOR_1D`); #580 widens it; the chip receipt for the vector-add job is on an 463 unmerged branch (`hive/DEEP2-A3-gpu-engine-impl`). Note: the status paragraph at the top of `omega_gpu_engine.h` says only a 464 fake backend exists; `src/omega_blackwell_engine.c` is on main and `src/omega_blackwell_submit.c` installs it, so that 465 paragraph is out of date (whether it is chip-qualified on main is UNVERIFIED here). 466 467 ### 9.5 Libraries (matmul, elementwise, attention, serving) 468 469 The 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 471 manifest). 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; 473 their headers are the description. One value differs from sovereign-core's pinned copy: `OMEGA_GPU_MATMUL_MAX_CTAS` is 1024 in 474 the 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 479 Types 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 522 Not in the manifest; may change or vanish without notice. Every external function a manifest header declares is either 523 a manifest `fn` or named below as one of the leading names of a bullet (the names before any other text; names in the 524 prose after them do not count); `make test-runtime-api` fails on any other, and on a name that is both (section 11). 525 526 Session (`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 531 Job 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 534 Matmul (`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 540 Elementwise (`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 546 Attention (`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 552 Everything 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 557 copy 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 558 changed 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 559 signature that only appears inside a longer one (`int32_t` inside `uint32_t`), a STABLE entry with no section here, a removed 560 struct field the manifest lists (`OmegaGpuCmdListOpts.first_barrier_none`), a new function in a manifest header with no 561 manifest line, the same for a function that returns a function pointer, an INTERNAL function dropped from section 10, a 562 manifest `fn` dropped from the manifest while section 10's prose still mentions it (`omega_gpu_serving_seal`), and a 563 manifest `fn` also listed as INTERNAL. It needs no GPU and no physics checkout. It checks: every manifest function against its header 564 with exact types; sizes, offsets and constants against a compiled probe; the version macros against the manifest and this file; 565 that every STABLE entry has a `####` section here and every EXPERIMENTAL one is named here; that every C signature quoted 566 in this file appears verbatim in a header; and, with gcc's `-aux-info`, that every external function a manifest header 567 declares is either a manifest `fn` or a leading name of a section-10 bullet, never both, and every such name is still 568 declared (another compiler fails 569 the check with "needs a compiler with -aux-info"). It does not check that the prose is true. Not seen: a new struct or 570 constant (nothing to compare it with), a field added inside padding that the manifest does not list, a field that changes 571 type but keeps its size, and a constant value quoted in prose. 572 573 Where 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 575 its inputs. The hosted AIEN Checks job runs the portable gates it finds on main (`.github/workflows/aien-verification.yml`), 576 so it runs there from the first pull request after the gate file is on main. It needs gcc (for `-aux-info`), make, perl, 577 sed and a POSIX awk.