interplane.Get Omega
Read in your language

omega-bridge

Omega-first language interoperability: checked conversion backends and native language bindings

Brought by drakestapleton

branch main Branches Tags History

omega-bridge / AGENTS.md

108 lines · 12784 bytes Raw Blame History Rendered
1# Omega Bridge (Omega's compatibility gateway: a checked Omega subset converted to C and Python, native call bindings and GPU artifact negotiation)
2
3> `src/toc.om` is an Omega program, built by the pinned seeded Omega compiler, that emits executable C and Python from a checked, bounded Omega subset (ABI v0). `src/native.om` generates a C binding so C, C++, Python, Rust, Zig and Go call the machine code the seeded compiler produced (native call ABI v1/v2). `src/gpu_adapter.om` is an opt-in GPU adapter boundary that negotiates and admits artifacts; it converts no host program. The bootstrap and generators require Linux AArch64; emitted C is portable to Linux x86-64, and hosted native output also has explicit x86-64 SysV Linux selection, exercised under QEMU 10.0.14 (physical x86 NOT_RUN). Independent review remains required before release; no universal conversion or speedup is claimed.
4
5> Ownership rule (ARCH-0042, aien-dev/aien-architecture-mv#342, Accepted (Drake, 2026-10-30)): Omega owns computation, CUDA++ owns GPU execution, Omega Bridge owns compatibility. This repository is not a second Omega compiler, encoder or GPU runtime: it builds with omega-mv's pinned compiler and runs Omega GPU work only through aien-dev/CUDApp. Remaining overlaps: omega-mv#870 (own seed bootstrap), omega-mv#871 (own front end in `src/toc.om`).
6
7Shared rules: read https://www.aienos.com/agents/RULES.md first. This file adds what is specific to this repository; where the two differ, this file wins here.
8
9## Scope
10
11- Applies to the whole repository.
12- `src/`: all conversion logic and both runtime emitters (`toc.om`), the native binding generator (`native.om`) and the GPU adapter (`gpu_adapter.om`). These are Omega source; keep them Omega.
13- `tools/`: shell entry points (`bootstrap.sh`, `build.sh`, `test.sh`, `bridge`, `native`, `build-gpu-adapter.sh`, `run-device-window.sh`) and `run-device-window.om`, the Omega successor of `run-device-window.sh` (build and CPU controls: `tests/device-window/README.md`).
14- `tests/`: Python test harness (infrastructure only), fixtures, refusal cases, native callers in six languages, GPU adapter protocol tests.
15- `conformance/`: separate-process Omega versus Modular MAX harness. `evidence/`: raw logs and result manifests.
16- `pytorch/`: `torch.compile` backend `"omega"` (docs/OMEGA-TORCH.md). Kernels are `.om` (`pytorch/kernels/`); `pytorch/omega_torch/` is interim Python glue that registers the backend, walks the FX graph and calls units through the native ABI. It must never compute a tensor value; an unsupported op raises, and eager fallback only happens for ops the caller names, counted.
17- No compiler binary is stored here. Python/C input conversion is not implemented. Heap operations and other target languages are refused by the C/Python converters. Read-only text constants (`text NAME "..."`) convert in the baseline `tools/bridge c|python` only, as exact `static const uint8_t` bytes and immutable Python `bytes` (`docs/TEXT-CONVERSION.md`; run `python3 tests/text.py`); inline text literals stay refused by the seed. Floats are refused by the baseline `tools/bridge` and by Python; only the additive seeded C frontend (`tools/bridge-seeded c`) lowers internal f32/f64 scalars, float constants and float ops (see `docs/CAPABILITIES.md`; run `python3 tests/seeded_float.py`).
18
19## Installation
20
21Needs a Linux AArch64 build host, `git`, `sh`, `file`, `sha256sum`, `gcc` and `python3`. The bootstrap uses no C compiler, assembler or linker. Cross-building hosted x86 native libraries additionally needs an x86-targeting `CC`; it does not make the bootstrap or generator runnable on x86.
22
23```sh
24git clone https://github.com/aien-dev/omega-bridge.git
25cd omega-bridge
26sh tools/bootstrap.sh # fetches the pinned Omega source commit, grows omc from the seed, checks the fixpoint
27tools/build.sh # builds build/bridge from src/toc.om with the pinned seed
28```
29
30The bootstrap fetches the Omega source commit recorded in `docs/PROVENANCE.md` (`29b12760f4c962606411d6bf25032aedef063301`), so it needs access to the upstream repository. It ends with `bootstrap fixpoint RC=0` and leaves the seed at `build/bootstrap/omc` (sha256 `191b776ef98821597c3e30655da6d680a9b66edbc9ceaca3c39c61ea6df098e9`).
31
32## Configuration
33
34- `OMEGA_SOURCE`: an existing Omega checkout to read the pinned commit from instead of fetching it (read only).
35- `OMEGA_SEED`: an already qualified seed compiler; its sha256 must be the pinned one above.
36- `OMEGA_NATIVE_OMC`: mandatory baseline compiler for building the native generator and compiling AArch64 OM-1 units, sha256 `734f0a39319fbfa930bcc62cb30dbf06d47d78e126372b74f5baf478e6126b61` (omega-mv PR #696). Do not replace this pin with the x86 compiler.
37- `OMEGA_NATIVE_OMC2`: compiler for AArch64 OM-2 units; its digest is recorded in their identities.
38- `OMEGA_NATIVE_HOST_OMC2`: native-v2 qualification section 11's host-fixture compiler only, omega-mv #1008 @ `2992a68b`, sha256 `c000ec029fb85847084a82e345cb7b384cc678a735ed37e9fcbc0f557534b911`. That suite separately pins `OMEGA_NATIVE_OMC2` to `hoist/865-main` @ `7286d61d`, sha256 `078200466af2dc0452da7793b186d91bc9539f0cf5fafa15bcdb2a48e3bedef7`; neither compiler alone has both features. Exact rebuilds: `docs/NATIVE-ABI.md`, AArch64 qualification.
39- `OMEGA_NATIVE_DEVICE_OMC2`: native-v2 device and single-edit phase compiler, sha256 `6d1b1cf5a44803389a831b67f750ea4cd1c9f53edfde9d6d9241d7352887f1f8`. Supply its source via `OMEGA_NATIVE_OMC2_SOURCE` for the exact-fixpoint mutant checks. This role does not replace the hoist or section 11 pins.
40- `OMEGA_NATIVE_X86_OMC`: separate compiler for both OM-1 and OM-2 units under `tools/native --target x86linux`, sha256 `be8c51301307555254fc59e351d281aae1aa096d91521777e33a41c8b446448a` (omega-mv main `seed/out/omc` since #994). `OMEGA_NATIVE_OMC2` is unused for this target.
41- `CC`: native library C compiler, for example `x86_64-linux-gnu-gcc` with `--target x86linux`; no host-architecture inference changes the requested target. `OMEGA_NATIVE_CFLAGS` supplies extra C flags.
42- `QEMU_X86_64`: emulator command for `tests/native/x86/run.sh`. Use the unpatched QEMU 10.0.14 oracle documented in `docs/NATIVE-ABI.md`; integration observed signal and `/proc/self/maps` failures with 8.2.2. This is verification infrastructure, not a production dependency. At the current x86 compiler pin, full-suite, mismatched-pin and failed/missing-toolchain controls passed EMULATED; physical x86 execution remains NOT_RUN. Receipt: `evidence/native-x86-be8c5130.json`; earlier pins' receipts remain in `evidence/native-x86-62775d2a.json`, `evidence/native-x86-badedbb0/`, `evidence/native-x86-f7752bc5/` and `evidence/native-x86/`.
43- `OMEGA_NATIVE_X86_PYTHON`, `OMEGA_NATIVE_X86_SYSROOT`, `OMEGA_NATIVE_X86_LIBPATH`: guest Python executable, loader sysroot and optional guest library path for the x86 emulator suite. The Python must be x86 Linux, not the host interpreter.
44- `OMEGA_SEEDED_OMC`: optional additive `tools/bridge-seeded` frontend compiler, omega-mv `e5b32567`, sha256 `2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f`. It does not replace the baseline build/test seed. See `docs/CAPABILITIES.md` and run `python3 tests/seeded.py` after the unchanged baseline suite.
45- `MAXPY`: Python interpreter of a venv with `modular==26.7.0`, used by `conformance/run.sh`.
46- On a shared build host, prefix the build and test commands with `quiet-build`, as the README does. Without it, run the scripts directly.
47
48## Usage
49
50```sh
51# Full local suite: build, differential (native vs C vs Python), refusals, callers, controls, robustness
52tools/test.sh
53
54# Convert and run an example
55tools/bridge c tests/fixtures/fib.om > build/fib.c
56gcc -std=gnu11 -O2 build/fib.c -o build/fib
57build/fib
58tools/bridge python tests/fixtures/fib.om > build/fib.py
59python3 build/fib.py
60
61# Real C and Python application callers of a generated library
62python3 tests/attachments.py
63
64# Native call ABI v1: one compiled Omega function called from C, C++, Python, Rust, Zig, Go
65OMEGA_NATIVE_OMC=/path/to/omega-mv/seed/out/omc sh tests/native/run.sh
66
67# f32 and ushort array kinds (C oracle, refusals, add->sub mutant)
68OMEGA_NATIVE_OMC=/path/to/omega-mv/seed/out/omc sh tests/native/kinds.sh
69
70# Hosted x86 native output (cross-build only; this command does not execute callers)
71OMEGA_NATIVE_OMC=/path/to/baseline/omc OMEGA_NATIVE_X86_OMC=/path/to/x86/omc \
72 CC=x86_64-linux-gnu-gcc tools/native --target x86linux build/native-x86 tests/native/madd.om
73
74# GPU adapter protocol (no device is opened)
75OMEGA_SEED=build/bootstrap/omc sh tools/build-gpu-adapter.sh
76python3 tests/gpu/test_gpu_adapter.py
77```
78
79`tools/test.sh` ends with `ALL SUITES RC=0`. `tests/native/run.sh` emits `NATIVE-CALL PASS` only after all seven required callers (including C with BTI) have built and executed successfully. Missing language toolchains emit NOT_RUN and exit nonzero; present toolchains whose builds fail emit FAIL and exit nonzero. `tests/native/test_build_failures.sh` exercises both refusal paths with failing-toolchain controls, then runs the real Zig and Go callers. `tools/bridge` writes to stdout only after the whole conversion succeeds and refuses to run if `build/compiler.sha256` no longer matches (rebuild with `tools/build.sh`).
80
81`conformance/run.sh` needs `MAXPY` (a Modular MAX 26.7 venv); without `--device` it runs on CPU only. `conformance/run.sh --device`, `tools/run-device-window.sh --ledger <ID>` and `build/run-device-window --ledger <ID>` need the NVIDIA GB10 on a DGX Spark inside an authorized `spark-window`, plus a sibling CUDApp build. Do not run them anywhere else.
82
83## Conventions
84
85- All conversion logic stays in `src/*.om`. The Python under `tests/` and `conformance/` is test infrastructure, not part of the bridge.
86- Every compiler input is pinned by sha256. Never commit a compiler binary; the bootstrap rebuilds it from source.
87- The seed checks the whole unit before either backend runs; `tools/bridge` snapshots the input once so validation and generation read identical bytes. Keep that order.
88- A refusal is a result: capacity exhaustion or an unsupported feature exits with a code and writes no partial output. Do not add silent fallbacks.
89- Keep red before green: add the failing log beside the passing one in `evidence/` when you fix a defect. Never rewrite an existing evidence log.
90- Generated C targets GNU C11 and POSIX; generated Python targets Python 3. Callers must supply an eight-MiB stack (see `docs/CAPABILITIES.md`).
91- Native output defaults to `aarch64linux`; keep its compiler inputs and `native-gen OUTPUT` calls unchanged. For x86, compile `target x86linux\n` plus the source snapshot and invoke `native-gen OUTPUT x86linux`. Never put the prefix into framed source or source identity. X86 OM-2 export entries occupy six bytes, not AArch64's four-byte words.
92- `tools/native --freestanding` supports AArch64 and x86 pure units: OM-1 integer scalars, or OM-2 views/layouts/local/out arrays and private f32/f64 behind an integer-only public ABI. No host/TLS/heap/libc imports; only the `_GLOBAL_OFFSET_TABLE_` linker marker may remain unresolved. Private floats require caller-enabled hardware FP and inherit its control state. FP32 arithmetic NaNs compare by class only; integer-ABI outputs must never be canonicalized. Cross-builds and QEMU runs do not qualify native x86 execution: label emulator evidence explicitly and unexecuted native callers NOT_RUN. Do not run the AArch64 BTI-specific caller as an x86 qualification requirement.
93
94## Safety and approvals
95
96- Conversion creates isolated temporary build files and never installs or replaces an application. Keep it that way; do not add install steps.
97- The GPU adapter is disabled by default: no daemon, no environment hook, no automatic attachment. A caller proceeds only on `ACCEPT`; `REFUSE` is final. Ask before changing that contract or the wire format in `docs/GPU-ADAPTER.md`.
98- Device runs happen only in an authorized GB10 window. `tools/run-device-window.sh` and `tools/run-device-window.om` never reset the GPU, change the driver or touch a serving process; keep it that way.
99- Ask before changing any pinned commit or fingerprint (`tools/bootstrap.sh`, `tools/build.sh`, `tools/bridge`, `tests/native/run.sh`).
100
101## Further reading
102
103- `README.md`: build, convert and caller quick start.
104- `docs/CAPABILITIES.md`: supported features, limits and trap codes.
105- `docs/ABI.md` (ABI v0), `docs/NATIVE-ABI.md` (native call ABI v1).
106- `docs/GPU-ADAPTER.md`, `docs/GPU-SUPPORT-MATRIX.md`, `docs/MAX-INTEGRATION.md`: the GPU and MAX boundary.
107- `docs/DESIGN.md`, `docs/PROVENANCE.md`, `docs/REPRODUCE.md`: design decisions, source pins, reproduction steps.
108- `evidence/README.md`: what the local qualification ran.