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 / head-to-head / main.om

294 lines · 6271 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note gpu/head-to-head/main.om: CLI reading paired benchmark records on stdin and printing verified
3note comparison statistics, numerical parity results, mutant-control verification, and verdict on stdout.
4note Compose with: si/directives/om2.om gpu/head-to-head/lib.om gpu/head-to-head/main.om
5note Stdin line grammar (comments start with #):
6note BYTES <u64>
7note TOL <atol_f64> <rtol_f64>
8note PAIR <arm_a_ns_u64> <arm_b_ns_u64>
9note ELEM <arm_a_f64> <arm_b_f64>
10note MUTANT <mutant_f64>
11
12text h2h_cli_bytes "BYTES"
13text h2h_cli_tol "TOL"
14text h2h_cli_pair "PAIR"
15text h2h_cli_elem "ELEM"
16text h2h_cli_mut "MUTANT"
17text h2h_cli_err "ERROR invalid input on stdin\n"
18text h2h_cli_nan "NaN"
19text h2h_cli_inf "Inf"
20text h2h_cli_ninf "-Inf"
21
22global h2h_inbuf uchar 65536
23global h2h_arm_a_ns ulong 512
24global h2h_arm_b_ns ulong 512
25global h2h_arm_a_f f64 1024
26global h2h_arm_b_f f64 1024
27global h2h_mut_f f64 1024
28
29fn h2h_read_stdin to long
30total = ulong 0
31while lt total 65536 bound 65536
32k = read 0 h2h_inbuf total sub 65536 total
33if lt k 0
34ret k
35end
36if eq k 0
37break
38end
39total = add total ulong k
40end
41ret long total
42end
43
44fn h2h_parse_f64_or_special line view uchar * s ulong e ulong dst edit f64 1 to bool
45if h2h_tok_eq line s e h2h_cli_nan
46put dst 0 bitcast f64 ulong 0x7ff8000000000000
47ret true
48end
49if h2h_tok_eq line s e h2h_cli_inf
50put dst 0 bitcast f64 ulong 0x7ff0000000000000
51ret true
52end
53if h2h_tok_eq line s e h2h_cli_ninf
54put dst 0 bitcast f64 ulong 0xfff0000000000000
55ret true
56end
57if not h2h_parse_f64_ok line s e
58ret false
59end
60put dst 0 h2h_parse_f64_val line s e
61ret true
62end
63
64fn h2h_parse_line line view uchar * state edit ulong 4 tol edit H2hTol to bool
65note state[0]=bytes_moved state[1]=n_pairs state[2]=n_elems state[3]=n_mut
66v1 = new f64 1 0.0f64
67v2 = new f64 1 0.0f64
68n = len line
69p = h2h_skip_ws line 0 n
70if ge p n
71ret true
72end
73if eq get line p 35
74ret true
75end
76t0e = h2h_next_tok_end line p n
77if h2h_tok_eq line p t0e h2h_cli_bytes
78p1 = h2h_skip_ws line t0e n
79t1e = h2h_next_tok_end line p1 n
80if not h2h_parse_u64_ok line p1 t1e
81ret false
82end
83put state 0 h2h_parse_u64_val line p1 t1e
84ret true
85end
86if h2h_tok_eq line p t0e h2h_cli_tol
87p1 = h2h_skip_ws line t0e n
88t1e = h2h_next_tok_end line p1 n
89p2 = h2h_skip_ws line t1e n
90t2e = h2h_next_tok_end line p2 n
91if not h2h_parse_f64_or_special line p1 t1e v1
92ret false
93end
94if not h2h_parse_f64_or_special line p2 t2e v2
95ret false
96end
97put tol atol get v1 0
98put tol rtol get v2 0
99ret true
100end
101if h2h_tok_eq line p t0e h2h_cli_pair
102p1 = h2h_skip_ws line t0e n
103t1e = h2h_next_tok_end line p1 n
104p2 = h2h_skip_ws line t1e n
105t2e = h2h_next_tok_end line p2 n
106if not h2h_parse_u64_ok line p1 t1e
107ret false
108end
109if not h2h_parse_u64_ok line p2 t2e
110ret false
111end
112idx = get state 1
113if ge idx 512
114ret false
115end
116put h2h_arm_a_ns idx h2h_parse_u64_val line p1 t1e
117put h2h_arm_b_ns idx h2h_parse_u64_val line p2 t2e
118put state 1 add idx 1
119ret true
120end
121if h2h_tok_eq line p t0e h2h_cli_elem
122p1 = h2h_skip_ws line t0e n
123t1e = h2h_next_tok_end line p1 n
124p2 = h2h_skip_ws line t1e n
125t2e = h2h_next_tok_end line p2 n
126if not h2h_parse_f64_or_special line p1 t1e v1
127ret false
128end
129if not h2h_parse_f64_or_special line p2 t2e v2
130ret false
131end
132idx = get state 2
133if ge idx 1024
134ret false
135end
136put h2h_arm_a_f idx get v1 0
137put h2h_arm_b_f idx get v2 0
138put state 2 add idx 1
139ret true
140end
141if h2h_tok_eq line p t0e h2h_cli_mut
142p1 = h2h_skip_ws line t0e n
143t1e = h2h_next_tok_end line p1 n
144if not h2h_parse_f64_or_special line p1 t1e v1
145ret false
146end
147idx = get state 3
148if ge idx 1024
149ret false
150end
151put h2h_mut_f idx get v1 0
152put state 3 add idx 1
153ret true
154end
155ret false
156end
157
158fn h2h_copy_line pos ulong total ulong dst edit uchar 512 to long
159cnt = ulong 0
160p = pos
161while lt p total bound 65536
162c = get h2h_inbuf p
163if eq c 10
164break
165end
166if ge cnt 512
167ret -1
168end
169put dst cnt c
170cnt = add cnt 1
171p = add p 1
172end
173ret long cnt
174end
175
176fn h2h_eval_timings np ulong sa edit H2hStats sb edit H2hStats to void
177ta = new ulong 512 0
178tb = new ulong 512 0
179scr = new ulong 512 0
180i = ulong 0
181while lt i np bound 512
182put ta i get h2h_arm_a_ns i
183put tb i get h2h_arm_b_ns i
184i = add i 1
185end
186oka = h2h_compute_stats part ta 0 np scr sa
187okb = h2h_compute_stats part tb 0 np scr sb
188if and oka okb
189ret
190end
191end
192
193fn h2h_eval_parity_mut nel ulong nm ulong tol view H2hTol par edit H2hParity to ulong
194fa = new f64 1024 0.0f64
195fb = new f64 1024 0.0f64
196fm = new f64 1024 0.0f64
197mpar = new H2hParity 0 0 0 0 0 0.0f64 0.0f64
198j = ulong 0
199while lt j nel bound 1024
200put fa j get h2h_arm_a_f j
201put fb j get h2h_arm_b_f j
202j = add j 1
203end
204h2h_check_parity part fa 0 nel part fb 0 nel tol par
205if eq nel 0
206ret ulong 0
207end
208if eq nm 0
209mn = h2h_make_wrong_kernel_mutant part fa 0 nel fm
210if eq mn nel
211if h2h_verify_mutant part fa 0 nel part fm 0 nel tol mpar
212ret ulong 2
213end
214end
215ret ulong 1
216end
217k = ulong 0
218while lt k nm bound 1024
219put fm k get h2h_mut_f k
220k = add k 1
221end
222if h2h_verify_mutant part fa 0 nel part fm 0 nm tol mpar
223ret ulong 2
224end
225ret ulong 1
226end
227
228fn h2h_run_eval np ulong nel ulong nm ulong bytes_moved ulong tol view H2hTol to int
229sa = new H2hStats 0 0 0 0 0.0f64 0 0 0 0
230sb = new H2hStats 0 0 0 0 0.0f64 0 0 0 0
231par = new H2hParity 0 0 0 0 0 0.0f64 0.0f64
232sum = new H2hSummary 2 0 bytes_moved 0.0f64 0.0f64 0.0f64 0 0 0 0
233h2h_eval_timings np sa sb
234mst = h2h_eval_parity_mut nel nm tol par
235mchk = ulong 0
236mcaught = ulong 0
237if gt mst 0
238mchk = ulong 1
239end
240if eq mst 2
241mcaught = ulong 1
242end
243h2h_finalize_summary sa sb par mchk mcaught sum
244h2h_emit_report 1 sa sb par sum
245v = get sum verdict
246if eq v H2H_VERDICT_PASS
247ret 0
248end
249if eq v H2H_VERDICT_FAIL
250ret 1
251end
252ret 2
253end
254
255fn main to int
256got = h2h_read_stdin
257if lt got 0
258okw = h2h_write_all 2 h2h_cli_err
259if okw
260ret 2
261end
262ret 2
263end
264total = ulong got
265state = new ulong 4 0
266tol = new H2hTol 0.000001f64 0.00001f64
267line = new uchar 512 0
268pos = ulong 0
269while lt pos total bound 65536
270ln_s = h2h_copy_line pos total line
271if lt ln_s 0
272oke_l = h2h_write_all 2 h2h_cli_err
273if oke_l
274ret 2
275end
276ret 2
277end
278ln = ulong ln_s
279if not h2h_parse_line part line 0 ln state tol
280oke = h2h_write_all 2 h2h_cli_err
281if oke
282ret 2
283end
284ret 2
285end
286pos = add pos ln
287if lt pos total
288if eq get h2h_inbuf pos 10
289pos = add pos 1
290end
291end
292end
293ret h2h_run_eval get state 1 get state 2 get state 3 get state 0 tol
294end