diff --git a/.crumb b/.crumb index 9d299efd4..9d6ad9b02 100644 --- a/.crumb +++ b/.crumb @@ -51,8 +51,8 @@ "purpose": "Directory calibration. Purpose not yet described by a human." }, { - "digest": "24d7c03a26a7ffe9b181b73585480b5801289accbdf63146edbc36cf3e1cf21f", - "last_commit": "6637b32b", + "digest": "06530caf3f6710cdfc333d10a8e8c702571372e0926768b44396f9f971ca7573", + "last_commit": "e04bd502", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." }, @@ -63,8 +63,8 @@ "purpose": "Directory doctrine. Purpose not yet described by a human." }, { - "digest": "ac43a69e03617abcc3c94f3fc1bc10c7593d9d57d49059c20bc4ce3abfaa8489", - "last_commit": "e59633e5", + "digest": "09ea357529c7b5ad670bb41f2663e4d11210c1e71d493cded07cf6bc5dd79686", + "last_commit": "e04bd502", "name": "mk", "purpose": "Directory mk. Purpose not yet described by a human." }, @@ -87,33 +87,33 @@ "purpose": "Directory spec. Purpose not yet described by a human." }, { - "digest": "367e186a354de5a8c64c790ec75e13f168681d09579dad58192c9e995db87ff0", - "last_commit": "a19147e0", + "digest": "929078f81753cba5bcf364be0c4da936d8cdff4b879ca6eccf8cbea7724a5b6c", + "last_commit": "e04bd502", "name": "src", "purpose": "Directory src. Purpose not yet described by a human." }, { - "digest": "8a71f0ad0592cd5203841779f40edd0aa2628635b6878d6f9bf18ae5fc4f709c", - "last_commit": "a19147e0", + "digest": "38c14347e7f7885f0858c2e66c9cb8d029ad128c80cc84818ceda5e7d77de7e3", + "last_commit": "e04bd502", "name": "tests", "purpose": "Directory tests. Purpose not yet described by a human." }, { - "digest": "acd42de9387a133f34b4b6afca962c82d340fba67c6a770a74852406769b4186", - "last_commit": "7683eaaa", + "digest": "285407d8f7949613c6b57b225fa50b2bb076aaa874fded0895d82fbf285fb832", + "last_commit": "e04bd502", "name": "tools", "purpose": "Directory tools. Purpose not yet described by a human." } ], - "children_root": "sha256:fc31a05a0acc60e9e72ebaf03ad6cc61c1dd5467b8fddb0cfe8112d66b67ee8f", - "compiled_at": "2026-10-12T10:28:55Z", + "children_root": "sha256:94c91b7a592ba075701e2dadb839f65ae1e99b7860fac9f99cd672d7aaf76609", + "compiled_at": "2026-10-12T10:51:44Z", "compiler": "crumb-compile/1", - "digest": "sha256:f91173a1a92e04c868eef5243b50bc9f9d49cd396cbc72b2d56af4160af27dbf", + "digest": "sha256:49bfa3ca7946ce21bc4a18c54462583f9878efb4a68378a7cc0273752561797d", "evidence_files": 7245, "evidence_root": "sha256:035beef5cdb99afaefd1743640f5e7eeaaed13c4a5ec6c8b4b6a4cb0c528407a", - "files": 9734, - "generated_at_commit": "a19147e052a95f949522bdb40a1be2483601a3d9", - "source_tree": "sha256:2500ae8b61aeb84142d3692d7cb33879c85cc76d269de8e04563d894ca7007c3" + "files": 9738, + "generated_at_commit": "e04bd5021b2a4f311fb9838887c170c4bf3164b6", + "source_tree": "sha256:b284014f1bbef6f8add13b7a17b7c2d5fdbc81a1072d591e0f434df7b119fadd" }, "owner_lane": "", "provenance": { diff --git a/.github/workflows/host-suites-2.yml b/.github/workflows/host-suites-2.yml index 2bbc06328..1154df3e3 100644 --- a/.github/workflows/host-suites-2.yml +++ b/.github/workflows/host-suites-2.yml @@ -111,6 +111,7 @@ jobs: argus: ${{ steps.f.outputs.argus }} numeric2: ${{ steps.f.outputs.numeric2 }} tensor: ${{ steps.f.outputs.tensor }} + gpuengine: ${{ steps.f.outputs.gpuengine }} steps: - uses: actions/checkout@v4 with: @@ -154,6 +155,7 @@ jobs: sel argus "^src/runtime/|^tests/runtime/|^tests/bench_rx_argus\.c$|^mk/machine-identity\.mk$|^src/(sha256|omega_evidence)\.|^(physics|aienos|argus)\.lock$" sel numeric2 "^tests/(test_omega_reduce|test_omega_divsqrt_gb10)\.c$|^tests/numeric_oracle\.h$|^src/(omega_numeric|omega_blackwell_(encoder|codegen|matmul|qmd)|sha256)" sel tensor "^tools/m20_receipt(_mutations)?\.sh$|^tests/test_m20_receipt\.sh$|^tests/fixtures/m20_receipt/|^src/tensor/|^tests/test_omega_tensor(_store)?\.c$|^tools/tensor_mutations\.sh$|^mk/tensor\.mk$|^src/(omega_numeric|omega_blackwell_(encoder|codegen|matmul|qmd)|sha256)" + sel gpuengine "^src/omega_gpu_(engine|platform)\.|^src/omega_blackwell_(encoder|qmd|realize)\.|^src/sha256\.|^tests/test_omega_gpu_(engine|engine_compile|platform)\.c$|^tools/gpu_engine_mutations\.sh$|^mk/omega-gpu-engine\.mk$" visor: needs: changes @@ -417,6 +419,22 @@ jobs: - name: Reduce CPU tier and GB10 div/sqrt sequences on the host (CPU only) run: make PHYSICS_DIR=/nonexistent PHYSICS_LOCK_CHECK=0 test-numeric-reduce-cpu test-divsqrt-host + gpu-engine: + needs: changes + if: needs.changes.outputs.gpuengine == 'true' + runs-on: ubuntu-24.04-arm + timeout-minutes: 15 + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: GPU engine core against the fake backend (host, no device) + run: make PHYSICS_DIR=/nonexistent PHYSICS_LOCK_CHECK=0 test-gpu-engine-compile test-gpu-engine + - name: Freestanding GPU link target and contract tests (native v1 P07 cut A) + run: make PHYSICS_DIR=/nonexistent PHYSICS_LOCK_CHECK=0 test-gpu-engine-freestanding + - name: Engine mutants (each protection removed once must be caught) + run: make PHYSICS_DIR=/nonexistent PHYSICS_LOCK_CHECK=0 test-gpu-engine-mutants + tensor: needs: changes if: needs.changes.outputs.tensor == 'true' diff --git a/docs/.crumb b/docs/.crumb index 17a27d1cb..814dc3916 100644 --- a/docs/.crumb +++ b/docs/.crumb @@ -81,8 +81,8 @@ "purpose": "Directory docs/estimation. Purpose not yet described by a human." }, { - "digest": "daa5aa1391e048c926c5cd9960008e3e33c8405d1cfa79a29bfc89b79486ad76", - "last_commit": "c7d98f37", + "digest": "7783bdb01c21689056aa1722791b699ccbd5c1ec6dd90c1b39de264966da8981", + "last_commit": "e04bd502", "name": "numeric", "purpose": "Directory docs/numeric. Purpose not yet described by a human." }, @@ -117,15 +117,15 @@ "purpose": "Directory docs/turing. Purpose not yet described by a human." } ], - "children_root": "sha256:97cd6e4730ccdf9dd75f0481c7506cb88dd2b5c66d140438973edd3fbfbb1e9e", - "compiled_at": "2026-10-12T05:17:54Z", + "children_root": "sha256:5f73204bf9306b344a9e95e840df24ced95c5d443290b3c25681dc13e9437ddd", + "compiled_at": "2026-10-12T10:51:44Z", "compiler": "crumb-compile/1", - "digest": "sha256:24d7c03a26a7ffe9b181b73585480b5801289accbdf63146edbc36cf3e1cf21f", + "digest": "sha256:06530caf3f6710cdfc333d10a8e8c702571372e0926768b44396f9f971ca7573", "evidence_files": 34, "evidence_root": "sha256:589d8b3706e6d7a202ab20b278dac5fc5bafc973f1c2a867b2668aa7210b65cc", - "files": 118, - "generated_at_commit": "6e6f1c8e27b4f3a511bb284e7f51f2a957863ded", - "source_tree": "sha256:22bb817cd659d6a4345b0d411cb903b0300bc2150117e1c1a1f120e76163f077" + "files": 119, + "generated_at_commit": "e04bd5021b2a4f311fb9838887c170c4bf3164b6", + "source_tree": "sha256:c4dc6b00ee640e0b3eabcd044fd45d082f30c950f9713126d04daf9072182459" }, "owner_lane": "", "provenance": { diff --git a/docs/numeric/.crumb b/docs/numeric/.crumb index 1a1942652..3463ff40c 100644 --- a/docs/numeric/.crumb +++ b/docs/numeric/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-07T03:36:22Z", + "compiled_at": "2026-10-12T10:51:44Z", "compiler": "crumb-compile/1", - "digest": "sha256:daa5aa1391e048c926c5cd9960008e3e33c8405d1cfa79a29bfc89b79486ad76", + "digest": "sha256:7783bdb01c21689056aa1722791b699ccbd5c1ec6dd90c1b39de264966da8981", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 10, - "generated_at_commit": "c988166e4a2d5a5eabd46539bf1601d1e1c88e6e", - "source_tree": "sha256:5c5e161b78de9d27dc04a3f4d4314e6ac13ae02d3390a601554465a3518fb6f3" + "files": 11, + "generated_at_commit": "e04bd5021b2a4f311fb9838887c170c4bf3164b6", + "source_tree": "sha256:81f785a6d21833cfa07ff1adcb74b6f1d011043d8db5172105bffb4859db41c1" }, "owner_lane": "", "provenance": { diff --git a/docs/numeric/OMEGA_GPU_ENGINE.md b/docs/numeric/OMEGA_GPU_ENGINE.md index 2f61bd4b4..7f7755447 100644 --- a/docs/numeric/OMEGA_GPU_ENGINE.md +++ b/docs/numeric/OMEGA_GPU_ENGINE.md @@ -854,7 +854,18 @@ 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 +## 15. Native boundary (native v1 P07 cut A) + +`src/omega_gpu_engine.c` also builds freestanding (`OMEGA_GPU_NO_POSIX`: no +errno, no default clock, `omega_gpu_engine_set_clock` is the platform time +service and a missing clock is refused at `STEP_CLOCK_CHECK`). The platform +contract a native backend programs against is `src/omega_gpu_platform.h`. +The per-file dependency map, the driver-responsibility table and the cut plan +live in `docs/numeric/OMEGA_GPU_NATIVE_BOUNDARY.md`; `make +test-gpu-engine-freestanding` is the host evidence. Device ownership stays +NOT_RUN until cut B runs on the Spark. + +## 16. 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 diff --git a/docs/numeric/OMEGA_GPU_NATIVE_BOUNDARY.md b/docs/numeric/OMEGA_GPU_NATIVE_BOUNDARY.md new file mode 100644 index 000000000..a6b22713e --- /dev/null +++ b/docs/numeric/OMEGA_GPU_NATIVE_BOUNDARY.md @@ -0,0 +1,191 @@ +# Omega GPU native boundary: dependency map and freestanding link target + +Native v1 P07 cut A. Tracks aienos#286 (cut A) and aien-architecture#190. +Companion of `docs/numeric/OMEGA_GPU_ENGINE.md` (the engine contract) and +`src/omega_gpu_platform.h` (the platform contract this cut adds). + +Status words used here: DONE (host evidence in this repo's CI), NOT_RUN (no +evidence; needs the physical Spark in an attended window), PLANNED (a later +cut). NOT_RUN is never PASS. + +## 1. What this cut claims, and what it does not + +Claimed (host evidence, `make test-gpu-engine-freestanding`): + +- Six files of the first-compute path build with `-ffreestanding -fno-builtin` + and `OMEGA_GPU_NO_POSIX`, and their partial link leaves only `memcpy`, + `memset`, `strcmp` and `strlen` undefined: `src/omega_gpu_engine.c`, + `src/omega_gpu_platform.c`, `src/omega_blackwell_encoder.c`, + `src/omega_blackwell_qmd.c`, `src/omega_blackwell_realize.c`, `src/sha256.c`. + No Linux header, no `errno`, no `clock_gettime`, no `printf`, no `malloc`, + no `pthread_*`, no `nvrm_*`, no `m16_*`. The make target fails on any other + undefined symbol. +- The engine contract test (`tests/test_omega_gpu_engine.c`, 50 cases) passes + linked against the freestanding engine object, with one added case: with no + platform clock installed, every job is refused at `STEP_CLOCK_CHECK` before + any backend call. +- The platform contract (`src/omega_gpu_platform.h`) has a test + (`tests/test_omega_gpu_platform.c`, 6 cases) reaching every refusal name. +- The engine mutation sweep still kills all 49 mutants (`make test-gpu-engine-mutants`). + +Not claimed: + +- No whole-project independence from Linux. Section 3 lists every file that + still calls the Linux RM/UVM driver through `physics/nvrm` and `physics/m16`, + and which cut migrates it. +- No device ownership. Nothing in this cut opens, discovers, maps or resets a + GPU. Device discovery, bounded MMIO/DMA/IRQ ownership and the SMMU path are + cut B, and their evidence is NOT_RUN until an attended hardware window + (native v1 gate N4; the B7b one-page SMMU probe is not GPU compute). +- No production use of the test-only hooks. `omega_gpu_engine_test_set_clock` + remains test-only; the production time service is + `omega_gpu_engine_set_clock`, which the native platform calls once at init. + +## 2. Driver-provided responsibilities: who owns each today and later + +Today every row is served by the Linux RM/UVM driver (nvidia-open 580.173.02) +through `physics/nvrm/nvrm.c` and `physics/m16/m16_native.c`, called from the +files in section 3. + +| Responsibility | Linux path today | Native owner | Cut | Status | +|---|---|---|---|---| +| Device discovery, bounded ownership (MMIO/DMA/IRQ capabilities) | RM device open (`nvrm_open`, `m16_native_open`) | AIENOS PCI/SMMU layer + `OmegaGpuPlatform` MMIO/DMA services | B | NOT_RUN | +| Device and firmware initialization (GSP, falcons) | RM boot inside the kernel module | AIENOS GB10 firmware lifecycle (P08) | B/P08 | NOT_RUN | +| Context / address space creation | RM client + VA space objects (`nvrm_mthd`) | native context object behind `OmegaGpuDeviceHandle` | B | NOT_RUN | +| Memory allocation with cache attributes | `nvrm_alloc`, `nvrm_alloc_gpu_uncached` | `OmegaGpuPlatform.dma_alloc` with `OmegaGpuBufferDesc` (kind, rights, cache policy) | B | contract DONE, device NOT_RUN | +| GPU page tables / mapping | UVM + RM map | AIENOS page tables, GPU VA through `OmegaGpuVa` | B | NOT_RUN | +| Bus addresses / SMMU translation | kernel DMA API inside RM | AIENOS SMMU, `OmegaGpuBusAddr` (no raw physical address type exists) | B | NOT_RUN | +| Channel / queue creation (GPFIFO, USERD) | `m16_native_create_channel`, `nvrm_channel` | native queue behind `OmegaGpuQueueHandle`, ring is a `BUF_QUEUE` buffer | B/C | NOT_RUN | +| Submit token / doorbell | `m16_native_submit_methods`, `nvrm_enqueue`, `nvrm_ring` | `OmegaGpuPlatform.mmio_write32` on the doorbell region | C | NOT_RUN | +| Completion (marker words, semaphores) | `m16_native_wait_marker*`, host polling | `OmegaGpuPlatform.wait_word` on a HOST_POLLED, GPU-uncached buffer | C | contract DONE, device NOT_RUN | +| Interrupts | RM interrupt handling (not used by our launchers: they poll) | `OMEGA_GPU_SVC_IRQ` only when a real interrupt wait exists; polling never claims it | B | NOT_RUN | +| Visibility / cache maintenance | L2 flush mem-op + uncached marker (C3 block) | `OmegaGpuPlatform.sync_*` plus the same mem-op sequence in the encoder | C | NOT_RUN | +| Time, waiting, locking | `clock_gettime`, `usleep`, pthread | `OmegaGpuPlatform.time_now_ms`, `wait_ms`, `lock`/`unlock` | A (contract) | DONE | +| Reset / recovery of a hung device | RM channel teardown, process exit | native quiesce path (P03 lifecycle), no `ck_reset`-style shortcut | P08 | NOT_RUN | +| Resource numbering across incarnations | per-process RM handles | aienos#285 resource incarnations, before any domain-1 number is persisted | P05/#285 | PLANNED | + +Rule carried over from the 2026-10-02 E1 stall: anything the CPU polls for a +device write is `OMEGA_GPU_RIGHT_HOST_POLLED` and must be +`OMEGA_GPU_CACHE_GPU_UNCACHED`. Source: nvidia-open 580.173.02 +`src/common/sdk/nvidia/inc/nvos.h`, `NVOS32_ATTR2_GPU_CACHEABLE_YES`: "For +system memory this will not be coherent with direct CPU mappings." The +platform contract refuses a cached host-polled buffer +(`OMEGA_GPU_PLAT_REFUSED_CACHE_POLICY`). + +## 3. File inventory: Linux driver and libc dependencies, migrating cut + +Counts are `grep -c` of `nvrm_` and `m16_` on 2026-10-12 at omega main +536870f1. "Linux headers" lists hosted headers the file includes. "Cut" is +where the file stops depending on them. "Host tooling" means the file is +development-host measurement or gating and is not part of the native product +(the plan separates development hosts from the delivered runtime). + +| File | nvrm_ | m16_ | Linux headers | Cut | Note | +|---|---|---|---|---|---| +| `src/omega_gpu_engine.c` | 0 | 0 | none (errno/time only on the host build) | A | DONE: `OMEGA_GPU_NO_POSIX` build, clock refusal | +| `src/omega_gpu_platform.c` | 0 | 0 | none | A | DONE: new, contract checks and handle table | +| `src/omega_blackwell_encoder.c` | 0 | 0 | none (stdio removed in A) | A | DONE | +| `src/omega_blackwell_qmd.c` | 0 | 0 | none | A | DONE | +| `src/omega_blackwell_realize.c` | 0 | 0 | none | A | DONE | +| `src/sha256.c` | 0 | 0 | none | A | DONE | +| `src/omega_blackwell_codegen.c` | 0 | 0 | stdio, stdlib (malloc/free for kernel code, printf in the variation self-test) | A.2 | allocator seam: caller-provided code buffer, self-test moved to the test | +| `src/omega_blackwell_matmul.c` | 0 | 0 | stdlib (free) | A.2 | same allocator seam | +| `src/omega_gpu_wait.c` | 0 | 0 | time.h | C | clock from the platform time service | +| `src/omega_gpu_serving.c` | 0 | 0 | none | C | moves with the session | +| `src/omega_gpu_matmul_api.c` | 0 | 0 | stdlib, stdio, time | C | moves with the session | +| `src/omega_gpu_attention_api.c` | 0 | 0 | stdio, stdlib, time | C | moves with the session | +| `src/omega_gpu_session.c` (+ `.h` leaks `NvrmMem`) | 19 | 7 | pthread, stdio, time | C | `NvrmMem` in the session header becomes `OmegaGpuBufferHandle`; lock from the platform | +| `src/omega_blackwell_engine.c` | 19 | 13 | errno, stdio, time | stays Linux-private | the Linux backend of `OmegaGpuBackend`; a sibling native backend over `OmegaGpuPlatform` arrives in B/C | +| `src/omega_numeric_gb10.c` | 21 | 2 | stdio, stdlib, errno, time | C/D | numeric launchers follow the engine Phase B order | +| `src/omega_numeric_divsqrt_gb10.c` | 20 | 2 | stdio, stdlib, errno, time | C/D | same | +| `src/omega_numeric_reduce_gb10.c` | 17 | 2 | stdio, stdlib, errno, time | C/D | same | +| `src/omega_numeric_ldst_gb10.c` | 16 | 2 | stdio, stdlib | C/D | same | +| `src/omega_blackwell_submit.c` | 41 | 34 | stdio, stdlib, time, unistd | D | vector executor; sha256-pinned by the M17/M18 gates, re-sealed on chip | +| `src/runtime/rx_resident_gpu.c` | 18 | 9 | pthread, stdio, stdlib, unistd | D | resident runtime seat | +| `src/omega_world_gates.c` | 60 | 2 | stdio, stdlib, time, unistd | host tooling | gates and measurement, stays on Linux | +| `src/omega_accelerator_world.c` | 38 | 9 | stdio, stdlib, time, unistd, sys/mman | host tooling | stays on Linux | +| `src/omega_blackwell_gates.c` | 0 | 1 | stdio, stdlib, time | host tooling | stays on Linux | + +Headers that still expose a Linux driver type and must lose it before the cut +that migrates their users: `src/omega_gpu_session.h` (`NvrmMem`, cut C), +`src/omega_numeric_native.h` (C/D), `src/forge_realization.h`, +`src/omega_evidence.h`, `src/omega_accelerator_world.h`, +`src/omega_physics_dir.h` (host tooling; they keep it). + +Distinct driver entry points in use (count of call sites, same snapshot): +`nvrm_mthd` 188, `m16_native_close` 46, `nvrm_alloc` 33, +`nvrm_alloc_gpu_uncached` 30, `m16_native_submit_methods` 11, +`m16_native_create_channel` 10, `nvrm_free` 6, `m16_native_open` 6, +`nvrm_retire` 5, `m16_native_wait_marker` 4, `nvrm_enqueue` 2, +`nvrm_channel_destroy` 2, `nvrm_channel` 2, `m16_native_wait_marker_ge` 2, +`nvrm_ring`, `nvrm_open`, `nvrm_close` 1 each. The 188 `nvrm_mthd` sites are +RM control calls (class allocation, VA space, channel setup); each maps to a +row of section 2, and none of them exists in the native path by design: the +native backend talks to the device through the platform services, not through +an RM method table. + +## 4. The freestanding link target + +`mk/omega-gpu-engine.mk`, targets `gpu-engine-freestanding` and +`test-gpu-engine-freestanding`, run by the `gpu-engine` job of +`.github/workflows/host-suites-2.yml`. + +- Flags: `-std=gnu11 -O2 -Wall -Wextra -Werror -ffreestanding -fno-builtin + -fno-stack-protector -DOMEGA_GPU_NO_POSIX -DOMEGA_NUMERIC_CPU_ONLY`. +- The six objects are partially linked (`gcc -r -nostdlib`); `nm -u` on the + result may show only `memcpy|memmove|memset|memcmp|strlen|strcmp` (and the + GOT symbol). Anything else fails the build with the symbol named. +- `OMEGA_GPU_NO_POSIX` in `src/omega_gpu_engine.c`: `err_no` is recorded as 0 + (there is no errno), there is no default clock, and `omega_gpu_execute` + refuses with `INTERNAL_INVARIANT` at `STEP_CLOCK_CHECK` until + `omega_gpu_engine_set_clock` installed one. The host build is unchanged + (errno captured, `CLOCK_MONOTONIC` default), and the 15 errno pass-through + expectations of the contract test become 0 under the freestanding build. +- The same 49-mutant sweep runs on the host build; the mutation that removes + the poison fill now matches the `ERRNO_CLEAR()` spelling. + +## 5. The platform contract in one page + +`src/omega_gpu_platform.h`, ABI 1.0. + +- Handles: `OmegaGpuDeviceHandle`, `OmegaGpuBufferHandle`, `OmegaGpuQueueHandle`, + each `index + generation`; generation 0 is never issued; a closed handle is + stale and refused; a handle of the wrong kind is refused. +- Addresses: `OmegaCpuView` (pointer + length), `OmegaGpuVa`, `OmegaGpuBusAddr` + are three distinct struct types. No raw physical address type. +- Buffers: `OmegaGpuBufferDesc` carries kind (DATA, CODE, QUEUE), explicit + `bytes`, `rights`, cache policy and alignment. Code is CPU-written and + GPU-executed, never GPU-written; a queue is CPU-written and device-read; a + host-polled word is CPU-read, GPU-written and GPU-uncached. +- Services: TIME, WAIT, LOCK, MMIO, DMA, SYNC, COMPLETION are required for + v1; IRQ is optional and claimed only by a real interrupt wait. + `omega_gpu_platform_check` refuses a claimed service without a function and + refuses a function that no claimed service declares (a hidden path is a + silent fallback). +- Limits and concurrency: `OmegaGpuPlatformCaps` carries device, buffer, + queue, in-flight, per-buffer and total byte limits; + `omega_gpu_platform_negotiate` refuses a required set the platform does not + meet; `OmegaGpuHandleTable` enforces per-kind slot limits and byte totals. +- Refusals: thirteen named codes, no silent fallback to Linux, CPU or a + remote device anywhere in the contract. + +## 6. Next cuts + +- A.2: allocator seam for `omega_blackwell_codegen.c` and + `omega_blackwell_matmul.c` (caller-provided code buffers, self-test printf + moved into the test), adding them to the freestanding target. +- B (needs an attended window, native v1 gate order N1 then N4): AIENOS-side + discovery and bounded device ownership through the platform services; a + discovery-only run makes zero configuration writes; SMMU/DMA resolved; + polling does not claim IRQ. Implement aienos#285 before any domain-1 + resource number is reused or persisted. The arch#163 native-order conflict + is resolved explicitly in that cut, not implied here. +- C: native backend of `OmegaGpuBackend` over `OmegaGpuPlatform`; the + session, serving and API files drop `NvrmMem` and libc time/lock calls. +- D: vector executor (sha256 pin re-sealed on chip), numeric launchers, + resident runtime. + +Pre-existing, unrelated to this cut: `make test-gpu-serving-alloc` fails its +`bounds` mode on omega main 536870f1 ("in-bounds paged calls touched the +driver (1 allocs)"), reproduced on an untouched checkout on 2026-10-12. It +belongs to the matmul serving lane (cut I, omega#414), and is reported there. diff --git a/mk/.crumb b/mk/.crumb index 2fe89fb7f..65c009448 100644 --- a/mk/.crumb +++ b/mk/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-11T15:21:12Z", + "compiled_at": "2026-10-12T10:51:44Z", "compiler": "crumb-compile/1", - "digest": "sha256:ac43a69e03617abcc3c94f3fc1bc10c7593d9d57d49059c20bc4ce3abfaa8489", + "digest": "sha256:09ea357529c7b5ad670bb41f2663e4d11210c1e71d493cded07cf6bc5dd79686", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 67, - "generated_at_commit": "7b4c5827922e7d2632dd631f3d65be82ec4f8b74", - "source_tree": "sha256:3afb292e715afe4210094af3bdff61e9cedc6ed94e902968c0e3aaad0d0f2f04" + "generated_at_commit": "e04bd5021b2a4f311fb9838887c170c4bf3164b6", + "source_tree": "sha256:e23b915251eb5661e6ca1d390d4eda36347eab36f9d846928d270f9bcc9f4e6d" }, "owner_lane": "", "provenance": { diff --git a/mk/omega-gpu-engine.mk b/mk/omega-gpu-engine.mk index 9d9420c17..2579f7f3e 100644 --- a/mk/omega-gpu-engine.mk +++ b/mk/omega-gpu-engine.mk @@ -11,7 +11,11 @@ # (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 +# gpu-engine-freestanding (native v1 P07 cut A) the portable GPU files built -ffreestanding with +# OMEGA_GPU_NO_POSIX: no Linux header, no errno, no clock, no libc beyond mem*/str* +# test-gpu-engine-freestanding the engine contract test and the platform contract test linked against +# those freestanding objects (host runner, opens no device) +.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 gpu-engine-freestanding test-gpu-engine-freestanding 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 @@ -97,3 +101,40 @@ test-gpu-serving-alloc: build/gpu_serving_alloc_count_test @if ./build/gpu_serving_alloc_count_test reserve-skip >build/gpu_serving_alloc_count_skip.log 2>&1; then echo "RED RUN PASSED: the zero-allocation assertion does not need the reservation call"; exit 1; fi @if [ "$$(grep -c "^FAIL" build/gpu_serving_alloc_count_skip.log)" -lt 1 ]; then echo "reserve-skip exited nonzero without a FAIL check (crash, not the red assertion)"; exit 1; fi @echo "reserve-skip (no reservation call): fails as required ($$(grep -c "^FAIL" build/gpu_serving_alloc_count_skip.log) failing checks)" + +# native v1 P07 cut A (aienos#286 cut A, aien-architecture#190): the freestanding link target. +# Each file below is compiled with no hosted headers available (-ffreestanding, -fno-builtin, +# OMEGA_GPU_NO_POSIX) and the partial link of all of them may leave only the mem*/str* symbols +# undefined. Any other undefined symbol (errno, clock_gettime, printf, malloc, pthread_*, nvrm_*, +# m16_*) fails the target. This proves the first-compute PATH links without Linux headers or +# runtime symbols; it proves nothing about device ownership (NOT_RUN until cut B runs on the Spark). +GPU_FS_DIR = build/gpu_fs +GPU_FS_CFLAGS = -std=gnu11 -O2 -Wall -Wextra -Werror -ffreestanding -fno-builtin -fno-stack-protector \ + -DOMEGA_GPU_NO_POSIX -DOMEGA_NUMERIC_CPU_ONLY -Isrc +GPU_FS_SRCS = src/omega_gpu_engine.c src/omega_gpu_platform.c src/omega_blackwell_encoder.c \ + src/omega_blackwell_qmd.c src/omega_blackwell_realize.c src/sha256.c +GPU_FS_OBJS = $(patsubst src/%.c,$(GPU_FS_DIR)/%.o,$(GPU_FS_SRCS)) +GPU_FS_LINK = $(GPU_FS_DIR)/omega_gpu_freestanding.o +GPU_FS_ALLOWED = memcpy|memmove|memset|memcmp|strlen|strcmp + +$(GPU_FS_DIR)/%.o: src/%.c src/omega_gpu_engine.h src/omega_gpu_platform.h + @mkdir -p $(GPU_FS_DIR) + gcc $(GPU_FS_CFLAGS) -c -o $@ $< + +$(GPU_FS_LINK): $(GPU_FS_OBJS) + gcc -r -nostdlib -o $@ $(GPU_FS_OBJS) + @bad=$$(nm -u $@ | awk '{print $$NF}' | grep -Ev '^(_GLOBAL_OFFSET_TABLE_|($(GPU_FS_ALLOWED)))$$' || true); \ + if [ -n "$$bad" ]; then echo "freestanding GPU link still needs: $$bad"; rm -f $@; exit 1; fi + @echo "freestanding GPU link ($(words $(GPU_FS_SRCS)) files): only $$(nm -u $@ | awk '{print $$NF}' | grep -Ev '^_GLOBAL_OFFSET_TABLE_$$' | sort -u | tr '\n' ' ')undefined" +gpu-engine-freestanding: $(GPU_FS_LINK) + +build/test_omega_gpu_engine_freestanding: tests/test_omega_gpu_engine.c $(GPU_FS_DIR)/omega_gpu_engine.o src/omega_gpu_engine.h + @mkdir -p build + gcc -std=gnu11 -O2 -Wall -Wextra -Werror -Isrc -DOMEGA_NUMERIC_CPU_ONLY -DOMEGA_GPU_NO_POSIX \ + -o $@ tests/test_omega_gpu_engine.c $(GPU_FS_DIR)/omega_gpu_engine.o +build/test_omega_gpu_platform: tests/test_omega_gpu_platform.c $(GPU_FS_DIR)/omega_gpu_platform.o src/omega_gpu_platform.h + @mkdir -p build + gcc -std=gnu11 -O2 -Wall -Wextra -Werror -Isrc -o $@ tests/test_omega_gpu_platform.c $(GPU_FS_DIR)/omega_gpu_platform.o +test-gpu-engine-freestanding: $(GPU_FS_LINK) build/test_omega_gpu_engine_freestanding build/test_omega_gpu_platform + ./build/test_omega_gpu_engine_freestanding + ./build/test_omega_gpu_platform diff --git a/src/.crumb b/src/.crumb index c06123ba9..2ee5036fa 100644 --- a/src/.crumb +++ b/src/.crumb @@ -176,14 +176,14 @@ } ], "children_root": "sha256:2f64d32b2351272f4de10e1143efdb74dbc3cae56b1f0a3039ca9edcfebf6e8c", - "compiled_at": "2026-10-12T10:28:55Z", + "compiled_at": "2026-10-12T10:51:44Z", "compiler": "crumb-compile/1", - "digest": "sha256:367e186a354de5a8c64c790ec75e13f168681d09579dad58192c9e995db87ff0", + "digest": "sha256:929078f81753cba5bcf364be0c4da936d8cdff4b879ca6eccf8cbea7724a5b6c", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 451, - "generated_at_commit": "a19147e052a95f949522bdb40a1be2483601a3d9", - "source_tree": "sha256:8702307ccaecffa8ada606d7a60079af5078a7cc311c60407f05b8cbd1416fa1" + "files": 453, + "generated_at_commit": "e04bd5021b2a4f311fb9838887c170c4bf3164b6", + "source_tree": "sha256:80e3c17915d31b2335f9bfde5d01021fe1c847778292891337f80f622748d18b" }, "owner_lane": "", "provenance": { diff --git a/src/omega_blackwell_encoder.c b/src/omega_blackwell_encoder.c index b0611415d..6ab6e7a3f 100644 --- a/src/omega_blackwell_encoder.c +++ b/src/omega_blackwell_encoder.c @@ -1,6 +1,5 @@ #include "omega_blackwell_encoder.h" #include "sha256.h" -#include #include /* @@ -85,9 +84,11 @@ int omega_blackwell_verify_encoder_fixtures(void) { return -1; } + static const char HEXDIGITS[16] = "0123456789abcdef"; char hex[65]; - for (int i = 0; i < 32; i++) { - sprintf(&hex[i * 2], "%02x", digest[i]); + for (int i = 0; i < 32; i++) { /* no sprintf: this file is part of the freestanding link target */ + hex[i * 2] = HEXDIGITS[digest[i] >> 4]; + hex[i * 2 + 1] = HEXDIGITS[digest[i] & 0x0f]; } hex[64] = 0; diff --git a/src/omega_gpu_engine.c b/src/omega_gpu_engine.c index afdb878d1..021332753 100644 --- a/src/omega_gpu_engine.c +++ b/src/omega_gpu_engine.c @@ -19,10 +19,21 @@ */ #include "omega_gpu_engine.h" -#include #include #include +#ifdef OMEGA_GPU_NO_POSIX +/* Freestanding link target (native v1 P07 cut A, aienos#286 cut A): no errno + * and no POSIX clock. err_no is always 0, and the millisecond clock must be + * installed with omega_gpu_engine_set_clock before any job runs; without one + * omega_gpu_execute refuses at STEP_CLOCK_CHECK instead of guessing. */ +#define ERRNO_CLEAR() ((void)0) +#define ERRNO_READ() 0 +#else +#include #include +#define ERRNO_CLEAR() (errno = 0) +#define ERRNO_READ() (errno) +#endif static const char *const FAILURE_NAMES[OMEGA_GPU_ENGINE_FAILURE_COUNT] = { "OK", @@ -79,11 +90,12 @@ static const char *const STEP_NAMES[OMEGA_GPU_ENGINE_STEP_COUNT] = { "SCAN", "FREE", "CLOSE", + "CLOCK_CHECK", }; static _Atomic(const OmegaGpuBackend *) g_backend; static atomic_int g_blocked; -static uint64_t (*g_clock)(void); /* test clock, NULL means CLOCK_MONOTONIC */ +static uint64_t (*g_clock)(void); /* installed clock; NULL means CLOCK_MONOTONIC on the host, none when freestanding */ const char *omega_gpu_engine_failure_name(int failure) { @@ -129,11 +141,22 @@ void omega_gpu_engine_test_force_block(void) atomic_store(&g_blocked, 1); } +void omega_gpu_engine_set_clock(uint64_t (*now_ms)(void)) +{ + g_clock = now_ms; +} + void omega_gpu_engine_test_set_clock(uint64_t (*now_ms)(void)) { g_clock = now_ms; } +#ifdef OMEGA_GPU_NO_POSIX +static uint64_t now_ms(void) +{ + return g_clock ? g_clock() : 0u; /* unreachable without a clock: omega_gpu_execute refuses first */ +} +#else static uint64_t mono_ms(void) { struct timespec ts; @@ -145,6 +168,7 @@ static uint64_t now_ms(void) { return g_clock ? g_clock() : mono_ms(); } +#endif static int backend_complete(const OmegaGpuBackend *b) { @@ -231,15 +255,15 @@ static int leave(const OmegaGpuBackend *b, const Run *run, OmegaGpuResult *resul int e; for (role = (int)OMEGA_GPU_BUF_ROLE_COUNT - 1; role >= 0; role--) { if (!run->allocated[role]) continue; /* MUT:FREE_UNALLOCATED */ - errno = 0; + ERRNO_CLEAR(); rc = b->free_buf(b->ctx, role); /* MUT:FREE_SKIPPED */ - e = errno; + e = ERRNO_READ(); if (rc != 0) cleanup_fault(b, result, OMEGA_GPU_ENGINE_STEP_FREE, e); } if (run->opened) { - errno = 0; + ERRNO_CLEAR(); rc = b->close(b->ctx); /* MUT:CLOSE_SKIPPED */ - e = errno; + e = ERRNO_READ(); if (rc != 0) cleanup_fault(b, result, OMEGA_GPU_ENGINE_STEP_CLOSE, e); } return result->failure; @@ -266,9 +290,9 @@ static int timed_call(int (*fn)(void *, uint64_t), void *ctx, uint64_t ms, uint6 uint64_t t0 = now_ms(); uint64_t t1; int rc; - errno = 0; + ERRNO_CLEAR(); rc = fn(ctx, ms); - *err = errno; + *err = ERRNO_READ(); t1 = now_ms(); *waited_ms = t1 >= t0 ? t1 - t0 : 0u; /* MUT:WAITED_NOT_A_DIFFERENCE */ return rc; @@ -277,9 +301,9 @@ static int timed_call(int (*fn)(void *, uint64_t), void *ctx, uint64_t ms, uint6 static int copy_in_role(const OmegaGpuBackend *b, int role, const void *src, size_t bytes, int *err) { int rc; - errno = 0; + ERRNO_CLEAR(); rc = b->copy_in(b->ctx, role, src, bytes); - *err = errno; + *err = ERRNO_READ(); return rc; } @@ -324,30 +348,34 @@ int omega_gpu_execute(const OmegaGpuJob *job, OmegaGpuResult *result) if (!backend_complete(b)) /* MUT:BACKEND_CHECK_SKIPPED */ return stop(result, OMEGA_GPU_ENGINE_INTERNAL_INVARIANT, OMEGA_GPU_ENGINE_STEP_BACKEND_CHECK); +#ifdef OMEGA_GPU_NO_POSIX + if (!g_clock) /* no platform clock: waited_ms could not be measured; refuse before touching the device */ + return stop(result, OMEGA_GPU_ENGINE_INTERNAL_INVARIANT, OMEGA_GPU_ENGINE_STEP_CLOCK_CHECK); +#endif memset(&run, 0, sizeof run); /* INITIAL -> PREPARED */ - errno = 0; + ERRNO_CLEAR(); rc = b->open_device(b->ctx); - e = errno; + e = ERRNO_READ(); 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; + ERRNO_CLEAR(); rc = b->create_channel(b->ctx); - e = errno; + e = ERRNO_READ(); 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; + ERRNO_CLEAR(); rc = b->alloc(b->ctx, role, buf_bytes(job, role)); - e = errno; + e = ERRNO_READ(); 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 */ @@ -363,15 +391,15 @@ int omega_gpu_execute(const OmegaGpuJob *job, OmegaGpuResult *result) 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 */ + ERRNO_CLEAR(); rc = b->fill_poison(b->ctx, job->poison, job->poison_count); e = ERRNO_READ(); /* 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; + ERRNO_CLEAR(); rc = b->build(b->ctx, job); - e = errno; + e = ERRNO_READ(); if (rc != 0) { (void)fail(b, result, OMEGA_GPU_ENGINE_PREPARE, OMEGA_GPU_ENGINE_STEP_BUILD, e); return leave(b, &run, result); @@ -379,9 +407,9 @@ int omega_gpu_execute(const OmegaGpuJob *job, OmegaGpuResult *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; + ERRNO_CLEAR(); rc = b->submit(b->ctx); - e = errno; + e = ERRNO_READ(); 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 */ @@ -406,9 +434,9 @@ int omega_gpu_execute(const OmegaGpuJob *job, OmegaGpuResult *result) (void)fail(b, result, OMEGA_GPU_ENGINE_VISIBILITY_WAIT, OMEGA_GPU_ENGINE_STEP_BARRIER, e); return leave(b, &run, result); } - errno = 0; + ERRNO_CLEAR(); rc = b->copy_out(b->ctx, job->output, job->output_len); - e = errno; + e = ERRNO_READ(); if (rc != 0) { (void)fail(b, result, OMEGA_GPU_ENGINE_VISIBILITY_WAIT, OMEGA_GPU_ENGINE_STEP_COPY_OUT, e); return leave(b, &run, result); diff --git a/src/omega_gpu_engine.h b/src/omega_gpu_engine.h index 2faed479a..00e81f22e 100644 --- a/src/omega_gpu_engine.h +++ b/src/omega_gpu_engine.h @@ -102,6 +102,7 @@ typedef enum { OMEGA_GPU_ENGINE_STEP_SCAN, OMEGA_GPU_ENGINE_STEP_FREE, OMEGA_GPU_ENGINE_STEP_CLOSE, + OMEGA_GPU_ENGINE_STEP_CLOCK_CHECK, /* freestanding build only: no platform clock installed */ OMEGA_GPU_ENGINE_STEP_COUNT /* not a step: number of names above */ } OmegaGpuEngineStep; @@ -236,9 +237,16 @@ 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. */ +/* Platform time service. Installs the monotonic millisecond clock the engine + * uses to measure waited_ms. Host build: NULL restores CLOCK_MONOTONIC. + * Freestanding build (OMEGA_GPU_NO_POSIX, see src/omega_gpu_platform.h): + * there is no default; omega_gpu_execute refuses with INTERNAL_INVARIANT at + * STEP_CLOCK_CHECK until a clock is installed. Not thread safe: set it before + * any job runs. */ +void omega_gpu_engine_set_clock(uint64_t (*now_ms)(void)); + +/* TEST ONLY. Same as omega_gpu_engine_set_clock; lets host tests assert exact + * waited_ms with a fake clock. Kept so existing tests and mutants read as before. */ void omega_gpu_engine_test_set_clock(uint64_t (*now_ms)(void)); /* Static name strings, never NULL. Out-of-range values give "UNKNOWN". */ diff --git a/src/omega_gpu_platform.c b/src/omega_gpu_platform.c new file mode 100644 index 000000000..a795e0c13 --- /dev/null +++ b/src/omega_gpu_platform.c @@ -0,0 +1,174 @@ +/* omega_gpu_platform.c -- contract checks and the handle table of + * src/omega_gpu_platform.h. Freestanding: no libc beyond memset. */ +#include "omega_gpu_platform.h" + +#include + +static const char *const REFUSAL_NAMES[OMEGA_GPU_PLAT_REFUSAL_COUNT] = { + "OK", + "REFUSED_ARGS", + "REFUSED_ABI", + "REFUSED_MISSING_SERVICE", + "REFUSED_NULL_SERVICE", + "REFUSED_BAD_HANDLE", + "REFUSED_STALE_HANDLE", + "REFUSED_BAD_LENGTH", + "REFUSED_BAD_RIGHTS", + "REFUSED_BAD_KIND", + "REFUSED_CACHE_POLICY", + "REFUSED_LIMIT", + "REFUSED_BUSY", +}; + +const char *omega_gpu_platform_refusal_name(int refusal) +{ + if (refusal < 0 || refusal >= (int)OMEGA_GPU_PLAT_REFUSAL_COUNT) return "UNKNOWN"; + return REFUSAL_NAMES[refusal]; +} + +int omega_gpu_platform_negotiate(const OmegaGpuPlatformCaps *provided, const OmegaGpuPlatformCaps *required) +{ + if (!provided || !required) return OMEGA_GPU_PLAT_REFUSED_ARGS; + if (provided->abi_major != required->abi_major) return OMEGA_GPU_PLAT_REFUSED_ABI; + if (provided->abi_minor < required->abi_minor) return OMEGA_GPU_PLAT_REFUSED_ABI; + if ((provided->services | required->services) & ~OMEGA_GPU_SVC_ALL) return OMEGA_GPU_PLAT_REFUSED_ARGS; + if (required->services & ~provided->services) return OMEGA_GPU_PLAT_REFUSED_MISSING_SERVICE; + if (required->max_devices > provided->max_devices) return OMEGA_GPU_PLAT_REFUSED_LIMIT; + if (required->max_buffers > provided->max_buffers) return OMEGA_GPU_PLAT_REFUSED_LIMIT; + if (required->max_queues > provided->max_queues) return OMEGA_GPU_PLAT_REFUSED_LIMIT; + if (required->max_inflight > provided->max_inflight) return OMEGA_GPU_PLAT_REFUSED_LIMIT; + if (required->max_buffer_bytes > provided->max_buffer_bytes) return OMEGA_GPU_PLAT_REFUSED_LIMIT; + if (required->max_total_bytes > provided->max_total_bytes) return OMEGA_GPU_PLAT_REFUSED_LIMIT; + return OMEGA_GPU_PLAT_OK; +} + +/* A claimed service must have its functions; an unclaimed one must have none + * (a function the table never negotiated would be a silent fallback path). */ +static int svc(uint32_t services, uint32_t bit, int present_all, int present_any) +{ + if (services & bit) return present_all ? OMEGA_GPU_PLAT_OK : OMEGA_GPU_PLAT_REFUSED_NULL_SERVICE; + return present_any ? OMEGA_GPU_PLAT_REFUSED_ARGS : OMEGA_GPU_PLAT_OK; +} + +int omega_gpu_platform_check(const OmegaGpuPlatform *p, const OmegaGpuPlatformCaps *caps) +{ + int rc; + uint32_t s; + if (!p || !caps) return OMEGA_GPU_PLAT_REFUSED_ARGS; + s = caps->services; + if (s & ~OMEGA_GPU_SVC_ALL) return OMEGA_GPU_PLAT_REFUSED_ARGS; + if ((s & OMEGA_GPU_SVC_REQUIRED_V1) != OMEGA_GPU_SVC_REQUIRED_V1) return OMEGA_GPU_PLAT_REFUSED_MISSING_SERVICE; + if ((rc = svc(s, OMEGA_GPU_SVC_TIME, p->time_now_ms != 0, p->time_now_ms != 0)) != 0) return rc; + if ((rc = svc(s, OMEGA_GPU_SVC_WAIT, p->wait_ms != 0, p->wait_ms != 0)) != 0) return rc; + if ((rc = svc(s, OMEGA_GPU_SVC_LOCK, p->lock != 0 && p->unlock != 0, p->lock != 0 || p->unlock != 0)) != 0) + return rc; + if ((rc = svc(s, OMEGA_GPU_SVC_MMIO, p->mmio_read32 != 0 && p->mmio_write32 != 0, + p->mmio_read32 != 0 || p->mmio_write32 != 0)) != 0) + return rc; + if ((rc = svc(s, OMEGA_GPU_SVC_DMA, p->dma_alloc != 0 && p->dma_free != 0, + p->dma_alloc != 0 || p->dma_free != 0)) != 0) + return rc; + if ((rc = svc(s, OMEGA_GPU_SVC_SYNC, p->sync_cpu_to_gpu != 0 && p->sync_gpu_to_cpu != 0, + p->sync_cpu_to_gpu != 0 || p->sync_gpu_to_cpu != 0)) != 0) + return rc; + if ((rc = svc(s, OMEGA_GPU_SVC_COMPLETION, p->wait_word != 0, p->wait_word != 0)) != 0) return rc; + if ((rc = svc(s, OMEGA_GPU_SVC_IRQ, p->irq_wait != 0, p->irq_wait != 0)) != 0) return rc; + return OMEGA_GPU_PLAT_OK; +} + +static int is_pow2(uint32_t v) +{ + return v != 0u && (v & (v - 1u)) == 0u; +} + +int omega_gpu_platform_check_buffer(const OmegaGpuBufferDesc *d, const OmegaGpuPlatformCaps *caps) +{ + uint32_t r; + if (!d || !caps) return OMEGA_GPU_PLAT_REFUSED_ARGS; + if (d->kind != OMEGA_GPU_HANDLE_BUF_DATA && d->kind != OMEGA_GPU_HANDLE_BUF_CODE && + d->kind != OMEGA_GPU_HANDLE_BUF_QUEUE) + return OMEGA_GPU_PLAT_REFUSED_BAD_KIND; + if (d->bytes == 0u) return OMEGA_GPU_PLAT_REFUSED_BAD_LENGTH; + if (d->bytes > caps->max_buffer_bytes) return OMEGA_GPU_PLAT_REFUSED_LIMIT; + if (d->align != 0u && !is_pow2(d->align)) return OMEGA_GPU_PLAT_REFUSED_ARGS; + if (d->gpu_cache != OMEGA_GPU_CACHE_GPU_UNCACHED && d->gpu_cache != OMEGA_GPU_CACHE_GPU_CACHED) + return OMEGA_GPU_PLAT_REFUSED_ARGS; + r = d->rights; + if (r == 0u || (r & ~OMEGA_GPU_RIGHT_ALL)) return OMEGA_GPU_PLAT_REFUSED_BAD_RIGHTS; + if ((r & OMEGA_GPU_RIGHT_GPU_EXEC) && d->kind != OMEGA_GPU_HANDLE_BUF_CODE) return OMEGA_GPU_PLAT_REFUSED_BAD_RIGHTS; + if (d->kind == OMEGA_GPU_HANDLE_BUF_CODE) { + /* code: CPU writes it, GPU executes it, GPU never writes it, nobody polls it */ + if (r & (OMEGA_GPU_RIGHT_GPU_WRITE | OMEGA_GPU_RIGHT_HOST_POLLED)) return OMEGA_GPU_PLAT_REFUSED_BAD_RIGHTS; + if (!(r & OMEGA_GPU_RIGHT_GPU_EXEC) || !(r & OMEGA_GPU_RIGHT_CPU_WRITE)) return OMEGA_GPU_PLAT_REFUSED_BAD_RIGHTS; + } + if (d->kind == OMEGA_GPU_HANDLE_BUF_QUEUE) { + /* a submission ring: the CPU writes methods, the device reads them */ + if (!(r & OMEGA_GPU_RIGHT_CPU_WRITE) || !(r & OMEGA_GPU_RIGHT_GPU_READ)) return OMEGA_GPU_PLAT_REFUSED_BAD_RIGHTS; + } + if (r & OMEGA_GPU_RIGHT_HOST_POLLED) { + if (!(r & OMEGA_GPU_RIGHT_CPU_READ) || !(r & OMEGA_GPU_RIGHT_GPU_WRITE)) return OMEGA_GPU_PLAT_REFUSED_BAD_RIGHTS; + if (d->gpu_cache != OMEGA_GPU_CACHE_GPU_UNCACHED) return OMEGA_GPU_PLAT_REFUSED_CACHE_POLICY; + } + return OMEGA_GPU_PLAT_OK; +} + +void omega_gpu_handles_init(OmegaGpuHandleTable *t) +{ + uint32_t i; + if (!t) return; + memset(t, 0, sizeof *t); + for (i = 0; i < OMEGA_GPU_HANDLE_SLOTS; i++) t->generation[i] = 1u; +} + +static int kind_known(uint32_t kind) +{ + return kind >= OMEGA_GPU_HANDLE_DEVICE && kind < OMEGA_GPU_HANDLE_KIND_COUNT; +} + +int omega_gpu_handles_open(OmegaGpuHandleTable *t, uint32_t kind, uint64_t bytes, uint32_t limit_slots, + uint64_t limit_bytes, uint32_t *index, uint32_t *generation) +{ + uint32_t i; + uint32_t same_kind = 0; + if (!t || !index || !generation) return OMEGA_GPU_PLAT_REFUSED_ARGS; + if (!kind_known(kind)) return OMEGA_GPU_PLAT_REFUSED_BAD_KIND; + for (i = 0; i < OMEGA_GPU_HANDLE_SLOTS; i++) + if (t->live[i] && t->kind[i] == kind) same_kind++; + if (same_kind >= limit_slots) return OMEGA_GPU_PLAT_REFUSED_LIMIT; + if (bytes != 0u && (bytes > limit_bytes || t->total_bytes > limit_bytes - bytes)) /* byte accounting: buffers only */ + return OMEGA_GPU_PLAT_REFUSED_LIMIT; + for (i = 0; i < OMEGA_GPU_HANDLE_SLOTS; i++) { + if (t->live[i]) continue; + if (t->generation[i] == 0u) continue; /* generation wrapped: the slot is retired, never reissued */ + t->live[i] = 1; + t->kind[i] = kind; + t->bytes[i] = bytes; + t->nlive++; + t->total_bytes += bytes; + *index = i; + *generation = t->generation[i]; + return OMEGA_GPU_PLAT_OK; + } + return OMEGA_GPU_PLAT_REFUSED_LIMIT; +} + +int omega_gpu_handles_check(const OmegaGpuHandleTable *t, uint32_t index, uint32_t generation, uint32_t kind) +{ + if (!t) return OMEGA_GPU_PLAT_REFUSED_ARGS; + if (index >= OMEGA_GPU_HANDLE_SLOTS || generation == 0u) return OMEGA_GPU_PLAT_REFUSED_BAD_HANDLE; + if (!t->live[index] || t->generation[index] != generation) return OMEGA_GPU_PLAT_REFUSED_STALE_HANDLE; + if (t->kind[index] != kind) return OMEGA_GPU_PLAT_REFUSED_BAD_HANDLE; + return OMEGA_GPU_PLAT_OK; +} + +int omega_gpu_handles_close(OmegaGpuHandleTable *t, uint32_t index, uint32_t generation, uint32_t kind) +{ + int rc = omega_gpu_handles_check(t, index, generation, kind); + if (rc != OMEGA_GPU_PLAT_OK) return rc; + t->live[index] = 0; + t->total_bytes -= t->bytes[index]; + t->bytes[index] = 0u; + t->nlive--; + t->generation[index]++; /* the closed handle is now stale; 0 after wrap retires the slot */ + return OMEGA_GPU_PLAT_OK; +} diff --git a/src/omega_gpu_platform.h b/src/omega_gpu_platform.h new file mode 100644 index 000000000..daca3c4cf --- /dev/null +++ b/src/omega_gpu_platform.h @@ -0,0 +1,205 @@ +/* omega_gpu_platform.h -- native platform contract for the Omega GPU engine. + * + * Native v1 P07 cut A (aienos#286 cut A, aien-architecture#190). This header + * names what a GPU backend may ask of the platform it runs on, in a form that + * works the same under Linux (today's nvrm/m16 backend) and under AIENOS + * (the native backend of later cuts). It is pure C with no Linux header and + * no libc call; it builds in the freestanding link target + * (`make gpu-engine-freestanding`). + * + * Rules (from aienos#286 cut A): + * - Resources are typed handles (index + generation), never a Linux fd, a + * raw pointer or an unchecked physical address. A handle is valid only + * while its slot generation matches, so a closed handle is refused. + * - Every byte range carries an explicit length and explicit rights. + * - CPU views, GPU virtual addresses and bus (SMMU input) addresses are + * three distinct types. There is no type for a raw physical address on + * purpose: the native backend resolves DMA through the SMMU (cut B). + * - Buffers, code and queues have separate kinds and lifetimes. + * - A backend negotiates an ABI version and a service set up front; what + * the platform does not provide is refused, never emulated. There is no + * silent fallback to Linux, to the CPU, or to a remote device. + * - Polling a word is not interrupt support: OMEGA_GPU_SVC_IRQ is claimed + * only by a platform whose irq_wait blocks on a real device interrupt. + * - Anything the CPU polls for a device write (completion markers, + * semaphores) is OMEGA_GPU_RIGHT_HOST_POLLED and must be GPU-uncached + * (nvidia-open 580.173.02 nvos.h: GPU-cacheable system memory "will not + * be coherent with direct CPU mappings"; the 2026-10-02 E1 stall). + * + * What this header does NOT claim: no device has been opened through it, no + * GB10 register has been touched, and the Linux backend still owns every + * driver responsibility (docs/numeric/OMEGA_GPU_NATIVE_BOUNDARY.md). Hardware + * evidence for device ownership is NOT_RUN until cut B runs in an attended + * window. + */ +#ifndef OMEGA_GPU_PLATFORM_H +#define OMEGA_GPU_PLATFORM_H + +#include +#include + +#define OMEGA_GPU_PLATFORM_ABI_MAJOR 1u +#define OMEGA_GPU_PLATFORM_ABI_MINOR 0u + +/* ---- typed handles ------------------------------------------------------ */ + +/* Generation 0 is never issued, so a zeroed handle is "none". */ +typedef struct { uint32_t index; uint32_t generation; } OmegaGpuDeviceHandle; +typedef struct { uint32_t index; uint32_t generation; } OmegaGpuBufferHandle; +typedef struct { uint32_t index; uint32_t generation; } OmegaGpuQueueHandle; + +/* Handle kinds (also the buffer kinds below share the BUF_* space). */ +typedef enum { + OMEGA_GPU_HANDLE_DEVICE = 1, + OMEGA_GPU_HANDLE_BUF_DATA = 2, /* inputs, outputs, scratch */ + OMEGA_GPU_HANDLE_BUF_CODE = 3, /* kernel code: CPU writes once, GPU executes, GPU never writes */ + OMEGA_GPU_HANDLE_BUF_QUEUE = 4, /* pushbuffer / submission ring */ + OMEGA_GPU_HANDLE_QUEUE = 5, /* a channel or submission queue */ + OMEGA_GPU_HANDLE_KIND_COUNT +} OmegaGpuHandleKind; + +/* ---- address kinds ------------------------------------------------------ */ + +typedef struct { void *ptr; size_t len; } OmegaCpuView; /* CPU mapping with its length */ +typedef struct { uint64_t va; } OmegaGpuVa; /* GPU virtual address (device page tables) */ +typedef struct { uint64_t iova; } OmegaGpuBusAddr; /* what the device emits on the fabric (SMMU input) */ + +/* ---- rights and buffer descriptors -------------------------------------- */ + +enum { + OMEGA_GPU_RIGHT_CPU_READ = 1u << 0, + OMEGA_GPU_RIGHT_CPU_WRITE = 1u << 1, + OMEGA_GPU_RIGHT_GPU_READ = 1u << 2, + OMEGA_GPU_RIGHT_GPU_WRITE = 1u << 3, + OMEGA_GPU_RIGHT_GPU_EXEC = 1u << 4, /* code buffers only */ + OMEGA_GPU_RIGHT_HOST_POLLED = 1u << 5, /* CPU polls a device write here: must be GPU-uncached */ + OMEGA_GPU_RIGHT_ALL = (1u << 6) - 1u +}; + +typedef enum { OMEGA_GPU_CACHE_GPU_UNCACHED = 0, OMEGA_GPU_CACHE_GPU_CACHED = 1 } OmegaGpuCachePolicy; + +typedef struct { + uint32_t kind; /* OMEGA_GPU_HANDLE_BUF_DATA, _BUF_CODE or _BUF_QUEUE */ + uint32_t rights; /* OMEGA_GPU_RIGHT_* mask, never 0 */ + uint32_t gpu_cache; /* OmegaGpuCachePolicy */ + uint32_t align; /* bytes, a power of two, 0 means the platform minimum */ + uint64_t bytes; /* explicit length, never 0 */ +} OmegaGpuBufferDesc; + +/* ---- services and capabilities ------------------------------------------ */ + +enum { + OMEGA_GPU_SVC_TIME = 1u << 0, /* monotonic millisecond clock */ + OMEGA_GPU_SVC_WAIT = 1u << 1, /* bounded sleep or yield */ + OMEGA_GPU_SVC_LOCK = 1u << 2, /* mutual exclusion for queues and tables */ + OMEGA_GPU_SVC_MMIO = 1u << 3, /* bounded register access by device handle and region */ + OMEGA_GPU_SVC_DMA = 1u << 4, /* device-visible memory with CPU view, GPU VA and bus address */ + OMEGA_GPU_SVC_SYNC = 1u << 5, /* explicit CPU<->GPU visibility (cache maintenance, flush) */ + OMEGA_GPU_SVC_COMPLETION = 1u << 6, /* wait on an uncached word (polling) */ + OMEGA_GPU_SVC_IRQ = 1u << 7, /* real device interrupt wait; polling never counts */ + OMEGA_GPU_SVC_REQUIRED_V1 = OMEGA_GPU_SVC_TIME | OMEGA_GPU_SVC_WAIT | OMEGA_GPU_SVC_LOCK | + OMEGA_GPU_SVC_MMIO | OMEGA_GPU_SVC_DMA | OMEGA_GPU_SVC_SYNC | + OMEGA_GPU_SVC_COMPLETION, + OMEGA_GPU_SVC_ALL = (1u << 8) - 1u +}; + +typedef struct { + uint32_t abi_major; + uint32_t abi_minor; + uint32_t services; /* OMEGA_GPU_SVC_* provided (or required) */ + uint32_t max_devices; + uint32_t max_buffers; /* live buffer handles */ + uint32_t max_queues; + uint32_t max_inflight; /* jobs in flight per queue (concurrency limit) */ + uint64_t max_buffer_bytes; /* one buffer */ + uint64_t max_total_bytes; /* all live buffers */ +} OmegaGpuPlatformCaps; + +/* ---- refusals ----------------------------------------------------------- */ + +typedef enum { + OMEGA_GPU_PLAT_OK = 0, + OMEGA_GPU_PLAT_REFUSED_ARGS, /* NULL or malformed argument */ + OMEGA_GPU_PLAT_REFUSED_ABI, /* major differs, or provided minor older than required */ + OMEGA_GPU_PLAT_REFUSED_MISSING_SERVICE, /* a required service is not provided */ + OMEGA_GPU_PLAT_REFUSED_NULL_SERVICE, /* a claimed service has no function */ + OMEGA_GPU_PLAT_REFUSED_BAD_HANDLE, /* index out of range or kind mismatch */ + OMEGA_GPU_PLAT_REFUSED_STALE_HANDLE, /* generation mismatch: closed or never opened */ + OMEGA_GPU_PLAT_REFUSED_BAD_LENGTH, /* zero length */ + OMEGA_GPU_PLAT_REFUSED_BAD_RIGHTS, /* empty, unknown or contradictory rights */ + OMEGA_GPU_PLAT_REFUSED_BAD_KIND, /* unknown kind */ + OMEGA_GPU_PLAT_REFUSED_CACHE_POLICY, /* host-polled buffer asked to be GPU-cached */ + OMEGA_GPU_PLAT_REFUSED_LIMIT, /* a capability limit would be exceeded */ + OMEGA_GPU_PLAT_REFUSED_BUSY, /* concurrency limit reached */ + OMEGA_GPU_PLAT_REFUSAL_COUNT +} OmegaGpuPlatformRefusal; + +const char *omega_gpu_platform_refusal_name(int refusal); /* static strings, never NULL */ + +/* ---- the platform service table ----------------------------------------- */ + +typedef struct { + void *ctx; + /* TIME, WAIT, LOCK */ + uint64_t (*time_now_ms)(void *ctx); + int (*wait_ms)(void *ctx, uint64_t ms); + int (*lock)(void *ctx, uint32_t lock_id); + int (*unlock)(void *ctx, uint32_t lock_id); + /* MMIO: bounded by (device, region); the platform refuses an offset past the region. */ + int (*mmio_read32)(void *ctx, OmegaGpuDeviceHandle dev, uint32_t region, uint64_t offset, uint32_t *out); + int (*mmio_write32)(void *ctx, OmegaGpuDeviceHandle dev, uint32_t region, uint64_t offset, uint32_t value); + /* DMA: one allocation yields a handle plus the three views; free by handle only. */ + int (*dma_alloc)(void *ctx, OmegaGpuDeviceHandle dev, const OmegaGpuBufferDesc *desc, + OmegaGpuBufferHandle *out, OmegaCpuView *cpu, OmegaGpuVa *gpu, OmegaGpuBusAddr *bus); + int (*dma_free)(void *ctx, OmegaGpuBufferHandle buf); + /* SYNC: explicit visibility over a byte range of one buffer. */ + int (*sync_cpu_to_gpu)(void *ctx, OmegaGpuBufferHandle buf, uint64_t offset, uint64_t len); + int (*sync_gpu_to_cpu)(void *ctx, OmegaGpuBufferHandle buf, uint64_t offset, uint64_t len); + /* COMPLETION: poll one uncached 32-bit word until it equals expected or timeout_ms passes. */ + int (*wait_word)(void *ctx, OmegaGpuBufferHandle buf, uint64_t offset, uint32_t expected, + uint64_t timeout_ms, uint32_t *observed); + /* IRQ: NULL unless OMEGA_GPU_SVC_IRQ is claimed. */ + int (*irq_wait)(void *ctx, OmegaGpuDeviceHandle dev, uint64_t timeout_ms); +} OmegaGpuPlatform; + +/* ---- contract checks (pure, freestanding) -------------------------------- */ + +/* Version and service negotiation. required.services must be a subset of + * provided.services, required limits must not exceed provided limits. */ +int omega_gpu_platform_negotiate(const OmegaGpuPlatformCaps *provided, const OmegaGpuPlatformCaps *required); + +/* Every service in caps->services has a function in p; every function + * outside caps->services is NULL (no undeclared service, no fallback); the + * v1 required set is present. */ +int omega_gpu_platform_check(const OmegaGpuPlatform *p, const OmegaGpuPlatformCaps *caps); + +/* Buffer descriptor rules: kind known, length non-zero and within caps, + * rights non-empty and consistent with the kind, host-polled means + * GPU-uncached, align a power of two. */ +int omega_gpu_platform_check_buffer(const OmegaGpuBufferDesc *d, const OmegaGpuPlatformCaps *caps); + +/* ---- handle table (index + generation) ----------------------------------- */ + +#define OMEGA_GPU_HANDLE_SLOTS 64u + +typedef struct { + uint32_t generation[OMEGA_GPU_HANDLE_SLOTS]; /* next generation to issue for the slot; starts at 1 */ + uint32_t kind[OMEGA_GPU_HANDLE_SLOTS]; + uint64_t bytes[OMEGA_GPU_HANDLE_SLOTS]; + uint8_t live[OMEGA_GPU_HANDLE_SLOTS]; + uint32_t nlive; + uint64_t total_bytes; +} OmegaGpuHandleTable; + +void omega_gpu_handles_init(OmegaGpuHandleTable *t); +/* Opens a slot of the given kind. limit_slots caps live handles of that kind. + * bytes is accounted against limit_bytes across all slots; devices and queues + * pass bytes 0 and are not byte-accounted. */ +int omega_gpu_handles_open(OmegaGpuHandleTable *t, uint32_t kind, uint64_t bytes, uint32_t limit_slots, + uint64_t limit_bytes, uint32_t *index, uint32_t *generation); +/* OK only for a live slot whose generation and kind match. */ +int omega_gpu_handles_check(const OmegaGpuHandleTable *t, uint32_t index, uint32_t generation, uint32_t kind); +/* Closes a live, matching slot and bumps its generation so the old handle is stale. */ +int omega_gpu_handles_close(OmegaGpuHandleTable *t, uint32_t index, uint32_t generation, uint32_t kind); + +#endif /* OMEGA_GPU_PLATFORM_H */ diff --git a/tests/.crumb b/tests/.crumb index 790472a55..d9385e8d0 100644 --- a/tests/.crumb +++ b/tests/.crumb @@ -290,14 +290,14 @@ } ], "children_root": "sha256:9597c068d5bf4eb27f1d91842813a2b10269c2ccae421dceefb4308030ec0fc2", - "compiled_at": "2026-10-12T10:28:55Z", + "compiled_at": "2026-10-12T10:51:44Z", "compiler": "crumb-compile/1", - "digest": "sha256:8a71f0ad0592cd5203841779f40edd0aa2628635b6878d6f9bf18ae5fc4f709c", + "digest": "sha256:38c14347e7f7885f0858c2e66c9cb8d029ad128c80cc84818ceda5e7d77de7e3", "evidence_files": 16, "evidence_root": "sha256:96d08097822ad95f4e562c19e0ba5df5a035774c48632f1832912c40a27bd27a", - "files": 1024, - "generated_at_commit": "a19147e052a95f949522bdb40a1be2483601a3d9", - "source_tree": "sha256:c2abb5b543c07e0b4dfd1fdb44eebd1d007d522fafcc8707b47a48a6cc2fb095" + "files": 1025, + "generated_at_commit": "e04bd5021b2a4f311fb9838887c170c4bf3164b6", + "source_tree": "sha256:efe76096c973d3bfeb051874d5a71de55419609a2558298731f97d413731157c" }, "owner_lane": "", "provenance": { diff --git a/tests/test_omega_gpu_engine.c b/tests/test_omega_gpu_engine.c index d0eec4624..254c7ee04 100644 --- a/tests/test_omega_gpu_engine.c +++ b/tests/test_omega_gpu_engine.c @@ -18,6 +18,11 @@ #define N 16u #define INJ_ERRNO EIO +#ifdef OMEGA_GPU_NO_POSIX +#define EXPECT_ERRNO 0 /* the freestanding engine (make test-gpu-engine-freestanding) records no errno */ +#else +#define EXPECT_ERRNO INJ_ERRNO +#endif #define DIAG_RC (-1234) #define DIAG_TEXT "fake driver text" #define LOGMAX 64 @@ -567,7 +572,7 @@ static void case_open_channel_alloc_prepare(void) 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_passthrough(&r, EXPECT_ERRNO); expect_log(want, LOGLEN(want)); expect_released(&r); expect_no_host_output(); @@ -581,7 +586,7 @@ static void case_open_channel_alloc_prepare(void) 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_passthrough(&r, EXPECT_ERRNO); expect_log(want, LOGLEN(want)); expect_released(&r); expect_no_host_output(); @@ -596,7 +601,7 @@ static void case_open_channel_alloc_prepare(void) 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_passthrough(&r, EXPECT_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); @@ -614,7 +619,7 @@ static void case_open_channel_alloc_prepare(void) 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_passthrough(&r, EXPECT_ERRNO); expect_log(want, LOGLEN(want)); expect_released(&r); case_end("FAIL_PREPARE_COPY_IN"); @@ -628,7 +633,7 @@ static void case_open_channel_alloc_prepare(void) 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_passthrough(&r, EXPECT_ERRNO); expect_log(want, LOGLEN(want)); expect_released(&r); case_end("FAIL_PREPARE_FILL_POISON"); @@ -642,7 +647,7 @@ static void case_open_channel_alloc_prepare(void) 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_passthrough(&r, EXPECT_ERRNO); expect_log(want, LOGLEN(want)); expect_released(&r); case_end("FAIL_PREPARE_BUILD"); @@ -663,7 +668,7 @@ static void case_submit_and_visibility(void) 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_passthrough(&r, EXPECT_ERRNO); expect_log(want, LOGLEN(want)); EXPECT(F.submit_seen == 0); expect_released(&r); /* SUBMIT is a known failure: cleaned up, not blocked */ @@ -678,7 +683,7 @@ static void case_submit_and_visibility(void) 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_passthrough(&r, EXPECT_ERRNO); expect_log(want, LOGLEN(want)); expect_released(&r); /* completion is known: cleaned up, not blocked */ expect_no_host_output(); @@ -692,7 +697,7 @@ static void case_submit_and_visibility(void) 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_passthrough(&r, EXPECT_ERRNO); expect_log(want, LOGLEN(want)); expect_released(&r); case_end("FAIL_VISIBILITY_COPY_OUT"); @@ -718,7 +723,7 @@ static void case_uncertain(void) 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_passthrough(&r, EXPECT_ERRNO); expect_log(want, LOGLEN(want)); expect_retained(&r); expect_no_host_output(); @@ -758,7 +763,7 @@ static void case_uncertain(void) 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_passthrough(&r, EXPECT_ERRNO); expect_log(want, LOGLEN(want)); expect_retained(&r); case_end("UNCERTAIN_MARKER2_UNKNOWN_STATE"); @@ -775,7 +780,7 @@ static void case_uncertain(void) OMEGA_GPU_ENGINE_WAIT_RELEASE_SEMAPHORE); EXPECT(r.wait_timeout_ms == TMO_RELEASE); EXPECT(r.waited_ms == 777u); - expect_passthrough(&r, INJ_ERRNO); + expect_passthrough(&r, EXPECT_ERRNO); expect_log(want, LOGLEN(want)); expect_retained(&r); case_end("UNCERTAIN_RELEASE_DRIVER_FAULT"); @@ -879,7 +884,7 @@ static void case_cleanup_faults(void) 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_passthrough(&r, EXPECT_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)); @@ -893,7 +898,7 @@ static void case_cleanup_faults(void) 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_passthrough(&r, EXPECT_ERRNO); EXPECT(F.count[C_FREE] == 5); EXPECT(omega_gpu_engine_is_blocked() == 0); case_end("CLEANUP_CLOSE_FAILS_AFTER_GOOD_RUN"); @@ -922,7 +927,7 @@ static void case_cleanup_faults(void) EXPECT(F.count[C_FREE] == 5); EXPECT(F.count[C_CLOSE] == 1); EXPECT(F.count[C_DIAG] == 1); - expect_passthrough(&r, INJ_ERRNO); + expect_passthrough(&r, EXPECT_ERRNO); case_end("CLEANUP_FAULT_NEVER_OVERWRITES_FIRST_FAILURE"); /* unchanged output plus a close fault: still OUTPUT_UNCHANGED */ @@ -1100,6 +1105,31 @@ static void case_block_and_backend(void) case_end("BACKEND_TABLE_INCOMPLETE_REFUSED"); } +#ifdef OMEGA_GPU_NO_POSIX +/* Freestanding engine only: with no platform clock installed every job is + * refused before any backend call; installing one through the production + * setter makes the same job run. */ +static void case_platform_clock(void) +{ + OmegaGpuJob job; + OmegaGpuResult r; + int rc; + reset_all(); make_job(&job); + omega_gpu_engine_set_clock(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_CLOCK_CHECK, OMEGA_GPU_ENGINE_WAIT_NONE); + EXPECT(F.nlog == 0); + EXPECT(strcmp(omega_gpu_engine_step_name(r.failed_step), "CLOCK_CHECK") == 0); + omega_gpu_engine_set_clock(fake_now); + rc = run(&job, &r); + EXPECT(rc == OMEGA_GPU_ENGINE_OK); + EXPECT(F.nlog > 0); + case_end("FREESTANDING_NO_CLOCK_REFUSED_BEFORE_ANY_CALL"); +} +#endif + int main(void) { omega_gpu_engine_test_set_clock(fake_now); @@ -1113,6 +1143,9 @@ int main(void) case_cleanup_faults(); case_invalid_args(); case_block_and_backend(); +#ifdef OMEGA_GPU_NO_POSIX + case_platform_clock(); +#endif omega_gpu_engine_set_backend(NULL); omega_gpu_engine_test_reset_block(); diff --git a/tests/test_omega_gpu_platform.c b/tests/test_omega_gpu_platform.c new file mode 100644 index 000000000..ceeba2f54 --- /dev/null +++ b/tests/test_omega_gpu_platform.c @@ -0,0 +1,264 @@ +/* Contract tests for src/omega_gpu_platform.h (native v1 P07 cut A). Host + * program, links the FREESTANDING object of src/omega_gpu_platform.c. Opens + * no device. Every rule in the header comment has a case here, and every + * refusal name is reached at least once. */ +#include "omega_gpu_platform.h" + +#include +#include + +static int n_pass, n_fail, case_ok; +#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++; else n_fail++; + printf("%s %s\n", case_ok ? "PASS" : "FAIL", id); +} + +/* ---- a complete fake platform (no device behind it) ---------------------- */ +static uint64_t f_now(void *c) { (void)c; return 1u; } +static int f_wait(void *c, uint64_t ms) { (void)c; (void)ms; return 0; } +static int f_lock(void *c, uint32_t id) { (void)c; (void)id; return 0; } +static int f_rd(void *c, OmegaGpuDeviceHandle d, uint32_t r, uint64_t o, uint32_t *v) { (void)c; (void)d; (void)r; (void)o; *v = 0; return 0; } +static int f_wr(void *c, OmegaGpuDeviceHandle d, uint32_t r, uint64_t o, uint32_t v) { (void)c; (void)d; (void)r; (void)o; (void)v; return 0; } +static int f_alloc(void *c, OmegaGpuDeviceHandle d, const OmegaGpuBufferDesc *desc, OmegaGpuBufferHandle *o, + OmegaCpuView *cpu, OmegaGpuVa *g, OmegaGpuBusAddr *b) +{ (void)c; (void)d; (void)desc; (void)o; (void)cpu; (void)g; (void)b; return 0; } +static int f_free(void *c, OmegaGpuBufferHandle b) { (void)c; (void)b; return 0; } +static int f_sync(void *c, OmegaGpuBufferHandle b, uint64_t o, uint64_t l) { (void)c; (void)b; (void)o; (void)l; return 0; } +static int f_word(void *c, OmegaGpuBufferHandle b, uint64_t o, uint32_t e, uint64_t t, uint32_t *v) { (void)c; (void)b; (void)o; (void)e; (void)t; *v = 0; return 0; } +static int f_irq(void *c, OmegaGpuDeviceHandle d, uint64_t t) { (void)c; (void)d; (void)t; return 0; } + +static void full_platform(OmegaGpuPlatform *p) +{ + memset(p, 0, sizeof *p); + p->time_now_ms = f_now; p->wait_ms = f_wait; p->lock = f_lock; p->unlock = f_lock; + p->mmio_read32 = f_rd; p->mmio_write32 = f_wr; p->dma_alloc = f_alloc; p->dma_free = f_free; + p->sync_cpu_to_gpu = f_sync; p->sync_gpu_to_cpu = f_sync; p->wait_word = f_word; +} + +static void caps_v1(OmegaGpuPlatformCaps *c) +{ + memset(c, 0, sizeof *c); + c->abi_major = OMEGA_GPU_PLATFORM_ABI_MAJOR; c->abi_minor = OMEGA_GPU_PLATFORM_ABI_MINOR; + c->services = OMEGA_GPU_SVC_REQUIRED_V1; + c->max_devices = 1; c->max_buffers = 8; c->max_queues = 2; c->max_inflight = 1; + c->max_buffer_bytes = 1u << 20; c->max_total_bytes = 4u << 20; +} + +static void case_names(void) +{ + int i, j; + case_begin(); + for (i = 0; i < (int)OMEGA_GPU_PLAT_REFUSAL_COUNT; i++) { + EXPECT(strcmp(omega_gpu_platform_refusal_name(i), "UNKNOWN") != 0); + for (j = 0; j < i; j++) EXPECT(strcmp(omega_gpu_platform_refusal_name(i), omega_gpu_platform_refusal_name(j)) != 0); + } + EXPECT(strcmp(omega_gpu_platform_refusal_name(-1), "UNKNOWN") == 0); + EXPECT(strcmp(omega_gpu_platform_refusal_name(OMEGA_GPU_PLAT_REFUSAL_COUNT), "UNKNOWN") == 0); + EXPECT(strcmp(omega_gpu_platform_refusal_name(0), "OK") == 0); + case_end("REFUSAL_NAMES_DISTINCT"); +} + +static void case_negotiate(void) +{ + OmegaGpuPlatformCaps p, r; + case_begin(); + caps_v1(&p); caps_v1(&r); + EXPECT(omega_gpu_platform_negotiate(&p, &r) == OMEGA_GPU_PLAT_OK); + EXPECT(omega_gpu_platform_negotiate(NULL, &r) == OMEGA_GPU_PLAT_REFUSED_ARGS); + EXPECT(omega_gpu_platform_negotiate(&p, NULL) == OMEGA_GPU_PLAT_REFUSED_ARGS); + /* a newer provided minor is fine; an older one or another major is refused */ + p.abi_minor = r.abi_minor + 1u; + EXPECT(omega_gpu_platform_negotiate(&p, &r) == OMEGA_GPU_PLAT_OK); + caps_v1(&p); r.abi_minor = p.abi_minor + 1u; + EXPECT(omega_gpu_platform_negotiate(&p, &r) == OMEGA_GPU_PLAT_REFUSED_ABI); + caps_v1(&r); p.abi_major = r.abi_major + 1u; + EXPECT(omega_gpu_platform_negotiate(&p, &r) == OMEGA_GPU_PLAT_REFUSED_ABI); + /* a required service the platform lacks is refused, never emulated */ + caps_v1(&p); r.services |= OMEGA_GPU_SVC_IRQ; + EXPECT(omega_gpu_platform_negotiate(&p, &r) == OMEGA_GPU_PLAT_REFUSED_MISSING_SERVICE); + p.services |= OMEGA_GPU_SVC_IRQ; + EXPECT(omega_gpu_platform_negotiate(&p, &r) == OMEGA_GPU_PLAT_OK); + /* unknown service bits are malformed */ + p.services |= 1u << 9; + EXPECT(omega_gpu_platform_negotiate(&p, &r) == OMEGA_GPU_PLAT_REFUSED_ARGS); + /* every limit */ + caps_v1(&p); caps_v1(&r); r.max_devices = 2; EXPECT(omega_gpu_platform_negotiate(&p, &r) == OMEGA_GPU_PLAT_REFUSED_LIMIT); + caps_v1(&r); r.max_buffers = 9; EXPECT(omega_gpu_platform_negotiate(&p, &r) == OMEGA_GPU_PLAT_REFUSED_LIMIT); + caps_v1(&r); r.max_queues = 3; EXPECT(omega_gpu_platform_negotiate(&p, &r) == OMEGA_GPU_PLAT_REFUSED_LIMIT); + caps_v1(&r); r.max_inflight = 2; EXPECT(omega_gpu_platform_negotiate(&p, &r) == OMEGA_GPU_PLAT_REFUSED_LIMIT); + caps_v1(&r); r.max_buffer_bytes = (1u << 20) + 1u; EXPECT(omega_gpu_platform_negotiate(&p, &r) == OMEGA_GPU_PLAT_REFUSED_LIMIT); + caps_v1(&r); r.max_total_bytes = (4u << 20) + 1u; EXPECT(omega_gpu_platform_negotiate(&p, &r) == OMEGA_GPU_PLAT_REFUSED_LIMIT); + /* asking for less is fine */ + caps_v1(&r); r.max_buffers = 1; r.max_total_bytes = 1; + EXPECT(omega_gpu_platform_negotiate(&p, &r) == OMEGA_GPU_PLAT_OK); + case_end("NEGOTIATE_ABI_SERVICES_LIMITS"); +} + +static void case_check_table(void) +{ + OmegaGpuPlatform p; + OmegaGpuPlatformCaps c; + case_begin(); + full_platform(&p); caps_v1(&c); + EXPECT(omega_gpu_platform_check(&p, &c) == OMEGA_GPU_PLAT_OK); + EXPECT(omega_gpu_platform_check(NULL, &c) == OMEGA_GPU_PLAT_REFUSED_ARGS); + EXPECT(omega_gpu_platform_check(&p, NULL) == OMEGA_GPU_PLAT_REFUSED_ARGS); + /* the v1 required set is mandatory */ + c.services = OMEGA_GPU_SVC_REQUIRED_V1 & ~OMEGA_GPU_SVC_SYNC; + EXPECT(omega_gpu_platform_check(&p, &c) == OMEGA_GPU_PLAT_REFUSED_MISSING_SERVICE); + /* a claimed service with a missing function, one per service */ + caps_v1(&c); + full_platform(&p); p.time_now_ms = NULL; EXPECT(omega_gpu_platform_check(&p, &c) == OMEGA_GPU_PLAT_REFUSED_NULL_SERVICE); + full_platform(&p); p.wait_ms = NULL; EXPECT(omega_gpu_platform_check(&p, &c) == OMEGA_GPU_PLAT_REFUSED_NULL_SERVICE); + full_platform(&p); p.unlock = NULL; EXPECT(omega_gpu_platform_check(&p, &c) == OMEGA_GPU_PLAT_REFUSED_NULL_SERVICE); + full_platform(&p); p.mmio_write32 = NULL; EXPECT(omega_gpu_platform_check(&p, &c) == OMEGA_GPU_PLAT_REFUSED_NULL_SERVICE); + full_platform(&p); p.dma_free = NULL; EXPECT(omega_gpu_platform_check(&p, &c) == OMEGA_GPU_PLAT_REFUSED_NULL_SERVICE); + full_platform(&p); p.sync_gpu_to_cpu = NULL; EXPECT(omega_gpu_platform_check(&p, &c) == OMEGA_GPU_PLAT_REFUSED_NULL_SERVICE); + full_platform(&p); p.wait_word = NULL; EXPECT(omega_gpu_platform_check(&p, &c) == OMEGA_GPU_PLAT_REFUSED_NULL_SERVICE); + /* IRQ: claimed needs irq_wait; polling-only platforms do not claim it and must not carry one */ + full_platform(&p); c.services |= OMEGA_GPU_SVC_IRQ; + EXPECT(omega_gpu_platform_check(&p, &c) == OMEGA_GPU_PLAT_REFUSED_NULL_SERVICE); + p.irq_wait = f_irq; + EXPECT(omega_gpu_platform_check(&p, &c) == OMEGA_GPU_PLAT_OK); + caps_v1(&c); + EXPECT(omega_gpu_platform_check(&p, &c) == OMEGA_GPU_PLAT_REFUSED_ARGS); /* undeclared function = hidden path */ + case_end("SERVICE_TABLE_MATCHES_CLAIMS_NO_HIDDEN_FALLBACK"); +} + +static void case_buffers(void) +{ + OmegaGpuBufferDesc d; + OmegaGpuPlatformCaps c; + case_begin(); + caps_v1(&c); + memset(&d, 0, sizeof d); + d.kind = OMEGA_GPU_HANDLE_BUF_DATA; d.rights = OMEGA_GPU_RIGHT_CPU_WRITE | OMEGA_GPU_RIGHT_GPU_READ; d.bytes = 4096; + EXPECT(omega_gpu_platform_check_buffer(&d, &c) == OMEGA_GPU_PLAT_OK); + EXPECT(omega_gpu_platform_check_buffer(NULL, &c) == OMEGA_GPU_PLAT_REFUSED_ARGS); + EXPECT(omega_gpu_platform_check_buffer(&d, NULL) == OMEGA_GPU_PLAT_REFUSED_ARGS); + d.kind = OMEGA_GPU_HANDLE_QUEUE; EXPECT(omega_gpu_platform_check_buffer(&d, &c) == OMEGA_GPU_PLAT_REFUSED_BAD_KIND); + d.kind = OMEGA_GPU_HANDLE_BUF_DATA; + d.bytes = 0; EXPECT(omega_gpu_platform_check_buffer(&d, &c) == OMEGA_GPU_PLAT_REFUSED_BAD_LENGTH); + d.bytes = (1u << 20) + 1u; EXPECT(omega_gpu_platform_check_buffer(&d, &c) == OMEGA_GPU_PLAT_REFUSED_LIMIT); + d.bytes = 4096; + d.align = 48; EXPECT(omega_gpu_platform_check_buffer(&d, &c) == OMEGA_GPU_PLAT_REFUSED_ARGS); + d.align = 64; EXPECT(omega_gpu_platform_check_buffer(&d, &c) == OMEGA_GPU_PLAT_OK); + d.gpu_cache = 7; EXPECT(omega_gpu_platform_check_buffer(&d, &c) == OMEGA_GPU_PLAT_REFUSED_ARGS); + d.gpu_cache = OMEGA_GPU_CACHE_GPU_CACHED; + d.rights = 0; EXPECT(omega_gpu_platform_check_buffer(&d, &c) == OMEGA_GPU_PLAT_REFUSED_BAD_RIGHTS); + d.rights = 1u << 7; EXPECT(omega_gpu_platform_check_buffer(&d, &c) == OMEGA_GPU_PLAT_REFUSED_BAD_RIGHTS); + /* exec only on code */ + d.rights = OMEGA_GPU_RIGHT_GPU_EXEC | OMEGA_GPU_RIGHT_CPU_WRITE; + EXPECT(omega_gpu_platform_check_buffer(&d, &c) == OMEGA_GPU_PLAT_REFUSED_BAD_RIGHTS); + d.kind = OMEGA_GPU_HANDLE_BUF_CODE; + EXPECT(omega_gpu_platform_check_buffer(&d, &c) == OMEGA_GPU_PLAT_OK); + d.rights |= OMEGA_GPU_RIGHT_GPU_WRITE; EXPECT(omega_gpu_platform_check_buffer(&d, &c) == OMEGA_GPU_PLAT_REFUSED_BAD_RIGHTS); + d.rights = OMEGA_GPU_RIGHT_CPU_WRITE; EXPECT(omega_gpu_platform_check_buffer(&d, &c) == OMEGA_GPU_PLAT_REFUSED_BAD_RIGHTS); /* code without exec */ + d.rights = OMEGA_GPU_RIGHT_GPU_EXEC; EXPECT(omega_gpu_platform_check_buffer(&d, &c) == OMEGA_GPU_PLAT_REFUSED_BAD_RIGHTS); /* nobody can fill it */ + /* queue: CPU writes, device reads */ + d.kind = OMEGA_GPU_HANDLE_BUF_QUEUE; d.rights = OMEGA_GPU_RIGHT_CPU_WRITE; + EXPECT(omega_gpu_platform_check_buffer(&d, &c) == OMEGA_GPU_PLAT_REFUSED_BAD_RIGHTS); + d.rights |= OMEGA_GPU_RIGHT_GPU_READ; EXPECT(omega_gpu_platform_check_buffer(&d, &c) == OMEGA_GPU_PLAT_OK); + /* host-polled: CPU reads, GPU writes, GPU-uncached (the E1 rule) */ + d.kind = OMEGA_GPU_HANDLE_BUF_DATA; + d.rights = OMEGA_GPU_RIGHT_HOST_POLLED | OMEGA_GPU_RIGHT_CPU_READ | OMEGA_GPU_RIGHT_GPU_WRITE; + d.gpu_cache = OMEGA_GPU_CACHE_GPU_CACHED; + EXPECT(omega_gpu_platform_check_buffer(&d, &c) == OMEGA_GPU_PLAT_REFUSED_CACHE_POLICY); + d.gpu_cache = OMEGA_GPU_CACHE_GPU_UNCACHED; + EXPECT(omega_gpu_platform_check_buffer(&d, &c) == OMEGA_GPU_PLAT_OK); + d.rights = OMEGA_GPU_RIGHT_HOST_POLLED | OMEGA_GPU_RIGHT_CPU_READ; + EXPECT(omega_gpu_platform_check_buffer(&d, &c) == OMEGA_GPU_PLAT_REFUSED_BAD_RIGHTS); + d.kind = OMEGA_GPU_HANDLE_BUF_CODE; d.rights = OMEGA_GPU_RIGHT_HOST_POLLED | OMEGA_GPU_RIGHT_CPU_WRITE | OMEGA_GPU_RIGHT_GPU_EXEC | OMEGA_GPU_RIGHT_CPU_READ; + EXPECT(omega_gpu_platform_check_buffer(&d, &c) == OMEGA_GPU_PLAT_REFUSED_BAD_RIGHTS); + case_end("BUFFER_DESC_KIND_LENGTH_RIGHTS_CACHE"); +} + +static void case_handles(void) +{ + static OmegaGpuHandleTable t; + uint32_t i0, g0, i1, g1, i2, g2, i, g; + uint32_t n; + case_begin(); + omega_gpu_handles_init(&t); + EXPECT(t.nlive == 0 && t.total_bytes == 0); + EXPECT(omega_gpu_handles_open(NULL, OMEGA_GPU_HANDLE_DEVICE, 0, 1, 0, &i0, &g0) == OMEGA_GPU_PLAT_REFUSED_ARGS); + EXPECT(omega_gpu_handles_open(&t, 0, 0, 1, 0, &i0, &g0) == OMEGA_GPU_PLAT_REFUSED_BAD_KIND); + EXPECT(omega_gpu_handles_open(&t, OMEGA_GPU_HANDLE_KIND_COUNT, 0, 1, 0, &i0, &g0) == OMEGA_GPU_PLAT_REFUSED_BAD_KIND); + /* one device allowed */ + EXPECT(omega_gpu_handles_open(&t, OMEGA_GPU_HANDLE_DEVICE, 0, 1, 0, &i0, &g0) == OMEGA_GPU_PLAT_OK); + EXPECT(g0 != 0u); + EXPECT(omega_gpu_handles_open(&t, OMEGA_GPU_HANDLE_DEVICE, 0, 1, 0, &i1, &g1) == OMEGA_GPU_PLAT_REFUSED_LIMIT); + /* buffers account bytes against the total */ + EXPECT(omega_gpu_handles_open(&t, OMEGA_GPU_HANDLE_BUF_DATA, 3000, 8, 4096, &i1, &g1) == OMEGA_GPU_PLAT_OK); + EXPECT(omega_gpu_handles_open(&t, OMEGA_GPU_HANDLE_BUF_DATA, 2000, 8, 4096, &i2, &g2) == OMEGA_GPU_PLAT_REFUSED_LIMIT); + EXPECT(omega_gpu_handles_open(&t, OMEGA_GPU_HANDLE_BUF_DATA, 5000, 8, 4096, &i2, &g2) == OMEGA_GPU_PLAT_REFUSED_LIMIT); + EXPECT(omega_gpu_handles_open(&t, OMEGA_GPU_HANDLE_BUF_CODE, 1096, 8, 4096, &i2, &g2) == OMEGA_GPU_PLAT_OK); + EXPECT(t.nlive == 3 && t.total_bytes == 4096); + /* checks: kind, index, generation */ + EXPECT(omega_gpu_handles_check(&t, i1, g1, OMEGA_GPU_HANDLE_BUF_DATA) == OMEGA_GPU_PLAT_OK); + EXPECT(omega_gpu_handles_check(&t, i1, g1, OMEGA_GPU_HANDLE_BUF_CODE) == OMEGA_GPU_PLAT_REFUSED_BAD_HANDLE); + EXPECT(omega_gpu_handles_check(&t, OMEGA_GPU_HANDLE_SLOTS, 1, OMEGA_GPU_HANDLE_BUF_DATA) == OMEGA_GPU_PLAT_REFUSED_BAD_HANDLE); + EXPECT(omega_gpu_handles_check(&t, i1, 0, OMEGA_GPU_HANDLE_BUF_DATA) == OMEGA_GPU_PLAT_REFUSED_BAD_HANDLE); + EXPECT(omega_gpu_handles_check(&t, i1, g1 + 1u, OMEGA_GPU_HANDLE_BUF_DATA) == OMEGA_GPU_PLAT_REFUSED_STALE_HANDLE); + EXPECT(omega_gpu_handles_check(&t, 40, 1, OMEGA_GPU_HANDLE_BUF_DATA) == OMEGA_GPU_PLAT_REFUSED_STALE_HANDLE); /* never opened */ + EXPECT(omega_gpu_handles_check(NULL, i1, g1, OMEGA_GPU_HANDLE_BUF_DATA) == OMEGA_GPU_PLAT_REFUSED_ARGS); + /* close: frees bytes, the old handle goes stale, double close refused, slot reuse gets a new generation */ + EXPECT(omega_gpu_handles_close(&t, i1, g1, OMEGA_GPU_HANDLE_BUF_CODE) == OMEGA_GPU_PLAT_REFUSED_BAD_HANDLE); + EXPECT(omega_gpu_handles_close(&t, i1, g1, OMEGA_GPU_HANDLE_BUF_DATA) == OMEGA_GPU_PLAT_OK); + EXPECT(t.nlive == 2 && t.total_bytes == 1096); + EXPECT(omega_gpu_handles_check(&t, i1, g1, OMEGA_GPU_HANDLE_BUF_DATA) == OMEGA_GPU_PLAT_REFUSED_STALE_HANDLE); + EXPECT(omega_gpu_handles_close(&t, i1, g1, OMEGA_GPU_HANDLE_BUF_DATA) == OMEGA_GPU_PLAT_REFUSED_STALE_HANDLE); + EXPECT(omega_gpu_handles_open(&t, OMEGA_GPU_HANDLE_BUF_DATA, 3000, 8, 4096, &i, &g) == OMEGA_GPU_PLAT_OK); + EXPECT(i == i1 && g == g1 + 1u); + EXPECT(omega_gpu_handles_check(&t, i1, g1, OMEGA_GPU_HANDLE_BUF_DATA) == OMEGA_GPU_PLAT_REFUSED_STALE_HANDLE); + EXPECT(omega_gpu_handles_check(&t, i, g, OMEGA_GPU_HANDLE_BUF_DATA) == OMEGA_GPU_PLAT_OK); + /* per-kind slot limit counts only live handles of that kind */ + for (n = 0; n < 2; n++) EXPECT(omega_gpu_handles_open(&t, OMEGA_GPU_HANDLE_QUEUE, 0, 2, 0, &i2, &g2) == OMEGA_GPU_PLAT_OK); + EXPECT(omega_gpu_handles_open(&t, OMEGA_GPU_HANDLE_QUEUE, 0, 2, 0, &i2, &g2) == OMEGA_GPU_PLAT_REFUSED_LIMIT); + EXPECT(omega_gpu_handles_close(&t, i2, g2, OMEGA_GPU_HANDLE_QUEUE) == OMEGA_GPU_PLAT_OK); + EXPECT(omega_gpu_handles_open(&t, OMEGA_GPU_HANDLE_QUEUE, 0, 2, 0, &i2, &g2) == OMEGA_GPU_PLAT_OK); + /* table capacity */ + omega_gpu_handles_init(&t); + for (n = 0; n < OMEGA_GPU_HANDLE_SLOTS; n++) + EXPECT(omega_gpu_handles_open(&t, OMEGA_GPU_HANDLE_BUF_DATA, 1, 1000, 1000, &i, &g) == OMEGA_GPU_PLAT_OK); + EXPECT(omega_gpu_handles_open(&t, OMEGA_GPU_HANDLE_BUF_DATA, 1, 1000, 1000, &i, &g) == OMEGA_GPU_PLAT_REFUSED_LIMIT); + /* a wrapped generation retires the slot instead of reissuing generation 0 */ + omega_gpu_handles_init(&t); + t.generation[0] = 0xFFFFFFFFu; + EXPECT(omega_gpu_handles_open(&t, OMEGA_GPU_HANDLE_BUF_DATA, 1, 8, 8, &i, &g) == OMEGA_GPU_PLAT_OK); + EXPECT(i == 0 && g == 0xFFFFFFFFu); + EXPECT(omega_gpu_handles_close(&t, 0, g, OMEGA_GPU_HANDLE_BUF_DATA) == OMEGA_GPU_PLAT_OK); + EXPECT(omega_gpu_handles_open(&t, OMEGA_GPU_HANDLE_BUF_DATA, 1, 8, 8, &i, &g) == OMEGA_GPU_PLAT_OK); + EXPECT(i == 1 && g == 1u); + case_end("HANDLES_TYPED_GENERATIONED_LIMITED"); +} + +static void case_sizes(void) +{ + /* No Linux fd, no raw pointer and no physical address can be smuggled + * through a handle: it is two 32-bit fields, and the address types are + * distinct structs that do not convert into each other. */ + case_begin(); + EXPECT(sizeof(OmegaGpuDeviceHandle) == 8u); + EXPECT(sizeof(OmegaGpuBufferHandle) == 8u); + EXPECT(sizeof(OmegaGpuQueueHandle) == 8u); + EXPECT(sizeof(OmegaGpuVa) == 8u && sizeof(OmegaGpuBusAddr) == 8u); + EXPECT(sizeof(OmegaCpuView) == sizeof(void *) + sizeof(size_t)); + EXPECT(OMEGA_GPU_SVC_REQUIRED_V1 == (OMEGA_GPU_SVC_ALL & ~OMEGA_GPU_SVC_IRQ)); + case_end("HANDLE_AND_ADDRESS_SHAPES"); +} + +int main(void) +{ + case_names(); + case_negotiate(); + case_check_table(); + case_buffers(); + case_handles(); + case_sizes(); + printf("SUMMARY passed=%d failed=%d\n", n_pass, n_fail); + return n_fail ? 1 : 0; +} diff --git a/tools/.crumb b/tools/.crumb index fb52b6532..20936ec8c 100644 --- a/tools/.crumb +++ b/tools/.crumb @@ -26,44 +26,44 @@ "children": [ { "digest": "9cd3943087595dd868914a23a9fef7bebda3d78b773762c287ac4b7a6c2e2f40", - "last_commit": "05ed1a1", + "last_commit": "05ed1a10", "name": "argus", "purpose": "Directory tools/argus. Purpose not yet described by a human." }, { "digest": "870928d3974d2e90f8bd2999a69a0e81e8d6026feecc2bd133988da61d8b4bba", - "last_commit": "ee0c99d", + "last_commit": "7683eaaa", "name": "brownian", "purpose": "Directory tools/brownian. Purpose not yet described by a human." }, { "digest": "64fe22fe57fab7e61e65cb7652e73dbde613c260cb8677b05d8b98a067231e83", - "last_commit": "00f54b6", + "last_commit": "00f54b6b", "name": "dual_experiment", "purpose": "Runner for the DUAL applicability experiment: runs the pre-registered campaign and writes result" }, { "digest": "11eb4960ad04fe5bd01ee9d2bbb6900712176c0991ecc0b02b3204ac60248eeb", - "last_commit": "38a6a56", + "last_commit": "38a6a569", "name": "estimation", "purpose": "Directory tools/estimation. Purpose not yet described by a human." }, { "digest": "98d1f4d802b90006977d73b14acb92971927f2cf5bdf05d8dc5653a1b10fcf1b", - "last_commit": "ae1dd00", + "last_commit": "ae1dd00a", "name": "turing_verify_indep", "purpose": "Directory tools/turing_verify_indep. Purpose not yet described by a human." } ], "children_root": "sha256:3051f793dc23155cfff1c4a549e97d3bfe74b3e094d3bd812985bba517919051", - "compiled_at": "2026-10-09T15:42:59Z", + "compiled_at": "2026-10-12T10:51:44Z", "compiler": "crumb-compile/1", - "digest": "sha256:acd42de9387a133f34b4b6afca962c82d340fba67c6a770a74852406769b4186", + "digest": "sha256:285407d8f7949613c6b57b225fa50b2bb076aaa874fded0895d82fbf285fb832", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 139, - "generated_at_commit": "d83c1e207b3d3422601486a205644753e9d9a17c", - "source_tree": "sha256:7ffcb20eb7e4660174aebbb20b9e188d0f32726e4b780e9a86a0d27cd6e14b3c" + "generated_at_commit": "e04bd5021b2a4f311fb9838887c170c4bf3164b6", + "source_tree": "sha256:5a8bc055de0e0c544201ed70b9e091c93298f8cce9ef8ff967cade1712e69975" }, "owner_lane": "", "provenance": { diff --git a/tools/gpu_engine_mutations.sh b/tools/gpu_engine_mutations.sh index 86a39fe28..17b9f582e 100755 --- a/tools/gpu_engine_mutations.sh +++ b/tools/gpu_engine_mutations.sh @@ -38,7 +38,7 @@ 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;/ +POISON_FILL_SKIPPED|$FILE|s/ERRNO_CLEAR(); 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;/