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 / q38-head / select.om

117 lines · 2578 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note Exact-head candidate policy, core issue710. No allocation or device calls.
3note Contract: c[i] >= ||W[i]-Q[i]|| + rounding allowances for BOTH actual dots.
4note Coefficients must be upward-rounded and bound the supplied compact scores.
5note This unit does not establish coefficient provenance or quantizer correctness.
6note h is the same normalized vector used by both heads. Only rows below count
7note are read or written. All input validation precedes any output mutation.
8note Binary32 values convert exactly to binary64. Squares are exact in binary64;
9note sum, sqrt, product and interval endpoints are rounded outward one ulp.
10note Thus tau=max(lower) and upper>=tau retain every possible full-head winner.
11note Recheck kept rows with the original full-head arithmetic, first index on ties.
12
13fn up x f64 to f64
14bits = bitcast ulong x
15if eq and bits 9223372036854775807 0
16ret bitcast f64 ulong 1
17end
18if ne and bits 9223372036854775808 0
19ret bitcast f64 sub bits 1
20end
21ret bitcast f64 add bits 1
22end
23
24fn finite x f32 to bool
25ret lt and bitcast uint x 2147483647 2139095040
26end
27
28fn normup h view f32 5120 to f64
29total = f64 0.0
30for i ulong 5120
31x = get h i
32if not finite x
33trap 5
34end
35y = f64 x
36if ne y 0.0
37total = up add total mul y y
38end
39end
40if eq total 0.0
41ret 0.0
42end
43ret up fsqrt total
44end
45
46fn validate s view f32 248320 c view f32 248320 count ulong to void
47for i ulong count
48if not finite get s i
49trap 5
50end
51v = get c i
52if not finite v
53trap 5
54end
55if lt v 0.0
56trap 5
57end
58end
59end
60
61fn radius coef f32 hn f64 to f64
62if or eq coef 0.0 eq hn 0.0
63ret 0.0
64end
65ret up mul f64 coef hn
66end
67
68fn lower score f32 coef f32 hn f64 to f64
69b = radius coef hn
70if eq b 0.0
71ret f64 score
72end
73ret neg up neg sub f64 score b
74end
75
76fn upper score f32 coef f32 hn f64 to f64
77b = radius coef hn
78if eq b 0.0
79ret f64 score
80end
81ret up add f64 score b
82end
83
84fn thresh s view f32 248320 c view f32 248320 count ulong hn f64 to f64
85tau = lower get s 0 get c 0 hn
86for i ulong count
87v = lower get s i get c i hn
88if gt v tau
89tau = v
90end
91end
92ret tau
93end
94
95fn publish s view f32 248320 c view f32 248320 mask edit uchar 248320 count ulong hn f64 tau f64 to ulong
96kept = ulong 0
97for i ulong count
98take = ge upper get s i get c i hn tau
99if take
100put mask i 1
101kept = add kept 1
102else
103put mask i 0
104end
105end
106ret kept
107end
108
109fn q38select h view f32 5120 s view f32 248320 c view f32 248320 mask edit uchar 248320 count ulong to ulong
110if or eq count 0 gt count 248320
111trap 5
112end
113validate s c count
114hn = normup h
115tau = thresh s c count hn
116ret publish s c mask count hn tau
117end