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 / README.md

156 lines · 15604 bytes Raw Blame History Rendered
1# Omega Bridge
2
3Omega's compatibility gateway. `src/toc.om` is an Omega program that converts a checked, bounded Omega subset into executable C and Python; `src/native.om` generates bindings so existing C, C++, Python, Rust, Zig and Go code calls compiled Omega; `src/gpu_adapter.om` negotiates and admits GPU artifacts and runs no kernel. Apache-2.0 WITH LLVM-exception.
4
5Ownership rule ([ARCH-0042](https://github.com/aien-dev/aien-architecture-mv/pull/342), Accepted (Drake, 2026-10-30)): Omega owns computation, CUDA++ owns GPU execution, Omega Bridge owns compatibility.
6
7- **Omega Bridge (this repository)** owns compatibility: conversion to C and Python, native-call bindings, framework attachments (MAX conformance; PyTorch and GGML pending (#23/#30, ggml-omega#1/#2)) and GPU artifact negotiation. It exists so existing ecosystems can adopt Omega without rewriting; it makes them optional and does not constrain Omega to them.
8- **[Omega](https://github.com/aien-dev/omega-mv)** owns computation: the language and its semantics, the seeded compiler and its pin. This repository builds with that compiler; it is not a second Omega compiler. Today `tools/bootstrap.sh` replays the seed itself and `src/toc.om` keeps its own front end; both stay as they are, and new compiler work goes to Omega ([omega-mv#870](https://github.com/aien-dev/omega-mv/issues/870), [omega-mv#871](https://github.com/aien-dev/omega-mv/issues/871)).
9- **[CUDA++](https://github.com/aien-dev/CUDApp)** owns GPU execution: encoder, GPU code generation, cubin writer, artifact admission, driver client and runtime. Omega device runs here go through CUDA++ (`conformance/build.sh` links `conformance/omega_runner.c` against its `libomega_gpu.a`; `tools/run-device-window.sh` calls its `cubin_probe`).
10
11The source-only bootstrap of the pinned Omega compiler currently requires Linux AArch64. Generated C uses GNU C11 and POSIX; generated Python uses Python 3. This branch has local differential tests and caller demos; independent review remains required before release. No universal conversion or performance improvement is claimed.
12
13## How it works / How I built it
14
15`tools/bridge c|python file.om` checks two hashes: the converter against its source and the seed compiler against pin `191b776e…`. It then takes one snapshot of the input. The pinned Omega seed compiler checks the whole unit, and `build/bridge` (compiled from `src/toc.om`) parses that snapshot into typed expression nodes. Separate writers emit C or Python from those nodes. The generated program prints the same output, exits with the same status and traps with the same code as native Omega. A feature outside the subset is refused with its error code and nothing on stdout. Conversion never installs anything, so rollback means you stop importing the file.
16
17`src/toc.om` was recovered from uncommitted omega source on base `29b12760`. Run unchanged, its emitter failed 8 of 20 inherited cases: traps turned into exit 0 or a segfault ([evidence/01-recovered-red.log](evidence/01-recovered-red.log)). It was replaced by checked typed nodes. Limits: scalar subset only (no text, floats or heap), and the bootstrap proves a fixpoint, not DDC. The [walkthrough](docs/WALKTHROUGH.md) has the full story, a source map, and an offline recipe with a positive case, a refusal case (exit 24) and a tampered-pin control (exit 65).
18
19Build from exact pinned source:
20
21```sh
22quiet-build tools/bootstrap.sh
23quiet-build tools/build.sh
24quiet-build tools/test.sh
25```
26
27On a host without quiet-build, run those scripts directly. The bootstrap fetches the exact Omega source commit recorded in docs/PROVENANCE.md. Access to the upstream repository is required. An existing checkout can supply it through OMEGA_SOURCE; it is read only. No compiler binary is stored in this repository. If you already have the qualified seed, OMEGA_SEED can name it; its fingerprint is enforced.
28
29The `Portable bridge behavior` workflow runs the existing baseline suite,
30`tests/seeded.py`, `tests/seeded_float.py`, `tests/seeded_views.py`, and `tests/freest.py` on disposable
31Linux AArch64 runners. It source-bootstraps the baseline, checks the exact
32seeded compiler hash, and exercises the pinned CUDApp revision/epoch roots.
33This is executable behavior and refusal coverage, not CodeQL or device
34qualification. Native x86 compiled-C consumer coverage is separate in CUDApp's
35`Ampere native x86 host` workflow; the failing native Omega compiler923 is
36not a dependency of either route.
37
38The scalar profile admits unsigned shifts only when the count is a literal
39or resolved scalar constant below the operand's width. Dynamic, negative,
40boolean, signed-operand and out-of-width shifts remain refused across the
41whole unit, including unused helpers. Count validation precedes emission;
42the generated C uses unsigned operations, masking left-shift results to
43the source width. `tests/freest.py` compares accepted shifts against the
44pinned seed and challenges the result with a wrong-direction mutant.
45
46Convert and run an example:
47
48```sh
49tools/bridge c tests/fixtures/fib.om > build/fib.c
50gcc -std=gnu11 -O2 build/fib.c -o build/fib
51build/fib
52tools/bridge python tests/fixtures/fib.om > build/fib.py
53python3 build/fib.py
54```
55
56Output goes to stdout only after the complete conversion succeeds. Source validation is mandatory. Conversion creates isolated temporary build files and never installs or replaces an application. Inspect generated output before opting to link or import it.
57
58Run real C and Python application callers:
59
60```sh
61quiet-build python3 tests/attachments.py
62```
63
64See [supported features and limits](docs/CAPABILITIES.md), [caller ABI and ownership](docs/ABI.md), [design and study decisions](docs/DESIGN.md), and [provenance](docs/PROVENANCE.md). Heap operations and other target languages are explicitly unsupported by the C/Python converters. Read-only text constants convert exactly in the baseline `tools/bridge c|python` ([text conversion](docs/TEXT-CONVERSION.md), checked by `tests/text.py`); inline text literals stay refused. The additive seeded C frontend supports f32/f64 scalars, constants, arithmetic and fsqrt, public float scalars and ushort/uint/f32 views and arrays (`tools/bridge-seeded c|h`, checked by `tests/seeded_float.py` and `tests/seeded_views.py`). The native `tools/native --float` profile also exposes typed scalar floats in C, Python, Rust, Zig and Go (`tests/native/float.py`); its compiler pin is separate from the baseline. GPU interoperability is a separate, opt-in adapter boundary (it converts no host program): see [GPU adapter](docs/GPU-ADAPTER.md) and the [support matrix](docs/GPU-SUPPORT-MATRIX.md). Python/C input conversion is not implemented. The Python test harness is infrastructure; all conversion logic and both runtime emitters are in [src/toc.om](src/toc.om).
65
66C shared libraries: `tools/bridge-seeded lib-c|lib-h|lib-map unit.om` (cabi-1) lowers one seeded Omega unit with `note cabi` declarations into library C, a public header and a version script, with lock-wrapped exports that publish outputs only after bounds checks and a provenance trailer `build/bridge` re-verifies. Checked by the seeded gate `tests/cabi/gate.om`; see [C ABI library mode](docs/CAPABILITIES.md#c-abi-library-mode-cabi-1-omega-bridge83).
67
68PyTorch: `torch.compile(model, backend="omega")` runs a small set of float32 core-ATen ops (mm, addmm, 2-D transpose, add, relu, softmax) on CPU through Omega-generated AArch64 kernels called via the native call ABI, and refuses everything else. The Python under `pytorch/omega_torch/` is interim glue that computes no tensor value. Exercised on CPU against PyTorch eager only; see [docs/OMEGA-TORCH.md](docs/OMEGA-TORCH.md).
69
70DeepInfer (deepseek-ai/DeepInfer) is a proposed translation and attachment target; its inventory, measured import coverage and extension plan are in [DeepInfer as a bridge target](docs/DEEPINFER.md).
71
72Call compiled Omega in place from six languages (the native call adapter, a separate claim from conversion: it runs Omega's own machine code, it does not turn Omega into another language):
73
74```sh
75OMEGA_NATIVE_OMC=<seeded omc> tools/native build/native tests/native/madd.om
76```
77
78That writes `libomega_native.so` and, from the same Omega signatures, `omega_native.h` (C and C++), `omega_native.py`, `omega_native.rs`, `omega_native.zig` and `omega_native.go`; a program includes or imports its file and calls `omega_madd`, nothing is declared by hand. One generator, [src/native.om](src/native.om), writes all six. Contract, limits and the qualification run: [native call ABI](docs/NATIVE-ABI.md).
79
80A worked integration: [examples/deepinfer](examples/deepinfer/README.md) replaces DeepInfer's `FlopsEstimator` pair-count helpers with an OM-2 unit called through these bindings, differential-tested against the pinned upstream code.
81
82`f32` and `ushort` array kinds (4-byte and 2-byte elements) are qualified by `OMEGA_NATIVE_OMC=<seeded omc> sh tests/native/kinds.sh`. The contract is in [native call ABI](docs/NATIVE-ABI.md).
83
84`tools/native --host` admits nine OM-2 file/identity words, three clocks and twelve bounded device words with the staged context-format compiler. Select AArch64 Linux by default or x86-64 Linux with `--target x86linux`; each hosted target enforces its own compiler fingerprint. Without the flag every host word is refused. Mapping libraries retain default128-slot exports and add C exports selecting explicit contexts with capacity1..4098. Owned fixed bind replaces only a PROT_NONE reservation. A failed bind retires the token after successful cleanup; cleanup failure quarantines the owned slot until `mapdrop` retries. This is a **draft contract requiring Drake approval before merge**. Compiler custody, generation ownership and destruction rules are in the [native call ABI](docs/NATIVE-ABI.md). `tests/native/v2/dev/run.py` exercises libc ioctl comparisons, shared-memfd publication, fixed-bind/context controls and runtime/compiler mutants on AArch64. `tests/native/x86/device.py` runs the same fixtures under the QEMU10.0.14 oracle and adds x86 syscall and MFENCE controls. Emulation is not native x86 qualification. GPU/chip qualification is NOT_RUN.
85
86The staged AArch64 profile also admits five exact aien-gpu ABI1 ioctl requests,
87not the whole `'A'` family. CPU-only callers use fd-1 and check exact-length
88guards against libc; device, driver and GPU integration remain NOT_RUN.
89This trust-surface draft also requires Drake approval before merge. See the
90exact compiler fingerprint and request list in `docs/NATIVE-ABI.md`.
91
92The native target defaults to `aarch64linux`. Hosted x86-64 SysV Linux bindings
93are selected explicitly; there is no build-host architecture inference:
94
95```sh
96OMEGA_NATIVE_OMC=/path/to/baseline/omc \
97OMEGA_NATIVE_X86_OMC=/path/to/x86/omc \
98CC=x86_64-linux-gnu-gcc \
99tools/native --target x86linux build/native-x86 tests/native/madd.om
100```
101
102The existing pinned `OMEGA_NATIVE_OMC` remains required to build the generator.
103The separately pinned `OMEGA_NATIVE_X86_OMC` compiles both OM-1 and OM-2 inputs;
104its target directive is not added to the source identity. Pins and the exact
105generator contract are in [native call ABI](docs/NATIVE-ABI.md#target-selection-and-compiler-custody).
106`--freestanding` also accepts `--target x86linux` (omega-mv#940). Cross-building a library
107does not execute its callers. QEMU results are emulator evidence, not native
108x86-64 qualification; native execution is NOT_RUN until exercised on an x86-64
109host. The historical AArch64 evidence does not qualify this x86 integration.
110The x86 emulator suite selects its oracle with `QEMU_X86_64`; use the unpatched
111QEMU 10.0.14 oracle and guest Python setup documented in
112[native call ABI](docs/NATIVE-ABI.md#x86-emulator-runner-and-qemu-oracle).
113QEMU 8.2.2 has observed signal and `/proc/self/maps` limitations for these
114callers. At the current x86 compiler pin, the full suite plus mismatched-pin and
115failed/missing-toolchain controls passed EMULATED; see
116[the pinned receipts](evidence/native-x86-be8c5130.json). Earlier
117pins' receipts remain in `evidence/native-x86-62775d2a.json`, `evidence/native-x86-badedbb0/`, `evidence/native-x86-f7752bc5/` and `evidence/native-x86/`. Physical x86
118execution remains NOT_RUN.
119
120## Pending Linux kernel-leaf envelope experiment
121
122[`src/kernel_leaf.om`](src/kernel_leaf.om) emits a fixed-symbol AArch64 assembly
123envelope for the companion restricted `kleaf` compiler experiment. It matches
124the inspected Linux `7.0.0-1019-nvidia` leaf tracing/PAC metadata, not an arbitrary
125kernel ABI. It requires trusted compiler/source custody: framing checks are not
126a general machine-code verifier. It does not implement driver policy, Linux
127effects, a module loader or the userspace native trampoline.
128
129This source-only experiment is not integrated into `tools/native`, does not
130change any compiler fingerprint or production admission path, and is not a
131kernel/GPU qualification claim. The compiler-side
132`seed/omc/kernel-leaf-experiment.py` is its host oracle and exact kbuild-object
133comparison. GNU assembly/object tooling remains a disclosed build dependency.
134
135## Framework attachments
136
137| Framework | Attachment | Scope (receipt) |
138|---|---|---|
139| llama.cpp / ggml | [aien-dev/ggml-omega](https://github.com/aien-dev/ggml-omega), an out-of-tree ggml backend built on `src/native.om` | host device (draft ggml-omega#1): 16 ops on Omega CPU code; opt-in `OmegaGB10` device (draft ggml-omega#2): MUL_MAT, RMS_NORM, swiglu on the GB10 through CUDA++ (CUDApp#139 `gemm_ex`), every other op on ggml's CPU backend; test-backend-ops against the CPU backend on the chip, MUL_MAT 871 / RMS_NORM 7 / SWIGLU 12 cases OK, 0 FAIL |
140| PyTorch | [attach/torch](attach/torch/cudapp_torch.py): `torch.library` ops `cudapp::mm` (f32, bf16, f16) and `cudapp::swiglu` (f32) calling CUDA++ (`omega_gpu_gemm_ex`, `omega_gpu_swiglu_f32`) on the GB10 | CPU tensors in and out (staged to the chip per call), no autograd; checked against torch CPU plus `torch.library.opcheck` and a mutant (`attach/torch/test_cudapp_torch.py`); receipt `evidence/attach-gb10-20261027T0726Z/`, EXERCISED on a single GB10 |
141
142`attach/torch` is migration-pending host glue (`ctypes` at the torch ABI surface, switch `MIGRATION_PENDING`); its named successor is the `omega_native.py` binding that `tools/native` writes (the `python` word of `src/native.om`) once CUDA++ entries are callable as Omega units. Neither attachment has run a model on the GB10 yet: that needs an exclusive GPU window.
143
144## Human-Directed Agentic Engineering
145
146Development follows Human-Directed Agentic Engineering (HDAE): humans define goals, architecture, constraints, acceptance criteria, and stopping points; agents implement, execute checks, diagnose failures, and revise within those boundaries. Human review retains responsibility for claims, acceptance, and release decisions.
147
148For the documented method and a systems-software case study, see Gregory M. Kurtzer, [*Ginux: Building an Independent Kernel That Runs Linux Userspace through Human-Directed Agentic Engineering* (2026)](https://doi.org/10.5281/zenodo.23682548). This method citation does not widen the checked conversion subset or replace independent review.
149
150## License
151
152First-party material is licensed under the Apache License, Version 2.0 with LLVM
153Exceptions (`Apache-2.0 WITH LLVM-exception`). See [LICENSE](LICENSE) and
154[NOTICE](NOTICE). The LLVM exception permits compiled object code derived from
155this software to be redistributed under terms of the recipient's choosing.
156Third-party components keep their own notices.