interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / seed / nki / README.md

162 lines · 8973 bytes Raw Blame History Rendered
1# seed/nki: Omega to AWS Trainium / Inferentia (NKI)
2
3`irnki.om` is a handwritten, seeded-Omega emitter. It reads an OSC IR v1 unit
4(`spec/one-layer-format.md`) and writes an NKI kernel module in Python at the `nki.isa`
5(NISA) level. NISA is the lowest level AWS documents publicly. The first kernel is
6vecadd: `out[i] = a[i] + b[i]`.
7
8Status, 2026-10-26:
9
10| Item | Status |
11|---|---|
12| Emitter `irnki.om` | IMPLEMENTED |
13| Kernels on the NKI CPU simulator, targets trn1, trn2, trn3 | EXERCISED-on-oracle (interop oracle, not Omega-native) |
14| Trainium or Inferentia hardware | NOT_RUN |
15
16## What it emits
17
18Each function becomes one `@nki.jit` kernel. The kernel loops over tiles of
19128 partitions x 512 elements (`nl.affine_range`) and keeps three explicit SBUF tiles per
20step, `ta`, `tb` and `tc`. It moves data with `nisa.dma_copy` (HBM to SBUF and back) and
21computes one `nisa.tensor_tensor(dst=tc, data1=, data2=, op=nl.<op>)`. The module ends
22with `KERNELS = {name: (kernel, dtype)}`.
23
24The emitter lifts only this shape:
25
26- two parameters and a result, all u32 (tag 4), and three vregs;
27- one block of two instructions: `BIN sub dst=2 a b` (a and b are params 0 or 1), then `RET 2`.
28
29The supported subcodes are add, sub, mul, and, or and xor, mapped to `nl.add`,
30`subtract`, `multiply`, `bitwise_and`, `bitwise_or` and `bitwise_xor`. These are refused:
31
32| Input | Exit and message |
33|---|---|
34| div, rem, shl, shr | 24 UNSUPPORTED_OP. Omega traps on these and NKI has no trap. |
35| Any tag other than u32 | 25 UNSUPPORTED_TAG |
36| Any other function shape | 29 NOT_ELEMENTWISE |
37| Bad bytes | 20–28, as in irwasm |
38| Bad arguments | 30 USAGE |
39
40Every refusal happens before the first stdout byte.
41
42`irnki f32` retypes the lanes to float32 and then allows only add, sub and mul. This
43retyping is explicit and documented. It exists because IR v1 cannot carry floats: the
44compiler refuses float words in `ir` mode with error 16, and the float tags in spec
45section 10.3 are not produced yet. The f32 vecadd is therefore the u32 unit
46`vecadd.unit.om` with float32 lanes. The gate computes the f32 reference from the same
47unit with `uint` read as `f32`.
48
49Shape limits: the kernels take 2-D arrays whose rows are a multiple of 128 and whose
50columns are a multiple of 512. Any other shape is refused by an assertion, and the gate
51checks that (128, 500) is refused. Three f32 tiles take 6144 bytes per partition, which
52is 1/32 of the 192 KiB trn1 SBUF partition (224 KiB on trn2, 256 KiB on trn3). Computed
53with WolframLanguageEvaluator: `3*512*4 -> 6144`, `3*512*4/(192*1024) -> 0.03125`.
54
55## Run
56
57```sh
58seed/nki/setup-oracle.sh /tmp/nki-oracle # pinned downloads, user files only
59NKI_ORACLE_DIR=/tmp/nki-oracle nice -n 19 seed/nki/gate-irnki.sh
60```
61
62Exit codes: 0 PASS, 1 FAIL, 3 NOT_RUN (no oracle directory, the oracle does not start,
63the oracle version differs from the pin, or the host is not AArch64). Artifacts go to
64`build/seed/nki/`, and `gate.log` holds SOURCE, COMPILER, ORACLE and PLATFORM.
65
66The gate does the following:
67
681. Builds `irnki` with the pinned `seed/out/omc` (sha256 `2c824805…029f`).
692. Lifts `vecadd.unit.om` (f32 and u32) and `ops.unit.om` (8 functions: every op,
70 swapped operands `sub b a`, and repeated operands `add a a`). Each module is emitted
71 twice and compared with `cmp`.
723. Computes the expected lanes with a native AArch64 Omega program for each function,
73 built from the same unit source plus a driver. No foreign code computes expected
74 values.
754. Runs every kernel in `nki.simulate` for trn1, trn2 and trn3 on 262144 lanes, shaped
76 (256, 1024), which is 4 tiles. The input set includes all pairs of edge values: 100
77 for u32, and 196 for f32, covering ±0, ±inf, NaN, ±max, min-normal, subnormals and
78 1+ulp. Results are compared bit for bit, except that two NaNs count as equal, because
79 NaN sign and payload are not part of the IEEE result.
805. Negative controls, each of which must FAIL:
81 - an emitted `nl.add` edited to `nl.subtract`;
82 - the IR BIN subcode byte changed from add to sub before lifting;
83 - one expected bit flipped;
84 - a kernel dropped from `KERNELS`.
856. Checks 14 refusals: exact exit code, the message on stderr and empty stdout.
86
87Measured 2026-10-26 on the DGX Spark: PASS, with 30 of 30 kernel/target runs equal and
88every control rejected. The same result came from a directory freshly prepared by
89`setup-oracle.sh`.
90
91## Oracle stack (interop oracle, not Omega-native; never generates kernels)
92
93The nki wheel is published for x86_64 only, so on AArch64 it runs as x86_64 CPython
94under qemu-user. Every item is a host dependency of the oracle only.
95
96| Item | Version | Licence | sha256 |
97|---|---|---|---|
98| nki (from `pip.repos.neuron.amazonaws.com`) | 0.7.0+37713544100.gfede04bb, cp312 linux_x86_64 | Apache-2.0 | `03543bed…0c4e` |
99| numpy | 2.2.6 | BSD-3-Clause | `fd83c012…6249` |
100| ml_dtypes | 0.5.3 | Apache-2.0 | `1b255aca…9e55` |
101| typing_extensions | 4.15.0 | PSF-2.0 | `f0fa19c6…e548` |
102| CPython (python-build-standalone 20261026) | 3.12.16 x86_64 | PSF-2.0 | `6a79e922…9de` |
103| qemu-user (Debian trixie) | 10.0.13+ds-0+deb13u1 arm64 | GPL-2.0 | `c73711af…158d` |
104| libc6, libgcc-s1, libstdc++6, zlib1g (Ubuntu noble amd64) | see `setup-oracle.sh` | LGPL-2.1 / GPL-3 with runtime exception / zlib | see `setup-oracle.sh` |
105
106`setup-oracle.sh` holds the full pins. The host qemu 8.2.2 crashes (internal SIGSEGV)
107when Python reads `/proc/self/maps`, which is why the Debian 10.0.13 static build is used.
108
109`oracle.py` is the only foreign code. It writes the deterministic inputs, runs the
110emitted kernels and compares bits. It never writes a kernel or an expected value.
111There is no Omega replacement yet: it needs an Omega reader for the NKI simulator, or
112an Omega NISA interpreter.
113
114## How open the stack is (primary sources, read 2026-10-26)
115
116- The NKI programming interface (`nki.language`, `nki.isa`) and the CPU simulator ship in
117 the `nki` wheel under Apache-2.0. Wheels exist for x86_64 only.
118 https://awsdocs-neuron.readthedocs-hosted.com/en/latest/nki/get-started/about/index.html,
119 https://awsdocs-neuron.readthedocs-hosted.com/en/latest/nki/guides/nki_simulator.html
120- The NKI compiler (MLIR based) is announced as open source but is a private beta. The
121 wheel's project URL `github.com/aws-neuron/private-nki-staging` is not public, and
122 `github.com/aws-neuron/nki` returns 404. The NKI IR and its MLIR dialect ship only as
123 compiled binaries and are not documented.
124 https://aws.amazon.com/about-aws/whats-new/2025/12/announcement-aws-neuron-2-27/,
125 https://awsdocs-neuron.readthedocs-hosted.com/en/latest/nki/deep-dives/nki-compiler.html
126- The lowest documented level is therefore `nki.isa`, one call per engine instruction.
127 Below it, NEFF and the engine binary encodings are not public.
128- `neuronx-cc` 2.28.7631.0 (wheel METADATA and LICENSE.txt, read without installing) is
129 under the "AWS Neuron Software License Agreement". That agreement grants use only "in
130 connection with AWS Services" and requires an AWS account in good standing. The gate
131 does not use it.
132- nki-samples is MIT-0; nki-library and nkipy are Apache-2.0; aws-neuron-driver is
133 GPL-2.0. https://awsdocs-neuron.readthedocs-hosted.com/en/latest/about-neuron/oss/index.html
134- Architecture figures (SBUF 24/28/32 MiB = 128 partitions of 192/224/256 KiB; PSUM
135 2 MiB) come from
136 https://awsdocs-neuron.readthedocs-hosted.com/en/latest/nki/guides/architecture/trainium_inferentia2_arch.html,
137 `trainium2_arch.html` and `trainium3_arch.html`.
138
139## What is NOT established
140
141- No hardware run. The simulator is AWS's functional model; it is not the chip. Engine
142 choice, timing, subnormal flushing and NaN payloads on Trainium/Inferentia are not
143 measured. The simulator runs with its default `NKI_PRECISE_FP=1`.
144- Kernels are not compiled by `neuronx-cc`, and no NEFF exists.
145- Only single-op elementwise u32 units are covered, plus the f32 retyping. There are no
146 reductions, no matmul (TensorE/PSUM), no broadcasting and no ragged shapes.
147
148## Path to hardware (NOT_RUN)
149
1501. An AWS account and a Neuron instance: inf2.xlarge or trn1.2xlarge (NeuronCore-v2),
151 trn2 (v3) or trn3 (v4), with the Neuron DLAMI or the driver, runtime and `neuronx-cc`
152 from the Neuron setup guide.
153 https://awsdocs-neuron.readthedocs-hosted.com/en/latest/setup/index.html
1542. Run the same emitted module with `@nki.jit` on NumPy arrays (it compiles through
155 `neuronx-cc` and runs on the NeuronDevice), and compare the lanes with the same
156 native Omega references used here.
1573. Record the instance type, Neuron SDK versions and the NEFF sha256 in a receipt. Only
158 that receipt can move the status past EXERCISED-on-oracle.
159
160The next kernel is matmul: `nisa.nc_matmul` with a 128x128 stationary tile and a 128x512
161moving tile accumulating in PSUM, then `nisa.tensor_copy` PSUM to SBUF and `dma_copy` out,
162checked on the same simulator against a native Omega reference.