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