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 / nvidia / checks / nartf.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note gpu/nvidia/checks/nartf.om: the Omega port of the artifacts() block of CUDApp tests/api_attn_rest_diff.c. |
| 3 | note Composed after gpu/nvidia/om/api/attn_art.om (it starts with om2), the roots gpu/nvidia/om/api/na_json.om, |
| 4 | note na_ver.om, na_layout.om, na_cubin.om and na_read.om, gpu/nvidia/checks/lib.om and gpu/nvidia/checks/lib-om2.om; |
| 5 | note run with gpu/nvidia/checks/nartf.tsv. Rows, tab separated; bytes are lowercase hex, "-" for none: |
| 6 | note j C BYTES the JSON string of the one-byte C string C (empty for C 0) is BYTES, quotes included |
| 7 | note v H N R H >= N as the C semver_ge says: R 1, 0, or -1 when either is not a strict A.B.C |
| 8 | note k BYTES the key list the C binding of manifest_layout_ok passes na_layout (kept for later rows) |
| 9 | note b BYTES the base manifest of the test (kept for later rows) |
| 10 | note L N R na_layout of the first N bytes of the base manifest (zero beyond it) is R |
| 11 | note M I V R na_layout of the base manifest with byte I set to V is R |
| 12 | note c BYTES TEXT the test's base cubin and its text (kept for later rows) |
| 13 | note C N R na_cubin of the first N bytes of the base cubin, function foo, is R |
| 14 | note X I V R na_cubin of the base cubin with byte I set to V is R |
| 15 | note F N R na_cubin of the base cubin for a function name of N bytes f is R |
| 16 | note T I V R na_cubin of the base cubin with byte I of the text xored with V is R |
| 17 | note r N W na_read of the first N bytes of the base cubin is W (hex) |
| 18 | note K CUBIN TEXT FUNCTION C OMEGA WHY |
| 19 | note a known difference: the pending C answers C and na_cubin answers OMEGA for this cubin, text |
| 20 | note and function name. The row passes only when OMEGA is still na_cubin's answer and C still |
| 21 | note differs from it, so a change on either side fails the gate. C comes from the oracle (no C |
| 22 | note runs here); OMEGA was recorded when the check first met the input. WHY says what differs. |
| 23 | note The kept rows live in fixed arrays: a manifest of at most 8192 bytes (the binding's MANIFEST_CAP; one byte |
| 24 | note more so that the test's 8192-byte refusal case reads zeros), a key list and a cubin of at most 4096 bytes and |
| 25 | note a text of at most 64. A longer row is refused as a malformed table (exit 2), never cut. The units take views |
| 26 | note and a pool that grows cannot be passed (docs/RUNTIME-POOLS.md), so each row copies what it needs into its |
| 27 | note frame. The strict A.B.C parse of the v rows is the C binding's parse_semver, ported here: na_ver compares |
| 28 | note parsed versions. |
| 29 | text t_name "NARTF" |
| 30 | text t_foo "foo" |
| 31 | global nt_m uchar 8193 |
| 32 | global nt_k uchar 4096 |
| 33 | global nt_c uchar 4096 |
| 34 | global nt_t uchar 64 |
| 35 | note nt_n: 0 manifest length, 1 key length, 2 cubin length, 3 text length, 4 manifest and keys kept, 5 cubin kept |
| 36 | global nt_n ulong 6 |
| 37 | fn cname to void |
| 38 | for i ulong len t_name bound 64 |
| 39 | ckoc ulong get t_name i |
| 40 | end |
| 41 | end |
| 42 | fn ntx i ulong to ulong |
| 43 | n = cklen i |
| 44 | if or eq n 0 gt n 16 |
| 45 | ckbad |
| 46 | end |
| 47 | v = ulong 0 |
| 48 | for j ulong n bound 16 |
| 49 | v = or shl v 4 cknib ckch i j |
| 50 | end |
| 51 | ret v |
| 52 | end |
| 53 | note field i as 0, 1, or 2 for -1 |
| 54 | fn ntr i ulong to ulong |
| 55 | if and eq cklen i 2 eq ckch i 0 45 |
| 56 | if eq ckch i 1 49 |
| 57 | ret 2 |
| 58 | end |
| 59 | end |
| 60 | v = cknum i |
| 61 | if gt v 1 |
| 62 | ckbad |
| 63 | end |
| 64 | ret v |
| 65 | end |
| 66 | note the C binding's parse_semver: three decimal components of 1 to 9 digits split by dots, nothing more |
| 67 | fn ntsv s view uchar * v edit uint 3 to bool |
| 68 | p = ulong 0 |
| 69 | for k ulong 3 |
| 70 | x = uint 0 |
| 71 | d = ulong 0 |
| 72 | while lt p len s bound 4096 |
| 73 | c = get s p |
| 74 | if or lt c 48 gt c 57 |
| 75 | break |
| 76 | end |
| 77 | d = add d 1 |
| 78 | if gt d 9 |
| 79 | ret false |
| 80 | end |
| 81 | x = add mul x uint 10 uint sub c 48 |
| 82 | p = add p 1 |
| 83 | end |
| 84 | if eq d 0 |
| 85 | ret false |
| 86 | end |
| 87 | put v k x |
| 88 | if lt k 2 |
| 89 | if ge p len s |
| 90 | ret false |
| 91 | end |
| 92 | if ne get s p 46 |
| 93 | ret false |
| 94 | end |
| 95 | p = add p 1 |
| 96 | end |
| 97 | end |
| 98 | ret eq p len s |
| 99 | end |
| 100 | note copy hex field i into global array k of the kept rows (0 manifest, 1 keys, 2 cubin, 3 text) |
| 101 | fn ntkeep i ulong k ulong to void |
| 102 | n = ckhexn i |
| 103 | if eq k 0 |
| 104 | if ge n len nt_m |
| 105 | ckbad |
| 106 | end |
| 107 | for j ulong n bound 8193 |
| 108 | put nt_m j uchar ckhex i j |
| 109 | end |
| 110 | end |
| 111 | if eq k 1 |
| 112 | if gt n len nt_k |
| 113 | ckbad |
| 114 | end |
| 115 | for j ulong n bound 4096 |
| 116 | put nt_k j uchar ckhex i j |
| 117 | end |
| 118 | end |
| 119 | if eq k 2 |
| 120 | if gt n len nt_c |
| 121 | ckbad |
| 122 | end |
| 123 | for j ulong n bound 4096 |
| 124 | put nt_c j uchar ckhex i j |
| 125 | end |
| 126 | end |
| 127 | if eq k 3 |
| 128 | if gt n len nt_t |
| 129 | ckbad |
| 130 | end |
| 131 | for j ulong n bound 64 |
| 132 | put nt_t j uchar ckhex i j |
| 133 | end |
| 134 | end |
| 135 | put nt_n k n |
| 136 | end |
| 137 | note j rows |
| 138 | fn ntj to bool |
| 139 | js = new uchar 6 0 |
| 140 | if ne ckcnt 3 |
| 141 | ckbad |
| 142 | end |
| 143 | c = ntx 1 |
| 144 | if gt c 255 |
| 145 | ckbad |
| 146 | end |
| 147 | w = ckhexn 2 |
| 148 | o = ulong 0 |
| 149 | if ne c 0 |
| 150 | o = na_json uchar c edit js |
| 151 | end |
| 152 | if ne w add o 2 |
| 153 | ret false |
| 154 | end |
| 155 | if ne ckhex 2 0 34 |
| 156 | ret false |
| 157 | end |
| 158 | if ne ckhex 2 add o 1 34 |
| 159 | ret false |
| 160 | end |
| 161 | for j ulong o bound 6 |
| 162 | if ne ckhex 2 add j 1 ulong get js j |
| 163 | ret false |
| 164 | end |
| 165 | end |
| 166 | ret true |
| 167 | end |
| 168 | note v rows |
| 169 | fn ntv to bool |
| 170 | hv = new uchar 4096 0 |
| 171 | nv = new uchar 4096 0 |
| 172 | h3 = new uint 3 0 |
| 173 | n3 = new uint 3 0 |
| 174 | if ne ckcnt 4 |
| 175 | ckbad |
| 176 | end |
| 177 | a = ckhexn 1 |
| 178 | b = ckhexn 2 |
| 179 | if or gt a len hv gt b len nv |
| 180 | ckbad |
| 181 | end |
| 182 | for j ulong a bound 4096 |
| 183 | put hv j uchar ckhex 1 j |
| 184 | end |
| 185 | for j ulong b bound 4096 |
| 186 | put nv j uchar ckhex 2 j |
| 187 | end |
| 188 | got = ulong 2 |
| 189 | if ntsv part hv 0 a edit h3 |
| 190 | if ntsv part nv 0 b edit n3 |
| 191 | got = 0 |
| 192 | if na_ver view h3 view n3 |
| 193 | got = 1 |
| 194 | end |
| 195 | end |
| 196 | end |
| 197 | ret eq got ntr 3 |
| 198 | end |
| 199 | note L and M rows (k is the row letter) |
| 200 | fn ntl k ulong to bool |
| 201 | m = new uchar 8193 0 |
| 202 | ky = new uchar 4096 0 |
| 203 | if ne get nt_n 4 3 |
| 204 | ckbad |
| 205 | end |
| 206 | for j ulong len nt_m bound 8193 |
| 207 | put m j get nt_m j |
| 208 | end |
| 209 | kl = get nt_n 1 |
| 210 | for j ulong kl bound 4096 |
| 211 | put ky j get nt_k j |
| 212 | end |
| 213 | n = get nt_n 0 |
| 214 | want = ulong 0 |
| 215 | if eq k 76 |
| 216 | if ne ckcnt 3 |
| 217 | ckbad |
| 218 | end |
| 219 | n = cknum 1 |
| 220 | if ge n len m |
| 221 | ckbad |
| 222 | end |
| 223 | want = ntr 2 |
| 224 | else |
| 225 | if ne ckcnt 4 |
| 226 | ckbad |
| 227 | end |
| 228 | i = cknum 1 |
| 229 | v = cknum 2 |
| 230 | if or ge i n gt v 255 |
| 231 | ckbad |
| 232 | end |
| 233 | put m i uchar v |
| 234 | want = ntr 3 |
| 235 | end |
| 236 | got = ulong 0 |
| 237 | if na_layout part m 0 n part ky 0 kl 8192 |
| 238 | got = 1 |
| 239 | end |
| 240 | ret eq got want |
| 241 | end |
| 242 | note r, C, X, F and T rows (k is the row letter) |
| 243 | fn ntc k ulong to bool |
| 244 | cb = new uchar 4096 0 |
| 245 | tx = new uchar 64 0 |
| 246 | if ne get nt_n 5 1 |
| 247 | ckbad |
| 248 | end |
| 249 | cl = get nt_n 2 |
| 250 | tl = get nt_n 3 |
| 251 | for j ulong cl bound 4096 |
| 252 | put cb j get nt_c j |
| 253 | end |
| 254 | for j ulong tl bound 64 |
| 255 | put tx j get nt_t j |
| 256 | end |
| 257 | if eq k 114 |
| 258 | if ne ckcnt 3 |
| 259 | ckbad |
| 260 | end |
| 261 | n = cknum 1 |
| 262 | if or gt n 8 gt n cl |
| 263 | ckbad |
| 264 | end |
| 265 | ret eq na_read part cb 0 n n ntx 2 |
| 266 | end |
| 267 | ret ntcm k edit cb edit tx |
| 268 | end |
| 269 | note X and T rows: set byte I of the cubin copy, or xor byte I of the text copy, with V |
| 270 | fn ntmut k ulong cb edit uchar * tx edit uchar * to void |
| 271 | if ne ckcnt 4 |
| 272 | ckbad |
| 273 | end |
| 274 | i = cknum 1 |
| 275 | v = cknum 2 |
| 276 | if gt v 255 |
| 277 | ckbad |
| 278 | end |
| 279 | if eq k 88 |
| 280 | if ge i get nt_n 2 |
| 281 | ckbad |
| 282 | end |
| 283 | put cb i uchar v |
| 284 | else |
| 285 | if ge i get nt_n 3 |
| 286 | ckbad |
| 287 | end |
| 288 | put tx i xor get tx i uchar v |
| 289 | end |
| 290 | end |
| 291 | note F rows: na_cubin for a function name of fl bytes f (the test's names of 120 to 129 bytes and shorter) |
| 292 | fn ntff cb view uchar * fl ulong tx view uchar * to bool |
| 293 | fb = new uchar 130 102 |
| 294 | if gt fl len fb |
| 295 | ckbad |
| 296 | end |
| 297 | ret na_cubin cb part fb 0 fl tx |
| 298 | end |
| 299 | note C, X, F and T rows on the frame copies of the kept cubin cb and text tx |
| 300 | fn ntcm k ulong cb edit uchar * tx edit uchar * to bool |
| 301 | if or lt ckcnt 3 gt ckcnt 4 |
| 302 | ckbad |
| 303 | end |
| 304 | n = get nt_n 2 |
| 305 | if eq k 67 |
| 306 | n = cknum 1 |
| 307 | if or gt n get nt_n 2 ne ckcnt 3 |
| 308 | ckbad |
| 309 | end |
| 310 | end |
| 311 | if or eq k 88 eq k 84 |
| 312 | ntmut k edit cb edit tx |
| 313 | end |
| 314 | got = false |
| 315 | if eq k 70 |
| 316 | if ne ckcnt 3 |
| 317 | ckbad |
| 318 | end |
| 319 | got = ntff part cb 0 n cknum 1 part tx 0 get nt_n 3 |
| 320 | else |
| 321 | got = na_cubin part cb 0 n t_foo part tx 0 get nt_n 3 |
| 322 | end |
| 323 | r = ulong 0 |
| 324 | if got |
| 325 | r = 1 |
| 326 | end |
| 327 | ret eq r ntr sub ckcnt 1 |
| 328 | end |
| 329 | note K rows: a recorded known difference between the pending C and na_cubin |
| 330 | fn ntk to bool |
| 331 | cb = new uchar 4096 0 |
| 332 | tx = new uchar 64 0 |
| 333 | nm = new uchar 4096 0 |
| 334 | if ne ckcnt 7 |
| 335 | ckbad |
| 336 | end |
| 337 | a = ckhexn 1 |
| 338 | b = ckhexn 2 |
| 339 | f = ckhexn 3 |
| 340 | if or or gt a len cb gt b len tx gt f len nm |
| 341 | ckbad |
| 342 | end |
| 343 | for j ulong a bound 4096 |
| 344 | put cb j uchar ckhex 1 j |
| 345 | end |
| 346 | for j ulong b bound 64 |
| 347 | put tx j uchar ckhex 2 j |
| 348 | end |
| 349 | for j ulong f bound 4096 |
| 350 | put nm j uchar ckhex 3 j |
| 351 | end |
| 352 | if eq ntr 4 ntr 5 |
| 353 | ret false |
| 354 | end |
| 355 | got = ulong 0 |
| 356 | if na_cubin part cb 0 a part nm 0 f part tx 0 b |
| 357 | got = 1 |
| 358 | end |
| 359 | ret eq got ntr 5 |
| 360 | end |
| 361 | fn crow to bool |
| 362 | if ne cklen 0 1 |
| 363 | ckbad |
| 364 | end |
| 365 | k = ckch 0 0 |
| 366 | if eq k 106 |
| 367 | ret ntj |
| 368 | end |
| 369 | if eq k 118 |
| 370 | ret ntv |
| 371 | end |
| 372 | if eq k 107 |
| 373 | if ne ckcnt 2 |
| 374 | ckbad |
| 375 | end |
| 376 | ntkeep 1 1 |
| 377 | put nt_n 4 or get nt_n 4 1 |
| 378 | ret true |
| 379 | end |
| 380 | if eq k 98 |
| 381 | if ne ckcnt 2 |
| 382 | ckbad |
| 383 | end |
| 384 | ntkeep 1 0 |
| 385 | put nt_n 4 or get nt_n 4 2 |
| 386 | ret true |
| 387 | end |
| 388 | if eq k 99 |
| 389 | if ne ckcnt 3 |
| 390 | ckbad |
| 391 | end |
| 392 | ntkeep 1 2 |
| 393 | ntkeep 2 3 |
| 394 | put nt_n 5 1 |
| 395 | ret true |
| 396 | end |
| 397 | if eq k 75 |
| 398 | ret ntk |
| 399 | end |
| 400 | if or eq k 76 eq k 77 |
| 401 | ret ntl k |
| 402 | end |
| 403 | if not or or or or eq k 67 eq k 88 eq k 84 eq k 70 eq k 114 |
| 404 | ckbad |
| 405 | end |
| 406 | ret ntc k |
| 407 | end |