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