From 6e077f1ab0de7ec1b4d3d4479d0e9413c2152c67 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Fri, 2 Oct 2026 05:55:49 -0500 Subject: [PATCH 1/2] gpu-engine: design doc, header, compile stub [host NOT_RUN] Adds the Omega GPU Engine design doc, public header, a stub that returns a defined not-implemented result, and a host compile test target (test-gpu-engine-compile). No launcher, kernel, gate or evidence file changed. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01DsjWa6csUe4NxndCTmugHu --- docs/numeric/OMEGA_GPU_ENGINE.md | 254 ++++++++++++++++++++++++++ mk/omega-gpu-engine.mk | 9 + src/omega_gpu_engine.c | 90 +++++++++ src/omega_gpu_engine.h | 162 ++++++++++++++++ tests/test_omega_gpu_engine_compile.c | 60 ++++++ 5 files changed, 575 insertions(+) create mode 100644 docs/numeric/OMEGA_GPU_ENGINE.md create mode 100644 mk/omega-gpu-engine.mk create mode 100644 src/omega_gpu_engine.c create mode 100644 src/omega_gpu_engine.h create mode 100644 tests/test_omega_gpu_engine_compile.c diff --git a/docs/numeric/OMEGA_GPU_ENGINE.md b/docs/numeric/OMEGA_GPU_ENGINE.md new file mode 100644 index 000000000..d6f198437 --- /dev/null +++ b/docs/numeric/OMEGA_GPU_ENGINE.md @@ -0,0 +1,254 @@ +# Omega GPU Engine: design (phase A2) + +Status: DESIGN ONLY. Nothing here launches a GPU kernel yet. Every test and +chip label for this work is NOT_RUN (host NOT_RUN, chip NOT_RUN). No receipt +exists today. + +Sources. Facts below come from two read-only scout reports, cited as A1 and +A1b: `~/handoffs/2026-10-02-DEEP2-A1-scout.md` and +`~/handoffs/2026-10-02-DEEP2-A1b-scout.md`. A1 section names are quoted as +"A1 File N" or "A1 (a)..(f)". Line numbers are those the scouts recorded +(MAIN f633e343 for A1, 2db71da for A1b; PR198 lines are marked "PR198" and +may have drifted because that PR has since moved, A1b section 6). Anything +neither scout verified is labeled UNVERIFIED with a confidence. + +## 1. What it is, and why + +The Omega GPU Engine is one small module that takes "here is my already-built +GPU kernel, its inputs, and the buffers I expect it to fill" and returns +either SUCCESS or exactly one named failure that says which step broke. + +Why: five launcher files repeat the same open, allocate, copy-in, pushbuffer, +submit, wait, readback, close sequence (A1 Files 1 to 5, A1b section 4: +"What NUM duplicates from SUB"). They report errors in three different styles +(the GB10_DEVFAIL macros, the LDST_DEVERR line, and a bare `-1`, A1 macro +section and File 4). The divsqrt second-marker wait fails silently with no +step name (A1 headline 2: divsqrt 1160-1162). `omega_blackwell_submit.c` has +no semaphore wait and no second-marker protection, "C3" (A1 headline 3 and +A1b section 1: instant compare at line 207, no L2 flush, no marker2). + +## 2. Motivating case + +REPORTED, RECEIPT NOT READ (source: Drake/queen message 2026-10-02, relayed +from the E1 owner; no receipt path available to this cut): the live rc=-4 +failures on the reduce chip run are marker2 wait timeouts. The second marker, +written after the L2 flush, was not seen within 5000 ms. The reduce launcher +waits 5 s while ldst and divsqrt wait 600 s (A1 File 2: reduce 5000 ms at +449-450 and 473-477 PR198; A1 File 1: divsqrt 600000 ms at 1156-1169; A1 +File 5: ldst 600000 ms at 362-367 PR198). + +So the result must say WHICH wait timed out and AFTER HOW LONG, and each +timeout is a per-step input from the caller, never hard-coded in the engine. +For contrast, today ldst gives its marker wait and its semaphore wait the same +step name "wait" (A1 File 5), so a timeout there is ambiguous. + +## 3. What the module owns, and what it does not + +Kept small on purpose, so it does not become a new giant layer. + +OWNS: +1. Submission of one already-built kernel image. +2. Buffer allocation and copy-in. +3. The completion rule, in one fixed order: wait for the first marker, then + the second marker after the L2 flush (C3), then the release semaphore, + then a barrier before readback. Host order follows divsqrt (A1 File 1: + marker 1156, marker2 1160, semaphore 1168, barrier 1171), which PR198 + copies into reduce (A1 File 2: 470, 473-477, 482-485). +4. Per-step timeouts, recorded in the result. +5. Copy-out. +6. Cleanup on every exit, success or failure. +7. Poison-fill before and unwritten scan after (the "unwritten-output trap"), + reusing `omega_unwritten_scan` from `src/omega_unwritten_trap.h` (A1 (a): + the caller passes the poison; callers use 0x55555555, matching the 0x55 + fills in the launchers). The engine default is 0x55555555. +8. One error vocabulary, with the failing step named. + +DOES NOT OWN: +1. Kernel generation or codegen. +2. Launch-geometry choice. +3. Numeric contracts, or what a gate measures. +4. Evidence directories and receipts. +5. Physics pin, lock and quiet-flag policy. These stay in the scripts and the + chip_run wrapper of another program (A1b section 5: `check-physics-lock`). +6. Retries. +7. Scheduling. +8. Running more than one kernel per call. + +Check against the scout facts. The split holds. Three adjustments or +clarifications, each with evidence: + +- A. Pre-device refusals stay with the caller. Argument checks, kernel + building and QMD preflight happen before any device is opened and return + BAD_ARGS or OPERANDS (A1 File 1: 1023-1046; File 2: 318; File 5: 234-255). + These are the caller's contract checks, so the engine does not absorb them. +- B. The Blackwell backend, not the engine core and not the caller, turns the + opaque launch descriptor into a QMD (the hardware work descriptor) and a + pushbuffer. Evidence: today the QMD is built after allocation because it + needs the GPU addresses of the buffers (A1 File 2: allocs 333-336 then + "qmd" at 370; File 3: allocs 113-123 then "qmd" at 180). The engine core + passes the descriptor through untouched, which keeps "launch-geometry + choice" with the caller. +- C. One kernel per call is confirmed. The reduce level loop calls the chunk + launcher repeatedly (A1 File 2: `omega_reduce_gb10` 467-517) and the loop + stays in the caller. Persistent device contexts (`omega_accelerator_world.c` + and the resident seat in `src/runtime/rx_resident_gpu.c`) keep one device + open across many submits (A1b sections 2 and 3). They are mapped here but + not absorbed in v1: the engine opens and closes per call, like the five + launchers do today. `src/runtime` is M20-owned: reuse ideas only, never edit. + +## 4. The contract + +Callers give: the kernel image; the launch descriptor (opaque, passed +through); input buffers; output buffers with sizes; per-step timeouts +(marker, semaphore, marker2, in milliseconds). + +The engine returns SUCCESS or exactly one of: + +| name | meaning | +|---|---| +| DEVICE_OPEN | device or channel could not be opened | +| DEVICE_ALLOC | a device buffer could not be allocated | +| DEVICE_SUBMIT | building or submitting the work failed | +| GPU_COMPLETION_TIMEOUT | a completion wait ran out; the result names the wait (MARKER, SEMAPHORE or MARKER2) and `waited_ms` | +| OUTPUT_NOT_VISIBLE | the GPU finished but the outputs could not be made visible and read back | +| OUTPUT_NOT_WRITTEN | after readback, some output still holds the poison word; the result gives the unwritten byte count per output | +| DEVICE_ERROR | any other device or driver fault, step named (also used for a bad request and for cleanup failure) | + +State machine: NONE -> PREPARED -> SUBMITTED -> GPU_COMPLETE -> +OUTPUT_VISIBLE -> OUTPUT_PRODUCED -> COMMITTED. NONE is "nothing done yet" +and is the state reported by a run that fails before PREPARED. Success is +reported only at COMMITTED. The result always records the last state reached, +so a failure says how far the run got. + +Every output is poison-filled before submit (device copy and host copy) and +must contain non-poison words before OUTPUT_PRODUCED. Poison can be switched +off per request (flag NO_POISON); the default is ON. The C3 protection (L2 +flush and second marker) is also ON by default; flag NO_C3 exists only for +the A/B control arm that PR198 keeps under `OMEGA_C3_PROTECT_OFF` (A1 +headline 1). + +What the engine promises: "faithfully launched, the GPU completed, and these +bytes are genuinely its output". It never judges whether the math is correct. + +| # | Transition | Guard (check) | Failure name | Launcher step today (A1 / A1b) | +|---|---|---|---|---| +| 0 | start -> NONE | request is valid: kernel present, 1 to 8 outputs, backend table complete | DEVICE_ERROR, step "bad_request" | arg checks: divsqrt 1023, reduce 318 (BAD_ARGS) | +| 1 | NONE -> PREPARED | device and channel open; all buffers allocated; inputs copied in; outputs poison-filled | DEVICE_OPEN (steps "open", "channel"); DEVICE_ALLOC (steps "alloc_pb", "alloc_buffers"); DEVICE_ERROR (steps "copy_in", "poison") | open 1059, channel 1060, alloc_pb 1062, alloc_buffers 1073, fills 1075-1078 (divsqrt); open 324, channel 325, alloc 327-337, fills 340-341 (reduce); simt 103-129; ldst 268-286 | +| 2 | PREPARED -> SUBMITTED | backend builds QMD and pushbuffer and submits | DEVICE_SUBMIT (steps "build", "submit") | "submit": divsqrt 1154, reduce 448, simt 263, ldst 360, submit.c 200; "qmd"/"build_kernel": reduce 346, 370, simt 134, 180 | +| 3 | SUBMITTED -> GPU_COMPLETE | first marker seen; then marker2 (C3); then release semaphore; each within its own timeout | GPU_COMPLETION_TIMEOUT with wait = MARKER, MARKER2 or SEMAPHORE, `wait_timeout_ms`, `waited_ms`; a non-timeout driver fault gives DEVICE_ERROR | marker: divsqrt 1156 (600 s), reduce 449 (5 s), simt 267 (5 s), ldst 362 (600 s), submit.c 203 (5 s); marker2: divsqrt 1160-1162 (SILENT), reduce/ldst PR198 only; semaphore: divsqrt 1168, reduce 455, ldst 367; none in simt, instant compare only in submit.c 207 | +| 4 | GPU_COMPLETE -> OUTPUT_VISIBLE | barrier (dsb sy) succeeds and every output is copied back | OUTPUT_NOT_VISIBLE | dsb + memcpy: divsqrt 1171-1172, reduce 458-459; simt and submit.c have no dsb before readback (271, 210). No launcher can fail here today | +| 5 | OUTPUT_VISIBLE -> OUTPUT_PRODUCED | `omega_unwritten_scan` finds zero poison words in every output | OUTPUT_NOT_WRITTEN, with unwritten bytes per output | no launcher does this; only `tests/test_omega_unwritten_trap_gb10.c:158` scans after the call (A1 (b)) | +| 6 | OUTPUT_PRODUCED -> COMMITTED | every buffer freed and device closed without error | DEVICE_ERROR, step "cleanup" (state stays OUTPUT_PRODUCED) | close: divsqrt 1173, reduce 460, simt 273, ldst 370, submit.c 225; none frees buffers | + +Cleanup runs on every exit. If cleanup itself fails after an earlier failure, +the first failure is kept in the result; the engine never overwrites it. + +Mapping to the existing numeric codes (`src/omega_numeric.h:271-276`, A1 (d): +OK 0, BAD_ARGS -1, NOT_ENCODED -2, OPERANDS -3, DEVICE -4, FPENV -5; no +"unwritten" code exists; the next free value is -6, which is an inference): + +| engine result | old code a migrating caller reports | +|---|---| +| OK | OK (0) | +| DEVICE_OPEN, DEVICE_ALLOC, DEVICE_SUBMIT, GPU_COMPLETION_TIMEOUT, OUTPUT_NOT_VISIBLE, DEVICE_ERROR (from the device) | ERR_DEVICE (-4) | +| DEVICE_ERROR with step "bad_request" | ERR_BAD_ARGS (-1) | +| OUTPUT_NOT_WRITTEN | ERR_DEVICE (-4) during migration; PROPOSED new `OMEGA_NUMERIC_ERR_UNWRITTEN` = -6 in a later PR | + +This PR does not edit `omega_numeric.h`. Callers keep reporting -4 during +migration, but the engine result carries the precise name, wait and time, so +the old code no longer hides the cause. + +## 5. Backend seam + +The engine core talks to the device only through a small table of function +pointers (`OmegaGpuEngineBackend` in `src/omega_gpu_engine.h`): open, alloc, +copy_in, poison_output, build_and_submit, wait_marker, wait_marker2, +wait_semaphore, flush_barrier, copy_out, free_buf, close. This lets a fake +backend drive every transition and every failure name in host tests. The one +addition to the list the program brief gave is `poison_output`, because the +poison fill is a device-side write today (A1 File 1: divsqrt 1077). + +A wait callback returns 0 when satisfied, a defined TIMEOUT value on timeout, +and any other nonzero value for a driver fault. The engine measures +`waited_ms` itself and captures `errno` right after a failing call. + +The real Blackwell GB10 backend wraps the same `m16_native_*` calls the +launchers use today: open, create_channel, alloc_memory, free_memory, +submit_methods, wait_marker, close (declared in `physics/m16/m16_native.h`, +A1 (f)). No fake of these exists anywhere today (A1 (f), A1b section 5), so +this seam is the first. + +CPU_ONLY seam. The device backend is compiled out under +`OMEGA_NUMERIC_CPU_ONLY`, exactly like the reduce launcher: include guards at +`src/omega_numeric_reduce_gb10.c:38-41`, the executor guarded at 258, and the +early return at 479-480 (A1 (c)). The engine core and the fake backend need no +physics headers and build under that flag. The phase A2 header includes no +physics header at all. + +## 6. What is NOT changed + +This PR changes no gate measurement, no kernel, no launcher and no evidence +file. It adds only: this document, `src/omega_gpu_engine.h`, +`src/omega_gpu_engine.c` (a stub), `mk/omega-gpu-engine.mk` and +`tests/test_omega_gpu_engine_compile.c`. The top-level Makefile is not edited +(omega#198 edits it). None of the files in the omega#198 list is touched +(A1b section 6). In particular `src/omega_blackwell_submit.c` is not edited in +Phase A: its sha256 is recomputed by `tests/run_m17_gates.sh:66-67,129-130` +and `src/omega_blackwell_gates.c:1166-1167` (A1b section 1), so any edit +invalidates chip receipts and can only be verified on the chip. + +## 7. Phase plan + +Receipts that exist today: NONE. All labels are NOT_RUN. + +1. A2 (this PR, draft): design doc, header, compiling stub, and + `make test-gpu-engine-compile`, which checks the stub's exact return values + and that every enum name is distinct. Host NOT_RUN until the forge runs it. +2. A3 (stacked on A2): engine core, a fake backend, a host test that drives + every transition and every failure name, and mutants that remove each + transition check (each mutant must make the test fail). +3. Phase B, held until the queen says the GPU is released. The Blackwell GB10 + backend is evolved out of `src/omega_blackwell_submit.c` (it is the + file that already owns the 18-word setup, the pushbuffer, the 0x44444444 + marker and the semaphore constants, A1b section 1). Conversion order, with + real GB10 tests before the next step starts: + 1. Reduce launcher first. + 2. Load/store launcher. + 3. Base executor (`omega_numeric_gb10.c`), then divsqrt, then + `omega_blackwell_submit.c`. + 4. A final PR deletes the old duplicated launch code. + Moving `omega_blackwell_submit.c` re-seals the M17 and M18 digests, which + needs a chip rerun (A1b "Implications"). Any PR that touches it stays DRAFT + until its chip gate passes. Converting `omega_numeric_gb10.c` and + `omega_blackwell_submit.c` also adds the semaphore wait and the C3 protection + they lack today (A1 headline 3 and 4): a behavior change, tested on the chip. + The numeric launchers do not link `omega_blackwell_submit.c` today (A1b + section 1), so their chip build recipes (`tests/run_numeric_gates.sh:156-163`, + `tests/run_reduce_chip.sh:64`, `tests/run_tensor_chip.sh:67`) must gain the + engine sources at the step that converts them. + +## 8. Open questions and UNVERIFIED items + +Carried from A1 and A1b, plus new ones from this cut: +1. The E1 marker2 timeout case in section 2 is reported, receipt not read. +2. How `src/omega_numeric_gb10.c` is compiled in the main binary: not read, 70% + a glob or a tool compiles it (A1 open questions). +3. PR198 line numbers in this document may have drifted; the head moved from + 617971aa to 44741c1b (A1b section 6). +4. No GPU run was done by the scouts; chip behavior is code-reading only (A1). +5. The poison value used by `omega_blackwell_submit.c` was not read; 75% it is + 0x55 (A1b open question 1). +6. Whether the NUM files carry their own 18 setup words: 70% yes (A1b open + question 3). Three implementations of those words likely exist, which the + backend should unify. +7. `omega_world_dispatch_matmul` was read only by grep (A1b open question 5). +8. How `--run-m18-gates` is invoked from the Makefile or tools: 70% a tools + script (A1b open question 2). +9. New: a legitimate output equal to the poison word 0x55555555 (a valid float) + would be reported as unwritten. The poison is a per-output field so a caller + can choose another word. Likelihood unmeasured. +10. New: there is no BAD_REQUEST failure name, because the brief fixes the + vocabulary. The stub reports a bad request as DEVICE_ERROR with step + "bad_request". A3 or the queen may add a name. +11. New: the numeric code -6 for "unwritten" is a proposal only. +12. New: the choice of `waited_ms` measurement clock is left to A3. diff --git a/mk/omega-gpu-engine.mk b/mk/omega-gpu-engine.mk new file mode 100644 index 000000000..fc5cd08ca --- /dev/null +++ b/mk/omega-gpu-engine.mk @@ -0,0 +1,9 @@ +# Omega GPU Engine (docs/numeric/OMEGA_GPU_ENGINE.md), phase A2: compile check +# of the header and the stub. Picked up by `-include mk/*.mk`. Host only: opens +# no device, needs no physics headers, not part of `all` or `test`. +.PHONY: test-gpu-engine-compile +build/test_omega_gpu_engine_compile: tests/test_omega_gpu_engine_compile.c src/omega_gpu_engine.c src/omega_gpu_engine.h + @mkdir -p build + gcc -std=gnu11 -O2 -Wall -Wextra -Werror -Isrc -DOMEGA_NUMERIC_CPU_ONLY -o $@ tests/test_omega_gpu_engine_compile.c src/omega_gpu_engine.c +test-gpu-engine-compile: build/test_omega_gpu_engine_compile + ./build/test_omega_gpu_engine_compile diff --git a/src/omega_gpu_engine.c b/src/omega_gpu_engine.c new file mode 100644 index 000000000..00e626435 --- /dev/null +++ b/src/omega_gpu_engine.c @@ -0,0 +1,90 @@ +/* + * Omega GPU Engine, A2 compile stub. See src/omega_gpu_engine.h and + * docs/numeric/OMEGA_GPU_ENGINE.md. No launch logic yet: omega_gpu_engine_run + * validates its arguments, then reports DEVICE_ERROR at step "not_implemented". + * The real engine core (A3) replaces omega_gpu_engine_run; the name functions + * below are final. + */ +#include "omega_gpu_engine.h" + +#include + +static const char *const FAILURE_NAMES[OMEGA_GPU_ENGINE_FAILURE_COUNT] = { + "OK", + "DEVICE_OPEN", + "DEVICE_ALLOC", + "DEVICE_SUBMIT", + "GPU_COMPLETION_TIMEOUT", + "OUTPUT_NOT_VISIBLE", + "OUTPUT_NOT_WRITTEN", + "DEVICE_ERROR", +}; + +static const char *const STATE_NAMES[OMEGA_GPU_ENGINE_STATE_COUNT] = { + "NONE", + "PREPARED", + "SUBMITTED", + "GPU_COMPLETE", + "OUTPUT_VISIBLE", + "OUTPUT_PRODUCED", + "COMMITTED", +}; + +static const char *const WAIT_NAMES[OMEGA_GPU_ENGINE_WAIT_COUNT] = { + "NONE", + "MARKER", + "SEMAPHORE", + "MARKER2", +}; + +const char *omega_gpu_engine_failure_name(int failure) +{ + if (failure < 0 || failure >= (int)OMEGA_GPU_ENGINE_FAILURE_COUNT) return "UNKNOWN"; + return FAILURE_NAMES[failure]; +} + +const char *omega_gpu_engine_state_name(int state) +{ + if (state < 0 || state >= (int)OMEGA_GPU_ENGINE_STATE_COUNT) return "UNKNOWN"; + return STATE_NAMES[state]; +} + +const char *omega_gpu_engine_wait_name(int wait) +{ + if (wait < 0 || wait >= (int)OMEGA_GPU_ENGINE_WAIT_COUNT) return "UNKNOWN"; + return WAIT_NAMES[wait]; +} + +static int backend_complete(const OmegaGpuEngineBackend *b) +{ + return b->open && b->alloc && b->copy_in && b->poison_output && b->build_and_submit && + b->wait_marker && b->wait_marker2 && b->wait_semaphore && b->flush_barrier && + b->copy_out && b->free_buf && b->close; +} + +static int request_valid(const OmegaGpuEngineRequest *rq) +{ + if (!rq->kernel_image || rq->kernel_len == 0) return 0; + if (rq->n_inputs > OMEGA_GPU_ENGINE_MAX_BUFFERS) return 0; + if (rq->n_outputs == 0 || rq->n_outputs > OMEGA_GPU_ENGINE_MAX_BUFFERS) return 0; + if (rq->n_inputs > 0 && !rq->inputs) return 0; + if (!rq->outputs) return 0; + return 1; +} + +int omega_gpu_engine_run(const OmegaGpuEngineBackend *b, void *backend_ctx, + const OmegaGpuEngineRequest *rq, OmegaGpuEngineResult *out) +{ + (void)backend_ctx; + if (!out) return OMEGA_GPU_ENGINE_DEVICE_ERROR; + memset(out, 0, sizeof *out); + out->state = OMEGA_GPU_ENGINE_STATE_NONE; + out->failure = OMEGA_GPU_ENGINE_DEVICE_ERROR; + out->wait = OMEGA_GPU_ENGINE_WAIT_NONE; + if (!b || !rq || !backend_complete(b) || !request_valid(rq)) { + out->step = "bad_request"; + return OMEGA_GPU_ENGINE_DEVICE_ERROR; + } + out->step = "not_implemented"; + return OMEGA_GPU_ENGINE_DEVICE_ERROR; +} diff --git a/src/omega_gpu_engine.h b/src/omega_gpu_engine.h new file mode 100644 index 000000000..0aefdfa70 --- /dev/null +++ b/src/omega_gpu_engine.h @@ -0,0 +1,162 @@ +/* + * Omega GPU Engine: launch one already-built GPU kernel and return SUCCESS or + * exactly one named failure. + * + * Purpose: today five launcher files repeat the same open / alloc / copy-in / + * pushbuffer / submit / completion-wait / readback / close sequence with three + * different error styles. This module owns that sequence once. Design: + * docs/numeric/OMEGA_GPU_ENGINE.md. + * + * Contract: the caller gives a kernel image, an opaque launch descriptor, + * input buffers, output buffers and per-step timeouts. The engine walks the + * states NONE -> PREPARED -> SUBMITTED -> GPU_COMPLETE -> OUTPUT_VISIBLE -> + * OUTPUT_PRODUCED -> COMMITTED. Success is returned only at COMMITTED. Every + * output is poison-filled before submit and must hold non-poison words before + * OUTPUT_PRODUCED. The engine never judges whether the math is right: it + * promises only "faithfully launched, GPU completed, these bytes are + * genuinely its output". + * + * Return value of omega_gpu_engine_run: 0 (OMEGA_GPU_ENGINE_OK) on success, + * otherwise the failure code, which is also stored in the result. + * + * STATUS: A2 stub. omega_gpu_engine_run does not launch anything yet; it + * validates its arguments and reports DEVICE_ERROR at step "not_implemented". + */ +#ifndef OMEGA_GPU_ENGINE_H +#define OMEGA_GPU_ENGINE_H + +#include +#include + +#define OMEGA_GPU_ENGINE_MAX_BUFFERS 8u +#define OMEGA_GPU_ENGINE_POISON_DEFAULT 0x55555555u + +/* Request flags. A zeroed request means: poison ON, C3 protection ON. */ +#define OMEGA_GPU_ENGINE_FLAG_NO_POISON 0x1u /* skip poison fill and unwritten scan */ +#define OMEGA_GPU_ENGINE_FLAG_NO_C3 0x2u /* A/B control arm only: skip L2 flush and marker2 */ + +/* One failure name per run. OK is 0, so the return value reads as a boolean. */ +typedef enum { + OMEGA_GPU_ENGINE_OK = 0, + OMEGA_GPU_ENGINE_DEVICE_OPEN, + OMEGA_GPU_ENGINE_DEVICE_ALLOC, + OMEGA_GPU_ENGINE_DEVICE_SUBMIT, + OMEGA_GPU_ENGINE_GPU_COMPLETION_TIMEOUT, + OMEGA_GPU_ENGINE_OUTPUT_NOT_VISIBLE, + OMEGA_GPU_ENGINE_OUTPUT_NOT_WRITTEN, + OMEGA_GPU_ENGINE_DEVICE_ERROR, + OMEGA_GPU_ENGINE_FAILURE_COUNT /* not a failure: number of names above */ +} OmegaGpuEngineFailure; + +/* How far a run got. Success is only COMMITTED. */ +typedef enum { + OMEGA_GPU_ENGINE_STATE_NONE = 0, /* nothing done yet (device may be unopened) */ + OMEGA_GPU_ENGINE_STATE_PREPARED, + OMEGA_GPU_ENGINE_STATE_SUBMITTED, + OMEGA_GPU_ENGINE_STATE_GPU_COMPLETE, + OMEGA_GPU_ENGINE_STATE_OUTPUT_VISIBLE, + OMEGA_GPU_ENGINE_STATE_OUTPUT_PRODUCED, + OMEGA_GPU_ENGINE_STATE_COMMITTED, + OMEGA_GPU_ENGINE_STATE_COUNT /* not a state: number of names above */ +} OmegaGpuEngineState; + +/* Which completion wait timed out (only meaningful for GPU_COMPLETION_TIMEOUT). */ +typedef enum { + OMEGA_GPU_ENGINE_WAIT_NONE = 0, + OMEGA_GPU_ENGINE_WAIT_MARKER, + OMEGA_GPU_ENGINE_WAIT_SEMAPHORE, + OMEGA_GPU_ENGINE_WAIT_MARKER2, + OMEGA_GPU_ENGINE_WAIT_COUNT /* not a wait: number of names above */ +} OmegaGpuEngineWait; + +/* What a device buffer is for. SCRATCH is backend-internal (pushbuffer, completion + * marker, QMD); the engine asks for it once so its allocation failure is named. */ +typedef enum { + OMEGA_GPU_ENGINE_BUF_SCRATCH = 0, + OMEGA_GPU_ENGINE_BUF_KERNEL, + OMEGA_GPU_ENGINE_BUF_LAUNCH, + OMEGA_GPU_ENGINE_BUF_INPUT, + OMEGA_GPU_ENGINE_BUF_OUTPUT +} OmegaGpuEngineBufRole; + +/* A wait callback returns 0 when satisfied, this value on timeout, any other + * nonzero value on a driver fault (reported as DEVICE_ERROR, value kept as drv_rc). */ +#define OMEGA_GPU_ENGINE_BACKEND_TIMEOUT 1 + +typedef struct { + const void *ptr; + size_t len; /* bytes */ +} OmegaGpuEngineInBuf; + +typedef struct { + void *ptr; /* host destination, must be 4-byte aligned when poison is on */ + size_t len; /* bytes, multiple of 4 when poison is on */ + uint32_t poison; /* 0 means OMEGA_GPU_ENGINE_POISON_DEFAULT */ +} OmegaGpuEngineOutBuf; + +/* Per-step timeouts in milliseconds. Never hard-coded by the engine. Each wait + * that is enabled needs a value greater than 0 (marker2_ms is ignored with NO_C3). */ +typedef struct { + uint64_t marker_ms; + uint64_t semaphore_ms; + uint64_t marker2_ms; +} OmegaGpuEngineTimeouts; + +typedef struct { + const void *kernel_image; /* already-built kernel code */ + size_t kernel_len; + const void *launch; /* opaque launch descriptor, passed through untouched */ + size_t launch_len; + const OmegaGpuEngineInBuf *inputs; + size_t n_inputs; /* at most OMEGA_GPU_ENGINE_MAX_BUFFERS */ + const OmegaGpuEngineOutBuf *outputs; + size_t n_outputs; /* 1 .. OMEGA_GPU_ENGINE_MAX_BUFFERS */ + OmegaGpuEngineTimeouts timeouts; + uint32_t flags; /* OMEGA_GPU_ENGINE_FLAG_* */ +} OmegaGpuEngineRequest; + +typedef struct { + int state; /* last OmegaGpuEngineState reached */ + int failure; /* OmegaGpuEngineFailure, OK on success */ + const char *step; /* static string naming the failing step, "ok" on success */ + int wait; /* OmegaGpuEngineWait, NONE unless a completion wait failed */ + uint64_t wait_timeout_ms; /* the configured limit of that wait */ + uint64_t waited_ms; /* how long the engine actually waited before giving up */ + int drv_rc; /* driver return code of the failing call, 0 if none */ + int err_no; /* errno captured right after the failing call, 0 if none */ + size_t n_outputs; /* number of valid entries in unwritten_bytes */ + uint64_t unwritten_bytes[OMEGA_GPU_ENGINE_MAX_BUFFERS]; /* poison bytes left, per output */ +} OmegaGpuEngineResult; + +/* + * Backend seam. Every callback returns 0 on success and nonzero on failure, + * except where noted. A fake backend implements these to drive every + * transition in host tests; the Blackwell GB10 backend wraps the m16_native_* + * calls the launchers use today (physics/m16/m16_native.h). All callbacks must + * be non-NULL. + */ +typedef struct { + int (*open)(void *ctx); /* device + channel */ + int (*alloc)(void *ctx, int role, unsigned index, size_t bytes); + int (*copy_in)(void *ctx, int role, unsigned index, const void *src, size_t bytes); + int (*poison_output)(void *ctx, unsigned index, uint32_t word, size_t bytes); /* device side */ + int (*build_and_submit)(void *ctx, const OmegaGpuEngineRequest *rq); + int (*wait_marker)(void *ctx, uint64_t timeout_ms); /* may return BACKEND_TIMEOUT */ + int (*wait_marker2)(void *ctx, uint64_t timeout_ms); /* may return BACKEND_TIMEOUT */ + int (*wait_semaphore)(void *ctx, uint64_t timeout_ms); /* may return BACKEND_TIMEOUT */ + int (*flush_barrier)(void *ctx); /* dsb sy before readback */ + int (*copy_out)(void *ctx, unsigned index, void *dst, size_t bytes); + int (*free_buf)(void *ctx, int role, unsigned index); + int (*close)(void *ctx); +} OmegaGpuEngineBackend; + +/* Runs one kernel. Returns OMEGA_GPU_ENGINE_OK (0) or the failure code; fills *out. */ +int omega_gpu_engine_run(const OmegaGpuEngineBackend *b, void *backend_ctx, + const OmegaGpuEngineRequest *rq, OmegaGpuEngineResult *out); + +/* Static name strings, never NULL. Out-of-range values give "UNKNOWN". */ +const char *omega_gpu_engine_failure_name(int failure); +const char *omega_gpu_engine_state_name(int state); +const char *omega_gpu_engine_wait_name(int wait); + +#endif diff --git a/tests/test_omega_gpu_engine_compile.c b/tests/test_omega_gpu_engine_compile.c new file mode 100644 index 000000000..f9ed29cd6 --- /dev/null +++ b/tests/test_omega_gpu_engine_compile.c @@ -0,0 +1,60 @@ +/* Omega GPU Engine A2: the stub returns its defined results and every enum name is distinct. */ +#include "omega_gpu_engine.h" +#include +#include + +static int bad; +#define CHECK(c) do { if (!(c)) { printf("[FAIL] line %d: %s\n", __LINE__, #c); bad++; } } while (0) + +static int f_ctx(void *c) { (void)c; return 0; } +static int f_alloc(void *c, int r, unsigned i, size_t n) { (void)c; (void)r; (void)i; (void)n; return 0; } +static int f_in(void *c, int r, unsigned i, const void *s, size_t n) { (void)c; (void)r; (void)i; (void)s; (void)n; return 0; } +static int f_poison(void *c, unsigned i, uint32_t w, size_t n) { (void)c; (void)i; (void)w; (void)n; return 0; } +static int f_submit(void *c, const OmegaGpuEngineRequest *rq) { (void)c; (void)rq; return 0; } +static int f_wait(void *c, uint64_t ms) { (void)c; (void)ms; return 0; } +static int f_out(void *c, unsigned i, void *d, size_t n) { (void)c; (void)i; (void)d; (void)n; return 0; } +static int f_free(void *c, int r, unsigned i) { (void)c; (void)r; (void)i; return 0; } + +static int all_distinct(const char *(*name)(int), int count) +{ + for (int i = 0; i < count; i++) { + CHECK(name(i) != NULL && strcmp(name(i), "UNKNOWN") != 0); + for (int j = i + 1; j < count; j++) CHECK(strcmp(name(i), name(j)) != 0); + } + return strcmp(name(-1), "UNKNOWN") == 0 && strcmp(name(count), "UNKNOWN") == 0; +} + +int main(void) +{ + CHECK(all_distinct(omega_gpu_engine_failure_name, OMEGA_GPU_ENGINE_FAILURE_COUNT)); + CHECK(all_distinct(omega_gpu_engine_state_name, OMEGA_GPU_ENGINE_STATE_COUNT)); + CHECK(all_distinct(omega_gpu_engine_wait_name, OMEGA_GPU_ENGINE_WAIT_COUNT)); + CHECK(OMEGA_GPU_ENGINE_OK == 0 && strcmp(omega_gpu_engine_failure_name(0), "OK") == 0); + CHECK(strcmp(omega_gpu_engine_failure_name(OMEGA_GPU_ENGINE_GPU_COMPLETION_TIMEOUT), "GPU_COMPLETION_TIMEOUT") == 0); + + OmegaGpuEngineBackend be = { f_ctx, f_alloc, f_in, f_poison, f_submit, f_wait, f_wait, f_wait, f_ctx, f_out, f_free, f_ctx }; + unsigned char code[4] = {0}; uint32_t outw[4] = {0}; + OmegaGpuEngineOutBuf ob = { outw, sizeof outw, 0 }; + OmegaGpuEngineRequest rq; memset(&rq, 0, sizeof rq); + rq.kernel_image = code; rq.kernel_len = sizeof code; rq.outputs = &ob; rq.n_outputs = 1; + + OmegaGpuEngineResult r; memset(&r, 0x7f, sizeof r); + CHECK(omega_gpu_engine_run(&be, NULL, &rq, &r) == OMEGA_GPU_ENGINE_DEVICE_ERROR); + CHECK(r.failure == OMEGA_GPU_ENGINE_DEVICE_ERROR && r.state == OMEGA_GPU_ENGINE_STATE_NONE); + CHECK(r.step != NULL && strcmp(r.step, "not_implemented") == 0); + CHECK(r.wait == OMEGA_GPU_ENGINE_WAIT_NONE && r.waited_ms == 0 && r.drv_rc == 0 && r.n_outputs == 0); + + memset(&r, 0x7f, sizeof r); + rq.kernel_image = NULL; /* counterexample: a bad request must not look like not_implemented */ + CHECK(omega_gpu_engine_run(&be, NULL, &rq, &r) == OMEGA_GPU_ENGINE_DEVICE_ERROR); + CHECK(r.step != NULL && strcmp(r.step, "bad_request") == 0); + rq.kernel_image = code; + memset(&r, 0x7f, sizeof r); + be.close = NULL; /* an incomplete backend table is refused too */ + CHECK(omega_gpu_engine_run(&be, NULL, &rq, &r) == OMEGA_GPU_ENGINE_DEVICE_ERROR); + CHECK(r.step != NULL && strcmp(r.step, "bad_request") == 0); + CHECK(omega_gpu_engine_run(&be, NULL, &rq, NULL) == OMEGA_GPU_ENGINE_DEVICE_ERROR); + + printf("SUMMARY failed=%d\n", bad); + return bad ? 1 : 0; +} From 112e1ae8e11c31e0637d3d08398dfb9d00a52dcd Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Fri, 2 Oct 2026 06:02:14 -0500 Subject: [PATCH 2/2] gpu-engine: reconcile to Drake first-cut plan (omega_gpu_execute, INITIAL..SUCCESS, error list, uncertain-completion block) [host NOT_RUN] Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01DsjWa6csUe4NxndCTmugHu --- docs/numeric/OMEGA_GPU_ENGINE.md | 549 ++++++++++++++++++-------- src/omega_gpu_engine.c | 159 ++++++-- src/omega_gpu_engine.h | 269 ++++++++----- tests/test_omega_gpu_engine_compile.c | 159 ++++++-- 4 files changed, 809 insertions(+), 327 deletions(-) diff --git a/docs/numeric/OMEGA_GPU_ENGINE.md b/docs/numeric/OMEGA_GPU_ENGINE.md index d6f198437..70e8fe34b 100644 --- a/docs/numeric/OMEGA_GPU_ENGINE.md +++ b/docs/numeric/OMEGA_GPU_ENGINE.md @@ -1,33 +1,55 @@ -# Omega GPU Engine: design (phase A2) +# Omega GPU Engine: design (phase A2, reconciled to Drake's first-cut plan) Status: DESIGN ONLY. Nothing here launches a GPU kernel yet. Every test and chip label for this work is NOT_RUN (host NOT_RUN, chip NOT_RUN). No receipt exists today. +Plan authority: Drake's pasted first-cut plan, items 1 to 11, 2026-10-02 +(`~/handoffs/2026-10-02-DEEP2-first-cut-drake.md`), plus the queen rulings in +that file. This document, the header and the stub were reconciled to it in the +second commit of omega#218. Where the first draft differed, the change is +named in section 12. + Sources. Facts below come from two read-only scout reports, cited as A1 and A1b: `~/handoffs/2026-10-02-DEEP2-A1-scout.md` and `~/handoffs/2026-10-02-DEEP2-A1b-scout.md`. A1 section names are quoted as "A1 File N" or "A1 (a)..(f)". Line numbers are those the scouts recorded (MAIN f633e343 for A1, 2db71da for A1b; PR198 lines are marked "PR198" and -may have drifted because that PR has since moved, A1b section 6). Anything -neither scout verified is labeled UNVERIFIED with a confidence. +may have drifted because that PR has since moved, A1b section 6). Source +lines quoted as "now" were read directly on this branch (base 2db71da). +Anything neither scout nor this cut verified is labeled UNVERIFIED with a +confidence. ## 1. What it is, and why The Omega GPU Engine is one small module that takes "here is my already-built -GPU kernel, its inputs, and the buffers I expect it to fill" and returns +GPU program, its two inputs, and the buffer I expect it to fill" and returns either SUCCESS or exactly one named failure that says which step broke. -Why: five launcher files repeat the same open, allocate, copy-in, pushbuffer, -submit, wait, readback, close sequence (A1 Files 1 to 5, A1b section 4: -"What NUM duplicates from SUB"). They report errors in three different styles -(the GB10_DEVFAIL macros, the LDST_DEVERR line, and a bare `-1`, A1 macro -section and File 4). The divsqrt second-marker wait fails silently with no -step name (A1 headline 2: divsqrt 1160-1162). `omega_blackwell_submit.c` has -no semaphore wait and no second-marker protection, "C3" (A1 headline 3 and -A1b section 1: instant compare at line 207, no L2 flush, no marker2). - -## 2. Motivating case +Why: several launcher files repeat the same open, allocate, copy-in, +pushbuffer, submit, wait, readback, close sequence (A1 Files 1 to 5, A1b +section 4: "What NUM duplicates from SUB"). They report errors in three +different styles (the GB10_DEVFAIL macros, the LDST_DEVERR line, and a bare +`-1`, A1 macro section and File 4). The divsqrt second-marker wait fails +silently with no step name (A1 headline 2: divsqrt 1160-1162). +`omega_blackwell_submit.c` has no semaphore wait and no second-marker +protection, "C3" (A1 headline 3 and A1b section 1: instant compare at line +207, no L2 flush, no marker2). + +Execution paths found (plan item 1, from the scouts): `omega_blackwell_submit.c` +runs vector addition, integer matrix multiplication and tensor matrix +multiplication on its own (A1 File 4). Separate executors handle ordinary +numeric operations, reduction chunks and DIV/SQRT/transcendentals (A1 Files +1 to 3). `omega_accelerator_world.c` has persistent vector, matrix and queued +submission paths, `rx_resident_gpu.c` has a resident-kernel lifecycle, and +`omega_world_gates.c` submits directly for qualification (A1b sections 2 and +3). The differences that matter (plan item 3): ordinary numeric execution +checks only the host marker; reduction also waits for the release semaphore +and uses a CPU barrier; DIV/SQRT also flushes GPU cache writes and waits for a +second marker; persistent world execution tracks in-flight ownership; the +resident kernel has its own cooperative shutdown protocol. + +## 2. Motivating case (E1) REPORTED, RECEIPT NOT READ (source: Drake/queen message 2026-10-02, relayed from the E1 owner; no receipt path available to this cut): the live rc=-4 @@ -40,108 +62,198 @@ File 5: ldst 600000 ms at 362-367 PR198). So the result must say WHICH wait timed out and AFTER HOW LONG, and each timeout is a per-step input from the caller, never hard-coded in the engine. For contrast, today ldst gives its marker wait and its semaphore wait the same -step name "wait" (A1 File 5), so a timeout there is ambiguous. - -## 3. What the module owns, and what it does not - -Kept small on purpose, so it does not become a new giant layer. +step name "wait" (A1 File 5), so a timeout there is ambiguous. E1 is not +touched by this cut. + +## 3. The engine seed, and what the module owns + +Seed (plan item 4 and item 8). The engine is extracted from the vector +lifecycle that already lives inside `src/omega_blackwell_submit.c`: +`omega_blackwell_execute_vector` (A1 File 4, lines 24 to 226 recorded by the +scout). That path is the FIRST MIGRATED PATH of the engine. It already does +open (45), channel (46), pushbuffer and buffer allocation (50, 58-64), copy-in, +a poison pre-fill of the output, QMD build, `dsb sy` (128), submit (200), a +5000 ms marker wait (203), an equality check of the semaphore word without a +wait (207), readback (210) and close (225) (A1 File 4). Reading the source +now, the poison pre-fill is at lines 74 to 80 and uses +`OMEGA_VECTOR_POISON_VALUE`, which is `0xdeadbeefU` (`src/omega_vector.h:10`). +This differs from the scout line "no poison fill" for that file (A1 File 4 +common row), so the source wins and the scout line is recorded as a +discrepancy. The engine strengthens the path with: the second marker after an +L2 flush (C3), a real release semaphore wait, a visibility barrier before +readback, a post-readback check that no output word is still its poison word, +named failure steps and the uncertain-completion rule below. + +The seed reuses the existing launch-descriptor builders (the QMD and +pushbuffer code in `omega_blackwell_submit.c`, which moves to the GB10 backend +`src/omega_blackwell_engine.c/.h`) and the unwritten-output idea of +`src/omega_unwritten_trap.h` (A1 (a)). The trap module takes a single poison +word, while the engine job carries one poison word per output word, so the +engine core (A3) does its own word comparison against the poison array and +does not call `omega_unwritten_scan`. This is a design choice of this cut, not +something a scout verified. + +Poison responsibility (plan item 8). The wrapper (the vector operation that +calls the engine) supplies poison values that are guaranteed to differ from the +expected outputs. The engine writes those words to the device output before +submit and afterwards only checks whether each output word changed. The +engine never chooses poison. Math verification (the oracle that compares the +output against the expected arithmetic result, today +`omega_blackwell_gates.c:191` for the poison test and the parity code in the +vector executor) stays in the wrapper. OWNS: -1. Submission of one already-built kernel image. +1. Submission of one already-built program. 2. Buffer allocation and copy-in. 3. The completion rule, in one fixed order: wait for the first marker, then - the second marker after the L2 flush (C3), then the release semaphore, - then a barrier before readback. Host order follows divsqrt (A1 File 1: - marker 1156, marker2 1160, semaphore 1168, barrier 1171), which PR198 + the second marker after the L2 flush (C3), then the release semaphore, then + a visibility barrier before readback. Host order follows divsqrt (A1 File + 1: marker 1156, marker2 1160, semaphore 1168, barrier 1171), which PR198 copies into reduce (A1 File 2: 470, 473-477, 482-485). 4. Per-step timeouts, recorded in the result. 5. Copy-out. -6. Cleanup on every exit, success or failure. -7. Poison-fill before and unwritten scan after (the "unwritten-output trap"), - reusing `omega_unwritten_scan` from `src/omega_unwritten_trap.h` (A1 (a): - the caller passes the poison; callers use 0x55555555, matching the 0x55 - fills in the launchers). The engine default is 0x55555555. +6. Cleanup on every exit where completion is known, success or failure. +7. The poison write before and the unchanged-word check after. 8. One error vocabulary, with the failing step named. +9. The uncertain-completion block (section 5). DOES NOT OWN: 1. Kernel generation or codegen. 2. Launch-geometry choice. -3. Numeric contracts, or what a gate measures. -4. Evidence directories and receipts. -5. Physics pin, lock and quiet-flag policy. These stay in the scripts and the - chip_run wrapper of another program (A1b section 5: `check-physics-lock`). -6. Retries. -7. Scheduling. -8. Running more than one kernel per call. - -Check against the scout facts. The split holds. Three adjustments or -clarifications, each with evidence: - -- A. Pre-device refusals stay with the caller. Argument checks, kernel - building and QMD preflight happen before any device is opened and return - BAD_ARGS or OPERANDS (A1 File 1: 1023-1046; File 2: 318; File 5: 234-255). - These are the caller's contract checks, so the engine does not absorb them. +3. Numeric contracts, math verification, or what a gate measures. +4. Choosing poison values. +5. Evidence directories and receipts. +6. Physics pin, lock and quiet-flag policy. These stay in the scripts and the + chip_run wrapper (A1b section 5: `check-physics-lock`). +7. Retries. +8. Scheduling. +9. Running more than one program per call. + +Three clarifications, each with evidence: + +- A. Pre-device refusals stay with the caller where they are about numeric + contracts. Argument checks, kernel building and QMD preflight happen before + any device is opened and return BAD_ARGS or OPERANDS (A1 File 1: 1023-1046; + File 2: 318; File 5: 234-255). The engine's own INVALID_ARGS covers only a + malformed job (null pointers, wrong lengths, zero timeouts), checked before + any device is touched. - B. The Blackwell backend, not the engine core and not the caller, turns the - opaque launch descriptor into a QMD (the hardware work descriptor) and a - pushbuffer. Evidence: today the QMD is built after allocation because it - needs the GPU addresses of the buffers (A1 File 2: allocs 333-336 then - "qmd" at 370; File 3: allocs 113-123 then "qmd" at 180). The engine core - passes the descriptor through untouched, which keeps "launch-geometry - choice" with the caller. -- C. One kernel per call is confirmed. The reduce level loop calls the chunk - launcher repeatedly (A1 File 2: `omega_reduce_gb10` 467-517) and the loop - stays in the caller. Persistent device contexts (`omega_accelerator_world.c` - and the resident seat in `src/runtime/rx_resident_gpu.c`) keep one device - open across many submits (A1b sections 2 and 3). They are mapped here but - not absorbed in v1: the engine opens and closes per call, like the five - launchers do today. `src/runtime` is M20-owned: reuse ideas only, never edit. + job into a QMD (the hardware work descriptor) and a pushbuffer. Evidence: + today the QMD is built after allocation because it needs the GPU addresses + of the buffers (A1 File 2: allocs 333-336 then "qmd" at 370; File 3: allocs + 113-123 then "qmd" at 180; File 4: QMD invariant at 118). +- C. One program per call. The reduce level loop calls the chunk launcher + repeatedly (A1 File 2: `omega_reduce_gb10` 467-517) and the loop stays in + the caller. Persistent device contexts (`omega_accelerator_world.c` and the + resident seat in `src/runtime/rx_resident_gpu.c`) keep one device open across + many submits (A1b sections 2 and 3). They are mapped here but not absorbed in + v1: the engine opens and closes per call, like the launchers do today. + `src/runtime` is M20-owned: reuse ideas only, never edit. ## 4. The contract -Callers give: the kernel image; the launch descriptor (opaque, passed -through); input buffers; output buffers with sizes; per-step timeouts -(marker, semaphore, marker2, in milliseconds). +Public entry point, in `src/omega_gpu_engine.h`: -The engine returns SUCCESS or exactly one of: + int omega_gpu_execute(const OmegaGpuJob *job, OmegaGpuResult *result); + +It returns 0 (`OMEGA_GPU_ENGINE_OK`) on success, otherwise the failure code, +which is also stored in `result->failure`. + +### 4.1 The job (plan item 5) + +| field | meaning | +|---|---| +| program, program_len | encoded program bytes, already built by the caller | +| layout | `OMEGA_GPU_LAYOUT_VECTOR_1D` only; later layouts are separate qualified cuts | +| element_count | number of 32-bit elements, greater than 0 | +| input_a, input_a_len | first input, `element_count * 4` bytes | +| input_b, input_b_len | second input, `element_count * 4` bytes | +| output, output_len | host output buffer, 4-byte aligned, `element_count * 4` bytes | +| poison, poison_count | wrapper-supplied poison words, one per output word, `poison_count == element_count` | +| timeouts | `marker_ms`, `release_semaphore_ms`, `marker2_ms`, `visibility_ms`, each greater than 0 (`marker2_ms` is ignored with the A/B flag below) | +| flags | zero means every protection ON. `OMEGA_GPU_ENGINE_FLAG_NO_C3` exists only for the A/B control arm that PR198 keeps under `OMEGA_C3_PROTECT_OFF` (A1 headline 1) | + +The 4-byte element size follows the vector executor's buffer sizing +`(n*4+0xfff)&~0xfff` (A1 File 4: 55-56). Anything else is INVALID_ARGS. + +### 4.2 The result (plan items 6 and 7) + +The result records: the failure name; the last COMPLETED state; the precise +failed step (an enum, `OMEGA_GPU_ENGINE_STEP_*`, with names); which wait +failed (`MARKER`, `RELEASE_SEMAPHORE` or `MARKER2`), its configured limit and +the milliseconds actually waited; the driver return code, `errno` captured +right after the failing call, and the driver text; the observed marker, +marker2 and semaphore words, with a mask saying which are meaningful; whether +context and allocations were retained; whether cleanup failed; and the number +of still-poison words per output (`output_unchanged_words`, one output today). +The vector path uses one semaphore word (A1 File 4: `hsem` at lines 124-126 +now; A1b section 1), so the result carries one. + +### 4.3 States (plan item 6) + +INITIAL -> PREPARED -> SUBMITTED -> GPU_COMPLETE -> OUTPUT_VISIBLE -> +OUTPUT_PRODUCED -> SUCCESS. + +INITIAL is "nothing completed yet" and is the last state of a run that fails +before PREPARED (the device may or may not be open). Success is reported only +at SUCCESS. The result always records the last state completed, so a failure +says how far the run got. The earlier draft of this document called the first +state NONE and the last state COMMITTED. + +### 4.4 Failures (plan item 7) | name | meaning | |---|---| -| DEVICE_OPEN | device or channel could not be opened | -| DEVICE_ALLOC | a device buffer could not be allocated | -| DEVICE_SUBMIT | building or submitting the work failed | -| GPU_COMPLETION_TIMEOUT | a completion wait ran out; the result names the wait (MARKER, SEMAPHORE or MARKER2) and `waited_ms` | -| OUTPUT_NOT_VISIBLE | the GPU finished but the outputs could not be made visible and read back | -| OUTPUT_NOT_WRITTEN | after readback, some output still holds the poison word; the result gives the unwritten byte count per output | -| DEVICE_ERROR | any other device or driver fault, step named (also used for a bad request and for cleanup failure) | - -State machine: NONE -> PREPARED -> SUBMITTED -> GPU_COMPLETE -> -OUTPUT_VISIBLE -> OUTPUT_PRODUCED -> COMMITTED. NONE is "nothing done yet" -and is the state reported by a run that fails before PREPARED. Success is -reported only at COMMITTED. The result always records the last state reached, -so a failure says how far the run got. - -Every output is poison-filled before submit (device copy and host copy) and -must contain non-poison words before OUTPUT_PRODUCED. Poison can be switched -off per request (flag NO_POISON); the default is ON. The C3 protection (L2 -flush and second marker) is also ON by default; flag NO_C3 exists only for -the A/B control arm that PR198 keeps under `OMEGA_C3_PROTECT_OFF` (A1 -headline 1). +| DEVICE_OPEN | the device could not be opened | +| CHANNEL_CREATE | the channel could not be created | +| ALLOC | a device buffer could not be allocated | +| PREPARE | copy-in, the device-side poison fill, or the descriptor build failed | +| SUBMIT | submitting the work failed | +| COMPLETION_WAIT | the marker wait or the marker2 wait failed or timed out; `wait` says MARKER or MARKER2, with `wait_timeout_ms` and `waited_ms` | +| RELEASE_WAIT | the release semaphore wait failed or timed out; `wait` is RELEASE_SEMAPHORE, with `wait_timeout_ms` and `waited_ms` | +| VISIBILITY_WAIT | the visibility barrier failed or timed out, or the readback failed | +| OUTPUT_UNCHANGED | after readback, some output words still equal their poison words; the result gives the unchanged-word count per output | +| INVALID_ARGS | the job or the result pointer is malformed | +| INTERNAL_INVARIANT | the engine or its backend broke its own contract (incomplete backend table, a stub that is not implemented yet, an impossible state) | +| CLEANUP | free or close failed after an otherwise good run | +| UNCERTAIN_COMPLETION_BLOCKED | an earlier job in this process left completion uncertain; this job was refused without touching the device | + +Reconciliation note. Plan item 7 lists "completion wait" and "release wait" +as two names. The lieutenant brief for this cut said the completion wait names +which wait it was (MARKER, RELEASE_SEMAPHORE or MARKER2). This document keeps +both names distinct and splits the waits so no name overlaps: COMPLETION_WAIT +covers MARKER and MARKER2, and RELEASE_WAIT covers RELEASE_SEMAPHORE. The +`wait` field names the wait in both cases. If the queen wants all three waits +under COMPLETION_WAIT, RELEASE_WAIT would then have no meaning, so that is +left as a decision for the queen. + +Preserved on every failure: driver return code, `errno`, driver text, and the +observed marker, marker2 and semaphore words. + +Cleanup runs on every exit where completion is known. If cleanup itself fails +after an earlier failure, the first failure is kept in the result and +`cleanup_failed` is set; the engine never overwrites the first failure. If +cleanup fails after an otherwise good run, the failure is CLEANUP, the last +state stays OUTPUT_PRODUCED, and the run is not SUCCESS. What the engine promises: "faithfully launched, the GPU completed, and these -bytes are genuinely its output". It never judges whether the math is correct. +bytes are not their poison words". It never judges whether the math is correct. -| # | Transition | Guard (check) | Failure name | Launcher step today (A1 / A1b) | -|---|---|---|---|---| -| 0 | start -> NONE | request is valid: kernel present, 1 to 8 outputs, backend table complete | DEVICE_ERROR, step "bad_request" | arg checks: divsqrt 1023, reduce 318 (BAD_ARGS) | -| 1 | NONE -> PREPARED | device and channel open; all buffers allocated; inputs copied in; outputs poison-filled | DEVICE_OPEN (steps "open", "channel"); DEVICE_ALLOC (steps "alloc_pb", "alloc_buffers"); DEVICE_ERROR (steps "copy_in", "poison") | open 1059, channel 1060, alloc_pb 1062, alloc_buffers 1073, fills 1075-1078 (divsqrt); open 324, channel 325, alloc 327-337, fills 340-341 (reduce); simt 103-129; ldst 268-286 | -| 2 | PREPARED -> SUBMITTED | backend builds QMD and pushbuffer and submits | DEVICE_SUBMIT (steps "build", "submit") | "submit": divsqrt 1154, reduce 448, simt 263, ldst 360, submit.c 200; "qmd"/"build_kernel": reduce 346, 370, simt 134, 180 | -| 3 | SUBMITTED -> GPU_COMPLETE | first marker seen; then marker2 (C3); then release semaphore; each within its own timeout | GPU_COMPLETION_TIMEOUT with wait = MARKER, MARKER2 or SEMAPHORE, `wait_timeout_ms`, `waited_ms`; a non-timeout driver fault gives DEVICE_ERROR | marker: divsqrt 1156 (600 s), reduce 449 (5 s), simt 267 (5 s), ldst 362 (600 s), submit.c 203 (5 s); marker2: divsqrt 1160-1162 (SILENT), reduce/ldst PR198 only; semaphore: divsqrt 1168, reduce 455, ldst 367; none in simt, instant compare only in submit.c 207 | -| 4 | GPU_COMPLETE -> OUTPUT_VISIBLE | barrier (dsb sy) succeeds and every output is copied back | OUTPUT_NOT_VISIBLE | dsb + memcpy: divsqrt 1171-1172, reduce 458-459; simt and submit.c have no dsb before readback (271, 210). No launcher can fail here today | -| 5 | OUTPUT_VISIBLE -> OUTPUT_PRODUCED | `omega_unwritten_scan` finds zero poison words in every output | OUTPUT_NOT_WRITTEN, with unwritten bytes per output | no launcher does this; only `tests/test_omega_unwritten_trap_gb10.c:158` scans after the call (A1 (b)) | -| 6 | OUTPUT_PRODUCED -> COMMITTED | every buffer freed and device closed without error | DEVICE_ERROR, step "cleanup" (state stays OUTPUT_PRODUCED) | close: divsqrt 1173, reduce 460, simt 273, ldst 370, submit.c 225; none frees buffers | +### 4.5 Transitions -Cleanup runs on every exit. If cleanup itself fails after an earlier failure, -the first failure is kept in the result; the engine never overwrites it. +| # | Transition | Guard (check) | Failure name, step | Launcher step today (A1 / A1b) | +|---|---|---|---|---| +| 0 | start -> INITIAL | the engine is not blocked; the job and result are well formed; the backend table is complete | UNCERTAIN_COMPLETION_BLOCKED, step BLOCKED; INVALID_ARGS, step VALIDATE; INTERNAL_INVARIANT, step BACKEND_CHECK | arg checks: divsqrt 1023, reduce 318 (BAD_ARGS) | +| 1 | INITIAL -> PREPARED | device and channel open; all buffers allocated; inputs copied in; output poison written; descriptors built | DEVICE_OPEN (OPEN_DEVICE); CHANNEL_CREATE (CREATE_CHANNEL); ALLOC (ALLOC); PREPARE (COPY_IN, FILL_POISON, BUILD) | vector: open 45, channel 46, alloc 50 and 58-64, qmd 118; divsqrt: open 1059, channel 1060, alloc 1062 and 1073, fills 1075-1078; reduce 324-341; ldst 268-286 | +| 2 | PREPARED -> SUBMITTED | the backend submits the work | SUBMIT (SUBMIT) | "submit": vector 200, divsqrt 1154, reduce 448, simt 263, ldst 360 | +| 3 | SUBMITTED -> GPU_COMPLETE | first marker seen; then marker2 (C3); then the release semaphore; each within its own timeout | COMPLETION_WAIT (WAIT_MARKER or WAIT_MARKER2); RELEASE_WAIT (WAIT_RELEASE_SEMAPHORE). Any non-zero wait result is an uncertain completion (section 5) | marker: vector 203 (5 s), divsqrt 1156 (600 s), reduce 449 (5 s), simt 267 (5 s), ldst 362 (600 s); marker2: divsqrt 1160-1162 (SILENT), reduce and ldst PR198 only; semaphore: divsqrt 1168, reduce 455, ldst 367; vector has an instant compare only at 207, simt has none | +| 4 | GPU_COMPLETE -> OUTPUT_VISIBLE | the barrier (`dsb sy`) succeeds within `visibility_ms` and the output is copied back | VISIBILITY_WAIT (BARRIER or COPY_OUT) | dsb + memcpy: divsqrt 1171-1172, reduce 458-459; vector 128 is before submit and the readback at 210 has no barrier; simt has none (271) | +| 5 | OUTPUT_VISIBLE -> OUTPUT_PRODUCED | no output word still equals its poison word | OUTPUT_UNCHANGED (SCAN), with the unchanged-word count per output | the vector executor poisons at lines 74-80 but the check lives in `omega_blackwell_gates.c:191`; `tests/test_omega_unwritten_trap_gb10.c:158` scans after the call (A1 (b)) | +| 6 | OUTPUT_PRODUCED -> SUCCESS | every buffer freed and the device closed without error | CLEANUP (FREE or CLOSE); last state stays OUTPUT_PRODUCED | close: vector 225, divsqrt 1173, reduce 460, simt 273, ldst 370; none frees buffers | + +Failures at steps 1, 2 and 4 and the late failures at 5 and 6 run cleanup +(free every allocated buffer, then close) before returning. A failure at step 3 +does not: see section 5. Mapping to the existing numeric codes (`src/omega_numeric.h:271-276`, A1 (d): OK 0, BAD_ARGS -1, NOT_ENCODED -2, OPERANDS -3, DEVICE -4, FPENV -5; no @@ -150,27 +262,82 @@ OK 0, BAD_ARGS -1, NOT_ENCODED -2, OPERANDS -3, DEVICE -4, FPENV -5; no | engine result | old code a migrating caller reports | |---|---| | OK | OK (0) | -| DEVICE_OPEN, DEVICE_ALLOC, DEVICE_SUBMIT, GPU_COMPLETION_TIMEOUT, OUTPUT_NOT_VISIBLE, DEVICE_ERROR (from the device) | ERR_DEVICE (-4) | -| DEVICE_ERROR with step "bad_request" | ERR_BAD_ARGS (-1) | -| OUTPUT_NOT_WRITTEN | ERR_DEVICE (-4) during migration; PROPOSED new `OMEGA_NUMERIC_ERR_UNWRITTEN` = -6 in a later PR | - -This PR does not edit `omega_numeric.h`. Callers keep reporting -4 during -migration, but the engine result carries the precise name, wait and time, so -the old code no longer hides the cause. - -## 5. Backend seam - -The engine core talks to the device only through a small table of function -pointers (`OmegaGpuEngineBackend` in `src/omega_gpu_engine.h`): open, alloc, -copy_in, poison_output, build_and_submit, wait_marker, wait_marker2, -wait_semaphore, flush_barrier, copy_out, free_buf, close. This lets a fake -backend drive every transition and every failure name in host tests. The one -addition to the list the program brief gave is `poison_output`, because the -poison fill is a device-side write today (A1 File 1: divsqrt 1077). - -A wait callback returns 0 when satisfied, a defined TIMEOUT value on timeout, -and any other nonzero value for a driver fault. The engine measures -`waited_ms` itself and captures `errno` right after a failing call. +| DEVICE_OPEN, CHANNEL_CREATE, ALLOC, PREPARE, SUBMIT, COMPLETION_WAIT, RELEASE_WAIT, VISIBILITY_WAIT, CLEANUP, UNCERTAIN_COMPLETION_BLOCKED, INTERNAL_INVARIANT | ERR_DEVICE (-4) | +| INVALID_ARGS | ERR_BAD_ARGS (-1) | +| OUTPUT_UNCHANGED | ERR_DEVICE (-4) during migration; PROPOSED new `OMEGA_NUMERIC_ERR_UNWRITTEN` = -6 in a later PR | + +This cut does not edit `omega_numeric.h`. Callers keep reporting -4 during +migration, but the engine result carries the precise name, step, wait and +time, so the old code no longer hides the cause. The vector executor returns +a bare -1 for every failure today (A1 File 4), so its wrapper decides its own +mapping when it migrates. + +## 5. Uncertain completion rule (plan item 7) + +If the engine cannot tell whether the GPU finished, it RETAINS the device +context and every allocation: no free, no close. "Cannot tell" means any +non-zero result from a completion wait (marker, marker2 or release +semaphore): a timeout (`OMEGA_GPU_BACKEND_TIMEOUT`), an unknown device state +(`OMEGA_GPU_BACKEND_UNKNOWN_STATE`), or a driver fault, because in each case the GPU may +still be running and may still write the buffers. The reason to retain: freeing +memory or closing the context under a running GPU could let it write into +memory that has been reused. (UNVERIFIED, 70%: the exact driver behavior on +freeing under a running channel was not measured by anyone in this program.) + +The engine then: +1. records in the result that context and allocations were retained + (`retained = 1`), the failure (COMPLETION_WAIT or RELEASE_WAIT), the wait, + `waited_ms`, driver return code, `errno`, driver text and the observed + marker, marker2 and semaphore words; +2. sets a process-wide block; +3. refuses every later `omega_gpu_execute` call in that process, in order + before argument checks, with UNCERTAIN_COMPLETION_BLOCKED at step BLOCKED + and last state INITIAL. + +Stub-level API for the block, in `src/omega_gpu_engine.h`: +`omega_gpu_engine_is_blocked()` returns 1 once blocked. A test-only +`omega_gpu_engine_test_reset_block()` clears it. A second test-only function, +`omega_gpu_engine_test_force_block()`, was added so the compile test can +exercise the blocked result before the real core exists. Production code +must never call either test function. There is no production way to clear the +block: recovery is a new process, and whether that is safe is unproven (section +10). + +## 6. Backend seam + +The engine core talks to the device only through the function table +`OmegaGpuBackend` in `src/omega_gpu_engine.h`, which carries its own context +pointer. The table: open_device, create_channel, alloc, copy_in, fill_poison, +build, submit, wait_marker, wait_marker2, wait_release_semaphore, barrier, +copy_out, diagnostics, free_buf, close. This lets a fake backend drive every +transition and every failure name in host tests. Compared with the first +draft: open is split into open_device and create_channel so DEVICE_OPEN and +CHANNEL_CREATE are told apart; `build_and_submit` is split into `build` and +`submit` so PREPARE and SUBMIT are told apart; the `diagnostics` callback +returns the raw driver code, driver text and observed sync words; and the +roles are the vector layout's (program, input A, input B, output, backend +scratch). + +A wait callback returns 0 when satisfied, `OMEGA_GPU_BACKEND_TIMEOUT` on +timeout, `OMEGA_GPU_BACKEND_UNKNOWN_STATE` when the device reports a state the +backend cannot classify, and any other non-zero value for a driver fault. The +engine measures `waited_ms` itself and captures `errno` right after a failing +call. The barrier callback uses the same codes, but a barrier failure is a +VISIBILITY_WAIT, which is not an uncertain completion because completion is +already known at that point. + +Default backend. `omega_gpu_execute` uses a process-wide default backend +pointer. Real code sets it with `omega_gpu_engine_set_backend`; host tests set +a fake. With none set, `omega_gpu_execute` returns the defined stub result +(INTERNAL_INVARIANT, step NOT_IMPLEMENTED) until the A3 core exists. + +Replaced call. The first draft had `omega_gpu_engine_run(backend, ctx, +request, result)`. It is replaced by `omega_gpu_execute(job, result)` plus the +default-backend setter, because plan item 5 fixes the public call. Nothing +needed the explicit-backend call: a test that wants a fake sets it as the +default. The first draft's `OmegaGpuEngineRequest` and its multi-buffer, flags +and opaque-launch-descriptor fields are replaced by `OmegaGpuJob` +(VECTOR_1D only). The real Blackwell GB10 backend wraps the same `m16_native_*` calls the launchers use today: open, create_channel, alloc_memory, free_memory, @@ -182,52 +349,87 @@ CPU_ONLY seam. The device backend is compiled out under `OMEGA_NUMERIC_CPU_ONLY`, exactly like the reduce launcher: include guards at `src/omega_numeric_reduce_gb10.c:38-41`, the executor guarded at 258, and the early return at 479-480 (A1 (c)). The engine core and the fake backend need no -physics headers and build under that flag. The phase A2 header includes no -physics header at all. +physics headers and build under that flag. The header includes no physics +header at all. -## 6. What is NOT changed +## 7. What this cut changes -This PR changes no gate measurement, no kernel, no launcher and no evidence -file. It adds only: this document, `src/omega_gpu_engine.h`, -`src/omega_gpu_engine.c` (a stub), `mk/omega-gpu-engine.mk` and -`tests/test_omega_gpu_engine_compile.c`. The top-level Makefile is not edited -(omega#198 edits it). None of the files in the omega#198 list is touched -(A1b section 6). In particular `src/omega_blackwell_submit.c` is not edited in -Phase A: its sha256 is recomputed by `tests/run_m17_gates.sh:66-67,129-130` -and `src/omega_blackwell_gates.c:1166-1167` (A1b section 1), so any edit -invalidates chip receipts and can only be verified on the chip. +This commit changes no gate measurement, no kernel, no launcher and no +evidence file. It changes only: this document, `src/omega_gpu_engine.h`, +`src/omega_gpu_engine.c` (still a stub) and +`tests/test_omega_gpu_engine_compile.c`. `mk/omega-gpu-engine.mk` is unchanged. +The top-level Makefile is not edited (omega#198 edits it). No launcher file and +not `src/omega_blackwell_submit.c` is edited in this cut. None of the files in +the omega#198 list is touched (A1b section 6). -## 7. Phase plan +## 8. Phase plan (corrected) Receipts that exist today: NONE. All labels are NOT_RUN. -1. A2 (this PR, draft): design doc, header, compiling stub, and - `make test-gpu-engine-compile`, which checks the stub's exact return values - and that every enum name is distinct. Host NOT_RUN until the forge runs it. -2. A3 (stacked on A2): engine core, a fake backend, a host test that drives - every transition and every failure name, and mutants that remove each - transition check (each mutant must make the test fail). -3. Phase B, held until the queen says the GPU is released. The Blackwell GB10 - backend is evolved out of `src/omega_blackwell_submit.c` (it is the - file that already owns the 18-word setup, the pushbuffer, the 0x44444444 - marker and the semaphore constants, A1b section 1). Conversion order, with - real GB10 tests before the next step starts: - 1. Reduce launcher first. - 2. Load/store launcher. - 3. Base executor (`omega_numeric_gb10.c`), then divsqrt, then - `omega_blackwell_submit.c`. - 4. A final PR deletes the old duplicated launch code. - Moving `omega_blackwell_submit.c` re-seals the M17 and M18 digests, which - needs a chip rerun (A1b "Implications"). Any PR that touches it stays DRAFT - until its chip gate passes. Converting `omega_numeric_gb10.c` and - `omega_blackwell_submit.c` also adds the semaphore wait and the C3 protection - they lack today (A1 headline 3 and 4): a behavior change, tested on the chip. - The numeric launchers do not link `omega_blackwell_submit.c` today (A1b - section 1), so their chip build recipes (`tests/run_numeric_gates.sh:156-163`, - `tests/run_reduce_chip.sh:64`, `tests/run_tensor_chip.sh:67`) must gain the - engine sources at the step that converts them. - -## 8. Open questions and UNVERIFIED items +Correction to the first draft: Phase A may edit `src/omega_blackwell_submit.c` +and `.h`. Drake asked for that twice (queen ruling). The condition is that any +PR touching `omega_blackwell_submit.c` stays DRAFT and cannot merge until the +M17 and M18 gates and the vector chip test have run in Phase B. The reason is +the file's sha256 pin: `tests/run_m17_gates.sh:66-67,129-130` and +`src/omega_blackwell_gates.c:1166-1167` (A1b section 1). Existing blackwell +chip gates must keep measuring the same things: no gate changes. + +Phase A (light lane only, no GPU): +1. A2 (omega#218, draft): this document, the header, the compiling stub and + `make test-gpu-engine-compile`, which checks the stub's exact return values, + that every enum name is distinct, and that the block functions behave as + specified. +2. A3 (stacked): the engine core in `src/omega_gpu_engine.c`. +3. `src/omega_blackwell_engine.c/.h`: the GB10 backend extracted from + `omega_blackwell_execute_vector`. +4. Edit `src/omega_blackwell_submit.c/.h` so the vector executor becomes a + wrapper over the engine (it supplies poison guaranteed to differ from its + expected outputs, and keeps the arithmetic oracle). DRAFT only. +5. `tests/test_omega_gpu_engine.c`: host test of the REAL engine core against a + simulated driver, driving every transition and every failure name, the + uncertain-completion block, and cleanup-failure precedence. +6. A mutation sweep on the shared runner `tools/mutation_runner.sh` + (merged in omega#204, no Python; edit kinds sed, marker-sed and replace). + Each mutant removes one protection (poison write, unchanged check, marker2 + wait, release wait, barrier, retain-on-uncertain, block, cleanup) and must be + KILLED by the host test. +7. `tests/test_omega_gpu_engine_gb10.c` and + `tools/manifests/gpu_engine.chiprun`, written now in the format of + `tools/manifests/unwritten_trap.chiprun` over `tools/chip_run.sh` + (omega#205, both on origin/main). Written in Phase A, run only in Phase B. +8. Before any chip test (plan item 10): the host test above, the mutant sweep, + the existing numeric, reduction and DIV/SQRT host regressions, and a + production build at the pinned PHYSICS version. + +Phase B, held until the queen says the GPU is released. Conversion order is +unchanged, with real GB10 tests before the next step starts: +1. The vector chip test, and the M17 and M18 gates for the edited + `omega_blackwell_submit.c` (the sha256 pin is re-sealed by a chip rerun). +2. Reduce launcher: the FIRST NUMERIC migration. +3. Load/store launcher. +4. Base executor (`omega_numeric_gb10.c`), then divsqrt, then the remaining + executors in `omega_blackwell_submit.c`. +5. A final PR deletes the old duplicated launch code. + +Converting `omega_numeric_gb10.c` and the remaining `omega_blackwell_submit.c` +executors also adds the semaphore wait and the C3 protection they lack today +(A1 headline 3 and 4): a behavior change, tested on the chip. The numeric +launchers do not link `omega_blackwell_submit.c` today (A1b section 1), so +their chip build recipes (`tests/run_numeric_gates.sh:156-163`, +`tests/run_reduce_chip.sh:64`, `tests/run_tensor_chip.sh:67`) must gain the +engine sources at the step that converts them. + +## 9. Order note + +Vector addition is the engine SEED: it proves the engine using the path +already inside `omega_blackwell_submit.c`. Reduce stays the first numeric +migration in Phase B. + +## 10. Unproven until chip + +Unproven assumptions: sufficiency of this synchronization sequence for the vector path; cache visibility under faults; safe recovery after uncertain completion; suitability for persistent kernels. Host tests cannot prove those. E1 untouched; this cut is not chip-qualified. + +## 11. Open questions and UNVERIFIED items Carried from A1 and A1b, plus new ones from this cut: 1. The E1 marker2 timeout case in section 2 is reported, receipt not read. @@ -235,20 +437,39 @@ Carried from A1 and A1b, plus new ones from this cut: a glob or a tool compiles it (A1 open questions). 3. PR198 line numbers in this document may have drifted; the head moved from 617971aa to 44741c1b (A1b section 6). -4. No GPU run was done by the scouts; chip behavior is code-reading only (A1). -5. The poison value used by `omega_blackwell_submit.c` was not read; 75% it is - 0x55 (A1b open question 1). +4. No GPU run was done by the scouts or by this cut; chip behavior is code + reading only. +5. The A1 scout said `omega_blackwell_submit.c` has no poison fill; the source + on this branch fills the vector output with `0xdeadbeef` (lines 74-80, and + at 286 for the matrix path). Poison is uniform there, so the wrapper will + supply an array filled with that word. 6. Whether the NUM files carry their own 18 setup words: 70% yes (A1b open question 3). Three implementations of those words likely exist, which the backend should unify. 7. `omega_world_dispatch_matmul` was read only by grep (A1b open question 5). 8. How `--run-m18-gates` is invoked from the Makefile or tools: 70% a tools script (A1b open question 2). -9. New: a legitimate output equal to the poison word 0x55555555 (a valid float) - would be reported as unwritten. The poison is a per-output field so a caller - can choose another word. Likelihood unmeasured. -10. New: there is no BAD_REQUEST failure name, because the brief fixes the - vocabulary. The stub reports a bad request as DEVICE_ERROR with step - "bad_request". A3 or the queen may add a name. -11. New: the numeric code -6 for "unwritten" is a proposal only. -12. New: the choice of `waited_ms` measurement clock is left to A3. +9. A legitimate output equal to its poison word would be reported as unchanged. + The wrapper must pick poison guaranteed to differ from the expected output; + the engine cannot check that. Likelihood unmeasured. +10. The numeric code -6 for "unwritten" is a proposal only. +11. The clock used for `waited_ms` is left to A3. +12. Whether a failed SUBMIT can leave work queued on the GPU is unknown (no + evidence read). This cut treats SUBMIT as a known failure and runs cleanup; + the queen may want SUBMIT to count as uncertain too. UNVERIFIED, 50%. +13. Whether the COMPLETION_WAIT / RELEASE_WAIT split in section 4.4 matches + the queen's intent. + +## 12. Changes from the first draft (omega#218 commit 6e077f1) + +| first draft | now | +|---|---| +| `omega_gpu_engine_run(backend, ctx, request, result)`, `OmegaGpuEngineRequest/Result` | `omega_gpu_execute(job, result)`, `OmegaGpuJob/Result`, default backend setter | +| states NONE .. COMMITTED | states INITIAL .. SUCCESS | +| failures DEVICE_OPEN, DEVICE_ALLOC, DEVICE_SUBMIT, GPU_COMPLETION_TIMEOUT, OUTPUT_NOT_VISIBLE, OUTPUT_NOT_WRITTEN, DEVICE_ERROR | DEVICE_OPEN, CHANNEL_CREATE, ALLOC, PREPARE, SUBMIT, COMPLETION_WAIT, RELEASE_WAIT, VISIBILITY_WAIT, OUTPUT_UNCHANGED, INVALID_ARGS, INTERNAL_INVARIANT, CLEANUP, UNCERTAIN_COMPLETION_BLOCKED | +| wait name SEMAPHORE | wait name RELEASE_SEMAPHORE | +| step as a string | step as an enum with names | +| poison per output buffer, default 0x55555555, engine default | poison array supplied by the wrapper, engine never chooses | +| flag NO_POISON | removed: poison is always on | +| Phase A may not edit `omega_blackwell_submit.c` | Phase A may edit it as a DRAFT that cannot merge before the M17/M18 gates and the vector chip test | +| mutation tool: unspecified | shared shell runner `tools/mutation_runner.sh` | diff --git a/src/omega_gpu_engine.c b/src/omega_gpu_engine.c index 00e626435..4a30c2ff3 100644 --- a/src/omega_gpu_engine.c +++ b/src/omega_gpu_engine.c @@ -1,42 +1,76 @@ /* - * Omega GPU Engine, A2 compile stub. See src/omega_gpu_engine.h and - * docs/numeric/OMEGA_GPU_ENGINE.md. No launch logic yet: omega_gpu_engine_run - * validates its arguments, then reports DEVICE_ERROR at step "not_implemented". - * The real engine core (A3) replaces omega_gpu_engine_run; the name functions - * below are final. + * Omega GPU Engine, A2b compile stub. See src/omega_gpu_engine.h and + * docs/numeric/OMEGA_GPU_ENGINE.md. No launch logic yet: omega_gpu_execute + * checks the block, validates the job, then reports INTERNAL_INVARIANT at step + * NOT_IMPLEMENTED. The real engine core (A3) replaces omega_gpu_execute and + * sets the block on uncertain completion; the name functions, the backend + * pointer and the block query below are final. */ #include "omega_gpu_engine.h" +#include #include static const char *const FAILURE_NAMES[OMEGA_GPU_ENGINE_FAILURE_COUNT] = { "OK", "DEVICE_OPEN", - "DEVICE_ALLOC", - "DEVICE_SUBMIT", - "GPU_COMPLETION_TIMEOUT", - "OUTPUT_NOT_VISIBLE", - "OUTPUT_NOT_WRITTEN", - "DEVICE_ERROR", + "CHANNEL_CREATE", + "ALLOC", + "PREPARE", + "SUBMIT", + "COMPLETION_WAIT", + "RELEASE_WAIT", + "VISIBILITY_WAIT", + "OUTPUT_UNCHANGED", + "INVALID_ARGS", + "INTERNAL_INVARIANT", + "CLEANUP", + "UNCERTAIN_COMPLETION_BLOCKED", }; static const char *const STATE_NAMES[OMEGA_GPU_ENGINE_STATE_COUNT] = { - "NONE", + "INITIAL", "PREPARED", "SUBMITTED", "GPU_COMPLETE", "OUTPUT_VISIBLE", "OUTPUT_PRODUCED", - "COMMITTED", + "SUCCESS", }; static const char *const WAIT_NAMES[OMEGA_GPU_ENGINE_WAIT_COUNT] = { "NONE", "MARKER", - "SEMAPHORE", + "RELEASE_SEMAPHORE", "MARKER2", }; +static const char *const STEP_NAMES[OMEGA_GPU_ENGINE_STEP_COUNT] = { + "NONE", + "VALIDATE", + "BACKEND_CHECK", + "BLOCKED", + "NOT_IMPLEMENTED", + "OPEN_DEVICE", + "CREATE_CHANNEL", + "ALLOC", + "COPY_IN", + "FILL_POISON", + "BUILD", + "SUBMIT", + "WAIT_MARKER", + "WAIT_MARKER2", + "WAIT_RELEASE_SEMAPHORE", + "BARRIER", + "COPY_OUT", + "SCAN", + "FREE", + "CLOSE", +}; + +static _Atomic(const OmegaGpuBackend *) g_backend; +static atomic_int g_blocked; + const char *omega_gpu_engine_failure_name(int failure) { if (failure < 0 || failure >= (int)OMEGA_GPU_ENGINE_FAILURE_COUNT) return "UNKNOWN"; @@ -55,36 +89,85 @@ const char *omega_gpu_engine_wait_name(int wait) return WAIT_NAMES[wait]; } -static int backend_complete(const OmegaGpuEngineBackend *b) +const char *omega_gpu_engine_step_name(int step) +{ + if (step < 0 || step >= (int)OMEGA_GPU_ENGINE_STEP_COUNT) return "UNKNOWN"; + return STEP_NAMES[step]; +} + +void omega_gpu_engine_set_backend(const OmegaGpuBackend *backend) +{ + atomic_store(&g_backend, backend); +} + +int omega_gpu_engine_is_blocked(void) { - return b->open && b->alloc && b->copy_in && b->poison_output && b->build_and_submit && - b->wait_marker && b->wait_marker2 && b->wait_semaphore && b->flush_barrier && - b->copy_out && b->free_buf && b->close; + return atomic_load(&g_blocked) ? 1 : 0; } -static int request_valid(const OmegaGpuEngineRequest *rq) +void omega_gpu_engine_test_reset_block(void) { - if (!rq->kernel_image || rq->kernel_len == 0) return 0; - if (rq->n_inputs > OMEGA_GPU_ENGINE_MAX_BUFFERS) return 0; - if (rq->n_outputs == 0 || rq->n_outputs > OMEGA_GPU_ENGINE_MAX_BUFFERS) return 0; - if (rq->n_inputs > 0 && !rq->inputs) return 0; - if (!rq->outputs) return 0; + atomic_store(&g_blocked, 0); +} + +void omega_gpu_engine_test_force_block(void) +{ + atomic_store(&g_blocked, 1); +} + +static int backend_complete(const OmegaGpuBackend *b) +{ + return b->open_device && b->create_channel && b->alloc && b->copy_in && b->fill_poison && + b->build && b->submit && b->wait_marker && b->wait_marker2 && + b->wait_release_semaphore && b->barrier && b->copy_out && b->diagnostics && + b->free_buf && b->close; +} + +/* Returns 1 when the job is well formed for the VECTOR_1D layout. */ +static int job_valid(const OmegaGpuJob *job) +{ + uint64_t bytes; + if (!job->program || job->program_len == 0) return 0; + if (job->layout != OMEGA_GPU_LAYOUT_VECTOR_1D) return 0; + if (job->element_count == 0) return 0; + bytes = (uint64_t)job->element_count * 4u; + if (!job->input_a || (uint64_t)job->input_a_len != bytes) return 0; + if (!job->input_b || (uint64_t)job->input_b_len != bytes) return 0; + if (!job->output || (uint64_t)job->output_len != bytes) return 0; + if (((uintptr_t)job->output & 3u) != 0) return 0; + if (!job->poison || (uint64_t)job->poison_count != (uint64_t)job->element_count) return 0; + if ((job->flags & ~(uint32_t)OMEGA_GPU_ENGINE_FLAG_NO_C3) != 0) return 0; + if (job->timeouts.marker_ms == 0) return 0; + if (job->timeouts.release_semaphore_ms == 0) return 0; + if (job->timeouts.visibility_ms == 0) return 0; + if ((job->flags & OMEGA_GPU_ENGINE_FLAG_NO_C3) == 0 && job->timeouts.marker2_ms == 0) return 0; return 1; } -int omega_gpu_engine_run(const OmegaGpuEngineBackend *b, void *backend_ctx, - const OmegaGpuEngineRequest *rq, OmegaGpuEngineResult *out) +static int stop(OmegaGpuResult *result, int failure, int step) +{ + result->failure = failure; + result->failed_step = step; + return failure; +} + +int omega_gpu_execute(const OmegaGpuJob *job, OmegaGpuResult *result) { - (void)backend_ctx; - if (!out) return OMEGA_GPU_ENGINE_DEVICE_ERROR; - memset(out, 0, sizeof *out); - out->state = OMEGA_GPU_ENGINE_STATE_NONE; - out->failure = OMEGA_GPU_ENGINE_DEVICE_ERROR; - out->wait = OMEGA_GPU_ENGINE_WAIT_NONE; - if (!b || !rq || !backend_complete(b) || !request_valid(rq)) { - out->step = "bad_request"; - return OMEGA_GPU_ENGINE_DEVICE_ERROR; - } - out->step = "not_implemented"; - return OMEGA_GPU_ENGINE_DEVICE_ERROR; + const OmegaGpuBackend *b; + if (!result) return OMEGA_GPU_ENGINE_INVALID_ARGS; + memset(result, 0, sizeof *result); + result->failure = OMEGA_GPU_ENGINE_OK; + result->last_state = OMEGA_GPU_ENGINE_STATE_INITIAL; + result->failed_step = OMEGA_GPU_ENGINE_STEP_NONE; + result->wait = OMEGA_GPU_ENGINE_WAIT_NONE; + if (omega_gpu_engine_is_blocked()) + return stop(result, OMEGA_GPU_ENGINE_UNCERTAIN_COMPLETION_BLOCKED, + OMEGA_GPU_ENGINE_STEP_BLOCKED); + if (!job || !job_valid(job)) + return stop(result, OMEGA_GPU_ENGINE_INVALID_ARGS, OMEGA_GPU_ENGINE_STEP_VALIDATE); + b = atomic_load(&g_backend); + if (b && !backend_complete(b)) + return stop(result, OMEGA_GPU_ENGINE_INTERNAL_INVARIANT, + OMEGA_GPU_ENGINE_STEP_BACKEND_CHECK); + return stop(result, OMEGA_GPU_ENGINE_INTERNAL_INVARIANT, OMEGA_GPU_ENGINE_STEP_NOT_IMPLEMENTED); } diff --git a/src/omega_gpu_engine.h b/src/omega_gpu_engine.h index 0aefdfa70..cc72ea57c 100644 --- a/src/omega_gpu_engine.h +++ b/src/omega_gpu_engine.h @@ -1,26 +1,36 @@ /* - * Omega GPU Engine: launch one already-built GPU kernel and return SUCCESS or + * Omega GPU Engine: run one already-built GPU kernel job and return SUCCESS or * exactly one named failure. * - * Purpose: today five launcher files repeat the same open / alloc / copy-in / + * Purpose: today several launcher files repeat the same open / alloc / copy-in / * pushbuffer / submit / completion-wait / readback / close sequence with three * different error styles. This module owns that sequence once. Design: - * docs/numeric/OMEGA_GPU_ENGINE.md. + * docs/numeric/OMEGA_GPU_ENGINE.md (the first-cut plan is Drake's, 2026-10-02). * - * Contract: the caller gives a kernel image, an opaque launch descriptor, - * input buffers, output buffers and per-step timeouts. The engine walks the - * states NONE -> PREPARED -> SUBMITTED -> GPU_COMPLETE -> OUTPUT_VISIBLE -> - * OUTPUT_PRODUCED -> COMMITTED. Success is returned only at COMMITTED. Every - * output is poison-filled before submit and must hold non-poison words before - * OUTPUT_PRODUCED. The engine never judges whether the math is right: it - * promises only "faithfully launched, GPU completed, these bytes are - * genuinely its output". + * Public entry point: + * int omega_gpu_execute(const OmegaGpuJob *job, OmegaGpuResult *result); + * It returns OMEGA_GPU_ENGINE_OK (0) on success, otherwise the failure code, + * which is also stored in result->failure. * - * Return value of omega_gpu_engine_run: 0 (OMEGA_GPU_ENGINE_OK) on success, - * otherwise the failure code, which is also stored in the result. + * States: INITIAL -> PREPARED -> SUBMITTED -> GPU_COMPLETE -> OUTPUT_VISIBLE -> + * OUTPUT_PRODUCED -> SUCCESS. The result records the last completed state and + * the precise failed step. (The earlier draft of this header called the final + * state COMMITTED and the first one NONE.) * - * STATUS: A2 stub. omega_gpu_engine_run does not launch anything yet; it - * validates its arguments and reports DEVICE_ERROR at step "not_implemented". + * Poison: the wrapper supplies one poison word per output word. The engine + * writes those words to the device output before submit and, after readback, + * checks only whether any word is still equal to its poison word. The engine + * never chooses poison and never judges whether the math is right. + * + * Uncertain completion: if the engine cannot tell whether the GPU finished (a + * completion wait timed out, or the device returned an unknown state), it keeps + * the device context and every allocation (no free, no close), records that in + * the result, and blocks every later omega_gpu_execute call in this process, + * which then returns UNCERTAIN_COMPLETION_BLOCKED. + * + * STATUS: A2b stub. omega_gpu_execute launches nothing yet. It validates its + * arguments and reports INTERNAL_INVARIANT at step NOT_IMPLEMENTED. This cut is + * not chip-qualified (host NOT_RUN, chip NOT_RUN). */ #ifndef OMEGA_GPU_ENGINE_H #define OMEGA_GPU_ENGINE_H @@ -28,135 +38,206 @@ #include #include -#define OMEGA_GPU_ENGINE_MAX_BUFFERS 8u -#define OMEGA_GPU_ENGINE_POISON_DEFAULT 0x55555555u - -/* Request flags. A zeroed request means: poison ON, C3 protection ON. */ -#define OMEGA_GPU_ENGINE_FLAG_NO_POISON 0x1u /* skip poison fill and unwritten scan */ -#define OMEGA_GPU_ENGINE_FLAG_NO_C3 0x2u /* A/B control arm only: skip L2 flush and marker2 */ - /* One failure name per run. OK is 0, so the return value reads as a boolean. */ typedef enum { OMEGA_GPU_ENGINE_OK = 0, - OMEGA_GPU_ENGINE_DEVICE_OPEN, - OMEGA_GPU_ENGINE_DEVICE_ALLOC, - OMEGA_GPU_ENGINE_DEVICE_SUBMIT, - OMEGA_GPU_ENGINE_GPU_COMPLETION_TIMEOUT, - OMEGA_GPU_ENGINE_OUTPUT_NOT_VISIBLE, - OMEGA_GPU_ENGINE_OUTPUT_NOT_WRITTEN, - OMEGA_GPU_ENGINE_DEVICE_ERROR, - OMEGA_GPU_ENGINE_FAILURE_COUNT /* not a failure: number of names above */ + OMEGA_GPU_ENGINE_DEVICE_OPEN, /* device could not be opened */ + OMEGA_GPU_ENGINE_CHANNEL_CREATE, /* channel could not be created */ + OMEGA_GPU_ENGINE_ALLOC, /* a device buffer could not be allocated */ + OMEGA_GPU_ENGINE_PREPARE, /* copy-in, poison fill or descriptor build failed */ + OMEGA_GPU_ENGINE_SUBMIT, /* submitting the work failed */ + OMEGA_GPU_ENGINE_COMPLETION_WAIT, /* marker or marker2 wait failed or timed out */ + OMEGA_GPU_ENGINE_RELEASE_WAIT, /* release semaphore wait failed or timed out */ + OMEGA_GPU_ENGINE_VISIBILITY_WAIT, /* barrier or readback failed or timed out */ + OMEGA_GPU_ENGINE_OUTPUT_UNCHANGED, /* after readback, output words still equal their poison */ + OMEGA_GPU_ENGINE_INVALID_ARGS, /* the job or the result pointer is malformed */ + OMEGA_GPU_ENGINE_INTERNAL_INVARIANT, /* the engine or its backend broke its own contract */ + OMEGA_GPU_ENGINE_CLEANUP, /* free or close failed after an otherwise good run */ + OMEGA_GPU_ENGINE_UNCERTAIN_COMPLETION_BLOCKED, /* an earlier job left completion uncertain */ + OMEGA_GPU_ENGINE_FAILURE_COUNT /* not a failure: number of names above */ } OmegaGpuEngineFailure; -/* How far a run got. Success is only COMMITTED. */ +/* How far a run got. Success is only SUCCESS. */ typedef enum { - OMEGA_GPU_ENGINE_STATE_NONE = 0, /* nothing done yet (device may be unopened) */ + OMEGA_GPU_ENGINE_STATE_INITIAL = 0, /* nothing completed yet (device may be unopened) */ OMEGA_GPU_ENGINE_STATE_PREPARED, OMEGA_GPU_ENGINE_STATE_SUBMITTED, OMEGA_GPU_ENGINE_STATE_GPU_COMPLETE, OMEGA_GPU_ENGINE_STATE_OUTPUT_VISIBLE, OMEGA_GPU_ENGINE_STATE_OUTPUT_PRODUCED, - OMEGA_GPU_ENGINE_STATE_COMMITTED, + OMEGA_GPU_ENGINE_STATE_SUCCESS, OMEGA_GPU_ENGINE_STATE_COUNT /* not a state: number of names above */ } OmegaGpuEngineState; -/* Which completion wait timed out (only meaningful for GPU_COMPLETION_TIMEOUT). */ +/* Which completion wait failed (meaningful for COMPLETION_WAIT and RELEASE_WAIT). */ typedef enum { OMEGA_GPU_ENGINE_WAIT_NONE = 0, OMEGA_GPU_ENGINE_WAIT_MARKER, - OMEGA_GPU_ENGINE_WAIT_SEMAPHORE, + OMEGA_GPU_ENGINE_WAIT_RELEASE_SEMAPHORE, OMEGA_GPU_ENGINE_WAIT_MARKER2, OMEGA_GPU_ENGINE_WAIT_COUNT /* not a wait: number of names above */ } OmegaGpuEngineWait; -/* What a device buffer is for. SCRATCH is backend-internal (pushbuffer, completion - * marker, QMD); the engine asks for it once so its allocation failure is named. */ +/* The precise step that failed (the step the run was in when it stopped). */ typedef enum { - OMEGA_GPU_ENGINE_BUF_SCRATCH = 0, - OMEGA_GPU_ENGINE_BUF_KERNEL, - OMEGA_GPU_ENGINE_BUF_LAUNCH, - OMEGA_GPU_ENGINE_BUF_INPUT, - OMEGA_GPU_ENGINE_BUF_OUTPUT -} OmegaGpuEngineBufRole; - -/* A wait callback returns 0 when satisfied, this value on timeout, any other - * nonzero value on a driver fault (reported as DEVICE_ERROR, value kept as drv_rc). */ -#define OMEGA_GPU_ENGINE_BACKEND_TIMEOUT 1 + OMEGA_GPU_ENGINE_STEP_NONE = 0, /* no step failed (success) */ + OMEGA_GPU_ENGINE_STEP_VALIDATE, + OMEGA_GPU_ENGINE_STEP_BACKEND_CHECK, + OMEGA_GPU_ENGINE_STEP_BLOCKED, + OMEGA_GPU_ENGINE_STEP_NOT_IMPLEMENTED, + OMEGA_GPU_ENGINE_STEP_OPEN_DEVICE, + OMEGA_GPU_ENGINE_STEP_CREATE_CHANNEL, + OMEGA_GPU_ENGINE_STEP_ALLOC, + OMEGA_GPU_ENGINE_STEP_COPY_IN, + OMEGA_GPU_ENGINE_STEP_FILL_POISON, + OMEGA_GPU_ENGINE_STEP_BUILD, + OMEGA_GPU_ENGINE_STEP_SUBMIT, + OMEGA_GPU_ENGINE_STEP_WAIT_MARKER, + OMEGA_GPU_ENGINE_STEP_WAIT_MARKER2, + OMEGA_GPU_ENGINE_STEP_WAIT_RELEASE_SEMAPHORE, + OMEGA_GPU_ENGINE_STEP_BARRIER, + OMEGA_GPU_ENGINE_STEP_COPY_OUT, + OMEGA_GPU_ENGINE_STEP_SCAN, + OMEGA_GPU_ENGINE_STEP_FREE, + OMEGA_GPU_ENGINE_STEP_CLOSE, + OMEGA_GPU_ENGINE_STEP_COUNT /* not a step: number of names above */ +} OmegaGpuEngineStep; + +/* Argument layouts the engine accepts. Later layouts are separate qualified cuts. */ +typedef enum { + OMEGA_GPU_LAYOUT_VECTOR_1D = 0, /* two inputs, one output, element_count 32-bit words each */ + OMEGA_GPU_LAYOUT_COUNT /* not a layout: number of layouts above */ +} OmegaGpuLayout; -typedef struct { - const void *ptr; - size_t len; /* bytes */ -} OmegaGpuEngineInBuf; +/* Job flags. A zero flags word means every protection ON. */ +#define OMEGA_GPU_ENGINE_FLAG_NO_C3 0x1u /* A/B control arm only: skip L2 flush and marker2 */ -typedef struct { - void *ptr; /* host destination, must be 4-byte aligned when poison is on */ - size_t len; /* bytes, multiple of 4 when poison is on */ - uint32_t poison; /* 0 means OMEGA_GPU_ENGINE_POISON_DEFAULT */ -} OmegaGpuEngineOutBuf; +#define OMEGA_GPU_ENGINE_JOB_OUTPUTS 1u /* VECTOR_1D has exactly one output buffer */ +#define OMEGA_GPU_ENGINE_SEMAPHORE_WORDS 1u /* the vector path uses one semaphore word */ +#define OMEGA_GPU_ENGINE_DRV_TEXT_BYTES 128u /* Per-step timeouts in milliseconds. Never hard-coded by the engine. Each wait * that is enabled needs a value greater than 0 (marker2_ms is ignored with NO_C3). */ typedef struct { uint64_t marker_ms; - uint64_t semaphore_ms; + uint64_t release_semaphore_ms; uint64_t marker2_ms; -} OmegaGpuEngineTimeouts; + uint64_t visibility_ms; +} OmegaGpuTimeouts; typedef struct { - const void *kernel_image; /* already-built kernel code */ - size_t kernel_len; - const void *launch; /* opaque launch descriptor, passed through untouched */ - size_t launch_len; - const OmegaGpuEngineInBuf *inputs; - size_t n_inputs; /* at most OMEGA_GPU_ENGINE_MAX_BUFFERS */ - const OmegaGpuEngineOutBuf *outputs; - size_t n_outputs; /* 1 .. OMEGA_GPU_ENGINE_MAX_BUFFERS */ - OmegaGpuEngineTimeouts timeouts; + const void *program; /* encoded program bytes, already built by the caller */ + size_t program_len; /* bytes, > 0 */ + int layout; /* OmegaGpuLayout; only VECTOR_1D today */ + uint32_t element_count; /* > 0; each buffer below holds element_count 32-bit words */ + const void *input_a; /* element_count * 4 bytes */ + size_t input_a_len; + const void *input_b; /* element_count * 4 bytes */ + size_t input_b_len; + void *output; /* host destination, 4-byte aligned, element_count * 4 bytes */ + size_t output_len; + const uint32_t *poison; /* wrapper-supplied, one word per output word */ + size_t poison_count; /* must equal element_count */ + OmegaGpuTimeouts timeouts; uint32_t flags; /* OMEGA_GPU_ENGINE_FLAG_* */ -} OmegaGpuEngineRequest; +} OmegaGpuJob; typedef struct { - int state; /* last OmegaGpuEngineState reached */ int failure; /* OmegaGpuEngineFailure, OK on success */ - const char *step; /* static string naming the failing step, "ok" on success */ - int wait; /* OmegaGpuEngineWait, NONE unless a completion wait failed */ + int last_state; /* last COMPLETED OmegaGpuEngineState */ + int failed_step; /* OmegaGpuEngineStep, NONE on success */ + int wait; /* OmegaGpuEngineWait, NONE unless a completion or release wait failed */ uint64_t wait_timeout_ms; /* the configured limit of that wait */ uint64_t waited_ms; /* how long the engine actually waited before giving up */ int drv_rc; /* driver return code of the failing call, 0 if none */ int err_no; /* errno captured right after the failing call, 0 if none */ - size_t n_outputs; /* number of valid entries in unwritten_bytes */ - uint64_t unwritten_bytes[OMEGA_GPU_ENGINE_MAX_BUFFERS]; /* poison bytes left, per output */ -} OmegaGpuEngineResult; + char drv_text[OMEGA_GPU_ENGINE_DRV_TEXT_BYTES]; /* driver message, NUL terminated, "" if none */ + uint32_t sync_valid; /* OMEGA_GPU_SYNC_* mask: which observed values below are meaningful */ + uint32_t marker; /* observed first marker word */ + uint32_t marker2; /* observed second marker word */ + uint32_t semaphore[OMEGA_GPU_ENGINE_SEMAPHORE_WORDS]; /* observed semaphore words */ + int retained; /* 1 when context and allocations were kept (uncertain completion) */ + int cleanup_failed; /* 1 when free or close failed (first failure is never overwritten) */ + size_t n_outputs; /* number of valid entries in output_unchanged_words */ + uint64_t output_unchanged_words[OMEGA_GPU_ENGINE_JOB_OUTPUTS]; /* words still equal to poison, per output */ +} OmegaGpuResult; + +#define OMEGA_GPU_SYNC_MARKER 0x1u +#define OMEGA_GPU_SYNC_MARKER2 0x2u +#define OMEGA_GPU_SYNC_SEMAPHORE 0x4u /* - * Backend seam. Every callback returns 0 on success and nonzero on failure, - * except where noted. A fake backend implements these to drive every - * transition in host tests; the Blackwell GB10 backend wraps the m16_native_* - * calls the launchers use today (physics/m16/m16_native.h). All callbacks must - * be non-NULL. + * Backend seam. A fake backend implements these to drive every transition in + * host tests; the Blackwell GB10 backend (src/omega_blackwell_engine.c, later + * cut) wraps the m16_native_* calls the launchers use today. All callbacks + * must be non-NULL. Every callback returns 0 on success. The three wait + * callbacks and the barrier may also return: */ +#define OMEGA_GPU_BACKEND_TIMEOUT 1 /* the wait ran out of time */ +#define OMEGA_GPU_BACKEND_UNKNOWN_STATE 2 /* the device reported a state the backend cannot classify */ +/* Any other nonzero value is a driver fault; the backend reports its raw driver code via diagnostics. */ + +typedef enum { + OMEGA_GPU_BUF_SCRATCH = 0, /* backend-internal: pushbuffer, marker page, QMD */ + OMEGA_GPU_BUF_PROGRAM, + OMEGA_GPU_BUF_INPUT_A, + OMEGA_GPU_BUF_INPUT_B, + OMEGA_GPU_BUF_OUTPUT, + OMEGA_GPU_BUF_ROLE_COUNT /* not a role: number of roles above */ +} OmegaGpuBufRole; + +typedef struct { + int drv_rc; + char drv_text[OMEGA_GPU_ENGINE_DRV_TEXT_BYTES]; + uint32_t sync_valid; /* OMEGA_GPU_SYNC_* */ + uint32_t marker; + uint32_t marker2; + uint32_t semaphore[OMEGA_GPU_ENGINE_SEMAPHORE_WORDS]; +} OmegaGpuBackendDiag; + typedef struct { - int (*open)(void *ctx); /* device + channel */ - int (*alloc)(void *ctx, int role, unsigned index, size_t bytes); - int (*copy_in)(void *ctx, int role, unsigned index, const void *src, size_t bytes); - int (*poison_output)(void *ctx, unsigned index, uint32_t word, size_t bytes); /* device side */ - int (*build_and_submit)(void *ctx, const OmegaGpuEngineRequest *rq); - int (*wait_marker)(void *ctx, uint64_t timeout_ms); /* may return BACKEND_TIMEOUT */ - int (*wait_marker2)(void *ctx, uint64_t timeout_ms); /* may return BACKEND_TIMEOUT */ - int (*wait_semaphore)(void *ctx, uint64_t timeout_ms); /* may return BACKEND_TIMEOUT */ - int (*flush_barrier)(void *ctx); /* dsb sy before readback */ - int (*copy_out)(void *ctx, unsigned index, void *dst, size_t bytes); - int (*free_buf)(void *ctx, int role, unsigned index); + void *ctx; /* passed to every callback; owned by the backend */ + int (*open_device)(void *ctx); + int (*create_channel)(void *ctx); + int (*alloc)(void *ctx, int role, size_t bytes); + int (*copy_in)(void *ctx, int role, const void *src, size_t bytes); + int (*fill_poison)(void *ctx, const uint32_t *words, size_t count); /* device-side output pre-fill */ + int (*build)(void *ctx, const OmegaGpuJob *job); /* descriptors, QMD, pushbuffer */ + int (*submit)(void *ctx); + int (*wait_marker)(void *ctx, uint64_t timeout_ms); + int (*wait_marker2)(void *ctx, uint64_t timeout_ms); + int (*wait_release_semaphore)(void *ctx, uint64_t timeout_ms); + int (*barrier)(void *ctx, uint64_t timeout_ms); /* visibility before readback */ + int (*copy_out)(void *ctx, void *dst, size_t bytes); + void (*diagnostics)(void *ctx, OmegaGpuBackendDiag *diag); /* driver rc, text, observed words */ + int (*free_buf)(void *ctx, int role); int (*close)(void *ctx); -} OmegaGpuEngineBackend; +} OmegaGpuBackend; + +/* Runs one job on the process-wide default backend. See the header comment. */ +int omega_gpu_execute(const OmegaGpuJob *job, OmegaGpuResult *result); + +/* Sets the process-wide default backend (NULL clears it). The pointer must stay + * valid while it is set. With none set, omega_gpu_execute returns the defined + * stub result: INTERNAL_INVARIANT at step NOT_IMPLEMENTED. Real code sets it; + * host tests set a fake. */ +void omega_gpu_engine_set_backend(const OmegaGpuBackend *backend); + +/* 1 once an uncertain completion has blocked this process, else 0. */ +int omega_gpu_engine_is_blocked(void); + +/* TEST ONLY. Clears the block. Production code must never call this: a blocked + * process stays blocked because the GPU may still be running. */ +void omega_gpu_engine_test_reset_block(void); -/* Runs one kernel. Returns OMEGA_GPU_ENGINE_OK (0) or the failure code; fills *out. */ -int omega_gpu_engine_run(const OmegaGpuEngineBackend *b, void *backend_ctx, - const OmegaGpuEngineRequest *rq, OmegaGpuEngineResult *out); +/* TEST ONLY. Forces the blocked state so tests can exercise the blocked + * result without a real uncertain completion. */ +void omega_gpu_engine_test_force_block(void); /* Static name strings, never NULL. Out-of-range values give "UNKNOWN". */ const char *omega_gpu_engine_failure_name(int failure); const char *omega_gpu_engine_state_name(int state); const char *omega_gpu_engine_wait_name(int wait); +const char *omega_gpu_engine_step_name(int step); #endif diff --git a/tests/test_omega_gpu_engine_compile.c b/tests/test_omega_gpu_engine_compile.c index f9ed29cd6..b7ac55725 100644 --- a/tests/test_omega_gpu_engine_compile.c +++ b/tests/test_omega_gpu_engine_compile.c @@ -1,4 +1,5 @@ -/* Omega GPU Engine A2: the stub returns its defined results and every enum name is distinct. */ +/* Omega GPU Engine A2b: the stub returns its defined results, every enum name + * is distinct, and the uncertain-completion block functions behave as specified. */ #include "omega_gpu_engine.h" #include #include @@ -7,13 +8,14 @@ static int bad; #define CHECK(c) do { if (!(c)) { printf("[FAIL] line %d: %s\n", __LINE__, #c); bad++; } } while (0) static int f_ctx(void *c) { (void)c; return 0; } -static int f_alloc(void *c, int r, unsigned i, size_t n) { (void)c; (void)r; (void)i; (void)n; return 0; } -static int f_in(void *c, int r, unsigned i, const void *s, size_t n) { (void)c; (void)r; (void)i; (void)s; (void)n; return 0; } -static int f_poison(void *c, unsigned i, uint32_t w, size_t n) { (void)c; (void)i; (void)w; (void)n; return 0; } -static int f_submit(void *c, const OmegaGpuEngineRequest *rq) { (void)c; (void)rq; return 0; } +static int f_alloc(void *c, int r, size_t n) { (void)c; (void)r; (void)n; return 0; } +static int f_in(void *c, int r, const void *s, size_t n) { (void)c; (void)r; (void)s; (void)n; return 0; } +static int f_poison(void *c, const uint32_t *w, size_t n) { (void)c; (void)w; (void)n; return 0; } +static int f_build(void *c, const OmegaGpuJob *j) { (void)c; (void)j; return 0; } static int f_wait(void *c, uint64_t ms) { (void)c; (void)ms; return 0; } -static int f_out(void *c, unsigned i, void *d, size_t n) { (void)c; (void)i; (void)d; (void)n; return 0; } -static int f_free(void *c, int r, unsigned i) { (void)c; (void)r; (void)i; return 0; } +static int f_out(void *c, void *d, size_t n) { (void)c; (void)d; (void)n; return 0; } +static void f_diag(void *c, OmegaGpuBackendDiag *d) { (void)c; (void)d; } +static int f_free(void *c, int r) { (void)c; (void)r; return 0; } static int all_distinct(const char *(*name)(int), int count) { @@ -24,36 +26,131 @@ static int all_distinct(const char *(*name)(int), int count) return strcmp(name(-1), "UNKNOWN") == 0 && strcmp(name(count), "UNKNOWN") == 0; } +/* Expects the stub's full defined result for a job refused at `step` with `failure`. */ +static void expect_result(const OmegaGpuResult *r, int failure, int step) +{ + CHECK(r->failure == failure); + CHECK(r->failed_step == step); + CHECK(r->last_state == OMEGA_GPU_ENGINE_STATE_INITIAL); + CHECK(r->wait == OMEGA_GPU_ENGINE_WAIT_NONE); + CHECK(r->wait_timeout_ms == 0 && r->waited_ms == 0); + CHECK(r->drv_rc == 0 && r->err_no == 0 && r->drv_text[0] == '\0'); + CHECK(r->sync_valid == 0 && r->marker == 0 && r->marker2 == 0 && r->semaphore[0] == 0); + CHECK(r->retained == 0 && r->cleanup_failed == 0); + CHECK(r->n_outputs == 0 && r->output_unchanged_words[0] == 0); +} + int main(void) { CHECK(all_distinct(omega_gpu_engine_failure_name, OMEGA_GPU_ENGINE_FAILURE_COUNT)); CHECK(all_distinct(omega_gpu_engine_state_name, OMEGA_GPU_ENGINE_STATE_COUNT)); CHECK(all_distinct(omega_gpu_engine_wait_name, OMEGA_GPU_ENGINE_WAIT_COUNT)); + CHECK(all_distinct(omega_gpu_engine_step_name, OMEGA_GPU_ENGINE_STEP_COUNT)); CHECK(OMEGA_GPU_ENGINE_OK == 0 && strcmp(omega_gpu_engine_failure_name(0), "OK") == 0); - CHECK(strcmp(omega_gpu_engine_failure_name(OMEGA_GPU_ENGINE_GPU_COMPLETION_TIMEOUT), "GPU_COMPLETION_TIMEOUT") == 0); - - OmegaGpuEngineBackend be = { f_ctx, f_alloc, f_in, f_poison, f_submit, f_wait, f_wait, f_wait, f_ctx, f_out, f_free, f_ctx }; - unsigned char code[4] = {0}; uint32_t outw[4] = {0}; - OmegaGpuEngineOutBuf ob = { outw, sizeof outw, 0 }; - OmegaGpuEngineRequest rq; memset(&rq, 0, sizeof rq); - rq.kernel_image = code; rq.kernel_len = sizeof code; rq.outputs = &ob; rq.n_outputs = 1; - - OmegaGpuEngineResult r; memset(&r, 0x7f, sizeof r); - CHECK(omega_gpu_engine_run(&be, NULL, &rq, &r) == OMEGA_GPU_ENGINE_DEVICE_ERROR); - CHECK(r.failure == OMEGA_GPU_ENGINE_DEVICE_ERROR && r.state == OMEGA_GPU_ENGINE_STATE_NONE); - CHECK(r.step != NULL && strcmp(r.step, "not_implemented") == 0); - CHECK(r.wait == OMEGA_GPU_ENGINE_WAIT_NONE && r.waited_ms == 0 && r.drv_rc == 0 && r.n_outputs == 0); - - memset(&r, 0x7f, sizeof r); - rq.kernel_image = NULL; /* counterexample: a bad request must not look like not_implemented */ - CHECK(omega_gpu_engine_run(&be, NULL, &rq, &r) == OMEGA_GPU_ENGINE_DEVICE_ERROR); - CHECK(r.step != NULL && strcmp(r.step, "bad_request") == 0); - rq.kernel_image = code; - memset(&r, 0x7f, sizeof r); - be.close = NULL; /* an incomplete backend table is refused too */ - CHECK(omega_gpu_engine_run(&be, NULL, &rq, &r) == OMEGA_GPU_ENGINE_DEVICE_ERROR); - CHECK(r.step != NULL && strcmp(r.step, "bad_request") == 0); - CHECK(omega_gpu_engine_run(&be, NULL, &rq, NULL) == OMEGA_GPU_ENGINE_DEVICE_ERROR); + CHECK(strcmp(omega_gpu_engine_failure_name(OMEGA_GPU_ENGINE_COMPLETION_WAIT), "COMPLETION_WAIT") == 0); + CHECK(strcmp(omega_gpu_engine_failure_name(OMEGA_GPU_ENGINE_UNCERTAIN_COMPLETION_BLOCKED), + "UNCERTAIN_COMPLETION_BLOCKED") == 0); + CHECK(strcmp(omega_gpu_engine_state_name(OMEGA_GPU_ENGINE_STATE_INITIAL), "INITIAL") == 0); + CHECK(strcmp(omega_gpu_engine_state_name(OMEGA_GPU_ENGINE_STATE_SUCCESS), "SUCCESS") == 0); + CHECK(OMEGA_GPU_ENGINE_STATE_INITIAL == 0 && OMEGA_GPU_ENGINE_STATE_COUNT == 7); + CHECK(strcmp(omega_gpu_engine_wait_name(OMEGA_GPU_ENGINE_WAIT_RELEASE_SEMAPHORE), "RELEASE_SEMAPHORE") == 0); + CHECK(strcmp(omega_gpu_engine_step_name(OMEGA_GPU_ENGINE_STEP_NOT_IMPLEMENTED), "NOT_IMPLEMENTED") == 0); + + unsigned char code[4] = {0}; + uint32_t ina[4] = {0}, inb[4] = {0}, outw[4] = {0}, poison[4] = {1, 2, 3, 4}; + OmegaGpuJob job; + memset(&job, 0, sizeof job); + job.program = code; job.program_len = sizeof code; + job.layout = OMEGA_GPU_LAYOUT_VECTOR_1D; job.element_count = 4; + job.input_a = ina; job.input_a_len = sizeof ina; + job.input_b = inb; job.input_b_len = sizeof inb; + job.output = outw; job.output_len = sizeof outw; + job.poison = poison; job.poison_count = 4; + job.timeouts.marker_ms = 1; job.timeouts.release_semaphore_ms = 1; + job.timeouts.marker2_ms = 1; job.timeouts.visibility_ms = 1; + + OmegaGpuResult r; + + /* Not blocked at start; no backend set: the defined stub result. */ + omega_gpu_engine_test_reset_block(); + CHECK(omega_gpu_engine_is_blocked() == 0); + memset(&r, 0x7f, sizeof r); + CHECK(omega_gpu_execute(&job, &r) == OMEGA_GPU_ENGINE_INTERNAL_INVARIANT); + expect_result(&r, OMEGA_GPU_ENGINE_INTERNAL_INVARIANT, OMEGA_GPU_ENGINE_STEP_NOT_IMPLEMENTED); + + /* A missing result pointer is refused and nothing is written. */ + CHECK(omega_gpu_execute(&job, NULL) == OMEGA_GPU_ENGINE_INVALID_ARGS); + + /* Counterexamples: each malformed job is INVALID_ARGS at VALIDATE, never NOT_IMPLEMENTED. */ + memset(&r, 0x7f, sizeof r); + CHECK(omega_gpu_execute(NULL, &r) == OMEGA_GPU_ENGINE_INVALID_ARGS); + expect_result(&r, OMEGA_GPU_ENGINE_INVALID_ARGS, OMEGA_GPU_ENGINE_STEP_VALIDATE); + + OmegaGpuJob bad_job; +#define EXPECT_INVALID(edit) do { bad_job = job; edit; memset(&r, 0x7f, sizeof r); \ + CHECK(omega_gpu_execute(&bad_job, &r) == OMEGA_GPU_ENGINE_INVALID_ARGS); \ + expect_result(&r, OMEGA_GPU_ENGINE_INVALID_ARGS, OMEGA_GPU_ENGINE_STEP_VALIDATE); } while (0) + EXPECT_INVALID(bad_job.program = NULL); + EXPECT_INVALID(bad_job.program_len = 0); + EXPECT_INVALID(bad_job.layout = OMEGA_GPU_LAYOUT_COUNT); + EXPECT_INVALID(bad_job.element_count = 0); + EXPECT_INVALID(bad_job.input_a = NULL); + EXPECT_INVALID(bad_job.input_a_len = sizeof ina - 4); + EXPECT_INVALID(bad_job.input_b = NULL); + EXPECT_INVALID(bad_job.input_b_len = sizeof inb + 4); + EXPECT_INVALID(bad_job.output = NULL); + EXPECT_INVALID(bad_job.output_len = sizeof outw - 4); + EXPECT_INVALID(bad_job.output = (unsigned char *)outw + 1); /* not 4-byte aligned */ + EXPECT_INVALID(bad_job.poison = NULL); + EXPECT_INVALID(bad_job.poison_count = 3); + EXPECT_INVALID(bad_job.flags = 0x2u); /* unknown flag */ + EXPECT_INVALID(bad_job.timeouts.marker_ms = 0); + EXPECT_INVALID(bad_job.timeouts.release_semaphore_ms = 0); + EXPECT_INVALID(bad_job.timeouts.visibility_ms = 0); + EXPECT_INVALID(bad_job.timeouts.marker2_ms = 0); /* C3 on, so marker2 needs a timeout */ + + /* With NO_C3 a zero marker2 timeout is allowed. */ + bad_job = job; bad_job.flags = OMEGA_GPU_ENGINE_FLAG_NO_C3; bad_job.timeouts.marker2_ms = 0; + memset(&r, 0x7f, sizeof r); + CHECK(omega_gpu_execute(&bad_job, &r) == OMEGA_GPU_ENGINE_INTERNAL_INVARIANT); + expect_result(&r, OMEGA_GPU_ENGINE_INTERNAL_INVARIANT, OMEGA_GPU_ENGINE_STEP_NOT_IMPLEMENTED); + + /* Backend table: incomplete is refused, complete reaches the stub result, NULL clears. */ + OmegaGpuBackend be = { + .ctx = NULL, .open_device = f_ctx, .create_channel = f_ctx, .alloc = f_alloc, + .copy_in = f_in, .fill_poison = f_poison, .build = f_build, .submit = f_ctx, + .wait_marker = f_wait, .wait_marker2 = f_wait, .wait_release_semaphore = f_wait, + .barrier = f_wait, .copy_out = f_out, .diagnostics = f_diag, .free_buf = f_free, + .close = f_ctx, + }; + omega_gpu_engine_set_backend(&be); + memset(&r, 0x7f, sizeof r); + CHECK(omega_gpu_execute(&job, &r) == OMEGA_GPU_ENGINE_INTERNAL_INVARIANT); + expect_result(&r, OMEGA_GPU_ENGINE_INTERNAL_INVARIANT, OMEGA_GPU_ENGINE_STEP_NOT_IMPLEMENTED); + be.close = NULL; + memset(&r, 0x7f, sizeof r); + CHECK(omega_gpu_execute(&job, &r) == OMEGA_GPU_ENGINE_INTERNAL_INVARIANT); + expect_result(&r, OMEGA_GPU_ENGINE_INTERNAL_INVARIANT, OMEGA_GPU_ENGINE_STEP_BACKEND_CHECK); + omega_gpu_engine_set_backend(NULL); + memset(&r, 0x7f, sizeof r); + CHECK(omega_gpu_execute(&job, &r) == OMEGA_GPU_ENGINE_INTERNAL_INVARIANT); + expect_result(&r, OMEGA_GPU_ENGINE_INTERNAL_INVARIANT, OMEGA_GPU_ENGINE_STEP_NOT_IMPLEMENTED); + + /* Block: forced block refuses every job, even a malformed one, until reset. */ + omega_gpu_engine_test_force_block(); + CHECK(omega_gpu_engine_is_blocked() == 1); + memset(&r, 0x7f, sizeof r); + CHECK(omega_gpu_execute(&job, &r) == OMEGA_GPU_ENGINE_UNCERTAIN_COMPLETION_BLOCKED); + expect_result(&r, OMEGA_GPU_ENGINE_UNCERTAIN_COMPLETION_BLOCKED, OMEGA_GPU_ENGINE_STEP_BLOCKED); + memset(&r, 0x7f, sizeof r); + CHECK(omega_gpu_execute(NULL, &r) == OMEGA_GPU_ENGINE_UNCERTAIN_COMPLETION_BLOCKED); + expect_result(&r, OMEGA_GPU_ENGINE_UNCERTAIN_COMPLETION_BLOCKED, OMEGA_GPU_ENGINE_STEP_BLOCKED); + CHECK(omega_gpu_engine_is_blocked() == 1); /* a refusal does not clear the block */ + omega_gpu_engine_test_reset_block(); + CHECK(omega_gpu_engine_is_blocked() == 0); + memset(&r, 0x7f, sizeof r); + CHECK(omega_gpu_execute(&job, &r) == OMEGA_GPU_ENGINE_INTERNAL_INVARIANT); + expect_result(&r, OMEGA_GPU_ENGINE_INTERNAL_INVARIANT, OMEGA_GPU_ENGINE_STEP_NOT_IMPLEMENTED); printf("SUMMARY failed=%d\n", bad); return bad ? 1 : 0;