interplane.Get Omega
Read in your language

ggml-omega

aien-dev/ggml-omega

Brought by drakestapleton

branch main Branches Tags History

ggml-omega / README.md

132 lines · 8303 bytes Raw Blame History Rendered
1# ggml-omega
2
3A [ggml](https://github.com/ggml-org/llama.cpp/tree/master/ggml) backend whose op kernels are seeded-Omega units.
4llama.cpp loads it as an out-of-tree backend (`GGML_BACKEND_PATH=libggml-omega.so`); the ops it takes run in
5Omega-compiled code, every other op falls back to ggml's CPU backend. One job: run ggml ops through Omega.
6
7| Op | Omega kernels (`kernels/`) | Scope |
8|---|---|---|
9| MUL_MAT | `df32`, `dh16`, `dq8`, `dq8r` (row dots, f64 accumulation) | weights f32, f16, q8_0; activations f32 |
10| ADD SUB MUL DIV | `bin` | f32, row-level broadcast |
11| RMS_NORM, SCALE | `sq`, `rmsc`, `scl` | f32 rows |
12| SOFT_MAX | `smw`, `smwh`, `vmax`, `sexp`, `rcp` | f32, optional f32/f16 mask, no ALiBi bias, no sinks |
13| ROPE | `rtsc`, `rope` (own sin/cos/exp/log in `math.om`) | NORMAL and NEOX, no YaRN ramp, no freq factors |
14| GET_ROWS, SET_ROWS, CPY/CONT/DUP | `cpy`, `cpyh`, `h2fv`, `f2hv` | f32 and f16 (f16 rounding done in Omega) |
15| GLU (swiglu), UNARY (silu) | `swi`, `silu` | f32 |
16
17`ggml-omega.c` is **interim host glue**: tensor addressing, loops, thread split, staging copies and bit moves
18only; every arithmetic step and conversion is Omega. Its successor is an `.om` loadable object once the Omega
19native object ABI exists (aien-dev/omega-mv #636/#637).
20
21## OmegaGB10 device (opt-in)
22
23Built with `OMEGA_GGML_GB10=1 CUDAPP_SRC=<CUDApp src> CUDAPP_LIB=<CUDApp build-pic/libomega_gpu.a>` and selected at
24run time with `OMEGA_GGML_DEVICES=gb10` (or `host,gb10`; default `host`), a second device runs three ops on the
25NVIDIA GB10 through CUDA++ (aien-dev/CUDApp) runtime calls whose kernels come from Omega's own code generator:
26
27| Op | Chip call | Scope |
28|---|---|---|
29| MUL_MAT | `omega_gpu_gemm_ex` (CUDApp `gemm_ex`, aien-dev/CUDApp#139); shapes, leading dimensions and batch strides planned by the Omega unit `kernels/gbmm.om` | weights f32, f16, bf16, or q8_0 dequantised by the Omega unit `dq8r`; activations f32, so every call takes the bf16x3 route (HMMA.BF16, fp32 accumulation; not exact fp32) |
30| RMS_NORM | `omega_gpu_rmsnorm_f32` | f32 rows, row length a multiple of 128, at most 16384 |
31| GLU swiglu | `omega_gpu_swiglu_f32` | f32 |
32
33Every other op falls back to ggml's CPU backend. `ggml-omega-gb10.c` is interim host glue like `ggml-omega.c`
34(same successor). Receipt, 2026-10-27 on the Spark GB10 beside the resident server
35([evidence/gb10-20261027T0726Z](evidence/gb10-20261027T0726Z)): `test-backend-ops -b OmegaGB10` against the CPU
36backend, MUL_MAT 871 cases OK / 0 FAIL, RMS_NORM 7 / 0, SWIGLU 12 / 0; a mutant `gbmm.om` (`OMEGA_GGML_MUTANT=gbmm-k`)
37fails 385 MUL_MAT cases. This is op-level EXERCISED on one chip, not a qualification. NOT_RUN: any model on the
38GB10 device (`tests/e2e-gb10.sh`, CPU vs OmegaGB10 token and logit match) waits for an exclusive GPU window; CI
39has no GB10 and builds the host device only.
40
41Follow-up on this experimental branch, 2026-10-29: the exclusive model window was
42authorized and exercised. Qwen2.5-0.5B Q8 and Qwen3.5-9B BF16/Q8 each matched the
43CPU reference's greedy tokens for the fixed prompt over 16 steps. The Q35 runs
44recorded nonzero MUL_MAT, RMS_NORM and SWIGLU calls and an after-inference library
45snapshot without the forbidden NVIDIA user-space libraries. Logits are not
46numerically identical; this is a bounded model check, not full chat-corpus or
47performance qualification. The source and file hashes, exclusions and raw-result
48locations are in `evidence/gb10-model-20261029.json`.
49
50The model comparison now fails for empty output, partial rows, nonfinite scores,
51wrong step counts or a changed greedy token. `e2e-gb10.sh` also requires executed
52operations and the inference library snapshot. Its comparator status reaches the
53caller without a `tee` pipeline hiding a failure. Existing result files are
54preserved; reruns need a fresh output directory.
55
56## Build and test
57
58```sh
59OMEGA_GGML_OMC=<omega-mv seed/out/omc> OMEGA_GGML_BIND_OMC=<baseline omc> OMEGA_BRIDGE=<omega-bridge checkout> \
60GGML_SRC=<llama.cpp checkout> GGML_LIB=<llama.cpp build/bin> ./build.sh
61tests/backend-ops.sh <build/bin/test-backend-ops> build/libggml-omega.so [mutant .so]
62cc -std=gnu11 -O2 -Wall -Wextra -Werror -o build/cmp tests/cmp.c -lm
63node tests/test-cmp.mjs build/cmp
64node tests/test-e2e-gb10.mjs
65```
66
67The two Node scripts are verification-only failure controls, tested with Node
68v24.21.0; they do not add a model-serving or production dependency. The full model
69driver remains shell/C and uses the pinned llama.cpp build.
70
71The shared library exports only `ggml_backend_init`. Its Omega kernels, CUDApp
72entries and hashing helpers are private to the backend. This prevents a host
73library such as llama.cpp's `libmtmd` from replacing a same-named helper with an
74incompatible signature. `sh tests/exports.sh build/libggml-omega.so` checks this
75boundary. A full-server startup exposed this collision after the bounded model
76tests passed; those earlier tests did not load `libmtmd`.
77
78Pins (checked by `build.sh`, refuses on mismatch): omc sha256 `2c824805…` (aien-dev/omega-mv `e5b32567`),
79omega-bridge `src/native.om` sha256 `e2077722…` (omega-bridge `d8174edd`), binding compiler sha256 `734f0a39…`, llama.cpp `7aca0d2e`.
80`.github/workflows/ci.yml` runs the whole chain on `ubuntu-24.04-arm`: kernels vs libm and `_Float16`,
81`test-backend-ops` per op against the CPU backend, an `add -> sub` mutant that must fail, and a Qwen2.5-0.5B
82q8_0 end-to-end greedy decode, CPU vs Omega (top-1 agreement, max abs logit difference, timing).
83
84## Connected repos
85
86- Parent: [aien-dev/omega-bridge](https://github.com/aien-dev/omega-bridge) supplies the native call ABI binding
87 generator (`src/native.om`, f32/ushort kinds from omega-bridge PR #26), pinned by sha256.
88- Compiler: [aien-dev/omega-mv](https://github.com/aien-dev/omega-mv) `seed/out/omc`, pinned by sha256.
89- Host: [ggml-org/llama.cpp](https://github.com/ggml-org/llama.cpp), pinned by commit; nothing here is upstreamed.
90
91## License
92
93Apache-2.0 WITH LLVM-exception, see [LICENSE](LICENSE).
94
95## Human-Directed Agentic Engineering
96
97Development follows Human-Directed Agentic Engineering (HDAE): humans define goals,
98architecture, constraints, acceptance criteria, and stopping points; agents implement,
99execute checks, diagnose failures, and revise within those boundaries. Human review
100retains responsibility for claims, acceptance, and release decisions.
101
102For the documented method and a systems-software case study, see Gregory M. Kurtzer,
103[*Ginux: Building an Independent Kernel That Runs Linux Userspace through
104Human-Directed Agentic Engineering* (2026)](https://doi.org/10.5281/zenodo.23682548).
105
106## macOS ARM64 preparation and build
107
108The current native bridge emits both ELF and Mach-O compatible AArch64 bindings.
109The model kernels are still compiled by the original pinned Omega compiler.
110The separate pinned baseline compiler builds the newer binding generator.
111
112On Linux ARM64, set both compiler paths and `OMEGA_BRIDGE`, then run
113`OMEGA_GGML_STAGE=prepare OMEGA_GGML_OUT=/path/to/prepared ./build.sh`.
114Copy the complete prepared directory to the Mac. On the Mac, set `GGML_SRC` to
115the exact pinned llama.cpp checkout and `GGML_LIB` to its matching macOS release
116libraries, then run
117`OMEGA_GGML_STAGE=compile OMEGA_GGML_OUT=/path/to/prepared ./build.sh`.
118The compile phase verifies the recorded file hashes, compiler/source pins, and
119backend source identity. These are integrity checks on an operator-owned build
120artifact, not a signature or permission to accept an untrusted bundle.
121
122The matching upstream macOS ARM64 runtime release is llama.cpp `b11913`.
123Only the small backend is compiled on the Mac; no full llama.cpp build is needed.
124Run `tests/exports.sh prepared/libggml-omega.dylib` and the kernel/model checks
125before using it. Set `GGML_BACKEND_PATH` to the absolute dylib path.
126
127A model can mix supported Omega operations and ordinary CPU operations.
128Selecting `--device Omega -ngl 99` requests full eligible layer offload, but the
129scalar Omega matrix kernels are substantially slower than optimized CPU kernels.
130No Apple GPU acceleration is implemented by this backend. A loaded backend alone
131is not execution evidence: use an executed-kernel negative control and a model
132comparison. The existing `bin-add` mutant supplies that control.