Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/seed/nki/oracle.py # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / seed / nki / oracle.py` 134 lines ยท 5483 bytes Raw Blame History 1 # SPDX-License-Identifier: Apache-2.0 2 # interop oracle, not Omega-native; never generates kernels. 3 # 4 # Host dependency (oracle only): CPython 3.12 + nki 0.7.0 (Apache-2.0, AWS) + numpy 2.2.6. 5 # Omega replacement: none yet. The kernels come from seed/nki/irnki.om; the expected 6 # values come from a native Omega program built by gate-irnki.sh. This script only 7 # (1) writes deterministic input lanes and (2) runs the emitted kernels on the public 8 # NKI CPU simulator (nki.simulate) and compares the result bits with the Omega values. 9 # 10 # oracle.py version 11 # oracle.py inputs uint32|float32 > in.bin a lanes then b lanes, little-endian 12 # oracle.py check kernels.py in.bin refdir name... exit 0 all equal, 1 any differ 13 # oracle.py limit kernels.py name exit 0 if a (128, 500) call is refused 14 import importlib.util 15 import os 16 import sys 17 18 ROWS, COLS = 256, 1024 19 N = ROWS * COLS 20 21 22 def die(msg, code): 23 sys.stderr.write("oracle: " + msg + "\n") 24 sys.exit(code) 25 26 27 try: 28 import numpy as np 29 import nki 30 except Exception as ex: # the gate maps exit 3 to NOT_RUN 31 die("cannot import the simulator: %s: %s" % (type(ex).__name__, ex), 3) 32 33 34 def load(path): 35 spec = importlib.util.spec_from_file_location("omnki", path) 36 mod = importlib.util.module_from_spec(spec) 37 spec.loader.exec_module(mod) 38 return mod.KERNELS 39 40 41 def inputs(dtype): 42 rng = np.random.default_rng(`20261026`) 43 a = rng.integers(0, 2 ** 32, N, dtype=np.uint64).astype(np.uint32) 44 b = rng.integers(0, 2 ** 32, N, dtype=np.uint64).astype(np.uint32) 45 if dtype == "uint32": 46 edge = [0, 1, 2, 0x7FFFFFFF, 0x80000000, 0x80000001, 0xFFFF, 0x10000, 0xFFFFFFFE, 0xFFFFFFFF] 47 elif dtype == "float32": 48 # +0 -0 +inf -inf qNaN max -max min-normal smallest/largest subnormal 1 -1 1+ulp 2^24 49 edge = [0x00000000, 0x80000000, 0x7F800000, 0xFF800000, 0x7FC00000, 0x7F7FFFFF, 50 0xFF7FFFFF, 0x00800000, 0x00000001, 0x007FFFFF, 0x3F800000, 0xBF800000, 51 0x3F800001, 0x4B800000] 52 # the rest: half raw bit patterns (all exponents), half normal values near 1 53 k = N // 2 54 a[k:] = rng.standard_normal(N - k).astype(np.float32).view(np.uint32) 55 b[k:] = rng.standard_normal(N - k).astype(np.float32).view(np.uint32) 56 else: 57 die("inputs: dtype must be uint32 or float32", 2) 58 e = np.array(edge, dtype=np.uint32) 59 m = len(edge) 60 a[: m * m] = np.repeat(e, m) 61 b[: m * m] = np.tile(e, m) 62 sys.stdout.buffer.write(a.astype("= 6 and argv[1] == "check": 126 check(argv[2], argv[3], argv[4], argv[5:]) 127 elif len(argv) == 4 and argv[1] == "limit": 128 limit(argv[2], argv[3]) 129 else: 130 die("usage: see header", 2) 131 132 133 if __name__ == "__main__": 134 main(sys.argv)