omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
GitHub aien-dev/omega-mv#220 (code only)
Apply it
git checkout -b patch-2528a41c589a5cf2 87e8793c9b4e790412b37be83600b8c6ba5db8d3 curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/2528a41c589a5cf2.patch | git am
Provenance
github-import 1
aien-dev/omega-mv
220
ce42e62f9632b495f494aa8e419a70f4a36c88c0
{"kind":"github-import","owner":"aien-dev","repo":"omega-mv","number":220,"url":"https://github.com/aien-dev/omega-mv/pull/220","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:50Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/Makefile b/Makefile index 5fb0b5d24..92fc86d74 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ SRCS = src/sha256.c src/omega_canonical.c src/omega_validate.c src/omega_core.c src/omega_library.c src/omega_discovery.c src/omega_machine.c src/omega_realize_synth.c \ src/omega_matvec.c src/omega_accelerator.c src/omega_accelerator_world.c \ src/omega_vector.c src/omega_blackwell_encoder.c src/omega_blackwell_qmd.c \ - src/omega_blackwell_realize.c src/omega_blackwell_submit.c src/omega_blackwell_gates.c src/omega_blackwell_matmul.c src/omega_blackwell_codegen.c src/omega_world_gates.c \ + src/omega_blackwell_realize.c src/omega_blackwell_submit.c src/omega_blackwell_engine.c src/omega_gpu_engine.c src/omega_blackwell_gates.c src/omega_blackwell_matmul.c src/omega_blackwell_codegen.c src/omega_world_gates.c \ src/omega_evidence.c \ $(PHYSICS_DIR)/m16/m16_native.c $(PHYSICS_DIR)/nvrm/nvrm.c \ tools/omegatool.c @@ -1612,7 +1612,7 @@ print-c4-requal-bin: # tests/runtime/rx_compose_gpu_skill.h. A chip run: take the quiet flag and # use tools/composition_gate.sh --gpu (clean tree, content-addressed receipt). RX_COMPOSE_GATE_GPU = $(OUT_DIR)/rx_composition_gate_gpu -RX_COMPOSE_GPU_SRCS = src/omega_blackwell_submit.c src/omega_blackwell_matmul.c \ +RX_COMPOSE_GPU_SRCS = src/omega_blackwell_submit.c src/omega_blackwell_engine.c src/omega_gpu_engine.c src/omega_blackwell_matmul.c \ src/omega_blackwell_codegen.c src/omega_blackwell_encoder.c src/omega_blackwell_qmd.c \ src/omega_blackwell_realize.c src/omega_vector.c src/omega_validate.c \ $(PHYSICS_DIR)/m16/m16_native.c $(PHYSICS_DIR)/nvrm/nvrm.c diff --git a/docs/numeric/OMEGA_GPU_ENGINE.md b/docs/numeric/OMEGA_GPU_ENGINE.md index 70e8fe34b..2f61bd4b4 100644 --- a/docs/numeric/OMEGA_GPU_ENGINE.md +++ b/docs/numeric/OMEGA_GPU_ENGINE.md @@ -1,8 +1,15 @@ # 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. +Status: DRAFT, chip-unproven. The engine core (section 13) and, since cut A3b1, +the Blackwell backend (section 14) exist, and the vector executor +`omega_blackwell_execute_vector` now routes through `omega_gpu_execute`. No +other launcher is converted. Every test and chip label for this work is +NOT_RUN (host NOT_RUN, chip NOT_RUN). No receipt exists today. Editing +`src/omega_blackwell_submit.c` changes the sha256 that the M17 and M18 gates +compute at run time (`tests/run_m17_gates.sh:66-67,129-130`, +`src/omega_blackwell_gates.c:1166-1167`), so receipts for the vector gates can +only be verified on the chip in Phase B, and any PR carrying this change stays +DRAFT until then. 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 @@ -356,8 +363,8 @@ header at all. 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. +`src/omega_gpu_engine.c` (still a stub; superseded by section 13) and +`tests/test_omega_gpu_engine_compile.c`. `mk/omega-gpu-engine.mk` is unchanged (superseded by section 13). 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). @@ -453,12 +460,16 @@ Carried from A1 and A1b, plus new ones from this cut: 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. +11. The clock used for `waited_ms` is left to A3 (superseded by section 13: an injectable test clock was added). 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. +14. (A3b1) Whether `src/omega_gpu_engine.h` and `.c` join the sha256 pinned lists next to + `src/omega_blackwell_engine.*` (the vector executor now depends on them). They are not + added in A3b1. Also whether free-then-close is safe on the chip for the vector launch + (section 14, UNVERIFIED, 70%). ## 12. Changes from the first draft (omega#218 commit 6e077f1) @@ -473,3 +484,386 @@ Carried from A1 and A1b, plus new ones from this cut: | 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` | + +## 13. Host tests and mutants (A3a engine core) + +Status: host NOT_RUN, chip NOT_RUN. Nothing in this section has been compiled +or executed by its author. The queue lines `DEEP2-A3a-host`, `DEEP2-A3a-mut` +and `DEEP2-A3a-compile` carry the first runs. + +What A3a adds: the real `omega_gpu_execute` in `src/omega_gpu_engine.c` +(replacing the stub when a backend is set), a fake-backend host test, and a +mutation sweep. Build targets in `mk/omega-gpu-engine.mk`: `test-gpu-engine`, +`test-gpu-engine-mutants`, `test-gpu-engine-compile`. No physics header, no +device. The Blackwell backend and `omega_blackwell_submit.c` are untouched +(A3b). + +Core details the doc did not fix before (choices of this cut): +- Order of backend calls: open, channel, alloc of SCRATCH, PROGRAM, INPUT_A, + INPUT_B, OUTPUT (in that order; SCRATCH gets `bytes == 0`, the backend sizes + it, UNVERIFIED: the A3b backend may need a different rule), copy-in of + PROGRAM, INPUT_A, INPUT_B, poison fill, build, submit, marker wait, marker2 + wait (skipped with NO_C3), release semaphore wait, barrier, copy-out, then + free in reverse allocation order and close. +- Diagnostics (driver code, text, observed marker, marker2 and semaphore words) + are captured with one `diagnostics` call at the FIRST failure of a run, + including OUTPUT_UNCHANGED, and are not captured on success. `errno` is read + immediately after the failing callback. A later cleanup fault never + overwrites them. +- `waited_ms` is measured by the engine around each wait callback using + CLOCK_MONOTONIC. A small additive test hook, + `omega_gpu_engine_test_set_clock`, lets the host test supply a fake clock so + `waited_ms` is asserted exactly. +- The header has one output only (`OMEGA_GPU_ENGINE_JOB_OUTPUTS` is 1, no + buffer counts), so the "two outputs" and "buffer count out of range" cases + of the A3a brief do not exist yet. The unchanged-word count is per output + and the test checks output 0. +- With no backend set, the defined stub result (INTERNAL_INVARIANT at step + NOT_IMPLEMENTED) is kept, as section 6 says. A NULL job or result is + INVALID_ARGS. +- SUBMIT failure is a known failure (section 11, item 12): cleanup runs, no + block. A barrier or copy-out failure also runs cleanup (completion is known). + +Test cases in `tests/test_omega_gpu_engine.c` (id: what it guards): +- SUCCESS_FULL_RUN: a good run is SUCCESS with every result field defined, + output bytes copied back, balanced open/close. +- CALL_ORDER_FULL_RUN: the exact backend call order of the whole run. +- STATE_ADVANCES_STEP_BY_STEP: `last_state` at each backend call (INITIAL until + build, PREPARED at submit, SUBMITTED during the waits, GPU_COMPLETE at barrier + and copy-out, OUTPUT_PRODUCED during cleanup). +- ROLES_BYTES_AND_REVERSE_FREE_ORDER: alloc and copy-in roles and byte counts, + free in reverse order. +- PER_STEP_TIMEOUTS_FROM_JOB: each wait gets its own timeout from the job. +- POISON_WRITTEN_BEFORE_SUBMIT: the fake device output holds the wrapper poison + words at submit. +- NO_C3_SKIPS_MARKER2_ONLY: the NO_C3 flag drops only the marker2 wait. +- FAIL_DEVICE_OPEN, FAIL_CHANNEL_CREATE, FAIL_ALLOC (third buffer, partial + cleanup), FAIL_PREPARE_COPY_IN, FAIL_PREPARE_FILL_POISON, FAIL_PREPARE_BUILD: + failure name, failing step, last state INITIAL, driver code, errno and text + passthrough, cleanup, host output untouched. +- FAIL_SUBMIT_IS_NOT_UNCERTAIN: SUBMIT cleans up and does not block. +- FAIL_VISIBILITY_BARRIER, FAIL_VISIBILITY_COPY_OUT: VISIBILITY_WAIT at the + right step, cleanup, no block. +- UNCERTAIN_MARKER_TIMEOUT, UNCERTAIN_MARKER2_UNKNOWN_STATE, + UNCERTAIN_RELEASE_DRIVER_FAULT: COMPLETION_WAIT or RELEASE_WAIT, which wait, + configured limit, exact `waited_ms`, observed sync words, retained = 1, + nothing freed or closed, process blocked. +- UNCERTAIN_BLOCKS_NEXT_JOB_NO_BACKEND_CALL, UNCERTAIN_TEST_RESET_CLEARS_BLOCK. +- UNCHANGED_NOTHING_WRITTEN, UNCHANGED_PARTIAL_EXACT_COUNT, + UNCHANGED_LAST_WORD_ONLY, UNCHANGED_FIRST_WORD_ONLY, + UNCHANGED_ALL_WRITTEN_IS_SUCCESS, UNCHANGED_NEEDS_POISON_FILL: + OUTPUT_UNCHANGED with the exact count, SUCCESS when every word changed. +- CLEANUP_FREE_FAILS_AFTER_GOOD_RUN, CLEANUP_CLOSE_FAILS_AFTER_GOOD_RUN: + CLEANUP failure, last state stays OUTPUT_PRODUCED, remaining frees and close + still run. CLEANUP_FIRST_CLEANUP_FAULT_KEPT, + CLEANUP_FAULT_NEVER_OVERWRITES_FIRST_FAILURE, + CLEANUP_FAULT_AFTER_UNCHANGED_KEEPS_UNCHANGED: first failure is kept, + `cleanup_failed` set. +- INVALID_ARGS_PROGRAM, _LAYOUT, _ZERO_ELEMENTS, _BUFFERS, _OUTPUT_ALIGNMENT, + _POISON, _UNKNOWN_FLAG, _ZERO_MARKER_TIMEOUT, _ZERO_RELEASE_TIMEOUT, + _ZERO_VISIBILITY_TIMEOUT, _ZERO_MARKER2_TIMEOUT_WITH_C3, _NULL_JOB, + _NULL_RESULT: INVALID_ARGS at VALIDATE with no backend call. +- BLOCKED_REFUSES_BEFORE_ANY_CHECK_OR_CALL, BLOCK_RESET_ALLOWS_JOBS_AGAIN, + NO_BACKEND_NOT_IMPLEMENTED, BACKEND_TABLE_INCOMPLETE_REFUSED (each of the 15 + callbacks missing in turn): the refusals that come before any backend call. + +Mutants in `tools/gpu_engine_mutations.sh` (each is a `MUT:<name>` marker in +`src/omega_gpu_engine.c`; each must be KILLED by the host test; none is +currently marked redundant): +- VALIDATE_SKIPPED, VALID_PROGRAM, VALID_LAYOUT, VALID_COUNT_ZERO, VALID_ALIGN, + VALID_POISON_COUNT, VALID_FLAGS, VALID_TIMEOUT_MARKER1, + VALID_TIMEOUT_MARKER2: argument validation, whole and one check at a time. +- BLOCK_CHECK_SKIPPED: the blocked refusal. BACKEND_CHECK_SKIPPED: the table + completeness check. +- OPEN_NOT_TRACKED, ALLOC_NOT_TRACKED: cleanup bookkeeping (close, free). +- CLEANUP_SKIPPED_CHANNEL, _ALLOC, _COPY_IN, _SUBMIT: cleanup on one early + failure path each. FREE_UNALLOCATED, FREE_SKIPPED, CLOSE_SKIPPED: what + cleanup frees and closes. +- CLEANUP_OVERWRITES_FIRST, CLEANUP_FLAG_NOT_SET, SUCCESS_AFTER_CLEANUP_FAIL: + cleanup fault precedence and the SUCCESS rule. +- POISON_FILL_SKIPPED, POISON_INDEX_FIXED, UNCHANGED_COUNT_SATURATES, + UNCHANGED_CHECK_SKIPPED: the poison write and the unchanged-word check. +- STATE_PREPARED_SKIPPED, STATE_SUBMITTED_SKIPPED, STATE_GPU_COMPLETE_SKIPPED, + STATE_OUTPUT_VISIBLE_SKIPPED, STATE_OUTPUT_PRODUCED_SKIPPED, + STATE_SUCCESS_SKIPPED: each transition's `last_state` update. +- MARKER1_WAIT_SKIPPED, MARKER1_TIMEOUT_WRONG, MARKER1_RESULT_IGNORED, + MARKER2_WAIT_SKIPPED, C3_FLAG_IGNORED, MARKER2_RESULT_IGNORED, + RELEASE_WAIT_SKIPPED, RELEASE_RESULT_IGNORED, BARRIER_SKIPPED, + BARRIER_RESULT_IGNORED: the completion rule, per wait: skipping the call, + ignoring its result, the NO_C3 flag, the timeout wiring. +- UNCERTAIN_FREES_MARKER1, UNCERTAIN_FREES_MARKER2, UNCERTAIN_FREES_RELEASE + (free and close on uncertain completion), RETAINED_FLAG_NOT_SET, NO_BLOCK + (do not block afterwards): the uncertain-completion rule. +- WAITED_NOT_A_DIFFERENCE: `waited_ms` is end minus start. + +Not covered by any host test (needs the chip, see section 10): whether the +sequence is sufficient on real hardware, cache visibility under faults, +recovery after an uncertain completion, persistent kernels. + +## 14. Blackwell backend and the vector executor (A3b1) + +Status: DRAFT, host NOT_RUN, chip NOT_RUN. Nothing in this section has been +compiled or executed by its author. The queue lines `DEEP2-A3b1-backend`, +`DEEP2-A3b1-prod`, `DEEP2-A3b1-host` and `DEEP2-A3b1-mut` carry the first runs. +The simulated-driver host test, the backend mutants, the chip test and the chip +manifest are section 14.1 (cut A3b2). + +What this cut adds: +- `src/omega_blackwell_engine.c` and `.h`: the backend table + (`omega_blackwell_engine_backend()`, type `OmegaGpuBackend`) that the core + drives. It defines no job, result or execute type. The device sequence is the + one in `omega_blackwell_execute_vector` as it stood at commit 676f16f, split + into the fifteen callbacks. +- `omega_blackwell_execute_vector` in `src/omega_blackwell_submit.c` keeps its + public signature and result fields. Inside, it encodes the program, builds the + poison words, calls `omega_gpu_execute`, then runs the vector oracle + (`omega_vector_verify_oracle`) on the host as before. +- Makefile: `src/omega_blackwell_engine.c` and `src/omega_gpu_engine.c` join the + two source lists that already hold `src/omega_blackwell_submit.c` (`SRCS` and + `RX_COMPOSE_GPU_SRCS`), nothing else. +- `mk/omega-gpu-engine.mk`: `test-gpu-engine-backend-compile` (syntax check of + the backend, `-c` only, no link, no device) and `test-gpu-engine-prod-build` + (`make build/omegatool` at the physics pin: links only, opens no device). +- Digest lists: `src/omega_blackwell_engine.h` and `.c` are added to the pinned + list in `src/omega_blackwell_gates.c` (manifest at 1166-1169) and in + `tests/run_m17_gates.sh`. `src/omega_gpu_engine.h` and `.c` are NOT added (the + vector executor depends on them now; whether to pin them is open, section 11). + +Choices of this cut: +- Poison. The wrapper supplies it. Each poison word is the bit complement of the + expected output word (`~(a[i] + b[i])`), computed on the host before launch. + A word and its complement always differ, so a poison word never equals the + expected word at its position. This replaces the constant + `OMEGA_VECTOR_POISON_VALUE` for this executor. +- L2 flush. The core has no callback for it, so `build` emits the L2 flush and + the second release marker (0x46464646 at marker page + 0x10) inside the + pushbuffer unless the job sets NO_C3, as divsqrt does today + (`src/omega_numeric_divsqrt_gb10.c:1145-1152`). The vector wrapper passes flags + 0, so the vector launch now has C3, a second marker wait and a semaphore wait + that it did not have at 676f16f (A1 finding 1 and 3). The timeouts are 5000 ms + each, the value the old marker wait used. +- Completion rule per wait: the native wait is a ">=" serial compare + (`physics/m16/m16_native.c:93-108`), so each wait callback also re-checks that + the word is exactly the expected value and reports a mismatch as + `UNKNOWN_STATE` (an uncertain completion). The check is from GPT-6 Astra's + first cut. +- Values on success. The core copies driver diagnostics only on a failure, and + frees and closes the device (unmapping the marker and semaphore memory) before + it returns. So the backend snapshots the marker, second marker and semaphore + words inside its wait callbacks, plus the submit and marker-done timestamps, + and `omega_blackwell_engine_run_info` returns them. The wrapper fills + `completion_marker`, `intermediate_semaphore`, `launch_timestamp_ns`, + `completion_timestamp_ns` and `elapsed_ns` from that. The engine result itself + cannot supply these on success. +- Cleanup. The backend frees every buffer with `nvrm_free` before `close`, + which the old launcher never did (it relied on `nvrm_close`, `nvrm.c:757-766`). + `nvrm_free` before close is used by `src/omega_accelerator_world.c` + (A1b section 4). Chip behaviour of this order for the vector launch is + UNVERIFIED (confidence 70%). +- Allocation order differs from 676f16f: the four SCRATCH buffers come first, + then program, input A, input B, output. Sizes are unchanged. Chip effect + UNVERIFIED (confidence 90% harmless, no address is hard coded). +- One run at a time: the backend keeps one static context and refuses a second + open while a run is active. + +### 14.1 Simulated-driver host test, backend mutants, chip test (A3b2) + +Status: host PASS at DEEP2-A3b3 (333 sim assertions, 120 mutants: 107 killed, 13 +redundant as listed, 0 test gaps), chip NOT_RUN. The A3b2 run found no bug in the +engine or backend sources: the first run failed because the test re-used the hang +or overshoot armed in the simulated driver for its "backend works again after +drain" check (test bug, fixed in the test), and one mutant row did not build +(unused variable under -Werror, fixed in the row). An address and undefined-behaviour +sanitizer run of the sim test is clean except one old finding in src/omega_blackwell_qmd.c +line 139 (`0x1000 << 19` overflows a signed int; gcc wraps it to the intended value). The +file is gate-hashed (M17/M18) and was left unchanged. + +Files: +- `tests/test_omega_blackwell_engine.c` and `tests/fake_m16_native.c/.h` + (`make test-gpu-engine-sim`). The REAL engine core, the REAL Blackwell backend + and the REAL `omega_blackwell_execute_vector` run on the host. Only seven + driver symbols are replaced by the fake: `m16_native_open`, + `m16_native_create_channel`, `m16_native_submit_methods`, `m16_native_wait_marker`, + `m16_native_close`, `nvrm_alloc`, `nvrm_free`. No physics C file is linked. + Output is `[PASS] id` or `[FAIL] id` per check and a last line + `SUMMARY passed=N failed=M`. +- `tools/gpu_engine_backend_mutations.sh` (`make test-gpu-engine-backend-mutants`), + a table adapter over `tools/mutation_runner.sh`. One mutant per protection in + `src/omega_blackwell_engine.c` and in the vector wrapper. The real sources carry + no marker comments; the rows match their text exactly once or by line range. +- `tests/test_omega_gpu_engine_gb10.c` (compile only here, + `make test-gpu-engine-gb10-compile`) and `tools/manifests/gpu_engine.chiprun` + (omega#205 chip_run format). Phase B only: needs the GB10, the queen's go and + the quiet flag via chip_run. Never run in Phase A. The chip test is a fresh + rewrite against the real API; GPT-6 Astra's first-cut test (commit 21392ee, + older API) was the outline. + +Test case groups (each id starts with `sim_`; the full list is the `check` calls in the test): +`success` (24-entry call order, allocation sizes, pushbuffer packet order, wait +order, zeroed sync words at the doorbell, kernel arguments and addresses), +`noc3`, `twice` (back to back runs), `open`, `channel`, `alloc` (fault on each of +the 8 allocations, and a buffer that fails its own checks), `submit`, `unc_*` +(8 uncertain-completion scenarios: marker, second marker and semaphore each +hanging and overshooting, plus no-C3), `cleanup` (free and close faults), +`unchanged` (unwritten output, wrong program bytes), `guard` (direct table calls +with bad roles, lengths, NULLs, page rounding), `close` (close unmaps the sync +words), `vec` (the wrapper: result, oracle, poison complement, timeouts, flags, +timestamps). + +Failure names that no driver fault can reach through the real backend, covered +only by the fake-backend core test (`tests/test_omega_gpu_engine.c`): `PREPARE` +(copy-in and build refuse only on arguments the core already validated), +`VISIBILITY_WAIT` (the barrier always returns 0), `INTERNAL_INVARIANT` (the +backend table is complete). + +Modelling assumptions of the fake. Every one is a MODEL, UNVERIFIED on the chip, +confidence about 70 percent that it matches the real driver and device: +device memory is host memory with GPU address equal to CPU address and a dirty +0x5a fill; the second marker release lands only if an L2 flush came between the +two releases; a successful real `nvrm_free` clobbers `errno` (to EBADF); the +channel's own 4 KiB pushbuffer buffer is orphaned when the backend installs the +large ring; the pushbuffer is parsed and executed in order. The link set (the +Makefile `RX_COMPOSE_GPU_SRCS` list plus `omega_core.c`, `omega_canonical.c`, +`sha256.c`) links and runs on the host (checked at A3b3); whether it also matches the chip build is not tested here. + +Backend and wrapper mutants. Each must be KILLED by the sim test, or carries class +`redundant` with a reason (a surviving redundant mutant is accepted by the runner). + +- `BE_ALLOC_CHECK_CPU`: a buffer without a CPU mapping is refused (ALLOC) +- `BE_ALLOC_CHECK_SIZE`: a buffer smaller than asked is refused (ALLOC) +- `BE_ALLOC_CHECK_ALIGN`: a GPU address that is not 256-byte aligned is refused (ALLOC) +- `BE_ALLOC_OWN_CHECK_NOTE`: the backend's own refusal text reaches the result +- `BE_ALLOC_OWN_CHECK_FREE`: a buffer that fails its own checks is freed, not leaked +- `BE_ROLE_FREE_SKIPPED`: free_buf really frees a program, input or output buffer +- `BE_SCRATCH_FREE_SKIPPED`: release_scratch really frees all four SCRATCH parts +- `BE_SCRATCH_FREE_ERROR_DROPPED`: a failed SCRATCH part free is reported +- `BE_SCRATCH_FREE_STOPS_AT_ERROR`: one failed SCRATCH part free does not leave the other parts allocated +- `BE_SCRATCH_ALLOC_FAIL_NO_RELEASE`: a failed SCRATCH allocation frees the parts that did succeed (the core does not) +- `BE_ERRNO_NOT_RESTORED`: the frees after a failed SCRATCH allocation do not clobber the errno the core reads +- `BE_ALLOC_FAIL_TEXT_RESTORE` (redundant): the failure text survives the cleanup frees. Reason: release_scratch writes neither c->text nor the driver text on a successful free, in the simulated driver and in nvrm_free (physics nvrm.h: free only zeroes the NvrmMem); the restore is a safety net for a driver that writes text on success, which no model here does +- `BE_SCRATCH_PB_NOT_INSTALLED`: the large pushbuffer ring replaces the channel's 4 KiB buffer +- `BE_PB_REPLACED_RESET` (redundant): the flag that records the replaced ring is cleared after SCRATCH is freed. Reason: the zeroing of m.pb_mem stays (it is a separate line); a stale flag only repeats that harmless zeroing, and open memsets the whole context each run. physics m16_native_close is only nvrm_close(&ctx->rm) and never reads pb_mem +- `BE_BUSY_CHECK_DROPPED`: a second open while a run is retained is refused +- `BE_OPEN_FAIL_KEEPS_BUSY`: a failed open releases the busy flag +- `BE_CLOSE_BUSY_CLEAR_DROPPED`: close releases the busy flag so the next run can open +- `BE_OPEN_MEMSET_DROPPED`: open resets the whole context, including the previous run's snapshot +- `BE_OPEN_NATIVE_FLAG_DROPPED`: a failed open still reports the driver's own text +- `BE_OPEN_ERROR_IGNORED`: a failed driver open is reported (DEVICE_OPEN) +- `BE_OPEN_LAST_RC_DROPPED`: the failed open's driver code reaches the result +- `BE_CHANNEL_ERROR_IGNORED`: a failed channel create is reported (CHANNEL_CREATE) +- `BE_CHANNEL_LAST_RC_DROPPED`: the failed channel create's driver code reaches the result +- `BE_ALLOC_LAST_RC_DROPPED`: the failed allocation's driver code reaches the result +- `BE_ALLOC_UNKNOWN_ROLE_ACCEPTED`: alloc refuses an unknown role +- `BE_ROLE_MEM_UPPER_BOUND`: a role above the last one has no buffer slot +- `BE_ROLE_MEM_LOWER_BOUND`: a negative role has no buffer slot +- `BE_ROUND_PAGES_ZERO_ACCEPTED`: a zero-byte allocation is refused +- `BE_ROUND_PAGES_NO_ROUNDING`: allocation sizes round up to whole pages +- `BE_ROUND_PAGES_MINIMUM` (redundant): one-page minimum. Reason: after the zero check, rounding any nonzero byte count up to a page multiple already gives at least one page, so the minimum can never apply +- `BE_COPY_IN_NO_MEMCPY`: copy_in really copies the program and the inputs +- `BE_COPY_IN_BOUNDS`: copy_in refuses a length beyond the buffer +- `BE_COPY_IN_NULL_SOURCE`: copy_in refuses a NULL source +- `BE_FILL_POISON_DROPPED`: the device output is pre-filled with the poison words +- `BE_FILL_POISON_SHORT`: every output word is pre-filled, including the last +- `BE_FILL_POISON_BOUNDS`: fill_poison refuses a length beyond the output buffer +- `BE_COPY_OUT_NO_MEMCPY`: copy_out really reads the device output back +- `BE_COPY_OUT_BOUNDS`: copy_out refuses a length beyond the output buffer +- `BE_BUILD_LAYOUT_CHECK`: build refuses a missing job and an unsupported layout +- `BE_BUILD_COUNT_OVERFLOW` (redundant): grid arithmetic overflow guard. Reason: an element count above UINT32_MAX - 63 needs at least 16 GiB of input, output and input buffers, so the buffer-size check in the same condition chain refuses it first; only the grid rounding (n + 63) could overflow, and it is never reached +- `BE_BUILD_BUFFERS_SIZE`: build refuses buffers smaller than the element count needs +- `BE_C3_FLAG_IGNORED`: the NO_C3 flag removes the L2 flush and the second marker +- `BE_C3_NEVER`: with flags 0 the L2 flush and the second marker are in the pushbuffer +- `BE_THREADS_WRONG`: the launch covers every element +- `BE_GRID_ROUNDS_DOWN`: the grid rounds up so a partial last block still runs +- `BE_ARGS_C_SWAPPED`: the kernel writes the OUTPUT buffer +- `BE_ARGS_A_B_SWAPPED`: the kernel gets input A and input B in the right argument slots +- `BE_PROGRAM_VA`: the QMD points at the program buffer +- `BE_CBANK_VA`: the QMD points at the constant bank buffer +- `BE_SEM_VA`: the QMD release semaphore address is the word the host waits on +- `BE_MARKER_VA`: the first release lands on the word the host waits on +- `BE_SEM_ZERO_DROPPED`: the semaphore word is zeroed before the doorbell (no stale DONE) +- `BE_MARKER_ZERO_DROPPED`: the first marker word is zeroed before the doorbell (no stale payload) +- `BE_MARKER2_ZERO_DROPPED`: the second marker word is zeroed before the doorbell +- `BE_NOC3_MARKER2_REPORTED`: with NO_C3 the second marker is neither waited for nor reported +- `BE_MARKER2_OFFSET_CHANGED`: the second marker is 0x10 bytes after the first +- `BE_MARKER2_PAYLOAD_CHANGED`: the second marker payload is 0x46464646 +- `BE_RELEASE1_PAYLOAD_ZERO`: the first release writes the completion payload +- `BE_RELEASE2_PAYLOAD_ZERO`: the second release writes its payload +- `BE_FLUSH_OP_DROPPED`: the L2 flush operation word is L2_FLUSH_DIRTY +- `BE_FLUSH_METHOD_CHANGED`: the flush uses the memory-operation method +- `BE_WFI_FLAG_RELEASE1`: the first release waits for idle (WFI) +- `BE_WFI_FLAG_RELEASE2`: the second release waits for idle (WFI) +- `BE_BARRIER_IN_BUILD` (redundant): dsb sy after zeroing the sync words. Reason: a CPU barrier instruction has no effect a host test can observe (the fake driver runs on the same core); it is verified on the chip only (Phase B) +- `BE_QMD_RELEASE_CHECK` (redundant): extra QMD1 release-word checks. Reason: the real descriptor builder always produces these words (src/omega_blackwell_qmd.c), so no input makes the check fire; it guards a future change of the builder, which tests/test_omega_blackwell_qmd.c style checks cover +- `BE_PB_OVERFLOW` (redundant): pushbuffer word-capacity guard. Reason: the vector pushbuffer is a fixed 492 words against a 1024-word capacity, so it cannot overflow for any job +- `BE_SUBMIT_NOTHING_BUILT` (redundant): submit before build is refused. Reason: the driver refuses an empty submission too (physics m16_native.c m16_native_enqueue_methods: count == 0 returns -1), so the result is the same refusal +- `BE_LAUNCH_NS_DROPPED`: the launch time is recorded before the doorbell +- `BE_SUBMIT_ERROR_IGNORED`: a failed submit is reported (SUBMIT), not treated as launched +- `BE_WAIT_UNMAPPED_ACCEPTED`: a wait before build or after free is refused without a driver call +- `BE_WAIT_DRIVER_RC_DROPPED`: the driver's wait code reaches the result +- `BE_WAIT_RC_MAPPING` (redundant): timeout versus driver fault classification. Reason: the engine core treats every nonzero wait result the same (uncertain completion), and the real m16_native_wait_marker returns only 0 or -1 (m16_native.c) +- `BE_WAIT_EQUALITY_RECHECK`: an overshoot of the ">=" compare is refused (UNKNOWN_STATE) +- `BE_WAIT_SNAPSHOT_DROPPED`: the observed word is recorded after every wait +- `BE_MARKER_DONE_NS_ALWAYS`: the completion time is recorded only when the first marker wait succeeded +- `BE_WAIT_MARKER_WRONG_WORD`: wait_marker waits on the first marker word +- `BE_WAIT_SEMAPHORE_WRONG_VALUE`: the release semaphore wait is for DONE (6), not the initial value (5) +- `BE_DIAG_DRV_RC_DROPPED`: diagnostics report the raw driver code +- `BE_DIAG_TEXT_OWN_DROPPED`: diagnostics report the backend's own text +- `BE_DIAG_TEXT_DRIVER_DROPPED`: diagnostics fall back to the driver's text +- `BE_DIAG_MARKER_DROPPED`: diagnostics report the first marker word +- `BE_DIAG_MARKER2_DROPPED`: diagnostics report the second marker word +- `BE_DIAG_SEMAPHORE_DROPPED`: diagnostics report the semaphore word +- `BE_DIAG_VALID_MARKER_DROPPED`: the first marker is flagged valid only when mapped +- `BE_DIAG_VALID_MARKER2_DROPPED`: the second marker is flagged valid only when mapped +- `BE_DIAG_VALID_SEMAPHORE_DROPPED`: the semaphore is flagged valid only when mapped +- `BE_FREE_SCRATCH_ROLE_DROPPED`: free_buf of SCRATCH frees the four SCRATCH parts +- `BE_FREE_UNKNOWN_ROLE_ACCEPTED`: free_buf refuses an unknown role +- `BE_FREE_ERROR_DROPPED`: a failed free is reported (CLEANUP) +- `BE_RELEASE_KEEPS_MARKER_POINTER`: the first marker word is unmapped before SCRATCH is freed +- `BE_RELEASE_KEEPS_MARKER2_POINTER`: the second marker word is unmapped before SCRATCH is freed +- `BE_RELEASE_KEEPS_SEM_POINTER`: the semaphore word is unmapped before SCRATCH is freed +- `BE_CLOSE_KEEPS_MARKER_POINTER`: close unmaps the first marker word +- `BE_CLOSE_KEEPS_MARKER2_POINTER`: close unmaps the second marker word +- `BE_CLOSE_KEEPS_SEM_POINTER`: close unmaps the semaphore word +- `BE_CLOSE_NOT_CALLED`: close really closes the driver +- `BE_CLOSE_ERROR_IGNORED`: a failed close is reported (CLEANUP) +- `WRAP_POISON_NOT_COMPLEMENT`: the poison word is the complement of the expected sum +- `WRAP_POISON_CONSTANT`: the poison word never collides with a legitimate sum (0xdeadbeef is one) +- `WRAP_ENGINE_FAILURE_IGNORED`: an engine failure (here a cleanup fault) fails the wrapper +- `WRAP_ORACLE_IGNORED`: the host oracle decides success, not the engine +- `WRAP_PARITY_FLAG_FORCED`: parity_verified follows the oracle +- `WRAP_MARKER_NOT_REPORTED`: the completion marker is reported +- `WRAP_SEMAPHORE_NOT_REPORTED`: the semaphore value is reported +- `WRAP_LAUNCH_TIME_NOT_REPORTED`: the launch time is reported +- `WRAP_DONE_TIME_NOT_REPORTED`: the completion time is reported +- `WRAP_ELAPSED_NOT_REPORTED`: the elapsed time is reported +- `WRAP_SM_ARCH_NOT_REPORTED`: the architecture is reported +- `WRAP_ELEMENT_COUNT_NOT_REPORTED`: the element count is reported +- `WRAP_NULL_GUARD_DROPPED`: a NULL argument is refused before any use +- `WRAP_ZERO_COUNT_GUARD` (redundant): a zero element count is refused by the wrapper. Reason: the engine refuses element_count 0 as INVALID_ARGS (src/omega_gpu_engine.c job_valid) and the wrapper then returns -1, so the result is the same refusal +- `WRAP_MARKER_TIMEOUT`: the first marker wait limit is 5000 ms +- `WRAP_SEMAPHORE_TIMEOUT`: the semaphore wait limit is 5000 ms +- `WRAP_MARKER2_TIMEOUT`: the second marker wait limit is 5000 ms +- `WRAP_VISIBILITY_TIMEOUT` (redundant): the visibility limit is 5000 ms. Reason: the Blackwell barrier callback ignores its timeout argument (it is a CPU dsb sy that cannot wait), so no host observation depends on the value +- `WRAP_FLAGS_ALL_PROTECTIONS`: the wrapper runs with every protection on (flags 0) +- `WRAP_BACKEND_NOT_INSTALLED`: the wrapper installs the Blackwell backend itself +- `WRAP_PROGRAM_LENGTH`: the whole encoded program is handed to the engine +- `WRAP_MARKER_CHECK` (redundant): second check of the marker payload. Reason: the backend wait_word already refuses any first-marker value other than 0x44444444 (UNKNOWN_STATE), so the engine fails before this line is reached +- `WRAP_SEMAPHORE_CHECK` (redundant): second check of the semaphore value. Reason: the backend wait_word already refuses any semaphore value other than DONE (6), so the engine fails before this line is reached + +The `dsb sy` barrier mutants are chip only: a CPU barrier instruction has no +effect a host test can observe, so they are redundant on the host and belong to +Phase B. Mutants of the core itself stay in `tools/gpu_engine_mutations.sh`. + +## 15. Origin + +The engine core and the Blackwell backend were seeded from the first cut written +by GPT-6 Astra (branch `fix/omega-gpu-engine-first-cut`, commit 21392ee, dated +2026-10-02). Claude workers did the host test, the mutation sweep, the +reconciliation of Astra's single-file engine to the omega#218 public API +(`OmegaGpuJob`, `OmegaGpuResult`, `omega_gpu_execute`, the backend table), and the +vector wrapper. What was kept from Astra: the device call order, the pushbuffer +and QMD sequence, the allocation checks, the QMD1 word checks, the exact-value +re-check after each wait, the dsb barrier and the L2 flush plus second marker. +What was not copied: Astra's own job and result types, her state machine, the +poison comparison and the quarantine logic, because the A3a core already does +those. diff --git a/evidence/OMEGA-GPU-ENGINE/gb10-1-2eb912d/M17.log b/evidence/OMEGA-GPU-ENGINE/gb10-1-2eb912d/M17.log new file mode 100644 index 000000000..076a8f750 --- /dev/null +++ b/evidence/OMEGA-GPU-ENGINE/gb10-1-2eb912d/M17.log @@ -0,0 +1,24 @@ +================================================================================ + AIEN OMEGA SUBSTRATE: MILESTONE 17: OMEGA_BLACKWELL_VECTOR GATES +================================================================================ + [PASS] OMEGA_BW_VECTOR_SEMANTIC_PASS : Machine-independent semantic definition C[i] = (A[i] + B[i]) mod 2^32 + [PASS] OMEGA_BW_VECTOR_MACHINE_BINDING_PASS : Grace Blackwell GB10 sm_121 machine target binding + [PASS] OMEGA_BW_VECTOR_REALIZATION_PASS : Cryptographic triple identity (spec || machine || code) + [PASS] OMEGA_BW_VECTOR_ENCODER_FIXTURE_PASS : Blackwell 128-bit instruction encoding fixtures + [PASS] OMEGA_BW_VECTOR_NATIVE_ENCODING_PASS : Dynamic native sm_121 vecadd code emission (512 bytes) + [PASS] OMEGA_BW_VECTOR_QMD_PASS : Queue Meta Data Version 05_00 launch descriptor generation + [PASS] OMEGA_BW_VECTOR_PHYSICS_AUTHORITY_PASS : M16 frozen dependency authority and clean interface + [PASS] OMEGA_BW_VECTOR_NATIVE_SUBMIT_PASS : Unified pushbuffer submission via M16 GPFIFO ring + [PASS] OMEGA_BW_VECTOR_DEVICE_OUTPUT_PASS : Physical SM execution and unpoisoned output buffer + [PASS] OMEGA_BW_VECTOR_COMPLETION_PASS : WFI completion marker 0x44444444 and semaphore state 6 + [PASS] OMEGA_BW_VECTOR_V1_PARITY_PASS : Bit-for-bit exact parity against semantic oracle (N=64) + [PASS] OMEGA_BW_VECTOR_BOUNDARY_PASS : Boundary sweep across N in {1,15,63,64,65,127,128,256,1024} + [PASS] OMEGA_BW_VECTOR_MUTATION_REFUSAL_PASS : Tamper resistance: bit flips and corruptions rejected + [PASS] OMEGA_BW_VECTOR_ZERO_LIBCUDA_LINK_PASS : Zero dynamic linkage to libcuda.so or libcudart.so + [PASS] OMEGA_BW_VECTOR_ZERO_CUDA_SYMBOL_PASS : Zero undefined dynamic CUDA symbols + [PASS] OMEGA_BW_VECTOR_ZERO_LIBCUDA_RUNTIME_PASS : Zero runtime libcuda mappings in /proc/self/maps + [PASS] OMEGA_BW_VECTOR_EVIDENCE_DURABILITY_PASS : Durable machine code and QMD hex dumps recorded + [PASS] OMEGA_BW_VECTOR_RECEIPT_PASS : Cryptographic qualification receipt generated +================================================================================ + TOTAL GATES: 18 | PASSED: 18 | FAILED: 0 +================================================================================ diff --git a/evidence/OMEGA-GPU-ENGINE/gb10-1-2eb912d/M18.log b/evidence/OMEGA-GPU-ENGINE/gb10-1-2eb912d/M18.log new file mode 100644 index 000000000..47b9df55a --- /dev/null +++ b/evidence/OMEGA-GPU-ENGINE/gb10-1-2eb912d/M18.log @@ -0,0 +1,65 @@ +================================================================================ + AIEN OMEGA SUBSTRATE: MILESTONE 18: OMEGA_BLACKWELL_MATMUL QUALIFICATION GATES +================================================================================ + [PASS] OMEGA_BW_MATMUL_SEMANTIC_CONTRACT_PASS : Formal mathematical contract & CPU oracle parity + [PASS] OMEGA_BW_MATMUL_MACHINE_GRAPH_PASS : Grace Blackwell GB10 sm_121 machine target binding + [PASS] OMEGA_BW_MATMUL_ENCODER_UNIT_PASS : Dynamic sm_121 instruction encoder bitfield programmatic unit tests + [PASS] OMEGA_BW_MATMUL_BOUNDED_REGALLOC_PASS : Bounded deterministic live-interval register allocation & conflict rejection + [PASS] OMEGA_BW_MATMUL_INSTRUCTION_SEQUENCING_PASS : Dynamic instruction sequencer & 128-byte bundle alignment + [PASS] OMEGA_BW_MATMUL_CODE_TRUTH_PASS : Code truth invariant: zero static precompiled instruction tables in codegen core +================================================================================ + OMEGA BLACKWELL CODEGEN VARIATION DEMONSTRATION (GATE 7 STAGE-1) +================================================================================ +Config 1: 16x16x16 INT32 + Instructions: 136 (2176 bytes, 21 GPRs, 6 UGPRs) + Spec ID: dbbdbda6e207dbc896360900a8a6d36f... + Code Digest: 836e0a5039fa05034f9df1d189f03cdc... + Realization: 7def35b10e6c80c4499f276aed3f895f... + +Config 2: 32x16x64 INT32 + Instructions: 136 (2176 bytes, 21 GPRs, 6 UGPRs) + Spec ID: f03d86c6ec34126d2cfe23eb6bc9c58d... + Code Digest: 895ce738ce4eada171b642dbe0b26337... + Realization: 9e842539ad3be21838ac1ca869e4d6e7... +================================================================================ +PASS: Dynamic codegen variation verified (distinct specifications, code digests, and realization IDs). + [PASS] OMEGA_BW_MATMUL_CODEGEN_VARIATION_PASS : Stage-1 dynamic code variation: distinct code digests & realization IDs + [PASS] OMEGA_BW_MATMUL_REALIZATION_ID_PASS : Dynamic code digest & 4-tuple realization identity binding + [PASS] OMEGA_BW_MATMUL_QMD_2D_PASS : Queue Meta Data Version 05_00 2D grid launch descriptor synthesis + [PASS] OMEGA_BW_MATMUL_NATIVE_SUBMIT_PASS : Native M16 submission path & GPFIFO pushbuffer integration + [PASS] OMEGA_BW_MATMUL_INT32_INTERMEDIATE_PASS : Intermediate INT32 execution on physical GB10 with exact bit-for-bit parity + [PASS] OMEGA_BW_MATMUL_TENSOR_CORE_EXECUTION_PASS : Mandatory physical GB10 Tensor Core MMA execution & 9-point proof bundle + [PASS] OMEGA_BW_MATMUL_NUMERICAL_BOUND_PASS : Bounded numerical parity against oracle (< 10^-4) across canonical shapes + [PASS] OMEGA_BW_MATMUL_BOUNDARY_ANNIHILATION_PASS : Boundary and annihilation matrix tests (zero, identity, dynamic range, cancellation) + [PASS] OMEGA_BW_MATMUL_ZERO_LIBCUDA_PASS : Zero foreign userspace runtime verification (linkage, symbols, maps) + [PASS] OMEGA_BW_MATMUL_CLEAN_CLONE_PASS : Clean-clone isolated reproduction on DGX Spark +================================================================================ + AIEN OMEGA SUBSTRATE: MILESTONE 17: OMEGA_BLACKWELL_VECTOR GATES +================================================================================ + [PASS] OMEGA_BW_VECTOR_SEMANTIC_PASS : Machine-independent semantic definition C[i] = (A[i] + B[i]) mod 2^32 + [PASS] OMEGA_BW_VECTOR_MACHINE_BINDING_PASS : Grace Blackwell GB10 sm_121 machine target binding + [PASS] OMEGA_BW_VECTOR_REALIZATION_PASS : Cryptographic triple identity (spec || machine || code) + [PASS] OMEGA_BW_VECTOR_ENCODER_FIXTURE_PASS : Blackwell 128-bit instruction encoding fixtures + [PASS] OMEGA_BW_VECTOR_NATIVE_ENCODING_PASS : Dynamic native sm_121 vecadd code emission (512 bytes) + [PASS] OMEGA_BW_VECTOR_QMD_PASS : Queue Meta Data Version 05_00 launch descriptor generation + [PASS] OMEGA_BW_VECTOR_PHYSICS_AUTHORITY_PASS : M16 frozen dependency authority and clean interface + [PASS] OMEGA_BW_VECTOR_NATIVE_SUBMIT_PASS : Unified pushbuffer submission via M16 GPFIFO ring + [PASS] OMEGA_BW_VECTOR_DEVICE_OUTPUT_PASS : Physical SM execution and unpoisoned output buffer + [PASS] OMEGA_BW_VECTOR_COMPLETION_PASS : WFI completion marker 0x44444444 and semaphore state 6 + [PASS] OMEGA_BW_VECTOR_V1_PARITY_PASS : Bit-for-bit exact parity against semantic oracle (N=64) + [PASS] OMEGA_BW_VECTOR_BOUNDARY_PASS : Boundary sweep across N in {1,15,63,64,65,127,128,256,1024} + [PASS] OMEGA_BW_VECTOR_MUTATION_REFUSAL_PASS : Tamper resistance: bit flips and corruptions rejected + [PASS] OMEGA_BW_VECTOR_ZERO_LIBCUDA_LINK_PASS : Zero dynamic linkage to libcuda.so or libcudart.so + [PASS] OMEGA_BW_VECTOR_ZERO_CUDA_SYMBOL_PASS : Zero undefined dynamic CUDA symbols + [PASS] OMEGA_BW_VECTOR_ZERO_LIBCUDA_RUNTIME_PASS : Zero runtime libcuda mappings in /proc/self/maps + [PASS] OMEGA_BW_VECTOR_EVIDENCE_DURABILITY_PASS : Durable machine code and QMD hex dumps recorded + [PASS] OMEGA_BW_VECTOR_RECEIPT_PASS : Cryptographic qualification receipt generated +================================================================================ + TOTAL GATES: 18 | PASSED: 18 | FAILED: 0 +================================================================================ + [PASS] OMEGA_BW_MATMUL_REGRESSION_PASS : Cumulative regression parity: 18 / 18 prior milestone gates passing + [PASS] OMEGA_BW_MATMUL_RECEIPT_PASS : Milestone 18 qualification receipt and cryptographic manifest generated +================================================================================ + STAGE 2 / FULL QUALIFICATION: 18 / 18 M18 GATES PASSED + TOTAL GATES EVALUATED: 36 (18 M18 Gates + 18 Prior Regression Gates) +================================================================================ diff --git a/evidence/OMEGA-GPU-ENGINE/gb10-1-2eb912d/SHA256SUMS b/evidence/OMEGA-GPU-ENGINE/gb10-1-2eb912d/SHA256SUMS new file mode 100644 index 000000000..080ad907d --- /dev/null +++ b/evidence/OMEGA-GPU-ENGINE/gb10-1-2eb912d/SHA256SUMS @@ -0,0 +1,13 @@ +abbf12d1b255c2b51e20dee630d4cfce4d3c789c52714d348e415aa493648fe9 ./BUILD.log +cb22507f254235764b4d001a5b051e12d761c61dde7106f1d59bdc097a7e4f81 ./device.txt +ebfff6bb8f71d81a034023cf96d1f7637b87e1ba6326324802c913b640608aad ./ENGINE.log +2a1650abca47a97827d7a5596b3ec59ee95ab0a23097a48553e692ba4a736921 ./exit.txt +afacf5d469fc8b658a35621cbfbfd64d2dee025e7e149d305a9cb53ccad06e90 ./gpu_engine/afacf5d469fc8b658a35621cbfbfd64d2dee025e7e149d305a9cb53ccad06e90.json +9213ec554ae09d44f2224926b818331c817de08bd8bcf222d2a3017abb6c2905 ./gpu_engine/blobs/9213ec554ae09d44f2224926b818331c817de08bd8bcf222d2a3017abb6c2905.log +59a740e9a43c4565e9ede54de90745f43a0794e460fba500b7eeb35fd0e6161f ./M17.log +7317ef22eed3b7029798553d38cccf397a69a3ceaa8ff934b1028c6ecb042efa ./M18.log +c484007c8045e53af0304c448c759ff40863d3038a37f13d5e27e97f10f6e3a5 ./omega-head.txt +c149029294339025e23719a4dc4a3e143622bb8f869ca94b7e3b14684feaa767 ./omegatool.sha256 +d49dfc0048ddb45fceee592565c47daba54cb65cfcd48209e3fdf993f096b948 ./physics-head.txt +02c51a24c843a3717145c6c8c15eb7bbf0b6a70a5b71aa66a172385de3fc68d1 ./runner.sh +cba8184e24fdaf382a61ebd9285e12dccccd2aedeb9c07db056d848540f1668e ./start.txt diff --git a/evidence/OMEGA-GPU-ENGINE/gb10-1-2eb912d/afacf5d469fc8b658a35621cbfbfd64d2dee025e7e149d305a9cb53ccad06e90.json b/evidence/OMEGA-GPU-ENGINE/gb10-1-2eb912d/afacf5d469fc8b658a35621cbfbfd64d2dee025e7e149d305a9cb53ccad06e90.json new file mode 100644 index 000000000..d90841d2c --- /dev/null +++ b/evidence/OMEGA-GPU-ENGINE/gb10-1-2eb912d/afacf5d469fc8b658a35621cbfbfd64d2dee025e7e149d305a9cb53ccad06e90.json @@ -0,0 +1,27 @@ +{ + "gate": "gpu_engine", + "owner": "gpu_engine", + "omega_commit": "2eb912d0e4854b4e11d6b3b54754c5f53c2240b5", + "omega_tree_clean_before": true, + "omega_tree_clean_after": true, + "omega_commit_unchanged_after": true, + "physics_commit": "6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf", + "physics_lock_pin": "6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf", + "physics_tree_clean_before": true, + "physics_tree_clean_after": true, + "physics_commit_unchanged_after": true, + "binary_sha256": "b09a83340eabb9228f35cb5a68f2d5a8f1c7eff81050a9073272ec1f14c92803", + "chip_log_sha256": "9213ec554ae09d44f2224926b818331c817de08bd8bcf222d2a3017abb6c2905", + "run_args": [ + "--chip" + ], + "host_tier": "mutants: 120 total, 107 killed, 13 survived as redundant, 0 survived as test gaps (receipt /tmp/mutrun.tzBEF0/out.json)", + "verdict_lines": [ + "GPU_ENGINE: PASS" + ], + "chip_exit_status": 0, + "started_utc": "2026-10-03T14:01:20Z", + "finished_utc": "2026-10-03T14:01:39Z", + "verdict": "PASS", + "reason": "" +} diff --git a/evidence/OMEGA-GPU-ENGINE/gb10-1-2eb912d/blobs/9213ec554ae09d44f2224926b818331c817de08bd8bcf222d2a3017abb6c2905.log b/evidence/OMEGA-GPU-ENGINE/gb10-1-2eb912d/blobs/9213ec554ae09d44f2224926b818331c817de08bd8bcf222d2a3017abb6c2905.log new file mode 100644 index 000000000..c9a240fcb --- /dev/null +++ b/evidence/OMEGA-GPU-ENGINE/gb10-1-2eb912d/blobs/9213ec554ae09d44f2224926b818331c817de08bd8bcf222d2a3017abb6c2905.log @@ -0,0 +1,2 @@ +GPU_ENGINE_CASES vector_runs=120 no_store_control=detected +GPU_ENGINE: PASS diff --git a/mk/omega-gpu-engine.mk b/mk/omega-gpu-engine.mk index fc5cd08ca..39ac34545 100644 --- a/mk/omega-gpu-engine.mk +++ b/mk/omega-gpu-engine.mk @@ -1,9 +1,72 @@ -# 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 +# Omega GPU Engine (docs/numeric/OMEGA_GPU_ENGINE.md). Picked up by +# `-include mk/*.mk`. Host only: opens no device; needs no physics headers except the two A3b1 targets, not +# part of `all` or `test`. +# test-gpu-engine-compile header + core compile, enum names, refusals, no-op backend (A2/A3a) +# test-gpu-engine the engine core against a fake backend (every state and failure) +# test-gpu-engine-backend-compile syntax-checks src/omega_blackwell_engine.c (A3b1): -c only, no link, no device +# test-gpu-engine-prod-build production build of build/omegatool at the physics pin: links only, opens no device +# test-gpu-engine-mutants removes each protection from src/omega_gpu_engine.c in a scratch +# copy; the host test must fail each one (exit nonzero on a survivor) +# test-gpu-engine-sim (A3b2) the REAL engine core + Blackwell backend + vector wrapper against a simulated driver +# (tests/fake_m16_native.c); host only, no device, no physics C sources +# test-gpu-engine-backend-mutants (A3b2) one mutant per protection in the backend and the vector wrapper +# test-gpu-engine-gb10-compile (A3b2) compile-only check of tests/test_omega_gpu_engine_gb10.c (Phase B chip test, never run here) +.PHONY: test-gpu-engine-compile test-gpu-engine test-gpu-engine-mutants test-gpu-engine-backend-compile test-gpu-engine-prod-build test-gpu-engine-sim test-gpu-engine-backend-mutants test-gpu-engine-gb10-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 + +build/test_omega_gpu_engine: tests/test_omega_gpu_engine.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.c src/omega_gpu_engine.c +test-gpu-engine: build/test_omega_gpu_engine + ./build/test_omega_gpu_engine + +test-gpu-engine-mutants: + sh tools/gpu_engine_mutations.sh + +# A3b1: the Blackwell backend includes physics headers (m16_native.h, nvrm.h), so it +# uses the same physics -I paths as the top-level Makefile CFLAGS (Makefile lines 9-14). +GPU_ENGINE_PHYS_INC = -I$(PHYSICS_DIR)/m16 -I$(PHYSICS_DIR)/nvrm \ + -I$(PHYSICS_DIR)/third_party/nvidia-open-580.173.02/src/common/sdk/nvidia/inc \ + -I$(PHYSICS_DIR)/third_party/nvidia-open-580.173.02/kernel-open/common/inc \ + -I$(PHYSICS_DIR)/third_party/nvidia-open-580.173.02/kernel-open/nvidia-uvm \ + -I$(PHYSICS_DIR)/third_party/nvidia-open-580.173.02/src/nvidia/arch/nvalloc/unix/include + +build/omega_blackwell_engine_syntax.o: src/omega_blackwell_engine.c src/omega_blackwell_engine.h src/omega_gpu_engine.h + @mkdir -p build + gcc -std=gnu11 -O2 -Wall -Wextra -Werror -D_GNU_SOURCE -Isrc $(GPU_ENGINE_PHYS_INC) -c -o $@ src/omega_blackwell_engine.c +test-gpu-engine-backend-compile: build/omega_blackwell_engine_syntax.o + +# Links only, opens no device. Uses the real m16_native and nvrm sources at the physics pin. +test-gpu-engine-prod-build: + $(MAKE) build/omegatool + +# A3b2: simulated-driver host test. Links the sources of the Makefile RX_COMPOSE_GPU_SRCS list (plus the +# three core files the vector builder needs) with tests/fake_m16_native.c in place of the physics +# m16_native.c and nvrm.c. Opens no device. +GPU_ENGINE_SIM_SRCS = src/omega_blackwell_submit.c src/omega_blackwell_engine.c src/omega_gpu_engine.c \ + src/omega_blackwell_matmul.c src/omega_blackwell_codegen.c src/omega_blackwell_encoder.c \ + src/omega_blackwell_qmd.c src/omega_blackwell_realize.c src/omega_vector.c src/omega_validate.c \ + src/omega_core.c src/omega_canonical.c src/sha256.c + +build/test_omega_blackwell_engine: tests/test_omega_blackwell_engine.c tests/fake_m16_native.c tests/fake_m16_native.h \ + $(GPU_ENGINE_SIM_SRCS) src/omega_gpu_engine.h src/omega_blackwell_engine.h + @mkdir -p build + gcc -std=gnu11 -O2 -Wall -Wextra -Werror -D_GNU_SOURCE -pthread -ffunction-sections -fdata-sections \ + -Isrc -Itests $(GPU_ENGINE_PHYS_INC) -o $@ tests/test_omega_blackwell_engine.c tests/fake_m16_native.c \ + $(GPU_ENGINE_SIM_SRCS) -Wl,--gc-sections -lm +test-gpu-engine-sim: build/test_omega_blackwell_engine + ./build/test_omega_blackwell_engine + +# One mutant per backend and vector-wrapper protection; the sim test must fail each one. +test-gpu-engine-backend-mutants: + PHYSICS_DIR="$(PHYSICS_DIR)" sh tools/gpu_engine_backend_mutations.sh + +# Phase B chip test, compile only here. Never run in Phase A. +build/test_omega_gpu_engine_gb10.o: tests/test_omega_gpu_engine_gb10.c src/omega_gpu_engine.h src/omega_blackwell_engine.h src/omega_blackwell_submit.h + @mkdir -p build + gcc -std=gnu11 -O2 -Wall -Wextra -Werror -ffp-contract=off -fno-fast-math -pthread -Isrc $(GPU_ENGINE_PHYS_INC) -c -o $@ tests/test_omega_gpu_engine_gb10.c +test-gpu-engine-gb10-compile: build/test_omega_gpu_engine_gb10.o diff --git a/src/omega_blackwell_engine.c b/src/omega_blackwell_engine.c new file mode 100644 index 000000000..32f0cd596 --- /dev/null +++ b/src/omega_blackwell_engine.c @@ -0,0 +1,663 @@ +/* + * Omega GPU Engine, Blackwell GB10 backend (cut A3b1). See + * src/omega_blackwell_engine.h and docs/numeric/OMEGA_GPU_ENGINE.md. + * + * This file is the backend function table (OmegaGpuBackend) that the engine + * core in src/omega_gpu_engine.c drives. The core owns the state machine, the + * poison comparison, the uncertain-completion block and the cleanup order. + * This file owns only the device calls. Each callback below says which lines of + * the launcher it was lifted from. "SUB@676f16f" means + * omega_blackwell_execute_vector in src/omega_blackwell_submit.c at commit + * 676f16f (the file before this cut). "ASTRA" means the first cut by GPT-6 + * Astra, src/omega_blackwell_engine.c at commit 21392ee on branch + * fix/omega-gpu-engine-first-cut. + * + * Roles. SCRATCH is the backend's own and holds four device buffers: the large + * pushbuffer (0x10000), the driver/argument constant bank (0x1000), the marker + * page (0x1000) and the QMD page (0x10000), the same sizes as SUB@676f16f + * lines 50, 59, 63, 64. PROGRAM, INPUT_A, INPUT_B and OUTPUT are page rounded + * with a 0x1000 minimum (SUB@676f16f lines 55-56, 58-62). + * + * L2 flush. The core has no separate callback for it, so build() emits the L2 + * flush and the second release marker (payload 0x46464646 at marker page + 0x10) + * inside the pushbuffer unless the job sets NO_C3, exactly as divsqrt does in + * src/omega_numeric_divsqrt_gb10.c:1145-1152. The wait_marker2 callback waits + * for that marker. The CPU side of the visibility rule (dsb sy before readback) + * is the barrier callback (divsqrt line 1171). + * + * One run at a time. The context is one static object because a retained run + * (uncertain completion, nothing freed, nothing closed) must keep its device + * memory reachable for the life of the process, and because the native context + * is about 225 KiB (Nvrm in physics/nvrm/nvrm.h). A second open while a run is + * active fails with DEVICE_OPEN. + * + * NOT_RUN: this file has not been compiled or executed by its author. + */ +#include "omega_blackwell_engine.h" +#include "omega_blackwell_qmd.h" +#include "omega_blackwell_submit.h" +#include "m16_native.h" + +#include <errno.h> +#include <stdatomic.h> +#include <stddef.h> +#include <stdint.h> +#include <stdio.h> +#include <string.h> +#include <time.h> + +#define BE_PB_CAP 1024u /* pushbuffer words, SUB@676f16f line 131 (uint32_t pb[1024]) */ +#define BE_PAGE 0x1000u +#define BE_PB_BYTES 0x10000u /* SUB@676f16f line 50 */ +#define BE_QMD_BYTES 0x10000u /* SUB@676f16f line 64 */ +#define BE_SEM_OFFSET 0x2000u /* sem_va = qmd page + 0x2000, SUB@676f16f line 99 */ +#define BE_MARKER2_OFFSET 0x10u /* divsqrt line 1113 and 1152 */ +#define BE_MARKER2_PAYLOAD 0x46464646u /* divsqrt line 1152 */ + +typedef struct { + M16NativeContext m; + NvrmMem pb; /* SCRATCH part 1: large pushbuffer */ + NvrmMem cbank; /* SCRATCH part 2 */ + NvrmMem marker; /* SCRATCH part 3 */ + NvrmMem qmd; /* SCRATCH part 4 (QMD0, QMD1, semaphore) */ + NvrmMem buf[OMEGA_GPU_BUF_ROLE_COUNT]; /* PROGRAM, INPUT_A, INPUT_B, OUTPUT (SCRATCH slot unused) */ + int native_open; /* m16_native_open was attempted this run */ + int pb_replaced; /* m.pb_mem now points at the large pushbuffer */ + int c3; /* L2 flush and second marker are in the pushbuffer */ + volatile uint32_t *hmarker; /* NULL until build zeroes it; NULL again once SCRATCH is freed */ + volatile uint32_t *hmarker2; + volatile uint32_t *hsem; + uint32_t pb_words[BE_PB_CAP]; + size_t pb_len; + int pb_overflow; + int last_rc; /* raw driver code of the most recent callback */ + char text[OMEGA_GPU_ENGINE_DRV_TEXT_BYTES]; /* backend's own message, "" when none */ + OmegaBlackwellEngineRunInfo info; +} BeCtx; + +static BeCtx g_be; +static atomic_flag g_busy = ATOMIC_FLAG_INIT; + +static uint64_t now_ns(void) +{ + struct timespec t; + if (clock_gettime(CLOCK_MONOTONIC, &t) != 0) return 0u; + return (uint64_t)t.tv_sec * 1000000000ull + (uint64_t)t.tv_nsec; +} + +/* Bounded copy that never reads past a NUL and always terminates. */ +static void copy_text(char *dst, size_t cap, const char *src) +{ + size_t i = 0; + if (cap == 0) return; + while (i + 1u < cap && src[i] != '\0') { + dst[i] = src[i]; + i++; + } + dst[i] = '\0'; +} + +static void note(BeCtx *c, const char *msg) +{ + copy_text(c->text, sizeof c->text, msg); +} + +/* Start of every callback that can fail: forget the previous callback's code and text. */ +static void begin(BeCtx *c) +{ + c->last_rc = 0; + c->text[0] = '\0'; +} + +/* ---- allocation helpers ------------------------------------------------ */ + +/* Allocates and checks one device buffer. The post-allocation checks (CPU + * mapping present, size at least what was asked, 256-byte aligned GPU address) + * come from ASTRA checked_alloc. Returns 0 or non-zero. */ +static int alloc_checked(BeCtx *c, uint64_t bytes, NvrmMem *m) +{ + int rc; + memset(m, 0, sizeof *m); + /* GB10: the CPU rewrites pushbuffers and reads markers/outputs; GPU-cacheable system memory is not + * coherent with CPU mappings (nvos.h:1117-1118). All engine buffers are GPU-uncached until the + * allocator default is flipped (hive idea I36). */ + rc = nvrm_alloc_gpu_uncached(&c->m.rm, bytes, m); + if (rc != 0) { + c->last_rc = rc; + memset(m, 0, sizeof *m); + return rc; + } + if (!m->cpu || m->size < bytes || (m->va & 255u) != 0) { + note(c, "allocation failed its own checks (CPU mapping, size or 256-byte alignment)"); + (void)nvrm_free(&c->m.rm, m); + memset(m, 0, sizeof *m); + return -1; + } + return 0; +} + +/* Page rounding with a 0x1000 minimum, SUB@676f16f lines 55-56. Non-zero if bytes is 0 or overflows. */ +static int round_pages(size_t bytes, uint64_t *out) +{ + uint64_t v; + if (bytes == 0 || (uint64_t)bytes > UINT64_MAX - (BE_PAGE - 1u)) return -1; + v = ((uint64_t)bytes + (BE_PAGE - 1u)) & ~(uint64_t)(BE_PAGE - 1u); + if (v < BE_PAGE) v = BE_PAGE; + *out = v; + return 0; +} + +static NvrmMem *role_mem(BeCtx *c, int role) +{ + if (role < (int)OMEGA_GPU_BUF_PROGRAM || role >= (int)OMEGA_GPU_BUF_ROLE_COUNT) return NULL; + return &c->buf[role]; +} + +/* Frees the four SCRATCH buffers, every one even if an earlier one fails. + * Returns 0, or the first non-zero nvrm_free code. */ +static int release_scratch(BeCtx *c) +{ + NvrmMem *parts[4]; + int first = 0; + size_t i; + parts[0] = &c->qmd; + parts[1] = &c->marker; + parts[2] = &c->cbank; + parts[3] = &c->pb; + /* The marker and semaphore words live in these buffers: stop reading them first. */ + c->hmarker = NULL; + c->hmarker2 = NULL; + c->hsem = NULL; + for (i = 0; i < 4u; i++) { + int rc = nvrm_free(&c->m.rm, parts[i]); /* a zeroed NvrmMem is a no-op (nvrm.h) */ + if (rc != 0 && first == 0) first = rc; + } + if (c->pb_replaced) { + memset(&c->m.pb_mem, 0, sizeof c->m.pb_mem); + c->pb_replaced = 0; + } + return first; +} + +/* ---- pushbuffer helpers ------------------------------------------------ */ + +static void pb_put(BeCtx *c, uint32_t w) +{ + if (c->pb_len < BE_PB_CAP) c->pb_words[c->pb_len++] = w; + else c->pb_overflow = 1; +} + +static void pb_copy(BeCtx *c, const uint32_t *w, size_t n) +{ + size_t i; + for (i = 0; i < n; i++) pb_put(c, w[i]); +} + +/* Compute class and engine setup methods, SUB@676f16f lines 12-16 (also in divsqrt as SETUP). */ +static const uint32_t BE_SETUP_WORDS[18] = { + 0x20012061, 0x0000cec0, 0x20012092, 0x00000001, 0x200120a8, 0x0000000f, 0x2001255d, 0x00000003, + 0x2001255e, 0x20000000, 0x2001255f, 0x000fffff, 0x20012557, 0x00000003, 0x20012558, 0x22000000, + 0x20012559, 0x00000000, +}; + +/* ---- callbacks --------------------------------------------------------- */ + +/* Opens the RM client. Resets every bit of the context first so an open + * failure never reports values from an earlier run (ASTRA did memset(&ctx) at + * the same point). The busy flag stays set until be_close. */ +static int be_open_device(void *ctx) +{ + BeCtx *c = (BeCtx *)ctx; + int rc; + if (atomic_flag_test_and_set(&g_busy)) return -1; /* another run is active; touch nothing */ + memset(c, 0, sizeof *c); + c->native_open = 1; + rc = m16_native_open(&c->m); /* SUB@676f16f line 45 */ + if (rc != 0) { + c->last_rc = rc; + atomic_flag_clear(&g_busy); /* native open already cleaned up after itself (m16_native.c:15-21) */ + return rc; + } + return 0; +} + +static int be_create_channel(void *ctx) +{ + BeCtx *c = (BeCtx *)ctx; + int rc; + begin(c); + rc = m16_native_create_channel(&c->m); /* SUB@676f16f line 46 */ + c->last_rc = rc; + return rc; +} + +static int be_alloc(void *ctx, int role, size_t bytes) +{ + BeCtx *c = (BeCtx *)ctx; + NvrmMem *m; + uint64_t sz; + begin(c); + if (role == (int)OMEGA_GPU_BUF_SCRATCH) { + if (alloc_checked(c, BE_PB_BYTES, &c->pb) != 0 || + alloc_checked(c, BE_PAGE, &c->cbank) != 0 || + alloc_checked(c, BE_PAGE, &c->marker) != 0 || + alloc_checked(c, BE_QMD_BYTES, &c->qmd) != 0) { + int rc = c->last_rc ? c->last_rc : -1; + int saved_errno = errno; /* the core reads errno right after this callback */ + char keep[OMEGA_GPU_ENGINE_DRV_TEXT_BYTES]; + copy_text(keep, sizeof keep, c->text); + (void)release_scratch(c); /* the core does not free a role whose alloc failed */ + copy_text(c->text, sizeof c->text, keep); + c->last_rc = rc; + errno = saved_errno; + return rc; + } + c->m.pb_mem = c->pb; /* the unified method stream needs the large ring, SUB@676f16f lines 49-51 */ + c->pb_replaced = 1; + return 0; + } + m = role_mem(c, role); + if (!m) { + note(c, "alloc: unknown buffer role"); + return -1; + } + if (round_pages(bytes, &sz) != 0) { + note(c, "alloc: byte count is zero or too large"); + return -1; + } + return alloc_checked(c, sz, m); +} + +static int be_copy_in(void *ctx, int role, const void *src, size_t bytes) +{ + BeCtx *c = (BeCtx *)ctx; + NvrmMem *m; + begin(c); + m = role_mem(c, role); + if (!m || !m->cpu || !src || (uint64_t)bytes > m->size) { + note(c, "copy_in: bad role, buffer or length"); + return -1; + } + memcpy(m->cpu, src, bytes); /* SUB@676f16f lines 74-76 (code via the encoder, inputs via memcpy) */ + return 0; +} + +static int be_fill_poison(void *ctx, const uint32_t *words, size_t count) +{ + BeCtx *c = (BeCtx *)ctx; + NvrmMem *out = &c->buf[OMEGA_GPU_BUF_OUTPUT]; + begin(c); + if (!out->cpu || !words || (uint64_t)count * 4u > out->size) { + note(c, "fill_poison: no output buffer or length too large"); + return -1; + } + memcpy(out->cpu, words, count * 4u); /* SUB@676f16f lines 77-80: pre-fill the device output */ + return 0; +} + +/* Descriptors, QMDs and the whole pushbuffer. Lifted from SUB@676f16f lines + * 83-194 and, for the C3 tail, divsqrt lines 1145-1152. Zeroes the marker and + * semaphore words and issues dsb sy (SUB@676f16f lines 124-128). Does not submit. */ +static int be_build(void *ctx, const OmegaGpuJob *job) +{ + BeCtx *c = (BeCtx *)ctx; + const NvrmMem *code = &c->buf[OMEGA_GPU_BUF_PROGRAM]; + const NvrmMem *a = &c->buf[OMEGA_GPU_BUF_INPUT_A]; + const NvrmMem *b = &c->buf[OMEGA_GPU_BUF_INPUT_B]; + const NvrmMem *out = &c->buf[OMEGA_GPU_BUF_OUTPUT]; + uint32_t cbank_data[OMEGA_BW_CBANK_DRIVER_WORDS]; + uint32_t cbank_args[OMEGA_BW_CBANK_ARGS_WORDS]; + uint32_t qmd0_words[OMEGA_BW_QMD_WORDS]; + uint32_t qmd1_words[OMEGA_BW_QMD_WORDS]; + OmegaBlackwellQmdConfig cfg; + uint64_t qmd0_va, qmd1_va, sem_va, marker_va, marker2_va, need; + uint32_t n; + int rc; + + begin(c); + if (!job || job->layout != (int)OMEGA_GPU_LAYOUT_VECTOR_1D) { + note(c, "build: only the VECTOR_1D layout is supported"); + return -1; + } + n = job->element_count; + /* (n + 63) / 64 must not overflow; ASTRA refused n above UINT32_MAX - 63 as well. */ + if (n == 0 || n > UINT32_MAX - 63u) { + note(c, "build: element count is zero or too large"); + return -1; + } + need = (uint64_t)n * 4u; + if (!code->cpu || !a->cpu || !b->cpu || !out->cpu || !c->pb.cpu || !c->cbank.cpu || + !c->marker.cpu || !c->qmd.cpu || a->size < need || b->size < need || out->size < need) { + note(c, "build: a buffer is missing or too small"); + return -1; + } + c->c3 = (job->flags & OMEGA_GPU_ENGINE_FLAG_NO_C3) == 0; + + qmd0_va = c->qmd.va; + qmd1_va = c->qmd.va + 0x1000; + sem_va = c->qmd.va + BE_SEM_OFFSET; + marker_va = c->marker.va; + marker2_va = c->marker.va + BE_MARKER2_OFFSET; + + memset(&cfg, 0, sizeof cfg); + cfg.code_va = code->va; + cfg.cbank_va = c->cbank.va; + cfg.scratch_va = c->qmd.va + 0x4000; /* SUB@676f16f line 100 */ + cfg.sem_va = sem_va; + cfg.qmd0_va = qmd0_va; + cfg.qmd1_va = qmd1_va; + cfg.num_elements = n; + cfg.threads_per_block = 64; + cfg.grid_width = (n + 63u) / 64u; + + /* The builders return 0 on success (src/omega_blackwell_qmd.c); SUB@676f16f + * ignored their codes, ASTRA checked them. Checked here. */ + rc = omega_blackwell_build_cbank_driver(cbank_data, c->cbank.va); + if (rc == 0) rc = omega_blackwell_build_cbank_args(cbank_args, a->va, b->va, out->va, n); + if (rc == 0) rc = omega_blackwell_build_qmd0(qmd0_words, qmd0_va, qmd1_va); + if (rc == 0) rc = omega_blackwell_build_qmd1(qmd1_words, &cfg); + if (rc == 0) rc = omega_blackwell_verify_qmd_invariants(qmd1_words); /* SUB@676f16f line 118 */ + if (rc != 0) { + c->last_rc = rc; + note(c, "build: a descriptor builder or the QMD invariant check refused"); + return rc; + } + /* Extra QMD1 checks from ASTRA: release enable (word 9), the release + * semaphore address and the DONE value (words 15-17), and the memory + * barrier flags (word 19). The words come from src/omega_blackwell_qmd.c + * lines 81, 93-98. */ + if (qmd1_words[9] != 3u || qmd1_words[15] != (uint32_t)sem_va || + qmd1_words[16] != (uint32_t)(sem_va >> 32) || + qmd1_words[17] != OMEGA_BW_SEMAPHORE_INTERMEDIATE_DONE || + qmd1_words[19] != 0x81810000u) { + note(c, "build: QMD1 release words do not match the expected layout"); + return -1; + } + + memcpy(c->cbank.cpu, cbank_data, sizeof cbank_data); /* SUB@676f16f line 112 */ + memcpy((uint8_t *)c->cbank.cpu + 0x380, cbank_args, sizeof cbank_args); /* line 113 */ + memcpy(c->qmd.cpu, qmd0_words, sizeof qmd0_words); /* line 120 */ + memcpy((uint8_t *)c->qmd.cpu + 0x1000, qmd1_words, sizeof qmd1_words); /* line 121 */ + + /* Initialise the synchronisation words in coherent memory (lines 124-128; + * divsqrt also zeroes the second marker, line 1113). Then dsb sy so the + * zeros are visible to the chip before the doorbell. */ + c->hsem = (volatile uint32_t *)((uint8_t *)c->qmd.cpu + BE_SEM_OFFSET); + c->hmarker = (volatile uint32_t *)c->marker.cpu; + c->hmarker2 = (volatile uint32_t *)((uint8_t *)c->marker.cpu + BE_MARKER2_OFFSET); + *c->hsem = 0; + *c->hmarker = 0; + *c->hmarker2 = 0; + if (!c->c3) c->hmarker2 = NULL; /* never waited for, never reported */ + __asm__ volatile("dsb sy" ::: "memory"); + + /* ---- unified pushbuffer, SUB@676f16f lines 130-195 ---- */ + c->pb_len = 0; + c->pb_overflow = 0; + + /* 1. setup words (18) */ + pb_copy(c, BE_SETUP_WORDS, 18u); + + /* 2. driver constant bank upload (224 words by DMA) */ + pb_put(c, nvrm_mthd(1, 0x0188, 2)); + pb_put(c, (uint32_t)(c->cbank.va >> 32)); + pb_put(c, (uint32_t)c->cbank.va); + pb_put(c, nvrm_mthd(1, 0x0180, 2)); + pb_put(c, 0x00000380); + pb_put(c, 0x00000001); + pb_put(c, nvrm_mthd(1, 0x01b0, 1)); + pb_put(c, 0x00000041); + pb_put(c, (uint32_t)((224 << 16) | (1 << 13) | (0x01b4 >> 2) | (6u << 28))); + pb_copy(c, cbank_data, 224u); + + /* 3. kernel argument upload (7 words by DMA) */ + pb_put(c, nvrm_mthd(1, 0x0188, 2)); + pb_put(c, (uint32_t)((c->cbank.va + 0x380) >> 32)); + pb_put(c, (uint32_t)(c->cbank.va + 0x380)); + pb_put(c, nvrm_mthd(1, 0x0180, 2)); + pb_put(c, 0x0000001c); + pb_put(c, 0x00000001); + pb_put(c, nvrm_mthd(1, 0x01b0, 1)); + pb_put(c, 0x00000041); + pb_put(c, (uint32_t)((7 << 16) | (1 << 13) | (0x01b4 >> 2) | (6u << 28))); + pb_copy(c, cbank_args, 7u); + + /* 4. inline QMD 0 (2 address words + 96 QMD words) */ + pb_put(c, (uint32_t)((98 << 16) | (1 << 13) | (0x0318 >> 2) | (2u << 28))); + pb_put(c, (1u << 30) | (uint32_t)((qmd0_va >> 40) & 0x1ff)); + pb_put(c, (uint32_t)(qmd0_va >> 8)); + pb_copy(c, qmd0_words, 96u); + + /* 5. intermediate semaphore initial value (one word by DMA) */ + pb_put(c, nvrm_mthd(1, 0x0188, 2)); + pb_put(c, (uint32_t)(sem_va >> 32)); + pb_put(c, (uint32_t)sem_va); + pb_put(c, nvrm_mthd(1, 0x0180, 2)); + pb_put(c, 0x00000004); + pb_put(c, 0x00000001); + pb_put(c, nvrm_mthd(1, 0x01b0, 1)); + pb_put(c, 0x00000041); + pb_put(c, (uint32_t)((1 << 16) | (1 << 13) | (0x01b4 >> 2) | (6u << 28))); + pb_put(c, OMEGA_BW_SEMAPHORE_INTERMEDIATE_INIT); + + /* 6. inline QMD 1 */ + pb_put(c, (uint32_t)((98 << 16) | (1 << 13) | (0x0318 >> 2) | (2u << 28))); + pb_put(c, (1u << 30) | (uint32_t)((qmd1_va >> 40) & 0x1ff)); + pb_put(c, (uint32_t)(qmd1_va >> 8)); + pb_copy(c, qmd1_words, 96u); + + /* 7. subchannel 0 completion release (RELEASE | WFI) */ + pb_put(c, nvrm_mthd(0, 0x005c, 5)); + pb_put(c, (uint32_t)marker_va); + pb_put(c, (uint32_t)(marker_va >> 32)); + pb_put(c, OMEGA_BW_MARKER_COMPLETION_PAYLOAD); + pb_put(c, 0); + pb_put(c, 0x1u | (1u << 20)); + + /* 8. C3, divsqrt lines 1145-1152 (NVC96F_MEM_OP_A..D = 0x28..0x34, operation + * L2_FLUSH_DIRTY 0x10 in bits 31:27; third_party/nvidia-open-580.173.02/src/ + * common/sdk/nvidia/inc/class/clc96f.h:36-73): flush the L2, then a second + * WFI release at marker page + 0x10 that the host waits for before readback. */ + if (c->c3) { + pb_put(c, nvrm_mthd(0, 0x0028, 4)); + pb_put(c, 0); + pb_put(c, 0); + pb_put(c, 0); + pb_put(c, 0x10u << 27); + pb_put(c, nvrm_mthd(0, 0x005c, 5)); + pb_put(c, (uint32_t)marker2_va); + pb_put(c, (uint32_t)(marker2_va >> 32)); + pb_put(c, BE_MARKER2_PAYLOAD); + pb_put(c, 0); + pb_put(c, 0x1u | (1u << 20)); + } + + if (c->pb_overflow) { + note(c, "build: pushbuffer exceeded its word capacity"); + return -1; + } + return 0; +} + +/* Submit methods to the GPFIFO ring and ring the doorbell, SUB@676f16f lines + * 198-200. m16_native_submit_methods rings only after the enqueue succeeded + * (physics/m16/m16_native.c:76-84), so a non-zero return means the doorbell + * was not rung: a known failure, not an uncertain completion. */ +static int be_submit(void *ctx) +{ + BeCtx *c = (BeCtx *)ctx; + int rc; + begin(c); + if (c->pb_len == 0) { + note(c, "submit: nothing was built"); + return -1; + } + c->info.launch_ns = now_ns(); /* SUB@676f16f line 199 */ + rc = m16_native_submit_methods(&c->m, c->pb_words, c->pb_len); + c->last_rc = rc; + return rc; +} + +/* Waits for one coherent word. m16_native_wait_marker is a ">=" serial compare + * (physics/m16/m16_native.c:93-108), so an overshoot also returns 0; ASTRA + * checked_alloc/checked_wait therefore re-checked equality, kept here and + * reported as UNKNOWN_STATE (the device wrote a value we cannot classify). + * Returns 0, OMEGA_GPU_BACKEND_TIMEOUT, OMEGA_GPU_BACKEND_UNKNOWN_STATE or a + * driver fault. *snap always receives the last value read. */ +static int wait_word(BeCtx *c, volatile uint32_t *w, uint32_t want, uint64_t ms, uint32_t *snap) +{ + int rc; + begin(c); + if (!w) { + note(c, "wait: the word is not mapped (wait before build or after free)"); + return -2; + } + rc = m16_native_wait_marker(w, want, ms); + *snap = *w; + if (rc != 0) { + c->last_rc = rc; + return rc == -1 ? OMEGA_GPU_BACKEND_TIMEOUT : -2; + } + if (*snap != want) { + (void)snprintf(c->text, sizeof c->text, "observed 0x%08x, wanted 0x%08x", *snap, want); + return OMEGA_GPU_BACKEND_UNKNOWN_STATE; + } + return 0; +} + +static int be_wait_marker(void *ctx, uint64_t timeout_ms) +{ + BeCtx *c = (BeCtx *)ctx; + int rc = wait_word(c, c->hmarker, OMEGA_BW_MARKER_COMPLETION_PAYLOAD, timeout_ms, &c->info.marker); + if (rc == 0) c->info.marker_done_ns = now_ns(); /* SUB@676f16f line 204 */ + return rc; +} + +static int be_wait_marker2(void *ctx, uint64_t timeout_ms) +{ + BeCtx *c = (BeCtx *)ctx; + return wait_word(c, c->hmarker2, BE_MARKER2_PAYLOAD, timeout_ms, &c->info.marker2); +} + +/* The QMD's own release semaphore, written after the grid finishes (divsqrt + * lines 1163-1169). SUB@676f16f only compared it once (line 207); now it is waited for. */ +static int be_wait_release_semaphore(void *ctx, uint64_t timeout_ms) +{ + BeCtx *c = (BeCtx *)ctx; + return wait_word(c, c->hsem, OMEGA_BW_SEMAPHORE_INTERMEDIATE_DONE, timeout_ms, + &c->info.semaphore); +} + +/* dsb sy before readback, divsqrt line 1171. Completion is already known here. */ +static int be_barrier(void *ctx, uint64_t timeout_ms) +{ + BeCtx *c = (BeCtx *)ctx; + (void)timeout_ms; + begin(c); + __asm__ volatile("dsb sy" ::: "memory"); + return 0; +} + +static int be_copy_out(void *ctx, void *dst, size_t bytes) +{ + BeCtx *c = (BeCtx *)ctx; + const NvrmMem *out = &c->buf[OMEGA_GPU_BUF_OUTPUT]; + begin(c); + if (!out->cpu || !dst || (uint64_t)bytes > out->size) { + note(c, "copy_out: no output buffer or length too large"); + return -1; + } + memcpy(dst, out->cpu, bytes); /* SUB@676f16f line 210 */ + return 0; +} + +/* Driver code, driver text and the sync words as they are right now. Words are + * read only while SCRATCH is still mapped (hmarker and friends are NULL before + * build and after SCRATCH is freed), so this is safe during cleanup. */ +static void be_diagnostics(void *ctx, OmegaGpuBackendDiag *d) +{ + BeCtx *c = (BeCtx *)ctx; + d->drv_rc = c->last_rc; + if (c->text[0] != '\0') copy_text(d->drv_text, sizeof d->drv_text, c->text); + else if (c->native_open) copy_text(d->drv_text, sizeof d->drv_text, c->m.rm.err); + if (c->hmarker) { + d->marker = *c->hmarker; + d->sync_valid |= OMEGA_GPU_SYNC_MARKER; + } + if (c->hmarker2) { + d->marker2 = *c->hmarker2; + d->sync_valid |= OMEGA_GPU_SYNC_MARKER2; + } + if (c->hsem) { + d->semaphore[0] = *c->hsem; + d->sync_valid |= OMEGA_GPU_SYNC_SEMAPHORE; + } +} + +/* Real nvrm_free per buffer. SUB@676f16f never freed (m16_native_close frees + * everything left, nvrm.c:757-766); nvrm_free before close is already used by + * src/omega_accelerator_world.c (A1b scout, section 4). DIVERGENCE, chip + * behaviour of free-then-close for this launcher is UNVERIFIED (confidence 70%). */ +static int be_free_buf(void *ctx, int role) +{ + BeCtx *c = (BeCtx *)ctx; + NvrmMem *m; + int rc; + begin(c); + if (role == (int)OMEGA_GPU_BUF_SCRATCH) { + rc = release_scratch(c); + c->last_rc = rc; + return rc; + } + m = role_mem(c, role); + if (!m) { + note(c, "free: unknown buffer role"); + return -1; + } + rc = nvrm_free(&c->m.rm, m); + c->last_rc = rc; + return rc; +} + +static int be_close(void *ctx) +{ + BeCtx *c = (BeCtx *)ctx; + int rc; + begin(c); + c->hmarker = NULL; + c->hmarker2 = NULL; + c->hsem = NULL; + rc = m16_native_close(&c->m); /* SUB@676f16f line 225 */ + c->last_rc = rc; + atomic_flag_clear(&g_busy); + return rc; +} + +static const OmegaGpuBackend g_backend = { + &g_be, + be_open_device, + be_create_channel, + be_alloc, + be_copy_in, + be_fill_poison, + be_build, + be_submit, + be_wait_marker, + be_wait_marker2, + be_wait_release_semaphore, + be_barrier, + be_copy_out, + be_diagnostics, + be_free_buf, + be_close, +}; + +const OmegaGpuBackend *omega_blackwell_engine_backend(void) +{ + return &g_backend; +} + +void omega_blackwell_engine_run_info(OmegaBlackwellEngineRunInfo *out) +{ + if (out) *out = g_be.info; +} diff --git a/src/omega_blackwell_engine.h b/src/omega_blackwell_engine.h new file mode 100644 index 000000000..4f94ca6c3 --- /dev/null +++ b/src/omega_blackwell_engine.h @@ -0,0 +1,55 @@ +/* + * Omega GPU Engine, Blackwell GB10 backend (cut A3b1). + * + * This module is ONLY the device side of the engine. The public entry point is + * omega_gpu_execute in src/omega_gpu_engine.c (the A3a core); this file supplies + * the backend function table that the core drives (OmegaGpuBackend, declared in + * src/omega_gpu_engine.h). It does not define any job, result or execute type. + * + * Origin: the device sequence (open, channel, allocations, descriptor and QMD + * build, pushbuffer, submit, waits, copy-out, close) was seeded from the first + * cut by GPT-6 Astra (branch fix/omega-gpu-engine-first-cut, commit 21392ee, + * src/omega_blackwell_engine.c) and from omega_blackwell_execute_vector as it + * stood at 676f16f. See docs/numeric/OMEGA_GPU_ENGINE.md, section Origin. + * + * Usage: + * omega_gpu_engine_set_backend(omega_blackwell_engine_backend()); + * rc = omega_gpu_execute(&job, &result); + * Only the VECTOR_1D layout (two inputs, one output, 64 threads per block) is + * supported. One run at a time: the backend keeps one process-wide context and + * a second open while a run is active is refused as DEVICE_OPEN. + * + * Observed values on success: the core only copies driver diagnostics on a + * failure, and the core frees and closes the device (which unmaps the marker + * and semaphore memory) before it returns. So the backend snapshots what it saw + * inside its own wait callbacks, and omega_blackwell_engine_run_info returns + * that snapshot after a run. The vector wrapper in omega_blackwell_submit.c + * uses it to fill completion_marker, intermediate_semaphore and the timestamps. + * + * STATUS: DRAFT. Host NOT_RUN, chip NOT_RUN. Nothing here has been compiled or + * executed by its author. + */ +#ifndef OMEGA_BLACKWELL_ENGINE_H +#define OMEGA_BLACKWELL_ENGINE_H + +#include "omega_gpu_engine.h" + +#include <stdint.h> + +/* What the backend observed during the most recent run (valid after the run). */ +typedef struct { + uint64_t launch_ns; /* CLOCK_MONOTONIC, just before the pushbuffer submit; 0 if never submitted */ + uint64_t marker_done_ns; /* CLOCK_MONOTONIC, just after the first marker wait succeeded; 0 if it did not */ + uint32_t marker; /* first marker word as observed by the wait (0x44444444 on success) */ + uint32_t marker2; /* second marker word as observed (0x46464646 on success, 0 with NO_C3) */ + uint32_t semaphore; /* QMD release semaphore word as observed (6 on success) */ +} OmegaBlackwellEngineRunInfo; + +/* The process-wide Blackwell backend table. Never NULL. The ctx inside it is + * the backend's static context; callers must not touch it. */ +const OmegaGpuBackend *omega_blackwell_engine_backend(void); + +/* Copies the snapshot of the most recent run into *out. Reset at every open. */ +void omega_blackwell_engine_run_info(OmegaBlackwellEngineRunInfo *out); + +#endif diff --git a/src/omega_blackwell_gates.c b/src/omega_blackwell_gates.c index 29f3bdb33..fbc20f2a1 100644 --- a/src/omega_blackwell_gates.c +++ b/src/omega_blackwell_gates.c @@ -1165,6 +1165,8 @@ static bool test_m18_gate18_receipt(void) { "src/omega_blackwell_qmd.c", "src/omega_blackwell_submit.h", "src/omega_blackwell_submit.c", + "src/omega_blackwell_engine.h", + "src/omega_blackwell_engine.c", "src/omega_blackwell_gates.h", "src/omega_blackwell_gates.c", "tools/omegatool.c", diff --git a/src/omega_blackwell_submit.c b/src/omega_blackwell_submit.c index e1e32199a..79780e49e 100644 --- a/src/omega_blackwell_submit.c +++ b/src/omega_blackwell_submit.c @@ -2,6 +2,8 @@ #include "omega_blackwell_submit.h" #include "omega_blackwell_qmd.h" #include "omega_blackwell_encoder.h" +#include "omega_blackwell_engine.h" +#include "omega_gpu_engine.h" #include "m16_native.h" #include <stdio.h> #include <stdlib.h> @@ -40,189 +42,90 @@ int omega_blackwell_execute_vector(const OmegaVectorSpec *spec, exec_info->zero_cuda_symbols = (omega_blackwell_verify_zero_cuda_symbols(NULL) == 0); exec_info->zero_libcuda_runtime = (omega_blackwell_verify_zero_libcuda_runtime() == 0); } - - M16NativeContext ctx; - if (m16_native_open(&ctx) != 0) { return -1; } - if (m16_native_create_channel(&ctx) != 0) { m16_native_close(&ctx); return -1; } - - /* Allocate larger pushbuffer ring for unified method stream */ - NvrmMem large_pb; - if (nvrm_alloc(&ctx.rm, 0x10000, &large_pb) != 0) { m16_native_close(&ctx); return -1; } - ctx.pb_mem = large_pb; - - /* Allocate device-visible UVM buffers */ - NvrmMem code_mem, cbank_mem, a_mem, b_mem, c_mem, marker_mem, qmd_mem; - size_t vector_bytes = (n * sizeof(uint32_t) + 0xFFFULL) & ~0xFFFULL; - if (vector_bytes < 0x1000) vector_bytes = 0x1000; - - if (nvrm_alloc(&ctx.rm, 0x1000, &code_mem) != 0) { m16_native_close(&ctx); return -1; } - if (nvrm_alloc(&ctx.rm, 0x1000, &cbank_mem) != 0) { m16_native_close(&ctx); return -1; } - if (nvrm_alloc(&ctx.rm, vector_bytes, &a_mem) != 0) { m16_native_close(&ctx); return -1; } - if (nvrm_alloc(&ctx.rm, vector_bytes, &b_mem) != 0) { m16_native_close(&ctx); return -1; } - if (nvrm_alloc(&ctx.rm, vector_bytes, &c_mem) != 0) { m16_native_close(&ctx); return -1; } - if (nvrm_alloc(&ctx.rm, 0x1000, &marker_mem) != 0) { m16_native_close(&ctx); return -1; } - if (nvrm_alloc(&ctx.rm, 0x10000, &qmd_mem) != 0) { m16_native_close(&ctx); return -1; } - - - /* Emit machine code into code_mem */ + /* This executor no longer talks to the device itself. It builds the program + * and the poison words on the host, hands the job to omega_gpu_execute with + * the Blackwell backend (src/omega_blackwell_engine.c), and then does the + * arithmetic check here. The engine only checks that no output word is still + * equal to its poison word; it never judges the math. */ + + /* Program bytes. Capacity 0x1000 as before (the code page was 0x1000). */ + uint8_t code[0x1000]; size_t encoded_len = 0; - if (omega_blackwell_encode_vecadd(code_mem.cpu, code_mem.size, &encoded_len) != 0) { - m16_native_close(&ctx); - return -1; - } - - /* Populate input buffers A, B and initialize C with poison */ - memcpy(a_mem.cpu, h_a, n * sizeof(uint32_t)); - memcpy(b_mem.cpu, h_b, n * sizeof(uint32_t)); - uint32_t *c_dev = (uint32_t *)c_mem.cpu; + if (omega_blackwell_encode_vecadd(code, sizeof(code), &encoded_len) != 0 || encoded_len == 0) return -1; + + /* Poison words. The expected output word is computed here, on the host, + * before launch: expected[i] = (a[i] + b[i]) mod 2^32 (the same sum + * omega_vector_verify_oracle uses). The poison word is the bit complement of + * it. A word and its bit complement always differ, so a poison word can + * never equal the expected output word at the same position. If the device + * leaves a word unwritten the engine sees poison and reports + * OUTPUT_UNCHANGED. (This replaces the old constant OMEGA_VECTOR_POISON_VALUE, + * which could in principle collide with a legitimate sum.) */ + uint32_t *poison = (uint32_t *)malloc((size_t)n * sizeof(uint32_t)); + if (!poison) return -1; for (size_t i = 0; i < n; i++) { - c_dev[i] = OMEGA_VECTOR_POISON_VALUE; + poison[i] = ~(uint32_t)(h_a[i] + h_b[i]); } - /* Build driver cbank data and kernel arguments */ - uint32_t cbank_data[OMEGA_BW_CBANK_DRIVER_WORDS]; - omega_blackwell_build_cbank_driver(cbank_data, cbank_mem.va); - - uint32_t cbank_args[OMEGA_BW_CBANK_ARGS_WORDS]; - omega_blackwell_build_cbank_args(cbank_args, a_mem.va, b_mem.va, c_mem.va, n); - - /* Direct coherent CPU copy into cbank_mem */ - memcpy(cbank_mem.cpu, cbank_data, sizeof(cbank_data)); - memcpy((uint8_t *)cbank_mem.cpu + 0x380, cbank_args, sizeof(cbank_args)); - - /* Configure and build QMD 0 & QMD 1 */ - uint64_t qmd0_va = qmd_mem.va; - uint64_t qmd1_va = qmd_mem.va + 0x1000; - uint64_t sem_va = qmd_mem.va + 0x2000; - uint64_t scratch_va = qmd_mem.va + 0x4000; - - OmegaBlackwellQmdConfig qmd_cfg = { - .code_va = code_mem.va, - .cbank_va = cbank_mem.va, - .scratch_va = scratch_va, - .sem_va = sem_va, - .qmd0_va = qmd0_va, - .qmd1_va = qmd1_va, - .num_elements = n, - .threads_per_block = 64, - .grid_width = (n + 63) / 64 - }; - if (qmd_cfg.grid_width == 0) qmd_cfg.grid_width = 1; - - uint32_t qmd0_words[OMEGA_BW_QMD_WORDS]; - uint32_t qmd1_words[OMEGA_BW_QMD_WORDS]; - omega_blackwell_build_qmd0(qmd0_words, qmd0_va, qmd1_va); - omega_blackwell_build_qmd1(qmd1_words, &qmd_cfg); - - /* Verify QMD structural invariants before submission */ - if (omega_blackwell_verify_qmd_invariants(qmd1_words) != 0) { m16_native_close(&ctx); return -1; } - - memcpy(qmd_mem.cpu, qmd0_words, sizeof(qmd0_words)); - memcpy((uint8_t *)qmd_mem.cpu + 0x1000, qmd1_words, sizeof(qmd1_words)); - - /* Initialize synchronization semaphores in coherent memory */ - volatile uint32_t *hsem = (volatile uint32_t *)((uint8_t *)qmd_mem.cpu + 0x2000); - volatile uint32_t *hmarker = (volatile uint32_t *)marker_mem.cpu; - *hsem = 0; - *hmarker = 0; - __asm__ volatile("dsb sy" ::: "memory"); - - /* Assemble unified pushbuffer (481 words) */ - uint32_t pb[1024]; - size_t pb_len = 0; - - /* 1. Setup words (18 words) */ - memcpy(&pb[pb_len], SETUP_WORDS, sizeof(SETUP_WORDS)); - pb_len += sizeof(SETUP_WORDS) / 4; - - /* 2. Cbank driver data upload (224 words via DMA) */ - pb[pb_len++] = nvrm_mthd(1, 0x0188, 2); - pb[pb_len++] = (uint32_t)(cbank_mem.va >> 32); - pb[pb_len++] = (uint32_t)cbank_mem.va; - pb[pb_len++] = nvrm_mthd(1, 0x0180, 2); - pb[pb_len++] = 0x00000380; - pb[pb_len++] = 0x00000001; - pb[pb_len++] = nvrm_mthd(1, 0x01b0, 1); - pb[pb_len++] = 0x00000041; - pb[pb_len++] = (224 << 16) | (1 << 13) | (0x01b4 >> 2) | (6u << 28); - memcpy(&pb[pb_len], cbank_data, 224 * 4); - pb_len += 224; - - /* 3. Kernel args upload (7 words via DMA) */ - pb[pb_len++] = nvrm_mthd(1, 0x0188, 2); - pb[pb_len++] = (uint32_t)((cbank_mem.va + 0x380) >> 32); - pb[pb_len++] = (uint32_t)(cbank_mem.va + 0x380); - pb[pb_len++] = nvrm_mthd(1, 0x0180, 2); - pb[pb_len++] = 0x0000001c; - pb[pb_len++] = 0x00000001; - pb[pb_len++] = nvrm_mthd(1, 0x01b0, 1); - pb[pb_len++] = 0x00000041; - pb[pb_len++] = (7 << 16) | (1 << 13) | (0x01b4 >> 2) | (6u << 28); - memcpy(&pb[pb_len], cbank_args, 7 * 4); - pb_len += 7; - - /* 4. Inline QMD 0 (98 words: 2 addr + 96 QMD words) */ - pb[pb_len++] = (98 << 16) | (1 << 13) | (0x0318 >> 2) | (2u << 28); - pb[pb_len++] = (1u << 30) | (uint32_t)((qmd0_va >> 40) & 0x1ff); - pb[pb_len++] = (uint32_t)(qmd0_va >> 8); - memcpy(&pb[pb_len], qmd0_words, 96 * 4); - pb_len += 96; - - /* 5. Intermediate semaphore upload (1 word = 5 via DMA) */ - pb[pb_len++] = nvrm_mthd(1, 0x0188, 2); - pb[pb_len++] = (uint32_t)(sem_va >> 32); - pb[pb_len++] = (uint32_t)sem_va; - pb[pb_len++] = nvrm_mthd(1, 0x0180, 2); - pb[pb_len++] = 0x00000004; - pb[pb_len++] = 0x00000001; - pb[pb_len++] = nvrm_mthd(1, 0x01b0, 1); - pb[pb_len++] = 0x00000041; - pb[pb_len++] = (1 << 16) | (1 << 13) | (0x01b4 >> 2) | (6u << 28); - pb[pb_len++] = OMEGA_BW_SEMAPHORE_INTERMEDIATE_INIT; - - /* 6. Inline QMD 1 (98 words: 2 addr + 96 QMD words) */ - pb[pb_len++] = (98 << 16) | (1 << 13) | (0x0318 >> 2) | (2u << 28); - pb[pb_len++] = (1u << 30) | (uint32_t)((qmd1_va >> 40) & 0x1ff); - pb[pb_len++] = (uint32_t)(qmd1_va >> 8); - memcpy(&pb[pb_len], qmd1_words, 96 * 4); - pb_len += 96; - - /* 7. Subchannel 0 completion release (WFI) */ - pb[pb_len++] = nvrm_mthd(0, 0x005c, 5); - pb[pb_len++] = (uint32_t)marker_mem.va; - pb[pb_len++] = (uint32_t)(marker_mem.va >> 32); - pb[pb_len++] = OMEGA_BW_MARKER_COMPLETION_PAYLOAD; - pb[pb_len++] = 0; - pb[pb_len++] = 0x1 | (1u << 20); // RELEASE | WFI - - /* Record timestamp and submit methods to hardware GPFIFO ring */ - uint64_t t_start = current_time_ns(); - if (m16_native_submit_methods(&ctx, pb, pb_len) != 0) { m16_native_close(&ctx); return -1; } - - /* Wait for hardware completion marker */ - if (m16_native_wait_marker(hmarker, OMEGA_BW_MARKER_COMPLETION_PAYLOAD, 5000) != 0) { m16_native_close(&ctx); return -1; } - uint64_t t_end = current_time_ns(); - - /* Validate intermediate semaphore updated to 6 */ - if (*hsem != OMEGA_BW_SEMAPHORE_INTERMEDIATE_DONE) { m16_native_close(&ctx); return -1; } + OmegaGpuJob job; + OmegaGpuResult res; + memset(&job, 0, sizeof(job)); + job.program = code; + job.program_len = encoded_len; + job.layout = OMEGA_GPU_LAYOUT_VECTOR_1D; + job.element_count = n; + job.input_a = h_a; + job.input_a_len = (size_t)n * sizeof(uint32_t); + job.input_b = h_b; + job.input_b_len = (size_t)n * sizeof(uint32_t); + job.output = h_c_out; + job.output_len = (size_t)n * sizeof(uint32_t); + job.poison = poison; + job.poison_count = n; + /* 5000 ms is the marker wait this executor always used (the old + * m16_native_wait_marker(..., 5000) call). The same limit is used for the + * second marker and the semaphore, which the old code did not wait for, and + * for the barrier, which has no wait. flags 0 means every protection ON: + * the L2 flush and second marker are now part of this launch. */ + job.timeouts.marker_ms = 5000; + job.timeouts.release_semaphore_ms = 5000; + job.timeouts.marker2_ms = 5000; + job.timeouts.visibility_ms = 5000; + job.flags = 0; + + omega_gpu_engine_set_backend(omega_blackwell_engine_backend()); + int erc = omega_gpu_execute(&job, &res); + free(poison); + if (erc != OMEGA_GPU_ENGINE_OK) { + fprintf(stderr, "GB10_VECTOR_FAIL failure=%s step=%s state=%s drv_rc=%d errno=%d text=\"%s\"\n", + omega_gpu_engine_failure_name(res.failure), omega_gpu_engine_step_name(res.failed_step), + omega_gpu_engine_state_name(res.last_state), res.drv_rc, res.err_no, res.drv_text); + return -1; + } - /* Copy device output back to host */ - memcpy(h_c_out, c_mem.cpu, n * sizeof(uint32_t)); + /* The engine returns only pass or fail. The marker, the semaphore and the + * timestamps come from what the backend observed in its own wait callbacks + * (the engine result carries them only on failure). Both values were + * already required by the backend; checked again here because the gates + * depend on them: marker payload 0x44444444, semaphore DONE (6). */ + OmegaBlackwellEngineRunInfo info; + omega_blackwell_engine_run_info(&info); + if (info.marker != OMEGA_BW_MARKER_COMPLETION_PAYLOAD) return -1; + if (info.semaphore != OMEGA_BW_SEMAPHORE_INTERMEDIATE_DONE) return -1; /* Verify against OMEGA semantic oracle */ size_t mismatch_idx = 0; int parity_res = omega_vector_verify_oracle(h_a, h_b, h_c_out, n, &mismatch_idx); if (exec_info) { - exec_info->launch_timestamp_ns = t_start; - exec_info->completion_timestamp_ns = t_end; - exec_info->elapsed_ns = (t_end > t_start) ? (t_end - t_start) : 0; - exec_info->completion_marker = *hmarker; - exec_info->intermediate_semaphore = *hsem; + exec_info->launch_timestamp_ns = info.launch_ns; + exec_info->completion_timestamp_ns = info.marker_done_ns; + exec_info->elapsed_ns = (info.marker_done_ns > info.launch_ns) ? (info.marker_done_ns - info.launch_ns) : 0; + exec_info->completion_marker = info.marker; + exec_info->intermediate_semaphore = info.semaphore; exec_info->parity_verified = (parity_res == 0); } - m16_native_close(&ctx); return parity_res; } diff --git a/src/omega_blackwell_submit.h b/src/omega_blackwell_submit.h index 24eccce11..eba680fde 100644 --- a/src/omega_blackwell_submit.h +++ b/src/omega_blackwell_submit.h @@ -44,7 +44,9 @@ typedef struct { bool zero_libcuda_runtime; } OmegaBlackwellMatMulExecution; -/* Execute vector addition on physical GB10 silicon through frozen M16 native submission */ +/* Execute vector addition on physical GB10 silicon. Since cut A3b1 (DRAFT, chip-unproven) the + * device sequence runs through omega_gpu_execute with the Blackwell backend in + * src/omega_blackwell_engine.c; this wrapper keeps the host oracle and the result fields. */ int omega_blackwell_execute_vector(const OmegaVectorSpec *spec, const OmegaBlackwellRealization *real, const uint32_t *h_a, diff --git a/src/omega_gpu_engine.c b/src/omega_gpu_engine.c index 4a30c2ff3..afdb878d1 100644 --- a/src/omega_gpu_engine.c +++ b/src/omega_gpu_engine.c @@ -1,15 +1,28 @@ /* - * 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. + * Omega GPU Engine core (A3a). See src/omega_gpu_engine.h and + * docs/numeric/OMEGA_GPU_ENGINE.md. + * + * omega_gpu_execute drives the backend function table in one fixed order: + * open, channel, alloc x5, copy-in x3, poison fill, build -> PREPARED + * submit -> SUBMITTED + * marker wait, marker2 wait (unless NO_C3), release wait -> GPU_COMPLETE + * barrier, copy-out -> OUTPUT_VISIBLE + * compare every output word with its poison word -> OUTPUT_PRODUCED + * free every buffer (reverse order), close -> SUCCESS + * Every exit runs cleanup EXCEPT an uncertain completion (any non-zero result + * from one of the three completion waits), which keeps the context and every + * allocation, sets the process-wide block and reports retained = 1. + * The engine never judges the math: it only checks that output words changed. + * + * Marker comments of the form MUT:<name> label the lines that + * tools/gpu_engine_mutations.sh breaks one at a time. */ #include "omega_gpu_engine.h" +#include <errno.h> #include <stdatomic.h> #include <string.h> +#include <time.h> static const char *const FAILURE_NAMES[OMEGA_GPU_ENGINE_FAILURE_COUNT] = { "OK", @@ -70,6 +83,7 @@ static const char *const STEP_NAMES[OMEGA_GPU_ENGINE_STEP_COUNT] = { static _Atomic(const OmegaGpuBackend *) g_backend; static atomic_int g_blocked; +static uint64_t (*g_clock)(void); /* test clock, NULL means CLOCK_MONOTONIC */ const char *omega_gpu_engine_failure_name(int failure) { @@ -115,6 +129,23 @@ void omega_gpu_engine_test_force_block(void) atomic_store(&g_blocked, 1); } +void omega_gpu_engine_test_set_clock(uint64_t (*now_ms)(void)) +{ + g_clock = now_ms; +} + +static uint64_t mono_ms(void) +{ + struct timespec ts; + if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) return 0u; + return (uint64_t)ts.tv_sec * 1000u + (uint64_t)ts.tv_nsec / 1000000u; +} + +static uint64_t now_ms(void) +{ + return g_clock ? g_clock() : mono_ms(); +} + static int backend_complete(const OmegaGpuBackend *b) { return b->open_device && b->create_channel && b->alloc && b->copy_in && b->fill_poison && @@ -127,23 +158,30 @@ static int backend_complete(const OmegaGpuBackend *b) 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; + if (!job->program || job->program_len == 0) return 0; /* MUT:VALID_PROGRAM */ + if (job->layout != OMEGA_GPU_LAYOUT_VECTOR_1D) return 0; /* MUT:VALID_LAYOUT */ + if (job->element_count == 0) return 0; /* MUT:VALID_COUNT_ZERO */ 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 (((uintptr_t)job->output & 3u) != 0) return 0; /* MUT:VALID_ALIGN */ + if (!job->poison || (uint64_t)job->poison_count != (uint64_t)job->element_count) return 0; /* MUT:VALID_POISON_COUNT */ + if ((job->flags & ~(uint32_t)OMEGA_GPU_ENGINE_FLAG_NO_C3) != 0) return 0; /* MUT:VALID_FLAGS */ + if (job->timeouts.marker_ms == 0) return 0; /* MUT:VALID_TIMEOUT_MARKER1 */ 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; + if ((job->flags & OMEGA_GPU_ENGINE_FLAG_NO_C3) == 0 && job->timeouts.marker2_ms == 0) return 0; /* MUT:VALID_TIMEOUT_MARKER2 */ return 1; } +/* What the engine still owes the device: close if opened, free each allocated buffer. */ +typedef struct { + int opened; + int allocated[OMEGA_GPU_BUF_ROLE_COUNT]; +} Run; + +/* Failure before any backend call: nothing to capture, nothing to clean. */ static int stop(OmegaGpuResult *result, int failure, int step) { result->failure = failure; @@ -151,23 +189,248 @@ static int stop(OmegaGpuResult *result, int failure, int step) return failure; } +/* Copies the backend diagnostics (driver code, text, observed words) into the result. */ +static void capture(const OmegaGpuBackend *b, OmegaGpuResult *result) +{ + OmegaGpuBackendDiag d; + memset(&d, 0, sizeof d); + b->diagnostics(b->ctx, &d); + result->drv_rc = d.drv_rc; + memcpy(result->drv_text, d.drv_text, sizeof result->drv_text); + result->drv_text[sizeof result->drv_text - 1u] = '\0'; + result->sync_valid = d.sync_valid; + result->marker = d.marker; + result->marker2 = d.marker2; + memcpy(result->semaphore, d.semaphore, sizeof result->semaphore); +} + +/* Records the failure of a backend call. err is errno captured right after that call. */ +static int fail(const OmegaGpuBackend *b, OmegaGpuResult *result, int failure, int step, int err) +{ + capture(b, result); + result->failure = failure; + result->failed_step = step; + result->err_no = err; + return failure; +} + +/* A cleanup call failed. The first failure of the run is never overwritten. */ +static void cleanup_fault(const OmegaGpuBackend *b, OmegaGpuResult *result, int step, int err) +{ + if (result->failure == OMEGA_GPU_ENGINE_OK) /* MUT:CLEANUP_OVERWRITES_FIRST */ + (void)fail(b, result, OMEGA_GPU_ENGINE_CLEANUP, step, err); + result->cleanup_failed = 1; /* MUT:CLEANUP_FLAG_NOT_SET */ +} + +/* Frees every allocated buffer (reverse of allocation order), then closes the + * device. A failing call does not stop the rest. Returns result->failure. */ +static int leave(const OmegaGpuBackend *b, const Run *run, OmegaGpuResult *result) +{ + int role; + int rc; + int e; + for (role = (int)OMEGA_GPU_BUF_ROLE_COUNT - 1; role >= 0; role--) { + if (!run->allocated[role]) continue; /* MUT:FREE_UNALLOCATED */ + errno = 0; + rc = b->free_buf(b->ctx, role); /* MUT:FREE_SKIPPED */ + e = errno; + if (rc != 0) cleanup_fault(b, result, OMEGA_GPU_ENGINE_STEP_FREE, e); + } + if (run->opened) { + errno = 0; + rc = b->close(b->ctx); /* MUT:CLOSE_SKIPPED */ + e = errno; + if (rc != 0) cleanup_fault(b, result, OMEGA_GPU_ENGINE_STEP_CLOSE, e); + } + return result->failure; +} + +/* A completion wait gave a non-zero result: completion is uncertain. Keep the + * context and every allocation (no free, no close), say so, and block the process. */ +static int uncertain(const OmegaGpuBackend *b, OmegaGpuResult *result, int failure, int step, + int wait, uint64_t limit_ms, uint64_t waited_ms, int err) +{ + (void)fail(b, result, failure, step, err); + result->wait = wait; + result->wait_timeout_ms = limit_ms; + result->waited_ms = waited_ms; + result->retained = 1; /* MUT:RETAINED_FLAG_NOT_SET */ + atomic_store(&g_blocked, 1); /* MUT:NO_BLOCK */ + return failure; +} + +/* Calls a timed backend callback; captures errno right after it and measures the wait. */ +static int timed_call(int (*fn)(void *, uint64_t), void *ctx, uint64_t ms, uint64_t *waited_ms, + int *err) +{ + uint64_t t0 = now_ms(); + uint64_t t1; + int rc; + errno = 0; + rc = fn(ctx, ms); + *err = errno; + t1 = now_ms(); + *waited_ms = t1 >= t0 ? t1 - t0 : 0u; /* MUT:WAITED_NOT_A_DIFFERENCE */ + return rc; +} + +static int copy_in_role(const OmegaGpuBackend *b, int role, const void *src, size_t bytes, int *err) +{ + int rc; + errno = 0; + rc = b->copy_in(b->ctx, role, src, bytes); + *err = errno; + return rc; +} + +/* Device bytes for a buffer role. SCRATCH (pushbuffer, marker page, QMD) is the + * backend's own business, so the engine passes 0 and the backend sizes it. */ +static size_t buf_bytes(const OmegaGpuJob *job, int role) +{ + switch (role) { + case OMEGA_GPU_BUF_PROGRAM: return job->program_len; + case OMEGA_GPU_BUF_INPUT_A: return job->input_a_len; + case OMEGA_GPU_BUF_INPUT_B: return job->input_b_len; + case OMEGA_GPU_BUF_OUTPUT: return job->output_len; + default: return 0u; + } +} + int omega_gpu_execute(const OmegaGpuJob *job, OmegaGpuResult *result) { const OmegaGpuBackend *b; + Run run; + uint64_t waited = 0u; + uint64_t unchanged = 0u; + size_t i; + int role; + int rc; + int e = 0; + 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()) + if (omega_gpu_engine_is_blocked()) /* MUT:BLOCK_CHECK_SKIPPED */ return stop(result, OMEGA_GPU_ENGINE_UNCERTAIN_COMPLETION_BLOCKED, OMEGA_GPU_ENGINE_STEP_BLOCKED); - if (!job || !job_valid(job)) + if (!job || !job_valid(job)) /* MUT:VALIDATE_SKIPPED */ return stop(result, OMEGA_GPU_ENGINE_INVALID_ARGS, OMEGA_GPU_ENGINE_STEP_VALIDATE); b = atomic_load(&g_backend); - if (b && !backend_complete(b)) + if (!b) + return stop(result, OMEGA_GPU_ENGINE_INTERNAL_INVARIANT, OMEGA_GPU_ENGINE_STEP_NOT_IMPLEMENTED); + if (!backend_complete(b)) /* MUT:BACKEND_CHECK_SKIPPED */ 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); + memset(&run, 0, sizeof run); + + /* INITIAL -> PREPARED */ + errno = 0; + rc = b->open_device(b->ctx); + e = errno; + if (rc != 0) { + (void)fail(b, result, OMEGA_GPU_ENGINE_DEVICE_OPEN, OMEGA_GPU_ENGINE_STEP_OPEN_DEVICE, e); + return leave(b, &run, result); + } + run.opened = 1; /* MUT:OPEN_NOT_TRACKED */ + + errno = 0; + rc = b->create_channel(b->ctx); + e = errno; + if (rc != 0) { + (void)fail(b, result, OMEGA_GPU_ENGINE_CHANNEL_CREATE, OMEGA_GPU_ENGINE_STEP_CREATE_CHANNEL, e); + return leave(b, &run, result); /* MUT:CLEANUP_SKIPPED_CHANNEL */ + } + + for (role = 0; role < (int)OMEGA_GPU_BUF_ROLE_COUNT; role++) { + errno = 0; + rc = b->alloc(b->ctx, role, buf_bytes(job, role)); + e = errno; + if (rc != 0) { + (void)fail(b, result, OMEGA_GPU_ENGINE_ALLOC, OMEGA_GPU_ENGINE_STEP_ALLOC, e); + return leave(b, &run, result); /* MUT:CLEANUP_SKIPPED_ALLOC */ + } + run.allocated[role] = 1; /* MUT:ALLOC_NOT_TRACKED */ + } + + rc = copy_in_role(b, OMEGA_GPU_BUF_PROGRAM, job->program, job->program_len, &e); + if (rc == 0) rc = copy_in_role(b, OMEGA_GPU_BUF_INPUT_A, job->input_a, job->input_a_len, &e); + if (rc == 0) rc = copy_in_role(b, OMEGA_GPU_BUF_INPUT_B, job->input_b, job->input_b_len, &e); + if (rc != 0) { + (void)fail(b, result, OMEGA_GPU_ENGINE_PREPARE, OMEGA_GPU_ENGINE_STEP_COPY_IN, e); + return leave(b, &run, result); /* MUT:CLEANUP_SKIPPED_COPY_IN */ + } + + errno = 0; rc = b->fill_poison(b->ctx, job->poison, job->poison_count); e = errno; /* MUT:POISON_FILL_SKIPPED */ + if (rc != 0) { + (void)fail(b, result, OMEGA_GPU_ENGINE_PREPARE, OMEGA_GPU_ENGINE_STEP_FILL_POISON, e); + return leave(b, &run, result); + } + + errno = 0; + rc = b->build(b->ctx, job); + e = errno; + if (rc != 0) { + (void)fail(b, result, OMEGA_GPU_ENGINE_PREPARE, OMEGA_GPU_ENGINE_STEP_BUILD, e); + return leave(b, &run, result); + } + result->last_state = OMEGA_GPU_ENGINE_STATE_PREPARED; /* MUT:STATE_PREPARED_SKIPPED */ + + /* PREPARED -> SUBMITTED. A failed submit is a known failure, not an uncertain completion. */ + errno = 0; + rc = b->submit(b->ctx); + e = errno; + if (rc != 0) { + (void)fail(b, result, OMEGA_GPU_ENGINE_SUBMIT, OMEGA_GPU_ENGINE_STEP_SUBMIT, e); + return leave(b, &run, result); /* MUT:CLEANUP_SKIPPED_SUBMIT */ + } + result->last_state = OMEGA_GPU_ENGINE_STATE_SUBMITTED; /* MUT:STATE_SUBMITTED_SKIPPED */ + + /* SUBMITTED -> GPU_COMPLETE: marker, marker2 (unless NO_C3), release semaphore. + * Any non-zero result is an uncertain completion. */ + rc = timed_call(b->wait_marker, b->ctx, job->timeouts.marker_ms, &waited, &e); /* MUT:MARKER1_WAIT_SKIPPED MUT:MARKER1_TIMEOUT_WRONG */ + if (rc != 0) return uncertain(b, result, OMEGA_GPU_ENGINE_COMPLETION_WAIT, OMEGA_GPU_ENGINE_STEP_WAIT_MARKER, OMEGA_GPU_ENGINE_WAIT_MARKER, job->timeouts.marker_ms, waited, e); /* MUT:MARKER1_RESULT_IGNORED MUT:UNCERTAIN_FREES_MARKER1 */ + if (!(job->flags & OMEGA_GPU_ENGINE_FLAG_NO_C3)) { /* MUT:MARKER2_WAIT_SKIPPED MUT:C3_FLAG_IGNORED */ + rc = timed_call(b->wait_marker2, b->ctx, job->timeouts.marker2_ms, &waited, &e); + if (rc != 0) return uncertain(b, result, OMEGA_GPU_ENGINE_COMPLETION_WAIT, OMEGA_GPU_ENGINE_STEP_WAIT_MARKER2, OMEGA_GPU_ENGINE_WAIT_MARKER2, job->timeouts.marker2_ms, waited, e); /* MUT:MARKER2_RESULT_IGNORED MUT:UNCERTAIN_FREES_MARKER2 */ + } + rc = timed_call(b->wait_release_semaphore, b->ctx, job->timeouts.release_semaphore_ms, &waited, &e); /* MUT:RELEASE_WAIT_SKIPPED */ + if (rc != 0) return uncertain(b, result, OMEGA_GPU_ENGINE_RELEASE_WAIT, OMEGA_GPU_ENGINE_STEP_WAIT_RELEASE_SEMAPHORE, OMEGA_GPU_ENGINE_WAIT_RELEASE_SEMAPHORE, job->timeouts.release_semaphore_ms, waited, e); /* MUT:RELEASE_RESULT_IGNORED MUT:UNCERTAIN_FREES_RELEASE */ + result->last_state = OMEGA_GPU_ENGINE_STATE_GPU_COMPLETE; /* MUT:STATE_GPU_COMPLETE_SKIPPED */ + + /* GPU_COMPLETE -> OUTPUT_VISIBLE: completion is known here, so a failure cleans up. */ + rc = timed_call(b->barrier, b->ctx, job->timeouts.visibility_ms, &waited, &e); /* MUT:BARRIER_SKIPPED */ + if (rc != 0) { /* MUT:BARRIER_RESULT_IGNORED */ + (void)fail(b, result, OMEGA_GPU_ENGINE_VISIBILITY_WAIT, OMEGA_GPU_ENGINE_STEP_BARRIER, e); + return leave(b, &run, result); + } + errno = 0; + rc = b->copy_out(b->ctx, job->output, job->output_len); + e = errno; + if (rc != 0) { + (void)fail(b, result, OMEGA_GPU_ENGINE_VISIBILITY_WAIT, OMEGA_GPU_ENGINE_STEP_COPY_OUT, e); + return leave(b, &run, result); + } + result->last_state = OMEGA_GPU_ENGINE_STATE_OUTPUT_VISIBLE; /* MUT:STATE_OUTPUT_VISIBLE_SKIPPED */ + + /* OUTPUT_VISIBLE -> OUTPUT_PRODUCED: no output word may still equal its poison word. */ + for (i = 0; i < (size_t)job->element_count; i++) { + uint32_t w; + memcpy(&w, (const unsigned char *)job->output + i * 4u, sizeof w); + if (w == job->poison[i]) unchanged++; /* MUT:POISON_INDEX_FIXED MUT:UNCHANGED_COUNT_SATURATES */ + } + result->n_outputs = 1u; + result->output_unchanged_words[0] = unchanged; + if (unchanged != 0u) { /* MUT:UNCHANGED_CHECK_SKIPPED */ + (void)fail(b, result, OMEGA_GPU_ENGINE_OUTPUT_UNCHANGED, OMEGA_GPU_ENGINE_STEP_SCAN, 0); + return leave(b, &run, result); + } + result->last_state = OMEGA_GPU_ENGINE_STATE_OUTPUT_PRODUCED; /* MUT:STATE_OUTPUT_PRODUCED_SKIPPED */ + + /* OUTPUT_PRODUCED -> SUCCESS, only when cleanup also went well. */ + rc = leave(b, &run, result); + if (rc == OMEGA_GPU_ENGINE_OK) result->last_state = OMEGA_GPU_ENGINE_STATE_SUCCESS; /* MUT:STATE_SUCCESS_SKIPPED MUT:SUCCESS_AFTER_CLEANUP_FAIL */ + return rc; } diff --git a/src/omega_gpu_engine.h b/src/omega_gpu_engine.h index cc72ea57c..2faed479a 100644 --- a/src/omega_gpu_engine.h +++ b/src/omega_gpu_engine.h @@ -28,8 +28,10 @@ * 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 + * STATUS: A3a engine core. omega_gpu_execute drives the backend table below + * through the whole state machine; only a fake backend exists (host tests). + * With no backend set it still returns INTERNAL_INVARIANT at step + * NOT_IMPLEMENTED. The real Blackwell backend is a later cut (A3b). This cut is * not chip-qualified (host NOT_RUN, chip NOT_RUN). */ #ifndef OMEGA_GPU_ENGINE_H @@ -199,7 +201,7 @@ typedef struct { 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 (*alloc)(void *ctx, int role, size_t bytes); /* SCRATCH gets bytes == 0: the backend sizes it */ 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 */ @@ -234,6 +236,11 @@ void omega_gpu_engine_test_reset_block(void); * result without a real uncertain completion. */ void omega_gpu_engine_test_force_block(void); +/* TEST ONLY. Replaces the millisecond clock the engine uses to measure + * waited_ms (default: CLOCK_MONOTONIC). NULL restores the default. Not thread + * safe: set it before any job runs. Lets host tests assert exact waited_ms. */ +void omega_gpu_engine_test_set_clock(uint64_t (*now_ms)(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); diff --git a/tests/fake_m16_native.c b/tests/fake_m16_native.c new file mode 100644 index 000000000..4c77b7f73 --- /dev/null +++ b/tests/fake_m16_native.c @@ -0,0 +1,427 @@ +/* + * Simulated GB10 driver. See tests/fake_m16_native.h for what it models. + * NOT_RUN: written in cut A3b2, never compiled or executed by its author. + * + * Linked INSTEAD of physics/m16/m16_native.c and physics/nvrm/nvrm.c. The + * physics headers are still included, so the types (Nvrm, NvrmMem, + * M16NativeContext) and the prototypes are the real ones. + */ +#include "fake_m16_native.h" +#include "m16_native.h" + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define FK_LIVE_MAX 64 + +FakeDriver fk; + +typedef struct { + uint32_t handle; + void *ptr; +} LiveAlloc; + +static LiveAlloc g_live[FK_LIVE_MAX]; +static uint32_t g_next_handle; +static void *g_chan_pb; /* the channel's own 4 KiB pushbuffer, not counted in fk.live */ + +/* ---- test-side helpers ---------------------------------------------------- */ + +void fake_release_all(void) +{ + size_t i; + for (i = 0; i < FK_LIVE_MAX; i++) { + if (g_live[i].handle != 0) { + free(g_live[i].ptr); + g_live[i].handle = 0; + g_live[i].ptr = NULL; + } + } + fk.live = 0; + free(g_chan_pb); + g_chan_pb = NULL; +} + +void fake_reset(void) +{ + fake_release_all(); + memset(&fk, 0, sizeof fk); + g_next_handle = 0; +} + +uint64_t fake_now_ms(void) +{ + return fk.clock_ms; +} + +int fake_count(int kind) +{ + int i; + int n = 0; + for (i = 0; i < fk.nev; i++) + if (fk.ev[i].kind == kind) n++; + return n; +} + +int fake_nth(int kind, int nth) +{ + int i; + int n = 0; + for (i = 0; i < fk.nev; i++) { + if (fk.ev[i].kind != kind) continue; + n++; + if (n == nth) return i; + } + return -1; +} + +/* ---- internal ------------------------------------------------------------- */ + +static void logev(int kind, uint64_t a, uint64_t b, uint64_t c) +{ + if (fk.nev >= FK_EV_MAX) { + fk.ev_overflow = 1; + return; + } + fk.ev[fk.nev].kind = kind; + fk.ev[fk.nev].a = a; + fk.ev[fk.nev].b = b; + fk.ev[fk.nev].c = c; + fk.nev++; +} + +/* A failed driver call: errno and the driver's own text, like the real nvrm does. */ +static int inject(Nvrm *rm, int rc) +{ + errno = EIO; + if (rm) (void)snprintf(rm->err, sizeof rm->err, "%s", FK_TEXT); + return rc; +} + +static void live_add(uint32_t handle, void *ptr) +{ + size_t i; + for (i = 0; i < FK_LIVE_MAX; i++) { + if (g_live[i].handle == 0) { + g_live[i].handle = handle; + g_live[i].ptr = ptr; + fk.live++; + return; + } + } + free(ptr); /* the table is full: more live buffers than any test needs */ +} + +/* Returns 1 if the handle was live and is now released, else 0. */ +static int live_release(uint32_t handle) +{ + size_t i; + for (i = 0; i < FK_LIVE_MAX; i++) { + if (g_live[i].handle == handle) { + free(g_live[i].ptr); + g_live[i].handle = 0; + g_live[i].ptr = NULL; + fk.live--; + return 1; + } + } + return 0; +} + +static volatile uint32_t *word_at(uint64_t va) +{ + return (volatile uint32_t *)(uintptr_t)va; +} + +/* ---- the simulated GPU: pushbuffer parser and kernel ---------------------- */ + +/* The vector kernel: QMD1 words give the program address (32, 33), the thread + * count (34 and 39), the constant bank (42, 43) and the completion semaphore + * (15, 16, 17), as written by src/omega_blackwell_qmd.c. The arguments are read + * from constant bank + 0x380: a, b, c addresses (lo, hi) and the element count. */ +static void run_kernel(const uint32_t *q) +{ + uint64_t prog = ((uint64_t)(q[33] & 0x1fffffu) << 36) | ((uint64_t)q[32] << 4); + uint64_t cb = ((uint64_t)(q[43] & 0x7ffffu) << 38) | ((uint64_t)q[42] << 6); + uint64_t threads = (uint64_t)(q[34] & 0xffffu) * (uint64_t)q[39]; + const uint32_t *args = (const uint32_t *)(uintptr_t)(cb + 0x380u); + uint32_t *a = (uint32_t *)(uintptr_t)(((uint64_t)args[1] << 32) | args[0]); + uint32_t *b = (uint32_t *)(uintptr_t)(((uint64_t)args[3] << 32) | args[2]); + uint32_t *c = (uint32_t *)(uintptr_t)(((uint64_t)args[5] << 32) | args[4]); + uint32_t n = args[6]; + uint64_t sem = ((uint64_t)q[16] << 32) | q[15]; + uint64_t count = n < threads ? n : threads; + uint32_t i; + int ok = 1; + + fk.kernel_ran++; + fk.kernel_threads = threads; + fk.arg_a = (uint64_t)(uintptr_t)a; + fk.arg_b = (uint64_t)(uintptr_t)b; + fk.arg_c = (uint64_t)(uintptr_t)c; + fk.prog_va_seen = prog; + fk.cbank_va_seen = cb; + fk.kernel_n = n; + if (fk.prog_expect != NULL && fk.prog_len != 0) + ok = memcmp((const void *)(uintptr_t)prog, fk.prog_expect, fk.prog_len) == 0; + fk.prog_matched = ok; + logev(FK_EV_KERNEL, threads, n, 0); + + /* What the device output holds just before the kernel runs, and whether the + * poison words collide with the correct sums. */ + fk.snap_n = n < FK_SNAP_WORDS ? n : FK_SNAP_WORDS; + for (i = 0; i < fk.snap_n; i++) { + fk.out_before[i] = c[i]; + if (c[i] == (uint32_t)(a[i] + b[i])) fk.poison_collisions++; + } + + if (ok && fk.kernel_mode != FK_KERNEL_NO_WRITE) { + if (fk.kernel_mode == FK_KERNEL_HALF) count /= 2u; + for (i = 0; i < count; i++) { + c[i] = (uint32_t)(a[i] + b[i]); + if (fk.kernel_mode == FK_KERNEL_WRONG) c[i] += 1u; + } + } + + /* Completion semaphore (RELEASE_SEMAPHORE0 of the QMD): value q[17]. */ + if (fk.sem_mode != FK_SYNC_NEVER) + *word_at(sem) = q[17] + (fk.sem_mode == FK_SYNC_OVERSHOOT ? 1u : 0u); +} + +/* Walks the submitted pushbuffer. exec == 0 only collects addresses (so the + * state at the doorbell can be captured first); exec == 1 runs it. Every packet + * is a header (type 2 or 6 in bits 31:28, count in 28:16, subchannel in 15:13, + * method in 11:0 times 4) followed by count data words. */ +static void walk(const uint32_t *w, size_t n, int exec) +{ + size_t i = 0; + uint64_t dst = 0; + uint32_t line_bytes = 0; + uint32_t lines = 0; + int nrel = 0; + int flushed = 0; + + while (i < n) { + uint32_t h = w[i++]; + uint32_t type = h >> 28; + uint32_t cnt = (h >> 16) & 0x1fffu; + uint32_t subc = (h >> 13) & 7u; + uint32_t mthd = (h & 0xfffu) << 2; + const uint32_t *d; + + if ((type != 2u && type != 6u) || i + cnt > n) { + fk.pb_parse_error = 1; + return; + } + d = &w[i]; + i += cnt; + + if (subc == 1u && mthd == 0x0188u && cnt == 2u) { + dst = ((uint64_t)d[0] << 32) | d[1]; + } else if (subc == 1u && mthd == 0x0180u && cnt == 2u) { + line_bytes = d[0]; + lines = d[1]; + } else if (subc == 1u && mthd == 0x01b4u) { + if (dst == 0 || (uint64_t)cnt * 4u != (uint64_t)line_bytes * lines) { + fk.pb_parse_error = 1; + continue; + } + if (!exec) { + if (cnt == 1u) { + fk.sem_va = dst; + fk.sem_init_value = d[0]; + } + } else { + memcpy((void *)(uintptr_t)dst, d, (size_t)cnt * 4u); + if (cnt == 224u) logev(FK_EV_PB_CBANK, dst, cnt, 0); + else if (cnt == 7u) logev(FK_EV_PB_ARGS, dst, cnt, 0); + else if (cnt == 1u) logev(FK_EV_PB_SEM_INIT, dst, d[0], 0); + } + } else if (subc == 1u && mthd == 0x0318u && cnt == 98u) { + uint64_t qaddr = ((uint64_t)(d[0] & 0x1ffu) << 40) | ((uint64_t)d[1] << 8); + const uint32_t *q = d + 2; + int launch = ((d[0] >> 30) & 1u) != 0; + if (exec) { + if (qaddr == 0) { + fk.pb_parse_error = 1; + continue; + } + memcpy((void *)(uintptr_t)qaddr, q, 96u * 4u); + logev(FK_EV_PB_QMD, qaddr, (launch && (q[9] & 1u) != 0) ? 1u : 0u, 0); + if (launch && (q[9] & 1u) != 0) run_kernel(q); + } + } else if (subc == 0u && mthd == 0x005cu && cnt == 5u) { + uint64_t addr = ((uint64_t)d[1] << 32) | d[0]; + uint32_t payload = d[2]; + uint32_t flags = d[4]; + nrel++; + if (!exec) { + if (nrel == 1) fk.marker1_va = addr; + else if (nrel == 2) fk.marker2_va = addr; + } else { + int mode = nrel == 1 ? fk.marker_mode : fk.marker2_mode; + int writes = (flags & 1u) != 0; + logev(FK_EV_PB_RELEASE, addr, payload, flags); + if (nrel <= 2) fk.release_flags[nrel - 1] = flags; + /* Modelling choice: the second release only lands if an L2 flush + * memory operation came between the two releases. */ + if (nrel == 2 && !flushed) writes = 0; + if (mode == FK_SYNC_NEVER) writes = 0; + if (writes && addr != 0) + *word_at(addr) = payload + (mode == FK_SYNC_OVERSHOOT ? 1u : 0u); + flushed = 0; + } + } else if (subc == 0u && mthd == 0x0028u && cnt == 4u) { + if (exec) { + logev(FK_EV_PB_FLUSH, d[3], 0, 0); + if (d[3] == (0x10u << 27)) flushed = 1; + } + } + /* every other packet is a setup method: ignored */ + } +} + +/* ---- the seven faked symbols ---------------------------------------------- */ + +int m16_native_open(M16NativeContext *ctx) +{ + if (!ctx) return -1; + memset(ctx, 0, sizeof *ctx); + fk.open_calls++; + logev(FK_EV_OPEN, 0, 0, 0); + if (fk.open_fail) return inject(&ctx->rm, -1); + fk.device_open = 1; + return 0; +} + +int m16_native_create_channel(M16NativeContext *ctx) +{ + void *p = NULL; + if (!ctx) return -1; + fk.channel_calls++; + logev(FK_EV_CHANNEL, 0, 0, 0); + if (fk.channel_fail) return inject(&ctx->rm, -1); + if (posix_memalign(&p, 4096, 0x1000) != 0) return -1; + memset(p, 0, 0x1000); + ctx->pb_mem.handle = ++g_next_handle; + ctx->pb_mem.size = 0x1000; + ctx->pb_mem.cpu = p; + ctx->pb_mem.va = (uint64_t)(uintptr_t)p; + g_chan_pb = p; + fk.channel_up = 1; + return 0; +} + +int nvrm_alloc(Nvrm *rm, uint64_t size, NvrmMem *out) +{ + void *p = NULL; + int mode = -1; + fk.alloc_calls++; + logev(FK_EV_ALLOC, size, 0, 0); + if (!out || size == 0 || size > 0x100000u) return -1; + if (fk.alloc_fail_nth != 0 && fk.alloc_fail_nth == fk.alloc_calls) { + mode = fk.alloc_mode; + if (mode == FK_ALLOC_FAIL) return inject(rm, -1); + } + if (posix_memalign(&p, 4096, (size_t)size) != 0) return -1; + memset(p, 0x5a, (size_t)size); /* dirty memory */ + out->handle = ++g_next_handle; + out->size = size; + out->cpu = p; + out->va = (uint64_t)(uintptr_t)p; + live_add(out->handle, p); + if (fk.alloc_calls >= 1 && fk.alloc_calls <= 16) fk.alloc_va[fk.alloc_calls - 1] = out->va; + if (mode == FK_ALLOC_NO_CPU) out->cpu = NULL; + else if (mode == FK_ALLOC_SHORT) out->size = size / 2u; + else if (mode == FK_ALLOC_MISALIGNED) out->va += 0x10u; + return 0; +} + +/* Same as nvrm_alloc (the fake has no GPU cache); only counts the uncached request. */ +int nvrm_alloc_gpu_uncached(Nvrm *rm, uint64_t size, NvrmMem *out) +{ + fk.uncached_calls++; + return nvrm_alloc(rm, size, out); +} + +int nvrm_free(Nvrm *rm, NvrmMem *m) +{ + if (!m || m->handle == 0) return 0; /* a zeroed NvrmMem is a no-op (nvrm.h) */ + fk.free_calls++; + logev(FK_EV_FREE, m->handle, 0, 0); + if (fk.free_fail_nth != 0 && fk.free_fail_nth == fk.free_calls) return inject(rm, -1); + if (!live_release(m->handle)) { + fk.double_free++; + errno = EINVAL; + return -1; + } + memset(m, 0, sizeof *m); + errno = EBADF; /* a real free runs munmap and ioctl calls, which may change errno */ + return 0; +} + +int m16_native_submit_methods(M16NativeContext *ctx, const uint32_t *methods, size_t count) +{ + if (!ctx || !methods || count == 0) return -1; + fk.submit_calls++; + logev(FK_EV_SUBMIT, count, 0, 0); + if (!fk.channel_up || fk.submit_fail) return inject(&ctx->rm, -1); + /* Like m16_native_enqueue_methods: the words must fit the ring buffer. */ + if (count > ctx->pb_mem.size / sizeof(uint32_t) || count > FK_PB_MAX) return inject(&ctx->rm, -1); + fk.pb_mem_size = ctx->pb_mem.size; + memcpy(fk.pb, methods, count * sizeof(uint32_t)); + fk.pb_len = count; + + walk(fk.pb, count, 0); + if (fk.marker1_va != 0 && fk.sem_va != 0) { + fk.pre_marker1 = *word_at(fk.marker1_va); + fk.pre_marker2 = fk.marker2_va != 0 ? *word_at(fk.marker2_va) : 0u; + fk.pre_sem = *word_at(fk.sem_va); + fk.pre_valid = 1; + } + walk(fk.pb, count, 1); + return 0; +} + +static int which_word(volatile uint32_t *p) +{ + uint64_t a = (uint64_t)(uintptr_t)p; + if (p == NULL) return FK_W_UNKNOWN; + if (fk.marker1_va != 0 && a == fk.marker1_va) return FK_W_MARKER1; + if (fk.marker2_va != 0 && a == fk.marker2_va) return FK_W_MARKER2; + if (fk.sem_va != 0 && a == fk.sem_va) return FK_W_SEM; + return FK_W_UNKNOWN; +} + +/* The real wait is a ">=" serial compare in a loop with a deadline. The fake + * checks once and, if it is not satisfied, "waits" the whole timeout by + * advancing the fake clock. */ +int m16_native_wait_marker(volatile uint32_t *marker, uint32_t expected, uint64_t timeout_ms) +{ + int w = which_word(marker); + fk.wait_calls++; + fk.wait_n[w]++; + fk.wait_ms[w] = timeout_ms; + fk.wait_expected[w] = expected; + logev(FK_EV_WAIT, (uint64_t)w, expected, timeout_ms); + if (!marker) return -1; + if ((int32_t)(*marker - expected) >= 0) return 0; + fk.clock_ms += timeout_ms; + return -1; +} + +int m16_native_close(M16NativeContext *ctx) +{ + int rc = 0; + if (!ctx) return -1; + fk.close_calls++; + fk.live_at_close = fk.live; + logev(FK_EV_CLOSE, (uint64_t)fk.live, 0, 0); + /* Like nvrm_close: whatever is still allocated is released here. */ + fake_release_all(); + fk.device_open = 0; + if (fk.close_fail) rc = inject(&ctx->rm, -1); + return rc; +} diff --git a/tests/fake_m16_native.h b/tests/fake_m16_native.h new file mode 100644 index 000000000..a3f23e31b --- /dev/null +++ b/tests/fake_m16_native.h @@ -0,0 +1,156 @@ +/* + * Simulated GB10 driver for the host test of the Blackwell GPU engine backend + * (tests/test_omega_blackwell_engine.c). NOT_RUN: written in cut A3b2 and never + * compiled or executed by its author. + * + * It replaces seven symbols of the real driver stack, so the REAL backend + * (src/omega_blackwell_engine.c) and the REAL vector wrapper + * (src/omega_blackwell_submit.c) run unchanged on a machine with no GPU: + * m16_native_open, m16_native_create_channel, m16_native_submit_methods, + * m16_native_wait_marker, m16_native_close, nvrm_alloc, nvrm_free. + * The signatures come from physics/m16/m16_native.h and physics/nvrm/nvrm.h at + * the physics pin; the fake file includes those headers, so a mismatch is a + * compile error. + * + * What it models (every point is a MODEL, UNVERIFIED on the chip, confidence + * about 70 percent that it matches the real driver): + * - "device" memory is host memory, GPU address equals CPU address, dirty + * (0x5a fill) so a missing zeroing step shows up; + * - the submitted pushbuffer is parsed and executed in order: DMA uploads, + * the two inline QMDs, the semaphore initial value, the release packets and + * the L2 flush memory operation (method 0x28, operation 0x10 << 27); + * - the vector kernel is a simple loop (c[i] = a[i] + b[i] for the threads the + * QMD asks for) and only runs if the program bytes in device memory are the + * bytes the test expects; + * - the second marker release is only written if an L2 flush operation + * appears between the two releases (modelling choice, see the doc); + * - m16_native_wait_marker is the real ">=" serial compare with no loop; a + * timeout advances the fake clock by the timeout so waited_ms is exact; + * - nvrm_free of a zeroed NvrmMem is a no-op that counts nothing, a real free + * zeroes the NvrmMem and clobbers errno (like a munmap or ioctl might). + */ +#ifndef FAKE_M16_NATIVE_H +#define FAKE_M16_NATIVE_H + +#include <stddef.h> +#include <stdint.h> + +#define FK_TEXT "fake driver says no" +#define FK_EV_MAX 512 +#define FK_SNAP_WORDS 256 +#define FK_PB_MAX 2048 + +/* Event kinds in the log (fk.ev). */ +enum { + FK_EV_OPEN = 1, + FK_EV_CHANNEL, + FK_EV_ALLOC, /* a = bytes asked */ + FK_EV_FREE, /* a = handle */ + FK_EV_SUBMIT, /* a = word count */ + FK_EV_WAIT, /* a = FK_W_*, b = expected value, c = timeout ms */ + FK_EV_CLOSE, /* a = live allocations at the moment of close */ + FK_EV_PB_CBANK, /* a = destination, b = words (224) */ + FK_EV_PB_ARGS, /* a = destination, b = words (7) */ + FK_EV_PB_SEM_INIT, /* a = destination, b = value */ + FK_EV_PB_QMD, /* a = QMD address, b = 1 if it is the kernel QMD */ + FK_EV_PB_RELEASE, /* a = address, b = payload, c = flags word */ + FK_EV_PB_FLUSH, /* a = operation word (last word of the packet) */ + FK_EV_KERNEL /* a = threads, b = element count */ +}; + +/* Which coherent word a wait looked at. */ +enum { FK_W_UNKNOWN = 0, FK_W_MARKER1, FK_W_MARKER2, FK_W_SEM, FK_W_COUNT }; + +enum { FK_ALLOC_FAIL = 0, FK_ALLOC_NO_CPU, FK_ALLOC_SHORT, FK_ALLOC_MISALIGNED }; +enum { FK_SYNC_NORMAL = 0, FK_SYNC_NEVER, FK_SYNC_OVERSHOOT }; +enum { FK_KERNEL_OK = 0, FK_KERNEL_NO_WRITE, FK_KERNEL_HALF, FK_KERNEL_WRONG }; + +typedef struct { + int kind; + uint64_t a; + uint64_t b; + uint64_t c; +} FakeEvent; + +typedef struct { + /* ---- faults and behaviour, set by the test after fake_reset ---- */ + int open_fail; + int channel_fail; + int submit_fail; + int close_fail; + int alloc_fail_nth; /* 1-based nvrm_alloc call that misbehaves, 0 = none */ + int alloc_mode; /* FK_ALLOC_* for that call */ + int free_fail_nth; /* 1-based real nvrm_free call that fails, 0 = none */ + int marker_mode; /* FK_SYNC_*: first marker release */ + int marker2_mode; /* FK_SYNC_*: second marker release */ + int sem_mode; /* FK_SYNC_*: kernel completion semaphore */ + int kernel_mode; /* FK_KERNEL_* */ + const void *prog_expect; /* program bytes the device memory must hold, NULL = do not check */ + size_t prog_len; + + /* ---- observations ---- */ + uint64_t clock_ms; /* the fake millisecond clock (fake_now_ms) */ + int open_calls; + int channel_calls; + int alloc_calls; + int uncached_calls; /* allocations made through nvrm_alloc_gpu_uncached (also counted in alloc_calls) */ + int free_calls; /* real frees only (a zeroed NvrmMem is not counted) */ + int close_calls; + int submit_calls; + int wait_calls; + int double_free; /* frees of a handle that was not live */ + int live; /* live backend allocations right now (not the channel's own 4 KiB buffer) */ + int live_at_close; /* live allocations when m16_native_close was called */ + int device_open; + int channel_up; + uint64_t pb_mem_size; /* ctx->pb_mem.size when the pushbuffer was submitted */ + int pb_parse_error; /* the pushbuffer had a packet the fake could not parse */ + uint32_t pb[FK_PB_MAX]; + size_t pb_len; + + uint64_t marker1_va; /* first release address, from the pushbuffer */ + uint64_t marker2_va; /* second release address, 0 with NO_C3 */ + uint64_t sem_va; /* destination of the semaphore initial value DMA */ + uint32_t sem_init_value; + uint32_t pre_marker1; /* values the GPU would see at the doorbell */ + uint32_t pre_marker2; + uint32_t pre_sem; + int pre_valid; /* the three pre_* values were captured */ + int kernel_ran; + int prog_matched; + uint64_t kernel_threads; + uint64_t kernel_n; + uint32_t out_before[FK_SNAP_WORDS]; /* device output words just before the kernel ran */ + size_t snap_n; + int poison_collisions; /* snapshot words equal to the correct sum (a bad poison word) */ + uint32_t release_flags[2]; + uint64_t alloc_va[16]; /* GPU address of the nth nvrm_alloc (1-based nth stored at [nth - 1]) */ + uint64_t arg_a; /* kernel argument addresses the device saw in the constant bank */ + uint64_t arg_b; + uint64_t arg_c; + uint64_t prog_va_seen; /* program address from QMD1 */ + uint64_t cbank_va_seen;/* constant bank address from QMD1 */ + + int wait_n[FK_W_COUNT]; + uint64_t wait_ms[FK_W_COUNT]; + uint32_t wait_expected[FK_W_COUNT]; + + FakeEvent ev[FK_EV_MAX]; + int nev; + int ev_overflow; +} FakeDriver; + +extern FakeDriver fk; + +/* Frees every host allocation the fake still holds (the test's own teardown, not a driver call). */ +void fake_release_all(void); +/* fake_release_all, then zero the whole state. Call at the start of every case. */ +void fake_reset(void); +/* Millisecond clock for omega_gpu_engine_test_set_clock. */ +uint64_t fake_now_ms(void); +/* Number of events of this kind in the log. */ +int fake_count(int kind); +/* Index of the nth (1-based) event of this kind, or -1. */ +int fake_nth(int kind, int nth); + +#endif diff --git a/tests/run_m17_gates.sh b/tests/run_m17_gates.sh index 683030267..1e06e825c 100755 --- a/tests/run_m17_gates.sh +++ b/tests/run_m17_gates.sh @@ -53,7 +53,7 @@ echo "" # Step 5: Compute artifact digests echo "[*] Step 5: Computing artifact digests..." mkdir -p "$EVIDENCE_DIR/m17_blackwell_vector" -sha256sum "$OMEGA_ROOT/src/omega_vector."* "$OMEGA_ROOT/src/omega_blackwell_encoder."* "$OMEGA_ROOT/src/omega_blackwell_qmd."* "$OMEGA_ROOT/src/omega_blackwell_realize."* "$OMEGA_ROOT/src/omega_blackwell_submit."* "$OMEGA_ROOT/src/omega_blackwell_gates."* "$TOOL" > "$EVIDENCE_DIR/m17_corpus_digests.txt" +sha256sum "$OMEGA_ROOT/src/omega_vector."* "$OMEGA_ROOT/src/omega_blackwell_encoder."* "$OMEGA_ROOT/src/omega_blackwell_qmd."* "$OMEGA_ROOT/src/omega_blackwell_realize."* "$OMEGA_ROOT/src/omega_blackwell_submit."* "$OMEGA_ROOT/src/omega_blackwell_engine."* "$OMEGA_ROOT/src/omega_blackwell_gates."* "$TOOL" > "$EVIDENCE_DIR/m17_corpus_digests.txt" DIGEST_VEC_C=$(sha256sum "$OMEGA_ROOT/src/omega_vector.c" | cut -d' ' -f1) DIGEST_VEC_H=$(sha256sum "$OMEGA_ROOT/src/omega_vector.h" | cut -d' ' -f1) @@ -65,6 +65,8 @@ DIGEST_REAL_C=$(sha256sum "$OMEGA_ROOT/src/omega_blackwell_realize.c" | cut -d' DIGEST_REAL_H=$(sha256sum "$OMEGA_ROOT/src/omega_blackwell_realize.h" | cut -d' ' -f1) DIGEST_SUB_C=$(sha256sum "$OMEGA_ROOT/src/omega_blackwell_submit.c" | cut -d' ' -f1) DIGEST_SUB_H=$(sha256sum "$OMEGA_ROOT/src/omega_blackwell_submit.h" | cut -d' ' -f1) +DIGEST_ENGINE_C=$(sha256sum "$OMEGA_ROOT/src/omega_blackwell_engine.c" | cut -d' ' -f1) +DIGEST_ENGINE_H=$(sha256sum "$OMEGA_ROOT/src/omega_blackwell_engine.h" | cut -d' ' -f1) DIGEST_TOOL=$(sha256sum "$TOOL" | cut -d' ' -f1) QUALIFIED_COMMIT="$(git -C "$OMEGA_ROOT" rev-parse HEAD)" @@ -128,6 +130,8 @@ cat <<RECEIPT_EOF > "$RECEIPT" "src/omega_blackwell_realize.h": { "sha256": "$DIGEST_REAL_H" }, "src/omega_blackwell_submit.c": { "sha256": "$DIGEST_SUB_C" }, "src/omega_blackwell_submit.h": { "sha256": "$DIGEST_SUB_H" }, + "src/omega_blackwell_engine.c": { "sha256": "$DIGEST_ENGINE_C" }, + "src/omega_blackwell_engine.h": { "sha256": "$DIGEST_ENGINE_H" }, "build/omegatool": { "sha256": "$DIGEST_TOOL" } }, "qualification_gates": { diff --git a/tests/test_omega_blackwell_engine.c b/tests/test_omega_blackwell_engine.c new file mode 100644 index 000000000..a4397d823 --- /dev/null +++ b/tests/test_omega_blackwell_engine.c @@ -0,0 +1,995 @@ +/* + * Host test of the REAL Blackwell backend (src/omega_blackwell_engine.c), the + * REAL engine core (src/omega_gpu_engine.c) and the REAL vector wrapper + * omega_blackwell_execute_vector (src/omega_blackwell_submit.c), driven through + * a SIMULATED driver (tests/fake_m16_native.c). Cut A3b2. NOT_RUN: this file has + * never been compiled or executed by its author (Phase A rule). + * + * No GPU, no device node, no physics C sources: the seven driver symbols the + * backend calls are replaced by the fake. Every check prints "[PASS] id" or + * "[FAIL] id"; the last line is "SUMMARY passed=N failed=M"; the exit status is + * nonzero on any failure. docs/numeric/OMEGA_GPU_ENGINE.md section 14.1 lists + * every id and the mutants that need it. + * + * Techniques: + * - A tracing copy of the real backend table logs every callback (so the call + * order the core and the backend produce together can be asserted) and + * forwards to the original. The real table is never edited. + * - The fake parses and executes the pushbuffer, so the descriptors, the + * release packets and the L2 flush are checked as the device would see them. + * - A retained run (uncertain completion) leaves the backend busy by design. + * The test asserts that, then drains the backend through its own table + * (free every role, close), exactly what a process exit would do. + * + * Failure names that no driver fault can reach through the real backend, and so + * are covered by the fake-backend test (tests/test_omega_gpu_engine.c) only: + * PREPARE (copy-in and build refuse only on arguments the core already + * validated, and alloc_checked catches bad buffers first as ALLOC), + * VISIBILITY_WAIT (the barrier always returns 0, copy_out refuses only on bad + * arguments), + * INTERNAL_INVARIANT (the table is complete). + * The CPU barrier (dsb sy) has no effect a host can observe; it is chip only. + */ +#include "omega_gpu_engine.h" +#include "omega_blackwell_engine.h" +#include "omega_blackwell_submit.h" +#include "omega_blackwell_encoder.h" +#include "omega_vector.h" +#include "fake_m16_native.h" + +#include <errno.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define N 100u /* not a multiple of 64: a grid rounded down leaves words unwritten */ +#define TMO_MARKER 111u +#define TMO_MARKER2 222u +#define TMO_RELEASE 333u +#define TMO_VISIBILITY 444u + +#define MARKER1_PAYLOAD 0x44444444u +#define MARKER2_PAYLOAD 0x46464646u +#define SEM_INIT 5u +#define SEM_DONE 6u +#define RELEASE_FLAGS 0x00100001u /* RELEASE | WFI */ +#define FLUSH_OP (0x10u << 27) /* L2_FLUSH_DIRTY */ + +static int n_pass; +static int n_fail; + +static void check(const char *id, int ok) +{ + if (ok) { + n_pass++; + printf("[PASS] %s\n", id); + } else { + n_fail++; + printf("[FAIL] %s\n", id); + } +} + +/* ---- test data -------------------------------------------------------------- */ + +static uint32_t ina[N]; +static uint32_t inb[N]; +static uint32_t expect_out[N]; +static uint32_t poison[N]; +static uint32_t outbuf[N]; +static uint8_t prog[512]; +static uint8_t prog_other[512]; +static uint8_t vec_code[0x1000]; +static size_t vec_len; +static uint8_t bigbytes[0x2000]; +static uint32_t bigwords[2048]; + +static void init_data(void) +{ + uint32_t i; + for (i = 0; i < N; i++) { + uint32_t s; + ina[i] = i * 0x01000193u + 0x01234567u; + inb[i] = i * 0x9e3779b1u + 7u; + s = ina[i] + inb[i]; + /* a wrong-by-one result must never look like the poison word */ + if (s == 0x7fffffffu || s == 0xffffffffu) inb[i] += 0x10u; + } + /* the old fixed poison value as a legitimate sum */ + ina[7] = 0xdeadbeefu - 5u; + inb[7] = 5u; + for (i = 0; i < N; i++) { + expect_out[i] = ina[i] + inb[i]; + poison[i] = ~expect_out[i]; + } + for (i = 0; i < sizeof prog; i++) { + prog[i] = (uint8_t)(i * 7u + 3u); + prog_other[i] = (uint8_t)(i * 11u + 5u); + } +} + +static int output_correct(const uint32_t *o) +{ + uint32_t i; + for (i = 0; i < N; i++) + if (o[i] != expect_out[i]) return 0; + return 1; +} + +/* ---- tracing copy of the real backend table ---------------------------------- */ + +enum { + T_OPEN = 1, T_CHANNEL, T_ALLOC, T_COPY_IN, T_POISON, T_BUILD, T_SUBMIT, T_WAIT1, + T_WAIT2, T_WAITSEM, T_BARRIER, T_COPY_OUT, T_FREE, T_CLOSE +}; +#define TLOG_MAX 128 + +static const OmegaGpuBackend *g_real; +static OmegaGpuBackend g_wrap; +static int g_tlog[TLOG_MAX]; +static int g_targ[TLOG_MAX]; +static int g_tn; + +static void tlog(int kind, int arg) +{ + if (g_tn < TLOG_MAX) { + g_tlog[g_tn] = kind; + g_targ[g_tn] = arg; + g_tn++; + } +} + +static int w_open(void *ctx) { tlog(T_OPEN, 0); return g_real->open_device(ctx); } +static int w_channel(void *ctx) { tlog(T_CHANNEL, 0); return g_real->create_channel(ctx); } +static int w_alloc(void *ctx, int role, size_t bytes) { tlog(T_ALLOC, role); return g_real->alloc(ctx, role, bytes); } +static int w_copy_in(void *ctx, int role, const void *src, size_t bytes) { tlog(T_COPY_IN, role); return g_real->copy_in(ctx, role, src, bytes); } +static int w_poison(void *ctx, const uint32_t *words, size_t count) { tlog(T_POISON, 0); return g_real->fill_poison(ctx, words, count); } +static int w_build(void *ctx, const OmegaGpuJob *job) { tlog(T_BUILD, 0); return g_real->build(ctx, job); } +static int w_submit(void *ctx) { tlog(T_SUBMIT, 0); return g_real->submit(ctx); } +static int w_wait1(void *ctx, uint64_t ms) { tlog(T_WAIT1, 0); return g_real->wait_marker(ctx, ms); } +static int w_wait2(void *ctx, uint64_t ms) { tlog(T_WAIT2, 0); return g_real->wait_marker2(ctx, ms); } +static int w_waitsem(void *ctx, uint64_t ms) { tlog(T_WAITSEM, 0); return g_real->wait_release_semaphore(ctx, ms); } +static int w_barrier(void *ctx, uint64_t ms) { tlog(T_BARRIER, 0); return g_real->barrier(ctx, ms); } +static int w_copy_out(void *ctx, void *dst, size_t bytes) { tlog(T_COPY_OUT, 0); return g_real->copy_out(ctx, dst, bytes); } +static void w_diag(void *ctx, OmegaGpuBackendDiag *d) { g_real->diagnostics(ctx, d); } +static int w_free(void *ctx, int role) { tlog(T_FREE, role); return g_real->free_buf(ctx, role); } +static int w_close(void *ctx) { tlog(T_CLOSE, 0); return g_real->close(ctx); } + +static void wrap_init(void) +{ + g_real = omega_blackwell_engine_backend(); + g_wrap = *g_real; + g_wrap.open_device = w_open; + g_wrap.create_channel = w_channel; + g_wrap.alloc = w_alloc; + g_wrap.copy_in = w_copy_in; + g_wrap.fill_poison = w_poison; + g_wrap.build = w_build; + g_wrap.submit = w_submit; + g_wrap.wait_marker = w_wait1; + g_wrap.wait_marker2 = w_wait2; + g_wrap.wait_release_semaphore = w_waitsem; + g_wrap.barrier = w_barrier; + g_wrap.copy_out = w_copy_out; + g_wrap.diagnostics = w_diag; + g_wrap.free_buf = w_free; + g_wrap.close = w_close; +} + +static int tcount(int kind) +{ + int i; + int n = 0; + for (i = 0; i < g_tn; i++) + if (g_tlog[i] == kind) n++; + return n; +} + +/* ---- case plumbing ---------------------------------------------------------- */ + +static OmegaGpuJob job; +static OmegaGpuResult res; + +static void make_job(OmegaGpuJob *j) +{ + memset(j, 0, sizeof *j); + j->program = prog; + j->program_len = sizeof prog; + j->layout = OMEGA_GPU_LAYOUT_VECTOR_1D; + j->element_count = N; + j->input_a = ina; + j->input_a_len = N * 4u; + j->input_b = inb; + j->input_b_len = N * 4u; + j->output = outbuf; + j->output_len = N * 4u; + j->poison = poison; + j->poison_count = N; + j->timeouts.marker_ms = TMO_MARKER; + j->timeouts.marker2_ms = TMO_MARKER2; + j->timeouts.release_semaphore_ms = TMO_RELEASE; + j->timeouts.visibility_ms = TMO_VISIBILITY; + j->flags = 0; +} + +static void begin_case(void) +{ + fake_reset(); + omega_gpu_engine_test_reset_block(); + omega_gpu_engine_set_backend(&g_wrap); + g_tn = 0; + memset(outbuf, 0, sizeof outbuf); + fk.prog_expect = prog; + fk.prog_len = sizeof prog; + make_job(&job); +} + +static int run(void) +{ + return omega_gpu_execute(&job, &res); +} + +static int res_is(int failure, int step, int state) +{ + return res.failure == failure && res.failed_step == step && res.last_state == state; +} + +/* Everything the backend allocated was returned, the device was closed once, and + * the number of real driver frees is as expected. */ +static int balanced(int frees) +{ + return fk.live_at_close == 0 && fk.double_free == 0 && fk.close_calls == 1 && + fk.free_calls == frees && fk.device_open == 0; +} + +static int has(const char *hay, const char *needle) +{ + return strstr(hay, needle) != NULL; +} + +/* Drains a retained backend through its own table, the way process exit would: + * free every role (all of them are held), then close. Returns 0 if all went well. */ +static int drain(void) +{ + int bad = 0; + int role; + for (role = (int)OMEGA_GPU_BUF_ROLE_COUNT - 1; role >= 0; role--) + if (g_real->free_buf(g_real->ctx, role) != 0) bad = 1; + if (g_real->close(g_real->ctx) != 0) bad = 1; + return bad; +} + +static void idf(char *buf, size_t cap, const char *tag, const char *what) +{ + (void)snprintf(buf, cap, "sim_%s_%s", tag, what); +} + +/* ---- cases ------------------------------------------------------------------ */ + +static void case_success(void) +{ + static const int k_order[24] = { + T_OPEN, T_CHANNEL, T_ALLOC, T_ALLOC, T_ALLOC, T_ALLOC, T_ALLOC, T_COPY_IN, T_COPY_IN, + T_COPY_IN, T_POISON, T_BUILD, T_SUBMIT, T_WAIT1, T_WAIT2, T_WAITSEM, T_BARRIER, + T_COPY_OUT, T_FREE, T_FREE, T_FREE, T_FREE, T_FREE, T_CLOSE + }; + static const int k_args[24] = { + 0, 0, 0, 1, 2, 3, 4, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 4, 3, 2, 1, 0, 0 + }; + static const uint64_t k_sizes[8] = { + 0x10000u, 0x1000u, 0x1000u, 0x10000u, 0x1000u, 0x1000u, 0x1000u, 0x1000u + }; + OmegaBlackwellEngineRunInfo info; + int i; + int ok; + int i_cb, i_ar, i_q0, i_si, i_q1, i_k, i_r1, i_fl, i_r2; + + begin_case(); + check("sim_success_returns_ok", run() == OMEGA_GPU_ENGINE_OK); + check("sim_success_state", res.last_state == OMEGA_GPU_ENGINE_STATE_SUCCESS && + res.failed_step == OMEGA_GPU_ENGINE_STEP_NONE); + check("sim_success_result_flags_clear", + res.retained == 0 && res.cleanup_failed == 0 && res.wait == OMEGA_GPU_ENGINE_WAIT_NONE); + check("sim_success_not_blocked", omega_gpu_engine_is_blocked() == 0); + check("sim_success_output_values", output_correct(outbuf)); + check("sim_success_unchanged_zero", res.n_outputs == 1u && res.output_unchanged_words[0] == 0u); + + ok = g_tn == 24; + for (i = 0; ok && i < 24; i++) + if (g_tlog[i] != k_order[i] || g_targ[i] != k_args[i]) ok = 0; + check("sim_success_call_order", ok); + + check("sim_success_driver_counts", + fk.open_calls == 1 && fk.channel_calls == 1 && fk.alloc_calls == 8 && + fk.submit_calls == 1 && fk.close_calls == 1 && fk.wait_calls == 3); + check("sim_success_all_allocs_gpu_uncached", fk.uncached_calls == fk.alloc_calls && fk.uncached_calls == 8); + ok = fake_count(FK_EV_ALLOC) == 8; + for (i = 0; ok && i < 8; i++) + if (fk.ev[fake_nth(FK_EV_ALLOC, i + 1)].a != k_sizes[i]) ok = 0; + check("sim_success_alloc_sizes", ok); + check("sim_success_balanced", balanced(8)); + check("sim_success_large_pushbuffer_ring", fk.pb_mem_size == 0x10000u); + check("sim_success_pushbuffer_parses", fk.pb_parse_error == 0 && fk.ev_overflow == 0); + + /* The state the GPU sees at the doorbell: the sync words were zeroed first. */ + check("sim_success_doorbell_state_captured", fk.pre_valid == 1); + check("sim_success_marker1_zeroed_before_doorbell", fk.pre_marker1 == 0u); + check("sim_success_marker2_zeroed_before_doorbell", fk.pre_marker2 == 0u); + check("sim_success_semaphore_zeroed_before_doorbell", fk.pre_sem == 0u); + check("sim_success_semaphore_init_value", fk.sem_init_value == SEM_INIT); + + /* The pushbuffer, as the device executes it. */ + i_cb = fake_nth(FK_EV_PB_CBANK, 1); + i_ar = fake_nth(FK_EV_PB_ARGS, 1); + i_q0 = fake_nth(FK_EV_PB_QMD, 1); + i_si = fake_nth(FK_EV_PB_SEM_INIT, 1); + i_q1 = fake_nth(FK_EV_PB_QMD, 2); + i_k = fake_nth(FK_EV_KERNEL, 1); + i_r1 = fake_nth(FK_EV_PB_RELEASE, 1); + i_fl = fake_nth(FK_EV_PB_FLUSH, 1); + i_r2 = fake_nth(FK_EV_PB_RELEASE, 2); + check("sim_success_pushbuffer_order", + i_cb >= 0 && i_cb < i_ar && i_ar < i_q0 && i_q0 < i_si && i_si < i_q1 && i_q1 < i_k && + i_k < i_r1 && i_r1 < i_fl && i_fl < i_r2); + check("sim_success_one_flush_two_releases", + fake_count(FK_EV_PB_FLUSH) == 1 && fake_count(FK_EV_PB_RELEASE) == 2); + if (i_cb >= 0 && i_ar >= 0 && i_q0 >= 0 && i_q1 >= 0 && i_fl >= 0 && i_r1 >= 0 && i_r2 >= 0) { + check("sim_success_cbank_upload_words_and_place", + fk.ev[i_cb].b == 224u && fk.ev[i_cb].a == fk.alloc_va[1]); + check("sim_success_args_upload_words_and_place", + fk.ev[i_ar].b == 7u && fk.ev[i_ar].a == fk.ev[i_cb].a + 0x380u); + check("sim_success_qmd0_is_not_the_kernel_and_place", + fk.ev[i_q0].b == 0u && fk.ev[i_q0].a == fk.alloc_va[3]); + check("sim_success_qmd1_is_the_kernel_and_place", + fk.ev[i_q1].b == 1u && fk.ev[i_q1].a == fk.alloc_va[3] + 0x1000u); + check("sim_success_flush_operation", fk.ev[i_fl].a == (uint64_t)FLUSH_OP); + check("sim_success_release1_address_payload_flags", + fk.ev[i_r1].a == fk.marker1_va && fk.ev[i_r1].b == MARKER1_PAYLOAD && + fk.ev[i_r1].c == RELEASE_FLAGS); + check("sim_success_release2_is_marker_page_plus_0x10", + fk.ev[i_r2].a == fk.ev[i_r1].a + 0x10u); + check("sim_success_release2_payload_and_flags", + fk.ev[i_r2].b == MARKER2_PAYLOAD && fk.ev[i_r2].c == RELEASE_FLAGS); + } else { + check("sim_success_cbank_upload_words_and_place", 0); + check("sim_success_args_upload_words_and_place", 0); + check("sim_success_qmd0_is_not_the_kernel_and_place", 0); + check("sim_success_qmd1_is_the_kernel_and_place", 0); + check("sim_success_flush_operation", 0); + check("sim_success_release1_address_payload_flags", 0); + check("sim_success_release2_is_marker_page_plus_0x10", 0); + check("sim_success_release2_payload_and_flags", 0); + } + + /* The kernel launch the device saw. */ + check("sim_success_kernel_ran_once_with_right_program", fk.kernel_ran == 1 && fk.prog_matched == 1); + check("sim_success_kernel_threads_and_count", fk.kernel_threads == 128u && fk.kernel_n == N); + check("sim_success_kernel_arguments_are_a_b_output", + fk.arg_a == fk.alloc_va[5] && fk.arg_b == fk.alloc_va[6] && fk.arg_c == fk.alloc_va[7]); + check("sim_success_kernel_program_and_cbank_addresses", + fk.prog_va_seen == fk.alloc_va[4] && fk.cbank_va_seen == fk.alloc_va[1]); + check("sim_success_marker_and_semaphore_places", + fk.marker1_va == fk.alloc_va[2] && fk.sem_va == fk.alloc_va[3] + 0x2000u); + ok = fk.snap_n == N; + for (i = 0; ok && i < (int)N; i++) + if (fk.out_before[i] != poison[i]) ok = 0; + check("sim_success_poison_reached_device_output", ok); + check("sim_success_poison_never_equals_a_sum", fk.poison_collisions == 0); + + /* The waits, by word, expected value and timeout. */ + check("sim_success_wait_counts", + fk.wait_n[FK_W_MARKER1] == 1 && fk.wait_n[FK_W_MARKER2] == 1 && + fk.wait_n[FK_W_SEM] == 1 && fk.wait_n[FK_W_UNKNOWN] == 0); + check("sim_success_wait_expected_values", + fk.wait_expected[FK_W_MARKER1] == MARKER1_PAYLOAD && + fk.wait_expected[FK_W_MARKER2] == MARKER2_PAYLOAD && + fk.wait_expected[FK_W_SEM] == SEM_DONE); + check("sim_success_wait_timeouts_come_from_the_job", + fk.wait_ms[FK_W_MARKER1] == TMO_MARKER && fk.wait_ms[FK_W_MARKER2] == TMO_MARKER2 && + fk.wait_ms[FK_W_SEM] == TMO_RELEASE); + i = fake_nth(FK_EV_WAIT, 1); + ok = i >= 0 && fk.ev[i].a == (uint64_t)FK_W_MARKER1; + i = fake_nth(FK_EV_WAIT, 2); + ok = ok && i >= 0 && fk.ev[i].a == (uint64_t)FK_W_MARKER2; + i = fake_nth(FK_EV_WAIT, 3); + ok = ok && i >= 0 && fk.ev[i].a == (uint64_t)FK_W_SEM; + check("sim_success_wait_order_marker_marker2_semaphore", ok); + + /* What the backend observed, for the vector wrapper. */ + memset(&info, 0, sizeof info); + omega_blackwell_engine_run_info(&info); + check("sim_success_run_info_words", + info.marker == MARKER1_PAYLOAD && info.marker2 == MARKER2_PAYLOAD && info.semaphore == SEM_DONE); + check("sim_success_run_info_launch_time_set", info.launch_ns != 0u); + check("sim_success_run_info_done_time_after_launch", + info.marker_done_ns != 0u && info.marker_done_ns >= info.launch_ns); +} + +static void case_no_c3(void) +{ + OmegaBlackwellEngineRunInfo info; + begin_case(); + job.flags = OMEGA_GPU_ENGINE_FLAG_NO_C3; + check("sim_noc3_returns_ok", run() == OMEGA_GPU_ENGINE_OK); + check("sim_noc3_output_values", output_correct(outbuf)); + check("sim_noc3_no_flush_in_pushbuffer", fake_count(FK_EV_PB_FLUSH) == 0); + check("sim_noc3_one_release_only", fake_count(FK_EV_PB_RELEASE) == 1 && fk.marker2_va == 0u); + check("sim_noc3_marker2_never_waited", + fk.wait_n[FK_W_MARKER2] == 0 && tcount(T_WAIT2) == 0 && fk.wait_calls == 2); + check("sim_noc3_marker1_and_semaphore_waited", + fk.wait_n[FK_W_MARKER1] == 1 && fk.wait_n[FK_W_SEM] == 1); + memset(&info, 0, sizeof info); + omega_blackwell_engine_run_info(&info); + check("sim_noc3_run_info_marker2_not_reported", info.marker2 == 0u && info.marker == MARKER1_PAYLOAD); + check("sim_noc3_balanced", balanced(8)); +} + +static void case_back_to_back(void) +{ + int rc1; + int rc2; + int ok; + begin_case(); + rc1 = run(); + ok = output_correct(outbuf); + memset(outbuf, 0, sizeof outbuf); + rc2 = run(); + check("sim_twice_first_ok", rc1 == OMEGA_GPU_ENGINE_OK && ok); + check("sim_twice_second_ok_busy_flag_released", rc2 == OMEGA_GPU_ENGINE_OK && output_correct(outbuf)); + check("sim_twice_driver_opened_and_closed_twice", fk.open_calls == 2 && fk.close_calls == 2); +} + +static void case_open_fail(void) +{ + OmegaBlackwellEngineRunInfo info; + int rc; + begin_case(); + (void)run(); /* leave a dirty run snapshot behind */ + begin_case(); + fk.open_fail = 1; + rc = run(); + check("sim_open_fail_name_step_state", + rc == OMEGA_GPU_ENGINE_DEVICE_OPEN && + res_is(OMEGA_GPU_ENGINE_DEVICE_OPEN, OMEGA_GPU_ENGINE_STEP_OPEN_DEVICE, + OMEGA_GPU_ENGINE_STATE_INITIAL)); + check("sim_open_fail_errno_and_driver_code", res.err_no == EIO && res.drv_rc == -1); + check("sim_open_fail_driver_text_reported", strcmp(res.drv_text, FK_TEXT) == 0); + check("sim_open_fail_nothing_else_touched", + fk.channel_calls == 0 && fk.alloc_calls == 0 && fk.close_calls == 0 && fk.free_calls == 0); + check("sim_open_fail_not_retained_not_blocked", + res.retained == 0 && omega_gpu_engine_is_blocked() == 0); + memset(&info, 0, sizeof info); + omega_blackwell_engine_run_info(&info); + check("sim_open_fail_run_info_reset_at_open", + info.marker == 0u && info.semaphore == 0u && info.launch_ns == 0u && info.marker_done_ns == 0u); + begin_case(); + check("sim_open_fail_then_next_run_ok", run() == OMEGA_GPU_ENGINE_OK); +} + +static void case_channel_fail(void) +{ + int rc; + begin_case(); + fk.channel_fail = 1; + rc = run(); + check("sim_channel_fail_name_step_state", + rc == OMEGA_GPU_ENGINE_CHANNEL_CREATE && + res_is(OMEGA_GPU_ENGINE_CHANNEL_CREATE, OMEGA_GPU_ENGINE_STEP_CREATE_CHANNEL, + OMEGA_GPU_ENGINE_STATE_INITIAL)); + check("sim_channel_fail_errno_text_code", + res.err_no == EIO && res.drv_rc == -1 && strcmp(res.drv_text, FK_TEXT) == 0); + check("sim_channel_fail_closed_nothing_allocated", fk.alloc_calls == 0 && balanced(0)); + begin_case(); + check("sim_channel_fail_then_next_run_ok", run() == OMEGA_GPU_ENGINE_OK); +} + +static void case_alloc_faults(void) +{ + int nth; + char id[64]; + for (nth = 1; nth <= 8; nth++) { + int rc; + begin_case(); + fk.alloc_fail_nth = nth; + fk.alloc_mode = FK_ALLOC_FAIL; + rc = run(); + (void)snprintf(id, sizeof id, "sim_alloc%d_name_step_state", nth); + check(id, rc == OMEGA_GPU_ENGINE_ALLOC && + res_is(OMEGA_GPU_ENGINE_ALLOC, OMEGA_GPU_ENGINE_STEP_ALLOC, + OMEGA_GPU_ENGINE_STATE_INITIAL)); + (void)snprintf(id, sizeof id, "sim_alloc%d_errno_code_text", nth); + check(id, res.err_no == EIO && res.drv_rc == -1 && strcmp(res.drv_text, FK_TEXT) == 0); + (void)snprintf(id, sizeof id, "sim_alloc%d_stops_at_the_failure", nth); + check(id, fk.alloc_calls == nth); + /* nothing is leaked: every part that was allocated is freed (nth - 1 of them) */ + (void)snprintf(id, sizeof id, "sim_alloc%d_balanced", nth); + check(id, balanced(nth - 1)); + } +} + +static void case_alloc_own_checks(void) +{ + static const struct { int mode; int nth; int frees; const char *tag; } t[] = { + { FK_ALLOC_SHORT, 1, 1, "short_pb" }, + { FK_ALLOC_NO_CPU, 3, 3, "nocpu_marker" }, + { FK_ALLOC_MISALIGNED, 4, 4, "misaligned_qmd" }, + { FK_ALLOC_SHORT, 6, 6, "short_input_a" }, + { FK_ALLOC_NO_CPU, 6, 6, "nocpu_input_a" }, + { FK_ALLOC_MISALIGNED, 6, 6, "misaligned_input_a" }, + { FK_ALLOC_NO_CPU, 8, 8, "nocpu_output" } + }; + size_t k; + char id[64]; + for (k = 0; k < sizeof t / sizeof t[0]; k++) { + int rc; + begin_case(); + fk.alloc_fail_nth = t[k].nth; + fk.alloc_mode = t[k].mode; + rc = run(); + idf(id, sizeof id, t[k].tag, "refused_as_alloc"); + check(id, rc == OMEGA_GPU_ENGINE_ALLOC && + res_is(OMEGA_GPU_ENGINE_ALLOC, OMEGA_GPU_ENGINE_STEP_ALLOC, + OMEGA_GPU_ENGINE_STATE_INITIAL)); + idf(id, sizeof id, t[k].tag, "own_check_text"); + check(id, has(res.drv_text, "own checks")); + idf(id, sizeof id, t[k].tag, "balanced"); + check(id, balanced(t[k].frees)); + } +} + +static void case_submit_fail(void) +{ + int rc; + begin_case(); + fk.submit_fail = 1; + rc = run(); + check("sim_submit_fail_name_step_state", + rc == OMEGA_GPU_ENGINE_SUBMIT && + res_is(OMEGA_GPU_ENGINE_SUBMIT, OMEGA_GPU_ENGINE_STEP_SUBMIT, OMEGA_GPU_ENGINE_STATE_PREPARED)); + check("sim_submit_fail_errno_code_text", + res.err_no == EIO && res.drv_rc == -1 && strcmp(res.drv_text, FK_TEXT) == 0); + check("sim_submit_fail_is_not_uncertain", + res.retained == 0 && omega_gpu_engine_is_blocked() == 0 && fk.kernel_ran == 0); + check("sim_submit_fail_cleaned_up", balanced(8)); +} + +/* One uncertain completion: the engine keeps everything and blocks the process. + * Asserts that, asserts the next job is refused without touching the driver, asserts + * a second open of the backend is refused, drains, and proves the backend works again. */ +static void uncertain_case(const char *tag, int mk, int mk2, int sem, uint32_t flags, + int failure, int step, int wait, uint64_t limit, uint64_t waited, + uint32_t want_marker, uint32_t want_marker2, uint32_t want_sem, + uint32_t want_sync, const char *want_text, int want_drv_rc) +{ + char id[96]; + int rc; + int bad; + int open_before; + OmegaBlackwellEngineRunInfo info; + + begin_case(); + fk.marker_mode = mk; + fk.marker2_mode = mk2; + fk.sem_mode = sem; + job.flags = flags; + rc = run(); + + idf(id, sizeof id, tag, "name_step_wait"); + check(id, rc == failure && res.failure == failure && res.failed_step == step && res.wait == wait); + idf(id, sizeof id, tag, "last_state_submitted"); + check(id, res.last_state == OMEGA_GPU_ENGINE_STATE_SUBMITTED); + idf(id, sizeof id, tag, "limit_and_waited_ms"); + check(id, res.wait_timeout_ms == limit && res.waited_ms == waited); + idf(id, sizeof id, tag, "observed_words"); + check(id, res.marker == want_marker && res.marker2 == want_marker2 && + res.semaphore[0] == want_sem); + idf(id, sizeof id, tag, "sync_valid_mask"); + check(id, res.sync_valid == want_sync); + if (want_text != NULL) { + idf(id, sizeof id, tag, "driver_text"); + check(id, has(res.drv_text, want_text)); + } + idf(id, sizeof id, tag, "retained_and_blocked"); + check(id, res.retained == 1 && omega_gpu_engine_is_blocked() == 1); + idf(id, sizeof id, tag, "nothing_freed_nothing_closed"); + check(id, fk.free_calls == 0 && fk.close_calls == 0 && fk.live == 8 && fk.device_open == 1 && + tcount(T_FREE) == 0 && tcount(T_CLOSE) == 0); + + idf(id, sizeof id, tag, "driver_code"); + check(id, res.drv_rc == want_drv_rc); + memset(&info, 0, sizeof info); + omega_blackwell_engine_run_info(&info); + idf(id, sizeof id, tag, "run_info_marker"); + check(id, info.marker == want_marker && info.launch_ns != 0u); + idf(id, sizeof id, tag, "run_info_done_time_only_if_marker_succeeded"); + check(id, (step == OMEGA_GPU_ENGINE_STEP_WAIT_MARKER) == (info.marker_done_ns == 0u)); + idf(id, sizeof id, tag, "run_info_marker2_when_it_was_the_failed_wait"); + check(id, step != OMEGA_GPU_ENGINE_STEP_WAIT_MARKER2 || info.marker2 == want_marker2); + idf(id, sizeof id, tag, "run_info_semaphore_when_it_was_the_failed_wait"); + check(id, step != OMEGA_GPU_ENGINE_STEP_WAIT_RELEASE_SEMAPHORE || info.semaphore == want_sem); + idf(id, sizeof id, tag, "no_marker2_wait_with_noc3"); + check(id, (flags & OMEGA_GPU_ENGINE_FLAG_NO_C3) == 0u || (fk.wait_n[FK_W_MARKER2] == 0 && tcount(T_WAIT2) == 0)); + open_before = fk.open_calls; + rc = run(); + idf(id, sizeof id, tag, "next_job_blocked"); + check(id, rc == OMEGA_GPU_ENGINE_UNCERTAIN_COMPLETION_BLOCKED && + res.failed_step == OMEGA_GPU_ENGINE_STEP_BLOCKED && fk.open_calls == open_before); + idf(id, sizeof id, tag, "second_open_refused_by_backend"); + check(id, g_real->open_device(g_real->ctx) != 0 && fk.open_calls == open_before); + idf(id, sizeof id, tag, "still_retained_after_refusals"); + check(id, fk.live == 8 && fk.device_open == 1 && fk.close_calls == 0); + + bad = drain(); + idf(id, sizeof id, tag, "drained_through_the_table"); + check(id, bad == 0 && fk.close_calls == 1 && fk.live_at_close == 0 && fk.double_free == 0 && + fk.free_calls == 8); + omega_gpu_engine_test_reset_block(); + make_job(&job); + /* The simulated driver still has the hang or overshoot of this case armed: restore a healthy chip. */ + fk.marker_mode = FK_SYNC_NORMAL; + fk.marker2_mode = FK_SYNC_NORMAL; + fk.sem_mode = FK_SYNC_NORMAL; + idf(id, sizeof id, tag, "backend_works_again_after_drain"); + check(id, run() == OMEGA_GPU_ENGINE_OK && output_correct(outbuf)); +} + +static void case_uncertain(void) +{ + const uint32_t all = OMEGA_GPU_SYNC_MARKER | OMEGA_GPU_SYNC_MARKER2 | OMEGA_GPU_SYNC_SEMAPHORE; + + uncertain_case("unc_marker_hang", FK_SYNC_NEVER, FK_SYNC_NORMAL, FK_SYNC_NORMAL, 0u, + OMEGA_GPU_ENGINE_COMPLETION_WAIT, OMEGA_GPU_ENGINE_STEP_WAIT_MARKER, + OMEGA_GPU_ENGINE_WAIT_MARKER, TMO_MARKER, TMO_MARKER, + 0u, MARKER2_PAYLOAD, SEM_DONE, all, NULL, -1); + uncertain_case("unc_marker2_hang", FK_SYNC_NORMAL, FK_SYNC_NEVER, FK_SYNC_NORMAL, 0u, + OMEGA_GPU_ENGINE_COMPLETION_WAIT, OMEGA_GPU_ENGINE_STEP_WAIT_MARKER2, + OMEGA_GPU_ENGINE_WAIT_MARKER2, TMO_MARKER2, TMO_MARKER2, + MARKER1_PAYLOAD, 0u, SEM_DONE, all, NULL, -1); + uncertain_case("unc_semaphore_hang", FK_SYNC_NORMAL, FK_SYNC_NORMAL, FK_SYNC_NEVER, 0u, + OMEGA_GPU_ENGINE_RELEASE_WAIT, OMEGA_GPU_ENGINE_STEP_WAIT_RELEASE_SEMAPHORE, + OMEGA_GPU_ENGINE_WAIT_RELEASE_SEMAPHORE, TMO_RELEASE, TMO_RELEASE, + MARKER1_PAYLOAD, MARKER2_PAYLOAD, SEM_INIT, all, NULL, -1); + uncertain_case("unc_marker_overshoot", FK_SYNC_OVERSHOOT, FK_SYNC_NORMAL, FK_SYNC_NORMAL, 0u, + OMEGA_GPU_ENGINE_COMPLETION_WAIT, OMEGA_GPU_ENGINE_STEP_WAIT_MARKER, + OMEGA_GPU_ENGINE_WAIT_MARKER, TMO_MARKER, 0u, + MARKER1_PAYLOAD + 1u, MARKER2_PAYLOAD, SEM_DONE, all, "observed 0x44444445", 0); + uncertain_case("unc_marker2_overshoot", FK_SYNC_NORMAL, FK_SYNC_OVERSHOOT, FK_SYNC_NORMAL, 0u, + OMEGA_GPU_ENGINE_COMPLETION_WAIT, OMEGA_GPU_ENGINE_STEP_WAIT_MARKER2, + OMEGA_GPU_ENGINE_WAIT_MARKER2, TMO_MARKER2, 0u, + MARKER1_PAYLOAD, MARKER2_PAYLOAD + 1u, SEM_DONE, all, "observed 0x46464647", 0); + uncertain_case("unc_semaphore_overshoot", FK_SYNC_NORMAL, FK_SYNC_NORMAL, FK_SYNC_OVERSHOOT, 0u, + OMEGA_GPU_ENGINE_RELEASE_WAIT, OMEGA_GPU_ENGINE_STEP_WAIT_RELEASE_SEMAPHORE, + OMEGA_GPU_ENGINE_WAIT_RELEASE_SEMAPHORE, TMO_RELEASE, 0u, + MARKER1_PAYLOAD, MARKER2_PAYLOAD, SEM_DONE + 1u, all, "observed 0x00000007", 0); + /* NO_C3: the second marker does not exist, so it is never reported either. */ + uncertain_case("unc_noc3_semaphore_hang", FK_SYNC_NORMAL, FK_SYNC_NORMAL, FK_SYNC_NEVER, + OMEGA_GPU_ENGINE_FLAG_NO_C3, + OMEGA_GPU_ENGINE_RELEASE_WAIT, OMEGA_GPU_ENGINE_STEP_WAIT_RELEASE_SEMAPHORE, + OMEGA_GPU_ENGINE_WAIT_RELEASE_SEMAPHORE, TMO_RELEASE, TMO_RELEASE, + MARKER1_PAYLOAD, 0u, SEM_INIT, OMEGA_GPU_SYNC_MARKER | OMEGA_GPU_SYNC_SEMAPHORE, NULL, -1); +} + +static void case_cleanup_faults(void) +{ + int rc; + + /* a free of an ordinary buffer fails: every other free still runs */ + begin_case(); + fk.free_fail_nth = 1; + rc = run(); + check("sim_cleanup_free_role_name_step_state", + rc == OMEGA_GPU_ENGINE_CLEANUP && + res_is(OMEGA_GPU_ENGINE_CLEANUP, OMEGA_GPU_ENGINE_STEP_FREE, + OMEGA_GPU_ENGINE_STATE_OUTPUT_PRODUCED)); + check("sim_cleanup_free_role_flag_errno_text", + res.cleanup_failed == 1 && res.err_no == EIO && strcmp(res.drv_text, FK_TEXT) == 0); + check("sim_cleanup_free_role_every_free_attempted_and_closed", + fk.free_calls == 8 && fk.close_calls == 1 && fk.live_at_close == 1); + check("sim_cleanup_free_role_words_still_mapped_at_capture", + res.sync_valid == (OMEGA_GPU_SYNC_MARKER | OMEGA_GPU_SYNC_MARKER2 | OMEGA_GPU_SYNC_SEMAPHORE) && + res.marker == MARKER1_PAYLOAD && res.marker2 == MARKER2_PAYLOAD && res.semaphore[0] == SEM_DONE); + check("sim_cleanup_free_role_not_uncertain", res.retained == 0 && omega_gpu_engine_is_blocked() == 0); + + /* a free of one SCRATCH part fails (the marker page, sixth real free): the + * other scratch parts are still freed and the sync words are unmapped first */ + begin_case(); + fk.free_fail_nth = 6; + rc = run(); + check("sim_cleanup_free_scratch_name_step_state", + rc == OMEGA_GPU_ENGINE_CLEANUP && + res_is(OMEGA_GPU_ENGINE_CLEANUP, OMEGA_GPU_ENGINE_STEP_FREE, + OMEGA_GPU_ENGINE_STATE_OUTPUT_PRODUCED)); + check("sim_cleanup_free_scratch_code_and_text", + res.cleanup_failed == 1 && res.drv_rc == -1 && strcmp(res.drv_text, FK_TEXT) == 0); + check("sim_cleanup_free_scratch_all_four_parts_attempted", + fk.free_calls == 8 && fk.close_calls == 1 && fk.live_at_close == 1); + check("sim_cleanup_free_scratch_sync_words_unmapped_before_free", res.sync_valid == 0u); + + /* close fails */ + begin_case(); + fk.close_fail = 1; + rc = run(); + check("sim_cleanup_close_name_step_state", + rc == OMEGA_GPU_ENGINE_CLEANUP && + res_is(OMEGA_GPU_ENGINE_CLEANUP, OMEGA_GPU_ENGINE_STEP_CLOSE, + OMEGA_GPU_ENGINE_STATE_OUTPUT_PRODUCED)); + check("sim_cleanup_close_flag_errno_text", + res.cleanup_failed == 1 && res.err_no == EIO && strcmp(res.drv_text, FK_TEXT) == 0); + check("sim_cleanup_close_all_freed_first", fk.free_calls == 8 && fk.live_at_close == 0); + begin_case(); + check("sim_cleanup_close_failure_still_releases_busy_flag", run() == OMEGA_GPU_ENGINE_OK); +} + +static void case_unchanged(void) +{ + int rc; + + begin_case(); + fk.kernel_mode = FK_KERNEL_NO_WRITE; + rc = run(); + check("sim_unchanged_nowrite_name_step_state", + rc == OMEGA_GPU_ENGINE_OUTPUT_UNCHANGED && + res_is(OMEGA_GPU_ENGINE_OUTPUT_UNCHANGED, OMEGA_GPU_ENGINE_STEP_SCAN, + OMEGA_GPU_ENGINE_STATE_OUTPUT_VISIBLE)); + check("sim_unchanged_nowrite_counts_every_word", + res.n_outputs == 1u && res.output_unchanged_words[0] == N); + check("sim_unchanged_nowrite_completion_was_seen", + fk.kernel_ran == 1 && fk.wait_n[FK_W_MARKER1] == 1 && fk.wait_n[FK_W_SEM] == 1); + check("sim_unchanged_nowrite_cleaned_up_not_retained", + balanced(8) && res.retained == 0 && omega_gpu_engine_is_blocked() == 0); + + begin_case(); + fk.kernel_mode = FK_KERNEL_HALF; + rc = run(); + check("sim_unchanged_half_counts_the_unwritten_half", + rc == OMEGA_GPU_ENGINE_OUTPUT_UNCHANGED && res.output_unchanged_words[0] == N / 2u); + + /* the device runs different program bytes than the job supplied: it writes nothing */ + begin_case(); + fk.prog_expect = prog_other; + rc = run(); + check("sim_unchanged_wrong_program_bytes_detected", + rc == OMEGA_GPU_ENGINE_OUTPUT_UNCHANGED && fk.kernel_ran == 1 && fk.prog_matched == 0 && + res.output_unchanged_words[0] == N); +} + +static void case_table_guards(void) +{ + const OmegaGpuBackend *be = omega_blackwell_engine_backend(); + void *ctx = be->ctx; + OmegaGpuJob j; + int role; + int bad = 0; + + begin_case(); + memset(&j, 0, sizeof j); + j.layout = OMEGA_GPU_LAYOUT_VECTOR_1D; + j.element_count = N; + + check("sim_guard_open_ok", be->open_device(ctx) == 0); + check("sim_guard_channel_ok", be->create_channel(ctx) == 0); + check("sim_guard_alloc_zero_bytes_refused", be->alloc(ctx, (int)OMEGA_GPU_BUF_OUTPUT, 0u) != 0); + check("sim_guard_alloc_unknown_role_refused", be->alloc(ctx, 99, 4096u) != 0); + check("sim_guard_alloc_rounds_up_to_whole_pages", + be->alloc(ctx, (int)OMEGA_GPU_BUF_OUTPUT, 5000u) == 0 && fake_count(FK_EV_ALLOC) == 1 && + fk.ev[fake_nth(FK_EV_ALLOC, 1)].a == 0x2000u); + check("sim_guard_free_after_rounding_ok", be->free_buf(ctx, (int)OMEGA_GPU_BUF_OUTPUT) == 0); + check("sim_guard_wait_before_build_refused_without_driver_call", + be->wait_marker(ctx, 5u) != 0 && be->wait_marker2(ctx, 5u) != 0 && + be->wait_release_semaphore(ctx, 5u) != 0 && fk.wait_calls == 0); + check("sim_guard_submit_before_build_refused", be->submit(ctx) != 0); + check("sim_guard_build_without_buffers_refused", be->build(ctx, &j) != 0); + + check("sim_guard_alloc_scratch_ok", be->alloc(ctx, (int)OMEGA_GPU_BUF_SCRATCH, 0u) == 0); + check("sim_guard_alloc_program_ok", be->alloc(ctx, (int)OMEGA_GPU_BUF_PROGRAM, sizeof prog) == 0); + check("sim_guard_alloc_a_ok", be->alloc(ctx, (int)OMEGA_GPU_BUF_INPUT_A, N * 4u) == 0); + check("sim_guard_alloc_b_ok", be->alloc(ctx, (int)OMEGA_GPU_BUF_INPUT_B, N * 4u) == 0); + check("sim_guard_alloc_output_ok", be->alloc(ctx, (int)OMEGA_GPU_BUF_OUTPUT, N * 4u) == 0); + check("sim_guard_copy_in_negative_role_refused", be->copy_in(ctx, -1, prog, sizeof prog) != 0); + check("sim_guard_free_negative_role_refused", be->free_buf(ctx, -1) != 0); + check("sim_guard_build_null_job_refused", be->build(ctx, NULL) != 0); + j.layout = 7; + check("sim_guard_build_unknown_layout_refused", be->build(ctx, &j) != 0); + j.layout = (int)OMEGA_GPU_LAYOUT_VECTOR_1D; + j.element_count = 0u; + check("sim_guard_build_zero_count_refused", be->build(ctx, &j) != 0); + j.element_count = 2000u; + check("sim_guard_build_count_beyond_the_buffers_refused", be->build(ctx, &j) != 0); + j.element_count = N; + + check("sim_guard_copy_in_too_long_refused", + be->copy_in(ctx, (int)OMEGA_GPU_BUF_PROGRAM, bigbytes, 0x1000u + 8u) != 0); + check("sim_guard_copy_in_unknown_role_refused", be->copy_in(ctx, 99, prog, sizeof prog) != 0); + check("sim_guard_copy_in_null_source_refused", + be->copy_in(ctx, (int)OMEGA_GPU_BUF_PROGRAM, NULL, sizeof prog) != 0); + check("sim_guard_fill_poison_too_long_refused", + be->fill_poison(ctx, bigwords, 0x1000u / 4u + 1u) != 0); + check("sim_guard_fill_poison_null_refused", be->fill_poison(ctx, NULL, N) != 0); + check("sim_guard_copy_out_too_long_refused", + be->copy_out(ctx, bigbytes, 0x1000u + 8u) != 0); + check("sim_guard_copy_out_null_refused", be->copy_out(ctx, NULL, N * 4u) != 0); + check("sim_guard_free_unknown_role_refused", be->free_buf(ctx, 99) != 0); + + check("sim_guard_valid_copy_in_ok", be->copy_in(ctx, (int)OMEGA_GPU_BUF_PROGRAM, prog, sizeof prog) == 0); + check("sim_guard_valid_fill_poison_ok", be->fill_poison(ctx, poison, N) == 0); + memset(bigbytes, 0, sizeof bigbytes); + check("sim_guard_valid_copy_out_returns_the_poison", + be->copy_out(ctx, bigbytes, N * 4u) == 0 && memcmp(bigbytes, poison, N * 4u) == 0); + + for (role = (int)OMEGA_GPU_BUF_ROLE_COUNT - 1; role >= 0; role--) + if (be->free_buf(ctx, role) != 0) bad = 1; + if (be->close(ctx) != 0) bad = 1; + check("sim_guard_drain_ok", bad == 0); + check("sim_guard_nothing_leaked", fk.live_at_close == 0 && fk.double_free == 0 && fk.close_calls == 1); +} + +/* A close without the SCRATCH free (a backend that is closed with its words still + * mapped) must stop reading the sync words: the memory is gone. */ +static void case_close_unmaps_sync_words(void) +{ + const OmegaGpuBackend *be = omega_blackwell_engine_backend(); + void *ctx = be->ctx; + OmegaGpuBackendDiag d; + OmegaGpuJob j; + int ok; + + begin_case(); + make_job(&j); + ok = be->open_device(ctx) == 0 && be->create_channel(ctx) == 0 && + be->alloc(ctx, (int)OMEGA_GPU_BUF_SCRATCH, 0u) == 0 && + be->alloc(ctx, (int)OMEGA_GPU_BUF_PROGRAM, sizeof prog) == 0 && + be->alloc(ctx, (int)OMEGA_GPU_BUF_INPUT_A, N * 4u) == 0 && + be->alloc(ctx, (int)OMEGA_GPU_BUF_INPUT_B, N * 4u) == 0 && + be->alloc(ctx, (int)OMEGA_GPU_BUF_OUTPUT, N * 4u) == 0 && + be->build(ctx, &j) == 0; + check("sim_close_setup_through_the_table", ok); + memset(&d, 0, sizeof d); + be->diagnostics(ctx, &d); + check("sim_close_words_mapped_after_build", + d.sync_valid == (OMEGA_GPU_SYNC_MARKER | OMEGA_GPU_SYNC_MARKER2 | OMEGA_GPU_SYNC_SEMAPHORE)); + check("sim_close_returns_zero", be->close(ctx) == 0); + memset(&d, 0, sizeof d); + be->diagnostics(ctx, &d); + check("sim_close_unmaps_every_sync_word", d.sync_valid == 0u); + check("sim_close_released_everything", fk.close_calls == 1 && fk.live == 0); +} + +/* Like begin_case, for the vector wrapper: the device must see the encoder's real + * program bytes, and no backend is installed, so the wrapper has to install its own. */ +static void begin_vec(void) +{ + begin_case(); + omega_gpu_engine_set_backend(NULL); + fk.prog_expect = vec_code; + fk.prog_len = vec_len; +} + +static void case_vector(void) +{ + OmegaVectorSpec spec; + OmegaBlackwellRealization real; + OmegaBlackwellVectorExecution info; + uint32_t c[N]; + uint32_t i; + int rc; + int ok; + uint64_t want_elapsed; + + memset(&real, 0, sizeof real); + real.sm_architecture = OMEGA_BW_SM_ARCH_121; + check("sim_vec_spec_init", omega_vector_spec_init(&spec, "engine_sim", N) == 0); + + /* success */ + begin_vec(); + memset(c, 0, sizeof c); + memset(&info, 0xff, sizeof info); + rc = omega_blackwell_execute_vector(&spec, &real, ina, inb, c, &info); + check("sim_vec_success_returns_zero", rc == 0); + check("sim_vec_success_output_values", output_correct(c)); + check("sim_vec_success_parity_verified", info.parity_verified == true); + check("sim_vec_success_completion_marker_and_semaphore", + info.completion_marker == MARKER1_PAYLOAD && info.intermediate_semaphore == SEM_DONE); + check("sim_vec_success_shape_fields", + info.element_count == N && info.sm_architecture == (uint32_t)OMEGA_BW_SM_ARCH_121 && + info.target_chip[0] != '\0'); + want_elapsed = info.completion_timestamp_ns > info.launch_timestamp_ns ? + info.completion_timestamp_ns - info.launch_timestamp_ns : 0u; + check("sim_vec_success_timestamps", + info.launch_timestamp_ns != 0u && info.completion_timestamp_ns != 0u && + info.elapsed_ns == want_elapsed); + check("sim_vec_success_timeouts_are_5000_each", + fk.wait_ms[FK_W_MARKER1] == 5000u && fk.wait_ms[FK_W_MARKER2] == 5000u && + fk.wait_ms[FK_W_SEM] == 5000u); + check("sim_vec_success_all_protections_on", + fake_count(FK_EV_PB_FLUSH) == 1 && fake_count(FK_EV_PB_RELEASE) == 2 && + fk.wait_n[FK_W_MARKER2] == 1); + check("sim_vec_success_encoded_program_reached_the_device", + fk.kernel_ran == 1 && fk.prog_matched == 1); + ok = fk.snap_n == N; + for (i = 0; ok && i < N; i++) + if (fk.out_before[i] != (uint32_t)~expect_out[i]) ok = 0; + check("sim_vec_success_poison_is_the_complement_of_the_sum", ok); + check("sim_vec_success_poison_never_collides_even_for_0xdeadbeef", fk.poison_collisions == 0); + check("sim_vec_success_balanced", balanced(8)); + + /* wrong math on the device: the engine passes it (it only checks poison), the wrapper must not */ + begin_vec(); + fk.kernel_mode = FK_KERNEL_WRONG; + memset(c, 0, sizeof c); + memset(&info, 0, sizeof info); + rc = omega_blackwell_execute_vector(&spec, &real, ina, inb, c, &info); + check("sim_vec_wrong_math_returns_nonzero", rc != 0); + check("sim_vec_wrong_math_parity_not_verified", info.parity_verified == false); + + /* a cleanup fault after a good run is still a failure */ + begin_vec(); + fk.free_fail_nth = 1; + memset(c, 0, sizeof c); + rc = omega_blackwell_execute_vector(&spec, &real, ina, inb, c, &info); + check("sim_vec_cleanup_fault_returns_nonzero", rc != 0); + + /* the device wrote nothing */ + begin_vec(); + fk.kernel_mode = FK_KERNEL_NO_WRITE; + memset(c, 0, sizeof c); + rc = omega_blackwell_execute_vector(&spec, &real, ina, inb, c, &info); + check("sim_vec_unwritten_output_returns_nonzero", rc != 0); + + /* a hung first marker: failure, process blocked, backend retained */ + begin_vec(); + fk.marker_mode = FK_SYNC_NEVER; + memset(c, 0, sizeof c); + rc = omega_blackwell_execute_vector(&spec, &real, ina, inb, c, &info); + check("sim_vec_hang_returns_nonzero", rc != 0); + check("sim_vec_hang_blocks_the_process_and_retains", + omega_gpu_engine_is_blocked() == 1 && fk.free_calls == 0 && fk.close_calls == 0); + check("sim_vec_hang_drains", drain() == 0 && fk.live_at_close == 0); + omega_gpu_engine_test_reset_block(); + + /* refusals before any driver call */ + begin_vec(); + check("sim_vec_null_spec_refused", omega_blackwell_execute_vector(NULL, &real, ina, inb, c, &info) != 0); + check("sim_vec_null_output_refused", omega_blackwell_execute_vector(&spec, &real, ina, inb, NULL, &info) != 0); + check("sim_vec_null_input_refused", omega_blackwell_execute_vector(&spec, &real, NULL, inb, c, &info) != 0); + spec.element_count = 0u; + check("sim_vec_zero_count_refused", omega_blackwell_execute_vector(&spec, &real, ina, inb, c, &info) != 0); + check("sim_vec_refusals_never_touch_the_driver", fk.open_calls == 0 && fk.alloc_calls == 0); + spec.element_count = N; + + /* the wrapper can be used again afterwards (busy flag, block, tracing table) */ + begin_vec(); + memset(c, 0, sizeof c); + rc = omega_blackwell_execute_vector(&spec, &real, ina, inb, c, &info); + check("sim_vec_works_again", rc == 0 && output_correct(c)); +} + +int main(void) +{ + init_data(); + wrap_init(); + omega_gpu_engine_test_set_clock(fake_now_ms); + check("sim_setup_encoder_ok", + omega_blackwell_encode_vecadd(vec_code, sizeof vec_code, &vec_len) == 0 && vec_len > 0u); + + case_success(); + case_no_c3(); + case_back_to_back(); + case_open_fail(); + case_channel_fail(); + case_alloc_faults(); + case_alloc_own_checks(); + case_submit_fail(); + case_uncertain(); + case_cleanup_faults(); + case_unchanged(); + case_table_guards(); + case_close_unmaps_sync_words(); + case_vector(); + + omega_gpu_engine_set_backend(NULL); + omega_gpu_engine_test_reset_block(); + omega_gpu_engine_test_set_clock(NULL); + fake_reset(); + printf("SUMMARY passed=%d failed=%d\n", n_pass, n_fail); + return n_fail ? 1 : 0; +} diff --git a/tests/test_omega_gpu_engine.c b/tests/test_omega_gpu_engine.c new file mode 100644 index 000000000..d0eec4624 --- /dev/null +++ b/tests/test_omega_gpu_engine.c @@ -0,0 +1,1122 @@ +/* + * Host test of the Omega GPU Engine core (A3a) against a FAKE backend. + * No device, no physics headers. Every case prints "[PASS] id" or "[FAIL] id"; + * the last line is "SUMMARY passed=N failed=M"; exit status is nonzero on any + * failure. docs/numeric/OMEGA_GPU_ENGINE.md section 13 lists every case id. + * + * The fake records every backend call in order, can fail the n-th call of any + * kind with a chosen return code (and advance a fake clock), simulates device + * memory (poison fill, a kernel that writes a chosen word range, copy-in and + * copy-out) and flags protocol violations (free of a buffer that is not + * allocated, copy-in to an unallocated buffer, and so on). + */ +#include "omega_gpu_engine.h" + +#include <errno.h> +#include <stdio.h> +#include <string.h> + +#define N 16u +#define INJ_ERRNO EIO +#define DIAG_RC (-1234) +#define DIAG_TEXT "fake driver text" +#define LOGMAX 64 +#define TMO_MARKER 111u +#define TMO_MARKER2 222u +#define TMO_RELEASE 333u +#define TMO_VISIBILITY 444u + +enum { + C_OPEN = 0, C_CHANNEL, C_ALLOC, C_COPY_IN, C_POISON, C_BUILD, C_SUBMIT, C_MARKER, + C_MARKER2, C_RELEASE, C_BARRIER, C_COPY_OUT, C_FREE, C_CLOSE, C_DIAG, C_COUNT +}; + +typedef struct { + int call; /* which kind of call to fail */ + int nth; /* 1-based occurrence of that kind */ + int rc; /* value the call returns */ + int advance; /* fake milliseconds the call takes */ +} Inj; + +typedef struct { + int log[LOGMAX]; /* every call except diagnostics, in order */ + int nlog; + int count[C_COUNT]; + int state_at[C_COUNT]; /* result->last_state at the first call of each kind, -1 if never */ + uint64_t tmo[C_COUNT]; /* timeout last passed to a timed call */ + Inj inj[2]; + int ninj; + int violations; + int dev_open; + int channel; + int live[OMEGA_GPU_BUF_ROLE_COUNT]; + int alloc_roles[8]; + size_t alloc_bytes[8]; + int nalloc; + int copy_roles[8]; + size_t copy_bytes[8]; + int ncopy; + int free_roles[8]; + int nfree; + uint32_t dev_prog[16]; + uint32_t dev_a[N]; + uint32_t dev_b[N]; + uint32_t dev_out[N]; + uint32_t seen_at_submit[N]; + int submit_seen; + const OmegaGpuJob *build_job; + size_t klo; /* the fake kernel writes output words [klo, khi) */ + size_t khi; +} Fake; + +static Fake F; +static OmegaGpuResult *g_res; /* result being filled, to snapshot last_state at each call */ +static uint64_t g_time; /* fake clock, milliseconds */ +static OmegaGpuBackend BE; + +static const unsigned char code[8] = {1, 2, 3, 4, 5, 6, 7, 8}; +static uint32_t ina[N]; +static uint32_t inb[N]; +static uint32_t poison[N]; +static uint32_t host_out[N + 4u]; /* four spare words so a stray write is visible, not fatal */ + +static int case_ok; +static int n_pass; +static int n_fail; + +#define EXPECT(c) do { if (!(c)) { case_ok = 0; printf(" expect failed at line %d: %s\n", __LINE__, #c); } } while (0) + +static void case_begin(void) { case_ok = 1; } + +static void case_end(const char *id) +{ + if (case_ok) { n_pass++; printf("[PASS] %s\n", id); } + else { n_fail++; printf("[FAIL] %s\n", id); } +} + +static uint64_t fake_now(void) { return g_time; } + +static uint32_t exp_out(size_t i) { return ina[i] + inb[i] + 0x100u; } + +/* ---- the fake backend ---------------------------------------------------- */ + +static int hit(int call) +{ + int i; + int n; + if (F.nlog < LOGMAX) F.log[F.nlog] = call; + F.nlog++; + n = ++F.count[call]; + if (F.state_at[call] < 0 && g_res) F.state_at[call] = g_res->last_state; + for (i = 0; i < F.ninj; i++) { + if (F.inj[i].call == call && F.inj[i].nth == n) { + g_time += (uint64_t)F.inj[i].advance; + errno = INJ_ERRNO; + return F.inj[i].rc; + } + } + return 0; +} + +static int f_open(void *c) +{ + int rc; + (void)c; + rc = hit(C_OPEN); + if (rc == 0) F.dev_open = 1; + return rc; +} + +static int f_channel(void *c) +{ + int rc; + (void)c; + rc = hit(C_CHANNEL); + if (rc != 0) return rc; + if (!F.dev_open) F.violations++; + F.channel = 1; + return 0; +} + +static int role_ok(int role) +{ + return role >= 0 && role < (int)OMEGA_GPU_BUF_ROLE_COUNT; +} + +static int f_alloc(void *c, int role, size_t bytes) +{ + int rc; + (void)c; + rc = hit(C_ALLOC); + if (rc != 0) return rc; + if (!role_ok(role) || F.live[role] || !F.channel) { F.violations++; return 0; } + F.live[role] = 1; + if (F.nalloc < 8) { F.alloc_roles[F.nalloc] = role; F.alloc_bytes[F.nalloc] = bytes; } + F.nalloc++; + return 0; +} + +static int f_copy_in(void *c, int role, const void *src, size_t bytes) +{ + int rc; + (void)c; + rc = hit(C_COPY_IN); + if (rc != 0) return rc; + if (!role_ok(role) || !F.live[role]) { F.violations++; return 0; } + if (F.ncopy < 8) { F.copy_roles[F.ncopy] = role; F.copy_bytes[F.ncopy] = bytes; } + F.ncopy++; + switch (role) { + case OMEGA_GPU_BUF_PROGRAM: + if (bytes > sizeof F.dev_prog) { F.violations++; break; } + memcpy(F.dev_prog, src, bytes); + break; + case OMEGA_GPU_BUF_INPUT_A: + if (bytes > sizeof F.dev_a) { F.violations++; break; } + memcpy(F.dev_a, src, bytes); + break; + case OMEGA_GPU_BUF_INPUT_B: + if (bytes > sizeof F.dev_b) { F.violations++; break; } + memcpy(F.dev_b, src, bytes); + break; + default: + F.violations++; + break; + } + return 0; +} + +static int f_poison(void *c, const uint32_t *words, size_t count) +{ + int rc; + (void)c; + rc = hit(C_POISON); + if (rc != 0) return rc; + if (!F.live[OMEGA_GPU_BUF_OUTPUT] || count != N) { F.violations++; return 0; } + memcpy(F.dev_out, words, count * sizeof(uint32_t)); + return 0; +} + +static int f_build(void *c, const OmegaGpuJob *job) +{ + int rc; + (void)c; + rc = hit(C_BUILD); + if (rc != 0) return rc; + F.build_job = job; + return 0; +} + +static int f_submit(void *c) +{ + int rc; + size_t i; + (void)c; + rc = hit(C_SUBMIT); + if (rc != 0) return rc; + memcpy(F.seen_at_submit, F.dev_out, sizeof F.dev_out); + F.submit_seen = 1; + for (i = F.klo; i < F.khi && i < N; i++) F.dev_out[i] = F.dev_a[i] + F.dev_b[i] + 0x100u; + return 0; +} + +static int f_wait_marker(void *c, uint64_t ms) +{ + (void)c; + F.tmo[C_MARKER] = ms; + return hit(C_MARKER); +} + +static int f_wait_marker2(void *c, uint64_t ms) +{ + (void)c; + F.tmo[C_MARKER2] = ms; + return hit(C_MARKER2); +} + +static int f_wait_release(void *c, uint64_t ms) +{ + (void)c; + F.tmo[C_RELEASE] = ms; + return hit(C_RELEASE); +} + +static int f_barrier(void *c, uint64_t ms) +{ + (void)c; + F.tmo[C_BARRIER] = ms; + return hit(C_BARRIER); +} + +static int f_copy_out(void *c, void *dst, size_t bytes) +{ + int rc; + (void)c; + rc = hit(C_COPY_OUT); + if (rc != 0) return rc; + if (bytes != sizeof F.dev_out) { F.violations++; return 0; } + memcpy(dst, F.dev_out, bytes); + return 0; +} + +static void f_diag(void *c, OmegaGpuBackendDiag *d) +{ + (void)c; + F.count[C_DIAG]++; + d->drv_rc = DIAG_RC; + memcpy(d->drv_text, DIAG_TEXT, sizeof DIAG_TEXT); + d->sync_valid = OMEGA_GPU_SYNC_MARKER | OMEGA_GPU_SYNC_MARKER2 | OMEGA_GPU_SYNC_SEMAPHORE; + d->marker = 0x11111111u; + d->marker2 = 0x22222222u; + d->semaphore[0] = 0x33333333u; + errno = 0; /* a diagnostics call that clobbers errno must not matter */ +} + +static int f_free(void *c, int role) +{ + int rc; + (void)c; + rc = hit(C_FREE); + if (F.nfree < 8) F.free_roles[F.nfree] = role; + F.nfree++; + if (rc != 0) return rc; + if (!role_ok(role) || !F.live[role]) { F.violations++; return 0; } + F.live[role] = 0; + return 0; +} + +static int f_close(void *c) +{ + int rc; + (void)c; + rc = hit(C_CLOSE); + if (rc != 0) return rc; + if (!F.dev_open) F.violations++; + F.dev_open = 0; + F.channel = 0; + return 0; +} + +static void backend_init(OmegaGpuBackend *b) +{ + memset(b, 0, sizeof *b); + b->ctx = NULL; + b->open_device = f_open; + b->create_channel = f_channel; + b->alloc = f_alloc; + b->copy_in = f_copy_in; + b->fill_poison = f_poison; + b->build = f_build; + b->submit = f_submit; + b->wait_marker = f_wait_marker; + b->wait_marker2 = f_wait_marker2; + b->wait_release_semaphore = f_wait_release; + b->barrier = f_barrier; + b->copy_out = f_copy_out; + b->diagnostics = f_diag; + b->free_buf = f_free; + b->close = f_close; +} + +/* ---- case helpers ------------------------------------------------------- */ + +static void reset_all(void) +{ + size_t i; + int k; + memset(&F, 0, sizeof F); + for (k = 0; k < C_COUNT; k++) F.state_at[k] = -1; + for (i = 0; i < N; i++) F.dev_out[i] = 0xA5A5A5A5u; /* garbage, never a poison word */ + F.klo = 0; + F.khi = N; + g_time = 1000u; + memset(host_out, 0xCC, sizeof host_out); + g_res = NULL; + backend_init(&BE); + omega_gpu_engine_test_reset_block(); + omega_gpu_engine_set_backend(&BE); +} + +static void make_job(OmegaGpuJob *j) +{ + size_t i; + for (i = 0; i < N; i++) { + ina[i] = (uint32_t)(i + 1u); + inb[i] = (uint32_t)(2u * i + 3u); + poison[i] = 0xDEAD0000u + (uint32_t)(i * 7u); /* distinct per word, never an expected output */ + } + memset(j, 0, sizeof *j); + j->program = code; + j->program_len = sizeof code; + j->layout = OMEGA_GPU_LAYOUT_VECTOR_1D; + j->element_count = N; + j->input_a = ina; + j->input_a_len = sizeof ina; + j->input_b = inb; + j->input_b_len = sizeof inb; + j->output = host_out; + j->output_len = N * sizeof(uint32_t); + j->poison = poison; + j->poison_count = N; + j->timeouts.marker_ms = TMO_MARKER; + j->timeouts.marker2_ms = TMO_MARKER2; + j->timeouts.release_semaphore_ms = TMO_RELEASE; + j->timeouts.visibility_ms = TMO_VISIBILITY; + j->flags = 0; +} + +static void inject(int call, int nth, int rc, int advance) +{ + F.inj[F.ninj].call = call; + F.inj[F.ninj].nth = nth; + F.inj[F.ninj].rc = rc; + F.inj[F.ninj].advance = advance; + F.ninj++; +} + +static int run(const OmegaGpuJob *job, OmegaGpuResult *r) +{ + int rc; + memset(r, 0x7f, sizeof *r); /* stale garbage the engine must fully overwrite */ + g_res = r; + rc = omega_gpu_execute(job, r); + g_res = NULL; + return rc; +} + +static void expect_log(const int *want, int n) +{ + int i; + EXPECT(F.nlog == n); + for (i = 0; i < n && i < F.nlog && i < LOGMAX; i++) EXPECT(F.log[i] == want[i]); +} + +static void expect_failure(int rc, const OmegaGpuResult *r, int failure, int last, int step, int wait) +{ + EXPECT(rc == failure); + EXPECT(r->failure == failure); + EXPECT(r->last_state == last); + EXPECT(r->failed_step == step); + EXPECT(r->wait == wait); +} + +static void expect_passthrough(const OmegaGpuResult *r, int err) +{ + EXPECT(r->drv_rc == DIAG_RC); + EXPECT(r->err_no == err); + EXPECT(strcmp(r->drv_text, DIAG_TEXT) == 0); + EXPECT(r->sync_valid == (OMEGA_GPU_SYNC_MARKER | OMEGA_GPU_SYNC_MARKER2 | OMEGA_GPU_SYNC_SEMAPHORE)); + EXPECT(r->marker == 0x11111111u); + EXPECT(r->marker2 == 0x22222222u); + EXPECT(r->semaphore[0] == 0x33333333u); + EXPECT(F.count[C_DIAG] == 1); +} + +/* Device closed, every buffer freed, nothing broke the fake's protocol, no block. */ +static void expect_released(const OmegaGpuResult *r) +{ + int role; + EXPECT(F.dev_open == 0); + for (role = 0; role < (int)OMEGA_GPU_BUF_ROLE_COUNT; role++) EXPECT(F.live[role] == 0); + EXPECT(F.violations == 0); + EXPECT(omega_gpu_engine_is_blocked() == 0); + EXPECT(r->retained == 0); +} + +/* Uncertain completion: nothing freed or closed, everything retained, process blocked. */ +static void expect_retained(const OmegaGpuResult *r) +{ + int role; + EXPECT(r->retained == 1); + EXPECT(r->cleanup_failed == 0); + EXPECT(F.count[C_FREE] == 0); + EXPECT(F.count[C_CLOSE] == 0); + EXPECT(F.dev_open == 1); + for (role = 0; role < (int)OMEGA_GPU_BUF_ROLE_COUNT; role++) EXPECT(F.live[role] == 1); + EXPECT(F.violations == 0); + EXPECT(omega_gpu_engine_is_blocked() == 1); +} + +static void expect_no_host_output(void) +{ + size_t i; + for (i = 0; i < N; i++) EXPECT(host_out[i] == 0xCCCCCCCCu); +} + +#define PRE_SUBMIT C_OPEN, C_CHANNEL, C_ALLOC, C_ALLOC, C_ALLOC, C_ALLOC, C_ALLOC, \ + C_COPY_IN, C_COPY_IN, C_COPY_IN, C_POISON, C_BUILD, C_SUBMIT +#define FREE5 C_FREE, C_FREE, C_FREE, C_FREE, C_FREE +#define LOGLEN(a) ((int)(sizeof (a) / sizeof (a)[0])) + +/* ---- cases -------------------------------------------------------------- */ + +static void case_success(void) +{ + OmegaGpuJob job; + OmegaGpuResult r; + size_t i; + int rc; + static const int want[] = { PRE_SUBMIT, C_MARKER, C_MARKER2, C_RELEASE, C_BARRIER, C_COPY_OUT, FREE5, C_CLOSE }; + + reset_all(); + make_job(&job); + rc = run(&job, &r); + + case_begin(); + EXPECT(rc == OMEGA_GPU_ENGINE_OK); + EXPECT(r.failure == OMEGA_GPU_ENGINE_OK); + EXPECT(r.last_state == OMEGA_GPU_ENGINE_STATE_SUCCESS); + EXPECT(r.failed_step == OMEGA_GPU_ENGINE_STEP_NONE); + EXPECT(r.wait == OMEGA_GPU_ENGINE_WAIT_NONE); + EXPECT(r.wait_timeout_ms == 0 && r.waited_ms == 0); + EXPECT(r.drv_rc == 0 && r.err_no == 0 && r.drv_text[0] == '\0'); + EXPECT(r.sync_valid == 0 && r.marker == 0 && r.marker2 == 0 && r.semaphore[0] == 0); + EXPECT(r.retained == 0 && r.cleanup_failed == 0); + EXPECT(r.n_outputs == 1u); + EXPECT(r.output_unchanged_words[0] == 0); + for (i = 0; i < N; i++) EXPECT(host_out[i] == exp_out(i)); + for (i = N; i < N + 4u; i++) EXPECT(host_out[i] == 0xCCCCCCCCu); + EXPECT(F.count[C_DIAG] == 0); + expect_released(&r); + case_end("SUCCESS_FULL_RUN"); + + case_begin(); + expect_log(want, LOGLEN(want)); + case_end("CALL_ORDER_FULL_RUN"); + + case_begin(); + EXPECT(F.state_at[C_OPEN] == OMEGA_GPU_ENGINE_STATE_INITIAL); + EXPECT(F.state_at[C_POISON] == OMEGA_GPU_ENGINE_STATE_INITIAL); + EXPECT(F.state_at[C_BUILD] == OMEGA_GPU_ENGINE_STATE_INITIAL); + EXPECT(F.state_at[C_SUBMIT] == OMEGA_GPU_ENGINE_STATE_PREPARED); + EXPECT(F.state_at[C_MARKER] == OMEGA_GPU_ENGINE_STATE_SUBMITTED); + EXPECT(F.state_at[C_MARKER2] == OMEGA_GPU_ENGINE_STATE_SUBMITTED); + EXPECT(F.state_at[C_RELEASE] == OMEGA_GPU_ENGINE_STATE_SUBMITTED); + EXPECT(F.state_at[C_BARRIER] == OMEGA_GPU_ENGINE_STATE_GPU_COMPLETE); + EXPECT(F.state_at[C_COPY_OUT] == OMEGA_GPU_ENGINE_STATE_GPU_COMPLETE); + EXPECT(F.state_at[C_FREE] == OMEGA_GPU_ENGINE_STATE_OUTPUT_PRODUCED); + EXPECT(F.state_at[C_CLOSE] == OMEGA_GPU_ENGINE_STATE_OUTPUT_PRODUCED); + case_end("STATE_ADVANCES_STEP_BY_STEP"); + + case_begin(); + EXPECT(F.nalloc == 5); + for (i = 0; i < 5u; i++) EXPECT(F.alloc_roles[i] == (int)i); + EXPECT(F.alloc_bytes[OMEGA_GPU_BUF_SCRATCH] == 0u); + EXPECT(F.alloc_bytes[OMEGA_GPU_BUF_PROGRAM] == sizeof code); + EXPECT(F.alloc_bytes[OMEGA_GPU_BUF_INPUT_A] == sizeof ina); + EXPECT(F.alloc_bytes[OMEGA_GPU_BUF_INPUT_B] == sizeof inb); + EXPECT(F.alloc_bytes[OMEGA_GPU_BUF_OUTPUT] == N * sizeof(uint32_t)); + EXPECT(F.ncopy == 3); + EXPECT(F.copy_roles[0] == OMEGA_GPU_BUF_PROGRAM && F.copy_bytes[0] == sizeof code); + EXPECT(F.copy_roles[1] == OMEGA_GPU_BUF_INPUT_A && F.copy_bytes[1] == sizeof ina); + EXPECT(F.copy_roles[2] == OMEGA_GPU_BUF_INPUT_B && F.copy_bytes[2] == sizeof inb); + EXPECT(memcmp(F.dev_prog, code, sizeof code) == 0); + EXPECT(F.build_job == &job); + EXPECT(F.nfree == 5); + EXPECT(F.free_roles[0] == OMEGA_GPU_BUF_OUTPUT); + EXPECT(F.free_roles[1] == OMEGA_GPU_BUF_INPUT_B); + EXPECT(F.free_roles[2] == OMEGA_GPU_BUF_INPUT_A); + EXPECT(F.free_roles[3] == OMEGA_GPU_BUF_PROGRAM); + EXPECT(F.free_roles[4] == OMEGA_GPU_BUF_SCRATCH); + case_end("ROLES_BYTES_AND_REVERSE_FREE_ORDER"); + + case_begin(); + EXPECT(F.tmo[C_MARKER] == TMO_MARKER); + EXPECT(F.tmo[C_MARKER2] == TMO_MARKER2); + EXPECT(F.tmo[C_RELEASE] == TMO_RELEASE); + EXPECT(F.tmo[C_BARRIER] == TMO_VISIBILITY); + case_end("PER_STEP_TIMEOUTS_FROM_JOB"); + + case_begin(); + EXPECT(F.submit_seen == 1); + EXPECT(memcmp(F.seen_at_submit, poison, sizeof poison) == 0); + case_end("POISON_WRITTEN_BEFORE_SUBMIT"); +} + +static void case_no_c3(void) +{ + OmegaGpuJob job; + OmegaGpuResult r; + int rc; + static const int want[] = { PRE_SUBMIT, C_MARKER, C_RELEASE, C_BARRIER, C_COPY_OUT, FREE5, C_CLOSE }; + + reset_all(); + make_job(&job); + job.flags = OMEGA_GPU_ENGINE_FLAG_NO_C3; + job.timeouts.marker2_ms = 0; /* ignored with NO_C3 */ + rc = run(&job, &r); + case_begin(); + EXPECT(rc == OMEGA_GPU_ENGINE_OK); + EXPECT(r.last_state == OMEGA_GPU_ENGINE_STATE_SUCCESS); + EXPECT(F.count[C_MARKER2] == 0); + expect_log(want, LOGLEN(want)); + expect_released(&r); + case_end("NO_C3_SKIPS_MARKER2_ONLY"); +} + +static void case_open_channel_alloc_prepare(void) +{ + OmegaGpuJob job; + OmegaGpuResult r; + int rc; + + { + static const int want[] = { C_OPEN }; + reset_all(); make_job(&job); + inject(C_OPEN, 1, -3, 0); + rc = run(&job, &r); + case_begin(); + expect_failure(rc, &r, OMEGA_GPU_ENGINE_DEVICE_OPEN, OMEGA_GPU_ENGINE_STATE_INITIAL, + OMEGA_GPU_ENGINE_STEP_OPEN_DEVICE, OMEGA_GPU_ENGINE_WAIT_NONE); + expect_passthrough(&r, INJ_ERRNO); + expect_log(want, LOGLEN(want)); + expect_released(&r); + expect_no_host_output(); + case_end("FAIL_DEVICE_OPEN"); + } + { + static const int want[] = { C_OPEN, C_CHANNEL, C_CLOSE }; + reset_all(); make_job(&job); + inject(C_CHANNEL, 1, -3, 0); + rc = run(&job, &r); + case_begin(); + expect_failure(rc, &r, OMEGA_GPU_ENGINE_CHANNEL_CREATE, OMEGA_GPU_ENGINE_STATE_INITIAL, + OMEGA_GPU_ENGINE_STEP_CREATE_CHANNEL, OMEGA_GPU_ENGINE_WAIT_NONE); + expect_passthrough(&r, INJ_ERRNO); + expect_log(want, LOGLEN(want)); + expect_released(&r); + expect_no_host_output(); + case_end("FAIL_CHANNEL_CREATE"); + } + { + /* the third allocation (input A) fails: scratch and program are freed, newest first */ + static const int want[] = { C_OPEN, C_CHANNEL, C_ALLOC, C_ALLOC, C_ALLOC, C_FREE, C_FREE, C_CLOSE }; + reset_all(); make_job(&job); + inject(C_ALLOC, 3, -3, 0); + rc = run(&job, &r); + case_begin(); + expect_failure(rc, &r, OMEGA_GPU_ENGINE_ALLOC, OMEGA_GPU_ENGINE_STATE_INITIAL, + OMEGA_GPU_ENGINE_STEP_ALLOC, OMEGA_GPU_ENGINE_WAIT_NONE); + expect_passthrough(&r, INJ_ERRNO); + expect_log(want, LOGLEN(want)); + EXPECT(F.nfree == 2); + EXPECT(F.free_roles[0] == OMEGA_GPU_BUF_PROGRAM && F.free_roles[1] == OMEGA_GPU_BUF_SCRATCH); + expect_released(&r); + expect_no_host_output(); + case_end("FAIL_ALLOC"); + } + { + /* the second copy-in (input A) fails */ + static const int want[] = { C_OPEN, C_CHANNEL, C_ALLOC, C_ALLOC, C_ALLOC, C_ALLOC, C_ALLOC, + C_COPY_IN, C_COPY_IN, FREE5, C_CLOSE }; + reset_all(); make_job(&job); + inject(C_COPY_IN, 2, -3, 0); + rc = run(&job, &r); + case_begin(); + expect_failure(rc, &r, OMEGA_GPU_ENGINE_PREPARE, OMEGA_GPU_ENGINE_STATE_INITIAL, + OMEGA_GPU_ENGINE_STEP_COPY_IN, OMEGA_GPU_ENGINE_WAIT_NONE); + expect_passthrough(&r, INJ_ERRNO); + expect_log(want, LOGLEN(want)); + expect_released(&r); + case_end("FAIL_PREPARE_COPY_IN"); + } + { + static const int want[] = { C_OPEN, C_CHANNEL, C_ALLOC, C_ALLOC, C_ALLOC, C_ALLOC, C_ALLOC, + C_COPY_IN, C_COPY_IN, C_COPY_IN, C_POISON, FREE5, C_CLOSE }; + reset_all(); make_job(&job); + inject(C_POISON, 1, -3, 0); + rc = run(&job, &r); + case_begin(); + expect_failure(rc, &r, OMEGA_GPU_ENGINE_PREPARE, OMEGA_GPU_ENGINE_STATE_INITIAL, + OMEGA_GPU_ENGINE_STEP_FILL_POISON, OMEGA_GPU_ENGINE_WAIT_NONE); + expect_passthrough(&r, INJ_ERRNO); + expect_log(want, LOGLEN(want)); + expect_released(&r); + case_end("FAIL_PREPARE_FILL_POISON"); + } + { + static const int want[] = { C_OPEN, C_CHANNEL, C_ALLOC, C_ALLOC, C_ALLOC, C_ALLOC, C_ALLOC, + C_COPY_IN, C_COPY_IN, C_COPY_IN, C_POISON, C_BUILD, FREE5, C_CLOSE }; + reset_all(); make_job(&job); + inject(C_BUILD, 1, -3, 0); + rc = run(&job, &r); + case_begin(); + expect_failure(rc, &r, OMEGA_GPU_ENGINE_PREPARE, OMEGA_GPU_ENGINE_STATE_INITIAL, + OMEGA_GPU_ENGINE_STEP_BUILD, OMEGA_GPU_ENGINE_WAIT_NONE); + expect_passthrough(&r, INJ_ERRNO); + expect_log(want, LOGLEN(want)); + expect_released(&r); + case_end("FAIL_PREPARE_BUILD"); + } +} + +static void case_submit_and_visibility(void) +{ + OmegaGpuJob job; + OmegaGpuResult r; + int rc; + + { + static const int want[] = { PRE_SUBMIT, FREE5, C_CLOSE }; + reset_all(); make_job(&job); + inject(C_SUBMIT, 1, -3, 0); + rc = run(&job, &r); + case_begin(); + expect_failure(rc, &r, OMEGA_GPU_ENGINE_SUBMIT, OMEGA_GPU_ENGINE_STATE_PREPARED, + OMEGA_GPU_ENGINE_STEP_SUBMIT, OMEGA_GPU_ENGINE_WAIT_NONE); + expect_passthrough(&r, INJ_ERRNO); + expect_log(want, LOGLEN(want)); + EXPECT(F.submit_seen == 0); + expect_released(&r); /* SUBMIT is a known failure: cleaned up, not blocked */ + expect_no_host_output(); + case_end("FAIL_SUBMIT_IS_NOT_UNCERTAIN"); + } + { + static const int want[] = { PRE_SUBMIT, C_MARKER, C_MARKER2, C_RELEASE, C_BARRIER, FREE5, C_CLOSE }; + reset_all(); make_job(&job); + inject(C_BARRIER, 1, OMEGA_GPU_BACKEND_TIMEOUT, 0); + rc = run(&job, &r); + case_begin(); + expect_failure(rc, &r, OMEGA_GPU_ENGINE_VISIBILITY_WAIT, OMEGA_GPU_ENGINE_STATE_GPU_COMPLETE, + OMEGA_GPU_ENGINE_STEP_BARRIER, OMEGA_GPU_ENGINE_WAIT_NONE); + expect_passthrough(&r, INJ_ERRNO); + expect_log(want, LOGLEN(want)); + expect_released(&r); /* completion is known: cleaned up, not blocked */ + expect_no_host_output(); + case_end("FAIL_VISIBILITY_BARRIER"); + } + { + static const int want[] = { PRE_SUBMIT, C_MARKER, C_MARKER2, C_RELEASE, C_BARRIER, C_COPY_OUT, FREE5, C_CLOSE }; + reset_all(); make_job(&job); + inject(C_COPY_OUT, 1, -3, 0); + rc = run(&job, &r); + case_begin(); + expect_failure(rc, &r, OMEGA_GPU_ENGINE_VISIBILITY_WAIT, OMEGA_GPU_ENGINE_STATE_GPU_COMPLETE, + OMEGA_GPU_ENGINE_STEP_COPY_OUT, OMEGA_GPU_ENGINE_WAIT_NONE); + expect_passthrough(&r, INJ_ERRNO); + expect_log(want, LOGLEN(want)); + expect_released(&r); + case_end("FAIL_VISIBILITY_COPY_OUT"); + } +} + +static void case_uncertain(void) +{ + OmegaGpuJob job; + OmegaGpuResult r; + OmegaGpuResult r2; + int rc; + int nlog_before; + int k; + + { + static const int want[] = { PRE_SUBMIT, C_MARKER }; + reset_all(); make_job(&job); + inject(C_MARKER, 1, OMEGA_GPU_BACKEND_TIMEOUT, 4321); + rc = run(&job, &r); + case_begin(); + expect_failure(rc, &r, OMEGA_GPU_ENGINE_COMPLETION_WAIT, OMEGA_GPU_ENGINE_STATE_SUBMITTED, + OMEGA_GPU_ENGINE_STEP_WAIT_MARKER, OMEGA_GPU_ENGINE_WAIT_MARKER); + EXPECT(r.wait_timeout_ms == TMO_MARKER); + EXPECT(r.waited_ms == 4321u); + expect_passthrough(&r, INJ_ERRNO); + expect_log(want, LOGLEN(want)); + expect_retained(&r); + expect_no_host_output(); + case_end("UNCERTAIN_MARKER_TIMEOUT"); + + /* the next job in this process is refused with no backend call */ + nlog_before = F.nlog; + k = F.count[C_DIAG]; + rc = run(&job, &r2); + case_begin(); + expect_failure(rc, &r2, OMEGA_GPU_ENGINE_UNCERTAIN_COMPLETION_BLOCKED, + OMEGA_GPU_ENGINE_STATE_INITIAL, OMEGA_GPU_ENGINE_STEP_BLOCKED, + OMEGA_GPU_ENGINE_WAIT_NONE); + EXPECT(F.nlog == nlog_before); + EXPECT(F.count[C_DIAG] == k); + EXPECT(r2.retained == 0); + EXPECT(omega_gpu_engine_is_blocked() == 1); + case_end("UNCERTAIN_BLOCKS_NEXT_JOB_NO_BACKEND_CALL"); + + /* test reset clears it; a fresh fake then runs a good job */ + omega_gpu_engine_test_reset_block(); + case_begin(); + EXPECT(omega_gpu_engine_is_blocked() == 0); + reset_all(); + rc = run(&job, &r2); + EXPECT(rc == OMEGA_GPU_ENGINE_OK); + EXPECT(r2.last_state == OMEGA_GPU_ENGINE_STATE_SUCCESS); + case_end("UNCERTAIN_TEST_RESET_CLEARS_BLOCK"); + } + { + static const int want[] = { PRE_SUBMIT, C_MARKER, C_MARKER2 }; + reset_all(); make_job(&job); + inject(C_MARKER2, 1, OMEGA_GPU_BACKEND_UNKNOWN_STATE, 2500); + rc = run(&job, &r); + case_begin(); + expect_failure(rc, &r, OMEGA_GPU_ENGINE_COMPLETION_WAIT, OMEGA_GPU_ENGINE_STATE_SUBMITTED, + OMEGA_GPU_ENGINE_STEP_WAIT_MARKER2, OMEGA_GPU_ENGINE_WAIT_MARKER2); + EXPECT(r.wait_timeout_ms == TMO_MARKER2); + EXPECT(r.waited_ms == 2500u); + expect_passthrough(&r, INJ_ERRNO); + expect_log(want, LOGLEN(want)); + expect_retained(&r); + case_end("UNCERTAIN_MARKER2_UNKNOWN_STATE"); + omega_gpu_engine_test_reset_block(); + } + { + static const int want[] = { PRE_SUBMIT, C_MARKER, C_MARKER2, C_RELEASE }; + reset_all(); make_job(&job); + inject(C_RELEASE, 1, -5, 777); /* a driver fault, not a timeout */ + rc = run(&job, &r); + case_begin(); + expect_failure(rc, &r, OMEGA_GPU_ENGINE_RELEASE_WAIT, OMEGA_GPU_ENGINE_STATE_SUBMITTED, + OMEGA_GPU_ENGINE_STEP_WAIT_RELEASE_SEMAPHORE, + OMEGA_GPU_ENGINE_WAIT_RELEASE_SEMAPHORE); + EXPECT(r.wait_timeout_ms == TMO_RELEASE); + EXPECT(r.waited_ms == 777u); + expect_passthrough(&r, INJ_ERRNO); + expect_log(want, LOGLEN(want)); + expect_retained(&r); + case_end("UNCERTAIN_RELEASE_DRIVER_FAULT"); + omega_gpu_engine_test_reset_block(); + } +} + +static void case_unchanged(void) +{ + OmegaGpuJob job; + OmegaGpuResult r; + size_t i; + int rc; + + /* the fake kernel writes nothing: all 16 words are still poison */ + reset_all(); make_job(&job); + F.klo = 0; F.khi = 0; + rc = run(&job, &r); + case_begin(); + expect_failure(rc, &r, OMEGA_GPU_ENGINE_OUTPUT_UNCHANGED, OMEGA_GPU_ENGINE_STATE_OUTPUT_VISIBLE, + OMEGA_GPU_ENGINE_STEP_SCAN, OMEGA_GPU_ENGINE_WAIT_NONE); + EXPECT(r.n_outputs == 1u); + EXPECT(r.output_unchanged_words[0] == 16u); + EXPECT(r.err_no == 0); + EXPECT(r.drv_rc == DIAG_RC); /* observed words are kept on every failure */ + EXPECT(F.count[C_DIAG] == 1); + for (i = 0; i < N; i++) EXPECT(host_out[i] == poison[i]); + expect_released(&r); + case_end("UNCHANGED_NOTHING_WRITTEN"); + + /* only words 4..9 are written: 10 words are still poison */ + reset_all(); make_job(&job); + F.klo = 4; F.khi = 10; + rc = run(&job, &r); + case_begin(); + expect_failure(rc, &r, OMEGA_GPU_ENGINE_OUTPUT_UNCHANGED, OMEGA_GPU_ENGINE_STATE_OUTPUT_VISIBLE, + OMEGA_GPU_ENGINE_STEP_SCAN, OMEGA_GPU_ENGINE_WAIT_NONE); + EXPECT(r.output_unchanged_words[0] == 10u); + for (i = 0; i < N; i++) EXPECT(host_out[i] == ((i >= 4u && i < 10u) ? exp_out(i) : poison[i])); + expect_released(&r); + case_end("UNCHANGED_PARTIAL_EXACT_COUNT"); + + /* all but the last word written: exactly 1 */ + reset_all(); make_job(&job); + F.klo = 0; F.khi = N - 1u; + rc = run(&job, &r); + case_begin(); + expect_failure(rc, &r, OMEGA_GPU_ENGINE_OUTPUT_UNCHANGED, OMEGA_GPU_ENGINE_STATE_OUTPUT_VISIBLE, + OMEGA_GPU_ENGINE_STEP_SCAN, OMEGA_GPU_ENGINE_WAIT_NONE); + EXPECT(r.output_unchanged_words[0] == 1u); + EXPECT(host_out[N - 1u] == poison[N - 1u]); + expect_released(&r); + case_end("UNCHANGED_LAST_WORD_ONLY"); + + /* only the first word is unwritten: exactly 1 */ + reset_all(); make_job(&job); + F.klo = 1; F.khi = N; + rc = run(&job, &r); + case_begin(); + expect_failure(rc, &r, OMEGA_GPU_ENGINE_OUTPUT_UNCHANGED, OMEGA_GPU_ENGINE_STATE_OUTPUT_VISIBLE, + OMEGA_GPU_ENGINE_STEP_SCAN, OMEGA_GPU_ENGINE_WAIT_NONE); + EXPECT(r.output_unchanged_words[0] == 1u); + EXPECT(host_out[0] == poison[0]); + expect_released(&r); + case_end("UNCHANGED_FIRST_WORD_ONLY"); + + /* the fake kernel writes everything: SUCCESS and a zero count */ + reset_all(); make_job(&job); + F.klo = 0; F.khi = N; + rc = run(&job, &r); + case_begin(); + EXPECT(rc == OMEGA_GPU_ENGINE_OK); + EXPECT(r.last_state == OMEGA_GPU_ENGINE_STATE_SUCCESS); + EXPECT(r.n_outputs == 1u && r.output_unchanged_words[0] == 0u); + case_end("UNCHANGED_ALL_WRITTEN_IS_SUCCESS"); + + /* a silent kernel is only caught because the engine wrote the poison to the + * device output before submit (the fake device starts with other garbage). */ + reset_all(); make_job(&job); + F.klo = 0; F.khi = 0; + rc = run(&job, &r); + case_begin(); + EXPECT(memcmp(F.seen_at_submit, poison, sizeof poison) == 0); + EXPECT(rc == OMEGA_GPU_ENGINE_OUTPUT_UNCHANGED); + case_end("UNCHANGED_NEEDS_POISON_FILL"); +} + +static void case_cleanup_faults(void) +{ + OmegaGpuJob job; + OmegaGpuResult r; + size_t i; + int rc; + + /* free fails on the 2nd free after an otherwise good run: the rest still run */ + reset_all(); make_job(&job); + inject(C_FREE, 2, -9, 0); + rc = run(&job, &r); + case_begin(); + expect_failure(rc, &r, OMEGA_GPU_ENGINE_CLEANUP, OMEGA_GPU_ENGINE_STATE_OUTPUT_PRODUCED, + OMEGA_GPU_ENGINE_STEP_FREE, OMEGA_GPU_ENGINE_WAIT_NONE); + EXPECT(r.cleanup_failed == 1); + EXPECT(r.retained == 0); + expect_passthrough(&r, INJ_ERRNO); + EXPECT(F.count[C_FREE] == 5); + EXPECT(F.count[C_CLOSE] == 1); + for (i = 0; i < N; i++) EXPECT(host_out[i] == exp_out(i)); + EXPECT(omega_gpu_engine_is_blocked() == 0); + case_end("CLEANUP_FREE_FAILS_AFTER_GOOD_RUN"); + + reset_all(); make_job(&job); + inject(C_CLOSE, 1, -9, 0); + rc = run(&job, &r); + case_begin(); + expect_failure(rc, &r, OMEGA_GPU_ENGINE_CLEANUP, OMEGA_GPU_ENGINE_STATE_OUTPUT_PRODUCED, + OMEGA_GPU_ENGINE_STEP_CLOSE, OMEGA_GPU_ENGINE_WAIT_NONE); + EXPECT(r.cleanup_failed == 1); + expect_passthrough(&r, INJ_ERRNO); + EXPECT(F.count[C_FREE] == 5); + EXPECT(omega_gpu_engine_is_blocked() == 0); + case_end("CLEANUP_CLOSE_FAILS_AFTER_GOOD_RUN"); + + /* a free fault and then a close fault: the first (FREE) is kept */ + reset_all(); make_job(&job); + inject(C_FREE, 1, -9, 0); + inject(C_CLOSE, 1, -9, 0); + rc = run(&job, &r); + case_begin(); + expect_failure(rc, &r, OMEGA_GPU_ENGINE_CLEANUP, OMEGA_GPU_ENGINE_STATE_OUTPUT_PRODUCED, + OMEGA_GPU_ENGINE_STEP_FREE, OMEGA_GPU_ENGINE_WAIT_NONE); + EXPECT(r.cleanup_failed == 1); + EXPECT(F.count[C_DIAG] == 1); + case_end("CLEANUP_FIRST_CLEANUP_FAULT_KEPT"); + + /* an earlier failure (submit) then a free fault: the first failure is kept */ + reset_all(); make_job(&job); + inject(C_SUBMIT, 1, -3, 0); + inject(C_FREE, 1, -9, 0); + rc = run(&job, &r); + case_begin(); + expect_failure(rc, &r, OMEGA_GPU_ENGINE_SUBMIT, OMEGA_GPU_ENGINE_STATE_PREPARED, + OMEGA_GPU_ENGINE_STEP_SUBMIT, OMEGA_GPU_ENGINE_WAIT_NONE); + EXPECT(r.cleanup_failed == 1); + EXPECT(F.count[C_FREE] == 5); + EXPECT(F.count[C_CLOSE] == 1); + EXPECT(F.count[C_DIAG] == 1); + expect_passthrough(&r, INJ_ERRNO); + case_end("CLEANUP_FAULT_NEVER_OVERWRITES_FIRST_FAILURE"); + + /* unchanged output plus a close fault: still OUTPUT_UNCHANGED */ + reset_all(); make_job(&job); + F.klo = 0; F.khi = 0; + inject(C_CLOSE, 1, -9, 0); + rc = run(&job, &r); + case_begin(); + expect_failure(rc, &r, OMEGA_GPU_ENGINE_OUTPUT_UNCHANGED, OMEGA_GPU_ENGINE_STATE_OUTPUT_VISIBLE, + OMEGA_GPU_ENGINE_STEP_SCAN, OMEGA_GPU_ENGINE_WAIT_NONE); + EXPECT(r.cleanup_failed == 1); + EXPECT(r.output_unchanged_words[0] == 16u); + case_end("CLEANUP_FAULT_AFTER_UNCHANGED_KEEPS_UNCHANGED"); +} + +#define EXPECT_INVALID(edit) do { \ + OmegaGpuJob bj; \ + OmegaGpuResult br; \ + int brc; \ + reset_all(); make_job(&bj); \ + edit; \ + brc = run(&bj, &br); \ + expect_failure(brc, &br, OMEGA_GPU_ENGINE_INVALID_ARGS, OMEGA_GPU_ENGINE_STATE_INITIAL, \ + OMEGA_GPU_ENGINE_STEP_VALIDATE, OMEGA_GPU_ENGINE_WAIT_NONE); \ + EXPECT(F.nlog == 0 && F.count[C_DIAG] == 0); \ + EXPECT(br.drv_rc == 0 && br.err_no == 0 && br.retained == 0 && br.n_outputs == 0u); \ + EXPECT(omega_gpu_engine_is_blocked() == 0); \ + } while (0) + +static void case_invalid_args(void) +{ + OmegaGpuJob job; + OmegaGpuResult r; + int rc; + + case_begin(); + EXPECT_INVALID(bj.program = NULL); + EXPECT_INVALID(bj.program_len = 0); + case_end("INVALID_ARGS_PROGRAM"); + + case_begin(); + EXPECT_INVALID(bj.layout = OMEGA_GPU_LAYOUT_COUNT); + case_end("INVALID_ARGS_LAYOUT"); + + case_begin(); + /* zero elements with every length zeroed too: only the zero-count check rejects this */ + EXPECT_INVALID(bj.element_count = 0; bj.input_a_len = 0; bj.input_b_len = 0; bj.output_len = 0; bj.poison_count = 0); + EXPECT_INVALID(bj.element_count = 0); + case_end("INVALID_ARGS_ZERO_ELEMENTS"); + + case_begin(); + EXPECT_INVALID(bj.input_a = NULL); + EXPECT_INVALID(bj.input_a_len = sizeof ina - 4u); + EXPECT_INVALID(bj.input_b = NULL); + EXPECT_INVALID(bj.input_b_len = sizeof inb + 4u); + EXPECT_INVALID(bj.output = NULL); + EXPECT_INVALID(bj.output_len = N * sizeof(uint32_t) - 4u); + case_end("INVALID_ARGS_BUFFERS"); + + case_begin(); + EXPECT_INVALID(bj.output = (unsigned char *)host_out + 1); + case_end("INVALID_ARGS_OUTPUT_ALIGNMENT"); + + case_begin(); + EXPECT_INVALID(bj.poison = NULL); + EXPECT_INVALID(bj.poison_count = N - 1u); + EXPECT_INVALID(bj.poison_count = N + 1u); + case_end("INVALID_ARGS_POISON"); + + case_begin(); + EXPECT_INVALID(bj.flags = 0x2u); + case_end("INVALID_ARGS_UNKNOWN_FLAG"); + + case_begin(); + EXPECT_INVALID(bj.timeouts.marker_ms = 0); + case_end("INVALID_ARGS_ZERO_MARKER_TIMEOUT"); + case_begin(); + EXPECT_INVALID(bj.timeouts.release_semaphore_ms = 0); + case_end("INVALID_ARGS_ZERO_RELEASE_TIMEOUT"); + case_begin(); + EXPECT_INVALID(bj.timeouts.visibility_ms = 0); + case_end("INVALID_ARGS_ZERO_VISIBILITY_TIMEOUT"); + case_begin(); + EXPECT_INVALID(bj.timeouts.marker2_ms = 0); /* C3 on: marker2 needs a timeout */ + case_end("INVALID_ARGS_ZERO_MARKER2_TIMEOUT_WITH_C3"); + + case_begin(); + reset_all(); + memset(&r, 0x7f, sizeof r); + rc = omega_gpu_execute(NULL, &r); + EXPECT(rc == OMEGA_GPU_ENGINE_INVALID_ARGS); + EXPECT(r.failure == OMEGA_GPU_ENGINE_INVALID_ARGS && r.failed_step == OMEGA_GPU_ENGINE_STEP_VALIDATE); + EXPECT(r.last_state == OMEGA_GPU_ENGINE_STATE_INITIAL); + EXPECT(F.nlog == 0); + case_end("INVALID_ARGS_NULL_JOB"); + + case_begin(); + reset_all(); make_job(&job); + rc = omega_gpu_execute(&job, NULL); + EXPECT(rc == OMEGA_GPU_ENGINE_INVALID_ARGS); + EXPECT(F.nlog == 0); + case_end("INVALID_ARGS_NULL_RESULT"); +} + +static void case_block_and_backend(void) +{ + OmegaGpuJob job; + OmegaGpuResult r; + static OmegaGpuBackend be2; /* static: it stays the default backend until main clears it */ + int rc; + + /* forced block refuses even a malformed or NULL job, with no backend call */ + reset_all(); make_job(&job); + omega_gpu_engine_test_force_block(); + rc = run(&job, &r); + case_begin(); + expect_failure(rc, &r, OMEGA_GPU_ENGINE_UNCERTAIN_COMPLETION_BLOCKED, + OMEGA_GPU_ENGINE_STATE_INITIAL, OMEGA_GPU_ENGINE_STEP_BLOCKED, + OMEGA_GPU_ENGINE_WAIT_NONE); + EXPECT(F.nlog == 0); + job.element_count = 0; + rc = run(&job, &r); + EXPECT(rc == OMEGA_GPU_ENGINE_UNCERTAIN_COMPLETION_BLOCKED); + memset(&r, 0x7f, sizeof r); + rc = omega_gpu_execute(NULL, &r); + EXPECT(rc == OMEGA_GPU_ENGINE_UNCERTAIN_COMPLETION_BLOCKED); + EXPECT(F.nlog == 0); + EXPECT(omega_gpu_engine_is_blocked() == 1); + case_end("BLOCKED_REFUSES_BEFORE_ANY_CHECK_OR_CALL"); + + omega_gpu_engine_test_reset_block(); + case_begin(); + EXPECT(omega_gpu_engine_is_blocked() == 0); + make_job(&job); + rc = run(&job, &r); + EXPECT(rc == OMEGA_GPU_ENGINE_OK); + case_end("BLOCK_RESET_ALLOWS_JOBS_AGAIN"); + + /* no backend set: the defined stub result */ + reset_all(); make_job(&job); + omega_gpu_engine_set_backend(NULL); + rc = run(&job, &r); + case_begin(); + expect_failure(rc, &r, OMEGA_GPU_ENGINE_INTERNAL_INVARIANT, OMEGA_GPU_ENGINE_STATE_INITIAL, + OMEGA_GPU_ENGINE_STEP_NOT_IMPLEMENTED, OMEGA_GPU_ENGINE_WAIT_NONE); + EXPECT(F.nlog == 0); + case_end("NO_BACKEND_NOT_IMPLEMENTED"); + + /* an incomplete backend table is refused before any call: each callback in turn */ + case_begin(); +#define EXPECT_INCOMPLETE(field) do { \ + reset_all(); make_job(&job); \ + be2 = BE; be2.field = NULL; \ + omega_gpu_engine_set_backend(&be2); \ + rc = run(&job, &r); \ + expect_failure(rc, &r, OMEGA_GPU_ENGINE_INTERNAL_INVARIANT, OMEGA_GPU_ENGINE_STATE_INITIAL, \ + OMEGA_GPU_ENGINE_STEP_BACKEND_CHECK, OMEGA_GPU_ENGINE_WAIT_NONE); \ + EXPECT(F.nlog == 0); \ + } while (0) + EXPECT_INCOMPLETE(open_device); + EXPECT_INCOMPLETE(create_channel); + EXPECT_INCOMPLETE(alloc); + EXPECT_INCOMPLETE(copy_in); + EXPECT_INCOMPLETE(fill_poison); + EXPECT_INCOMPLETE(build); + EXPECT_INCOMPLETE(submit); + EXPECT_INCOMPLETE(wait_marker); + EXPECT_INCOMPLETE(wait_marker2); + EXPECT_INCOMPLETE(wait_release_semaphore); + EXPECT_INCOMPLETE(barrier); + EXPECT_INCOMPLETE(copy_out); + EXPECT_INCOMPLETE(diagnostics); + EXPECT_INCOMPLETE(free_buf); + EXPECT_INCOMPLETE(close); + case_end("BACKEND_TABLE_INCOMPLETE_REFUSED"); +} + +int main(void) +{ + omega_gpu_engine_test_set_clock(fake_now); + + case_success(); + case_no_c3(); + case_open_channel_alloc_prepare(); + case_submit_and_visibility(); + case_uncertain(); + case_unchanged(); + case_cleanup_faults(); + case_invalid_args(); + case_block_and_backend(); + + omega_gpu_engine_set_backend(NULL); + omega_gpu_engine_test_reset_block(); + omega_gpu_engine_test_set_clock(NULL); + printf("SUMMARY passed=%d failed=%d\n", n_pass, n_fail); + return n_fail ? 1 : 0; +} diff --git a/tests/test_omega_gpu_engine_compile.c b/tests/test_omega_gpu_engine_compile.c index b7ac55725..70245c3e2 100644 --- a/tests/test_omega_gpu_engine_compile.c +++ b/tests/test_omega_gpu_engine_compile.c @@ -1,5 +1,7 @@ -/* Omega GPU Engine A2b: the stub returns its defined results, every enum name - * is distinct, and the uncertain-completion block functions behave as specified. */ +/* Omega GPU Engine compile check: the header and the A3a core compile, every enum name + * is distinct, argument and backend-table refusals return their defined results, the + * uncertain-completion block functions behave as specified, and a no-op backend reaches + * SUCCESS. */ #include "omega_gpu_engine.h" #include <stdio.h> #include <string.h> @@ -115,7 +117,7 @@ int main(void) 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. */ + /* Backend table: incomplete is refused, complete runs the core to SUCCESS, 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, @@ -124,9 +126,16 @@ int main(void) .close = f_ctx, }; omega_gpu_engine_set_backend(&be); + /* The A3a core now runs the whole state machine: the all-success no-op backend + * (copy-out leaves the output zeros, which differ from the poison words 1..4) + * reaches SUCCESS. The full state machine is tested in tests/test_omega_gpu_engine.c. */ + omega_gpu_engine_test_set_clock(NULL); /* NULL keeps the default clock */ 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); + CHECK(omega_gpu_execute(&job, &r) == OMEGA_GPU_ENGINE_OK); + CHECK(r.failure == OMEGA_GPU_ENGINE_OK && r.failed_step == OMEGA_GPU_ENGINE_STEP_NONE); + CHECK(r.last_state == OMEGA_GPU_ENGINE_STATE_SUCCESS && r.wait == OMEGA_GPU_ENGINE_WAIT_NONE); + CHECK(r.retained == 0 && r.cleanup_failed == 0); + CHECK(r.n_outputs == 1u && r.output_unchanged_words[0] == 0); be.close = NULL; memset(&r, 0x7f, sizeof r); CHECK(omega_gpu_execute(&job, &r) == OMEGA_GPU_ENGINE_INTERNAL_INVARIANT); diff --git a/tests/test_omega_gpu_engine_gb10.c b/tests/test_omega_gpu_engine_gb10.c new file mode 100644 index 000000000..79f6022a3 --- /dev/null +++ b/tests/test_omega_gpu_engine_gb10.c @@ -0,0 +1,168 @@ +/* + * Phase B only: needs the GB10, queen's go, quiet flag via chip_run; never run in Phase A. + * + * Chip test of the Omega GPU Engine (docs/numeric/OMEGA_GPU_ENGINE.md), cut A3b2. + * Phase A only COMPILES it (make test-gpu-engine-gb10-compile). It was written + * against the real API (src/omega_gpu_engine.h, src/omega_blackwell_submit.h) and + * never compiled or executed by its author. It is a fresh rewrite: the first-cut + * test by GPT-6 Astra (commit 21392ee on fix/omega-gpu-engine-first-cut) used an + * older API, so it served as the outline only. + * + * What it does with --chip on the GB10, through tools/chip_run.sh and + * tools/manifests/gpu_engine.chiprun: + * 1. Runs omega_blackwell_execute_vector (engine core + Blackwell backend + the + * real driver) for element counts 1, 63, 64, 65, 4096 and 65537, ten times + * each. One extra pattern per size uses a[i] = 0xdeadbeef, b[i] = 0 (a sum + * that equals the old constant poison word, which must not fool the engine). + * 2. Negative control: the vector program with its one store instruction + * replaced by the instruction after it (an EXIT), so no lane writes. The + * engine must report OUTPUT_UNCHANGED for all 65 words, after the run + * completed and the output became visible, with nothing retained and no + * cleanup failure. The offsets are the fixture locations in + * src/omega_blackwell_encoder.c (0x120 store, 0x130 exit). + * Verdict lines (the only lines chip_run reads): "GPU_ENGINE: PASS" or + * "GPU_ENGINE: FAIL"; without --chip it prints "GPU_ENGINE: NOT_RUN ..." and + * exits 2. An uncertain completion blocks the process by design: this test then + * parks instead of exiting, because exiting would close the device under a GPU + * that may still be running. + */ +#include "omega_gpu_engine.h" +#include "omega_blackwell_engine.h" +#include "omega_blackwell_submit.h" +#include "omega_blackwell_encoder.h" +#include "omega_blackwell_realize.h" +#include "omega_vector.h" + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#define REPEATS 10u + +/* An uncertain completion leaves the context and the device memory alive on + * purpose. Never exit in that state. */ +static void park_if_blocked(void) +{ + if (!omega_gpu_engine_is_blocked()) return; + fprintf(stderr, "GPU_ENGINE_BLOCKED uncertain completion, parking (do not close the device)\n"); + puts("GPU_ENGINE: FAIL"); + fflush(stdout); + for (;;) pause(); +} + +static int run_size(uint32_t n, int deadbeef) +{ + OmegaVectorSpec spec; + OmegaBlackwellRealization real; + OmegaBlackwellVectorExecution info; + uint32_t *a = (uint32_t *)malloc((size_t)n * 4u); + uint32_t *b = (uint32_t *)malloc((size_t)n * 4u); + uint32_t *c = (uint32_t *)malloc((size_t)n * 4u); + uint32_t i; + unsigned rep; + int ok = (a && b && c); + + memset(&spec, 0, sizeof spec); + memset(&real, 0, sizeof real); + real.sm_architecture = OMEGA_BW_SM_ARCH_121; + if (ok && omega_vector_spec_init(&spec, "engine_chip", n) != 0) ok = 0; + for (i = 0; ok && i < n; i++) { + a[i] = deadbeef ? 0xdeadbeefu : (uint32_t)(i * 2654435761u + 1u); + b[i] = deadbeef ? 0u : (uint32_t)(i * 40503u + 7u); + } + for (rep = 0; ok && rep < REPEATS; rep++) { + int rc; + memset(c, 0, (size_t)n * 4u); + memset(&info, 0, sizeof info); + rc = omega_blackwell_execute_vector(&spec, &real, a, b, c, &info); + park_if_blocked(); + if (rc != 0 || !info.parity_verified) { + fprintf(stderr, "vector run failed n=%u deadbeef=%d repeat=%u rc=%d\n", n, deadbeef, rep, rc); + ok = 0; + } + } + free(a); + free(b); + free(c); + return ok; +} + +static int no_store_control(void) +{ + uint8_t code[OMEGA_BW_VECADD_CODE_SIZE]; + size_t code_bytes = 0; + uint32_t a[65], b[65], out[65], poison[65]; + OmegaGpuJob job; + OmegaGpuResult res; + uint32_t i; + int rc; + + if (omega_blackwell_verify_encoder_fixtures() != 0) return 0; + if (omega_blackwell_encode_vecadd(code, sizeof code, &code_bytes) != 0 || code_bytes < 0x140u) return 0; + /* Replace only the store with the exit that follows it. */ + memcpy(code + 0x120, code + 0x130, OMEGA_BW_INSTRUCTION_BYTES); + for (i = 0; i < 65u; i++) { + a[i] = i + 1u; + b[i] = 3u * i; + poison[i] = ~(a[i] + b[i]); + } + memset(out, 0, sizeof out); + memset(&job, 0, sizeof job); + job.program = code; + job.program_len = code_bytes; + job.layout = OMEGA_GPU_LAYOUT_VECTOR_1D; + job.element_count = 65u; + job.input_a = a; + job.input_a_len = sizeof a; + job.input_b = b; + job.input_b_len = sizeof b; + job.output = out; + job.output_len = sizeof out; + job.poison = poison; + job.poison_count = 65u; + job.timeouts.marker_ms = 5000; + job.timeouts.release_semaphore_ms = 5000; + job.timeouts.marker2_ms = 5000; + job.timeouts.visibility_ms = 5000; + job.flags = 0; + + omega_gpu_engine_set_backend(omega_blackwell_engine_backend()); + rc = omega_gpu_execute(&job, &res); + park_if_blocked(); + if (rc != OMEGA_GPU_ENGINE_OUTPUT_UNCHANGED || res.last_state != OMEGA_GPU_ENGINE_STATE_OUTPUT_VISIBLE || + res.n_outputs != 1u || res.output_unchanged_words[0] != 65u || res.cleanup_failed != 0 || + res.retained != 0) { + fprintf(stderr, "no-store control failed rc=%d state=%d unchanged=%llu cleanup_failed=%d retained=%d\n", + rc, res.last_state, (unsigned long long)res.output_unchanged_words[0], + res.cleanup_failed, res.retained); + return 0; + } + return 1; +} + +int main(int argc, char **argv) +{ + static const uint32_t sizes[] = {1u, 63u, 64u, 65u, 4096u, 65537u}; + size_t s; + unsigned runs = 0; + int failed = 0; + + if (argc < 2 || strcmp(argv[1], "--chip") != 0) { + puts("GPU_ENGINE: NOT_RUN (pass --chip; needs the GB10, via tools/chip_run.sh)"); + return 2; + } + for (s = 0; !failed && s < sizeof sizes / sizeof sizes[0]; s++) { + if (!run_size(sizes[s], 0) || !run_size(sizes[s], 1)) failed = 1; + else runs += 2u * REPEATS; + } + if (!failed && !no_store_control()) failed = 1; + if (failed) { + puts("GPU_ENGINE: FAIL"); + return 1; + } + printf("GPU_ENGINE_CASES vector_runs=%u no_store_control=detected\n", runs); + puts("GPU_ENGINE: PASS"); + return 0; +} diff --git a/tools/gpu_engine_backend_mutations.sh b/tools/gpu_engine_backend_mutations.sh new file mode 100755 index 000000000..ab7a27efe --- /dev/null +++ b/tools/gpu_engine_backend_mutations.sh @@ -0,0 +1,175 @@ +#!/bin/sh +# Omega GPU Engine BACKEND mutation sweep (cut A3b2), a thin adapter over +# tools/mutation_runner.sh, table reader. One mutant per protection in +# src/omega_blackwell_engine.c (the Blackwell backend) and in the vector wrapper +# omega_blackwell_execute_vector (src/omega_blackwell_submit.c). For each row the +# runner copies the needed files to a scratch directory, breaks that one +# protection, rebuilds tests/test_omega_blackwell_engine.c there (against the +# simulated driver tests/fake_m16_native.c) and requires it to FAIL. A mutant that +# does not apply, does not build or is not caught fails the sweep (exit nonzero), +# unless its row carries class "redundant" with a rationale. +# Host only, no device, no GPU, no physics C sources (the driver is the fake). +# The link set is the Makefile RX_COMPOSE_GPU_SRCS list plus the three core files the vector builder needs +# (omega_core.c, omega_canonical.c, sha256.c), with the fake driver in place of physics m16_native.c and nvrm.c. +# Shell only (no Python). The real sources carry no marker comments: the rows +# find their text with exact-once matches (R:) or line ranges (sed), and the +# runner reports "edit did not apply" if a row stops matching. +# Each mutant, what it guards and why a redundant one is redundant are listed in +# docs/numeric/OMEGA_GPU_ENGINE.md section 14.1. Set GPU_ENGINE_BMUT_OUT=path.json +# to also keep the JSON receipt. NOT_RUN in Phase A. +# +# Row format: id~files~edit~guards[~class~rationale]. A row cannot contain a tilde, +# so the one line that contains ~ (the poison complement) is matched with "." in a +# sed row. Edit kinds: "R:from@>@to" (from must match exactly once) or a sed +# expression (a "& " in a replacement is written \&; ranges like +# /^static int be_close/,/^}/ keep an edit inside one function). +set -u +cd "$(dirname "$0")/.." || exit 2 +unset ONLY + +# The scratch copy lives in /tmp, where ../physics does not resolve, so the physics +# path is made absolute here (PHYSICS_DIR, default ../physics). +PHYS=$(cd "${PHYSICS_DIR:-../physics}" 2>/dev/null && pwd -P) || { + echo "gpu_engine_backend_mutations: physics directory not found (set PHYSICS_DIR)" >&2 + exit 2 +} +TP=$PHYS/third_party/nvidia-open-580.173.02 +INC="-I$PHYS/m16 -I$PHYS/nvrm -I$TP/src/common/sdk/nvidia/inc -I$TP/kernel-open/common/inc -I$TP/kernel-open/nvidia-uvm -I$TP/src/nvidia/arch/nvalloc/unix/include" +SRCS="src/omega_blackwell_submit.c src/omega_blackwell_engine.c src/omega_gpu_engine.c src/omega_blackwell_matmul.c src/omega_blackwell_codegen.c src/omega_blackwell_encoder.c src/omega_blackwell_qmd.c src/omega_blackwell_realize.c src/omega_vector.c src/omega_validate.c src/omega_core.c src/omega_canonical.c src/sha256.c" +BUILD="gcc -std=gnu11 -O2 -Wall -Wextra -Werror -D_GNU_SOURCE -pthread -ffunction-sections -fdata-sections -Isrc -Itests $INC -o .gpu_engine_bt tests/test_omega_blackwell_engine.c tests/fake_m16_native.c $SRCS -Wl,--gc-sections -lm" + +OUT=${GPU_ENGINE_BMUT_OUT:-} +set -- -k table -m - -t ./.gpu_engine_bt -b "$BUILD" \ + -c "src tests/test_omega_blackwell_engine.c tests/fake_m16_native.c tests/fake_m16_native.h" \ + -f '\[FAIL\]' -B +[ -z "$OUT" ] || set -- "$@" -o "$OUT" + +tools/mutation_runner.sh "$@" <<'ROWS' +# ---- allocation checks and frees ------------------------------------------------ +BE_ALLOC_CHECK_CPU~src/omega_blackwell_engine.c~R:if (!m->cpu || m->size < bytes ||@>@if (0 || m->size < bytes ||~a buffer without a CPU mapping is refused (ALLOC) +BE_ALLOC_CHECK_SIZE~src/omega_blackwell_engine.c~R:|| m->size < bytes ||@>@|| 0 ||~a buffer smaller than asked is refused (ALLOC) +BE_ALLOC_CHECK_ALIGN~src/omega_blackwell_engine.c~R:|| (m->va & 255u) != 0) {@>@|| 0) {~a GPU address that is not 256-byte aligned is refused (ALLOC) +BE_ALLOC_OWN_CHECK_NOTE~src/omega_blackwell_engine.c~R:note(c, "allocation failed its own checks (CPU mapping, size or 256-byte alignment)");@>@(void)0;~the backend's own refusal text reaches the result +BE_ALLOC_OWN_CHECK_FREE~src/omega_blackwell_engine.c~R:(void)nvrm_free(&c->m.rm, m);@>@(void)0;~a buffer that fails its own checks is freed, not leaked +BE_ROLE_FREE_SKIPPED~src/omega_blackwell_engine.c~R:rc = nvrm_free(&c->m.rm, m);@>@rc = 0;~free_buf really frees a program, input or output buffer +BE_SCRATCH_FREE_SKIPPED~src/omega_blackwell_engine.c~R:int rc = nvrm_free(&c->m.rm, parts[i]);@>@int rc = (parts[i] == NULL) ? -1 : 0;~release_scratch really frees all four SCRATCH parts +BE_SCRATCH_FREE_ERROR_DROPPED~src/omega_blackwell_engine.c~R:if (rc != 0 && first == 0) first = rc;@>@if (0 && rc != 0 && first == 0) first = rc;~a failed SCRATCH part free is reported +BE_SCRATCH_FREE_STOPS_AT_ERROR~src/omega_blackwell_engine.c~R:if (rc != 0 && first == 0) first = rc;@>@if (rc != 0) { first = rc; break; }~one failed SCRATCH part free does not leave the other parts allocated +BE_SCRATCH_ALLOC_FAIL_NO_RELEASE~src/omega_blackwell_engine.c~R:(void)release_scratch(c);@>@(void)0;~a failed SCRATCH allocation frees the parts that did succeed (the core does not) +BE_ERRNO_NOT_RESTORED~src/omega_blackwell_engine.c~R:errno = saved_errno;@>@(void)saved_errno;~the frees after a failed SCRATCH allocation do not clobber the errno the core reads +BE_ALLOC_FAIL_TEXT_RESTORE~src/omega_blackwell_engine.c~R:copy_text(c->text, sizeof c->text, keep);@>@(void)keep;~the failure text survives the cleanup frees~redundant~release_scratch writes neither c->text nor the driver text on a successful free, in the simulated driver and in nvrm_free (physics nvrm.h: free only zeroes the NvrmMem); the restore is a safety net for a driver that writes text on success, which no model here does +BE_SCRATCH_PB_NOT_INSTALLED~src/omega_blackwell_engine.c~R:c->m.pb_mem = c->pb;@>@(void)0;~the large pushbuffer ring replaces the channel's 4 KiB buffer +BE_PB_REPLACED_RESET~src/omega_blackwell_engine.c~R:c->pb_replaced = 0;@>@(void)0;~the flag that records the replaced ring is cleared after SCRATCH is freed~redundant~the zeroing of m.pb_mem stays (it is a separate line); a stale flag only repeats that harmless zeroing, and open memsets the whole context each run. physics m16_native_close is only nvrm_close(&ctx->rm) and never reads pb_mem +# ---- busy flag and open ---------------------------------------------------------- +BE_BUSY_CHECK_DROPPED~src/omega_blackwell_engine.c~R:if (atomic_flag_test_and_set(&g_busy)) return -1;@>@(void)atomic_flag_test_and_set(&g_busy);~a second open while a run is retained is refused +BE_OPEN_FAIL_KEEPS_BUSY~src/omega_blackwell_engine.c~/^static int be_open_device/,/^}/ s/atomic_flag_clear(&g_busy);/(void)0;/~a failed open releases the busy flag +BE_CLOSE_BUSY_CLEAR_DROPPED~src/omega_blackwell_engine.c~/^static int be_close/,/^}/ s/atomic_flag_clear(&g_busy);/(void)0;/~close releases the busy flag so the next run can open +BE_OPEN_MEMSET_DROPPED~src/omega_blackwell_engine.c~R:memset(c, 0, sizeof *c);@>@(void)0;~open resets the whole context, including the previous run's snapshot +BE_OPEN_NATIVE_FLAG_DROPPED~src/omega_blackwell_engine.c~R:c->native_open = 1;@>@(void)0;~a failed open still reports the driver's own text +BE_OPEN_ERROR_IGNORED~src/omega_blackwell_engine.c~/^static int be_open_device/,/^}/ s/return rc;/return 0;/~a failed driver open is reported (DEVICE_OPEN) +BE_OPEN_LAST_RC_DROPPED~src/omega_blackwell_engine.c~/^static int be_open_device/,/^}/ s/c->last_rc = rc;/(void)0;/~the failed open's driver code reaches the result +BE_CHANNEL_ERROR_IGNORED~src/omega_blackwell_engine.c~/^static int be_create_channel/,/^}/ s/return rc;/return 0;/~a failed channel create is reported (CHANNEL_CREATE) +BE_CHANNEL_LAST_RC_DROPPED~src/omega_blackwell_engine.c~/^static int be_create_channel/,/^}/ s/c->last_rc = rc;/(void)0;/~the failed channel create's driver code reaches the result +BE_ALLOC_LAST_RC_DROPPED~src/omega_blackwell_engine.c~/^static int alloc_checked/,/^}/ s/c->last_rc = rc;/(void)0;/~the failed allocation's driver code reaches the result +# ---- roles, rounding, copies ------------------------------------------------------- +BE_ALLOC_UNKNOWN_ROLE_ACCEPTED~src/omega_blackwell_engine.c~/^static int be_alloc/,/^}/ s/if (!m) {/if (0) {/~alloc refuses an unknown role +BE_ROLE_MEM_UPPER_BOUND~src/omega_blackwell_engine.c~R:|| role >= (int)OMEGA_GPU_BUF_ROLE_COUNT) return NULL;@>@|| 0) return NULL;~a role above the last one has no buffer slot +BE_ROLE_MEM_LOWER_BOUND~src/omega_blackwell_engine.c~R:if (role < (int)OMEGA_GPU_BUF_PROGRAM ||@>@if (0 ||~a negative role has no buffer slot +BE_ROUND_PAGES_ZERO_ACCEPTED~src/omega_blackwell_engine.c~R:if (bytes == 0 ||@>@if (0 ||~a zero-byte allocation is refused +BE_ROUND_PAGES_NO_ROUNDING~src/omega_blackwell_engine.c~s/v = ((uint64_t)bytes + (BE_PAGE - 1u)) & .(uint64_t)(BE_PAGE - 1u);/v = (uint64_t)bytes;/~allocation sizes round up to whole pages +BE_ROUND_PAGES_MINIMUM~src/omega_blackwell_engine.c~R:if (v < BE_PAGE) v = BE_PAGE;@>@(void)0;~one-page minimum~redundant~after the zero check, rounding any nonzero byte count up to a page multiple already gives at least one page, so the minimum can never apply +BE_COPY_IN_NO_MEMCPY~src/omega_blackwell_engine.c~R:memcpy(m->cpu, src, bytes);@>@(void)0;~copy_in really copies the program and the inputs +BE_COPY_IN_BOUNDS~src/omega_blackwell_engine.c~R:!src || (uint64_t)bytes > m->size@>@!src~copy_in refuses a length beyond the buffer +BE_COPY_IN_NULL_SOURCE~src/omega_blackwell_engine.c~R:!m->cpu || !src ||@>@!m->cpu ||~copy_in refuses a NULL source +BE_FILL_POISON_DROPPED~src/omega_blackwell_engine.c~R:memcpy(out->cpu, words, count * 4u);@>@(void)0;~the device output is pre-filled with the poison words +BE_FILL_POISON_SHORT~src/omega_blackwell_engine.c~R:memcpy(out->cpu, words, count * 4u);@>@memcpy(out->cpu, words, (count - 1u) * 4u);~every output word is pre-filled, including the last +BE_FILL_POISON_BOUNDS~src/omega_blackwell_engine.c~R:!words || (uint64_t)count * 4u > out->size@>@!words~fill_poison refuses a length beyond the output buffer +BE_COPY_OUT_NO_MEMCPY~src/omega_blackwell_engine.c~R:memcpy(dst, out->cpu, bytes);@>@(void)0;~copy_out really reads the device output back +BE_COPY_OUT_BOUNDS~src/omega_blackwell_engine.c~R:!dst || (uint64_t)bytes > out->size@>@!dst~copy_out refuses a length beyond the output buffer +# ---- build: arguments, descriptors, sync words, pushbuffer --------------------------- +BE_BUILD_LAYOUT_CHECK~src/omega_blackwell_engine.c~R:if (!job || job->layout != (int)OMEGA_GPU_LAYOUT_VECTOR_1D) {@>@if (0) {~build refuses a missing job and an unsupported layout +BE_BUILD_COUNT_OVERFLOW~src/omega_blackwell_engine.c~R:n == 0 || n > UINT32_MAX - 63u@>@n == 0~grid arithmetic overflow guard~redundant~an element count above UINT32_MAX - 63 needs at least 16 GiB of input, output and input buffers, so the buffer-size check in the same condition chain refuses it first; only the grid rounding (n + 63) could overflow, and it is never reached +BE_BUILD_BUFFERS_SIZE~src/omega_blackwell_engine.c~R:|| a->size < need || b->size < need || out->size < need) {@>@|| need == 1) {~build refuses buffers smaller than the element count needs +BE_C3_FLAG_IGNORED~src/omega_blackwell_engine.c~R:c->c3 = (job->flags & OMEGA_GPU_ENGINE_FLAG_NO_C3) == 0;@>@c->c3 = 1;~the NO_C3 flag removes the L2 flush and the second marker +BE_C3_NEVER~src/omega_blackwell_engine.c~R:c->c3 = (job->flags & OMEGA_GPU_ENGINE_FLAG_NO_C3) == 0;@>@c->c3 = 0;~with flags 0 the L2 flush and the second marker are in the pushbuffer +BE_THREADS_WRONG~src/omega_blackwell_engine.c~R:cfg.threads_per_block = 64;@>@cfg.threads_per_block = 32;~the launch covers every element +BE_GRID_ROUNDS_DOWN~src/omega_blackwell_engine.c~R:cfg.grid_width = (n + 63u) / 64u;@>@cfg.grid_width = n / 64u;~the grid rounds up so a partial last block still runs +BE_ARGS_C_SWAPPED~src/omega_blackwell_engine.c~R:a->va, b->va, out->va, n)@>@a->va, out->va, b->va, n)~the kernel writes the OUTPUT buffer +BE_ARGS_A_B_SWAPPED~src/omega_blackwell_engine.c~R:a->va, b->va, out->va, n)@>@b->va, a->va, out->va, n)~the kernel gets input A and input B in the right argument slots +BE_PROGRAM_VA~src/omega_blackwell_engine.c~R:cfg.code_va = code->va;@>@cfg.code_va = c->qmd.va;~the QMD points at the program buffer +BE_CBANK_VA~src/omega_blackwell_engine.c~R:cfg.cbank_va = c->cbank.va;@>@cfg.cbank_va = c->marker.va;~the QMD points at the constant bank buffer +BE_SEM_VA~src/omega_blackwell_engine.c~R:sem_va = c->qmd.va + BE_SEM_OFFSET;@>@sem_va = c->qmd.va + BE_SEM_OFFSET + 0x100u;~the QMD release semaphore address is the word the host waits on +BE_MARKER_VA~src/omega_blackwell_engine.c~R:marker_va = c->marker.va;@>@marker_va = c->marker.va + 0x20u;~the first release lands on the word the host waits on +BE_SEM_ZERO_DROPPED~src/omega_blackwell_engine.c~R:*c->hsem = 0;@>@(void)0;~the semaphore word is zeroed before the doorbell (no stale DONE) +BE_MARKER_ZERO_DROPPED~src/omega_blackwell_engine.c~R:*c->hmarker = 0;@>@(void)0;~the first marker word is zeroed before the doorbell (no stale payload) +BE_MARKER2_ZERO_DROPPED~src/omega_blackwell_engine.c~R:*c->hmarker2 = 0;@>@(void)0;~the second marker word is zeroed before the doorbell +BE_NOC3_MARKER2_REPORTED~src/omega_blackwell_engine.c~R:if (!c->c3) c->hmarker2 = NULL;@>@(void)0;~with NO_C3 the second marker is neither waited for nor reported +BE_MARKER2_OFFSET_CHANGED~src/omega_blackwell_engine.c~R:#define BE_MARKER2_OFFSET 0x10u@>@#define BE_MARKER2_OFFSET 0x20u~the second marker is 0x10 bytes after the first +BE_MARKER2_PAYLOAD_CHANGED~src/omega_blackwell_engine.c~R:#define BE_MARKER2_PAYLOAD 0x46464646u@>@#define BE_MARKER2_PAYLOAD 0x46464647u~the second marker payload is 0x46464646 +BE_RELEASE1_PAYLOAD_ZERO~src/omega_blackwell_engine.c~R:pb_put(c, OMEGA_BW_MARKER_COMPLETION_PAYLOAD);@>@pb_put(c, 0);~the first release writes the completion payload +BE_RELEASE2_PAYLOAD_ZERO~src/omega_blackwell_engine.c~R:pb_put(c, BE_MARKER2_PAYLOAD);@>@pb_put(c, 0);~the second release writes its payload +BE_FLUSH_OP_DROPPED~src/omega_blackwell_engine.c~R:pb_put(c, 0x10u << 27);@>@pb_put(c, 0);~the L2 flush operation word is L2_FLUSH_DIRTY +BE_FLUSH_METHOD_CHANGED~src/omega_blackwell_engine.c~R:pb_put(c, nvrm_mthd(0, 0x0028, 4));@>@pb_put(c, nvrm_mthd(0, 0x002c, 4));~the flush uses the memory-operation method +BE_WFI_FLAG_RELEASE1~src/omega_blackwell_engine.c~/pb_put(c, OMEGA_BW_MARKER_COMPLETION_PAYLOAD);/,+2 s/0x1u | (1u << 20)/0x1u/~the first release waits for idle (WFI) +BE_WFI_FLAG_RELEASE2~src/omega_blackwell_engine.c~/pb_put(c, BE_MARKER2_PAYLOAD);/,+2 s/0x1u | (1u << 20)/0x1u/~the second release waits for idle (WFI) +BE_BARRIER_IN_BUILD~src/omega_blackwell_engine.c~/^static int be_build/,/^}/ s/__asm__ volatile("dsb sy" ::: "memory");/(void)0;/~dsb sy after zeroing the sync words~redundant~a CPU barrier instruction has no effect a host test can observe (the fake driver runs on the same core); it is verified on the chip only (Phase B) +BE_QMD_RELEASE_CHECK~src/omega_blackwell_engine.c~R:if (qmd1_words[9] != 3u ||@>@if (0 ||~extra QMD1 release-word checks~redundant~the real descriptor builder always produces these words (src/omega_blackwell_qmd.c), so no input makes the check fire; it guards a future change of the builder, which tests/test_omega_blackwell_qmd.c style checks cover +BE_PB_OVERFLOW~src/omega_blackwell_engine.c~R:if (c->pb_overflow) {@>@if (0) {~pushbuffer word-capacity guard~redundant~the vector pushbuffer is a fixed 492 words against a 1024-word capacity, so it cannot overflow for any job +# ---- submit, waits, diagnostics ------------------------------------------------------ +BE_SUBMIT_NOTHING_BUILT~src/omega_blackwell_engine.c~R:if (c->pb_len == 0) {@>@if (0) {~submit before build is refused~redundant~the driver refuses an empty submission too (physics m16_native.c m16_native_enqueue_methods: count == 0 returns -1), so the result is the same refusal +BE_LAUNCH_NS_DROPPED~src/omega_blackwell_engine.c~R:c->info.launch_ns = now_ns();@>@(void)0;~the launch time is recorded before the doorbell +BE_SUBMIT_ERROR_IGNORED~src/omega_blackwell_engine.c~/^static int be_submit/,/^}/ s/return rc;/return 0;/~a failed submit is reported (SUBMIT), not treated as launched +BE_WAIT_UNMAPPED_ACCEPTED~src/omega_blackwell_engine.c~R:if (!w) {@>@if (0) {~a wait before build or after free is refused without a driver call +BE_WAIT_DRIVER_RC_DROPPED~src/omega_blackwell_engine.c~/^static int wait_word/,/^}/ s/if (rc != 0) {/if (0) {/~the driver's wait code reaches the result +BE_WAIT_RC_MAPPING~src/omega_blackwell_engine.c~R:return rc == -1 ? OMEGA_GPU_BACKEND_TIMEOUT : -2;@>@return rc;~timeout versus driver fault classification~redundant~the engine core treats every nonzero wait result the same (uncertain completion), and the real m16_native_wait_marker returns only 0 or -1 (m16_native.c) +BE_WAIT_EQUALITY_RECHECK~src/omega_blackwell_engine.c~R:if (*snap != want) {@>@if (0) {~an overshoot of the ">=" compare is refused (UNKNOWN_STATE) +BE_WAIT_SNAPSHOT_DROPPED~src/omega_blackwell_engine.c~R:*snap = *w;@>@(void)0;~the observed word is recorded after every wait +BE_MARKER_DONE_NS_ALWAYS~src/omega_blackwell_engine.c~R:if (rc == 0) c->info.marker_done_ns = now_ns();@>@c->info.marker_done_ns = now_ns();~the completion time is recorded only when the first marker wait succeeded +BE_WAIT_MARKER_WRONG_WORD~src/omega_blackwell_engine.c~R:wait_word(c, c->hmarker, OMEGA_BW_MARKER_COMPLETION_PAYLOAD@>@wait_word(c, c->hmarker2, OMEGA_BW_MARKER_COMPLETION_PAYLOAD~wait_marker waits on the first marker word +BE_WAIT_SEMAPHORE_WRONG_VALUE~src/omega_blackwell_engine.c~R:c->hsem, OMEGA_BW_SEMAPHORE_INTERMEDIATE_DONE,@>@c->hsem, OMEGA_BW_SEMAPHORE_INTERMEDIATE_INIT,~the release semaphore wait is for DONE (6), not the initial value (5) +BE_DIAG_DRV_RC_DROPPED~src/omega_blackwell_engine.c~R:d->drv_rc = c->last_rc;@>@d->drv_rc = 0;~diagnostics report the raw driver code +BE_DIAG_TEXT_OWN_DROPPED~src/omega_blackwell_engine.c~R:if (c->text[0] != '\0') copy_text(@>@if (0) copy_text(~diagnostics report the backend's own text +BE_DIAG_TEXT_DRIVER_DROPPED~src/omega_blackwell_engine.c~R:else if (c->native_open) copy_text(@>@else if (0) copy_text(~diagnostics fall back to the driver's text +BE_DIAG_MARKER_DROPPED~src/omega_blackwell_engine.c~R:d->marker = *c->hmarker;@>@d->marker = 0;~diagnostics report the first marker word +BE_DIAG_MARKER2_DROPPED~src/omega_blackwell_engine.c~R:d->marker2 = *c->hmarker2;@>@d->marker2 = 0;~diagnostics report the second marker word +BE_DIAG_SEMAPHORE_DROPPED~src/omega_blackwell_engine.c~R:d->semaphore[0] = *c->hsem;@>@d->semaphore[0] = 0;~diagnostics report the semaphore word +BE_DIAG_VALID_MARKER_DROPPED~src/omega_blackwell_engine.c~R:d->sync_valid |= OMEGA_GPU_SYNC_MARKER;@>@(void)0;~the first marker is flagged valid only when mapped +BE_DIAG_VALID_MARKER2_DROPPED~src/omega_blackwell_engine.c~R:d->sync_valid |= OMEGA_GPU_SYNC_MARKER2;@>@(void)0;~the second marker is flagged valid only when mapped +BE_DIAG_VALID_SEMAPHORE_DROPPED~src/omega_blackwell_engine.c~R:d->sync_valid |= OMEGA_GPU_SYNC_SEMAPHORE;@>@(void)0;~the semaphore is flagged valid only when mapped +# ---- free_buf and close --------------------------------------------------------------- +BE_FREE_SCRATCH_ROLE_DROPPED~src/omega_blackwell_engine.c~/^static int be_free_buf/,/^}/ s/if (role == (int)OMEGA_GPU_BUF_SCRATCH) {/if (0) {/~free_buf of SCRATCH frees the four SCRATCH parts +BE_FREE_UNKNOWN_ROLE_ACCEPTED~src/omega_blackwell_engine.c~/^static int be_free_buf/,/^}/ s/if (!m) {/if (0) {/~free_buf refuses an unknown role +BE_FREE_ERROR_DROPPED~src/omega_blackwell_engine.c~/^static int be_free_buf/,/^}/ s/return rc;/return 0;/~a failed free is reported (CLEANUP) +BE_RELEASE_KEEPS_MARKER_POINTER~src/omega_blackwell_engine.c~/^static int release_scratch/,/^}/ s/c->hmarker = NULL;/(void)0;/~the first marker word is unmapped before SCRATCH is freed +BE_RELEASE_KEEPS_MARKER2_POINTER~src/omega_blackwell_engine.c~/^static int release_scratch/,/^}/ s/c->hmarker2 = NULL;/(void)0;/~the second marker word is unmapped before SCRATCH is freed +BE_RELEASE_KEEPS_SEM_POINTER~src/omega_blackwell_engine.c~/^static int release_scratch/,/^}/ s/c->hsem = NULL;/(void)0;/~the semaphore word is unmapped before SCRATCH is freed +BE_CLOSE_KEEPS_MARKER_POINTER~src/omega_blackwell_engine.c~/^static int be_close/,/^}/ s/c->hmarker = NULL;/(void)0;/~close unmaps the first marker word +BE_CLOSE_KEEPS_MARKER2_POINTER~src/omega_blackwell_engine.c~/^static int be_close/,/^}/ s/c->hmarker2 = NULL;/(void)0;/~close unmaps the second marker word +BE_CLOSE_KEEPS_SEM_POINTER~src/omega_blackwell_engine.c~/^static int be_close/,/^}/ s/c->hsem = NULL;/(void)0;/~close unmaps the semaphore word +BE_CLOSE_NOT_CALLED~src/omega_blackwell_engine.c~R:rc = m16_native_close(&c->m);@>@rc = 0;~close really closes the driver +BE_CLOSE_ERROR_IGNORED~src/omega_blackwell_engine.c~/^static int be_close/,/^}/ s/return rc;/return 0;/~a failed close is reported (CLEANUP) +# ---- the vector wrapper (src/omega_blackwell_submit.c) ---------------------------------- +WRAP_POISON_NOT_COMPLEMENT~src/omega_blackwell_submit.c~/^int omega_blackwell_execute_vector/,/^}/ s/poison\[i\] = .(uint32_t)(h_a\[i\] + h_b\[i\]);/poison[i] = (uint32_t)(h_a[i] + h_b[i]);/~the poison word is the complement of the expected sum +WRAP_POISON_CONSTANT~src/omega_blackwell_submit.c~/^int omega_blackwell_execute_vector/,/^}/ s/poison\[i\] = .(uint32_t)(h_a\[i\] + h_b\[i\]);/poison[i] = 0xdeadbeefu;/~the poison word never collides with a legitimate sum (0xdeadbeef is one) +WRAP_ENGINE_FAILURE_IGNORED~src/omega_blackwell_submit.c~/^int omega_blackwell_execute_vector/,/^}/ s/if (erc != OMEGA_GPU_ENGINE_OK) {/if ((void)erc, 0) {/~an engine failure (here a cleanup fault) fails the wrapper +WRAP_ORACLE_IGNORED~src/omega_blackwell_submit.c~/^int omega_blackwell_execute_vector/,/^}/ s/return parity_res;/return 0;/~the host oracle decides success, not the engine +WRAP_PARITY_FLAG_FORCED~src/omega_blackwell_submit.c~/^int omega_blackwell_execute_vector/,/^}/ s/exec_info->parity_verified = (parity_res == 0);/exec_info->parity_verified = 1;/~parity_verified follows the oracle +WRAP_MARKER_NOT_REPORTED~src/omega_blackwell_submit.c~/^int omega_blackwell_execute_vector/,/^}/ s/exec_info->completion_marker = info.marker;/exec_info->completion_marker = 0;/~the completion marker is reported +WRAP_SEMAPHORE_NOT_REPORTED~src/omega_blackwell_submit.c~/^int omega_blackwell_execute_vector/,/^}/ s/exec_info->intermediate_semaphore = info.semaphore;/exec_info->intermediate_semaphore = 0;/~the semaphore value is reported +WRAP_LAUNCH_TIME_NOT_REPORTED~src/omega_blackwell_submit.c~/^int omega_blackwell_execute_vector/,/^}/ s/exec_info->launch_timestamp_ns = info.launch_ns;/exec_info->launch_timestamp_ns = 0;/~the launch time is reported +WRAP_DONE_TIME_NOT_REPORTED~src/omega_blackwell_submit.c~/^int omega_blackwell_execute_vector/,/^}/ s/exec_info->completion_timestamp_ns = info.marker_done_ns;/exec_info->completion_timestamp_ns = 0;/~the completion time is reported +WRAP_ELAPSED_NOT_REPORTED~src/omega_blackwell_submit.c~/^int omega_blackwell_execute_vector/,/^}/ s/exec_info->elapsed_ns = .*$/exec_info->elapsed_ns = 0;/~the elapsed time is reported +WRAP_SM_ARCH_NOT_REPORTED~src/omega_blackwell_submit.c~/^int omega_blackwell_execute_vector/,/^}/ s/exec_info->sm_architecture = real->sm_architecture;/exec_info->sm_architecture = 0;/~the architecture is reported +WRAP_ELEMENT_COUNT_NOT_REPORTED~src/omega_blackwell_submit.c~/^int omega_blackwell_execute_vector/,/^}/ s/exec_info->element_count = n;/exec_info->element_count = 0;/~the element count is reported +WRAP_NULL_GUARD_DROPPED~src/omega_blackwell_submit.c~/^int omega_blackwell_execute_vector/,/^}/ s/if (!spec || !real || !h_a || !h_b || !h_c_out) return -1;/(void)0;/~a NULL argument is refused before any use +WRAP_ZERO_COUNT_GUARD~src/omega_blackwell_submit.c~/^int omega_blackwell_execute_vector/,/^}/ s/if (n == 0) return -1;/(void)0;/~a zero element count is refused by the wrapper~redundant~the engine refuses element_count 0 as INVALID_ARGS (src/omega_gpu_engine.c job_valid) and the wrapper then returns -1, so the result is the same refusal +WRAP_MARKER_TIMEOUT~src/omega_blackwell_submit.c~/^int omega_blackwell_execute_vector/,/^}/ s/job.timeouts.marker_ms = 5000;/job.timeouts.marker_ms = 6000;/~the first marker wait limit is 5000 ms +WRAP_SEMAPHORE_TIMEOUT~src/omega_blackwell_submit.c~/^int omega_blackwell_execute_vector/,/^}/ s/job.timeouts.release_semaphore_ms = 5000;/job.timeouts.release_semaphore_ms = 6000;/~the semaphore wait limit is 5000 ms +WRAP_MARKER2_TIMEOUT~src/omega_blackwell_submit.c~/^int omega_blackwell_execute_vector/,/^}/ s/job.timeouts.marker2_ms = 5000;/job.timeouts.marker2_ms = 6000;/~the second marker wait limit is 5000 ms +WRAP_VISIBILITY_TIMEOUT~src/omega_blackwell_submit.c~/^int omega_blackwell_execute_vector/,/^}/ s/job.timeouts.visibility_ms = 5000;/job.timeouts.visibility_ms = 6000;/~the visibility limit is 5000 ms~redundant~the Blackwell barrier callback ignores its timeout argument (it is a CPU dsb sy that cannot wait), so no host observation depends on the value +WRAP_FLAGS_ALL_PROTECTIONS~src/omega_blackwell_submit.c~/^int omega_blackwell_execute_vector/,/^}/ s/job.flags = 0;/job.flags = 1;/~the wrapper runs with every protection on (flags 0) +WRAP_BACKEND_NOT_INSTALLED~src/omega_blackwell_submit.c~/^int omega_blackwell_execute_vector/,/^}/ s/omega_gpu_engine_set_backend(omega_blackwell_engine_backend());/(void)0;/~the wrapper installs the Blackwell backend itself +WRAP_PROGRAM_LENGTH~src/omega_blackwell_submit.c~/^int omega_blackwell_execute_vector/,/^}/ s/job.program_len = encoded_len;/job.program_len = 16;/~the whole encoded program is handed to the engine +WRAP_MARKER_CHECK~src/omega_blackwell_submit.c~/^int omega_blackwell_execute_vector/,/^}/ s/if (info.marker != OMEGA_BW_MARKER_COMPLETION_PAYLOAD) return -1;/(void)0;/~second check of the marker payload~redundant~the backend wait_word already refuses any first-marker value other than 0x44444444 (UNKNOWN_STATE), so the engine fails before this line is reached +WRAP_SEMAPHORE_CHECK~src/omega_blackwell_submit.c~/^int omega_blackwell_execute_vector/,/^}/ s/if (info.semaphore != OMEGA_BW_SEMAPHORE_INTERMEDIATE_DONE) return -1;/(void)0;/~second check of the semaphore value~redundant~the backend wait_word already refuses any semaphore value other than DONE (6), so the engine fails before this line is reached +ROWS diff --git a/tools/gpu_engine_mutations.sh b/tools/gpu_engine_mutations.sh new file mode 100755 index 000000000..86a39fe28 --- /dev/null +++ b/tools/gpu_engine_mutations.sh @@ -0,0 +1,74 @@ +#!/bin/sh +# Omega GPU Engine mutation sweep, a thin adapter over tools/mutation_runner.sh. +# For each rule marked MUT:<name> in src/omega_gpu_engine.c the runner copies the +# needed files to a scratch directory, breaks that one protection, rebuilds +# tests/test_omega_gpu_engine.c there and requires it to FAIL. A mutant that does +# not apply, does not build or is not caught fails the sweep (exit nonzero). +# Host only, no device, no physics headers. Shell only (no Python). +# Each mutant and what it guards is listed in docs/numeric/OMEGA_GPU_ENGINE.md +# section 13. Set GPU_ENGINE_MUT_OUT=path.json to also keep the JSON receipt. +set -u +cd "$(dirname "$0")/.." || exit 2 +unset ONLY + +FILE=src/omega_gpu_engine.c +BUILD='gcc -std=gnu11 -O2 -Wall -Wextra -Werror -Isrc -DOMEGA_NUMERIC_CPU_ONLY -o .gpu_engine_t tests/test_omega_gpu_engine.c src/omega_gpu_engine.c' + +# name|file|sed expression (applied only to the line carrying MUT:<name>). +# In an expression, & in the replacement is written \& . +ROWS="VALIDATE_SKIPPED|$FILE|s/if (!job || !job_valid(job))/if (0 \\&\\& (!job || !job_valid(job)))/ +VALID_PROGRAM|$FILE|s/return 0;/(void)0;/ +VALID_LAYOUT|$FILE|s/return 0;/(void)0;/ +VALID_COUNT_ZERO|$FILE|s/return 0;/(void)0;/ +VALID_ALIGN|$FILE|s/return 0;/(void)0;/ +VALID_POISON_COUNT|$FILE|s/return 0;/(void)0;/ +VALID_FLAGS|$FILE|s/return 0;/(void)0;/ +VALID_TIMEOUT_MARKER1|$FILE|s/return 0;/(void)0;/ +VALID_TIMEOUT_MARKER2|$FILE|s/return 0;/(void)0;/ +BLOCK_CHECK_SKIPPED|$FILE|s/if (omega_gpu_engine_is_blocked())/if (0)/ +BACKEND_CHECK_SKIPPED|$FILE|s/if (!backend_complete(b))/if (0 \\&\\& !backend_complete(b))/ +OPEN_NOT_TRACKED|$FILE|s/run.opened = 1;/(void)0;/ +ALLOC_NOT_TRACKED|$FILE|s/run.allocated\\[role\\] = 1;/(void)0;/ +CLEANUP_SKIPPED_CHANNEL|$FILE|s/return leave(b, &run, result);/return result->failure;/ +CLEANUP_SKIPPED_ALLOC|$FILE|s/return leave(b, &run, result);/return result->failure;/ +CLEANUP_SKIPPED_COPY_IN|$FILE|s/return leave(b, &run, result);/return result->failure;/ +CLEANUP_SKIPPED_SUBMIT|$FILE|s/return leave(b, &run, result);/return result->failure;/ +FREE_UNALLOCATED|$FILE|s/if (!run->allocated\\[role\\]) continue;/(void)0;/ +FREE_SKIPPED|$FILE|s/rc = b->free_buf(b->ctx, role);/rc = 0;/ +CLOSE_SKIPPED|$FILE|s/rc = b->close(b->ctx);/rc = 0;/ +CLEANUP_OVERWRITES_FIRST|$FILE|s/if (result->failure == OMEGA_GPU_ENGINE_OK)/if (1)/ +CLEANUP_FLAG_NOT_SET|$FILE|s/result->cleanup_failed = 1;/(void)0;/ +POISON_FILL_SKIPPED|$FILE|s/errno = 0; rc = b->fill_poison.*/rc = 0; e = 0;/ +STATE_PREPARED_SKIPPED|$FILE|s/result->last_state = OMEGA_GPU_ENGINE_STATE_PREPARED;/(void)0;/ +STATE_SUBMITTED_SKIPPED|$FILE|s/result->last_state = OMEGA_GPU_ENGINE_STATE_SUBMITTED;/(void)0;/ +STATE_GPU_COMPLETE_SKIPPED|$FILE|s/result->last_state = OMEGA_GPU_ENGINE_STATE_GPU_COMPLETE;/(void)0;/ +STATE_OUTPUT_VISIBLE_SKIPPED|$FILE|s/result->last_state = OMEGA_GPU_ENGINE_STATE_OUTPUT_VISIBLE;/(void)0;/ +STATE_OUTPUT_PRODUCED_SKIPPED|$FILE|s/result->last_state = OMEGA_GPU_ENGINE_STATE_OUTPUT_PRODUCED;/(void)0;/ +STATE_SUCCESS_SKIPPED|$FILE|s/if (rc == OMEGA_GPU_ENGINE_OK) result->last_state = OMEGA_GPU_ENGINE_STATE_SUCCESS;/(void)0;/ +SUCCESS_AFTER_CLEANUP_FAIL|$FILE|s/if (rc == OMEGA_GPU_ENGINE_OK) result/if (1) result/ +MARKER1_WAIT_SKIPPED|$FILE|s/rc = timed_call(.*\$/rc = 0;/ +MARKER1_TIMEOUT_WRONG|$FILE|s/job->timeouts.marker_ms, &waited/job->timeouts.release_semaphore_ms, \\&waited/ +MARKER1_RESULT_IGNORED|$FILE|s/if (rc != 0) return uncertain/if (0 \\&\\& rc != 0) return uncertain/ +UNCERTAIN_FREES_MARKER1|$FILE|s/return uncertain(\\(.*\\));/{ (void)uncertain(\\1); return leave(b, \\&run, result); }/ +MARKER2_WAIT_SKIPPED|$FILE|s/if (!(job->flags & OMEGA_GPU_ENGINE_FLAG_NO_C3)) {/if (0) {/ +C3_FLAG_IGNORED|$FILE|s/if (!(job->flags & OMEGA_GPU_ENGINE_FLAG_NO_C3)) {/if (1) {/ +MARKER2_RESULT_IGNORED|$FILE|s/if (rc != 0) return uncertain/if (0 \\&\\& rc != 0) return uncertain/ +UNCERTAIN_FREES_MARKER2|$FILE|s/return uncertain(\\(.*\\));/{ (void)uncertain(\\1); return leave(b, \\&run, result); }/ +RELEASE_WAIT_SKIPPED|$FILE|s/rc = timed_call(.*\$/rc = 0;/ +RELEASE_RESULT_IGNORED|$FILE|s/if (rc != 0) return uncertain/if (0 \\&\\& rc != 0) return uncertain/ +UNCERTAIN_FREES_RELEASE|$FILE|s/return uncertain(\\(.*\\));/{ (void)uncertain(\\1); return leave(b, \\&run, result); }/ +BARRIER_SKIPPED|$FILE|s/rc = timed_call(.*\$/rc = 0;/ +BARRIER_RESULT_IGNORED|$FILE|s/if (rc != 0) {/if (0 \\&\\& rc != 0) {/ +RETAINED_FLAG_NOT_SET|$FILE|s/result->retained = 1;/(void)0;/ +NO_BLOCK|$FILE|s/atomic_store(&g_blocked, 1);/(void)0;/ +WAITED_NOT_A_DIFFERENCE|$FILE|s/t1 >= t0 ? t1 - t0 : 0u;/t1 >= t0 ? t1 : 0u;/ +POISON_INDEX_FIXED|$FILE|s/w == job->poison\\[i\\]/w == job->poison[0]/ +UNCHANGED_COUNT_SATURATES|$FILE|s/unchanged++;/unchanged = 1u;/ +UNCHANGED_CHECK_SKIPPED|$FILE|s/if (unchanged != 0u) {/if (0) {/" + +OUT=${GPU_ENGINE_MUT_OUT:-} +set -- -k marker -m - -t ./.gpu_engine_t -b "$BUILD" \ + -c "src/omega_gpu_engine.c src/omega_gpu_engine.h tests/test_omega_gpu_engine.c" \ + -f '\[FAIL\]' -B +[ -z "$OUT" ] || set -- "$@" -o "$OUT" +printf '%s\n' "$ROWS" | tools/mutation_runner.sh "$@" diff --git a/tools/manifests/gpu_engine.chiprun b/tools/manifests/gpu_engine.chiprun new file mode 100644 index 000000000..4316742e6 --- /dev/null +++ b/tools/manifests/gpu_engine.chiprun @@ -0,0 +1,31 @@ +# Phase B only: needs the GB10, queen's go, quiet flag via chip_run; never run in Phase A. +# Manifest for tools/chip_run.sh: the Omega GPU Engine chip test (cut A3b2, docs/numeric/OMEGA_GPU_ENGINE.md). +# Sourced as shell by chip_run.sh, which provides $HERE (omega root) and $PHYSICS. +# Format follows tools/manifests/unwritten_trap.chiprun (omega#205). NOT_RUN: never executed by its author. +# Verdict lines printed by tests/test_omega_gpu_engine_gb10.c: +# "GPU_ENGINE: PASS" or "GPU_ENGINE: FAIL" on a completed run (exit 0 or 1) +# "GPU_ENGINE: NOT_RUN ..." and exit 2 when --chip is missing +# The "GPU_ENGINE_CASES ..." and "GPU_ENGINE_BLOCKED ..." lines do not start with the verdict tag +# followed by a space, so they are not verdict candidates. +GATE=gpu_engine +OWNER=gpu_engine +TEST_SOURCE="tests/test_omega_gpu_engine_gb10.c" +# The real engine core, the Blackwell backend, the vector wrapper and what the vector builder needs. +# Not the fake driver: the real m16_native.c and nvrm.c come in below. +SOURCES="src/omega_gpu_engine.c src/omega_blackwell_engine.c src/omega_blackwell_submit.c src/omega_blackwell_realize.c src/omega_blackwell_encoder.c src/omega_blackwell_codegen.c src/omega_blackwell_matmul.c src/omega_blackwell_qmd.c src/omega_vector.c src/omega_validate.c src/omega_core.c src/omega_canonical.c src/sha256.c" +EXTRA_BUILD_SOURCES="$PHYSICS/nvrm/nvrm.c $PHYSICS/m16/m16_native.c" +RUN_ARGS="--chip" +VERDICT_RE='^GPU_ENGINE: ' +PASS_LINE='^GPU_ENGINE: PASS$' +EVIDENCE_DIR="$HOME/workspace/evidence-out/OMEGA-GPU-ENGINE" +# Refusals keep the harness's own NOT_RUN line and exit code 2. +REFUSE_EXIT=2 +REFUSE_VERDICT_LINE="GPU_ENGINE: NOT_RUN" +# A chip run: raise the quiet flag (only with the queen's go) and take the GPU lock. +RAISE_QUIET=1 +TAKE_GPU_LOCK=1 +REFUSE_DIRTY_OMEGA=1 +REQUIRE_ALL_PASS=0 +CHILD_EXIT_PASSTHROUGH=1 +# Host tier first (nonzero refuses): the simulated-driver test and the backend mutants, real target names. +HOST_TIER_CMD="make test-gpu-engine-sim test-gpu-engine-backend-mutants PHYSICS_DIR=\"$PHYSICS\""