interplane.Get Omega
Read in your language

aien-sovereign-core-mv

AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.

Brought by drakestapleton

branch main Branches Tags History

aien-sovereign-core-mv / om / ribbon / check_overlap.py

82 lines · 3054 bytes Raw Blame History
1#!/usr/bin/env python3
2# SPDX-License-Identifier: Apache-2.0
3"""Discrete-event test instrument for the actual compiled Omega controller.
4
5Ticks are synthetic. These results assert scheduling, never hardware speed.
6"""
7import ctypes as c
8import importlib.util
9from pathlib import Path
10import sys
11
12spec = importlib.util.spec_from_file_location('native', Path(sys.argv[1]) / 'omega_native.py')
13native = importlib.util.module_from_spec(spec)
14spec.loader.exec_module(native)
15
16
17def simulate(buffers, read_ticks, compute_ticks, shared_engine=False):
18 state = (c.c_uint64 * 4096)()
19 now = 0
20 shared_free = 0
21 reads = []
22 compute = None
23 completed = 0
24
25 def call(op, key=0, size=0, deadline=0, ok=0):
26 q = (c.c_uint64 * 8)(op, key, size, deadline, ok, 0, now, 0)
27 out = (c.c_uint64 * 8)()
28 result = c.c_uint64()
29 assert native.omega_pipeline(c.byref(result), state, 4096, q, 8, out, 8) == 0
30 return result.value, list(out)
31
32 assert call(1, 4, buffers, buffers)[0] == 0
33 for key in range(4):
34 assert call(2, key, 1, 10000)[0] == 0
35 for _ in range(100):
36 if compute is not None and compute[0] <= now:
37 assert call(8, compute[1])[0] == 0
38 assert call(9, compute[1])[0] == 0
39 compute = None
40 completed += 1
41 for end, ticket in list(reads):
42 if end <= now:
43 assert call(4, ticket, ok=1)[0] == 0
44 reads.remove((end, ticket))
45 if compute is None:
46 code, out = call(5)
47 assert code in (0, 1)
48 if code == 0:
49 assert call(6, out[0], ok=1)[0] == 0
50 assert call(7, out[0])[0] == 0
51 begin = max(now, shared_free) if shared_engine else now
52 compute = (begin + compute_ticks, out[0])
53 if shared_engine:
54 shared_free = compute[0]
55 if buffers == 2 or compute is None:
56 while True:
57 code, out = call(3)
58 assert code in (0, 1)
59 if code == 1:
60 break
61 begin = max(now, shared_free) if shared_engine else now
62 reads.append((begin + read_ticks, out[0]))
63 if shared_engine:
64 shared_free = reads[-1][0]
65 if completed == 4:
66 return now
67 events = [end for end, _ in reads]
68 if compute is not None:
69 events.append(compute[0])
70 assert events, 'controller stopped making progress'
71 now = min(events)
72 raise AssertionError('unbounded scheduling loop')
73
74
75parallel = [simulate(b, 10, 10) for b in (1, 2)]
76cached = [simulate(b, 0, 10) for b in (1, 2)]
77serialized = [simulate(b, 10, 10, True) for b in (1, 2)]
78assert parallel[1] < parallel[0], parallel
79assert cached[1] == cached[0], cached
80assert serialized[1] == serialized[0], serialized
81print('PASS synthetic schedule ticks (one/two):',
82 {'independent_engines': parallel, 'zero_read_cost': cached, 'shared_engine': serialized})