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
omega-mv / gpu / turing / types.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note gpu/turing/types.om: TURING field selection, kill-test & energy attribution types and math helpers. |
| 3 | note Converted from src/turing/{field.h,select.h,ty_energy.h}. |
| 4 | |
| 5 | const TURING_MAX_SPECS ulong 8 |
| 6 | const TURING_MAX_EV ulong 64 |
| 7 | const TURING_MAX_RCPT ulong 8 |
| 8 | const TURING_MAX_CITE ulong 16 |
| 9 | |
| 10 | const TURING_PACK_ONCE int 0 |
| 11 | const TURING_PACK_PER_CALL int 1 |
| 12 | |
| 13 | const TURING_TIER_OTHER uint 0 |
| 14 | const TURING_TIER_E2 uint 2 |
| 15 | const TURING_TIER_E3 uint 3 |
| 16 | const TURING_TIER_E4 uint 4 |
| 17 | |
| 18 | const TURING_R_CHOSEN uint 0 |
| 19 | const TURING_R_RANKED uint 1 |
| 20 | const TURING_R_TIED uint 2 |
| 21 | const TURING_R_CONTRACT_MISMATCH uint 3 |
| 22 | const TURING_R_NOT_EXACT uint 4 |
| 23 | const TURING_R_MAX_N uint 5 |
| 24 | const TURING_R_NO_EVIDENCE uint 6 |
| 25 | const TURING_R_RECEIPT_UNVERIFIED uint 7 |
| 26 | const TURING_R_UNVERIFIED_RUN uint 8 |
| 27 | const TURING_R_CONTENTION_FORCED uint 9 |
| 28 | const TURING_R_TIER uint 10 |
| 29 | const TURING_R_EXPLORE uint 11 |
| 30 | |
| 31 | const TURING_V_NONE int 0 |
| 32 | const TURING_V_CHOSEN int 1 |
| 33 | const TURING_V_EXPLORE int 2 |
| 34 | const TURING_V_TIE int 3 |
| 35 | |
| 36 | const TY_DIRECT uint 0 |
| 37 | const TY_COUNTER_DERIVED uint 1 |
| 38 | const TY_CAUSAL_RUNTIME uint 2 |
| 39 | const TY_COUNTERFACTUAL uint 3 |
| 40 | const TY_MODELLED uint 4 |
| 41 | const TY_UNATTRIBUTED uint 5 |
| 42 | |
| 43 | const TY_FORGE_ENERGY_NOT_MEASURED uint 0 |
| 44 | const TY_FORGE_ENERGY_MEASURED uint 1 |
| 45 | const TY_FORGE_ENERGY_ESTIMATED uint 2 |
| 46 | |
| 47 | const TYE_OK uint 0 |
| 48 | const TYE_E_SENSOR uint 1 |
| 49 | const TYE_E_WRAP uint 2 |
| 50 | const TYE_E_HEADROOM uint 3 |
| 51 | const TYE_E_SAMPLING_GAP uint 4 |
| 52 | const TYE_E_PARTIAL_RUN uint 5 |
| 53 | const TYE_E_INTERVAL_MISMATCH uint 6 |
| 54 | const TYE_E_MULTIPLEXED uint 7 |
| 55 | const TYE_E_OVERLAP uint 8 |
| 56 | const TYE_E_MISSING_IDLE uint 9 |
| 57 | const TYE_E_DOUBLE_COUNT uint 10 |
| 58 | const TYE_E_OVER_ALLOCATED uint 11 |
| 59 | const TYE_E_NEGATIVE_SHARE uint 12 |
| 60 | const TYE_E_MISSING_PARTICIPANT uint 13 |
| 61 | const TYE_E_UNKNOWN_PARTICIPANT uint 14 |
| 62 | const TYE_E_CONDITION uint 15 |
| 63 | const TYE_E_ARG uint 16 |
| 64 | |
| 65 | const TY_MAX_GAP_NS ulong 300000000 |
| 66 | const TY_WRAP_UJ ulong 4294967296000 |
| 67 | const TY_HEADROOM_MIN_UJ ulong 1000000000 |
| 68 | |
| 69 | struct TuringQuery n ulong m ulong sparsity_milli uint pack int exclude_exact_cell int end |
| 70 | |
| 71 | struct TuringBucket n ulong m ulong pack int count uint 8 mean_ps f64 8 order uint 8 cursor uint end |
| 72 | |
| 73 | struct TuringDecision n ulong m ulong sparsity_milli uint pack int cell_n ulong cell_m ulong exact_cell int ncand uint reason uint 8 cost_ps ulong 8 chosen int verdict int margin_ppm uint band_ppm uint ncite uint cite ulong 16 end |
| 74 | |
| 75 | struct TyInterval sensor_ok int wrap_flag int e0_uj ulong e1_uj ulong t0_ns ulong t1_ns ulong work_t0_ns ulong work_t1_ns ulong planned_ns ulong max_gap_ns ulong samples uint expected_samples uint pmu_enabled_ns ulong pmu_running_ns ulong work_ok int end |
| 76 | |
| 77 | struct TyAttrib measured_uj long uncert_uj long n_part uint shares_uj long 4 part_id uint 4 conf uint 4 end |
| 78 | |
| 79 | note ---- Shared SplitMix64 (Vigna constants, matching pd0_splitmix64) ---- |
| 80 | |
| 81 | fn turing_splitmix64 r edit ulong 1 to ulong |
| 82 | s = add get r 0 ulong 0x9e3779b97f4a7c15 |
| 83 | put r 0 s |
| 84 | z = mul xor s shr s 30 ulong 0xbf58476d1ce4e5b9 |
| 85 | z = mul xor z shr z 27 ulong 0x94d049bb133111eb |
| 86 | ret xor z shr z 31 |
| 87 | end |
| 88 | |
| 89 | note ---- Exact IEEE-754 f64 log2 for footprint distance |log2(n/qn)| + |log2(m/qm)| ---- |
| 90 | |
| 91 | fn turing_log2_f64 x f64 to f64 |
| 92 | bits = bitcast ulong x |
| 93 | exp_raw = and shr bits 52 ulong 0x7ff |
| 94 | exp_i = sub long exp_raw long 1023 |
| 95 | mant_bits = or and bits ulong 0x000fffffffffffff ulong 0x3ff0000000000000 |
| 96 | m = bitcast f64 mant_bits |
| 97 | note Range-reduced mantissa m in [1, 2): let t = (m - 1) / (m + 1), ln(m) = 2*(t + t^3/3 + t^5/5 + t^7/7) |
| 98 | t = div sub m 1.0f64 add m 1.0f64 |
| 99 | t2 = mul t t |
| 100 | p = add 0.2f64 mul t2 div 1.0f64 7.0f64 |
| 101 | p = add div 1.0f64 3.0f64 mul t2 p |
| 102 | p = add 1.0f64 mul t2 p |
| 103 | ln_m = mul 2.0f64 mul t p |
| 104 | ret add f64 exp_i mul ln_m 1.4426950408889634f64 |
| 105 | end |
| 106 | |
| 107 | fn turing_foot_dist qn ulong qm ulong en ulong em ulong to f64 |
| 108 | dn = fabs turing_log2_f64 div f64 en f64 qn |
| 109 | dm = fabs turing_log2_f64 div f64 em f64 qm |
| 110 | ret add dn dm |
| 111 | end |