interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / gpu / turing / test.om

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