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
GitHub aien-dev/omega-mv#955 (code only)
Apply it
git checkout -b patch-920f86227f283ea3 62d1d0d668f897386a0e311374f8dbcc5c32dde8 curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/920f86227f283ea3.patch | git am
Provenance
github-import 1
aien-dev/omega-mv
955
7a6c036e814ff7f9b0d1c55956469c780f96d86f
{"kind":"github-import","owner":"aien-dev","repo":"omega-mv","number":955,"url":"https://github.com/aien-dev/omega-mv/pull/955","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:39:28Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/.crumb b/.crumb index f3e51fe46..5386b9e30 100644 --- a/.crumb +++ b/.crumb @@ -47,8 +47,8 @@ "purpose": "Directory calibration. Purpose not yet described by a human." }, { - "digest": "7ef7796693f23ad68d9a5bcaaee0f635018f4371139a040ba202d4ce7083ede8", - "last_commit": "dd39bf71f", + "digest": "bea7e9b212a45f729aa7e9d697efde88d458fff65c0782d62c2ddfc7d41e9e06", + "last_commit": "36f391500", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." }, @@ -59,8 +59,8 @@ "purpose": "Directory doctrine. Purpose not yet described by a human." }, { - "digest": "8f0e5cb325040247440527f6b54b65cf72c47ff5adca75b4f32a1ddf2b2d6ade", - "last_commit": "1f320caad", + "digest": "2730787e5508fd415a4cbabbb1aa19b9b67350d99b1eaa01e0383eb7168bc705", + "last_commit": "36f391500", "name": "mk", "purpose": "Directory mk. Purpose not yet described by a human." }, @@ -72,38 +72,38 @@ }, { "digest": "f765ad87fdddd9b47f690b07298c951a0f7e7675dc5de4ffe44e33a0c14b1986", - "last_commit": "a8a6a3d3c", + "last_commit": "62d1d0d66", "name": "spec", "purpose": "Directory spec. Purpose not yet described by a human." }, { - "digest": "aaf5acb82fd4c720cd60c85fd6087f636c72a98e2f3740c9295dcfa525dc64d7", - "last_commit": "bf54b19fa", + "digest": "be38bcedfe19615bd7b575135ba0b6cf312ae6781010f417af5fe1eba72136ca", + "last_commit": "e25aa1bb9", "name": "src", "purpose": "Directory src. Purpose not yet described by a human." }, { - "digest": "5395ff8ff9afceebe8e453788f80a3064b831513cc4cb92fd55869115e06b874", - "last_commit": "a8a6a3d3c", + "digest": "b7868bcc6bf0bf3134f15be5ca3a36041aca987b0ad65eb4ae8a6651712ae4d2", + "last_commit": "36f391500", "name": "tests", "purpose": "Directory tests. Purpose not yet described by a human." }, { - "digest": "308db0e6cf45c0a48f01f5f5f228450f191389de68006915b9ecf9c65b9a2e29", - "last_commit": "a8a6a3d3c", + "digest": "1f31b07e6e98823c1e7681b39e87da59c370fa4c187c4536accbed82e621161b", + "last_commit": "36f391500", "name": "tools", "purpose": "Directory tools. Purpose not yet described by a human." } ], - "children_root": "sha256:07bf1706dcffbad66c0353871ff67a6749055da03cee8d8ebdf9a4c91e36bddc", - "compiled_at": "2026-10-30T12:31:50Z", + "children_root": "sha256:31f19131ea95c3d8097eacb42c558dda06a166a6a64e17f8865a64a58b083d1a", + "compiled_at": "2026-10-30T17:08:24Z", "compiler": "crumb-compile/1", - "digest": "sha256:904fca8c0e0cf3e3a5e5adb73393e01c7018b920bb542d289904240f70e400d6", - "evidence_files": 12622, - "evidence_root": "sha256:b1a08e2ce56e6feada0d8a31f06fbd7adee57adc1c1ad8dec220293ee5d439f9", - "files": 17849, - "generated_at_commit": "52a82f392fa513ebbc2d9d719a0f14c385289b06", - "source_tree": "sha256:75458da6553a0ee5ea2af95f46afb658e8a3f6e53cca6e3b4b9874035f78c2ed" + "digest": "sha256:53f2b5fdde68aeeacf1097bb0fac8ea31db9754b10342090b06409538960d203", + "evidence_files": 12632, + "evidence_root": "sha256:b72b63e00c10cd208fac0b0c69e8ba4c012704cfde0c5433b19c5a57159008b1", + "files": 17867, + "generated_at_commit": "36f391500d8f24cf9704c4829a71797248df8803", + "source_tree": "sha256:ab87a9d9a03212db27b44af4d130d3aad28e84ee1ab9a975e89467a836b95406" }, "owner_lane": "", "provenance": { diff --git a/docs/.crumb b/docs/.crumb index 433100df5..d9fad1015 100644 --- a/docs/.crumb +++ b/docs/.crumb @@ -124,14 +124,14 @@ } ], "children_root": "sha256:c81d43c0c392dfec2b6ed5b38ba95ea7c592782b283950e32b777e7b9cfd9d61", - "compiled_at": "2026-10-30T02:47:38Z", + "compiled_at": "2026-10-30T17:08:24Z", "compiler": "crumb-compile/1", - "digest": "sha256:7ef7796693f23ad68d9a5bcaaee0f635018f4371139a040ba202d4ce7083ede8", + "digest": "sha256:bea7e9b212a45f729aa7e9d697efde88d458fff65c0782d62c2ddfc7d41e9e06", "evidence_files": 34, "evidence_root": "sha256:589d8b3706e6d7a202ab20b278dac5fc5bafc973f1c2a867b2668aa7210b65cc", - "files": 138, - "generated_at_commit": "e615e9ff47d03199514580f655d7670e61ab7e2f", - "source_tree": "sha256:ba44cf86b50127e2ec3824c2e913e032178628d69910a85ca9125cc1ed960bb5" + "files": 141, + "generated_at_commit": "36f391500d8f24cf9704c4829a71797248df8803", + "source_tree": "sha256:662e865cdd8613762c184e086086075c12cf7fc0733280afa11d5a2229a1beeb" }, "owner_lane": "", "provenance": { diff --git a/docs/runtime/API-REVIEW.md b/docs/runtime/API-REVIEW.md new file mode 100644 index 000000000..978d1a972 --- /dev/null +++ b/docs/runtime/API-REVIEW.md @@ -0,0 +1,40 @@ +# Omega Runtime API v0: independent review record (omega-mv#594, PR #955) + +This file is the review record that `docs/runtime/API.md` cites. It summarises two read-only review lanes; their full +notes are not in this repository. Host only (aarch64 Linux, gcc 13.3.0): no GPU, no chip run. + +## Review 1: ApiReview594, head 2908f13a against main 62d1d0d6 + +Scope: `docs/runtime/API.md`, `docs/runtime/omega_runtime_api.manifest`, `tools/runtime_api_check.sh`, +`tools/runtime_api_negative.sh`. Verdict: no blocking finding; 7 should-fix (F) and 5 nit (N). Fixed in commit e25aa1bb. + +| ID | Finding | Fix | +|---|---|---| +| F1 | Recovery cited omega-mv#518, which is a lock leak in `omega_gpu_decode_graph_begin_token`, not session recovery. | Cite cut C5 and `evidence/C5-ISOLATION/`. | +| F2 | "The RM client close destroys this process's channels and frees every buffer" was stated as fact; the C5 chip run is NO RESULT, then NOT RUN, and the host evidence uses a fake platform (ordering only). | Stated as intended, not shown; the host-proven ordering kept. | +| F3 | "Frees every buffer" contradicts `src/omega_gpu_platform_linux.c:198-199` (buffers the caller did not free are not unmapped). | API.md and the `omega_gpu_session_recover` header comment say the per-recovery leak of CPU mappings is not known. | +| F4 | "Every section 9.5 call takes the lock" was too broad: the accessors do not, and `omega_gpu_matmul_cta_budget` reads unlocked what `omega_gpu_matmul_set_cta_budget` writes under the lock (`src/omega_gpu_matmul_api.c:146-153`). | The locking and lock-free calls are listed by name; the race is named. | +| F5 | "With no platform installed the lock does nothing" holds only for the freestanding build; the hosted build installs the Linux reference through `pthread_once` (`src/omega_gpu_session.c:109-115`). | Stated per build. | +| F6 | Section 9.6 said "except the three STABLE session entries"; every entry in that table is EXPERIMENTAL. | "Every entry here is EXPERIMENTAL." | +| F7 | The review-state line predated the changes under review. | Replaced by the reviewed revisions and this record. | +| N1 | The check went manifest to headers only, so a new public function was not seen. | Reverse scan with gcc `-aux-info`; control `new-header-function`. | +| N2 | `OmegaGpuCmdListOpts.first_barrier_none` was in the manifest only. | Prose in section 9.3 (`src/omega_gpu_cmdlist.h:85-87`); control `removed-padding-field`. | +| N3 | The launch argument checks were incomplete (`L` NULL, `spin_us` bound) and the `timeout_ms` 0 text was wrong. | Matches `src/omega_gpu_session.c:525-527` and `session_wait`. | +| N4 | INTERNAL helpers are declared in the public `omega_gpu_session.h` with no mark there. | INTERNAL comments on four declarations. | +| N5 | Recovery from a command-list-only latch and the return values of `omega_gpu_session_recover` were not described. | Section 3 and the 9.1 row. | + +## Review 2: Rev955, head 7be2c6f7 against main 62d1d0d6 + +Verdict: F1-F7 and N1-N5 confirmed fixed; one major and five minor/nit findings, fixed in the commit that adds this file. + +| # | Finding | Fix | +|---|---|---| +| 1 (major) | The section-10 parser took every backticked `omega_*` name in section 10 as INTERNAL, including the manifest functions the prose mentions (`omega_gpu_reserve_serving`, `omega_gpu_serving_seal`, `omega_gpu_serving_release`). Dropping `fn omega_gpu_serving_seal` from the manifest still gave PASS. | Only the leading names of a section-10 bullet count, and a name that is both a manifest `fn` and INTERNAL fails. Controls `manifest-fn-named-in-prose` and `internal-also-manifest`. | +| 2 | Section 9.3 said "a timeout latches the list and then the session"; `force_latch` (`src/omega_gpu_cmdlist.c:233-240`) latches the session only if its 1 ms check launch also times out. | Reworded, pointing to section 3. | +| 3 | `test-runtime-api` ran in no workflow and was not `.PHONY`. | `.PHONY`; gate `tests/gates/omega-runtime-api.gate` (requires `portable`, `tests/gates/run.sh runtime-api`). The Spark judge runs it on PRs touching its inputs; hosted AIEN Checks takes its portable gate list from main, so it runs there only after this gate is merged (API.md section 11). Passes under gawk and mawk 1.3.4 (`evidence/RUNTIME-R1-API-review2/`). | +| 4 | Citation `omega_gpu_platform_linux.c:197-198` was off by one. | `:198-199`. | +| 5 | API.md and the review-fixes README cited a home-directory path as the review record. | This file. | +| 6 | Section 3 grouped every `*_last_error` call with the section 9.5 accessors, but `omega_gpu_elementwise_last_error` is INTERNAL (section 10). A function returning a function pointer would have been read as declaring `int`. | The accessors are named one by one; the name split skips a `(*` declarator; control `new-fnptr-function`. | + +Not checked by either review: that the prose is true beyond the cited lines, and any chip behaviour (recovery, extra +queues): NOT RUN. diff --git a/docs/runtime/API.md b/docs/runtime/API.md new file mode 100644 index 000000000..9f5f34321 --- /dev/null +++ b/docs/runtime/API.md @@ -0,0 +1,577 @@ +# Omega Runtime API v0 + +Omega Runtime API version: 0.1 + +Status: first written version, 2026-10-19 (slice R1, omega-mv#594, tracking #593). Source of truth is the C headers in +`src/`. This file describes them; `docs/runtime/omega_runtime_api.manifest` lists them; `make test-runtime-api` checks the +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). +The sections changed for main 62d1d0d6 (head 2908f13a) were reviewed again by a separate review lane (ApiReview594); its +findings F1-F7 and N1-N5 are fixed in this version. Those fixes were reviewed at head 7be2c6f7 (Rev955), and its six +findings are fixed too; `docs/runtime/API-REVIEW.md` records both reviews. The fixes of the second review have not been +reviewed again. The check proves the list and every quoted C signature match the headers; prose is checked by review. + +The version number lives in one header, `src/omega_runtime_api.h` (`OMEGA_RUNTIME_API_VERSION_MAJOR`, `_MINOR`). + +## 1. What this is + +Omega is a GPU compute runtime that does not use CUDA. This file is the written contract for the part a program calls +directly: find and open the GPU, get memory, copy data in and out, run a kernel, run many kernels in one submission, run a +packaged job, and read errors. It covers what exists on the main branch today, on one machine type (GB10, the DGX Spark), +through the Linux open-driver backend. Nothing here claims more than that. + +How to read an entry: + +| Tier | Meaning | +| --- | --- | +| **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. | +| **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. | +| **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). | + +Every C signature in this file is copied from the header it names. `tools/runtime_api_check.sh` re-checks every quoted +signature against the headers on every run. + +## 2. Version and compatibility rule + +The version is MAJOR.MINOR, currently **0.1**. It is a property of the list of entries and their behaviour, not of the +library build. + +**A MINOR bump (0.1 to 0.2) is allowed to:** +- add a function, a constant, an enum value at the end of an existing enum, or a new struct; +- add an EXPERIMENTAL entry, change or remove an EXPERIMENTAL entry, or move an entry from EXPERIMENTAL to STABLE; +- fix a STABLE function that did not do what this file says (the fix makes it match); +- add a new failure name for the same call to report (callers must treat an unknown failure code or stage text as a failure). + +**It needs a MAJOR bump (0.x to 1.0, then 1.x to 2.0) to:** +- remove or rename a STABLE function, struct, field or constant; +- change a STABLE function's argument or return types, a STABLE struct's size, field order or field offsets, or the value + of a STABLE constant or enum value; +- change documented behaviour of a STABLE entry: what the lock covers, what a latch does, which buffers get parked, what + a return value means; +- move a STABLE entry down to EXPERIMENTAL or INTERNAL; +- raise the platform contract's major number (section 9.2). + +MAJOR 0 means "the first written version", not "anything goes": the rule above already binds STABLE entries in 0.x. What +0 adds is a warning: the project may promote entries to STABLE freely until 1.0 (moving a STABLE entry down still needs a +MAJOR bump, as above), and the first 1.0 will be cut only when +section 8 (what v0 does not have) has been looked at again. + +How it is enforced: a header change that moves any listed entry fails `make test-runtime-api` until the manifest line is +edited on purpose (`tools/runtime_api_check.sh --bless` refreshes the numbers; the diff is reviewed). A reviewer then decides +MINOR or MAJOR using the rule above and edits the version macros and the `Omega Runtime API version:` line in this file; +the check fails if the three disagree. The check cannot tell whether the bump was the right size. That is a review duty. + +The platform contract has its own number (`OMEGA_GPU_PLATFORM_ABI_MAJOR` 1, `OMEGA_GPU_PLATFORM_ABI_MINOR` 2, set in +`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. + +## 3. How the pieces fit (plain English) + +**Device and platform.** Omega talks to the GPU through a small "platform" layer: a table of services (a clock, a lock, +device-visible memory, a submission queue, a way to poll for completion). Today one platform exists, the Linux reference +(`src/omega_gpu_platform_linux.c`), which uses NVIDIA's open kernel driver. The contract is written so a second backend +(WSL2 on Windows, or AIENOS with no Linux driver) can fill the same table. A program normally never touches the platform: +the first call that needs the GPU installs the Linux reference by itself. There is **one device, one channel per process**. +There is no call to ask the device its name, SM count or memory size yet (section 8). + +**Memory.** You ask the session for a buffer and get an `OmegaGpuMem`: a handle, a CPU pointer, a GPU address and a size. +Every ordinary buffer is GPU-uncached, because the CPU writes inputs the chip reads and polls markers the chip writes. +You make CPU writes visible to the GPU with `omega_gpu_session_sync_to_gpu` and GPU writes visible to the CPU with +`omega_gpu_session_sync_to_cpu`. Code (the machine code of a kernel) lives in a separate kind of buffer +(`omega_gpu_session_alloc_code`): the CPU writes it once, the GPU only executes it. Handles carry a generation number, so a +handle from a closed device or an already freed buffer is refused instead of silently reused. A buffer you mean to reuse and +grow, such as staging space, can be an `OmegaGpuScratch`. For read-only weights there is a GPU-cached allocation +(`omega_gpu_session_alloc_cached`, EXPERIMENTAL). There is no async copy and no unified memory in v0. + +**Launch.** One kernel launch is an `OmegaGpuLaunch`: where the code is, how many registers, the block and grid size, the +argument words, shared memory, and a timeout. `omega_gpu_session_launch` submits it and waits for the chip to finish (it +is synchronous). The wait is by polling a completion word, never by an interrupt. + +**Command lists.** `omega_gpu_cmdlist_*` records many launches and submits them as one unit with one completion wait. By +default each launch is preceded by a barrier so dependent launches cannot overlap; a launch can be marked independent. +EXPERIMENTAL: streams, events and dependency-ordered execution are being built on top of it (omega-mv#580), so its options +and statistics will grow. + +**Job engine.** `omega_gpu_execute` runs one already-built job (today only a 1-D vector job: two inputs, one output) through +named states and returns success or exactly one named failure. EXPERIMENTAL. + +**Errors, the latch and parked buffers.** +- A failing call returns a non-zero value and names its stage in text: `omega_gpu_session_last_error()`. A device-open failure + carries the driver's own text. Do not read a bare return code as the cause. +- 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), + the work may still be running and still be reading or writing your buffers. The process then **latches**: + `omega_gpu_session_is_blocked()` returns 1 for the rest of the process, every later launch is refused, close and reopen are + refused, and nothing is returned to the platform. +- After the latch, every buffer freed through `omega_gpu_session_free` is **parked**: kept allocated, counted by + `omega_gpu_session_parked`, never released. Handles stay valid for inspection (`omega_gpu_session_is_parked`). +- Recovery in the same process is EXPERIMENTAL (section 9.1; cut C5, `evidence/C5-ISOLATION/`): `omega_gpu_session_recover` + runs the on-close hooks while still latched, closes the device through the platform, and only then lifts the latch. If + the close is refused or reports a driver teardown fault, the process stays latched for good and must exit (header). + That ordering is checked on the host with a fake platform (`evidence/C5-ISOLATION/02-session-platform.log`). What the + Linux reference's close does on the chip is intended, not shown: its RM client close is meant to destroy this process's + channels, and with them any grid still running, and to release the driver objects. The chip run of this path has not + been done (`evidence/C5-ISOLATION/README.md`: NO RESULT, then NOT RUN). The reference does not unmap buffers the caller + did not free (`src/omega_gpu_platform_linux.c:198-199`), so whether each recovery leaks CPU mappings is not known. + Every handle and command list of the old device is stale afterwards. A latch held only by the command lists also + counts: `omega_gpu_session_is_blocked()` is then 0 while `omega_gpu_cmdlist_is_latched()` is 1, so check both. + +**Threads.** One process-wide lock (the platform LOCK service, lock id `OMEGA_GPU_SESSION_LOCK_ID`, which is 0). A call +sequence that touches the device (open, alloc, launch, readback) is done between `omega_gpu_session_lock()` and +`omega_gpu_session_unlock()`. Threads therefore take turns on the one channel. The Linux reference lock is a plain +(non-recursive) pthread mutex (`locks[id]`, `src/omega_gpu_platform_linux.c:45` and `:141`), so taking it twice from one thread +deadlocks. These take the lock themselves and must be called without it: `omega_gpu_session_close`, `omega_gpu_session_recover`, +`omega_gpu_cmdlist_create`, `omega_gpu_cmdlist_free`, and the section 9.5 calls that touch the device or a library cache +(the compute and upload calls, `omega_gpu_tensor_free`, `omega_gpu_matmul_cache_clear`, `omega_gpu_matmul_set_cta_budget`, +`omega_gpu_matmul_prepare`, `omega_gpu_attention_pool_alloc`, `omega_gpu_attention_pool_free`, the serving reserve, seal and +release calls, and `omega_gpu_device_close` through `omega_gpu_session_close`). The section 9.5 accessors do not take the lock: +`omega_gpu_matmul_cta_budget`, `omega_gpu_tensor_shape`, `omega_gpu_matmul_rc_name`, `omega_gpu_matmul_last_error`, +`omega_gpu_elementwise_rc_name`, `omega_gpu_attention_rc_name`, `omega_gpu_attention_last_error` and +`omega_gpu_matmul_is_blocked` (an atomic read); neither does the INTERNAL `omega_gpu_elementwise_last_error` (section 10). +`omega_gpu_matmul_cta_budget` reads without the lock the value that +`omega_gpu_matmul_set_cta_budget` writes under it (`src/omega_gpu_matmul_api.c:146-153`), so calling the two from different +threads at once is a data race. +`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. +`omega_gpu_session_last_error` returns a pointer into one process-wide text buffer: read it under the lock, before the next call. + +### 3.1 A minimal sequence (sketch) + +```c example +omega_gpu_session_lock(); +OmegaGpuSession *s = omega_gpu_session_open(); /* NULL: see omega_gpu_session_last_error() */ +OmegaGpuMem in, code; +omega_gpu_session_alloc(bytes, &in); /* GPU-uncached data buffer */ +omega_gpu_session_alloc_code(code_size, &code); /* write the machine code to code.cpu */ +omega_gpu_session_sync_to_gpu(&in); +OmegaGpuLaunch L = { .code_va = code.va, .timeout_ms = 1000, /* gpr_count, threads_*, grid_*, args, n_args ... */ }; +uint64_t elapsed_ns = 0; uint32_t marker = 0; /* launch adds to elapsed_ns: start it at 0 */ +int rc = omega_gpu_session_launch(&L, &elapsed_ns, &marker); +omega_gpu_session_sync_to_cpu(&in); +omega_gpu_session_free(&in); +omega_gpu_session_unlock(); +``` + +This is a shape sketch, not a worked example (the worked example is slice R2). + +## 4. Session: device, lock and state + +#### `omega_gpu_session_lock` +STABLE: used by every library API and chip-proven; the lock model is the documented one. +```c +void omega_gpu_session_lock(void); +``` +Takes the process-wide session lock (platform LOCK service, id `OMEGA_GPU_SESSION_LOCK_ID`). Does not touch the device. +In the hosted build the first call installs the Linux reference platform (`pthread_once`, `src/omega_gpu_session.c:109-115`), +so it takes a real mutex. Freestanding build only: with no platform installed it does nothing, and the open that follows refuses. + +#### `omega_gpu_session_unlock` +STABLE: pairs with the lock. +```c +void omega_gpu_session_unlock(void); +``` + +#### `omega_gpu_session_open` +STABLE: used by every library API and chip-proven. Treat the returned pointer as "the device is open"; the fields of +`OmegaGpuSession` are EXPERIMENTAL (the session's own launch buffers) and a caller needs none of them. +```c +OmegaGpuSession *omega_gpu_session_open(void); +``` +Caller holds the lock. Opens the device on first use. Returns NULL when the process is latched, no platform is installed or the +open failed; the stage is in `omega_gpu_session_last_error()`. + +#### `omega_gpu_session_is_open` +STABLE: simple state query. +```c +bool omega_gpu_session_is_open(void); +``` + +#### `omega_gpu_session_is_blocked` +STABLE: the latch query that every caller needs. +```c +int omega_gpu_session_is_blocked(void); +``` +Returns 1 once an uncertain completion has latched this process, else 0. Any thread. + +#### `omega_gpu_session_close` +STABLE: the only way to close the device; its refusal after a latch is part of the error model. +```c +void omega_gpu_session_close(void); +``` +Closes the device and frees every session buffer. **Takes the lock itself.** Refused (a no-op) after an uncertain completion. +The next open reopens; every handle of the closed device is stale from then on. + +#### `omega_gpu_session_open_count` +STABLE: diagnostic with a fixed meaning. +```c +uint32_t omega_gpu_session_open_count(void); +``` +Device opens so far in this process (a persistent session shows 1). + +#### `omega_gpu_session_set_spin_us` +STABLE: used by sovereign-core's binding; fixed meaning and limit. +```c +int omega_gpu_session_set_spin_us(uint32_t us); +``` +Process-wide marker-poll spin window, used by every launch whose own `spin_us` is 0. 0 (the default) keeps the platform's +sleep-poll. Returns 0 on success, -1 above `OMEGA_GPU_SESSION_MAX_SPIN_US` (setting unchanged). + +#### `omega_gpu_session_spin_us` +STABLE: reads the setting above. +```c +uint32_t omega_gpu_session_spin_us(void); +``` + +## 5. Session: memory + +All allocation calls need the caller to hold the lock with the device open. + +#### `OmegaGpuMem` +STABLE: the buffer type every API passes around. +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. + +| Field | Meaning (from `src/omega_gpu_session.h`) | +| --- | --- | +| `handle` | `OmegaGpuBufferHandle`: index and generation | +| `kind` | `OMEGA_GPU_HANDLE_BUF_DATA`, `_BUF_CODE` or `_BUF_QUEUE` | +| `cpu` | CPU view | +| `va` | GPU virtual address | +| `size` | bytes of both views | + +#### `OmegaGpuBufferHandle` +STABLE: a field of `OmegaGpuMem`, so its layout is part of it. +`{ uint32_t index; uint32_t generation; }`. Generation 0 is never issued, so a zeroed handle means "none". +A handle is valid only while its slot generation matches; a closed handle is refused. + +#### `OmegaGpuDeviceHandle` +STABLE: same shape and rule as the buffer handle; named in the platform contract. +`{ uint32_t index; uint32_t generation; }`. + +#### `OmegaGpuQueueHandle` +STABLE: same shape and rule as the buffer handle; named in the platform contract. +`{ uint32_t index; uint32_t generation; }`. + +#### `omega_gpu_session_alloc` +STABLE: the ordinary buffer call, used by every library. +```c +int omega_gpu_session_alloc(size_t bytes, OmegaGpuMem *out); +``` +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 +failure (the driver can refuse, for example with no memory; the refusal is counted in `OmegaGpuAllocStats.alloc_failures`). + +#### `omega_gpu_session_alloc_code` +STABLE: the only way to place kernel code; chip-proven. +```c +int omega_gpu_session_alloc_code(size_t code_size, OmegaGpuMem *out); +``` +A CODE buffer (CPU writes, GPU executes, GPU never writes) for `code_size` bytes plus the 2 KB instruction-prefetch tail +(`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). + +#### `omega_gpu_session_free` +STABLE: the release call; its latch behaviour is part of the error model. +```c +void omega_gpu_session_free(OmegaGpuMem *m); +``` +Releases `m` to the platform and zeroes `*m`. **Latched: `m` is parked instead (never released).** A stale handle (from a +closed device) or a closed session is refused: nothing is released, the refusal is counted +(`OmegaGpuAllocStats.stale_refusals`) and `*m` is zeroed. + +#### `omega_gpu_session_sync_to_gpu` +STABLE: the visibility rule for CPU writes. +```c +int omega_gpu_session_sync_to_gpu(const OmegaGpuMem *m); +``` +Makes CPU writes to the whole buffer visible to the device (platform SYNC). Returns 0, also for a buffer with no CPU view; +-1 with the stage named when refused or when there is no device. + +#### `omega_gpu_session_sync_to_cpu` +STABLE: the visibility rule for GPU writes. +```c +int omega_gpu_session_sync_to_cpu(const OmegaGpuMem *m); +``` +Makes device writes to the whole buffer visible to the CPU. Same return values as `sync_to_gpu`. + +#### `OmegaGpuScratch` +STABLE: the staging-buffer type the library APIs use. +A caller-owned staging buffer that grows to its high-water mark: `mem` (an `OmegaGpuMem`), `cap` (usable bytes), `high_water` +(largest request so far) and `reserved` (a serving reservation is active, see `omega_gpu_session_scratch_reserve`). +Zero-initialise it before first use. This is required: `omega_gpu_session_scratch` reads `reserved`, `cap`, `mem.cpu` and +`high_water` before it writes them (`src/omega_gpu_session.c:315-321`). + +#### `omega_gpu_session_scratch` +STABLE: used by every library API. +```c +int omega_gpu_session_scratch(OmegaGpuScratch *s, size_t bytes); +``` +Makes `s->mem` at least `bytes` long (reallocated when it grows; **contents are not kept**). Returns 0 or -1; with a +reservation active, a request past the reserved size returns `OMEGA_GPU_SESSION_SCRATCH_RESERVED` (-2) and allocates nothing. + +#### `omega_gpu_session_scratch_free` +STABLE: the matching release. +```c +void omega_gpu_session_scratch_free(OmegaGpuScratch *s); +``` + +#### `OmegaGpuAllocStats` +STABLE: used by sovereign-core's binding to show that serving asks the driver for nothing. +Counters of driver allocations made through `omega_gpu_session_alloc` since the process started: `allocs`, `alloc_bytes` +(page-rounded), `alloc_failures`, `frees`, `stale_refusals`. Covers the session layer only. + +#### `omega_gpu_session_alloc_stats` +STABLE: reads the counters above. +```c +void omega_gpu_session_alloc_stats(OmegaGpuAllocStats *out); +``` + +## 6. Session: launch + +#### `OmegaGpuLaunch` +STABLE: the launch descriptor; chip-proven by every library. +One launch: a kernel already resident at `code_va`, argument words for constant bank 0 at 0x380 (buffer addresses, then +parameters), and the grid. + +Argument layout and the checks `omega_gpu_session_launch` makes (`src/omega_gpu_session.c:525-537`): +- a 64-bit GPU address takes two words, the low word first, then the high word; +- `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` + 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 + launch is refused with "launch arguments" and nothing runs; +- `gpr_count` is rounded up to a multiple of 8, and to at least 64; +- `elapsed_ns` is added to, not set: start it at 0. +What the kernel itself may read in constant bank 0 besides these words, and where GB10 machine code comes from, is slice +R2 (`examples/hello_gpu`, README "Run your first kernel"). + +| Field | Meaning (from `src/omega_gpu_session.h`) | +| --- | --- | +| `code_va` | GPU address of the kernel code | +| `gpr_count` | registers the QMD (the launch descriptor the hardware reads) declares; multiple of 8, at least 64 in practice | +| `threads_x`, `threads_y` | block size | +| `grid_x`, `grid_y` | grid size | +| `num_elements` | QMD config num_elements (kept per API for identical words) | +| `args`, `n_args` | `n_args` words written at constant bank + 0x380; `n_args` at most `OMEGA_GPU_SESSION_MAX_ARGS` (32) | +| `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 | +| `shared_bytes` | shared memory per block; 0 = the default (1024) | +| `spin_us` | spin-poll window before the platform's sleep-poll; 0 = the process-wide setting; at most `OMEGA_GPU_SESSION_MAX_SPIN_US` | + +#### `omega_gpu_session_launch` +STABLE: the single-kernel launch; chip-proven. +```c +int omega_gpu_session_launch(const OmegaGpuLaunch *L, uint64_t *elapsed_ns, uint32_t *marker_out); +``` +Caller holds the lock, device open, not latched. Submits one launch and polls for both completion markers, so it returns when +the chip is done. 0 on success; -1 with the stage named on failure; `OMEGA_GPU_SESSION_CANCELLED` (-3) when a cancel request +was seen. A marker timeout latches the process. `elapsed_ns` (submit to second marker) is added to when the pointer is given; +`marker_out` receives the first marker word observed. + +## 7. Session: errors, the latch, parked buffers + +#### `omega_gpu_session_last_error` +STABLE: the error-model entry point. +```c +const char *omega_gpu_session_last_error(void); +``` +The stage of the most recent failure, `""` if none. Shared by every API. Points into one process-wide buffer: read it under +the lock, before the next call. + +#### `OmegaGpuParkStats` +STABLE: the parked-buffer report. +`buffers` (parked, listed plus untracked), `untracked` (parked past the listed `OMEGA_GPU_SESSION_PARK_MAX` = 512) and +`bytes`. + +#### `omega_gpu_session_parked` +STABLE: how a caller sees what the latch kept. +```c +void omega_gpu_session_parked(OmegaGpuParkStats *out); +``` +Buffers parked after an uncertain completion: kept allocated, never returned to the platform. The session's own launch +buffers (ring, constant bank, marker, QMD page) are parked at the latch and every later free parks too. + +#### `omega_gpu_session_is_parked` +STABLE: per-handle form of the above. +```c +int omega_gpu_session_is_parked(OmegaGpuBufferHandle h); +``` +1 if this handle is parked and listed. + +## 8. Not in v0 (so nobody assumes it) + +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. +- A device query (name, SM count, memory): there is no API call for it. +- More than one device in a process; sharing the GPU between processes (a second channel failed under load: omega-mv#523). + Extra queues on the one device (`omega_gpu_session_extra_queue`, `omega_gpu_cmdlist_submit_pair`) are EXPERIMENTAL (9.1, 9.3). +- A STABLE recovery contract: `omega_gpu_session_recover` is EXPERIMENTAL in v0 (section 9.1). +- Async copy, streams, events, host callbacks (omega-mv#580 is building ordering on command lists). +- Cached read-write buffers; unified memory. +- Launches with more than the 32 argument words, or an asynchronous single launch. +- A second real backend (WSL2 `/dev/dxg` is on branch `rig/gb20x`; native AIENOS is planned), so the platform contract has only been exercised by one. +- A runtime function that reports the version of the linked library (the version is a compile-time macro only). + +## 9. EXPERIMENTAL entries + +Listed in the manifest, may change in any minor version. Signatures are in the manifest and the headers; the names are +checked there. The reason is why each is not STABLE yet. + +### 9.1 Session extras (`src/omega_gpu_session.h`, `src/omega_gpu_mem_cached.h`) + +| Entry | Reason it is EXPERIMENTAL | +| --- | --- | +| `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). | +| `omega_gpu_session_scratch_reserve`, `omega_gpu_session_scratch_unreserve` | Serving-daemon feature (no driver call after warm-up); one user. | +| `omega_gpu_session_cancel` | A cancel after submit cannot stop the chip: it latches the process. Semantics may tighten as recovery matures. | +| `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). | +| `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). | +| `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. | +| `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. | +| `OmegaGpuSession` | The session's own launch buffers; a caller needs none of its fields. | + +### 9.2 Platform contract (`src/omega_gpu_platform.h`, ABI 1.2) + +Types: `OmegaGpuPlatform` (the service table), `OmegaGpuPlatformCaps`, `OmegaGpuBufferDesc`, `OmegaCpuView`, `OmegaGpuVa`, +`OmegaGpuBusAddr`, `OmegaGpuHandleTable`. Functions: `omega_gpu_platform_refusal_name`, `omega_gpu_platform_negotiate`, +`omega_gpu_platform_check`, `omega_gpu_platform_check_for`, `omega_gpu_platform_check_buffer`, `omega_gpu_handles_init`, +`omega_gpu_handles_open`, `omega_gpu_handles_check`, `omega_gpu_handles_close`. Enums and constants: the handle kinds, +rights (`OMEGA_GPU_RIGHT_*`), cache policy, services (`OMEGA_GPU_SVC_*`) and refusal names (`OMEGA_GPU_PLAT_*`). + +Reason: the contract is written for three backends but only the Linux reference has run; the second backend (`rig/gb20x`) and +the native one will likely force changes. What it already promises (from the header): resources are typed handles with a +generation; every byte range carries a length and rights; anything the CPU polls is `OMEGA_GPU_RIGHT_HOST_POLLED` and must be +GPU-uncached; polling a word is never claimed as interrupt support; a missing service is refused, never emulated. + +### 9.3 Command lists (`src/omega_gpu_cmdlist.h`) + +Types: `OmegaGpuCmdListOpts`, `OmegaGpuCmdListStats`, the opaque `OmegaGpuCmdList`. Functions: `omega_gpu_cmdlist_create` +(takes the lock itself), `omega_gpu_cmdlist_free`, `omega_gpu_cmdlist_reset`, `omega_gpu_cmdlist_count`, +`omega_gpu_cmdlist_add`, `omega_gpu_cmdlist_mark_independent`, `omega_gpu_cmdlist_submit`, `omega_gpu_cmdlist_is_latched`, +`omega_gpu_cmdlist_stamps`, `omega_gpu_cmdlist_barrier_name`, `omega_gpu_cmdlist_submit_pair` (list a on the session queue +and list b on extra queue 1, both submitted before either is waited; caller holds the lock), `omega_gpu_cmdlist_wait_for` +(C4 event: the next launch added waits on the chip for a launch of the other list of the pair). Up to +`OMEGA_GPU_CMDLIST_MAX_LAUNCHES` (4096) launches per list. A list made before `omega_gpu_session_recover` is refused after it. + +Reason: omega-mv#580 is building pipelined and dependency-ordered execution on this module, so the options, statistics +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 +(`evidence/OWN30B-LAUNCH-COST-20261014T0120Z/r1/receipt.json`, verdict FAIL on 4 of 11 checks). A timeout latches the list; +the session latches as well only if the 1 ms check launch queued behind the list also times out +(`src/omega_gpu_cmdlist.c:233-240`, section 3). The `OMEGA_GPU_CMDLIST_BARRIER_NONE` mode and `skip_launch` option are test-only. +`OmegaGpuCmdListOpts.first_barrier_none` (C4 streams) drops the WAIT_FOR_IDLE and the shader-cache invalidate before launch 0 +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 +(fresh slots or unchanged contents), or launch 0 may read old bytes (`src/omega_gpu_cmdlist.h:85-87`). 0 keeps the barrier. + +### 9.4 Job engine (`src/omega_gpu_engine.h`) + +Types: `OmegaGpuJob`, `OmegaGpuResult`, `OmegaGpuTimeouts`, `OmegaGpuBackend`, `OmegaGpuBackendDiag`. Functions: +`omega_gpu_execute`, `omega_gpu_engine_set_backend`, `omega_gpu_engine_is_blocked`, `omega_gpu_engine_set_clock`, +`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 +(`OMEGA_GPU_ENGINE_*`), states `INITIAL` to `SUCCESS`, the failed step recorded, and an uncertain completion blocks every +later `omega_gpu_execute` in the process with `UNCERTAIN_COMPLETION_BLOCKED`. + +Reason: accepts one job shape (`OMEGA_GPU_LAYOUT_VECTOR_1D`); #580 widens it; the chip receipt for the vector-add job is on an +unmerged branch (`hive/DEEP2-A3-gpu-engine-impl`). Note: the status paragraph at the top of `omega_gpu_engine.h` says only a +fake backend exists; `src/omega_blackwell_engine.c` is on main and `src/omega_blackwell_submit.c` installs it, so that +paragraph is out of date (whether it is chip-qualified on main is UNVERIFIED here). + +### 9.5 Libraries (matmul, elementwise, attention, serving) + +The entries carried over from aien-sovereign-core's manifest: `src/omega_gpu_matmul_api.h`, `omega_gpu_elementwise_api.h`, +`omega_gpu_attention_api.h`, `omega_gpu_serving.h` (the functions and structs after the `libraries` comment in the +manifest). Reason: shapes and formats follow one model (Qwen3-30B); there is no general any-shape GEMM yet +(`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; +their headers are the description. One value differs from sovereign-core's pinned copy: `OMEGA_GPU_MATMUL_MAX_CTAS` is 1024 in +the header (changed by omega #473, commit 98cecadc), 64 in their manifest. Omega's manifest is canonical; R12 brings theirs level. + + +### 9.6 Library entries (manifest spelling) + +Types are the manifest's Rust spelling (`*const`, `*mut`, `u32`, ...); the headers hold the C. Every entry here is EXPERIMENTAL. + +| Entry | Signature | +| --- | --- | +| `OmegaGpuMatmulInfo` | struct, 160 bytes (fields in the manifest) | +| `OmegaGpuServingBounds` | struct, 44 bytes (fields in the manifest) | +| `OmegaGpuEwInfo` | struct, 120 bytes (fields in the manifest) | +| `OmegaGpuAttnInfo` | struct, 176 bytes (fields in the manifest) | +| `OmegaGpuKvLayout` | struct, 64 bytes (fields in the manifest) | +| `omega_gpu_matmul_bf16` | `fn(u32, u32, u32, *const u16, *const u16, *mut f32, *mut OmegaGpuMatmulInfo) -> i32` | +| `omega_gpu_matmul_f32` | `fn(u32, u32, u32, *const f32, *const f32, *mut f32, *mut OmegaGpuMatmulInfo) -> i32` | +| `omega_gpu_matmul_rc_name` | `fn(i32) -> *const c_char` | +| `omega_gpu_matmul_cache_clear` | `fn() -> ()` | +| `omega_gpu_tensor_upload_bf16` | `fn(u32, u32, *const u16, *mut *mut OmegaGpuTensor) -> i32` | +| `omega_gpu_tensor_upload_f32` | `fn(u32, u32, *const f32, *mut *mut OmegaGpuTensor) -> i32` | +| `omega_gpu_tensor_free` | `fn(*mut OmegaGpuTensor) -> ()` | +| `omega_gpu_tensor_shape` | `fn(*const OmegaGpuTensor, *mut u32, *mut u32) -> ()` | +| `omega_gpu_matmul_resident_bf16` | `fn(u32, *const u16, *const OmegaGpuTensor, *mut f32, *mut OmegaGpuMatmulInfo) -> i32` | +| `omega_gpu_matmul_resident_f32` | `fn(u32, *const f32, *const OmegaGpuTensor, *mut f32, *mut OmegaGpuMatmulInfo) -> i32` | +| `omega_gpu_matmul_last_error` | `fn() -> *const c_char` | +| `omega_gpu_matmul_is_blocked` | `fn() -> i32` | +| `omega_gpu_device_close` | `fn() -> ()` | +| `omega_gpu_matmul_set_cta_budget` | `fn(u32) -> ()` | +| `omega_gpu_matmul_cta_budget` | `fn() -> u32` | +| `omega_gpu_reserve_serving` | `fn(*const OmegaGpuServingBounds) -> i32` | +| `omega_gpu_serving_release` | `fn() -> ()` | +| `omega_gpu_matmul_prepare` | `fn(u32, u32, u32) -> i32` | +| `omega_gpu_serving_seal` | `fn() -> ()` | +| `omega_gpu_rmsnorm_f32` | `fn(u32, u32, *const f32, *const f32, f32, *mut f32, *mut OmegaGpuEwInfo) -> i32` | +| `omega_gpu_rope_f32` | `fn(u32, u32, *const f32, *const f32, *const f32, *mut f32, *mut OmegaGpuEwInfo) -> i32` | +| `omega_gpu_swiglu_f32` | `fn(u32, *const f32, *const f32, *mut f32, *mut OmegaGpuEwInfo) -> i32` | +| `omega_gpu_elementwise_rc_name` | `fn(i32) -> *const c_char` | +| `omega_gpu_gqa_attention_f32` | `fn(*const f32, *const f32, *const f32, u32, u32, u32, u32, *mut f32, *mut OmegaGpuAttnInfo) -> i32` | +| `omega_gpu_gqa_attention_rows_f32` | `fn(*const f32, *const f32, *const f32, u32, u32, u32, u32, u32, *mut f32, *mut OmegaGpuAttnInfo) -> i32` | +| `omega_gpu_attention_pool_alloc` | `fn(usize, *mut *mut c_void) -> i32` | +| `omega_gpu_attention_pool_free` | `fn() -> ()` | +| `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` | +| `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` | +| `omega_gpu_attention_rc_name` | `fn(i32) -> *const c_char` | +| `omega_gpu_attention_last_error` | `fn() -> *const c_char` | + +## 10. INTERNAL (not part of the API) + +Not in the manifest; may change or vanish without notice. Every external function a manifest header declares is either +a manifest `fn` or named below as one of the leading names of a bullet (the names before any other text; names in the +prose after them do not count); `make test-runtime-api` fails on any other, and on a name that is both (section 11). + +Session (`src/omega_gpu_session.h`): +- `omega_gpu_session_set_error` (library code names its failure stage through it). +- `omega_gpu_session_on_close` (lets a library drop its resident kernels before the session closes; up to 8 hooks). +- `omega_gpu_session_latch_uncertain`, `omega_gpu_session_note_module_latch` (a module such as the command lists tells the session it latched). + +Job engine (`src/omega_gpu_engine.h`): +- `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. + +Matmul (`src/omega_gpu_matmul_api.h`): +- `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`). +- `omega_gpu_tensor_update_bf16`, `omega_gpu_tensor_update_f32` (rewrite a resident B in place). +- `omega_gpu_matmul_last_stages`, `omega_gpu_matmul_set_oracle` (per-stage timing of the last call; host oracle on the non-resident calls). +- `omega_gpu_matmul_test_set_mutant`, `omega_gpu_matmul_test_set_unroll`, `omega_gpu_matmul_test_a_row0_hits`: TEST ONLY. + +Elementwise (`src/omega_gpu_elementwise_api.h`): +- `omega_gpu_elementwise_cache_clear`, `omega_gpu_elementwise_last_error`. +- `omega_gpu_elementwise_codegen`, `omega_gpu_elementwise_codegen_ir` (build a kernel without launching it, for offline disassembly and the host IR simulator). +- `omega_gpu_ex2_f32`, `omega_gpu_shared_xchg_u32`, `omega_gpu_reconv_probe_u32` (chip probes). +- `omega_gpu_elementwise_test_set_mutant`, `omega_gpu_elementwise_test_set_mutant_level`: TEST ONLY. + +Attention (`src/omega_gpu_attention_api.h`): +- `omega_gpu_attention_cache_clear`, `omega_gpu_attention_heads_per_cta`, `omega_gpu_attention_mutant_name`. +- `omega_gpu_attention_reserve`, `omega_gpu_attention_reserve_rows`, `omega_gpu_attention_unreserve` (the serving reservation; callers use `omega_gpu_reserve_serving`). +- `omega_gpu_attention_codegen`, `omega_gpu_attention_codegen_hd` (build a kernel without launching it). +- `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. + +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). + +## 11. Checking this file + +`make test-runtime-api` runs `tools/runtime_api_check.sh` on the real headers and then `tools/runtime_api_negative.sh`, which breaks a +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 +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 +signature that only appears inside a longer one (`int32_t` inside `uint32_t`), a STABLE entry with no section here, a removed +struct field the manifest lists (`OmegaGpuCmdListOpts.first_barrier_none`), a new function in a manifest header with no +manifest line, the same for a function that returns a function pointer, an INTERNAL function dropped from section 10, a +manifest `fn` dropped from the manifest while section 10's prose still mentions it (`omega_gpu_serving_seal`), and a +manifest `fn` also listed as INTERNAL. It needs no GPU and no physics checkout. It checks: every manifest function against its header +with exact types; sizes, offsets and constants against a compiled probe; the version macros against the manifest and this file; +that every STABLE entry has a `####` section here and every EXPERIMENTAL one is named here; that every C signature quoted +in this file appears verbatim in a header; and, with gcc's `-aux-info`, that every external function a manifest header +declares is either a manifest `fn` or a leading name of a section-10 bullet, never both, and every such name is still +declared (another compiler fails +the check with "needs a compiler with -aux-info"). It does not check that the prose is true. Not seen: a new struct or +constant (nothing to compare it with), a field added inside padding that the manifest does not list, a field that changes +type but keeps its size, and a constant value quoted in prose. + +Where it runs: the gate `OMEGA-RUNTIME-API` (`tests/gates/omega-runtime-api.gate`, requires `portable`) runs +`make test-runtime-api` through `tests/gates/run.sh runtime-api`. The Spark judge runs it on a pull request that touches +its inputs. The hosted AIEN Checks job runs the portable gates it finds on main (`.github/workflows/aien-verification.yml`), +so it runs there from the first pull request after the gate file is on main. It needs gcc (for `-aux-info`), make, perl, +sed and a POSIX awk. diff --git a/docs/runtime/omega_runtime_api.manifest b/docs/runtime/omega_runtime_api.manifest new file mode 100644 index 000000000..d02c0ebe0 --- /dev/null +++ b/docs/runtime/omega_runtime_api.manifest @@ -0,0 +1,553 @@ +# Omega Runtime API manifest: the canonical list of the C entries that docs/runtime/API.md describes. +# Canonical from R1 (2026-10-19): Omega's copy leads; aien-sovereign-core's crates/aien-omega-gpu/abi/omega_gpu.manifest +# must match it (R12 checks that). The part from "libraries" down to the end of the `fn` lines of those headers was +# copied from that file at aien-sovereign-core origin/main (see the "carried over" comment below) and kept unchanged. +# Line format = aien-abi-conformance src/manifest.rs (header, struct, field, const, fn); `#` starts a comment. +# Additions to that format, all inside comments or in the free `kind` column, so its parser still reads the file: +# - every `struct` and `fn` line ends with a tier comment: `# STABLE` or `# EXPERIMENTAL` (INTERNAL entries are not listed); +# - field kinds beyond its list: `ptr` (any pointer, 8 bytes), `enum` (4 bytes), `struct:Name` (a struct by value); +# `usize`/size_t fields are written `u64` (LP64), as it does. +# Checked by tools/runtime_api_check.sh (make test-runtime-api): every `fn` against its header with the exact types, +# every size, offset and constant against a compiled probe, the version macros against src/omega_runtime_api.h. +# After a deliberate header change: edit the line here, run `tools/runtime_api_check.sh --bless` to refresh numbers, review the diff. +abi omega_runtime 0.1 +header src/omega_runtime_api.h +header src/omega_gpu_platform.h +header src/omega_gpu_session.h +header src/omega_gpu_mem_cached.h +header src/omega_gpu_cmdlist.h +header src/omega_gpu_engine.h +header src/omega_gpu_matmul_api.h +header src/omega_gpu_serving.h +header src/omega_gpu_elementwise_api.h +header src/omega_gpu_attention_api.h +# ---- version ---- +const OMEGA_RUNTIME_API_VERSION_MAJOR 0 +const OMEGA_RUNTIME_API_VERSION_MINOR 1 +# ---- platform contract (src/omega_gpu_platform.h, ABI 1.2) ---- +struct OmegaGpuDeviceHandle 8 4 # STABLE +field OmegaGpuDeviceHandle index 0 4 u32 1 +field OmegaGpuDeviceHandle generation 4 4 u32 1 +struct OmegaGpuBufferHandle 8 4 # STABLE +field OmegaGpuBufferHandle index 0 4 u32 1 +field OmegaGpuBufferHandle generation 4 4 u32 1 +struct OmegaGpuQueueHandle 8 4 # STABLE +field OmegaGpuQueueHandle index 0 4 u32 1 +field OmegaGpuQueueHandle generation 4 4 u32 1 +struct OmegaCpuView 16 8 # EXPERIMENTAL +field OmegaCpuView ptr 0 8 ptr 1 +field OmegaCpuView len 8 8 u64 1 +struct OmegaGpuVa 8 8 # EXPERIMENTAL +field OmegaGpuVa va 0 8 u64 1 +struct OmegaGpuBusAddr 8 8 # EXPERIMENTAL +field OmegaGpuBusAddr iova 0 8 u64 1 +struct OmegaGpuBufferDesc 24 8 # EXPERIMENTAL +field OmegaGpuBufferDesc kind 0 4 u32 1 +field OmegaGpuBufferDesc rights 4 4 u32 1 +field OmegaGpuBufferDesc gpu_cache 8 4 u32 1 +field OmegaGpuBufferDesc align 12 4 u32 1 +field OmegaGpuBufferDesc bytes 16 8 u64 1 +struct OmegaGpuPlatformCaps 56 8 # EXPERIMENTAL +field OmegaGpuPlatformCaps abi_major 0 4 u32 1 +field OmegaGpuPlatformCaps abi_minor 4 4 u32 1 +field OmegaGpuPlatformCaps services 8 4 u32 1 +field OmegaGpuPlatformCaps max_devices 12 4 u32 1 +field OmegaGpuPlatformCaps max_buffers 16 4 u32 1 +field OmegaGpuPlatformCaps max_queues 20 4 u32 1 +field OmegaGpuPlatformCaps max_inflight 24 4 u32 1 +field OmegaGpuPlatformCaps max_buffer_bytes 32 8 u64 1 +field OmegaGpuPlatformCaps max_total_bytes 40 8 u64 1 +field OmegaGpuPlatformCaps submit_prefix_words 48 4 u32 1 +struct OmegaGpuPlatform 184 8 # EXPERIMENTAL +field OmegaGpuPlatform ctx 0 8 ptr 1 +field OmegaGpuPlatform time_now_ms 8 8 ptr 1 +field OmegaGpuPlatform wait_ms 16 8 ptr 1 +field OmegaGpuPlatform lock 24 8 ptr 1 +field OmegaGpuPlatform unlock 32 8 ptr 1 +field OmegaGpuPlatform mmio_read32 40 8 ptr 1 +field OmegaGpuPlatform mmio_write32 48 8 ptr 1 +field OmegaGpuPlatform dma_alloc 56 8 ptr 1 +field OmegaGpuPlatform dma_free 64 8 ptr 1 +field OmegaGpuPlatform sync_cpu_to_gpu 72 8 ptr 1 +field OmegaGpuPlatform sync_gpu_to_cpu 80 8 ptr 1 +field OmegaGpuPlatform poll_word 88 8 ptr 1 +field OmegaGpuPlatform irq_wait 96 8 ptr 1 +field OmegaGpuPlatform device_open 104 8 ptr 1 +field OmegaGpuPlatform device_close 112 8 ptr 1 +field OmegaGpuPlatform diag_text 120 8 ptr 1 +field OmegaGpuPlatform queue_open 128 8 ptr 1 +field OmegaGpuPlatform queue_close 136 8 ptr 1 +field OmegaGpuPlatform queue_submit 144 8 ptr 1 +field OmegaGpuPlatform queue_retire 152 8 ptr 1 +field OmegaGpuPlatform time_now_ns 160 8 ptr 1 +field OmegaGpuPlatform host_alloc 168 8 ptr 1 +field OmegaGpuPlatform host_free 176 8 ptr 1 +struct OmegaGpuHandleTable 69648 8 # EXPERIMENTAL +field OmegaGpuHandleTable generation 0 16384 u32 4096 +field OmegaGpuHandleTable kind 16384 16384 u32 4096 +field OmegaGpuHandleTable bytes 32768 32768 u64 4096 +field OmegaGpuHandleTable live 65536 4096 u8 4096 +field OmegaGpuHandleTable nlive 69632 4 u32 1 +field OmegaGpuHandleTable total_bytes 69640 8 u64 1 +fn omega_gpu_platform_refusal_name fn(i32) -> *const c_char # EXPERIMENTAL +fn omega_gpu_platform_negotiate fn(*const OmegaGpuPlatformCaps, *const OmegaGpuPlatformCaps) -> i32 # EXPERIMENTAL +fn omega_gpu_platform_check fn(*const OmegaGpuPlatform, *const OmegaGpuPlatformCaps) -> i32 # EXPERIMENTAL +fn omega_gpu_platform_check_for fn(*const OmegaGpuPlatform, *const OmegaGpuPlatformCaps, u32) -> i32 # EXPERIMENTAL +fn omega_gpu_platform_check_buffer fn(*const OmegaGpuBufferDesc, *const OmegaGpuPlatformCaps) -> i32 # EXPERIMENTAL +fn omega_gpu_handles_init fn(*mut OmegaGpuHandleTable) -> () # EXPERIMENTAL +fn omega_gpu_handles_open fn(*mut OmegaGpuHandleTable, u32, u64, u32, u64, *mut u32, *mut u32) -> i32 # EXPERIMENTAL +fn omega_gpu_handles_check fn(*const OmegaGpuHandleTable, u32, u32, u32) -> i32 # EXPERIMENTAL +fn omega_gpu_handles_close fn(*mut OmegaGpuHandleTable, u32, u32, u32) -> i32 # EXPERIMENTAL +# ---- session: device, memory, launch, errors (src/omega_gpu_session.h, src/omega_gpu_mem_cached.h) ---- +struct OmegaGpuMem 40 8 # STABLE +field OmegaGpuMem handle 0 8 struct:OmegaGpuBufferHandle 1 +field OmegaGpuMem kind 8 4 u32 1 +field OmegaGpuMem cpu 16 8 ptr 1 +field OmegaGpuMem va 24 8 u64 1 +field OmegaGpuMem size 32 8 u64 1 +struct OmegaGpuSession 192 8 # EXPERIMENTAL +field OmegaGpuSession dev 0 8 struct:OmegaGpuDeviceHandle 1 +field OmegaGpuSession queue 8 8 struct:OmegaGpuQueueHandle 1 +field OmegaGpuSession pb 16 40 struct:OmegaGpuMem 1 +field OmegaGpuSession cbank 56 40 struct:OmegaGpuMem 1 +field OmegaGpuSession marker 96 40 struct:OmegaGpuMem 1 +field OmegaGpuSession qmd 136 40 struct:OmegaGpuMem 1 +field OmegaGpuSession opens 176 4 u32 1 +field OmegaGpuSession last_open_ns 184 8 u64 1 +struct OmegaGpuScratch 64 8 # STABLE +field OmegaGpuScratch mem 0 40 struct:OmegaGpuMem 1 +field OmegaGpuScratch cap 40 8 u64 1 +field OmegaGpuScratch high_water 48 8 u64 1 +field OmegaGpuScratch reserved 56 1 bool 1 +struct OmegaGpuLaunch 72 8 # STABLE +field OmegaGpuLaunch code_va 0 8 u64 1 +field OmegaGpuLaunch gpr_count 8 4 u32 1 +field OmegaGpuLaunch threads_x 12 4 u32 1 +field OmegaGpuLaunch threads_y 16 4 u32 1 +field OmegaGpuLaunch grid_x 20 4 u32 1 +field OmegaGpuLaunch grid_y 24 4 u32 1 +field OmegaGpuLaunch num_elements 32 8 u64 1 +field OmegaGpuLaunch args 40 8 ptr 1 +field OmegaGpuLaunch n_args 48 4 u32 1 +field OmegaGpuLaunch timeout_ms 56 8 u64 1 +field OmegaGpuLaunch shared_bytes 64 4 u32 1 +field OmegaGpuLaunch spin_us 68 4 u32 1 +struct OmegaGpuParkStats 16 8 # STABLE +field OmegaGpuParkStats buffers 0 4 u32 1 +field OmegaGpuParkStats untracked 4 4 u32 1 +field OmegaGpuParkStats bytes 8 8 u64 1 +fn omega_gpu_session_lock fn() -> () # STABLE +fn omega_gpu_session_unlock fn() -> () # STABLE +fn omega_gpu_session_open fn() -> *mut OmegaGpuSession # STABLE +fn omega_gpu_session_is_open fn() -> bool # STABLE +fn omega_gpu_session_is_blocked fn() -> i32 # STABLE +fn omega_gpu_session_close fn() -> () # STABLE +fn omega_gpu_session_open_count fn() -> u32 # STABLE +fn omega_gpu_session_alloc fn(usize, *mut OmegaGpuMem) -> i32 # STABLE +fn omega_gpu_session_alloc_code fn(usize, *mut OmegaGpuMem) -> i32 # STABLE +fn omega_gpu_session_free fn(*mut OmegaGpuMem) -> () # STABLE +fn omega_gpu_session_sync_to_gpu fn(*const OmegaGpuMem) -> i32 # STABLE +fn omega_gpu_session_sync_to_cpu fn(*const OmegaGpuMem) -> i32 # STABLE +fn omega_gpu_session_scratch fn(*mut OmegaGpuScratch, usize) -> i32 # STABLE +fn omega_gpu_session_scratch_free fn(*mut OmegaGpuScratch) -> () # STABLE +fn omega_gpu_session_launch fn(*const OmegaGpuLaunch, *mut u64, *mut u32) -> i32 # STABLE +fn omega_gpu_session_last_error fn() -> *const c_char # STABLE +fn omega_gpu_session_parked fn(*mut OmegaGpuParkStats) -> () # STABLE +fn omega_gpu_session_is_parked fn(OmegaGpuBufferHandle) -> i32 # STABLE +fn omega_gpu_session_alloc_cached fn(usize, *mut OmegaGpuMem) -> i32 # EXPERIMENTAL +fn omega_gpu_session_scratch_reserve fn(*mut OmegaGpuScratch, usize) -> i32 # EXPERIMENTAL +fn omega_gpu_session_scratch_unreserve fn(*mut OmegaGpuScratch) -> () # EXPERIMENTAL +fn omega_gpu_session_cancel fn() -> () # EXPERIMENTAL +fn omega_gpu_session_recover fn() -> i32 # EXPERIMENTAL +fn omega_gpu_session_recoveries fn() -> u32 # EXPERIMENTAL +fn omega_gpu_session_extra_queue fn(u32, *mut OmegaGpuQueueHandle) -> i32 # EXPERIMENTAL +fn omega_gpu_session_set_platform fn(*const OmegaGpuPlatform, *const OmegaGpuPlatformCaps) -> i32 # EXPERIMENTAL +fn omega_gpu_session_platform fn() -> *const OmegaGpuPlatform # EXPERIMENTAL +fn omega_gpu_session_submit_prefix_words fn() -> u32 # EXPERIMENTAL +fn omega_gpu_session_completion_mode fn() -> OmegaGpuCompletionMode # EXPERIMENTAL +fn omega_gpu_session_now_ns fn() -> u64 # EXPERIMENTAL +fn omega_gpu_host_alloc fn(usize) -> *mut c_void # EXPERIMENTAL +fn omega_gpu_host_calloc fn(usize, usize) -> *mut c_void # EXPERIMENTAL +fn omega_gpu_host_free fn(*mut c_void) -> () # EXPERIMENTAL +# ---- command lists (src/omega_gpu_cmdlist.h) ---- +struct OmegaGpuCmdListOpts 32 8 # EXPERIMENTAL +field OmegaGpuCmdListOpts mode 0 4 enum 1 +field OmegaGpuCmdListOpts barrier 4 4 enum 1 +field OmegaGpuCmdListOpts timeout_ms 8 8 u64 1 +field OmegaGpuCmdListOpts spin_us 16 4 u32 1 +field OmegaGpuCmdListOpts stamps 20 4 i32 1 +field OmegaGpuCmdListOpts skip_launch 24 4 i32 1 +field OmegaGpuCmdListOpts first_barrier_none 28 4 i32 1 +struct OmegaGpuCmdListStats 40 8 # EXPERIMENTAL +field OmegaGpuCmdListStats launches 0 4 u32 1 +field OmegaGpuCmdListStats submits 4 4 u32 1 +field OmegaGpuCmdListStats words 8 4 u32 1 +field OmegaGpuCmdListStats elapsed_ns 16 8 u64 1 +field OmegaGpuCmdListStats host_ns 24 8 u64 1 +field OmegaGpuCmdListStats sems_done 32 4 u32 1 +field OmegaGpuCmdListStats first_missing 36 4 i32 1 +fn omega_gpu_cmdlist_barrier_name fn(OmegaGpuCmdListBarrier) -> *const c_char # EXPERIMENTAL +fn omega_gpu_cmdlist_create fn(u32, *mut *mut OmegaGpuCmdList) -> i32 # EXPERIMENTAL +fn omega_gpu_cmdlist_free fn(*mut OmegaGpuCmdList) -> () # EXPERIMENTAL +fn omega_gpu_cmdlist_reset fn(*mut OmegaGpuCmdList) -> () # EXPERIMENTAL +fn omega_gpu_cmdlist_count fn(*const OmegaGpuCmdList) -> u32 # EXPERIMENTAL +fn omega_gpu_cmdlist_mark_independent fn(*mut OmegaGpuCmdList) -> i32 # EXPERIMENTAL +fn omega_gpu_cmdlist_add fn(*mut OmegaGpuCmdList, *const OmegaGpuLaunch) -> i32 # EXPERIMENTAL +fn omega_gpu_cmdlist_submit fn(*mut OmegaGpuCmdList, *const OmegaGpuCmdListOpts, *mut OmegaGpuCmdListStats) -> i32 # EXPERIMENTAL +fn omega_gpu_cmdlist_is_latched fn() -> i32 # EXPERIMENTAL +fn omega_gpu_cmdlist_stamps fn(*const OmegaGpuCmdList, *mut u64, u32) -> i32 # EXPERIMENTAL +fn omega_gpu_cmdlist_submit_pair fn(*mut OmegaGpuCmdList, *mut OmegaGpuCmdList, *const OmegaGpuCmdListOpts, *mut OmegaGpuCmdListStats, *mut OmegaGpuCmdListStats) -> i32 # EXPERIMENTAL +fn omega_gpu_cmdlist_wait_for fn(*mut OmegaGpuCmdList, *const OmegaGpuCmdList, u32) -> i32 # EXPERIMENTAL +# ---- job engine (src/omega_gpu_engine.h) ---- +struct OmegaGpuTimeouts 32 8 # EXPERIMENTAL +field OmegaGpuTimeouts marker_ms 0 8 u64 1 +field OmegaGpuTimeouts release_semaphore_ms 8 8 u64 1 +field OmegaGpuTimeouts marker2_ms 16 8 u64 1 +field OmegaGpuTimeouts visibility_ms 24 8 u64 1 +struct OmegaGpuJob 128 8 # EXPERIMENTAL +field OmegaGpuJob program 0 8 ptr 1 +field OmegaGpuJob program_len 8 8 u64 1 +field OmegaGpuJob layout 16 4 i32 1 +field OmegaGpuJob element_count 20 4 u32 1 +field OmegaGpuJob input_a 24 8 ptr 1 +field OmegaGpuJob input_a_len 32 8 u64 1 +field OmegaGpuJob input_b 40 8 ptr 1 +field OmegaGpuJob input_b_len 48 8 u64 1 +field OmegaGpuJob output 56 8 ptr 1 +field OmegaGpuJob output_len 64 8 u64 1 +field OmegaGpuJob poison 72 8 ptr 1 +field OmegaGpuJob poison_count 80 8 u64 1 +field OmegaGpuJob timeouts 88 32 struct:OmegaGpuTimeouts 1 +field OmegaGpuJob flags 120 4 u32 1 +struct OmegaGpuResult 208 8 # EXPERIMENTAL +field OmegaGpuResult failure 0 4 i32 1 +field OmegaGpuResult last_state 4 4 i32 1 +field OmegaGpuResult failed_step 8 4 i32 1 +field OmegaGpuResult wait 12 4 i32 1 +field OmegaGpuResult wait_timeout_ms 16 8 u64 1 +field OmegaGpuResult waited_ms 24 8 u64 1 +field OmegaGpuResult drv_rc 32 4 i32 1 +field OmegaGpuResult err_no 36 4 i32 1 +field OmegaGpuResult drv_text 40 128 c_char 128 +field OmegaGpuResult sync_valid 168 4 u32 1 +field OmegaGpuResult marker 172 4 u32 1 +field OmegaGpuResult marker2 176 4 u32 1 +field OmegaGpuResult semaphore 180 4 u32 1 +field OmegaGpuResult retained 184 4 i32 1 +field OmegaGpuResult cleanup_failed 188 4 i32 1 +field OmegaGpuResult n_outputs 192 8 u64 1 +field OmegaGpuResult output_unchanged_words 200 8 u64 1 +struct OmegaGpuBackendDiag 148 4 # EXPERIMENTAL +field OmegaGpuBackendDiag drv_rc 0 4 i32 1 +field OmegaGpuBackendDiag drv_text 4 128 c_char 128 +field OmegaGpuBackendDiag sync_valid 132 4 u32 1 +field OmegaGpuBackendDiag marker 136 4 u32 1 +field OmegaGpuBackendDiag marker2 140 4 u32 1 +field OmegaGpuBackendDiag semaphore 144 4 u32 1 +struct OmegaGpuBackend 128 8 # EXPERIMENTAL +field OmegaGpuBackend ctx 0 8 ptr 1 +field OmegaGpuBackend open_device 8 8 ptr 1 +field OmegaGpuBackend create_channel 16 8 ptr 1 +field OmegaGpuBackend alloc 24 8 ptr 1 +field OmegaGpuBackend copy_in 32 8 ptr 1 +field OmegaGpuBackend fill_poison 40 8 ptr 1 +field OmegaGpuBackend build 48 8 ptr 1 +field OmegaGpuBackend submit 56 8 ptr 1 +field OmegaGpuBackend wait_marker 64 8 ptr 1 +field OmegaGpuBackend wait_marker2 72 8 ptr 1 +field OmegaGpuBackend wait_release_semaphore 80 8 ptr 1 +field OmegaGpuBackend barrier 88 8 ptr 1 +field OmegaGpuBackend copy_out 96 8 ptr 1 +field OmegaGpuBackend diagnostics 104 8 ptr 1 +field OmegaGpuBackend free_buf 112 8 ptr 1 +field OmegaGpuBackend close 120 8 ptr 1 +fn omega_gpu_execute fn(*const OmegaGpuJob, *mut OmegaGpuResult) -> i32 # EXPERIMENTAL +fn omega_gpu_engine_set_backend fn(*const OmegaGpuBackend) -> () # EXPERIMENTAL +fn omega_gpu_engine_is_blocked fn() -> i32 # EXPERIMENTAL +fn omega_gpu_engine_set_clock fn(fn() -> u64) -> () # EXPERIMENTAL +fn omega_gpu_engine_failure_name fn(i32) -> *const c_char # EXPERIMENTAL +fn omega_gpu_engine_state_name fn(i32) -> *const c_char # EXPERIMENTAL +fn omega_gpu_engine_wait_name fn(i32) -> *const c_char # EXPERIMENTAL +fn omega_gpu_engine_step_name fn(i32) -> *const c_char # EXPERIMENTAL +# ---- libraries: carried over unchanged from aien-sovereign-core origin/main 10b4f851d6b082df6c2c477fbab700b551b854be crates/aien-omega-gpu/abi/omega_gpu.manifest ---- +# (matmul, elementwise, attention, serving; all EXPERIMENTAL: shapes follow one model, see docs/runtime/ROADMAP.md 1.3). +# ONE DIFFERENCE from that file: OMEGA_GPU_MATMUL_MAX_CTAS is 1024 here, 64 there (omega 98cecadc, #473, changed the header; sovereign-core pin is older). R12 must bring theirs to match. +# (omega_gpu_session_set_spin_us / _spin_us / _alloc_stats are STABLE session entries; they live in the session section of API.md) +struct OmegaGpuMatmulInfo 160 8 # EXPERIMENTAL +field OmegaGpuMatmulInfo m 0 4 u32 1 +field OmegaGpuMatmulInfo k 4 4 u32 1 +field OmegaGpuMatmulInfo n 8 4 u32 1 +field OmegaGpuMatmulInfo padded_m 12 4 u32 1 +field OmegaGpuMatmulInfo padded_n 16 4 u32 1 +field OmegaGpuMatmulInfo k_slices 20 4 u32 1 +field OmegaGpuMatmulInfo chip_calls 24 4 u32 1 +field OmegaGpuMatmulInfo rows_per_call 28 4 u32 1 +field OmegaGpuMatmulInfo elapsed_ns 32 8 u64 1 +field OmegaGpuMatmulInfo max_abs_err 40 4 f32 1 +field OmegaGpuMatmulInfo max_rel_err 44 4 f32 1 +field OmegaGpuMatmulInfo mismatch_count 48 8 u64 1 +field OmegaGpuMatmulInfo parity_verified 56 1 bool 1 +field OmegaGpuMatmulInfo completion_marker 60 4 u32 1 +field OmegaGpuMatmulInfo kernel_cache_hit 64 1 bool 1 +field OmegaGpuMatmulInfo target_chip 65 64 c_char 64 +field OmegaGpuMatmulInfo sm_architecture 132 4 u32 1 +field OmegaGpuMatmulInfo grid_x 136 4 u32 1 +field OmegaGpuMatmulInfo grid_y 140 4 u32 1 +field OmegaGpuMatmulInfo padded_k 144 4 u32 1 +field OmegaGpuMatmulInfo resident 148 1 bool 1 +field OmegaGpuMatmulInfo oracle_ran 149 1 bool 1 +field OmegaGpuMatmulInfo call_ns 152 8 u64 1 +struct OmegaGpuAllocStats 40 8 # STABLE +field OmegaGpuAllocStats allocs 0 8 u64 1 +field OmegaGpuAllocStats alloc_bytes 8 8 u64 1 +field OmegaGpuAllocStats alloc_failures 16 8 u64 1 +field OmegaGpuAllocStats frees 24 8 u64 1 +field OmegaGpuAllocStats stale_refusals 32 8 u64 1 +struct OmegaGpuServingBounds 44 4 # EXPERIMENTAL +field OmegaGpuServingBounds max_context 0 4 u32 1 +field OmegaGpuServingBounds max_seqs 4 4 u32 1 +field OmegaGpuServingBounds num_q_heads 8 4 u32 1 +field OmegaGpuServingBounds num_kv_heads 12 4 u32 1 +field OmegaGpuServingBounds head_dim 16 4 u32 1 +field OmegaGpuServingBounds kv_block_size 20 4 u32 1 +field OmegaGpuServingBounds max_rows 24 4 u32 1 +field OmegaGpuServingBounds max_k 28 4 u32 1 +field OmegaGpuServingBounds max_n 32 4 u32 1 +field OmegaGpuServingBounds max_n_one_row 36 4 u32 1 +field OmegaGpuServingBounds kernel_slots 40 4 u32 1 +struct OmegaGpuEwInfo 120 8 # EXPERIMENTAL +field OmegaGpuEwInfo chip_calls 0 4 u32 1 +field OmegaGpuEwInfo elapsed_ns 8 8 u64 1 +field OmegaGpuEwInfo completion_marker 16 4 u32 1 +field OmegaGpuEwInfo unwritten_words 20 4 u32 1 +field OmegaGpuEwInfo kernel_cache_hit 24 1 bool 1 +field OmegaGpuEwInfo gpr_count 28 4 u32 1 +field OmegaGpuEwInfo insn_count 32 4 u32 1 +field OmegaGpuEwInfo threads_per_cta 36 4 u32 1 +field OmegaGpuEwInfo ctas_last_launch 40 4 u32 1 +field OmegaGpuEwInfo target_chip 44 64 c_char 64 +field OmegaGpuEwInfo sm_architecture 108 4 u32 1 +field OmegaGpuEwInfo call_ns 112 8 u64 1 +struct OmegaGpuAttnInfo 176 8 # EXPERIMENTAL +field OmegaGpuAttnInfo chip_calls 0 4 u32 1 +field OmegaGpuAttnInfo elapsed_ns 8 8 u64 1 +field OmegaGpuAttnInfo call_ns 16 8 u64 1 +field OmegaGpuAttnInfo completion_marker 24 4 u32 1 +field OmegaGpuAttnInfo unwritten_words 28 4 u32 1 +field OmegaGpuAttnInfo gpr_count 32 4 u32 1 +field OmegaGpuAttnInfo insn_count 36 4 u32 1 +field OmegaGpuAttnInfo kernel_cache_hit 40 1 bool 1 +field OmegaGpuAttnInfo ctas_last_launch 44 4 u32 1 +field OmegaGpuAttnInfo threads_per_cta 48 4 u32 1 +field OmegaGpuAttnInfo target_chip 52 64 c_char 64 +field OmegaGpuAttnInfo sm_architecture 116 4 u32 1 +field OmegaGpuAttnInfo kv_bytes_staged 120 8 u64 1 +field OmegaGpuAttnInfo kv_bytes_naive 128 8 u64 1 +field OmegaGpuAttnInfo kv_blocks_logical 136 4 u32 1 +field OmegaGpuAttnInfo kv_blocks_unique 140 4 u32 1 +field OmegaGpuAttnInfo q_bytes 144 8 u64 1 +field OmegaGpuAttnInfo tab_bytes 152 8 u64 1 +field OmegaGpuAttnInfo out_bytes 160 8 u64 1 +field OmegaGpuAttnInfo kv_source 168 4 u32 1 +struct OmegaGpuKvLayout 64 8 # EXPERIMENTAL +field OmegaGpuKvLayout block_stride_bytes 0 8 u64 1 +field OmegaGpuKvLayout layer_stride_bytes 8 8 u64 1 +field OmegaGpuKvLayout kv_plane_stride_bytes 16 8 u64 1 +field OmegaGpuKvLayout token_stride_bytes 24 8 u64 1 +field OmegaGpuKvLayout head_stride_bytes 32 8 u64 1 +field OmegaGpuKvLayout pool_bytes 40 8 u64 1 +field OmegaGpuKvLayout num_blocks 48 4 u32 1 +field OmegaGpuKvLayout num_layers 52 4 u32 1 +field OmegaGpuKvLayout block_size 56 4 u32 1 +const OMEGA_GPU_MATMUL_OK 0 +const OMEGA_GPU_MATMUL_BAD_ARGS -1 +const OMEGA_GPU_MATMUL_TOO_LARGE -2 +const OMEGA_GPU_MATMUL_CODEGEN_FAIL -3 +const OMEGA_GPU_MATMUL_CHIP_FAIL -4 +const OMEGA_GPU_MATMUL_PARITY_FAIL -5 +const OMEGA_GPU_MATMUL_TILE_M 16 +const OMEGA_GPU_MATMUL_TILE_N 8 +const OMEGA_GPU_MATMUL_TILE_K 16 +const OMEGA_GPU_MATMUL_MAX_CTAS 1024 +const OMEGA_GPU_EW_OK 0 +const OMEGA_GPU_EW_BAD_ARGS -1 +const OMEGA_GPU_EW_TOO_LARGE -2 +const OMEGA_GPU_EW_CODEGEN_FAIL -3 +const OMEGA_GPU_EW_CHIP_FAIL -4 +const OMEGA_GPU_EW_UNWRITTEN -5 +const OMEGA_GPU_ATTN_OK 0 +const OMEGA_GPU_ATTN_BAD_ARGS -1 +const OMEGA_GPU_ATTN_TOO_LARGE -2 +const OMEGA_GPU_ATTN_CODEGEN_FAIL -3 +const OMEGA_GPU_ATTN_CHIP_FAIL -4 +const OMEGA_GPU_ATTN_UNWRITTEN -5 +const OMEGA_GPU_ATTN_KV_STAGED 0 +fn omega_gpu_matmul_bf16 fn(u32, u32, u32, *const u16, *const u16, *mut f32, *mut OmegaGpuMatmulInfo) -> i32 # EXPERIMENTAL +fn omega_gpu_matmul_f32 fn(u32, u32, u32, *const f32, *const f32, *mut f32, *mut OmegaGpuMatmulInfo) -> i32 # EXPERIMENTAL +fn omega_gpu_matmul_rc_name fn(i32) -> *const c_char # EXPERIMENTAL +fn omega_gpu_matmul_cache_clear fn() -> () # EXPERIMENTAL +fn omega_gpu_tensor_upload_bf16 fn(u32, u32, *const u16, *mut *mut OmegaGpuTensor) -> i32 # EXPERIMENTAL +fn omega_gpu_tensor_upload_f32 fn(u32, u32, *const f32, *mut *mut OmegaGpuTensor) -> i32 # EXPERIMENTAL +fn omega_gpu_tensor_free fn(*mut OmegaGpuTensor) -> () # EXPERIMENTAL +fn omega_gpu_tensor_shape fn(*const OmegaGpuTensor, *mut u32, *mut u32) -> () # EXPERIMENTAL +fn omega_gpu_matmul_resident_bf16 fn(u32, *const u16, *const OmegaGpuTensor, *mut f32, *mut OmegaGpuMatmulInfo) -> i32 # EXPERIMENTAL +fn omega_gpu_matmul_resident_f32 fn(u32, *const f32, *const OmegaGpuTensor, *mut f32, *mut OmegaGpuMatmulInfo) -> i32 # EXPERIMENTAL +fn omega_gpu_matmul_last_error fn() -> *const c_char # EXPERIMENTAL +fn omega_gpu_matmul_is_blocked fn() -> i32 # EXPERIMENTAL +fn omega_gpu_device_close fn() -> () # EXPERIMENTAL +fn omega_gpu_matmul_set_cta_budget fn(u32) -> () # EXPERIMENTAL +fn omega_gpu_matmul_cta_budget fn() -> u32 # EXPERIMENTAL +fn omega_gpu_session_set_spin_us fn(u32) -> i32 # STABLE +fn omega_gpu_session_spin_us fn() -> u32 # STABLE +fn omega_gpu_reserve_serving fn(*const OmegaGpuServingBounds) -> i32 # EXPERIMENTAL +fn omega_gpu_serving_release fn() -> () # EXPERIMENTAL +fn omega_gpu_matmul_prepare fn(u32, u32, u32) -> i32 # EXPERIMENTAL +fn omega_gpu_serving_seal fn() -> () # EXPERIMENTAL +fn omega_gpu_session_alloc_stats fn(*mut OmegaGpuAllocStats) -> () # STABLE +fn omega_gpu_rmsnorm_f32 fn(u32, u32, *const f32, *const f32, f32, *mut f32, *mut OmegaGpuEwInfo) -> i32 # EXPERIMENTAL +fn omega_gpu_rope_f32 fn(u32, u32, *const f32, *const f32, *const f32, *mut f32, *mut OmegaGpuEwInfo) -> i32 # EXPERIMENTAL +fn omega_gpu_swiglu_f32 fn(u32, *const f32, *const f32, *mut f32, *mut OmegaGpuEwInfo) -> i32 # EXPERIMENTAL +fn omega_gpu_elementwise_rc_name fn(i32) -> *const c_char # EXPERIMENTAL +fn omega_gpu_gqa_attention_f32 fn(*const f32, *const f32, *const f32, u32, u32, u32, u32, *mut f32, *mut OmegaGpuAttnInfo) -> i32 # EXPERIMENTAL +fn omega_gpu_gqa_attention_rows_f32 fn(*const f32, *const f32, *const f32, u32, u32, u32, u32, u32, *mut f32, *mut OmegaGpuAttnInfo) -> i32 # EXPERIMENTAL +fn omega_gpu_attention_pool_alloc fn(usize, *mut *mut c_void) -> i32 # EXPERIMENTAL +fn omega_gpu_attention_pool_free fn() -> () # EXPERIMENTAL +fn 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 # EXPERIMENTAL +fn 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 # EXPERIMENTAL +fn omega_gpu_attention_rc_name fn(i32) -> *const c_char # EXPERIMENTAL +fn omega_gpu_attention_last_error fn() -> *const c_char # EXPERIMENTAL +# ---- constants of the runtime headers (values blessed from the headers) ---- +const OMEGA_GPU_PLATFORM_ABI_MAJOR 1 +const OMEGA_GPU_PLATFORM_ABI_MINOR 2 +const OMEGA_GPU_POLL_TIMED_OUT 100 +const OMEGA_GPU_HANDLE_SLOTS 4096 +const OMEGA_GPU_HANDLE_DEVICE 1 +const OMEGA_GPU_HANDLE_BUF_DATA 2 +const OMEGA_GPU_HANDLE_BUF_CODE 3 +const OMEGA_GPU_HANDLE_BUF_QUEUE 4 +const OMEGA_GPU_HANDLE_QUEUE 5 +const OMEGA_GPU_HANDLE_KIND_COUNT 6 +const OMEGA_GPU_RIGHT_CPU_READ 1 +const OMEGA_GPU_RIGHT_CPU_WRITE 2 +const OMEGA_GPU_RIGHT_GPU_READ 4 +const OMEGA_GPU_RIGHT_GPU_WRITE 8 +const OMEGA_GPU_RIGHT_GPU_EXEC 16 +const OMEGA_GPU_RIGHT_HOST_POLLED 32 +const OMEGA_GPU_RIGHT_ALL 63 +const OMEGA_GPU_CACHE_GPU_UNCACHED 0 +const OMEGA_GPU_CACHE_GPU_CACHED 1 +const OMEGA_GPU_SVC_TIME 1 +const OMEGA_GPU_SVC_WAIT 2 +const OMEGA_GPU_SVC_LOCK 4 +const OMEGA_GPU_SVC_MMIO 8 +const OMEGA_GPU_SVC_DMA 16 +const OMEGA_GPU_SVC_SYNC 32 +const OMEGA_GPU_SVC_COMPLETION 64 +const OMEGA_GPU_SVC_IRQ 128 +const OMEGA_GPU_SVC_REQUIRED_V1 127 +const OMEGA_GPU_SVC_DEVICE 256 +const OMEGA_GPU_SVC_QUEUE 512 +const OMEGA_GPU_SVC_CLOCK_NS 1024 +const OMEGA_GPU_SVC_HOST_MEM 2048 +const OMEGA_GPU_SVC_REQUIRED_SESSION 3959 +const OMEGA_GPU_SVC_ALL 4095 +const OMEGA_GPU_PLAT_OK 0 +const OMEGA_GPU_PLAT_REFUSED_ARGS 1 +const OMEGA_GPU_PLAT_REFUSED_ABI 2 +const OMEGA_GPU_PLAT_REFUSED_MISSING_SERVICE 3 +const OMEGA_GPU_PLAT_REFUSED_NULL_SERVICE 4 +const OMEGA_GPU_PLAT_REFUSED_BAD_HANDLE 5 +const OMEGA_GPU_PLAT_REFUSED_STALE_HANDLE 6 +const OMEGA_GPU_PLAT_REFUSED_BAD_LENGTH 7 +const OMEGA_GPU_PLAT_REFUSED_BAD_RIGHTS 8 +const OMEGA_GPU_PLAT_REFUSED_BAD_KIND 9 +const OMEGA_GPU_PLAT_REFUSED_CACHE_POLICY 10 +const OMEGA_GPU_PLAT_REFUSED_LIMIT 11 +const OMEGA_GPU_PLAT_REFUSED_BUSY 12 +const OMEGA_GPU_PLAT_REFUSED_DEVICE 13 +const OMEGA_GPU_PLAT_REFUSAL_COUNT 14 +const OMEGA_GPU_SESSION_MAX_SPIN_US 1000000 +const OMEGA_GPU_SESSION_MAX_ARGS 32 +const OMEGA_GPU_SESSION_POLL_SLICE_MS 1 +const OMEGA_GPU_SESSION_LOCK_ID 0 +const OMEGA_GPU_SESSION_SCRATCH_RESERVED -2 +const OMEGA_GPU_SESSION_CANCELLED -3 +const OMEGA_GPU_SESSION_PARK_MAX 512 +const OMEGA_GPU_COMPLETION_POLLING 1 +const OMEGA_GPU_CMDLIST_MAX_LAUNCHES 4096 +const OMEGA_GPU_CMDLIST_BANK_BYTES 1024 +const OMEGA_GPU_CMDLIST_QMD_BYTES 1024 +const OMEGA_GPU_CMDLIST_PCAS 0 +const OMEGA_GPU_CMDLIST_INLINE 1 +const OMEGA_GPU_CMDLIST_BARRIER_WFI 0 +const OMEGA_GPU_CMDLIST_BARRIER_NONE 1 +const OMEGA_GPU_CMDLIST_BARRIER_WFI_ONLY 2 +const OMEGA_GPU_CMDLIST_BARRIER_WFI_DATA 3 +const OMEGA_GPU_CMDLIST_BARRIER_FLUSH_DATA 4 +const OMEGA_GPU_ENGINE_FLAG_NO_C3 1 +const OMEGA_GPU_ENGINE_JOB_OUTPUTS 1 +const OMEGA_GPU_ENGINE_SEMAPHORE_WORDS 1 +const OMEGA_GPU_ENGINE_DRV_TEXT_BYTES 128 +const OMEGA_GPU_SYNC_MARKER 1 +const OMEGA_GPU_SYNC_MARKER2 2 +const OMEGA_GPU_SYNC_SEMAPHORE 4 +const OMEGA_GPU_BACKEND_TIMEOUT 1 +const OMEGA_GPU_BACKEND_UNKNOWN_STATE 2 +const OMEGA_GPU_ENGINE_OK 0 +const OMEGA_GPU_ENGINE_DEVICE_OPEN 1 +const OMEGA_GPU_ENGINE_CHANNEL_CREATE 2 +const OMEGA_GPU_ENGINE_ALLOC 3 +const OMEGA_GPU_ENGINE_PREPARE 4 +const OMEGA_GPU_ENGINE_SUBMIT 5 +const OMEGA_GPU_ENGINE_COMPLETION_WAIT 6 +const OMEGA_GPU_ENGINE_RELEASE_WAIT 7 +const OMEGA_GPU_ENGINE_VISIBILITY_WAIT 8 +const OMEGA_GPU_ENGINE_OUTPUT_UNCHANGED 9 +const OMEGA_GPU_ENGINE_INVALID_ARGS 10 +const OMEGA_GPU_ENGINE_INTERNAL_INVARIANT 11 +const OMEGA_GPU_ENGINE_CLEANUP 12 +const OMEGA_GPU_ENGINE_UNCERTAIN_COMPLETION_BLOCKED 13 +const OMEGA_GPU_ENGINE_FAILURE_COUNT 14 +const OMEGA_GPU_ENGINE_STATE_INITIAL 0 +const OMEGA_GPU_ENGINE_STATE_PREPARED 1 +const OMEGA_GPU_ENGINE_STATE_SUBMITTED 2 +const OMEGA_GPU_ENGINE_STATE_GPU_COMPLETE 3 +const OMEGA_GPU_ENGINE_STATE_OUTPUT_VISIBLE 4 +const OMEGA_GPU_ENGINE_STATE_OUTPUT_PRODUCED 5 +const OMEGA_GPU_ENGINE_STATE_SUCCESS 6 +const OMEGA_GPU_ENGINE_STATE_COUNT 7 +const OMEGA_GPU_ENGINE_WAIT_NONE 0 +const OMEGA_GPU_ENGINE_WAIT_MARKER 1 +const OMEGA_GPU_ENGINE_WAIT_RELEASE_SEMAPHORE 2 +const OMEGA_GPU_ENGINE_WAIT_MARKER2 3 +const OMEGA_GPU_ENGINE_WAIT_COUNT 4 +const OMEGA_GPU_ENGINE_STEP_NONE 0 +const OMEGA_GPU_ENGINE_STEP_VALIDATE 1 +const OMEGA_GPU_ENGINE_STEP_BACKEND_CHECK 2 +const OMEGA_GPU_ENGINE_STEP_BLOCKED 3 +const OMEGA_GPU_ENGINE_STEP_NOT_IMPLEMENTED 4 +const OMEGA_GPU_ENGINE_STEP_OPEN_DEVICE 5 +const OMEGA_GPU_ENGINE_STEP_CREATE_CHANNEL 6 +const OMEGA_GPU_ENGINE_STEP_ALLOC 7 +const OMEGA_GPU_ENGINE_STEP_COPY_IN 8 +const OMEGA_GPU_ENGINE_STEP_FILL_POISON 9 +const OMEGA_GPU_ENGINE_STEP_BUILD 10 +const OMEGA_GPU_ENGINE_STEP_SUBMIT 11 +const OMEGA_GPU_ENGINE_STEP_WAIT_MARKER 12 +const OMEGA_GPU_ENGINE_STEP_WAIT_MARKER2 13 +const OMEGA_GPU_ENGINE_STEP_WAIT_RELEASE_SEMAPHORE 14 +const OMEGA_GPU_ENGINE_STEP_BARRIER 15 +const OMEGA_GPU_ENGINE_STEP_COPY_OUT 16 +const OMEGA_GPU_ENGINE_STEP_SCAN 17 +const OMEGA_GPU_ENGINE_STEP_FREE 18 +const OMEGA_GPU_ENGINE_STEP_CLOSE 19 +const OMEGA_GPU_ENGINE_STEP_CLOCK_CHECK 20 +const OMEGA_GPU_ENGINE_STEP_COUNT 21 +const OMEGA_GPU_LAYOUT_VECTOR_1D 0 +const OMEGA_GPU_LAYOUT_COUNT 1 +const OMEGA_GPU_BUF_SCRATCH 0 +const OMEGA_GPU_BUF_PROGRAM 1 +const OMEGA_GPU_BUF_INPUT_A 2 +const OMEGA_GPU_BUF_INPUT_B 3 +const OMEGA_GPU_BUF_OUTPUT 4 +const OMEGA_GPU_BUF_ROLE_COUNT 5 diff --git a/evidence/RUNTIME-R1-API-62d1d0d6/README.md b/evidence/RUNTIME-R1-API-62d1d0d6/README.md new file mode 100644 index 000000000..ff4ff207e --- /dev/null +++ b/evidence/RUNTIME-R1-API-62d1d0d6/README.md @@ -0,0 +1,16 @@ +# R1 Runtime API check rerun on omega-mv main 62d1d0d6 (#594) + +Branch `w2/594-runtime-api`: `runtime/r1-api@164fb76f` (three commits) cherry-picked onto main +`62d1d0d668f897386a0e311374f8dbcc5c32dde8`. Host only (aarch64 Linux, cc), no GPU, no physics checkout. + +| File | Result | +|---|---| +| `red-old-manifest-on-main.log` | exit 1, 9 FAIL lines: the 164fb76f manifest against main's headers. Main raised `OMEGA_GPU_HANDLE_SLOTS` 1024 -> 4096 (7c61dc28) and `OMEGA_GPU_CMDLIST_MAX_LAUNCHES` 2048 -> 4096 (52dd18a8), so `OmegaGpuHandleTable` grew. The check refuses the drift. | +| `test-runtime-api.log` | exit 0: PASS (96 functions, 28 structs, 237 fields, 159 constants) and all 10 negative controls caught. | + +Manifest changes on this branch: the two constants and the handle-table layout above; new EXPERIMENTAL entries for main's +C5/C4 additions (`omega_gpu_session_recover`, `omega_gpu_session_recoveries`, `omega_gpu_session_extra_queue`, +`omega_gpu_cmdlist_submit_pair`, `omega_gpu_cmdlist_wait_for`) and the field `OmegaGpuCmdListOpts.first_barrier_none` +(added inside the old struct padding, so the size check could not see it: the known blind spot named in API.md section 11). +`omega_gpu_session_latch_uncertain` and `omega_gpu_session_note_module_latch` are listed INTERNAL. +New control `removed-recover` proves a new EXPERIMENTAL entry is checked, not only the STABLE ones. diff --git a/evidence/RUNTIME-R1-API-62d1d0d6/red-old-manifest-on-main.log b/evidence/RUNTIME-R1-API-62d1d0d6/red-old-manifest-on-main.log new file mode 100644 index 000000000..acb4d4348 --- /dev/null +++ b/evidence/RUNTIME-R1-API-62d1d0d6/red-old-manifest-on-main.log @@ -0,0 +1,12 @@ +$ tools/runtime_api_check.sh <164fb76f manifest> . /dev/shm/r1red/w <164fb76f API.md> (headers of main 62d1d0d6) +FAIL: manifest says `struct OmegaGpuHandleTable 17424 8` but the header gives `struct OmegaGpuHandleTable 69648 8` +FAIL: manifest says `field OmegaGpuHandleTable generation 0 4096` but the header gives `field OmegaGpuHandleTable generation 0 16384` +FAIL: manifest says `field OmegaGpuHandleTable kind 4096 4096` but the header gives `field OmegaGpuHandleTable kind 16384 16384` +FAIL: manifest says `field OmegaGpuHandleTable bytes 8192 8192` but the header gives `field OmegaGpuHandleTable bytes 32768 32768` +FAIL: manifest says `field OmegaGpuHandleTable live 16384 1024` but the header gives `field OmegaGpuHandleTable live 65536 4096` +FAIL: manifest says `field OmegaGpuHandleTable nlive 17408 4` but the header gives `field OmegaGpuHandleTable nlive 69632 4` +FAIL: manifest says `field OmegaGpuHandleTable total_bytes 17416 8` but the header gives `field OmegaGpuHandleTable total_bytes 69640 8` +FAIL: manifest says `const OMEGA_GPU_HANDLE_SLOTS 1024` but the header gives `const OMEGA_GPU_HANDLE_SLOTS 4096` +FAIL: manifest says `const OMEGA_GPU_CMDLIST_MAX_LAUNCHES 2048` but the header gives `const OMEGA_GPU_CMDLIST_MAX_LAUNCHES 4096` +RESULT: FAIL (runtime API check) +exit=1 diff --git a/evidence/RUNTIME-R1-API-62d1d0d6/test-runtime-api.log b/evidence/RUNTIME-R1-API-62d1d0d6/test-runtime-api.log new file mode 100644 index 000000000..16bd46773 --- /dev/null +++ b/evidence/RUNTIME-R1-API-62d1d0d6/test-runtime-api.log @@ -0,0 +1,16 @@ +$ make test-runtime-api (w2/594-runtime-api on main 62d1d0d6, 2026-10-30T14:51:44Z) +CC="cc" tools/runtime_api_check.sh docs/runtime/omega_runtime_api.manifest . build/runtime-api/real docs/runtime/API.md +RESULT: PASS (runtime API 0.1: 96 functions, 28 structs, 237 fields, 159 constants match the headers) +CC="cc" tools/runtime_api_negative.sh docs/runtime/omega_runtime_api.manifest . build/runtime-api docs/runtime/API.md +NEGATIVE CONTROL removed-function: FAILED as it must (header disagrees with manifest: fn omega_gpu_session_alloc_code) +NEGATIVE CONTROL missing-version: FAILED as it must (version macro missing: OMEGA_RUNTIME_API_VERSION_MAJOR) +NEGATIVE CONTROL changed-signature: FAILED as it must (header disagrees with manifest: fn omega_gpu_session_free) +NEGATIVE CONTROL changed-struct: FAILED as it must (manifest says `struct OmegaGpuLaunch ) +NEGATIVE CONTROL changed-constant: FAILED as it must (manifest says `const OMEGA_GPU_SESSION_MAX_ARGS ) +NEGATIVE CONTROL version-doc-mismatch: FAILED as it must (must contain the line "Omega Runtime API version:) +NEGATIVE CONTROL stable-without-doc: FAILED as it must (STABLE entry omega_gpu_session_launch has no) +NEGATIVE CONTROL wrong-quoted-signature: FAILED as it must (signature quoted in) +NEGATIVE CONTROL signature-inside-another: FAILED as it must (signature quoted in) +NEGATIVE CONTROL removed-recover: FAILED as it must (header disagrees with manifest: fn omega_gpu_session_recover) +RESULT: PASS (every negative control was caught) +exit=0 diff --git a/evidence/RUNTIME-R1-API-review-fixes/README.md b/evidence/RUNTIME-R1-API-review-fixes/README.md new file mode 100644 index 000000000..df16ac0bd --- /dev/null +++ b/evidence/RUNTIME-R1-API-review-fixes/README.md @@ -0,0 +1,25 @@ +# R1 Runtime API: review findings fixed (#955, omega-mv#594) + +Review record: `docs/runtime/API-REVIEW.md`, review 1 (ApiReview594, head 2908f13a against main 62d1d0d6; the same +tree as PR head 933dcdba). Host only (aarch64 Linux, gcc 13.3.0), no GPU, no physics checkout. + +| File | Result | +|---|---| +| `test-runtime-api.log` | exit 0: PASS (96 functions, 28 structs, 237 fields, 159 constants) and all 13 negative controls caught. | +| `red-stale-internal-and-no-aux-info.log` | exit 1 twice: a name in API.md section 10 that no header declares, and a compiler without `-aux-info`. | + +What changed: +- N1: `tools/runtime_api_check.sh` scans the manifest headers back with gcc `-aux-info`. Every external function they + declare must be a manifest `fn` or be named in API.md section 10; every name there must still be declared. The scan + found 41 declarations in no list; section 10 now names all of them. New controls: `removed-padding-field` + (`OmegaGpuCmdListOpts.first_barrier_none`), `new-header-function`, `internal-unlisted`. +- F1-F3, N5: API.md section 3 and the `omega_gpu_session_recover` header comment no longer cite #518 or claim the RM + client close frees every buffer; the chip effect of the close is stated as intended and not shown + (`evidence/C5-ISOLATION/`), with the unmapped-buffer gap of the Linux reference. The command-list-only latch and + recover's return values are documented. +- F4, F5: which calls take the session lock (the accessors do not; `omega_gpu_matmul_cta_budget` races with + `omega_gpu_matmul_set_cta_budget`), and the hosted build's lock installs the Linux platform. +- F6, F7, N2, N3, N4: section 9.6 wording, the review-state line, `first_barrier_none`, the launch argument checks + (`L` not NULL, `spin_us` bound, `timeout_ms` 0), and INTERNAL comments on four session declarations. + +Not checked here: that the prose is true (review only); the fixes have not been reviewed again. diff --git a/evidence/RUNTIME-R1-API-review-fixes/red-stale-internal-and-no-aux-info.log b/evidence/RUNTIME-R1-API-review-fixes/red-stale-internal-and-no-aux-info.log new file mode 100644 index 000000000..e644e77d6 --- /dev/null +++ b/evidence/RUNTIME-R1-API-review-fixes/red-stale-internal-and-no-aux-info.log @@ -0,0 +1,10 @@ +$ sed "s/^- \`omega_gpu_session_set_error\` (library code/- \`omega_gpu_session_set_error\`, \`omega_gpu_zzz_gone\` (library code/" docs/runtime/API.md > API.md; sh tools/runtime_api_check.sh docs/runtime/omega_runtime_api.manifest . work API.md +FAIL: API.md section 10 names omega_gpu_zzz_gone as INTERNAL but no listed header declares it +RESULT: FAIL (runtime API check) +exit=1 + +$ CC=cc-noaux (a cc wrapper that rejects -aux-info) sh tools/runtime_api_check.sh docs/runtime/omega_runtime_api.manifest . work docs/runtime/API.md +FAIL: the header declaration scan needs a compiler with -aux-info (gcc; set CC=gcc): + cc: error: unrecognized option -aux-info +RESULT: FAIL (runtime API check) +exit=1 diff --git a/evidence/RUNTIME-R1-API-review-fixes/test-runtime-api.log b/evidence/RUNTIME-R1-API-review-fixes/test-runtime-api.log new file mode 100644 index 000000000..fb69dd3c1 --- /dev/null +++ b/evidence/RUNTIME-R1-API-review-fixes/test-runtime-api.log @@ -0,0 +1,19 @@ +$ taskset -c 6-19 nice -n 19 ionice -c3 make test-runtime-api # 2026-10-30T16:34:44Z, tree 933dcdba926e5042c5eea92cd5a36391690beb4b + this commit's edits, cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 +CC="cc" tools/runtime_api_check.sh docs/runtime/omega_runtime_api.manifest . build/runtime-api/real docs/runtime/API.md +RESULT: PASS (runtime API 0.1: 96 functions, 28 structs, 237 fields, 159 constants match the headers) +CC="cc" tools/runtime_api_negative.sh docs/runtime/omega_runtime_api.manifest . build/runtime-api docs/runtime/API.md +NEGATIVE CONTROL removed-function: FAILED as it must (header disagrees with manifest: fn omega_gpu_session_alloc_code) +NEGATIVE CONTROL missing-version: FAILED as it must (version macro missing: OMEGA_RUNTIME_API_VERSION_MAJOR) +NEGATIVE CONTROL changed-signature: FAILED as it must (header disagrees with manifest: fn omega_gpu_session_free) +NEGATIVE CONTROL changed-struct: FAILED as it must (manifest says `struct OmegaGpuLaunch ) +NEGATIVE CONTROL changed-constant: FAILED as it must (manifest says `const OMEGA_GPU_SESSION_MAX_ARGS ) +NEGATIVE CONTROL version-doc-mismatch: FAILED as it must (must contain the line "Omega Runtime API version:) +NEGATIVE CONTROL stable-without-doc: FAILED as it must (STABLE entry omega_gpu_session_launch has no) +NEGATIVE CONTROL wrong-quoted-signature: FAILED as it must (signature quoted in) +NEGATIVE CONTROL signature-inside-another: FAILED as it must (signature quoted in) +NEGATIVE CONTROL removed-recover: FAILED as it must (header disagrees with manifest: fn omega_gpu_session_recover) +NEGATIVE CONTROL removed-padding-field: FAILED as it must (header disagrees with manifest: field OmegaGpuCmdListOpts first_barrier_none) +NEGATIVE CONTROL new-header-function: FAILED as it must (omega_gpu_session.h declares omega_gpu_session_zzz_new, which is neither) +NEGATIVE CONTROL internal-unlisted: FAILED as it must (omega_gpu_session.h declares omega_gpu_session_set_error, which is neither) +RESULT: PASS (every negative control was caught) +exit=0 diff --git a/evidence/RUNTIME-R1-API-review2/README.md b/evidence/RUNTIME-R1-API-review2/README.md new file mode 100644 index 000000000..3ba24da40 --- /dev/null +++ b/evidence/RUNTIME-R1-API-review2/README.md @@ -0,0 +1,15 @@ +# R1 Runtime API: second review (Rev955) findings fixed (#955, omega-mv#594) + +Tree: commit 36f391500d8f24cf9704c4829a71797248df8803 (PR head 7be2c6f7 plus the fixes; base main 62d1d0d6). +Review record: `docs/runtime/API-REVIEW.md`, review 2. Host only (aarch64 Linux, gcc 13.3.0), no GPU, no physics checkout. +Commands ran under `taskset -c 6-19 nice -n 19 ionice -c3`. + +| File | Command | Result | +|---|---|---| +| `test-runtime-api.log` | `make -j2 PHYSICS_DIR=/nonexistent PHYSICS_LOCK_CHECK=0 test-runtime-api` | exit 0: PASS (96 functions, 28 structs, 237 fields, 159 constants), 16/16 negative controls FAILED as they must. | +| `test-runtime-api-mawk.log` | the same with `awk` resolved to mawk 1.3.4 (the awk of Ubuntu runners) | exit 0, 16/16. | +| `red-old-check-new-controls.log` | the new `tools/runtime_api_negative.sh` driving the check script of 7be2c6f7 | exit 1: the three new controls are NOT CAUGHT by the old check. `manifest-fn-named-in-prose` (the reviewer's mutant: `fn omega_gpu_serving_seal` removed from the manifest) gives PASS with 95 functions; `internal-also-manifest` gives PASS; `new-fnptr-function` fails for the wrong name (`declares int`). | +| `aien-test-run.log`, `aien-test-receipt.json` | `aien-test run tests/gates/omega-runtime-api.gate --no-cache` (local release build, sha256 c36cbbd8…, not the CI pin a51042b6) | AIEN_TEST: PASS, receipt commit 36f39150, derived_verdict PASS. | + +Not run: the hosted AIEN Checks run of this gate (the workflow takes the portable gate list from main, so the gate +runs there only after it is merged); any chip behaviour. diff --git a/evidence/RUNTIME-R1-API-review2/aien-test-receipt.json b/evidence/RUNTIME-R1-API-review2/aien-test-receipt.json new file mode 100644 index 000000000..106baaff6 --- /dev/null +++ b/evidence/RUNTIME-R1-API-review2/aien-test-receipt.json @@ -0,0 +1 @@ +{"core":{"binary_sha256":"9d426b59f519cb681334c6296058e8b10907f8a21e23328069cfde7c930e6e11","build_inputs_digest":"ff7b6c1eff887a382c5e04935cc614ce9b16b4b9fba9beabca0daf5704d834a5","checks":[],"commit":"36f391500d8f24cf9704c4829a71797248df8803","commit_unchanged_after":true,"dependencies":[],"derived_verdict":"PASS","env":{"LANG":"en_US.utf8"},"exit_status":0,"gate":"OMEGA-RUNTIME-API","machine":{"arch":"aarch64","cpu_count":14,"cpu_model":"","gb10_present":true,"judge_sha256":"c36cbbd82ae9a844a4fd633607e76e90bb6de37f2cd1d88b30f503f416b17b98","kernel_release":"7.0.0-1019-nvidia","mem_total_kib":127598532,"qemu_available":true},"machine_digest":"505f94353a30400162bfab1bcafaf30d56cd4f1383f622fd5acb05c2c4021296","manifest_digest":"cfb2387f0ec7148477e2a378e22b74a58a4e5a5e495c24997a8b91f121dc123c","mutants":[],"observations":[],"owner":"omega","pins":[],"reason":"","rules":[],"stderr_sha256":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","stdout_sha256":"abe9b8ce05d532092d5f8299f5f2a2a03cbd12ed16a0d8e47c9150a849e317f8","tree_clean_after":true,"tree_clean_before":true},"schema":"aien-test/EvidenceReceiptV1","volatile":{"batch_wait_ms":0,"cache":{"key":"b7695d8d83ce0df05f0b7f6bc96f284ddd4f3d6e1242d3a0c90cebb729238bde","mode":"disabled","reused":false,"reused_from":null},"duration_ms":30156,"finished_utc":"2026-10-30T17:08:01Z","gpu_wait":null,"pool":"host","pool_wait_ms":0,"runner":{"impl":"rust","name":"aien-test","version":"0.1.0"},"started_utc":"2026-10-30T17:07:31Z","target_wait_ms":0,"timeout_exceeded":false}} diff --git a/evidence/RUNTIME-R1-API-review2/aien-test-run.log b/evidence/RUNTIME-R1-API-review2/aien-test-run.log new file mode 100644 index 000000000..b7ec55389 --- /dev/null +++ b/evidence/RUNTIME-R1-API-review2/aien-test-run.log @@ -0,0 +1,3 @@ +RECEIPT <scratch>/aienev2/6972c3d5ec51b3e5525f3b6096267a58941e0f6cfd505baf586cbb5d09517502.json +CACHE not used: --no-cache +AIEN_TEST: PASS diff --git a/evidence/RUNTIME-R1-API-review2/red-old-check-new-controls.log b/evidence/RUNTIME-R1-API-review2/red-old-check-new-controls.log new file mode 100644 index 000000000..93473f603 --- /dev/null +++ b/evidence/RUNTIME-R1-API-review2/red-old-check-new-controls.log @@ -0,0 +1,24 @@ +NEGATIVE CONTROL removed-function: FAILED as it must (header disagrees with manifest: fn omega_gpu_session_alloc_code) +NEGATIVE CONTROL missing-version: FAILED as it must (version macro missing: OMEGA_RUNTIME_API_VERSION_MAJOR) +NEGATIVE CONTROL changed-signature: FAILED as it must (header disagrees with manifest: fn omega_gpu_session_free) +NEGATIVE CONTROL changed-struct: FAILED as it must (manifest says `struct OmegaGpuLaunch ) +NEGATIVE CONTROL changed-constant: FAILED as it must (manifest says `const OMEGA_GPU_SESSION_MAX_ARGS ) +NEGATIVE CONTROL version-doc-mismatch: FAILED as it must (must contain the line "Omega Runtime API version:) +NEGATIVE CONTROL stable-without-doc: FAILED as it must (STABLE entry omega_gpu_session_launch has no) +NEGATIVE CONTROL wrong-quoted-signature: FAILED as it must (signature quoted in) +NEGATIVE CONTROL signature-inside-another: FAILED as it must (signature quoted in) +NEGATIVE CONTROL removed-recover: FAILED as it must (header disagrees with manifest: fn omega_gpu_session_recover) +NEGATIVE CONTROL removed-padding-field: FAILED as it must (header disagrees with manifest: field OmegaGpuCmdListOpts first_barrier_none) +NEGATIVE CONTROL new-header-function: FAILED as it must (omega_gpu_session.h declares omega_gpu_session_zzz_new, which is neither) +NEGATIVE CONTROL internal-unlisted: FAILED as it must (omega_gpu_session.h declares omega_gpu_session_set_error, which is neither) +NEGATIVE CONTROL manifest-fn-named-in-prose: NOT CAUGHT (rc=0, wanted "omega_gpu_serving.h declares omega_gpu_serving_seal, which is neither") +RESULT: PASS (runtime API 0.1: 95 functions, 28 structs, 237 fields, 159 constants match the headers) +NEGATIVE CONTROL internal-also-manifest: NOT CAUGHT (rc=0, wanted "API.md section 10 names omega_gpu_session_launch as INTERNAL but the manifest lists it as a fn") +RESULT: PASS (runtime API 0.1: 96 functions, 28 structs, 237 fields, 159 constants match the headers) +NEGATIVE CONTROL new-fnptr-function: NOT CAUGHT (rc=1, wanted "omega_gpu_session.h declares omega_gpu_session_zzz_fp, which is neither") +FAIL: src/omega_gpu_session.h declares int, which is neither a manifest fn nor named INTERNAL in API.md section 10 +FAIL: src/omega_gpu_session.h declares int, which is neither a manifest fn nor named INTERNAL in API.md section 10 +FAIL: src/omega_gpu_session.h declares int, which is neither a manifest fn nor named INTERNAL in API.md section 10 +RESULT: FAIL (runtime API check) +RESULT: FAIL (a negative control was not caught) +rc=1 diff --git a/evidence/RUNTIME-R1-API-review2/test-runtime-api-mawk.log b/evidence/RUNTIME-R1-API-review2/test-runtime-api-mawk.log new file mode 100644 index 000000000..e711ba1e3 --- /dev/null +++ b/evidence/RUNTIME-R1-API-review2/test-runtime-api-mawk.log @@ -0,0 +1,20 @@ +CC="cc" tools/runtime_api_check.sh docs/runtime/omega_runtime_api.manifest . <scratch>/mawkout/runtime-api/real docs/runtime/API.md +RESULT: PASS (runtime API 0.1: 96 functions, 28 structs, 237 fields, 159 constants match the headers) +CC="cc" tools/runtime_api_negative.sh docs/runtime/omega_runtime_api.manifest . <scratch>/mawkout/runtime-api docs/runtime/API.md +NEGATIVE CONTROL removed-function: FAILED as it must (header disagrees with manifest: fn omega_gpu_session_alloc_code) +NEGATIVE CONTROL missing-version: FAILED as it must (version macro missing: OMEGA_RUNTIME_API_VERSION_MAJOR) +NEGATIVE CONTROL changed-signature: FAILED as it must (header disagrees with manifest: fn omega_gpu_session_free) +NEGATIVE CONTROL changed-struct: FAILED as it must (manifest says `struct OmegaGpuLaunch ) +NEGATIVE CONTROL changed-constant: FAILED as it must (manifest says `const OMEGA_GPU_SESSION_MAX_ARGS ) +NEGATIVE CONTROL version-doc-mismatch: FAILED as it must (must contain the line "Omega Runtime API version:) +NEGATIVE CONTROL stable-without-doc: FAILED as it must (STABLE entry omega_gpu_session_launch has no) +NEGATIVE CONTROL wrong-quoted-signature: FAILED as it must (signature quoted in) +NEGATIVE CONTROL signature-inside-another: FAILED as it must (signature quoted in) +NEGATIVE CONTROL removed-recover: FAILED as it must (header disagrees with manifest: fn omega_gpu_session_recover) +NEGATIVE CONTROL removed-padding-field: FAILED as it must (header disagrees with manifest: field OmegaGpuCmdListOpts first_barrier_none) +NEGATIVE CONTROL new-header-function: FAILED as it must (omega_gpu_session.h declares omega_gpu_session_zzz_new, which is neither) +NEGATIVE CONTROL internal-unlisted: FAILED as it must (omega_gpu_session.h declares omega_gpu_session_set_error, which is neither) +NEGATIVE CONTROL manifest-fn-named-in-prose: FAILED as it must (omega_gpu_serving.h declares omega_gpu_serving_seal, which is neither) +NEGATIVE CONTROL internal-also-manifest: FAILED as it must (API.md section 10 names omega_gpu_session_launch as INTERNAL but the manifest lists it as a fn) +NEGATIVE CONTROL new-fnptr-function: FAILED as it must (omega_gpu_session.h declares omega_gpu_session_zzz_fp, which is neither) +RESULT: PASS (every negative control was caught) diff --git a/evidence/RUNTIME-R1-API-review2/test-runtime-api.log b/evidence/RUNTIME-R1-API-review2/test-runtime-api.log new file mode 100644 index 000000000..8a9b092fa --- /dev/null +++ b/evidence/RUNTIME-R1-API-review2/test-runtime-api.log @@ -0,0 +1,21 @@ +CC="cc" tools/runtime_api_check.sh docs/runtime/omega_runtime_api.manifest . build/runtime-api/real docs/runtime/API.md +RESULT: PASS (runtime API 0.1: 96 functions, 28 structs, 237 fields, 159 constants match the headers) +CC="cc" tools/runtime_api_negative.sh docs/runtime/omega_runtime_api.manifest . build/runtime-api docs/runtime/API.md +NEGATIVE CONTROL removed-function: FAILED as it must (header disagrees with manifest: fn omega_gpu_session_alloc_code) +NEGATIVE CONTROL missing-version: FAILED as it must (version macro missing: OMEGA_RUNTIME_API_VERSION_MAJOR) +NEGATIVE CONTROL changed-signature: FAILED as it must (header disagrees with manifest: fn omega_gpu_session_free) +NEGATIVE CONTROL changed-struct: FAILED as it must (manifest says `struct OmegaGpuLaunch ) +NEGATIVE CONTROL changed-constant: FAILED as it must (manifest says `const OMEGA_GPU_SESSION_MAX_ARGS ) +NEGATIVE CONTROL version-doc-mismatch: FAILED as it must (must contain the line "Omega Runtime API version:) +NEGATIVE CONTROL stable-without-doc: FAILED as it must (STABLE entry omega_gpu_session_launch has no) +NEGATIVE CONTROL wrong-quoted-signature: FAILED as it must (signature quoted in) +NEGATIVE CONTROL signature-inside-another: FAILED as it must (signature quoted in) +NEGATIVE CONTROL removed-recover: FAILED as it must (header disagrees with manifest: fn omega_gpu_session_recover) +NEGATIVE CONTROL removed-padding-field: FAILED as it must (header disagrees with manifest: field OmegaGpuCmdListOpts first_barrier_none) +NEGATIVE CONTROL new-header-function: FAILED as it must (omega_gpu_session.h declares omega_gpu_session_zzz_new, which is neither) +NEGATIVE CONTROL internal-unlisted: FAILED as it must (omega_gpu_session.h declares omega_gpu_session_set_error, which is neither) +NEGATIVE CONTROL manifest-fn-named-in-prose: FAILED as it must (omega_gpu_serving.h declares omega_gpu_serving_seal, which is neither) +NEGATIVE CONTROL internal-also-manifest: FAILED as it must (API.md section 10 names omega_gpu_session_launch as INTERNAL but the manifest lists it as a fn) +NEGATIVE CONTROL new-fnptr-function: FAILED as it must (omega_gpu_session.h declares omega_gpu_session_zzz_fp, which is neither) +RESULT: PASS (every negative control was caught) +rc=0 diff --git a/evidence/RUNTIME-R1-API/negative-missing-version.log b/evidence/RUNTIME-R1-API/negative-missing-version.log new file mode 100644 index 000000000..c542e0797 --- /dev/null +++ b/evidence/RUNTIME-R1-API/negative-missing-version.log @@ -0,0 +1,11 @@ +# negative control: missing-version. Edit applied to a COPY of omega_runtime_api.h: sed '/define OMEGA_RUNTIME_API_VERSION_MAJOR/d' +# diff of the copy against the real header: +12d11 +< #define OMEGA_RUNTIME_API_VERSION_MAJOR 0 +# check output: +FAIL: version macros or headers do not compile: + /tmp/r1neg-missing-version/work/probe.c:7:2: error: #error "version macro missing: OMEGA_RUNTIME_API_VERSION_MAJOR" + 7 | #error "version macro missing: OMEGA_RUNTIME_API_VERSION_MAJOR" + /tmp/r1neg-missing-version/work/probe.c:297:70: error: ‘OMEGA_RUNTIME_API_VERSION_MAJOR’ undeclared (first use in this function); did you mean ‘OMEGA_RUNTIME_API_VERSION_MINOR’? +RESULT: FAIL (runtime API check, compile stage) +# exit code: 1 diff --git a/evidence/RUNTIME-R1-API/negative-removed-function.log b/evidence/RUNTIME-R1-API/negative-removed-function.log new file mode 100644 index 000000000..21502cedb --- /dev/null +++ b/evidence/RUNTIME-R1-API/negative-removed-function.log @@ -0,0 +1,8 @@ +# negative control: removed-function. Edit applied to a COPY of omega_gpu_session.h: sed '/^int omega_gpu_session_alloc_code(/d' +# diff of the copy against the real header: +169d168 +< int omega_gpu_session_alloc_code(size_t code_size, OmegaGpuMem *out); +# check output: +FAIL: header disagrees with manifest: fn omega_gpu_session_alloc_code fn(usize, *mut OmegaGpuMem) -> i32 +RESULT: FAIL (runtime API check, compile stage) +# exit code: 1 diff --git a/evidence/RUNTIME-R1-API/red-signature-inside-another.log b/evidence/RUNTIME-R1-API/red-signature-inside-another.log new file mode 100644 index 000000000..ee4994d16 --- /dev/null +++ b/evidence/RUNTIME-R1-API/red-signature-inside-another.log @@ -0,0 +1,3 @@ +red before green for the signature-inside-another control (2026-10-22T01:26:12Z): API.md copy with 'int32_t omega_gpu_session_open_count(void);' (the header has uint32_t) +old tools/runtime_api_check.sh (be1e4777): exit 0, RESULT: PASS (runtime API 0.1: 91 functions, 28 structs, 236 fields, 159 constants match the headers) +new tools/runtime_api_check.sh: exit 1, FAIL: signature quoted in /tmp/r1red/API.md but in no header: int32_t omega_gpu_session_open_count(void); diff --git a/evidence/RUNTIME-R1-API/test-runtime-api.log b/evidence/RUNTIME-R1-API/test-runtime-api.log new file mode 100644 index 000000000..4fbb36656 --- /dev/null +++ b/evidence/RUNTIME-R1-API/test-runtime-api.log @@ -0,0 +1,15 @@ +$ quiet-build make test-runtime-api (2026-10-22T01:24:25Z, runtime/r1-api after the Opus review fixes) +CC="cc" tools/runtime_api_check.sh docs/runtime/omega_runtime_api.manifest . build/runtime-api/real docs/runtime/API.md +RESULT: PASS (runtime API 0.1: 91 functions, 28 structs, 236 fields, 159 constants match the headers) +CC="cc" tools/runtime_api_negative.sh docs/runtime/omega_runtime_api.manifest . build/runtime-api docs/runtime/API.md +NEGATIVE CONTROL removed-function: FAILED as it must (header disagrees with manifest: fn omega_gpu_session_alloc_code) +NEGATIVE CONTROL missing-version: FAILED as it must (version macro missing: OMEGA_RUNTIME_API_VERSION_MAJOR) +NEGATIVE CONTROL changed-signature: FAILED as it must (header disagrees with manifest: fn omega_gpu_session_free) +NEGATIVE CONTROL changed-struct: FAILED as it must (manifest says `struct OmegaGpuLaunch ) +NEGATIVE CONTROL changed-constant: FAILED as it must (manifest says `const OMEGA_GPU_SESSION_MAX_ARGS ) +NEGATIVE CONTROL version-doc-mismatch: FAILED as it must (must contain the line "Omega Runtime API version:) +NEGATIVE CONTROL stable-without-doc: FAILED as it must (STABLE entry omega_gpu_session_launch has no) +NEGATIVE CONTROL wrong-quoted-signature: FAILED as it must (signature quoted in) +NEGATIVE CONTROL signature-inside-another: FAILED as it must (signature quoted in) +RESULT: PASS (every negative control was caught) +make exit=0 diff --git a/mk/.crumb b/mk/.crumb index e38efa48f..dea85ae91 100644 --- a/mk/.crumb +++ b/mk/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-28T03:06:12Z", + "compiled_at": "2026-10-30T17:07:18Z", "compiler": "crumb-compile/1", - "digest": "sha256:8f0e5cb325040247440527f6b54b65cf72c47ff5adca75b4f32a1ddf2b2d6ade", + "digest": "sha256:2730787e5508fd415a4cbabbb1aa19b9b67350d99b1eaa01e0383eb7168bc705", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 75, - "generated_at_commit": "79b8c1f9c24195c53ac8dad111d35175a4431506", - "source_tree": "sha256:b8302c1e15664dfe98c550a03830f5d4cf75c5451a6c75eed5042e623dea5d10" + "files": 76, + "generated_at_commit": "7be2c6f7a485b50c5c1506ef2e12b319a0dd9f97", + "source_tree": "sha256:7f904e55944fd36ff1468fc1296ee1a30303ef8bf3fc0d502c402a2550f2582a" }, "owner_lane": "", "provenance": { diff --git a/mk/runtime-r1.mk b/mk/runtime-r1.mk new file mode 100644 index 000000000..a6cc401cf --- /dev/null +++ b/mk/runtime-r1.mk @@ -0,0 +1,9 @@ +# Omega runtime R1 (omega-mv#594): the Runtime API manifest checked against the headers. Host only, no GPU, no physics checkout. +# Picked up by `-include mk/*.mk` at the top of the Makefile, so no extra include line is needed. +RUNTIME_API_MANIFEST ?= docs/runtime/omega_runtime_api.manifest +RUNTIME_API_MD ?= docs/runtime/API.md +RUNTIME_API_WORK ?= $(OUT_DIR)/runtime-api +.PHONY: test-runtime-api +test-runtime-api: + CC="$(CC)" tools/runtime_api_check.sh $(RUNTIME_API_MANIFEST) . $(RUNTIME_API_WORK)/real $(RUNTIME_API_MD) + CC="$(CC)" tools/runtime_api_negative.sh $(RUNTIME_API_MANIFEST) . $(RUNTIME_API_WORK) $(RUNTIME_API_MD) diff --git a/src/.crumb b/src/.crumb index 7c4b83da7..99174553c 100644 --- a/src/.crumb +++ b/src/.crumb @@ -188,14 +188,14 @@ } ], "children_root": "sha256:2f729945214be989a74d7c2064ae4ba3c2deb52ebea3f334b459198a7bd032ed", - "compiled_at": "2026-10-30T02:49:13Z", + "compiled_at": "2026-10-30T16:35:37Z", "compiler": "crumb-compile/1", - "digest": "sha256:aaf5acb82fd4c720cd60c85fd6087f636c72a98e2f3740c9295dcfa525dc64d7", + "digest": "sha256:be38bcedfe19615bd7b575135ba0b6cf312ae6781010f417af5fe1eba72136ca", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 568, - "generated_at_commit": "2cb1ccb5d3c1a1ce1cb94a7a3dd3c221395c4e15", - "source_tree": "sha256:7f1fef46a27e8baf5cf567bb590d417ede3767c5f07e714d0f0812af0645bb4b" + "files": 569, + "generated_at_commit": "933dcdba926e5042c5eea92cd5a36391690beb4b", + "source_tree": "sha256:866ebe4eceb71600b53737f76c51a4a50462859c14eaa2dc4da74371fccc389f" }, "owner_lane": "", "provenance": { diff --git a/src/omega_gpu_session.h b/src/omega_gpu_session.h index 8a4ae6727..4772b5982 100644 --- a/src/omega_gpu_session.h +++ b/src/omega_gpu_session.h @@ -118,14 +118,15 @@ typedef struct { uint64_t timeout_ms; /* marker poll; past it the completion is uncertain and the process latches */ uint32_t shared_bytes; /* shared memory per CTA; 0 = the QMD default (1024) */ uint32_t spin_us; /* poll the marker without sleeping for up to this long, then the platform's - poll_word (Linux reference: 50 us sleep-poll) until timeout_ms; 0 = poll_word only */ + poll_word (Linux reference: 50 us sleep-poll) until timeout_ms; 0 = the process-wide setting + (omega_gpu_session_set_spin_us) */ } OmegaGpuLaunch; #define OMEGA_GPU_SESSION_MAX_SPIN_US 1000000u #define OMEGA_GPU_SESSION_MAX_ARGS 32u /* poll_word is called in slices of at most this many ms so a cancel request is seen within one slice */ #define OMEGA_GPU_SESSION_POLL_SLICE_MS 1u -/* ---- platform (ABI 1.1) ---- */ +/* ---- platform (ABI 1.2) ---- */ /* Installs the platform the session runs on. Negotiates caps against OMEGA_GPU_SVC_REQUIRED_SESSION and checks the * table (omega_gpu_platform_check_for). OMEGA_GPU_PLAT_OK, or the refusal; REFUSED_BUSY while the device is open, @@ -224,6 +225,7 @@ void omega_gpu_session_cancel(void); /* Stage of the most recent failure ("" if none). Shared by every API. */ const char *omega_gpu_session_last_error(void); +/* INTERNAL (not part of the Runtime API; docs/runtime/API.md section 10): library code names its failure stage. */ void omega_gpu_session_set_error(const char *stage); /* L136 (roadblock R3): caller holds the lock, device open. Queue i (1..3) past the session's own queue, with its own @@ -232,24 +234,30 @@ void omega_gpu_session_set_error(const char *stage); * VA space); otherwise the platform refuses and this returns -1 with the stage named. Work on different queues is not * ordered against each other. 0 ok. */ int omega_gpu_session_extra_queue(uint32_t i, OmegaGpuQueueHandle *out); -/* L136: latch the process now (uncertain completion seen by a caller that cannot prove it with a queue-0 launch, e.g. a +/* INTERNAL (not part of the Runtime API; docs/runtime/API.md section 10). + * L136: latch the process now (uncertain completion seen by a caller that cannot prove it with a queue-0 launch, e.g. a * list on an extra queue timed out). Parks every session buffer; every later launch of every API is refused. */ void omega_gpu_session_latch_uncertain(const char *why); /* C5: after a latch (a timeout or a cancel after submit), throw the device away and lift the latch, in the same process. - * Takes the lock itself. Runs the on-close hooks (still latched), closes the device (Linux reference: the RM client - * close destroys this process's channels, and so any grid still running on them, then frees every buffer, parked ones - * included) and only then clears the latch and the parked list. Every handle and command list of the old device is - * stale; the next open starts a new device. 0 ok; -1 with the reason: not latched, or the close was refused or reported - * a driver teardown fault (then it stays latched for good: the old grid may still run, the process must exit). */ + * Takes the lock itself. Runs the on-close hooks (still latched), closes the device through the platform, and only + * then clears the latch and the parked list. The Linux reference's RM client close is meant to destroy this process's + * channels, and so any grid still running on them, and to release the driver objects; that has no chip run yet + * (evidence/C5-ISOLATION), and buffers the caller did not free are not unmapped by it (omega_gpu_platform_linux.c, + * ref_device_close). Every handle and command list of the old device is stale; the next open starts a new device. + * A latch noted by a module (omega_gpu_session_note_module_latch) counts as latched. 0 ok; -1 with the reason: not + * latched, latched but no device open, or the close was refused or reported a driver teardown fault (then it stays + * latched for good: the old grid may still run, the process must exit). */ int omega_gpu_session_recover(void); -/* A module that latched itself (the command lists after a timeout whose check launch completed) tells the session, so +/* INTERNAL (not part of the Runtime API; docs/runtime/API.md section 10). + * A module that latched itself (the command lists after a timeout whose check launch completed) tells the session, so * omega_gpu_session_recover accepts it as latched. Launches of other APIs are not refused by it. */ void omega_gpu_session_note_module_latch(void); /* Recoveries so far in this process (a command list latched before the latest recovery no longer blocks). */ uint32_t omega_gpu_session_recoveries(void); -/* Caller holds the lock. Register a function the session calls (lock held, device +/* INTERNAL (not part of the Runtime API; docs/runtime/API.md section 10). + * Caller holds the lock. Register a function the session calls (lock held, device * still open) right before it closes, so an API can drop its resident kernels and * scratch. Up to 8; the same function is registered once. (Taking the lock inside * deadlocked the first call of every API on 2026-10-04: the APIs register from diff --git a/src/omega_runtime_api.h b/src/omega_runtime_api.h new file mode 100644 index 000000000..89e2acbee --- /dev/null +++ b/src/omega_runtime_api.h @@ -0,0 +1,16 @@ +#ifndef OMEGA_RUNTIME_API_H +#define OMEGA_RUNTIME_API_H +/* + * Omega Runtime API version (R1, omega-mv#594). Defines the version and nothing else; includes nothing. + * + * The API is the set of entries listed in docs/runtime/omega_runtime_api.manifest and described in + * docs/runtime/API.md, which also states the compatibility rule: + * MINOR goes up when something is added; MAJOR goes up when a STABLE entry is removed, renamed or changes + * signature, layout, constant value or documented behaviour. MAJOR 0 is the first, written-down version. + * tools/runtime_api_check.sh (make test-runtime-api) fails when this header, the manifest and API.md disagree. + */ +#define OMEGA_RUNTIME_API_VERSION_MAJOR 0 +#define OMEGA_RUNTIME_API_VERSION_MINOR 1 +/* One number for #if comparisons: (MAJOR << 16) | MINOR. */ +#define OMEGA_RUNTIME_API_VERSION ((OMEGA_RUNTIME_API_VERSION_MAJOR << 16) | OMEGA_RUNTIME_API_VERSION_MINOR) +#endif diff --git a/tests/.crumb b/tests/.crumb index 5fbfcb29c..73d5440c8 100644 --- a/tests/.crumb +++ b/tests/.crumb @@ -302,14 +302,14 @@ } ], "children_root": "sha256:0c57282ff8cf1d34e5685e2729755f2978917e66debb5423961033be9d25c902", - "compiled_at": "2026-10-30T12:31:50Z", + "compiled_at": "2026-10-30T17:08:24Z", "compiler": "crumb-compile/1", - "digest": "sha256:5395ff8ff9afceebe8e453788f80a3064b831513cc4cb92fd55869115e06b874", + "digest": "sha256:b7868bcc6bf0bf3134f15be5ca3a36041aca987b0ad65eb4ae8a6651712ae4d2", "evidence_files": 16, "evidence_root": "sha256:96d08097822ad95f4e562c19e0ba5df5a035774c48632f1832912c40a27bd27a", - "files": 1386, - "generated_at_commit": "52a82f392fa513ebbc2d9d719a0f14c385289b06", - "source_tree": "sha256:a3b853bb9c0edfc5f1413ccaa2698cc6ea920f2e8795756121667cc9d37f6679" + "files": 1387, + "generated_at_commit": "36f391500d8f24cf9704c4829a71797248df8803", + "source_tree": "sha256:56b26e7f1d1a8f6e6d5c2f5df3ec5387f731d936c5b25e880531d6c4ae19799f" }, "owner_lane": "", "provenance": { diff --git a/tests/gates/omega-runtime-api.gate b/tests/gates/omega-runtime-api.gate new file mode 100644 index 000000000..3fce55276 --- /dev/null +++ b/tests/gates/omega-runtime-api.gate @@ -0,0 +1,24 @@ +# tests/gates/omega-runtime-api.gate +# Mirrors hosted: no dedicated workflow; as a portable gate it runs in the AIEN Checks portable smoke set (aien-verification.yml) +# requires: portable: the tree plus gcc (-aux-info), make, perl, sed and awk; no GPU, no physics checkout, no sibling repo. +gate: OMEGA-RUNTIME-API +manifest_version: 2 +owner: omega +requires: + - portable +inputs: + - docs/runtime/ + - mk/runtime-r1.mk + - src/ + - tools/runtime_api_check.sh + - tools/runtime_api_negative.sh + - tests/gates/ +run: + exec: tests/gates/run.sh + args: ["runtime-api"] +expects: + exit: 0 + verdict: PASS +timeout: 5m +exactness: EXACT +cache_scope: portable diff --git a/tests/gates/run.sh b/tests/gates/run.sh index 66da8e1a9..cac1f85fd 100755 --- a/tests/gates/run.sh +++ b/tests/gates/run.sh @@ -310,6 +310,9 @@ case "$step" in obs env_files_found false echo "Zero plaintext .env files verified." ;; + runtime-api) # omega-mv#594: the Runtime API manifest against the C headers, plus its negative controls. + # Host only (gcc for -aux-info), no GPU, no physics checkout. + make $NOPHYS test-runtime-api ;; om-units) # The C entry points whose algorithm is Omega (om/units.sh): omc born from the seed here, # the generator pinned by om/omega-bridge.lock; regenerated binding, SHA-256 and BLAKE3 # byte parity against the C they replaced, and the BLAKE3 mutants. NOT_RUN (3) without tools. diff --git a/tools/.crumb b/tools/.crumb index e9e4932b5..0caf3c5a9 100644 --- a/tools/.crumb +++ b/tools/.crumb @@ -62,14 +62,14 @@ } ], "children_root": "sha256:8d3d3b952374b3b72e667521f07bf028c4c02bcefff772ad1a71cfff3e5266f2", - "compiled_at": "2026-10-30T11:28:28Z", + "compiled_at": "2026-10-30T17:07:18Z", "compiler": "crumb-compile/1", - "digest": "sha256:308db0e6cf45c0a48f01f5f5f228450f191389de68006915b9ecf9c65b9a2e29", + "digest": "sha256:1f31b07e6e98823c1e7681b39e87da59c370fa4c187c4536accbed82e621161b", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 298, - "generated_at_commit": "a8a6a3d3c47ce797430f045edc5eae11594ba36d", - "source_tree": "sha256:acd1f1b0080968db950791b4eb2dce39bb0289dc0c2e8794bfc7449023446105" + "files": 300, + "generated_at_commit": "7be2c6f7a485b50c5c1506ef2e12b319a0dd9f97", + "source_tree": "sha256:a81ce1d239699d5c9e13c5802b6d8b48252d38afd26dfbfbbcce010c34dc7950" }, "owner_lane": "", "provenance": { diff --git a/tools/runtime_api_check.sh b/tools/runtime_api_check.sh new file mode 100755 index 000000000..74b6af9af --- /dev/null +++ b/tools/runtime_api_check.sh @@ -0,0 +1,195 @@ +#!/bin/sh +# runtime_api_check.sh -- host check of the Omega Runtime API manifest against the C headers (no GPU, no physics). +# +# tools/runtime_api_check.sh [--bless] MANIFEST ROOT WORK_DIR [API_MD] +# +# MANIFEST docs/runtime/omega_runtime_api.manifest (line format: docs/runtime/API.md, "The manifest") +# ROOT directory the manifest's `header` paths are relative to (the omega checkout; a copy in the negative controls) +# WORK_DIR scratch directory for the generated probe +# API_MD optional: also check that API.md states the version and has a section for every STABLE entry +# +# What it does: writes a C probe from the manifest and compiles it against the headers named there. +# - every `fn` line becomes a compile-time type-equality check on the function itself, so a removed function, a changed argument +# type or a changed return type is a compile error (-Werror=incompatible-pointer-types); +# - every `struct`/`field`/`const` line becomes a printf of sizeof/alignof/offsetof/value, compared with the manifest; +# - the version macros OMEGA_RUNTIME_API_VERSION_MAJOR/MINOR must exist (#error otherwise) and equal the manifest. +# With API_MD it also scans the headers back (gcc -aux-info): every external function a listed header declares must be a +# manifest `fn` or be a leading name of a bullet in API.md section 10 (INTERNAL), never both, and every such name must still be declared. So a new public +# function is seen. Not seen: a new struct or constant (no manifest line, nothing to compare), a field added inside struct +# padding that the manifest does not list (the struct size would not change), and a field that changes type but keeps its +# size (int -> unsigned). sovereign-core's Rust checker, which reads field names, covers the field cases later (R12). +# It does not link the library and does not touch the GPU. +# --bless prints the manifest to stdout with struct/field/const numbers taken from the headers (review the diff). +# Exit 0 = PASS, 1 = FAIL (each mismatch printed as "FAIL: ..."), 2 = usage. +set -u +BLESS=0 +if [ "${1:-}" = "--bless" ]; then BLESS=1; shift; fi +[ $# -ge 3 ] || { echo "usage: $0 [--bless] MANIFEST ROOT WORK_DIR [API_MD]" >&2; exit 2; } +MANIFEST=$1; ROOT=$(cd "$2" && pwd) || exit 2; WORK=$3; APIMD=${4:-} +CC=${CC:-cc} +mkdir -p "$WORK" || exit 2 +PROBE=$WORK/probe.c; ITEMS=$WORK/items.txt; GOT=$WORK/got.txt; WANT=$WORK/want.txt +fail=0 +say_fail() { echo "FAIL: $*"; fail=1; } + +# ---- 1. manifest -> probe source ------------------------------------------------------------------------- +awk -v root="$ROOT" -v items="$ITEMS" ' +function trim(s) { gsub(/^[ \t]+|[ \t]+$/, "", s); return s } +function base(t) { + if (t == "u8") return "uint8_t"; if (t == "u16") return "uint16_t"; if (t == "u32") return "uint32_t" + if (t == "u64") return "uint64_t"; if (t == "i8") return "int8_t"; if (t == "i16") return "int16_t" + if (t == "i32") return "int32_t"; if (t == "i64") return "int64_t"; if (t == "f32") return "float" + if (t == "f64") return "double"; if (t == "usize") return "size_t"; if (t == "c_char") return "char" + if (t == "c_void" || t == "()" || t == "") return "void" + return t +} +function ctype(t, r) { + t = trim(t) + if (t ~ /^\*const /) { r = ctype(substr(t, 8)); return (r ~ /\*$/) ? r " const *" : "const " r " *" } + if (t ~ /^\*mut /) { return ctype(substr(t, 6)) " *" } + if (t ~ /^fn\(/) { nfp++; fptd = fptd "typedef " fnsig(t, "(*FP" nfp ")") ";\n"; return "FP" nfp } + return base(t) +} +# "fn(a, b) -> r" as a C declarator named nm +function fnsig(s, nm, depth, i, c, cl, params, ret, n, parts, k, out) { + s = trim(s); sub(/^fn/, "", s); s = trim(s) + depth = 0; cl = 0 + for (i = 1; i <= length(s); i++) { c = substr(s, i, 1) + if (c == "(") depth++ + if (c == ")") { depth--; if (depth == 0) { cl = i; break } } } + params = substr(s, 2, cl - 2); ret = trim(substr(s, cl + 1)); sub(/^->/, "", ret) + n = splitparams(params, parts); out = "" + for (k = 1; k <= n; k++) out = out (k > 1 ? ", " : "") ctype(parts[k]) + if (n == 0) out = "void" + return ctype(ret) " " nm "(" out ")" +} +function splitparams(s, parts, i, c, depth, cur, n) { + n = 0; cur = ""; depth = 0 + for (i = 1; i <= length(s); i++) { c = substr(s, i, 1) + if (c == "(") depth++ + if (c == ")") depth-- + if (c == "," && depth == 0) { parts[++n] = trim(cur); cur = ""; continue } + cur = cur c } + if (trim(cur) != "") parts[++n] = trim(cur) + return n +} +function item(line) { k++; print k "\t" line > items; return sprintf("#if !defined(ONLY) || ONLY == %d\n", k) } +BEGIN { k = 0; nfp = 0; fptd = "" } +{ line = $0; sub(/#.*/, "", line); line = trim(line); if (line == "") next + nw = split(line, w, /[ \t]+/) + if (w[1] == "header") { inc = inc "#include \"" root "/" w[2] "\"\n"; next } + if (w[1] == "abi") next + if (w[1] == "struct") { body = body item(line) " printf(\"struct " w[2] " %zu %zu\\n\", sizeof(" w[2] "), _Alignof(" w[2] "));\n#endif\n"; next } + if (w[1] == "field") { body = body item(line) " printf(\"field " w[2] " " w[3] " %zu %zu\\n\", offsetof(" w[2] ", " w[3] "), sizeof(((" w[2] " *)0)->" w[3] "));\n#endif\n"; next } + if (w[1] == "const") { body = body item(line) " printf(\"const " w[2] " %lld\\n\", (long long)(" w[2] "));\n#endif\n"; next } + if (w[1] == "fn") { rest = line; sub(/^fn[ \t]+[^ \t]+[ \t]+/, "", rest) + decl = decl item(line) "_Static_assert(__builtin_types_compatible_p(__typeof__(" w[2] "), " fnsig(rest, "") "), \"signature of " w[2] "\");\n#endif\n"; next } + print "manifest: unknown or malformed line: " $0 > "/dev/stderr"; bad = 1 } +END { + print "#include <stdio.h>\n#include <stddef.h>\n#include <stdint.h>\n#include <stdbool.h>" + print "#include \"" root "/src/omega_runtime_api.h\"" + print "#ifndef OMEGA_RUNTIME_API_VERSION_MAJOR\n#error \"version macro missing: OMEGA_RUNTIME_API_VERSION_MAJOR\"\n#endif" + print "#ifndef OMEGA_RUNTIME_API_VERSION_MINOR\n#error \"version macro missing: OMEGA_RUNTIME_API_VERSION_MINOR\"\n#endif" + printf "%s", inc + printf "%s", fptd + printf "%s", decl + print "int main(void) {\n printf(\"const OMEGA_RUNTIME_API_VERSION_MAJOR %lld\\n\", (long long)(OMEGA_RUNTIME_API_VERSION_MAJOR));" + print " printf(\"const OMEGA_RUNTIME_API_VERSION_MINOR %lld\\n\", (long long)(OMEGA_RUNTIME_API_VERSION_MINOR));" + printf "%s", body + print " return 0;\n}" + exit bad +}' "$MANIFEST" > "$PROBE" || { echo "FAIL: manifest could not be turned into a probe"; exit 1; } + +# ---- 2. compile (all at once; on failure name each failing manifest line) -------------------------------- +CFL="-std=gnu11 -Wall -Wextra -Werror -Werror=implicit-function-declaration -D_GNU_SOURCE -I$ROOT/src" +if ! $CC $CFL -o "$WORK/probe" "$PROBE" 2> "$WORK/cc.err"; then + named=0 + if ! $CC $CFL -DONLY=0 -fsyntax-only "$PROBE" 2> "$WORK/cc0.err"; then + say_fail "version macros or headers do not compile:"; grep -m3 error "$WORK/cc0.err" | sed "s/^/ /" + else + while IFS=" " read -r n text; do + if ! $CC $CFL -DONLY="$n" -fsyntax-only "$PROBE" 2> /dev/null; then say_fail "header disagrees with manifest: $text"; named=1; fi + done < "$ITEMS" + if [ $named = 0 ]; then say_fail "probe does not compile:"; grep -m5 'error' "$WORK/cc.err" | sed 's/^/ /'; fi + fi + echo "RESULT: FAIL (runtime API check, compile stage)"; exit 1 +fi +"$WORK/probe" > "$GOT" || { echo "FAIL: probe crashed"; exit 1; } + +# ---- 3. bless or compare --------------------------------------------------------------------------------- +if [ $BLESS = 1 ]; then + awk 'NR == FNR { g[$1 " " $2 (($1 == "field") ? " " $3 : "")] = $0; next } + { raw = $0; line = raw; sub(/#.*/, "", line); n = split(line, w, /[ \t]+/); cm = "" + if (match(raw, /#.*/)) cm = " " substr(raw, RSTART) + if (w[1] == "struct") { split(g["struct " w[2]], v, " "); print "struct " w[2] " " v[3] " " v[4] cm; next } + if (w[1] == "field") { split(g["field " w[2] " " w[3]], v, " "); print "field " w[2] " " w[3] " " v[4] " " v[5] " " w[6] " " w[7] cm; next } + if (w[1] == "const") { split(g["const " w[2]], v, " "); print "const " w[2] " " v[3] cm; next } + print raw }' "$GOT" "$MANIFEST" + exit 0 +fi + +# manifest facts without kind/count and without comments, in file order +awk '{ sub(/#.*/, ""); n = split($0, w, /[ \t]+/); if (w[1] == "struct") print "struct " w[2] " " w[3] " " w[4] + else if (w[1] == "field") print "field " w[2] " " w[3] " " w[4] " " w[5]; else if (w[1] == "const") print "const " w[2] " " w[3] }' "$MANIFEST" > "$WANT" +while IFS= read -r l; do + grep -qxF "$l" "$GOT" || { key=$(echo "$l" | awk '{ print $1 " " $2 (($1 == "field") ? " " $3 : "") }') + have=$(grep -F "$key " "$GOT" | head -1); say_fail "manifest says \`$l\` but the header gives \`${have:-(absent)}\`"; } +done < "$WANT" + +# manifest sanity: tier tag on every struct/fn line, field size matches its kind, version consts present +awk '{ raw = $0; line = raw; sub(/#.*/, "", line); n = split(line, w, /[ \t]+/) + if (w[1] == "struct" || w[1] == "fn") { if (raw !~ /#[ \t]*(STABLE|EXPERIMENTAL)([ \t]|$)/) print "FAIL: " w[1] " " w[2] " has no STABLE/EXPERIMENTAL tag" } + if (w[1] == "field") { ks["u8"]=1; ks["i8"]=1; ks["bool"]=1; ks["c_char"]=1; ks["u16"]=2; ks["i16"]=2; ks["u32"]=4; ks["i32"]=4; ks["f32"]=4 + ks["enum"]=4; ks["u64"]=8; ks["i64"]=8; ks["f64"]=8; ks["ptr"]=8 + if (w[6] in ks && w[5] != ks[w[6]] * w[7]) print "FAIL: field " w[2] "." w[3] " size " w[5] " does not match kind " w[6] " x " w[7] } }' "$MANIFEST" > "$WORK/sanity.txt" +if [ -s "$WORK/sanity.txt" ]; then cat "$WORK/sanity.txt"; fail=1; fi +vmaj=$(awk '$1 == "const" && $2 == "OMEGA_RUNTIME_API_VERSION_MAJOR" { print $3 }' "$MANIFEST") +vmin=$(awk '$1 == "const" && $2 == "OMEGA_RUNTIME_API_VERSION_MINOR" { print $3 }' "$MANIFEST") +[ -n "$vmaj" ] && [ -n "$vmin" ] || say_fail "manifest does not list OMEGA_RUNTIME_API_VERSION_MAJOR and _MINOR" + +# API.md: states the version, has a section for every STABLE entry and mentions every EXPERIMENTAL one +if [ -n "$APIMD" ]; then + grep -q "^Omega Runtime API version: $vmaj\.$vmin\$" "$APIMD" || say_fail "$APIMD must contain the line \"Omega Runtime API version: $vmaj.$vmin\"" + awk '{ raw = $0; line = raw; sub(/#.*/, "", line); split(line, w, /[ \t]+/) + if ((w[1] == "fn" || w[1] == "struct") && match(raw, /#[ \t]*(STABLE|EXPERIMENTAL)/)) { t = substr(raw, RSTART); print w[2], (t ~ /STABLE/ && t !~ /EXPERIMENTAL/) ? "STABLE" : "EXPERIMENTAL" } }' "$MANIFEST" | + while read -r name tier; do + if [ "$tier" = STABLE ]; then grep -q "^#### \`$name\`" "$APIMD" || echo "FAIL: STABLE entry $name has no \"#### \`$name\`\" section in $APIMD" + else grep -qF "\`$name\`" "$APIMD" || echo "FAIL: EXPERIMENTAL entry $name is not mentioned in $APIMD"; fi + done > "$WORK/apimd.txt" + if [ -s "$WORK/apimd.txt" ]; then cat "$WORK/apimd.txt"; fail=1; fi + # every C signature quoted in API.md (lines inside a plain ```c fence that end in `);`) must be in a header, comments removed + for h in $(awk '$1 == "header" { print $2 }' "$MANIFEST"); do perl -0777 -pe 's{/\*.*?\*/}{}gs' "$ROOT/$h"; done | tr '\n' ' ' | sed 's/[[:space:]][[:space:]]*/ /g' | sed 's/^/ /' > "$WORK/headers.norm" + awk '/^```c$/ { f = 1; next } /^```/ { f = 0 } f && /\);[ \t]*$/ { print }' "$APIMD" | sed 's/[[:space:]][[:space:]]*/ /g; s/^ //; s/ $//' | + while IFS= read -r sig; do grep -qF -- " $sig" "$WORK/headers.norm" || echo "FAIL: signature quoted in $APIMD but in no header: $sig"; done > "$WORK/sigs.txt" + if [ -s "$WORK/sigs.txt" ]; then cat "$WORK/sigs.txt"; fail=1; fi + # headers -> manifest: every external function a listed header declares is a manifest `fn` or is named INTERNAL in + # API.md section 10, and every name section 10 lists is still declared. gcc -aux-info writes each declaration with the + # file it came from, so a function added to a header without a manifest line or an INTERNAL entry fails here. + # A name is INTERNAL only as a leading token of a section-10 bullet ("- `a`, `b` (prose `c`)": a and b, not c), so a + # manifest function mentioned in the prose is not taken as INTERNAL; a name that is both a manifest fn and INTERNAL fails. + if $CC $CFL -fsyntax-only -aux-info "$WORK/aux.txt" "$PROBE" 2> "$WORK/aux.err"; then + awk '/^## 10\./ { s = 1; next } /^## / { s = 0 } s && /^- `/ { t = substr($0, 3) + while (match(t, /^`omega_[a-z0-9_]+`/)) { print substr(t, 2, RLENGTH - 2); t = substr(t, RLENGTH + 1); if (t !~ /^, `/) break; t = substr(t, 3) } }' "$APIMD" | sort -u > "$WORK/internal.txt" + awk -v internal="$WORK/internal.txt" 'BEGIN { while ((getline l < internal) > 0) in10[l] = 1 } + FNR == NR { if ($1 == "header") hdr[$2] = 1; if ($1 == "fn") fn[$2] = 1; next } + /^\/\* .* \*\/ extern / { f = $2; sub(/:[0-9]+:[A-Z]+$/, "", f); listed = 0 + for (h in hdr) if (f == h || substr(f, length(f) - length(h)) == "/" h) { listed = 1; hf = h } + if (!listed) next + # the name is the identifier before the first "(" that does not open a declarator "(*" (a function returning a + # function pointer is written "int (*name (void)) (int)") + s = $0; sub(/^\/\* [^*]* \*\/ extern /, "", s); pre = "" + while ((i = index(s, "(")) > 0) { if (substr(s, i + 1) ~ /^ *\*/) { pre = pre substr(s, 1, i); s = substr(s, i + 1); continue } + pre = pre substr(s, 1, i - 1); break } + sub(/ +$/, "", pre); n = split(pre, a, /[^A-Za-z0-9_]+/); nm = a[n]; seen[nm] = 1 + if (!(nm in fn) && !(nm in in10)) print "FAIL: " hf " declares " nm ", which is neither a manifest fn nor named INTERNAL in API.md section 10" } + END { for (l in in10) { if (!(l in seen)) print "FAIL: API.md section 10 names " l " as INTERNAL but no listed header declares it" + if (l in fn) print "FAIL: API.md section 10 names " l " as INTERNAL but the manifest lists it as a fn" } }' "$MANIFEST" "$WORK/aux.txt" | sort > "$WORK/decls.txt" + if [ -s "$WORK/decls.txt" ]; then cat "$WORK/decls.txt"; fail=1; fi + else + say_fail "the header declaration scan needs a compiler with -aux-info (gcc; set CC=gcc):"; grep -m3 . "$WORK/aux.err" | sed 's/^/ /' + fi +fi + +nfn=$(grep -c '^fn ' "$MANIFEST"); nst=$(grep -c '^struct ' "$MANIFEST"); nfl=$(grep -c '^field ' "$MANIFEST"); nco=$(grep -c '^const ' "$MANIFEST") +if [ $fail = 0 ]; then echo "RESULT: PASS (runtime API $vmaj.$vmin: $nfn functions, $nst structs, $nfl fields, $nco constants match the headers)"; exit 0; fi +echo "RESULT: FAIL (runtime API check)"; exit 1 diff --git a/tools/runtime_api_negative.sh b/tools/runtime_api_negative.sh new file mode 100755 index 000000000..96af610d5 --- /dev/null +++ b/tools/runtime_api_negative.sh @@ -0,0 +1,45 @@ +#!/bin/sh +# runtime_api_negative.sh -- negative controls for tools/runtime_api_check.sh (R1, omega-mv#594). +# +# tools/runtime_api_negative.sh MANIFEST ROOT WORK_DIR API_MD +# +# Copies the headers to WORK_DIR, breaks the copy in one way at a time and runs the check on it. Each break must make +# the check FAIL and say the expected thing; if the check still passes, this script fails (the check cannot see that +# class of change). The real headers are never touched. +set -u +[ $# -eq 4 ] || { echo "usage: $0 MANIFEST ROOT WORK_DIR API_MD" >&2; exit 2; } +MANIFEST=$1; ROOT=$(cd "$2" && pwd) || exit 2; WORK=$3; APIMD=$4 +HERE=$(dirname "$0") +bad=0 +# control NAME EXPECTED_TEXT FILE SED_EXPR (FILE: a header under src/, API.md, or manifest) +control() { + name=$1; expect=$2; file=$3; expr=$4 + d=$WORK/neg-$name; rm -rf "$d"; mkdir -p "$d/src"; cp "$ROOT"/src/omega_*.h "$d/src/"; cp "$APIMD" "$d/API.md"; cp "$MANIFEST" "$d/manifest" + case $file in + API.md) sed -i "$expr" "$d/API.md"; orig=$APIMD; new=$d/API.md ;; + manifest) sed -i "$expr" "$d/manifest"; orig=$MANIFEST; new=$d/manifest ;; + *) sed -i "$expr" "$d/src/$file"; orig=$ROOT/src/$file; new=$d/src/$file ;; + esac + if cmp -s "$orig" "$new"; then echo "NEGATIVE CONTROL $name: BROKEN (the edit changed nothing)"; bad=1; return; fi + out=$("$HERE/runtime_api_check.sh" "$d/manifest" "$d" "$d/work" "$d/API.md" 2>&1); rc=$? + if [ $rc -ne 0 ] && printf '%s\n' "$out" | grep -qF "$expect"; then echo "NEGATIVE CONTROL $name: FAILED as it must ($expect)" + else echo "NEGATIVE CONTROL $name: NOT CAUGHT (rc=$rc, wanted \"$expect\")"; printf '%s\n' "$out" | head -5; bad=1; fi +} +control removed-function "header disagrees with manifest: fn omega_gpu_session_alloc_code" omega_gpu_session.h '/^int omega_gpu_session_alloc_code(/d' +control missing-version "version macro missing: OMEGA_RUNTIME_API_VERSION_MAJOR" omega_runtime_api.h '/define OMEGA_RUNTIME_API_VERSION_MAJOR/d' +control changed-signature "header disagrees with manifest: fn omega_gpu_session_free" omega_gpu_session.h 's/^void omega_gpu_session_free(OmegaGpuMem \*m);/void omega_gpu_session_free(const OmegaGpuMem *m);/' +control changed-struct 'manifest says `struct OmegaGpuLaunch ' omega_gpu_session.h 's/uint64_t timeout_ms; \/\*/uint32_t timeout_ms; \/*/' +control changed-constant 'manifest says `const OMEGA_GPU_SESSION_MAX_ARGS ' omega_gpu_session.h 's/OMEGA_GPU_SESSION_MAX_ARGS 32u/OMEGA_GPU_SESSION_MAX_ARGS 64u/' +control version-doc-mismatch "must contain the line \"Omega Runtime API version:" API.md 's/^Omega Runtime API version: .*/Omega Runtime API version: 9.9/' +control stable-without-doc "STABLE entry omega_gpu_session_launch has no" API.md 's/^#### `omega_gpu_session_launch`/#### launch/' +control wrong-quoted-signature "signature quoted in" API.md 's/^uint32_t omega_gpu_session_open_count(void);/uint64_t omega_gpu_session_open_count(void);/' +control signature-inside-another "signature quoted in" API.md 's/^uint32_t omega_gpu_session_open_count(void);/int32_t omega_gpu_session_open_count(void);/' +control removed-recover "header disagrees with manifest: fn omega_gpu_session_recover" omega_gpu_session.h '/^int omega_gpu_session_recover(void);/d' +control removed-padding-field "header disagrees with manifest: field OmegaGpuCmdListOpts first_barrier_none" omega_gpu_cmdlist.h '/int first_barrier_none;/,/\*\/$/d' +control new-header-function "omega_gpu_session.h declares omega_gpu_session_zzz_new, which is neither" omega_gpu_session.h '$a int omega_gpu_session_zzz_new(void);' +control internal-unlisted "omega_gpu_session.h declares omega_gpu_session_set_error, which is neither" API.md 's/^- `omega_gpu_session_set_error` (library code/- (library code/' +control manifest-fn-named-in-prose "omega_gpu_serving.h declares omega_gpu_serving_seal, which is neither" manifest '/^fn omega_gpu_serving_seal /d' +control internal-also-manifest "API.md section 10 names omega_gpu_session_launch as INTERNAL but the manifest lists it as a fn" API.md 's/^- `omega_gpu_session_set_error` (library code/- `omega_gpu_session_set_error`, `omega_gpu_session_launch` (library code/' +control new-fnptr-function "omega_gpu_session.h declares omega_gpu_session_zzz_fp, which is neither" omega_gpu_session.h '$a int (*omega_gpu_session_zzz_fp(void))(int);' +[ $bad = 0 ] && { echo "RESULT: PASS (every negative control was caught)"; exit 0; } +echo "RESULT: FAIL (a negative control was not caught)"; exit 1