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 / si / benchmarks / verify / bundle.om

272 lines · 6113 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note si/benchmarks/verify/bundle.om: pure-Omega port of benchmarks-mv verification engine:
3note benchmark bundle validator, MEASURED vs MODELED discriminator, quantile monotonicity,
4note hardware roofline ceiling comparator, and basis-point regression gate.
5note Compose after si/directives/om2.om and om/tls/sha2.om.
6
7const BM_OK ulong 0
8const BM_ERR_BAD_CLASS ulong 1
9const BM_ERR_MODELED_AS_MEASURED ulong 2
10const BM_ERR_NOT_MEASURED ulong 3
11const BM_ERR_DIRTY_TREE ulong 4
12const BM_ERR_BAD_SHA ulong 5
13const BM_ERR_TOO_FEW_SAMPLES ulong 6
14const BM_ERR_NONMONOTONIC_Q ulong 7
15const BM_ERR_ZERO_THROUGHPUT ulong 8
16const BM_ERR_EXCEEDS_CEILING ulong 9
17const BM_ERR_REGRESSION ulong 10
18const BM_ERR_ZERO_BASELINE ulong 11
19const BM_ERR_BELOW_FLOOR ulong 12
20const BM_ERR_OVERFLOW ulong 13
21
22const BM_CLASS_MEASURED ulong 1
23const BM_CLASS_MODELED ulong 2
24const BM_CLASS_ESTIMATED ulong 3
25const BM_CLASS_SYNTHETIC ulong 4
26
27text bm_lbl_measured "MEASURED"
28text bm_lbl_modeled "MODELED"
29text bm_lbl_estimated "ESTIMATED"
30text bm_lbl_synthetic "SYNTHETIC"
31
32note --- Basic helpers ---
33
34fn bm_slice_eq a view uchar * b view uchar * to bool
35na = len a
36nb = len b
37if ne na nb
38ret false
39end
40if gt na ulong 4096
41ret false
42end
43i = ulong 0
44while lt i na bound 4096
45if ne get a i get b i
46ret false
47end
48i = add i ulong 1
49end
50ret true
51end
52
53fn bm_write_all fd int buf view uchar * to bool
54n = len buf
55if eq n ulong 0
56ret true
57end
58if gt n ulong 1048576
59ret false
60end
61off = ulong 0
62while lt off n bound 1048576
63remn = sub n off
64k = write fd buf off remn
65if le k long 0
66ret false
67end
68off = add off ulong k
69end
70ret true
71end
72
73fn bm_put_u64_le dst edit uchar * pos ulong v ulong to ulong
74if gt add pos ulong 8 len dst
75ret pos
76end
77for i ulong 8
78sh = mul i ulong 8
79put dst add pos i uchar and shr v sh ulong 255
80end
81ret add pos ulong 8
82end
83
84fn bm_is_lower_hex s view uchar * expected_len ulong to bool
85if ne len s expected_len
86ret false
87end
88if gt expected_len ulong 128
89ret false
90end
91i = ulong 0
92while lt i expected_len bound 128
93b = get s i
94ok = false
95if and ge b uchar 48 le b uchar 57
96ok = true
97end
98if and ge b uchar 97 le b uchar 102
99ok = true
100end
101if not ok
102ret false
103end
104i = add i ulong 1
105end
106ret true
107end
108
109fn bm_digest_eq a view uchar 32 b view uchar 32 to bool
110for i ulong 32
111if ne get a i get b i
112ret false
113end
114end
115ret true
116end
117
118note --- MEASURED vs MODELED Discriminator ---
119
120fn bm_parse_class lbl view uchar * to ulong
121if bm_slice_eq lbl bm_lbl_measured
122ret BM_CLASS_MEASURED
123end
124if bm_slice_eq lbl bm_lbl_modeled
125ret BM_CLASS_MODELED
126end
127if bm_slice_eq lbl bm_lbl_estimated
128ret BM_CLASS_ESTIMATED
129end
130if bm_slice_eq lbl bm_lbl_synthetic
131ret BM_CLASS_SYNTHETIC
132end
133ret ulong 0
134end
135
136note Anti-laundering invariant: a MEASURED label MUST NOT be extrapolated, dirty, sample-less, or missing a HW receipt.
137fn bm_discriminate_class ev_class ulong samples ulong has_hw_receipt bool dirty bool extrapolated bool to ulong
138if or eq ev_class ulong 0 gt ev_class BM_CLASS_SYNTHETIC
139ret BM_ERR_BAD_CLASS
140end
141if eq ev_class BM_CLASS_MEASURED
142if dirty
143ret BM_ERR_DIRTY_TREE
144end
145if extrapolated
146ret BM_ERR_MODELED_AS_MEASURED
147end
148if not has_hw_receipt
149ret BM_ERR_MODELED_AS_MEASURED
150end
151if eq samples ulong 0
152ret BM_ERR_TOO_FEW_SAMPLES
153end
154end
155ret BM_OK
156end
157
158note Only MEASURED evidence may support a silicon/qualification benchmark claim.
159fn bm_allow_qualification ev_class ulong to ulong
160if ne ev_class BM_CLASS_MEASURED
161ret BM_ERR_NOT_MEASURED
162end
163ret BM_OK
164end
165
166note --- Benchmark Bundle Validator ---
167note Validates quantile ordering: min_us <= p50_us <= p95_us <= p99_us <= max_us, and min_us > 0.
168
169fn bm_validate_quantiles min_us ulong p50_us ulong p95_us ulong p99_us ulong max_us ulong to ulong
170if eq min_us ulong 0
171ret BM_ERR_NONMONOTONIC_Q
172end
173if gt min_us p50_us
174ret BM_ERR_NONMONOTONIC_Q
175end
176if gt p50_us p95_us
177ret BM_ERR_NONMONOTONIC_Q
178end
179if gt p95_us p99_us
180ret BM_ERR_NONMONOTONIC_Q
181end
182if gt p99_us max_us
183ret BM_ERR_NONMONOTONIC_Q
184end
185ret BM_OK
186end
187
188fn bm_validate_bundle_shas commit_sha view uchar * receipt_sha view uchar * to ulong
189if not bm_is_lower_hex commit_sha ulong 40
190ret BM_ERR_BAD_SHA
191end
192if not bm_is_lower_hex receipt_sha ulong 64
193ret BM_ERR_BAD_SHA
194end
195ret BM_OK
196end
197
198fn bm_validate_bundle_counts samples ulong min_samples ulong throughput ulong to ulong
199if lt samples min_samples
200ret BM_ERR_TOO_FEW_SAMPLES
201end
202if eq throughput ulong 0
203ret BM_ERR_ZERO_THROUGHPUT
204end
205ret BM_OK
206end
207
208note --- Hardware Roofline Ceiling & Basis-Point Regression Comparator ---
209
210fn bm_check_ceiling measured_val ulong physical_ceiling ulong to ulong
211if eq physical_ceiling ulong 0
212ret BM_ERR_EXCEEDS_CEILING
213end
214if gt measured_val physical_ceiling
215ret BM_ERR_EXCEEDS_CEILING
216end
217ret BM_OK
218end
219
220note Checks latency regression: candidate_us * 10000 <= baseline_us * (10000 + max_regress_bps)
221note Guarded against ulong overflow (inputs capped at 10^14 so * 20000 fits safely in ulong).
222fn bm_check_latency_regression baseline_us ulong candidate_us ulong max_regress_bps ulong to ulong
223if eq baseline_us ulong 0
224ret BM_ERR_ZERO_BASELINE
225end
226if gt max_regress_bps ulong 10000
227ret BM_ERR_OVERFLOW
228end
229cap = ulong 100000000000000
230if or gt baseline_us cap gt candidate_us cap
231ret BM_ERR_OVERFLOW
232end
233lhs = mul candidate_us ulong 10000
234rhs = mul baseline_us add ulong 10000 max_regress_bps
235if gt lhs rhs
236ret BM_ERR_REGRESSION
237end
238ret BM_OK
239end
240
241fn bm_check_throughput_floor measured_tps ulong floor_tps ulong to ulong
242if lt measured_tps floor_tps
243ret BM_ERR_BELOW_FLOOR
244end
245ret BM_OK
246end
247
248note Canonical SHA-256 digest of a benchmark bundle (meta[4]={ev_class,samples,p50,p99}, commit_sha).
249fn bm_bundle_digest meta view ulong 4 commit_sha view uchar * dst edit uchar 32 to void
250ctx = new ulong 40 0
251hdr = new uchar 32 0
252w1 = bm_put_u64_le hdr ulong 0 get meta 0
253if ne w1 ulong 8
254trap 8
255end
256w2 = bm_put_u64_le hdr ulong 8 get meta 1
257if ne w2 ulong 16
258trap 8
259end
260w3 = bm_put_u64_le hdr ulong 16 get meta 2
261if ne w3 ulong 24
262trap 8
263end
264w4 = bm_put_u64_le hdr ulong 24 get meta 3
265if ne w4 ulong 32
266trap 8
267end
268sha256_init ctx
269sha256_update ctx hdr
270sha256_update ctx commit_sha
271sha256_final ctx dst
272end