Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/patches/e683e3f96ab8fbb3 # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers ## GitHub aien-dev/omega-mv#852 (code only) closed derived `e683e3f96ab8fbb3` #852 Imported from GitHub aien-dev/omega-mv#852 (code only) GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed). Base `62d1d0d668f897386a0e311374f8dbcc5c32dde8` · Head `9053a316fb78bdae322a8c7df6e4ab752ef8dbde` ### Fetch it A git bundle of the pull request's head, 26333 bytes. ``` curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/e683e3f96ab8fbb3.bundle -o e683e3f96ab8fbb3.bundle git fetch e683e3f96ab8fbb3.bundle refs/pull/852/head ``` Raw bundle · Diff ### Provenance This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record: ``` github-import 1 aien-dev/omega-mv 852 9053a316fb78bdae322a8c7df6e4ab752ef8dbde ``` ``` {"kind":"github-import","owner":"aien-dev","repo":"omega-mv","number":852,"url":"https://github.com/aien-dev/omega-mv/pull/852","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:38:51Z","metadata":"unavailable","state_derived":true} ``` ### Changes ``` diff --git a/.crumb b/.crumb index f3e51fe46..2d995508b 100644 --- a/.crumb +++ b/.crumb @@ -47,8 +47,8 @@ "purpose": "Directory calibration. Purpose not yet described by a human." }, { - "digest": "7ef7796693f23ad68d9a5bcaaee0f635018f4371139a040ba202d4ce7083ede8", - "last_commit": "dd39bf71f", + "digest": "e1c8d82903bf372ca2e74eefffbf44516953318065c526517343ff0f5cf1ba0b", + "last_commit": "ae994a969", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." }, @@ -72,7 +72,7 @@ }, { "digest": "f765ad87fdddd9b47f690b07298c951a0f7e7675dc5de4ffe44e33a0c14b1986", - "last_commit": "a8a6a3d3c", + "last_commit": "d94a503f7", "name": "spec", "purpose": "Directory spec. Purpose not yet described by a human." }, @@ -84,26 +84,26 @@ }, { "digest": "5395ff8ff9afceebe8e453788f80a3064b831513cc4cb92fd55869115e06b874", - "last_commit": "a8a6a3d3c", + "last_commit": "dcccc0211", "name": "tests", "purpose": "Directory tests. Purpose not yet described by a human." }, { "digest": "308db0e6cf45c0a48f01f5f5f228450f191389de68006915b9ecf9c65b9a2e29", - "last_commit": "a8a6a3d3c", + "last_commit": "a50c3bd41", "name": "tools", "purpose": "Directory tools. Purpose not yet described by a human." } ], - "children_root": "sha256:07bf1706dcffbad66c0353871ff67a6749055da03cee8d8ebdf9a4c91e36bddc", - "compiled_at": "2026-10-30T12:31:50Z", + "children_root": "sha256:336577e526a60061b68a496e8660e2a7ffc4813b0b620f9d54b221bf6e467f9d", + "compiled_at": "2026-10-30T16:28:43Z", "compiler": "crumb-compile/1", - "digest": "sha256:904fca8c0e0cf3e3a5e5adb73393e01c7018b920bb542d289904240f70e400d6", - "evidence_files": 12622, - "evidence_root": "sha256:b1a08e2ce56e6feada0d8a31f06fbd7adee57adc1c1ad8dec220293ee5d439f9", - "files": 17849, - "generated_at_commit": "52a82f392fa513ebbc2d9d719a0f14c385289b06", - "source_tree": "sha256:75458da6553a0ee5ea2af95f46afb658e8a3f6e53cca6e3b4b9874035f78c2ed" + "digest": "sha256:bfe028cbd1a9e45cbc8f4b65e05bc6b920bf35c877deb242d1578d84ee82bfe7", + "evidence_files": 12625, + "evidence_root": "sha256:f02ee8724c7be25dd7ed7cde9fdaf91f48d73e4eca0d0c0660a182a5aad6f64f", + "files": 17859, + "generated_at_commit": "ae994a9699d7a1672321b25e149d9063a5ccad53", + "source_tree": "sha256:a704a0480e7db1eb136b71dba8bfd34895e562471120c3af183bf21ddcd64560" }, "owner_lane": "", "provenance": { diff --git a/docs/.crumb b/docs/.crumb index 433100df5..102c1a1ff 100644 --- a/docs/.crumb +++ b/docs/.crumb @@ -124,14 +124,14 @@ } ], "children_root": "sha256:c81d43c0c392dfec2b6ed5b38ba95ea7c592782b283950e32b777e7b9cfd9d61", - "compiled_at": "2026-10-30T02:47:38Z", + "compiled_at": "2026-10-30T03:40:24Z", "compiler": "crumb-compile/1", - "digest": "sha256:7ef7796693f23ad68d9a5bcaaee0f635018f4371139a040ba202d4ce7083ede8", + "digest": "sha256:e1c8d82903bf372ca2e74eefffbf44516953318065c526517343ff0f5cf1ba0b", "evidence_files": 34, "evidence_root": "sha256:589d8b3706e6d7a202ab20b278dac5fc5bafc973f1c2a867b2668aa7210b65cc", "files": 138, - "generated_at_commit": "e615e9ff47d03199514580f655d7670e61ab7e2f", - "source_tree": "sha256:ba44cf86b50127e2ec3824c2e913e032178628d69910a85ca9125cc1ed960bb5" + "generated_at_commit": "1938ed6105e7a74cb3e22be4cf98cfdc550fa3ef", + "source_tree": "sha256:cd99d3e1280a2fe5e105b22bef983af68e67e713c1793ebe087a58a7eae25b70" }, "owner_lane": "", "provenance": { diff --git a/docs/ROADMAP-1.0.md b/docs/ROADMAP-1.0.md index cc65df38c..44e10c938 100644 --- a/docs/ROADMAP-1.0.md +++ b/docs/ROADMAP-1.0.md @@ -293,6 +293,7 @@ Acceptance: | AArch64 Linux static ELF (program and function mode) | MERGED; host EXERCISED by `OMEGA-SEED` | QUALIFIED by RM1's full gate at the release commit | | WebAssembly MVP via OSC IR v1 (`irwasm`) | MERGED, scalar subset; host EXERCISED by authors | Gate wired (RM1); scope decision: stay scalar-only for 1.0, or add linear memory, text and globals with IR v2+ | | SPIR-V 1.0 OpenCL Kernel via OSC IR v1 (`irspirv`) | IMPLEMENTED and CPU EXERCISED in [#804](https://github.com/aien-dev/omega-mv/pull/804); [ABI, parity and toolchain](SPIRV.md) | Standalone `seed/spirv/gate-irspirv.sh`: full irwasm scalar corpus, exact trap/result parity on PoCL CPU, validator, determinism, mutant and refusals. Manifest wiring needs operator authorization; GPU and DPC++ integration NOT_RUN. | +| StableHLO MLIR text via OSC IR v1/v7 (`irstablehlo`, Google TPU path) | IMPLEMENTED; EXERCISED on IREE 3.13 llvm-cpu and XLA CPU PJRT (jaxlib 0.12.0.1) interop oracles, see [seed/stablehlo](../seed/stablehlo/README.md) | Standalone `seed/stablehlo/gate-irstablehlo.sh`: elementwise one-block functions, exact results on both oracles, Omega-native integer cross-check, wrong-op, wrong-expected, malformed-module and refusal controls. Signed overflow trap NOT preserved. TPU (closed libtpu) NOT_RUN. | | x86-64 Linux static ELF | DRAFT integration pending implementation/evidence on canonical base `6999fa9e6`, using historical `7eca2ac3f`; [design and unsupported paths](X86-LINUX.md) | Published PR; default AArch64 output byte-identical (C2 manifest); full existing fixture differential with equal trap codes; independent objdump oracle and wrong-encoding mutants; all NOT_RUN for this draft; QEMU labelled EMULATED, physical x86 NOT_RUN unless tested | | x86-64 UEFI PE32+ | Historical implementation in `7eca2ac3f`; removed from the Linux-only FR-9 draft | Outside this integration; separate firmware/PE32+ acceptance and evidence required; Linux execution does not establish firmware or physical x86 qualification | | RISC-V RV64GC (#630), other ISAs (#629, #628) | PROPOSED | Out of 1.0 unless a decision adds it | diff --git a/evidence/IRSTABLEHLO-20261026/gate.log b/evidence/IRSTABLEHLO-20261026/gate.log new file mode 100644 index 000000000..3d8224597 --- /dev/null +++ b/evidence/IRSTABLEHLO-20261026/gate.log @@ -0,0 +1,53 @@ +SOURCE 70a057475bb51c4f9bd254bfcbe097c6f142cc32 +COMPILER 2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f +ORACLE iree-compile 3.13.0rc20261016 @ 89ece87b89852100c0a4ac3d515e14842d090967 +ORACLE iree-run-module 06ad551b3fd3e1014885cf8134db79d2544e5b290eeb36d10126a3f32af4bb5d +ORACLE pjrt jax 0.12.0.1 jaxlib 0.12.0.1 +Linux aarch64 +PASS case-1-vaddi32 i32 deterministic, IREE exact match, PJRT bitwise match, native +PASS case-2-vaddu32 ui32 deterministic, IREE exact match, PJRT bitwise match, native +PASS case-3-vaddi64 i64 deterministic, IREE exact match, PJRT bitwise match, native +PASS case-4-madi32 i32 deterministic, IREE exact match, PJRT bitwise match, native +PASS case-5-biasi32 i32 deterministic, IREE exact match, PJRT bitwise match, native +PASS case-6-vaddf32 f32 deterministic, IREE exact match, PJRT bitwise match, native NOT_RUN (omc ir has no float words at this pin) +PASS case-7-vaddf64 f64 deterministic, IREE exact match, PJRT bitwise match, native NOT_RUN (omc ir has no float words at this pin) +PASS negative wrong op (add->subtract) i32: IREE [FAILED], PJRT MISMATCH +PASS negative wrong op (add->multiply) f32: IREE [FAILED], PJRT MISMATCH +PASS negative wrong expected (element 0 = 1) i32: IREE [FAILED], PJRT MISMATCH +PASS negative wrong expected (element 4 one ulp up) f32: IREE [FAILED], PJRT MISMATCH +PASS negative malformed (closing brace dropped): iree-compile and PJRT refused +PASS negative malformed (unknown op stablehlo.addx): iree-compile and PJRT refused +PASS negative malformed (return type f32 vs i32 value): iree-compile and PJRT refused +DIVERGENCE signed overflow: Omega native exit 101 (trap); IREE and PJRT return -2147483648 (StableHLO: implementation-defined) +PASS refusal integer div -> UNSUPPORTED_OP (exit 24) +PASS refusal integer shl -> UNSUPPORTED_OP (exit 24) +PASS refusal branches -> UNSUPPORTED_OP (exit 24) +PASS refusal mixed element types -> UNSUPPORTED_TAG (exit 25) +PASS refusal bool result -> UNSUPPORTED_TAG (exit 25) +PASS refusal f32 tag in wire v1 -> UNSUPPORTED_TAG (exit 25) +PASS refusal unknown function -> NO_FUNCTION (exit 30) +PASS refusal N zero -> USAGE (exit 29) +PASS refusal N leading zero -> USAGE (exit 29) +PASS refusal N above 16777216 -> USAGE (exit 29) +PASS refusal N not decimal -> USAGE (exit 29) +PASS refusal missing function argument -> USAGE (exit 29) +PASS refusal bad magic -> MAGIC (exit 20) +PASS refusal wire version 2 -> VERSION (exit 21) +PASS refusal truncated -> TRUNCATED (exit 22) +PASS refusal trailing byte -> TRAILING (exit 27) +SHA256 a6834f3d159acb747fa1fb6ff32555c75943efc51ed290da0c4d9fbadef926f1 build/seed/stablehlo/irstablehlo +SHA256 d7c398cbae781009df96bb6c165de20e33183d09ad03b4b1dbf854e7698b2a4f build/seed/stablehlo/case-1-vaddi32.again.mlir +SHA256 d7c398cbae781009df96bb6c165de20e33183d09ad03b4b1dbf854e7698b2a4f build/seed/stablehlo/case-1-vaddi32.mlir +SHA256 745f25fa09e9159b60a37aee3ee8a58433b59b15b4fa0c344c4e27d90348ab50 build/seed/stablehlo/case-2-vaddu32.again.mlir +SHA256 745f25fa09e9159b60a37aee3ee8a58433b59b15b4fa0c344c4e27d90348ab50 build/seed/stablehlo/case-2-vaddu32.mlir +SHA256 7dfd7e028434d7cdd7d71e95918568c3345df2db836399aa0efd7ff87c992e8d build/seed/stablehlo/case-3-vaddi64.again.mlir +SHA256 7dfd7e028434d7cdd7d71e95918568c3345df2db836399aa0efd7ff87c992e8d build/seed/stablehlo/case-3-vaddi64.mlir +SHA256 44cce882a97aa3a2a3b50af4ea880acfddee00b0b59541708421d75cf5fb3cb0 build/seed/stablehlo/case-4-madi32.again.mlir +SHA256 44cce882a97aa3a2a3b50af4ea880acfddee00b0b59541708421d75cf5fb3cb0 build/seed/stablehlo/case-4-madi32.mlir +SHA256 d1df8369e3eabcb950cf5ee2bcf718780b784d88147a71a777ba0cbac39242f8 build/seed/stablehlo/case-5-biasi32.again.mlir +SHA256 d1df8369e3eabcb950cf5ee2bcf718780b784d88147a71a777ba0cbac39242f8 build/seed/stablehlo/case-5-biasi32.mlir +SHA256 b070166afba5c9f4b8b72e5de47e584f9b3594f05725192887ddec76a72c0126 build/seed/stablehlo/case-6-vaddf32.again.mlir +SHA256 b070166afba5c9f4b8b72e5de47e584f9b3594f05725192887ddec76a72c0126 build/seed/stablehlo/case-6-vaddf32.mlir +SHA256 ed454c24cab4a2bd3b74ebcf055169f9cb81a925462c7327f415a9678ecaf0e8 build/seed/stablehlo/case-7-vaddf64.again.mlir +SHA256 ed454c24cab4a2bd3b74ebcf055169f9cb81a925462c7327f415a9678ecaf0e8 build/seed/stablehlo/case-7-vaddf64.mlir +PASS irstablehlo: 7 cases on two interop oracles (not Omega-native, not hardware), 23 negatives caught diff --git a/evidence/IRSTABLEHLO-20261026/receipt.log b/evidence/IRSTABLEHLO-20261026/receipt.log new file mode 100644 index 000000000..ceb1c9230 --- /dev/null +++ b/evidence/IRSTABLEHLO-20261026/receipt.log @@ -0,0 +1,19 @@ +Source revision exercised: 70a057475bb51c4f9bd254bfcbe097c6f142cc32 +Platform: Linux aarch64 (DGX Spark host CPU; GPU not used). +Command: IREE_COMPILE=/bin/iree-compile IREE_RUN=/bin/iree-run-module PYTHON=/bin/python nice -n 19 sh seed/stablehlo/gate-irstablehlo.sh +Observed exit: 0 +Full output: gate.log +Observed gate verdict: PASS irstablehlo: 7 cases on two interop oracles (not Omega-native, not hardware), 23 negatives caught + +Oracles (interop oracle, not Omega-native; they read the Omega-written module, never generate it): +iree-base-compiler 3.13.0 wheel sha256 230aec9b5d63c49f3f1ba228c35a7ce950075ce7b7780b786c85fa6fb0be3dbb +iree-base-runtime 3.13.0 wheel sha256 2a46a517c7dbdaa8701f9ee324dd94089af51a8251f36bd689949ee37e30d1d1 +jaxlib 0.12.0.1 wheel sha256 40812201c3bcd4cb104b88f71f58fec4cbd0c32ba90e5c92b3fa8f40819f6774 +jax 0.12.0.1 wheel sha256 e9dfd256ba090259b10f97f0755d4fc92535b8cb38c0a40df6488a8c8a7dd8ae +numpy 2.5.4 wheel sha256 fe4d21ab149f15e4e6043dfb0de87e6e5f34ac176cde83060e9802981fca2ac2 + +Determinism: each module is translated twice per run (cmp); a second full run of the +gate (before this commit, same translator source) printed identical SHA256 lines. +Expected vectors: Wolfram Language evaluator, 2026-10-26 (integer wrap/fit checks; f32/f64 +round-to-nearest-even of each sum; decimal round-trip of every float input and expected value). +Evidence class: HOST interop oracle. TPU: NOT_RUN (libtpu is closed and x86_64-only; no TPU VM). diff --git a/evidence/IRSTABLEHLO-20261026/rerun-c1e19133.log b/evidence/IRSTABLEHLO-20261026/rerun-c1e19133.log new file mode 100644 index 000000000..629e216e6 --- /dev/null +++ b/evidence/IRSTABLEHLO-20261026/rerun-c1e19133.log @@ -0,0 +1,54 @@ +Rerun at c1e1913379009f086e336de8fa3d0a138ca4010d (PJRT oracle platform made selectable; gate pins cpu). Same command. Observed exit: 0 +SOURCE c1e1913379009f086e336de8fa3d0a138ca4010d +COMPILER 2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f +ORACLE iree-compile 3.13.0rc20261016 @ 89ece87b89852100c0a4ac3d515e14842d090967 +ORACLE iree-run-module 06ad551b3fd3e1014885cf8134db79d2544e5b290eeb36d10126a3f32af4bb5d +ORACLE pjrt jax 0.12.0.1 jaxlib 0.12.0.1 +Linux aarch64 +PASS case-1-vaddi32 i32 deterministic, IREE exact match, PJRT bitwise match, native +PASS case-2-vaddu32 ui32 deterministic, IREE exact match, PJRT bitwise match, native +PASS case-3-vaddi64 i64 deterministic, IREE exact match, PJRT bitwise match, native +PASS case-4-madi32 i32 deterministic, IREE exact match, PJRT bitwise match, native +PASS case-5-biasi32 i32 deterministic, IREE exact match, PJRT bitwise match, native +PASS case-6-vaddf32 f32 deterministic, IREE exact match, PJRT bitwise match, native NOT_RUN (omc ir has no float words at this pin) +PASS case-7-vaddf64 f64 deterministic, IREE exact match, PJRT bitwise match, native NOT_RUN (omc ir has no float words at this pin) +PASS negative wrong op (add->subtract) i32: IREE [FAILED], PJRT MISMATCH +PASS negative wrong op (add->multiply) f32: IREE [FAILED], PJRT MISMATCH +PASS negative wrong expected (element 0 = 1) i32: IREE [FAILED], PJRT MISMATCH +PASS negative wrong expected (element 4 one ulp up) f32: IREE [FAILED], PJRT MISMATCH +PASS negative malformed (closing brace dropped): iree-compile and PJRT refused +PASS negative malformed (unknown op stablehlo.addx): iree-compile and PJRT refused +PASS negative malformed (return type f32 vs i32 value): iree-compile and PJRT refused +DIVERGENCE signed overflow: Omega native exit 101 (trap); IREE and PJRT return -2147483648 (StableHLO: implementation-defined) +PASS refusal integer div -> UNSUPPORTED_OP (exit 24) +PASS refusal integer shl -> UNSUPPORTED_OP (exit 24) +PASS refusal branches -> UNSUPPORTED_OP (exit 24) +PASS refusal mixed element types -> UNSUPPORTED_TAG (exit 25) +PASS refusal bool result -> UNSUPPORTED_TAG (exit 25) +PASS refusal f32 tag in wire v1 -> UNSUPPORTED_TAG (exit 25) +PASS refusal unknown function -> NO_FUNCTION (exit 30) +PASS refusal N zero -> USAGE (exit 29) +PASS refusal N leading zero -> USAGE (exit 29) +PASS refusal N above 16777216 -> USAGE (exit 29) +PASS refusal N not decimal -> USAGE (exit 29) +PASS refusal missing function argument -> USAGE (exit 29) +PASS refusal bad magic -> MAGIC (exit 20) +PASS refusal wire version 2 -> VERSION (exit 21) +PASS refusal truncated -> TRUNCATED (exit 22) +PASS refusal trailing byte -> TRAILING (exit 27) +SHA256 a6834f3d159acb747fa1fb6ff32555c75943efc51ed290da0c4d9fbadef926f1 build/seed/stablehlo/irstablehlo +SHA256 d7c398cbae781009df96bb6c165de20e33183d09ad03b4b1dbf854e7698b2a4f build/seed/stablehlo/case-1-vaddi32.again.mlir +SHA256 d7c398cbae781009df96bb6c165de20e33183d09ad03b4b1dbf854e7698b2a4f build/seed/stablehlo/case-1-vaddi32.mlir +SHA256 745f25fa09e9159b60a37aee3ee8a58433b59b15b4fa0c344c4e27d90348ab50 build/seed/stablehlo/case-2-vaddu32.again.mlir +SHA256 745f25fa09e9159b60a37aee3ee8a58433b59b15b4fa0c344c4e27d90348ab50 build/seed/stablehlo/case-2-vaddu32.mlir +SHA256 7dfd7e028434d7cdd7d71e95918568c3345df2db836399aa0efd7ff87c992e8d build/seed/stablehlo/case-3-vaddi64.again.mlir +SHA256 7dfd7e028434d7cdd7d71e95918568c3345df2db836399aa0efd7ff87c992e8d build/seed/stablehlo/case-3-vaddi64.mlir +SHA256 44cce882a97aa3a2a3b50af4ea880acfddee00b0b59541708421d75cf5fb3cb0 build/seed/stablehlo/case-4-madi32.again.mlir +SHA256 44cce882a97aa3a2a3b50af4ea880acfddee00b0b59541708421d75cf5fb3cb0 build/seed/stablehlo/case-4-madi32.mlir +SHA256 d1df8369e3eabcb950cf5ee2bcf718780b784d88147a71a777ba0cbac39242f8 build/seed/stablehlo/case-5-biasi32.again.mlir +SHA256 d1df8369e3eabcb950cf5ee2bcf718780b784d88147a71a777ba0cbac39242f8 build/seed/stablehlo/case-5-biasi32.mlir +SHA256 b070166afba5c9f4b8b72e5de47e584f9b3594f05725192887ddec76a72c0126 build/seed/stablehlo/case-6-vaddf32.again.mlir +SHA256 b070166afba5c9f4b8b72e5de47e584f9b3594f05725192887ddec76a72c0126 build/seed/stablehlo/case-6-vaddf32.mlir +SHA256 ed454c24cab4a2bd3b74ebcf055169f9cb81a925462c7327f415a9678ecaf0e8 build/seed/stablehlo/case-7-vaddf64.again.mlir +SHA256 ed454c24cab4a2bd3b74ebcf055169f9cb81a925462c7327f415a9678ecaf0e8 build/seed/stablehlo/case-7-vaddf64.mlir +PASS irstablehlo: 7 cases on two interop oracles (not Omega-native, not hardware), 23 negatives caught diff --git a/seed/stablehlo/.crumb b/seed/stablehlo/.crumb new file mode 100644 index 000000000..bec031155 --- /dev/null +++ b/seed/stablehlo/.crumb @@ -0,0 +1,20 @@ +{ + "extensions": { + "generated": { + "children": [], + "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "compiled_at": "2026-10-30T02:52:10Z", + "compiler": "crumb-compile/1", + "digest": "sha256:88b676b032638280e6192f32eab0600f285b216ceff56e2401c7f64f6f14c044", + "evidence_files": 0, + "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "files": 7, + "generated_at_commit": "10899d703ab2a0002ccf8e5ed567f24b1d62ebe8", + "source_tree": "sha256:2399cb998a18806c290ce0afc4dfed3aec4be91a39fe300a488783832c246394" + } + }, + "layer": "seed", + "name": "stablehlo", + "purpose": "Seeded Omega OSC IR scalar unit to StableHLO MLIR, verified on IREE and XLA CPU PJRT interop oracles (Google TPU path)", + "schema_version": "1.0.0" +} diff --git a/seed/stablehlo/README.md b/seed/stablehlo/README.md new file mode 100644 index 000000000..cab7a0605 --- /dev/null +++ b/seed/stablehlo/README.md @@ -0,0 +1,103 @@ +# seed/stablehlo: OSC IR scalar unit to StableHLO (Google TPU path, first rung) + +`irstablehlo.om` is a handwritten Omega program. It reads one OSC IR unit on stdin and writes a +StableHLO MLIR module that applies one named scalar function elementwise to `N`-element tensors: + +``` +irstablehlo N FUNCTION < unit.ir > module.mlir +``` + +For `fn vaddi32 a int b int to int / ret add a b` and `N = 8` it writes: + +``` +module { + func.func public @main(%p0: tensor<8xi32>, %p1: tensor<8xi32>) -> tensor<8xi32> { + %i0 = stablehlo.add %p0, %p1 : tensor<8xi32> + func.return %i0 : tensor<8xi32> + } +} +``` + +## Run the gate + +``` +IREE_COMPILE=... IREE_RUN=... PYTHON=... nice -n 19 sh seed/stablehlo/gate-irstablehlo.sh +``` + +Exit 0 PASS, 1 FAIL, 3 NOT_RUN (not AArch64 Linux, or an oracle missing). Artifacts go to +`build/seed/stablehlo`. The gate pins `seed/out/omc` by sha256, builds the translator, translates every +row of `cases.tsv` twice (byte-identical), compiles and runs each module on two oracles, and compares +every element exactly. Integer rows are also run through the same Omega function compiled natively by +omc. It then requires these to be caught: a wrong op (add to subtract, add to multiply), a wrong +expected value (including one f32 ulp), three malformed modules both oracles must refuse, and 16 +translator refusals that must leave stdout empty. + +## Oracles (interop oracle, not Omega-native) + +Neither oracle writes the module; both only read what Omega wrote. jax.jit and JAX tracing are unused. + +| Oracle | Version (installed 2026-10-26 in a user venv) | Wheel sha256 | Licence | +|---|---|---|---| +| IREE `iree-compile` (llvm-cpu) | iree-base-compiler 3.13.0 (`3.13.0rc20261016 @ 89ece87b`) | `230aec9b5d63c49f3f1ba228c35a7ce950075ce7b7780b786c85fa6fb0be3dbb` | Apache-2.0 | +| IREE `iree-run-module` (`--equality_mode=exact`) | iree-base-runtime 3.13.0 | `2a46a517c7dbdaa8701f9ee324dd94089af51a8251f36bd689949ee37e30d1d1` | Apache-2.0 | +| XLA CPU PJRT client, via `pjrt-oracle.py` | jaxlib 0.12.0.1 | `40812201c3bcd4cb104b88f71f58fec4cbd0c32ba90e5c92b3fa8f40819f6774` | Apache-2.0 | +| (driver dependency) | jax 0.12.0.1 / numpy 2.5.4 | `e9dfd256…` / `fe4d21ab…` | Apache-2.0 / BSD-3-Clause AND 0BSD AND MIT AND Zlib AND CC0-1.0 | + +`pjrt-oracle.py` is a foreign-language oracle driver: it only compiles and runs an existing module and +compares numbers. Its Omega replacement is a PJRT C API caller written in `.om`, which needs shared +object and C ABI support (FR-7 in `docs/one_layer/OM_COMPLETION.md`, absent at this pin). + +IREE is called with `--iree-input-demote-f64-to-f32=false --iree-input-demote-i64-to-i32=false`; +without them IREE 3.13 rewrites f64 functions to f32 by default. + +## What is established, and what is not + +- IMPLEMENTED: the translator for one-block functions over one element type: BIN add, subtract, + multiply (all types), divide (f32/f64 only), and, or, xor (integers), integer CONST, MOV, RET. + Types ui8..ui64, i8..i64, f32, f64. Wire v1 (as `omc ir` writes it) and wire v7 for f32/f64. +- EXERCISED on the oracles: i32, ui32, i64, multiply-add and constant rows, plus f32 and f64 add, + all matching exactly on both oracles at N = 8. +- f32/f64 IR is a hand-written wire v7 fixture in the gate, because `omc ir` refuses float words at + this pin. No Omega producer of float IR exists yet, so the float rows have no native cross-check. +- NOT_RUN: any TPU. No result here is hardware qualification. + +Refused (with the class on stderr and nothing on stdout): integer div, rem, shl, shr; UN, CMP, CAST, +CALL, TRAP, BR, CBR; more than one block; requires/ensures contracts; bool; float constants; mixed +element types; structs, regions, refs; f32/f64 tags in wire v1. + +### Semantics + +| Omega rule | StableHLO (spec, read 2026-10-26) | Status | +|---|---|---| +| Signed add/sub/mul trap 1 on overflow | Integer overflow is implementation-defined ("Errors") | NOT preserved. The gate shows Omega exiting 101 while both oracles return -2147483648 | +| Unsigned add/sub/mul wrap | Implementation-defined | Same on both oracles; not a spec guarantee | +| IEEE-754 float add/sub/mul/div | IEEE-754, exceptions give the default result, no flags | Preserved; NaN payloads are not compared | +| div/rem trap 2, shift trap 7 | No trap | Refused | + +## Openness of the Google TPU stack (read 2026-10-26) + +| Layer | Status | Source | +|---|---|---| +| StableHLO opset and spec | Open, Apache-2.0 | https://github.com/openxla/stablehlo (`docs/spec.md`, main `44151da3`) | +| XLA compiler, PJRT C API | Open, Apache-2.0 | https://github.com/openxla/xla | +| JAX, jaxlib (CPU PJRT client) | Open, Apache-2.0 | https://github.com/jax-ml/jax | +| Mosaic TPU dialect (Pallas TPU) | Dialect definition public (`jaxlib/mosaic/dialect/tpu/tpu.td`), but it reaches the chip only as a `tpu_custom_call` that libtpu compiles | https://github.com/jax-ml/jax/blob/main/jaxlib/mosaic/dialect/tpu/tpu.td | +| libtpu (TPU compiler backend and runtime) | Closed binary; PyPI licence field "Google Cloud Platform Terms of Service"; x86_64 wheels only (0.0.51) | https://pypi.org/project/libtpu/ | +| TPU instruction set | No public ISA document found | — | +| StableHLO reference interpreter | Open, but prebuilt `stablehlo-translate` wheels are linux x86_64 only | https://github.com/openxla/stablehlo/releases | + +So the lowest level Omega can write without closed tools is StableHLO text (or Mosaic TPU-dialect MLIR, +which only libtpu can lower). Everything below that is inside libtpu. + +## Path to a TPU receipt (NOT_RUN) + +1. Get a Cloud TPU VM through the TPU Research Cloud (https://sites.research.google/trc/). It needs a + Google Cloud account and acceptance of Google's terms; libtpu ships on the VM. +2. Copy `build/seed/stablehlo/case-*.mlir` (made here, sha256 values from the gate output) to the VM. + Do not regenerate them there. +3. Run `pjrt-oracle.py` unchanged with `PJRT_ORACLE_PLATFORM=tpu`: the same `client.compile_and_load` on the + TPU PJRT client, with the `cases.tsv` inputs and expected vectors. +4. Record the libtpu version, TPU generation, module sha256 values and output. Even then the label is + "EXERCISED on TPU via closed libtpu": the kernel code below StableHLO is Google's, not Omega's. + +f64 is not native on TPUs; expect f64 rows to be refused or emulated, and record which. diff --git a/seed/stablehlo/cases.tsv b/seed/stablehlo/cases.tsv new file mode 100644 index 000000000..7c062f7fa --- /dev/null +++ b/seed/stablehlo/cases.tsv @@ -0,0 +1,10 @@ +# fixture function type expected inputs (tab separated; commas between the N=8 elements) +# fixture vecadd = vecadd.unit.om through omc ir; f32/f64 = the wire v7 fixtures built by the gate. +# Expected vectors computed with Wolfram (WolframLanguageEvaluator, 2026-10-26); see README.md. +vecadd vaddi32 i32 0,3,-2,2147483647,-2147483648,777777,0,-3 0,1,-1,2147483646,-2147483647,123456,-98765,7 0,2,-1,1,-1,654321,98765,-10 +vecadd vaddu32 ui32 0,3,0,4294967294,0,123,65536,4294967295 0,1,4294967295,4294967295,2147483648,100,65535,3000000000 0,2,1,4294967295,2147483648,23,1,1294967295 +vecadd vaddi64 i64 0,0,9223372036854775807,-9223372036854775808,-1,30,-30,3 0,-1,9223372036854775806,-9223372036854775807,5,10,-10,1 0,1,1,-1,-6,20,-20,2 +vecadd madi32 i32 6,13,22,-31,1,10001,50,2147395601 1,2,3,-4,0,100,-7,46340 5,6,7,8,9,100,-7,46340 1,1,1,1,1,1,1,1 +vecadd biasi32 i32 -3,0,-6,7,2147483644,-2147483648,997,-4 0,3,-3,10,2147483647,-2147483645,1000,-1 +f32 vaddf32 f32 3.75,0.75,0,1048576.5,0.300000012,16777216,1.99999994e38,-7.625 1.5,0.25,-2,1048576,0.1,16777216,1e38,-7.75 2.25,0.5,2,0.5,0.2,1,1e38,0.125 +f64 vaddf64 f64 0.30000000000000004,9007199254740992,3.75,0,2.0000000000000001e300,0.66666666666666663,0,0 0.1,9007199254740992,1.5,-2,1e300,0.3333333333333333,5,-0.0009765625 0.2,1,2.25,2,1e300,0.3333333333333333,-5,0.0009765625 diff --git a/seed/stablehlo/gate-irstablehlo.sh b/seed/stablehlo/gate-irstablehlo.sh new file mode 100755 index 000000000..5e6f71ef3 --- /dev/null +++ b/seed/stablehlo/gate-irstablehlo.sh @@ -0,0 +1,202 @@ +#!/bin/sh +# Host-only verification of seed/stablehlo/irstablehlo.om on AArch64 Linux. +# IREE (iree-compile, iree-run-module) and the XLA CPU PJRT client in jaxlib are +# interop oracles, not Omega-native: they only read the module Omega wrote and +# never generate kernels. No result here is hardware qualification. +# Exit 0 PASS, 1 FAIL, 3 NOT_RUN (an oracle or the host is absent). +# Oracle locations: IREE_COMPILE, IREE_RUN, PYTHON (defaults from PATH). +set -eu +cd "$(dirname "$0")/../.." +B=build/seed/stablehlo +D=seed/stablehlo +fail() { printf 'FAIL %s\n' "$*"; exit 1; } +notrun() { printf 'NOT_RUN %s\n' "$*"; exit 3; } +[ "$(uname -sm)" = 'Linux aarch64' ] || notrun 'requires AArch64 Linux' +IREE_COMPILE=${IREE_COMPILE:-$(command -v iree-compile || true)} +IREE_RUN=${IREE_RUN:-$(command -v iree-run-module || true)} +PYTHON=${PYTHON:-$(command -v python3 || true)} +[ -n "$IREE_COMPILE" ] && [ -x "$IREE_COMPILE" ] || notrun 'requires iree-compile oracle' +[ -n "$IREE_RUN" ] && [ -x "$IREE_RUN" ] || notrun 'requires iree-run-module oracle' +[ -n "$PYTHON" ] && "$PYTHON" -c 'import jax, jaxlib, numpy' 2>/dev/null || notrun 'requires jaxlib PJRT CPU oracle' +OMC=seed/out/omc +pin=62775d2a391cfef7cde64e387655caa9809a267093112910ec76bfa568f3712b +[ "$(sha256sum "$OMC" | cut -d ' ' -f 1)" = "$pin" ] || fail 'compiler pin differs' +rm -rf "$B" +mkdir -p "$B" +printf 'SOURCE %s\n' "$(git rev-parse HEAD)" +printf 'COMPILER %s\n' "$pin" +printf 'ORACLE iree-compile %s\n' "$("$IREE_COMPILE" --version 2>&1 | sed -n 's/^ *IREE compiler version //p' | head -n 1)" +printf 'ORACLE iree-run-module %s\n' "$(sha256sum "$IREE_RUN" | cut -d ' ' -f 1)" +printf 'ORACLE pjrt %s\n' "$(JAX_PLATFORMS=cpu "$PYTHON" -c 'import jax, jaxlib; print("jax", jax.__version__, "jaxlib", jaxlib.__version__)')" +uname -sm + +nice -n 19 "$OMC" < "$D/irstablehlo.om" > "$B/irstablehlo" 2> "$B/compile.err" || fail 'translator compile' +[ ! -s "$B/compile.err" ] || fail 'translator compiler stderr' +chmod +x "$B/irstablehlo" +T="$B/irstablehlo" +for unit in vecadd refuse; do + { printf 'ir\n'; cat "$D/$unit.unit.om"; } | nice -n 19 "$OMC" > "$B/$unit.ir" || fail "$unit ir" +done +# Wire v7 fixtures (spec/one-layer-format.md section 10): omc ir refuses float +# words at this pin, so the f32/f64 scalar IR is written byte by byte here. +# Header: magic OSC1IR\0, version, nstructs 0, nregions 0, nfuncs 1. Function: +# name, nparams 2, return tag, nvregs 3 with tags, one block (first 0, count 2), +# BIN add r2 = r0 + r1, RET r2, empty requires and ensures. +bytes() { for b in "$@"; do printf "\\$(printf %03o "$b")"; done; } +fixture() { + ver=$1 tag=$2; shift 2 + bytes 79 83 67 49 73 82 0 "$ver" + [ "$ver" = 7 ] && bytes 0 0 0 + bytes 1 0 "$#"; bytes "$@" + bytes 2 "$tag" 3 0 "$tag" "$tag" "$tag" 1 0 0 0 0 0 2 0 0 0 2 0 0 0 + bytes 3 1 2 0 0 0 1 0 15 2 0 0 0 0 0 +} +fixture 7 13 118 97 100 100 102 51 50 > "$B/f32.ir" +fixture 7 14 118 97 100 100 102 54 52 > "$B/f64.ir" +fixture 1 13 118 97 100 100 102 51 50 > "$B/v1f32.ir" + +iree_compile() { nice -n 19 "$IREE_COMPILE" --iree-hal-target-device=local \ + --iree-hal-local-target-device-backends=llvm-cpu --iree-input-type=stablehlo --iree-input-demote-f64-to-f32=false \ + --iree-input-demote-i64-to-i32=false "$1" -o "$2"; } +# iree_check MODULE.vmfb TYPE EXPECTED INPUT...; byte-equality compare. +iree_check() { + vm=$1 ty=$2 ex=$3; shift 3 + set -- "$@" + args= + for x in "$@"; do args="$args --input=8x$ty=$x"; done + # shellcheck disable=SC2086 + nice -n 19 "$IREE_RUN" --device=local-task --module="$vm" --function=main $args \ + --expected_output="8x$ty=$ex" --equality_mode=exact +} +pjrt() { PJRT_ORACLE_PLATFORM=cpu nice -n 19 "$PYTHON" "$D/pjrt-oracle.py" "$@" 2>> "$B/pjrt.stderr"; } +otype() { case "$1" in i32) echo int ;; ui32) echo uint ;; i64) echo long ;; *) echo - ;; esac; } + +i=0 +tab=$(printf '\t') +while IFS="$tab" read -r fx fn ty ex in1 in2 in3; do + case "$fx" in ''|'#'*) continue ;; esac + i=$((i+1)) + id="case-$i-$fn" + nice -n 19 "$T" 8 "$fn" < "$B/$fx.ir" > "$B/$id.mlir" || fail "$id translate" + nice -n 19 "$T" 8 "$fn" < "$B/$fx.ir" > "$B/$id.again.mlir" || fail "$id translate again" + cmp -s "$B/$id.mlir" "$B/$id.again.mlir" || fail "$id nondeterministic" + set -- "$in1" + [ -z "$in2" ] || set -- "$@" "$in2" + [ -z "$in3" ] || set -- "$@" "$in3" + iree_compile "$B/$id.mlir" "$B/$id.vmfb" 2> "$B/$id.iree-compile.err" || fail "$id iree-compile refused Omega module" + iree_check "$B/$id.vmfb" "$ty" "$ex" "$@" > "$B/$id.iree.out" 2>&1 || fail "$id IREE mismatch: $(grep -m1 FAILED "$B/$id.iree.out")" + grep -q '^\[SUCCESS\]' "$B/$id.iree.out" || fail "$id IREE gave no SUCCESS line" + pjrt "$B/$id.mlir" "$ty" 8 "$ex" "$@" > "$B/$id.pjrt.out" || fail "$id PJRT: $(tail -n 1 "$B/$id.pjrt.out")" + # Omega-native differential: the same scalar function, compiled natively by + # omc, must give the expected value for every element (integer rows). + ot=$(otype "$ty") + if [ "$ot" != - ]; then + { cat "$D/vecadd.unit.om"; printf 'fn main to int\n' + for k in 1 2 3 4 5 6 7 8; do + call="$fn" + for v in "$@"; do call="$call $ot $(printf '%s' "$v" | cut -d , -f "$k")"; done + printf 'if ne %s %s %s\nexit 1\nend\n' "$call" "$ot" "$(printf '%s' "$ex" | cut -d , -f "$k")" + done + printf 'ret 0\nend\n'; } > "$B/$id.native.om" + nice -n 19 "$OMC" < "$B/$id.native.om" > "$B/$id.native" 2> "$B/$id.native.err" || fail "$id native compile" + chmod +x "$B/$id.native" + nice -n 19 "$B/$id.native" || fail "$id Omega-native result differs from table" + native=native + else + native='native NOT_RUN (omc ir has no float words at this pin)' + fi + printf 'PASS %s %s deterministic, IREE exact match, PJRT bitwise match, %s\n' "$id" "$ty" "$native" +done < "$D/cases.tsv" +[ "$i" = 7 ] || fail "expected 7 case rows, ran $i" + +# Negative controls: each must be caught. +neg=0 +expect_mismatch() { + label=$1 mod=$2 ty=$3 ex=$4; shift 4 + iree_compile "$mod" "$mod.vmfb" 2> "$mod.iree-compile.err" || fail "$label: iree-compile refused instead of mismatching" + if iree_check "$mod.vmfb" "$ty" "$ex" "$@" > "$mod.iree.out" 2>&1; then fail "$label: IREE accepted"; fi + grep -q '^\[FAILED\]' "$mod.iree.out" || fail "$label: IREE failed without a mismatch line" + set +e; pjrt "$mod" "$ty" 8 "$ex" "$@" > "$mod.pjrt.out"; rc=$?; set -e + [ "$rc" = 1 ] || fail "$label: PJRT rc $rc, expected 1 (mismatch)" + neg=$((neg+1)) + printf 'PASS negative %s: IREE [FAILED], PJRT MISMATCH\n' "$label" +} +expect_refused() { + label=$1 mod=$2 + if iree_compile "$mod" "$mod.vmfb" 2> "$mod.iree-compile.err"; then fail "$label: iree-compile accepted"; fi + set +e; pjrt "$mod" i32 8 0,0,0,0,0,0,0,0 0,0,0,0,0,0,0,0 0,0,0,0,0,0,0,0 > "$mod.pjrt.out"; rc=$?; set -e + [ "$rc" = 2 ] || fail "$label: PJRT rc $rc, expected 2 (module refused)" + neg=$((neg+1)) + printf 'PASS negative %s: iree-compile and PJRT refused\n' "$label" +} +I32A=0,1,-1,2147483646,-2147483647,123456,-98765,7 +I32B=0,2,-1,1,-1,654321,98765,-10 +I32E=0,3,-2,2147483647,-2147483648,777777,0,-3 +F32A=1.5,0.25,-2,1048576,0.1,16777216,1e38,-7.75 +F32B=2.25,0.5,2,0.5,0.2,1,1e38,0.125 +sed 's/stablehlo\.add/stablehlo.subtract/' "$B/case-1-vaddi32.mlir" > "$B/neg-wrongop.mlir" +cmp -s "$B/neg-wrongop.mlir" "$B/case-1-vaddi32.mlir" && fail 'mutant identical' +expect_mismatch 'wrong op (add->subtract) i32' "$B/neg-wrongop.mlir" i32 "$I32E" "$I32A" "$I32B" +sed 's/stablehlo\.add/stablehlo.multiply/' "$B/case-6-vaddf32.mlir" > "$B/neg-wrongop-f32.mlir" +expect_mismatch 'wrong op (add->multiply) f32' "$B/neg-wrongop-f32.mlir" f32 \ + 3.75,0.75,0,1048576.5,0.300000012,16777216,1.99999994e38,-7.625 "$F32A" "$F32B" +cp "$B/case-1-vaddi32.mlir" "$B/neg-wrongexp.mlir" +expect_mismatch 'wrong expected (element 0 = 1) i32' "$B/neg-wrongexp.mlir" i32 1,3,-2,2147483647,-2147483648,777777,0,-3 "$I32A" "$I32B" +cp "$B/case-6-vaddf32.mlir" "$B/neg-wrongexp-f32.mlir" +expect_mismatch 'wrong expected (element 4 one ulp up) f32' "$B/neg-wrongexp-f32.mlir" f32 \ + 3.75,0.75,0,1048576.5,0.300000042,16777216,1.99999994e38,-7.625 "$F32A" "$F32B" +sed '$d' "$B/case-1-vaddi32.mlir" > "$B/neg-nobrace.mlir" +expect_refused 'malformed (closing brace dropped)' "$B/neg-nobrace.mlir" +sed 's/stablehlo\.add/stablehlo.addx/' "$B/case-1-vaddi32.mlir" > "$B/neg-badop.mlir" +expect_refused 'malformed (unknown op stablehlo.addx)' "$B/neg-badop.mlir" +sed 's/-> tensor<8xi32>/-> tensor<8xf32>/' "$B/case-1-vaddi32.mlir" > "$B/neg-badtype.mlir" +expect_refused 'malformed (return type f32 vs i32 value)' "$B/neg-badtype.mlir" + +# Documented divergence: Omega signed add traps on overflow; the lifted module does not. +{ cat "$D/vecadd.unit.om"; printf 'fn main to int\nx = vaddi32 int 2147483647 int 1\nret 0\nend\n'; } > "$B/overflow.native.om" +nice -n 19 "$OMC" < "$B/overflow.native.om" > "$B/overflow.native" 2> "$B/overflow.native.err" || fail 'overflow native compile' +chmod +x "$B/overflow.native" +set +e; nice -n 19 "$B/overflow.native" 2> /dev/null; nrc=$?; set -e +[ "$nrc" != 0 ] || fail 'Omega native signed overflow did not trap' +ONES=1,1,1,1,1,1,1,1 +MAXS=2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647 +MINS=-2147483648,-2147483648,-2147483648,-2147483648,-2147483648,-2147483648,-2147483648,-2147483648 +iree_check "$B/case-1-vaddi32.vmfb" i32 "$MINS" "$MAXS" "$ONES" > "$B/overflow.iree.out" 2>&1 || fail 'IREE overflow result was not the wrapped value' +pjrt "$B/case-1-vaddi32.mlir" i32 8 "$MINS" "$MAXS" "$ONES" > "$B/overflow.pjrt.out" || fail 'PJRT overflow result was not the wrapped value' +printf 'DIVERGENCE signed overflow: Omega native exit %s (trap); IREE and PJRT return -2147483648 (StableHLO: implementation-defined)\n' "$nrc" + +# Translator refusals: exact class on stderr, nonzero status, nothing on stdout. +refuse() { + label=$1 class=$2 input=$3; shift 3 + set +e; nice -n 19 "$T" "$@" < "$input" > "$B/refuse.out" 2> "$B/refuse.err"; rc=$?; set -e + [ "$rc" != 0 ] || fail "refusal $label exited 0" + [ ! -s "$B/refuse.out" ] || fail "refusal $label wrote stdout" + [ "$(cat "$B/refuse.err")" = "irstablehlo: $class" ] || fail "refusal $label said $(cat "$B/refuse.err")" + neg=$((neg+1)) + printf 'PASS refusal %s -> %s (exit %s)\n' "$label" "$class" "$rc" +} +refuse 'integer div' UNSUPPORTED_OP "$B/refuse.ir" 8 divi32 +refuse 'integer shl' UNSUPPORTED_OP "$B/refuse.ir" 8 shlu32 +refuse 'branches' UNSUPPORTED_OP "$B/refuse.ir" 8 maxi32 +refuse 'mixed element types' UNSUPPORTED_TAG "$B/refuse.ir" 8 widen +refuse 'bool result' UNSUPPORTED_TAG "$B/refuse.ir" 8 isodd +refuse 'f32 tag in wire v1' UNSUPPORTED_TAG "$B/v1f32.ir" 8 vaddf32 +refuse 'unknown function' NO_FUNCTION "$B/vecadd.ir" 8 nosuch +refuse 'N zero' USAGE "$B/vecadd.ir" 0 vaddi32 +refuse 'N leading zero' USAGE "$B/vecadd.ir" 08 vaddi32 +refuse 'N above 16777216' USAGE "$B/vecadd.ir" 16777217 vaddi32 +refuse 'N not decimal' USAGE "$B/vecadd.ir" 8x vaddi32 +refuse 'missing function argument' USAGE "$B/vecadd.ir" 8 +{ printf 'X'; tail -c +2 "$B/vecadd.ir"; } > "$B/bad-magic.ir" +refuse 'bad magic' MAGIC "$B/bad-magic.ir" 8 vaddi32 +{ head -c 7 "$B/vecadd.ir"; bytes 2; tail -c +9 "$B/vecadd.ir"; } > "$B/bad-version.ir" +refuse 'wire version 2' VERSION "$B/bad-version.ir" 8 vaddi32 +size=$(wc -c < "$B/vecadd.ir") +head -c $((size-1)) "$B/vecadd.ir" > "$B/truncated.ir" +refuse 'truncated' TRUNCATED "$B/truncated.ir" 8 vaddi32 +{ cat "$B/vecadd.ir"; bytes 0; } > "$B/trailing.ir" +refuse 'trailing byte' TRAILING "$B/trailing.ir" 8 vaddi32 +[ "$neg" = 23 ] || fail "expected 23 negative controls and refusals, ran $neg" + +sha256sum "$B/irstablehlo" "$B"/case-*.mlir | sed 's/^/SHA256 /' +printf 'PASS irstablehlo: %s cases on two interop oracles (not Omega-native, not hardware), %s negatives caught\n' "$i" "$neg" diff --git a/seed/stablehlo/irstablehlo.om b/seed/stablehlo/irstablehlo.om new file mode 100644 index 000000000..12187931d --- /dev/null +++ b/seed/stablehlo/irstablehlo.om @@ -0,0 +1,729 @@ +note SPDX-License-Identifier: Apache-2.0 +note OSC IR scalar unit to StableHLO MLIR text. One named function is lifted +note elementwise: every scalar value becomes a tensor of N elements of its type. +note Usage: irstablehlo N FUNCTION < unit.ir > module.mlir +note Wire authority spec/one-layer-format.md: version 1 (sections 3-7) as omc ir +note writes it, and version 7 (section 10) for f32/f64 scalar functions only. +note StableHLO authority https://github.com/openxla/stablehlo/blob/main/docs/spec.md +note ops add subtract multiply divide and or xor constant (read 2026-10-26). +note Handwritten Omega; no host or foreign generator dependency. +note NOT preserved: Omega signed add/sub/mul trap 1 on overflow. The StableHLO +note spec section Errors leaves integer overflow implementation-defined, so a +note lifted signed op neither traps nor has a specified result on overflow. +note Unsigned wrap is Omega's rule and the tested oracles' behaviour, not a +note StableHLO spec guarantee. Float ops are IEEE-754 in both. +note Refused: div rem shl shr on integers (trap 2 and trap 7 have no StableHLO +note form), UN CMP CAST CALL TRAP BR CBR, more than one block, contracts, bool, +note float constants, mixed element types, structs, regions, refs. +note Buffered output: every refusal happens before any stdout write. +global input uchar 2620252 +global output uchar 4194304 +note state slots: 0 input cursor, 1 input size, 2 output size, 3 nparams, +note 4 nvregs, 5 wire version, 6 N, 7 element tag, 8 name matches, +note 9 wanted name length, 10 ninsns, 11 nblocks, 12 block 0 first, +note 13 block 0 count, 14 return tag, 15 contract bytes +global state ulong 16 +global types ulong 480 +note cur: SSA value of each vreg; 0 undefined, 1+p parameter p, 100000+k insn k. +global cur ulong 480 +global ops ulong 4096 +global subs ulong 4096 +global dest ulong 4096 +global arg0 ulong 4096 +global arg1 ulong 4096 +global immed ulong 4096 +global want uchar 64 +global abuf uchar 16 +global digits uchar 24 +text emagic "irstablehlo: MAGIC\n" +text ever "irstablehlo: VERSION\n" +text etrunc "irstablehlo: TRUNCATED\n" +text ecap "irstablehlo: CAPACITY\n" +text eop "irstablehlo: UNSUPPORTED_OP\n" +text etype "irstablehlo: UNSUPPORTED_TAG\n" +text einval "irstablehlo: INVALID\n" +text etrail "irstablehlo: TRAILING\n" +text eio "irstablehlo: IO\n" +text eusage "irstablehlo: USAGE\n" +text enofn "irstablehlo: NO_FUNCTION\n" +text thead "module {\n func.func public @main(" +text tparam ": tensor<" +text tcomma ", " +text tarrow ") -> tensor<" +text tbody "> {\n" +text tinsn " %i" +text tassign " = stablehlo." +text tof " : tensor<" +text teol ">\n" +text tret " func.return " +text tclose " }\n}\n" +text tconst "constant dense<" +text tdense "> : tensor<" +text tadd "add" +text tsub "subtract" +text tmul "multiply" +text tdiv "divide" +text tand "and" +text tor "or" +text txor "xor" +fn refuse code int to void +k = long 0 +if eq code 20 +k = write 2 emagic 0 len emagic +end +if eq code 21 +k = write 2 ever 0 len ever +end +if eq code 22 +k = write 2 etrunc 0 len etrunc +end +if eq code 23 +k = write 2 ecap 0 len ecap +end +if eq code 24 +k = write 2 eop 0 len eop +end +if eq code 25 +k = write 2 etype 0 len etype +end +if eq code 26 +k = write 2 einval 0 len einval +end +if eq code 27 +k = write 2 etrail 0 len etrail +end +if eq code 28 +k = write 2 eio 0 len eio +end +if eq code 29 +k = write 2 eusage 0 len eusage +end +if eq code 30 +k = write 2 enofn 0 len enofn +end +exit code +end +fn need ok bool to void +if not ok +refuse 26 +end +end +fn rd n ulong to ulong +p = get state 0 +if gt n sub get state 1 p +refuse 22 +end +v = ulong 0 +for j ulong n +v = or v shl ulong get input add p j mul j 8 +end +put state 0 add p n +ret v +end +fn cap n ulong maxv ulong to ulong +if gt n maxv +refuse 23 +end +ret n +end +note Tags 2..9 integers, 13 f32 and 14 f64 (version 7 only); 0 void, 1 bool. +note Refs, bytes and cells (10..12) need more bytes and are refused here. +fn typ to ulong +t = rd 1 +if eq get state 5 7 +if or ge t 15 and ge t 10 le t 12 +refuse 25 +end +ret t +end +if gt t 9 +refuse 25 +end +ret t +end +fn vr to ulong +v = rd 2 +need lt v get state 4 +ret v +end +fn width t ulong to ulong +if eq t 1 +ret 1 +end +if or eq t 2 eq t 6 +ret 8 +end +if or eq t 3 eq t 7 +ret 16 +end +if or or eq t 4 eq t 8 eq t 13 +ret 32 +end +ret 64 +end +fn mask t ulong to ulong +w = width t +if eq w 64 +ret 18446744073709551615 +end +ret sub shl ulong 1 w 1 +end +note Canonical CONST: unsigned zero-extended, signed sign-extended to 64 bits. +fn canon v ulong t ulong to ulong +w = width t +if eq w 64 +ret v +end +v = and v mask t +if ge t 6 +m = shl ulong 1 sub w 1 +v = sub xor v m m +end +ret v +end +fn txt n ulong to void +for j ulong n +v = rd 1 +need ne v 0 +end +end +fn nametxt n ulong to void +for j ulong n +v = rd 1 +need and ne v 0 lt v 128 +end +end +fn insn i ulong to void +o = rd 1 +put ops i o +put subs i 0 +put dest i 65535 +put arg0 i 65535 +put arg1 i 65535 +put immed i 0 +if eq o 1 +put dest i vr +put immed i rd 8 +ret +end +if or eq o 2 eq o 6 +put dest i vr +put arg0 i vr +ret +end +if or or eq o 3 eq o 4 eq o 5 +put subs i rd 1 +put dest i vr +put arg0 i vr +if ne o 4 +put arg1 i vr +end +ret +end +if eq o 11 +d = rd 2 +if ne d 65535 +need lt d get state 4 +end +put dest i d +put immed i rd 2 +n = cap rd 1 6 +for j ulong n +a = vr +end +ret +end +if eq o 12 +put immed i rd 1 +ret +end +if eq o 13 +put immed i rd 2 +ret +end +if eq o 14 +put arg0 i vr +put immed i rd 2 +put arg1 i rd 2 +ret +end +if eq o 15 +v = rd 2 +if ne v 65535 +need lt v get state 4 +end +put arg0 i v +ret +end +refuse 24 +end +fn emit v ulong to void +p = get state 2 +if ge p len output +refuse 23 +end +put output p uchar v +put state 2 add p 1 +end +fn dec v ulong to void +n = ulong 0 +x = v +for j ulong 20 +put digits n uchar add rem x 10 48 +n = add n 1 +x = div x 10 +if eq x 0 +break +end +end +for j ulong n +emit ulong get digits sub sub n j 1 +end +end +fn sdec v ulong to void +t = get state 7 +if and ge t 6 ge v 9223372036854775808 +emit 45 +dec sub 0 v +ret +end +dec v +end +fn emtxt id ulong to void +if eq id 1 +for j ulong len thead +emit ulong get thead j +end +ret +end +if eq id 2 +for j ulong len tparam +emit ulong get tparam j +end +ret +end +if eq id 4 +for j ulong len tcomma +emit ulong get tcomma j +end +ret +end +if eq id 5 +for j ulong len tarrow +emit ulong get tarrow j +end +ret +end +if eq id 6 +for j ulong len tbody +emit ulong get tbody j +end +ret +end +if eq id 7 +for j ulong len tinsn +emit ulong get tinsn j +end +ret +end +if eq id 8 +for j ulong len tassign +emit ulong get tassign j +end +ret +end +if eq id 9 +for j ulong len tof +emit ulong get tof j +end +ret +end +if eq id 10 +for j ulong len teol +emit ulong get teol j +end +ret +end +if eq id 11 +for j ulong len tret +emit ulong get tret j +end +ret +end +if eq id 12 +for j ulong len tclose +emit ulong get tclose j +end +ret +end +if eq id 13 +for j ulong len tconst +emit ulong get tconst j +end +ret +end +if eq id 14 +for j ulong len tdense +emit ulong get tdense j +end +ret +end +if eq id 15 +for j ulong len tadd +emit ulong get tadd j +end +ret +end +if eq id 16 +for j ulong len tsub +emit ulong get tsub j +end +ret +end +if eq id 17 +for j ulong len tmul +emit ulong get tmul j +end +ret +end +if eq id 18 +for j ulong len tdiv +emit ulong get tdiv j +end +ret +end +if eq id 19 +for j ulong len tand +emit ulong get tand j +end +ret +end +if eq id 20 +for j ulong len tor +emit ulong get tor j +end +ret +end +if eq id 21 +for j ulong len txor +emit ulong get txor j +end +ret +end +refuse 26 +end +note Element type: ui8..ui64 for tags 2..5, i8..i64 (signed in StableHLO) for +note 6..9, f32 and f64 for 13 and 14. +fn elem to void +t = get state 7 +if ge t 13 +emit 102 +else +if le t 5 +emit 117 +end +emit 105 +end +dec width t +end +fn ttype to void +dec get state 6 +emit 120 +elem +end +fn valc c ulong to void +emit 37 +if lt c 100000 +emit 112 +dec sub c 1 +else +emit 105 +dec sub c 100000 +end +end +fn defd r ulong to ulong +c = get cur r +need ne c 0 +ret c +end +fn binname s ulong to ulong +fl = ge get state 7 13 +if eq s 1 +ret 15 +end +if eq s 2 +ret 16 +end +if eq s 3 +ret 17 +end +if eq s 4 +if fl +ret 18 +end +refuse 24 +end +need and not fl and ge s 5 le s 10 +if eq s 6 +ret 19 +end +if eq s 7 +ret 20 +end +if eq s 8 +ret 21 +end +refuse 24 +ret 0 +end +fn header to void +emtxt 1 +for j ulong get state 3 +if ne j 0 +emtxt 4 +end +emit 37 +emit 112 +dec j +emtxt 2 +ttype +emit 62 +end +emtxt 5 +ttype +emtxt 6 +end +fn step k ulong to void +o = get ops k +last = eq k sub get state 10 1 +if eq o 15 +need last +a = get arg0 k +need ne a 65535 +c = defd a +emtxt 11 +valc c +emtxt 9 +ttype +emtxt 10 +ret +end +need not last +d = get dest k +if eq o 2 +put cur d defd get arg0 k +ret +end +if eq o 1 +if ge get state 7 13 +refuse 24 +end +v = get immed k +need eq v canon v get state 7 +emtxt 7 +dec k +emtxt 8 +emtxt 13 +sdec v +emtxt 14 +ttype +emtxt 10 +put cur d add k 100000 +ret +end +if eq o 3 +nm = binname get subs k +x = defd get arg0 k +y = defd get arg1 k +emtxt 7 +dec k +emtxt 8 +emtxt nm +emit 32 +valc x +emtxt 4 +valc y +emtxt 9 +ttype +emtxt 10 +put cur d add k 100000 +ret +end +refuse 24 +end +fn lift to void +t = get state 14 +if or le t 1 and ge t 10 le t 12 +refuse 25 +end +put state 7 t +if ne get state 15 0 +refuse 24 +end +if ne get state 11 1 +refuse 24 +end +for j ulong get state 4 +if ne get types j t +refuse 25 +end +put cur j 0 +end +ni = get state 10 +need eq get state 12 0 +need eq get state 13 ni +for j ulong get state 3 +put cur j add j 1 +end +header +for k ulong ni +step k +end +emtxt 12 +end +fn loadfn to void +start = get state 0 +n = cap rd 1 63 +need ne n 0 +nametxt n +hit = false +if eq n get state 9 +hit = true +for j ulong n +if ne get input add start add j 1 get want j +hit = false +end +end +end +np = cap rd 1 6 +put state 14 typ +nv = cap rd 2 480 +need ge nv np +put state 3 np +put state 4 nv +for j ulong nv +t = typ +need ne t 0 +put types j t +end +nb = cap rd 2 512 +need ne nb 0 +put state 11 nb +for j ulong nb +f = rd 4 +c = rd 4 +if eq j 0 +put state 12 f +put state 13 c +end +end +ni = cap rd 4 4096 +need ne ni 0 +put state 10 ni +for j ulong ni +insn j +end +rq = cap rd 2 255 +txt rq +en = cap rd 2 255 +txt en +put state 15 add rq en +if hit +need eq get state 8 0 +put state 8 1 +lift +end +end +fn main to int +if ne argcnt 3 +refuse 29 +end +k = argread 1 abuf 0 len abuf +if or lt k 1 gt k 8 +refuse 29 +end +nv = ulong 0 +for j ulong ulong k +c = get abuf j +if or lt c 48 gt c 57 +refuse 29 +end +nv = add mul nv 10 ulong sub c 48 +end +if or eq get abuf 0 48 gt nv 16777216 +refuse 29 +end +put state 6 nv +k = argread 2 want 0 len want +if or lt k 1 gt k 63 +refuse 29 +end +put state 9 ulong k +n = ulong 0 +for attempt ulong 2620252 +if eq n len input +refuse 23 +end +k = read 0 input n sub len input n +if lt k 0 +refuse 28 +end +if eq k 0 +break +end +n = add n ulong k +end +if eq n len input +refuse 23 +end +put state 1 n +magic = new uchar 7 0 +put magic 0 79 +put magic 1 83 +put magic 2 67 +put magic 3 49 +put magic 4 73 +put magic 5 82 +for j ulong 7 +v = rd 1 +if ne v ulong get magic j +refuse 20 +end +end +v = rd 1 +if and ne v 1 ne v 7 +refuse 21 +end +put state 5 v +if eq v 7 +if ne rd 1 0 +refuse 24 +end +if ne rd 2 0 +refuse 24 +end +end +nf = cap rd 2 32 +need ne nf 0 +for f ulong nf +loadfn +end +if ne get state 0 n +refuse 27 +end +if eq get state 8 0 +refuse 30 +end +p = ulong 0 +for attempt ulong 4194304 +if eq p get state 2 +break +end +k = write 1 output p sub get state 2 p +if le k 0 +refuse 28 +end +p = add p ulong k +end +ret 0 +end diff --git a/seed/stablehlo/pjrt-oracle.py b/seed/stablehlo/pjrt-oracle.py new file mode 100644 index 000000000..8fcd8c221 --- /dev/null +++ b/seed/stablehlo/pjrt-oracle.py @@ -0,0 +1,101 @@ +# SPDX-License-Identifier: Apache-2.0 +# Interop oracle, not Omega-native; never generates kernels. +# Compiles an existing StableHLO MLIR text file (written by irstablehlo.om) with +# the XLA CPU PJRT client shipped in jaxlib, executes @main on the host CPU and +# compares every result element bit-for-bit with an expected vector. +# jax.jit and every jax tracing API are unused: the module text is the only input. +# Host dependency: jaxlib (Apache-2.0), version printed on every run. Omega +# replacement: a PJRT C API caller in .om once Omega can load a C ABI plugin +# (FR-7 in docs/one_layer/OM_COMPLETION.md). +# Usage: pjrt-oracle.py MODULE ELEMTYPE N EXPECTED INPUT... +# Lists are comma-separated decimals. Exit 0 match, 1 mismatch, 2 module refused +# by the oracle, 3 oracle unavailable, 4 bad arguments, 5 execution error. +import os +import sys + +# PJRT_ORACLE_PLATFORM selects the PJRT client: cpu (default, this gate) or tpu +# (a Cloud TPU VM with libtpu; the TPU receipt path, NOT_RUN so far). +PLATFORM = os.environ.get("PJRT_ORACLE_PLATFORM", "cpu") +os.environ["JAX_PLATFORMS"] = PLATFORM + +TYPES = { + "i8": "int8", "i16": "int16", "i32": "int32", "i64": "int64", + "ui8": "uint8", "ui16": "uint16", "ui32": "uint32", "ui64": "uint64", + "f32": "float32", "f64": "float64", +} + + +def main(argv): + if len(argv) < 5 or argv[2] not in TYPES: + print("usage: pjrt-oracle.py MODULE ELEMTYPE N EXPECTED INPUT...", file=sys.stderr) + return 4 + try: + import numpy as np + import jax + import jaxlib + from jax._src.lib import xla_client as xc + except ImportError as exc: + print(f"ORACLE_MISSING {exc}", file=sys.stderr) + return 3 + dtype = np.dtype(TYPES[argv[2]]) + count = int(argv[3]) + + def vector(text): + words = text.split(",") + if len(words) != count: + raise ValueError(f"expected {count} elements, got {len(words)}") + if dtype.kind == "f": + return np.array([dtype.type(w) for w in words], dtype=dtype) + info = np.iinfo(dtype) + values = [int(w) for w in words] + if any(v < info.min or v > info.max for v in values): + raise ValueError(f"value outside {dtype}") + return np.array(values, dtype=dtype) + + try: + expected = vector(argv[4]) + inputs = [vector(t) for t in argv[5:]] + except ValueError as exc: + print(f"BAD_ARGUMENT {exc}", file=sys.stderr) + return 4 + devices = jax.devices(PLATFORM) + client = devices[0].client + print(f"PJRT jax={jax.__version__} jaxlib={jaxlib.__version__} " + f"platform={client.platform} platform_version={client.platform_version}") + with open(argv[1], encoding="utf-8") as handle: + module = handle.read() + try: + executable = client.compile_and_load( + module, xc.DeviceList(tuple(devices[:1])), xc.CompileOptions()) + except Exception as exc: # the oracle's own refusal is the evidence here + print(f"MODULE_REFUSED {type(exc).__name__}: {str(exc).splitlines()[0]}") + return 2 + # jax_enable_x64 keeps 64-bit element types; device_put would otherwise + # narrow them to 32 bits. It changes buffer transfer only, not the module. + jax.config.update("jax_enable_x64", True) + try: + buffers = [jax.device_put(x, devices[0]) for x in inputs] + results = executable.execute_sharded(buffers).disassemble_into_single_device_arrays() + except Exception as exc: + print(f"EXECUTE_ERROR {type(exc).__name__}: {str(exc).splitlines()[0]}") + return 5 + if len(results) != 1: + print(f"MISMATCH result count {len(results)}") + return 1 + observed = np.asarray(results[0][0]) + print("OBSERVED " + ",".join(repr(v.item()) for v in observed)) + if observed.dtype != dtype or observed.shape != expected.shape: + print(f"MISMATCH type {observed.dtype}{observed.shape} expected {dtype}{expected.shape}") + return 1 + bits = np.dtype(f"u{dtype.itemsize}") + diff = np.nonzero(observed.view(bits) != expected.view(bits))[0] + if diff.size: + i = int(diff[0]) + print(f"MISMATCH index {i} observed {observed[i]!r} expected {expected[i]!r}") + return 1 + print("MATCH bitwise") + return 0 + + +if __name__ == "__main__": + sys.exit(main(sys.argv)) diff --git a/seed/stablehlo/refuse.unit.om b/seed/stablehlo/refuse.unit.om new file mode 100644 index 000000000..355e56583 --- /dev/null +++ b/seed/stablehlo/refuse.unit.om @@ -0,0 +1,19 @@ +note Functions irstablehlo must refuse with an empty stdout. +fn divi32 a int b int to int +ret div a b +end +fn shlu32 a uint b uint to uint +ret shl a b +end +fn maxi32 a int b int to int +if gt a b +ret a +end +ret b +end +fn widen a uint to ulong +ret ulong a +end +fn isodd a int to bool +ret ne and a 1 0 +end diff --git a/seed/stablehlo/vecadd.unit.om b/seed/stablehlo/vecadd.unit.om new file mode 100644 index 000000000..ac12adedc --- /dev/null +++ b/seed/stablehlo/vecadd.unit.om @@ -0,0 +1,16 @@ +note Scalar functions lifted elementwise by irstablehlo: out[i] = f(a[i], b[i]). +fn vaddi32 a int b int to int +ret add a b +end +fn vaddu32 a uint b uint to uint +ret add a b +end +fn vaddi64 a long b long to long +ret add a b +end +fn madi32 a int b int c int to int +ret add mul a b c +end +fn biasi32 a int to int +ret add a -3 +end ```