ggml-omega
aien-dev/ggml-omega
Brought by drakestapleton
ggml-omega / README.md
| 1 | # ggml-omega |
| 2 | |
| 3 | A [ggml](https://github.com/ggml-org/llama.cpp/tree/master/ggml) backend whose op kernels are seeded-Omega units. |
| 4 | llama.cpp loads it as an out-of-tree backend (`GGML_BACKEND_PATH=libggml-omega.so`); the ops it takes run in |
| 5 | Omega-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 |
| 18 | only; every arithmetic step and conversion is Omega. Its successor is an `.om` loadable object once the Omega |
| 19 | native object ABI exists (aien-dev/omega-mv #636/#637). |
| 20 | |
| 21 | ## OmegaGB10 device (opt-in) |
| 22 | |
| 23 | Built with `OMEGA_GGML_GB10=1 CUDAPP_SRC=<CUDApp src> CUDAPP_LIB=<CUDApp build-pic/libomega_gpu.a>` and selected at |
| 24 | run time with `OMEGA_GGML_DEVICES=gb10` (or `host,gb10`; default `host`), a second device runs three ops on the |
| 25 | NVIDIA 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 | |
| 33 | Every 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 |
| 36 | backend, MUL_MAT 871 cases OK / 0 FAIL, RMS_NORM 7 / 0, SWIGLU 12 / 0; a mutant `gbmm.om` (`OMEGA_GGML_MUTANT=gbmm-k`) |
| 37 | fails 385 MUL_MAT cases. This is op-level EXERCISED on one chip, not a qualification. NOT_RUN: any model on the |
| 38 | GB10 device (`tests/e2e-gb10.sh`, CPU vs OmegaGB10 token and logit match) waits for an exclusive GPU window; CI |
| 39 | has no GB10 and builds the host device only. |
| 40 | |
| 41 | Follow-up on this experimental branch, 2026-10-29: the exclusive model window was |
| 42 | authorized and exercised. Qwen2.5-0.5B Q8 and Qwen3.5-9B BF16/Q8 each matched the |
| 43 | CPU reference's greedy tokens for the fixed prompt over 16 steps. The Q35 runs |
| 44 | recorded nonzero MUL_MAT, RMS_NORM and SWIGLU calls and an after-inference library |
| 45 | snapshot without the forbidden NVIDIA user-space libraries. Logits are not |
| 46 | numerically identical; this is a bounded model check, not full chat-corpus or |
| 47 | performance qualification. The source and file hashes, exclusions and raw-result |
| 48 | locations are in `evidence/gb10-model-20261029.json`. |
| 49 | |
| 50 | The model comparison now fails for empty output, partial rows, nonfinite scores, |
| 51 | wrong step counts or a changed greedy token. `e2e-gb10.sh` also requires executed |
| 52 | operations and the inference library snapshot. Its comparator status reaches the |
| 53 | caller without a `tee` pipeline hiding a failure. Existing result files are |
| 54 | preserved; reruns need a fresh output directory. |
| 55 | |
| 56 | ## Build and test |
| 57 | |
| 58 | ```sh |
| 59 | OMEGA_GGML_OMC=<omega-mv seed/out/omc> OMEGA_GGML_BIND_OMC=<baseline omc> OMEGA_BRIDGE=<omega-bridge checkout> \ |
| 60 | GGML_SRC=<llama.cpp checkout> GGML_LIB=<llama.cpp build/bin> ./build.sh |
| 61 | tests/backend-ops.sh <build/bin/test-backend-ops> build/libggml-omega.so [mutant .so] |
| 62 | cc -std=gnu11 -O2 -Wall -Wextra -Werror -o build/cmp tests/cmp.c -lm |
| 63 | node tests/test-cmp.mjs build/cmp |
| 64 | node tests/test-e2e-gb10.mjs |
| 65 | ``` |
| 66 | |
| 67 | The two Node scripts are verification-only failure controls, tested with Node |
| 68 | v24.21.0; they do not add a model-serving or production dependency. The full model |
| 69 | driver remains shell/C and uses the pinned llama.cpp build. |
| 70 | |
| 71 | The shared library exports only `ggml_backend_init`. Its Omega kernels, CUDApp |
| 72 | entries and hashing helpers are private to the backend. This prevents a host |
| 73 | library such as llama.cpp's `libmtmd` from replacing a same-named helper with an |
| 74 | incompatible signature. `sh tests/exports.sh build/libggml-omega.so` checks this |
| 75 | boundary. A full-server startup exposed this collision after the bounded model |
| 76 | tests passed; those earlier tests did not load `libmtmd`. |
| 77 | |
| 78 | Pins (checked by `build.sh`, refuses on mismatch): omc sha256 `2c824805…` (aien-dev/omega-mv `e5b32567`), |
| 79 | omega-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 |
| 82 | q8_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 | |
| 93 | Apache-2.0 WITH LLVM-exception, see [LICENSE](LICENSE). |
| 94 | |
| 95 | ## Human-Directed Agentic Engineering |
| 96 | |
| 97 | Development follows Human-Directed Agentic Engineering (HDAE): humans define goals, |
| 98 | architecture, constraints, acceptance criteria, and stopping points; agents implement, |
| 99 | execute checks, diagnose failures, and revise within those boundaries. Human review |
| 100 | retains responsibility for claims, acceptance, and release decisions. |
| 101 | |
| 102 | For the documented method and a systems-software case study, see Gregory M. Kurtzer, |
| 103 | [*Ginux: Building an Independent Kernel That Runs Linux Userspace through |
| 104 | Human-Directed Agentic Engineering* (2026)](https://doi.org/10.5281/zenodo.23682548). |
| 105 | |
| 106 | ## macOS ARM64 preparation and build |
| 107 | |
| 108 | The current native bridge emits both ELF and Mach-O compatible AArch64 bindings. |
| 109 | The model kernels are still compiled by the original pinned Omega compiler. |
| 110 | The separate pinned baseline compiler builds the newer binding generator. |
| 111 | |
| 112 | On Linux ARM64, set both compiler paths and `OMEGA_BRIDGE`, then run |
| 113 | `OMEGA_GGML_STAGE=prepare OMEGA_GGML_OUT=/path/to/prepared ./build.sh`. |
| 114 | Copy the complete prepared directory to the Mac. On the Mac, set `GGML_SRC` to |
| 115 | the exact pinned llama.cpp checkout and `GGML_LIB` to its matching macOS release |
| 116 | libraries, then run |
| 117 | `OMEGA_GGML_STAGE=compile OMEGA_GGML_OUT=/path/to/prepared ./build.sh`. |
| 118 | The compile phase verifies the recorded file hashes, compiler/source pins, and |
| 119 | backend source identity. These are integrity checks on an operator-owned build |
| 120 | artifact, not a signature or permission to accept an untrusted bundle. |
| 121 | |
| 122 | The matching upstream macOS ARM64 runtime release is llama.cpp `b11913`. |
| 123 | Only the small backend is compiled on the Mac; no full llama.cpp build is needed. |
| 124 | Run `tests/exports.sh prepared/libggml-omega.dylib` and the kernel/model checks |
| 125 | before using it. Set `GGML_BACKEND_PATH` to the absolute dylib path. |
| 126 | |
| 127 | A model can mix supported Omega operations and ordinary CPU operations. |
| 128 | Selecting `--device Omega -ngl 99` requests full eligible layer offload, but the |
| 129 | scalar Omega matrix kernels are substantially slower than optimized CPU kernels. |
| 130 | No Apple GPU acceleration is implemented by this backend. A loaded backend alone |
| 131 | is not execution evidence: use an executed-kernel negative control and a model |
| 132 | comparison. The existing `bin-add` mutant supplies that control. |