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 / test.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note gpu/turing/test.om: comprehensive positive, negative, K.6 kill-test & mutant-control suite for gpu/turing. |
| 3 | note Compose: si/directives/om2.om gpu/turing/types.om gpu/turing/select.om gpu/turing/energy.om gpu/turing/test.om |
| 4 | |
| 5 | text ty_ok1 "PASS turing SplitMix64 + ranking core (min mean, tie-break) + history control arm\n" |
| 6 | text ty_ok2 "PASS turing Field v1 selection, citations, leave-one-cell-out & nearest-footprint fallback\n" |
| 7 | text ty_ok3 "PASS turing Field v1 fail-closed filter refusals (8/8 reason codes)\n" |
| 8 | text ty_ok4 "PASS turing K.6 kill-test (v1 0-regret vs retired v0 tie-band regret) + mutants M1/M2\n" |
| 9 | text ty_ok5 "PASS turing TY-4/TY-5 energy interval & conserving attribution fail-closed checks\n" |
| 10 | text ty_all "ALL PASS gpu-turing\n" |
| 11 | text ty_fail "FAIL gpu-turing\n" |
| 12 | |
| 13 | fn ty_puts s view uchar * to void |
| 14 | k = write 1 s 0 len s |
| 15 | if lt k 0 |
| 16 | exit 2 |
| 17 | end |
| 18 | ret |
| 19 | end |
| 20 | |
| 21 | fn test_ranking_and_history to int |
| 22 | r1 = new ulong 1 99 |
| 23 | r2 = new ulong 1 99 |
| 24 | if ne turing_splitmix64 edit r1 turing_splitmix64 edit r2 |
| 25 | ret 1 |
| 26 | end |
| 27 | turing_store_reset ulong 777 |
| 28 | s0 = turing_store_add_spec ulong 777 ulong 128 1 1 |
| 29 | s1 = turing_store_add_spec ulong 777 ulong 128 1 0 |
| 30 | s2 = turing_store_add_spec ulong 777 ulong 32 1 0 |
| 31 | b = new TuringBucket 0 0 0 0 0.0f64 0 0 |
| 32 | turing_bucket_reset edit b ulong 64 ulong 64 TURING_PACK_ONCE |
| 33 | turing_bucket_shuffle edit b ulong 42 ulong 3 |
| 34 | q = new TuringQuery 64 64 500 0 0 |
| 35 | d = new TuringDecision 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 36 | note Cold start: explores s0 and s1 (skips s2 because q.n=64 > max_n=32) |
| 37 | c1 = turing_history_select edit b view q edit d |
| 38 | if or ne get d verdict TURING_V_EXPLORE eq c1 int s2 |
| 39 | ret 2 |
| 40 | end |
| 41 | if ne get d reason ulong s2 TURING_R_MAX_N |
| 42 | ret 3 |
| 43 | end |
| 44 | turing_bucket_observe edit b ulong c1 ulong 1200 |
| 45 | c = turing_history_select edit b view q edit d |
| 46 | if or ne get d verdict TURING_V_EXPLORE eq c c1 |
| 47 | ret 4 |
| 48 | end |
| 49 | if eq c int s2 |
| 50 | ret 5 |
| 51 | end |
| 52 | turing_bucket_observe edit b ulong c ulong 1200 |
| 53 | note Exact tie (both 1200 ps): lowest spec index (s0 = 0) MUST win! |
| 54 | c = turing_history_select edit b view q edit d |
| 55 | if or ne get d verdict TURING_V_CHOSEN ne c int s0 |
| 56 | ret 6 |
| 57 | end |
| 58 | note Feed lower cost to s1 -> s1 now has lower running mean -> s1 wins! |
| 59 | turing_bucket_observe edit b ulong s1 ulong 600 |
| 60 | c = turing_history_select edit b view q edit d |
| 61 | if or ne get d verdict TURING_V_CHOSEN ne c int s1 |
| 62 | ret 7 |
| 63 | end |
| 64 | ret 0 |
| 65 | end |
| 66 | |
| 67 | fn test_field_select_positive to int |
| 68 | turing_store_reset ulong 101 |
| 69 | r0 = turing_store_add_receipt 1 |
| 70 | s0 = turing_store_add_spec ulong 101 ulong 256 1 1 |
| 71 | s1 = turing_store_add_spec ulong 101 ulong 256 1 0 |
| 72 | note Footprint (64, 64): s0=2000ps, s1=1000ps (s1 is 2x faster) |
| 73 | ev = turing_store_add_ev s0 ulong 64 ulong 64 uint 500 r0 TURING_TIER_E2 |
| 74 | turing_store_set_ev_meas ev 1 uint 0 ulong 2000 ulong 100 uint 10000 |
| 75 | ev = turing_store_add_ev s1 ulong 64 ulong 64 uint 500 r0 TURING_TIER_E3 |
| 76 | turing_store_set_ev_meas ev 1 uint 0 ulong 1000 ulong 100 uint 10000 |
| 77 | note Footprint (128, 128): s0=3000ps, s1=4000ps (s0 is faster here) |
| 78 | ev = turing_store_add_ev s0 ulong 128 ulong 128 uint 500 r0 TURING_TIER_E4 |
| 79 | turing_store_set_ev_meas ev 1 uint 0 ulong 3000 ulong 100 uint 10000 |
| 80 | ev = turing_store_add_ev s1 ulong 128 ulong 128 uint 500 r0 TURING_TIER_E4 |
| 81 | turing_store_set_ev_meas ev 1 uint 0 ulong 4000 ulong 100 uint 10000 |
| 82 | q = new TuringQuery 64 64 500 0 0 |
| 83 | d = new TuringDecision 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 84 | if ne turing_field_select view q edit d 0 |
| 85 | ret 10 |
| 86 | end |
| 87 | if or ne get d chosen int s1 ne get d exact_cell 1 |
| 88 | ret 11 |
| 89 | end |
| 90 | if ne get d ncite uint 2 |
| 91 | ret 12 |
| 92 | end |
| 93 | if ne turing_regret_ppm get d chosen view q ulong 0 |
| 94 | ret 13 |
| 95 | end |
| 96 | note Leave-one-cell-out on (64, 64, 500) -> falls back to nearest footprint (128, 128) where s0 wins! |
| 97 | put q exclude_exact_cell 1 |
| 98 | if ne turing_field_select view q edit d 0 |
| 99 | ret 14 |
| 100 | end |
| 101 | if or ne get d chosen int s0 ne get d exact_cell 0 |
| 102 | ret 15 |
| 103 | end |
| 104 | if or ne get d cell_n ulong 128 ne get d cell_m ulong 128 |
| 105 | ret 16 |
| 106 | end |
| 107 | ret 0 |
| 108 | end |
| 109 | |
| 110 | fn test_field_select_negative to int |
| 111 | turing_store_reset ulong 202 |
| 112 | r_ok = turing_store_add_receipt 1 |
| 113 | r_bad = turing_store_add_receipt 0 |
| 114 | note 8 specs (indices 0..7) testing all 8 filter refusal codes |
| 115 | sp = turing_store_add_spec ulong 999 ulong 256 1 0 |
| 116 | sp = turing_store_add_spec ulong 202 ulong 256 0 0 |
| 117 | sp = turing_store_add_spec ulong 202 ulong 32 1 0 |
| 118 | sp = turing_store_add_spec ulong 202 ulong 256 1 0 |
| 119 | sp = turing_store_add_spec ulong 202 ulong 256 1 0 |
| 120 | sp = turing_store_add_spec ulong 202 ulong 256 1 0 |
| 121 | sp = turing_store_add_spec ulong 202 ulong 256 1 0 |
| 122 | sp = turing_store_add_spec ulong 202 ulong 256 1 0 |
| 123 | ev = turing_store_add_ev uint 4 ulong 64 ulong 64 uint 500 r_bad TURING_TIER_E2 |
| 124 | turing_store_set_ev_meas ev 1 uint 0 ulong 500 ulong 0 uint 1000 |
| 125 | ev = turing_store_add_ev uint 5 ulong 64 ulong 64 uint 500 r_ok TURING_TIER_E2 |
| 126 | turing_store_set_ev_meas ev 0 uint 0 ulong 500 ulong 0 uint 1000 |
| 127 | ev = turing_store_add_ev uint 6 ulong 64 ulong 64 uint 500 r_ok TURING_TIER_E2 |
| 128 | turing_store_set_ev_meas ev 1 uint 1 ulong 500 ulong 0 uint 1000 |
| 129 | ev = turing_store_add_ev uint 7 ulong 64 ulong 64 uint 500 r_ok TURING_TIER_OTHER |
| 130 | turing_store_set_ev_meas ev 1 uint 0 ulong 500 ulong 0 uint 1000 |
| 131 | q = new TuringQuery 64 64 500 0 0 |
| 132 | d = new TuringDecision 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 133 | note No candidate survives -> returns 1 (NONE) with exact reason code for every spec! |
| 134 | if ne turing_field_select view q edit d 1 |
| 135 | ret 20 |
| 136 | end |
| 137 | if ne get d verdict TURING_V_NONE |
| 138 | ret 21 |
| 139 | end |
| 140 | if ne get d reason 0 TURING_R_CONTRACT_MISMATCH |
| 141 | ret 22 |
| 142 | end |
| 143 | if ne get d reason 1 TURING_R_NOT_EXACT |
| 144 | ret 23 |
| 145 | end |
| 146 | if ne get d reason 2 TURING_R_MAX_N |
| 147 | ret 24 |
| 148 | end |
| 149 | if ne get d reason 3 TURING_R_NO_EVIDENCE |
| 150 | ret 25 |
| 151 | end |
| 152 | if ne get d reason 4 TURING_R_RECEIPT_UNVERIFIED |
| 153 | ret 26 |
| 154 | end |
| 155 | if ne get d reason 5 TURING_R_UNVERIFIED_RUN |
| 156 | ret 27 |
| 157 | end |
| 158 | if ne get d reason 6 TURING_R_CONTENTION_FORCED |
| 159 | ret 28 |
| 160 | end |
| 161 | if ne get d reason 7 TURING_R_TIER |
| 162 | ret 29 |
| 163 | end |
| 164 | ret 0 |
| 165 | end |
| 166 | |
| 167 | fn test_kill_test_and_mutants to int |
| 168 | turing_store_reset ulong 303 |
| 169 | r_ok = turing_store_add_receipt 1 |
| 170 | r_bad = turing_store_add_receipt 0 |
| 171 | note K.6 kill-test: ref spec s0=1050ps vs fast spec s1=1000ps, noise band = 8% (80000ppm) > margin 5% (50000ppm) |
| 172 | s0 = turing_store_add_spec ulong 303 ulong 256 1 1 |
| 173 | s1 = turing_store_add_spec ulong 303 ulong 256 1 0 |
| 174 | ev = turing_store_add_ev s0 ulong 64 ulong 64 uint 500 r_ok TURING_TIER_E2 |
| 175 | turing_store_set_ev_meas ev 1 uint 0 ulong 1050 ulong 0 uint 80000 |
| 176 | ev = turing_store_add_ev s1 ulong 64 ulong 64 uint 500 r_ok TURING_TIER_E2 |
| 177 | turing_store_set_ev_meas ev 1 uint 0 ulong 1000 ulong 0 uint 80000 |
| 178 | q = new TuringQuery 64 64 500 0 0 |
| 179 | d1 = new TuringDecision 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 180 | d0 = new TuringDecision 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 181 | if ne turing_field_select view q edit d1 0 |
| 182 | ret 30 |
| 183 | end |
| 184 | if or ne get d1 chosen int s1 ne get d1 verdict TURING_V_CHOSEN |
| 185 | ret 31 |
| 186 | end |
| 187 | if ne turing_regret_ppm get d1 chosen view q ulong 0 |
| 188 | ret 32 |
| 189 | end |
| 190 | note Retired v0 triggers tie-band rule and picks s0 (reference) -> 50000 ppm regret (K.6 FAIL reproduced!) |
| 191 | if ne turing_field_select_v0_retired view q edit d0 0 |
| 192 | ret 33 |
| 193 | end |
| 194 | if or ne get d0 chosen int s0 ne get d0 verdict TURING_V_TIE |
| 195 | ret 34 |
| 196 | end |
| 197 | reg0 = turing_regret_ppm get d0 chosen view q |
| 198 | if ne reg0 ulong 50000 |
| 199 | ret 35 |
| 200 | end |
| 201 | note Mutant M1: inverted ranking comparator picks s0 instead of s1 -> nonzero regret detected! |
| 202 | b = new TuringBucket 0 0 0 0 0.0f64 0 0 |
| 203 | turing_bucket_reset edit b ulong 64 ulong 64 TURING_PACK_ONCE |
| 204 | turing_bucket_observe edit b ulong s0 ulong 1050 |
| 205 | turing_bucket_observe edit b ulong s1 ulong 1000 |
| 206 | al = new int 8 1 |
| 207 | m1_pick = turing_rank_min_cost_mutant view b view al ulong 2 |
| 208 | if ne m1_pick int s0 |
| 209 | ret 36 |
| 210 | end |
| 211 | if eq turing_regret_ppm m1_pick view q ulong 0 |
| 212 | ret 37 |
| 213 | end |
| 214 | note Mutant M2: dropping receipt verification accepts unverified receipt that live v1 refuses! |
| 215 | turing_store_reset ulong 304 |
| 216 | r_b = turing_store_add_receipt 0 |
| 217 | sm = turing_store_add_spec ulong 304 ulong 256 1 0 |
| 218 | em = turing_store_add_ev sm ulong 64 ulong 64 uint 500 r_b TURING_TIER_E2 |
| 219 | turing_store_set_ev_meas em 1 uint 0 ulong 900 ulong 0 uint 5000 |
| 220 | if ne turing_field_select_impl view q edit d1 0 0 1 |
| 221 | ret 38 |
| 222 | end |
| 223 | if ne turing_field_select_impl view q edit d0 0 1 0 |
| 224 | ret 39 |
| 225 | end |
| 226 | ret 0 |
| 227 | end |
| 228 | |
| 229 | fn test_energy_invariants to int |
| 230 | note Confidence -> FORGE energy_source mapping |
| 231 | if ne ty_conf_forge TY_DIRECT TY_FORGE_ENERGY_MEASURED |
| 232 | ret 40 |
| 233 | end |
| 234 | if ne ty_conf_forge TY_COUNTER_DERIVED TY_FORGE_ENERGY_MEASURED |
| 235 | ret 41 |
| 236 | end |
| 237 | if ne ty_conf_forge TY_MODELLED TY_FORGE_ENERGY_ESTIMATED |
| 238 | ret 42 |
| 239 | end |
| 240 | if ne ty_conf_forge TY_UNATTRIBUTED TY_FORGE_ENERGY_NOT_MEASURED |
| 241 | ret 43 |
| 242 | end |
| 243 | note Valid interval passes |
| 244 | iv = new TyInterval 1 0 100000 250000 1000 5000 1100 4900 3800 100000000 100 100 10000 10000 1 |
| 245 | if ne ty_interval_check view iv TYE_OK |
| 246 | ret 44 |
| 247 | end |
| 248 | note Negative controls: sensor, wrap, headroom, gap, partial, mismatch, multiplexed |
| 249 | put iv sensor_ok 0 |
| 250 | if ne ty_interval_check view iv TYE_E_SENSOR |
| 251 | ret 45 |
| 252 | end |
| 253 | put iv sensor_ok 1 |
| 254 | put iv e1_uj ulong 50000 |
| 255 | if ne ty_interval_check view iv TYE_E_WRAP |
| 256 | ret 46 |
| 257 | end |
| 258 | put iv e1_uj sub TY_WRAP_UJ ulong 100 |
| 259 | if ne ty_interval_check view iv TYE_E_HEADROOM |
| 260 | ret 47 |
| 261 | end |
| 262 | put iv e1_uj ulong 250000 |
| 263 | put iv max_gap_ns ulong 300000001 |
| 264 | if ne ty_interval_check view iv TYE_E_SAMPLING_GAP |
| 265 | ret 48 |
| 266 | end |
| 267 | put iv max_gap_ns ulong 100000000 |
| 268 | put iv work_t0_ns ulong 900 |
| 269 | if ne ty_interval_check view iv TYE_E_INTERVAL_MISMATCH |
| 270 | ret 49 |
| 271 | end |
| 272 | put iv work_t0_ns ulong 1100 |
| 273 | put iv planned_ns ulong 5000 |
| 274 | if ne ty_interval_check view iv TYE_E_PARTIAL_RUN |
| 275 | ret 50 |
| 276 | end |
| 277 | put iv planned_ns ulong 3800 |
| 278 | put iv pmu_running_ns ulong 9900 |
| 279 | if ne ty_interval_check view iv TYE_E_MULTIPLEXED |
| 280 | ret 51 |
| 281 | end |
| 282 | note Window overlap detection |
| 283 | if ne ty_windows_overlap ulong 100 ulong 200 ulong 200 ulong 300 0 |
| 284 | ret 52 |
| 285 | end |
| 286 | if ne ty_windows_overlap ulong 100 ulong 200 ulong 150 ulong 250 1 |
| 287 | ret 53 |
| 288 | end |
| 289 | note Conserving attribution positive & negative controls |
| 290 | att = new TyAttrib 100000 1000 2 0 0 0 |
| 291 | put att shares_uj 0 long 60000 |
| 292 | put att shares_uj 1 long 40000 |
| 293 | put att part_id 0 uint 0 |
| 294 | put att part_id 1 uint 1 |
| 295 | if ne ty_attribution_check view att uint 3 TYE_OK |
| 296 | ret 54 |
| 297 | end |
| 298 | put att shares_uj 0 long 70000 |
| 299 | if ne ty_attribution_check view att uint 3 TYE_E_OVER_ALLOCATED |
| 300 | ret 55 |
| 301 | end |
| 302 | put att shares_uj 0 long -2000 |
| 303 | if ne ty_attribution_check view att uint 3 TYE_E_NEGATIVE_SHARE |
| 304 | ret 56 |
| 305 | end |
| 306 | put att shares_uj 0 long 50000 |
| 307 | put att part_id 1 uint 0 |
| 308 | if ne ty_attribution_check view att uint 3 TYE_E_DOUBLE_COUNT |
| 309 | ret 57 |
| 310 | end |
| 311 | put att part_id 1 uint 2 |
| 312 | if ne ty_attribution_check view att uint 3 TYE_E_UNKNOWN_PARTICIPANT |
| 313 | ret 58 |
| 314 | end |
| 315 | put att n_part uint 1 |
| 316 | if ne ty_attribution_check view att uint 3 TYE_E_MISSING_PARTICIPANT |
| 317 | ret 59 |
| 318 | end |
| 319 | ret 0 |
| 320 | end |
| 321 | |
| 322 | fn main to int |
| 323 | rc = test_ranking_and_history |
| 324 | if ne rc 0 |
| 325 | ty_puts ty_fail |
| 326 | ret rc |
| 327 | end |
| 328 | ty_puts ty_ok1 |
| 329 | |
| 330 | rc = test_field_select_positive |
| 331 | if ne rc 0 |
| 332 | ty_puts ty_fail |
| 333 | ret rc |
| 334 | end |
| 335 | ty_puts ty_ok2 |
| 336 | |
| 337 | rc = test_field_select_negative |
| 338 | if ne rc 0 |
| 339 | ty_puts ty_fail |
| 340 | ret rc |
| 341 | end |
| 342 | ty_puts ty_ok3 |
| 343 | |
| 344 | rc = test_kill_test_and_mutants |
| 345 | if ne rc 0 |
| 346 | ty_puts ty_fail |
| 347 | ret rc |
| 348 | end |
| 349 | ty_puts ty_ok4 |
| 350 | |
| 351 | rc = test_energy_invariants |
| 352 | if ne rc 0 |
| 353 | ty_puts ty_fail |
| 354 | ret rc |
| 355 | end |
| 356 | ty_puts ty_ok5 |
| 357 | |
| 358 | ty_puts ty_all |
| 359 | ret 0 |
| 360 | end |