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 / native / abft / cand.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note native/abft candidate: a tiled GEMM run by W simulated workers that share tile buffers sa/sb and |
| 3 | note meet at two barriers per K tile (after loads, after compute). It runs only in a forked child; its |
| 4 | note one channel back to the evaluator is the memfd bytes plus its exit status. The scheduler applies |
| 5 | note the evaluator's perturbation (sched.om validated it before fork). Fault injectors are labelled |
| 6 | note controls selected by the frozen plan row, never by candidate logic. Label: SIMULATED. |
| 7 | note Element order is k ascending for every element under every schedule, so a fault-free run is |
| 8 | note bitwise schedule independent; any schedule dependence in the output is a fault. |
| 9 | const TK ulong 8 |
| 10 | const PLOAD ulong 0 |
| 11 | const PB1 ulong 1 |
| 12 | const PCOMP ulong 2 |
| 13 | const PB2 ulong 3 |
| 14 | const PDONE ulong 4 |
| 15 | const KDT ulong 1 |
| 16 | const KM ulong 2 |
| 17 | const KN ulong 3 |
| 18 | const KK ulong 4 |
| 19 | const KW ulong 5 |
| 20 | const KPOL ulong 6 |
| 21 | const KTGT ulong 7 |
| 22 | const KSITE ulong 8 |
| 23 | const KFLT ulong 9 |
| 24 | const KSUB ulong 10 |
| 25 | const KP1 ulong 11 |
| 26 | const KP2 ulong 12 |
| 27 | const KSEED ulong 13 |
| 28 | const KFLG ulong 15 |
| 29 | global kp ulong 16 |
| 30 | global kat ulong 1 |
| 31 | global krep ulong 1 |
| 32 | global cc ulong 65536 |
| 33 | global sa ulong 2048 |
| 34 | global sb ulong 2048 |
| 35 | global wph ulong 64 |
| 36 | global wt ulong 64 |
| 37 | global wu ulong 64 |
| 38 | global warr ulong 64 |
| 39 | global clast ulong 1 |
| 40 | global csh ulong 1 |
| 41 | global gprev ulong 65536 |
| 42 | global gref ulong 65536 |
| 43 | fn kf f ulong to ulong |
| 44 | ret get kp f |
| 45 | end |
| 46 | fn fact to bool |
| 47 | if eq kf KFLT 0 |
| 48 | ret false |
| 49 | end |
| 50 | if eq and kf KFLG 1 1 |
| 51 | ret eq get kat 0 0 |
| 52 | end |
| 53 | ret true |
| 54 | end |
| 55 | fn fis f ulong s ulong to bool |
| 56 | if fact |
| 57 | ret and eq kf KFLT f eq kf KSUB s |
| 58 | end |
| 59 | ret false |
| 60 | end |
| 61 | fn ntiles to ulong |
| 62 | ret div add kf KK sub TK 1 TK |
| 63 | end |
| 64 | fn ctk t ulong to ulong |
| 65 | k0 = mul t TK |
| 66 | tk = sub kf KK k0 |
| 67 | if gt tk TK |
| 68 | tk = TK |
| 69 | end |
| 70 | if fis 4 1 |
| 71 | if eq t sub ntiles 1 |
| 72 | tk = sub tk 1 |
| 73 | end |
| 74 | end |
| 75 | ret tk |
| 76 | end |
| 77 | fn rowskip i ulong to bool |
| 78 | if fact |
| 79 | if eq kf KFLT 3 |
| 80 | if ge kf KSUB 2 |
| 81 | p1 = kf KP1 |
| 82 | ret and ge i p1 lt i add p1 kf KP2 |
| 83 | end |
| 84 | end |
| 85 | end |
| 86 | ret false |
| 87 | end |
| 88 | fn cloada w ulong k0 ulong tk ulong to void |
| 89 | e = w |
| 90 | while lt e mul kf KM tk |
| 91 | i = div e tk |
| 92 | q = rem e tk |
| 93 | s = add mul i kf KK add k0 q |
| 94 | v = get ga s |
| 95 | put sa add mul i TK q v |
| 96 | e = add e kf KW |
| 97 | end |
| 98 | end |
| 99 | fn cloadb w ulong k0 ulong tk ulong to void |
| 100 | n = kf KN |
| 101 | e = w |
| 102 | while lt e mul tk n |
| 103 | q = div e n |
| 104 | j = rem e n |
| 105 | s = add mul add k0 q n j |
| 106 | if fis 4 2 |
| 107 | s = add mul j n add k0 q |
| 108 | end |
| 109 | v = get gb s |
| 110 | put sb add mul q n j v |
| 111 | e = add e kf KW |
| 112 | end |
| 113 | end |
| 114 | fn cload w ulong t ulong to void |
| 115 | k0 = mul t TK |
| 116 | tk = sub kf KK k0 |
| 117 | if gt tk TK |
| 118 | tk = TK |
| 119 | end |
| 120 | cloada w k0 tk |
| 121 | cloadb w k0 tk |
| 122 | end |
| 123 | fn bfu v ulong to f32 |
| 124 | ret bitcast f32 uint shl and v 65535 16 |
| 125 | end |
| 126 | fn crowf i ulong tk ulong to void |
| 127 | n = kf KN |
| 128 | for j ulong n |
| 129 | p = add mul i n j |
| 130 | acc = bitcast f32 uint get cc p |
| 131 | for q ulong tk |
| 132 | a = bfu get sa add mul i TK q |
| 133 | b = bfu get sb add mul q n j |
| 134 | acc = add acc mul a b |
| 135 | end |
| 136 | put cc p fbits acc |
| 137 | end |
| 138 | end |
| 139 | fn crowx i ulong tk ulong to void |
| 140 | n = kf KN |
| 141 | for j ulong n |
| 142 | p = add mul i n j |
| 143 | acc = get cc p |
| 144 | for q ulong tk |
| 145 | a = get sa add mul i TK q |
| 146 | b = get sb add mul q n j |
| 147 | acc = and add acc mul a b MASK |
| 148 | end |
| 149 | put cc p acc |
| 150 | end |
| 151 | end |
| 152 | fn crow i ulong t ulong to void |
| 153 | if rowskip i |
| 154 | ret |
| 155 | end |
| 156 | if eq kf KDT 0 |
| 157 | crowx i ctk t |
| 158 | else |
| 159 | crowf i ctk t |
| 160 | end |
| 161 | end |
| 162 | fn bset v ulong to bool |
| 163 | if fis 5 3 |
| 164 | ret lt v 2 |
| 165 | end |
| 166 | ret true |
| 167 | end |
| 168 | fn bpass c ulong to bool |
| 169 | ok = true |
| 170 | for v ulong kf KW |
| 171 | if bset v |
| 172 | if lt get warr v c |
| 173 | ok = false |
| 174 | end |
| 175 | end |
| 176 | end |
| 177 | ret ok |
| 178 | end |
| 179 | fn cready w ulong to bool |
| 180 | ph = get wph w |
| 181 | if eq ph PDONE |
| 182 | ret false |
| 183 | end |
| 184 | t = get wt w |
| 185 | if eq ph PB1 |
| 186 | ret bpass add mul t 2 1 |
| 187 | end |
| 188 | if eq ph PB2 |
| 189 | ret bpass add mul t 2 2 |
| 190 | end |
| 191 | ret true |
| 192 | end |
| 193 | fn cnext w ulong to void |
| 194 | t = add get wt w 1 |
| 195 | put wt w t |
| 196 | if eq t ntiles |
| 197 | put wph w PDONE |
| 198 | ret |
| 199 | end |
| 200 | if fis 5 4 |
| 201 | if eq w 0 |
| 202 | put wph w PDONE |
| 203 | ret |
| 204 | end |
| 205 | end |
| 206 | put wph w PLOAD |
| 207 | end |
| 208 | fn carrive w ulong to void |
| 209 | put warr w add get warr w 1 |
| 210 | end |
| 211 | fn cstep w ulong to void |
| 212 | ph = get wph w |
| 213 | t = get wt w |
| 214 | if eq ph PLOAD |
| 215 | cload w t |
| 216 | carrive w |
| 217 | put wu w 0 |
| 218 | if fis 5 1 |
| 219 | put wph w PCOMP |
| 220 | else |
| 221 | put wph w PB1 |
| 222 | end |
| 223 | ret |
| 224 | end |
| 225 | if eq ph PB1 |
| 226 | put wph w PCOMP |
| 227 | put wu w 0 |
| 228 | ret |
| 229 | end |
| 230 | if eq ph PB2 |
| 231 | cnext w |
| 232 | ret |
| 233 | end |
| 234 | i = add w mul get wu w kf KW |
| 235 | if lt i kf KM |
| 236 | crow i t |
| 237 | put wu w add get wu w 1 |
| 238 | i = add w mul get wu w kf KW |
| 239 | end |
| 240 | if ge i kf KM |
| 241 | carrive w |
| 242 | if fis 5 2 |
| 243 | cnext w |
| 244 | else |
| 245 | put wph w PB2 |
| 246 | end |
| 247 | end |
| 248 | end |
| 249 | fn csite w ulong to ulong |
| 250 | ph = get wph w |
| 251 | if eq ph PLOAD |
| 252 | ret 1 |
| 253 | end |
| 254 | if eq ph PCOMP |
| 255 | ret 2 |
| 256 | end |
| 257 | ret 3 |
| 258 | end |
| 259 | fn crr ex ulong to ulong |
| 260 | w = kf KW |
| 261 | s = get clast 0 |
| 262 | for q ulong w |
| 263 | v = rem add add s 1 q w |
| 264 | if ne v ex |
| 265 | if cready v |
| 266 | ret v |
| 267 | end |
| 268 | end |
| 269 | end |
| 270 | ret w |
| 271 | end |
| 272 | fn ccount to ulong |
| 273 | c = ulong 0 |
| 274 | for v ulong kf KW |
| 275 | if cready v |
| 276 | c = add c 1 |
| 277 | end |
| 278 | end |
| 279 | ret c |
| 280 | end |
| 281 | fn ckth k ulong to ulong |
| 282 | c = ulong 0 |
| 283 | for v ulong kf KW |
| 284 | if cready v |
| 285 | if eq c k |
| 286 | ret v |
| 287 | end |
| 288 | c = add c 1 |
| 289 | end |
| 290 | end |
| 291 | ret kf KW |
| 292 | end |
| 293 | fn cpick to ulong |
| 294 | w = kf KW |
| 295 | n = ccount |
| 296 | if eq n 0 |
| 297 | ret w |
| 298 | end |
| 299 | pol = kf KPOL |
| 300 | tg = kf KTGT |
| 301 | if eq pol 1 |
| 302 | ret ckth rbelow 2 n |
| 303 | end |
| 304 | if eq pol 2 |
| 305 | if cready tg |
| 306 | ret tg |
| 307 | end |
| 308 | end |
| 309 | if eq pol 3 |
| 310 | if cready tg |
| 311 | if eq csite tg kf KSITE |
| 312 | if gt n 1 |
| 313 | ret crr tg |
| 314 | end |
| 315 | end |
| 316 | end |
| 317 | end |
| 318 | ret crr w |
| 319 | end |
| 320 | fn chang to void |
| 321 | note Simulated device hang: no worker can advance; the evaluator deadline kills this process. |
| 322 | for q ulong 1000000 |
| 323 | z = sleepns 1000000 |
| 324 | if lt z 0 |
| 325 | trap 9 |
| 326 | end |
| 327 | end |
| 328 | trap 10 |
| 329 | end |
| 330 | fn cinit to void |
| 331 | m = kf KM |
| 332 | n = kf KN |
| 333 | for e ulong mul m n |
| 334 | put cc e 0 |
| 335 | end |
| 336 | if fact |
| 337 | if eq kf KFLT 3 |
| 338 | for e ulong mul m n |
| 339 | i = div e n |
| 340 | if and ge i kf KP1 lt i add kf KP1 kf KP2 |
| 341 | if eq kf KSUB 3 |
| 342 | put cc e get gref e |
| 343 | else |
| 344 | put cc e get gprev e |
| 345 | end |
| 346 | end |
| 347 | end |
| 348 | end |
| 349 | end |
| 350 | for w ulong kf KW |
| 351 | put wph w PLOAD |
| 352 | put wt w 0 |
| 353 | put wu w 0 |
| 354 | put warr w 0 |
| 355 | end |
| 356 | put clast 0 sub kf KW 1 |
| 357 | put csh 0 14695981039346656037 |
| 358 | end |
| 359 | fn cflip e ulong b ulong to void |
| 360 | put cc e xor get cc e shl ulong 1 b |
| 361 | end |
| 362 | fn cbit c ulong to ulong |
| 363 | if eq c 1 |
| 364 | ret add 23 rbelow 3 9 |
| 365 | end |
| 366 | if eq c 2 |
| 367 | ret rbelow 3 8 |
| 368 | end |
| 369 | ret rbelow 3 32 |
| 370 | end |
| 371 | fn cpos to ulong |
| 372 | ret rbelow 3 mul kf KM kf KN |
| 373 | end |
| 374 | fn cfadd e ulong d f32 to void |
| 375 | put cc e fbits add bitcast f32 uint get cc e d |
| 376 | end |
| 377 | fn crect b ulong to void |
| 378 | m = kf KM |
| 379 | n = kf KN |
| 380 | i1 = rbelow 3 m |
| 381 | i2 = rem add add i1 1 rbelow 3 sub m 1 m |
| 382 | j1 = rbelow 3 n |
| 383 | j2 = rem add add j1 1 rbelow 3 sub n 1 n |
| 384 | if eq b 32 |
| 385 | e = f32 shl ulong 1 kf KP1 |
| 386 | cfadd add mul i1 n j1 e |
| 387 | cfadd add mul i1 n j2 neg e |
| 388 | cfadd add mul i2 n j1 neg e |
| 389 | cfadd add mul i2 n j2 e |
| 390 | ret |
| 391 | end |
| 392 | cflip add mul i1 n j1 b |
| 393 | cflip add mul i1 n j2 b |
| 394 | cflip add mul i2 n j1 b |
| 395 | cflip add mul i2 n j2 b |
| 396 | end |
| 397 | fn cshift to void |
| 398 | m = kf KM |
| 399 | n = kf KN |
| 400 | i = sub m 1 |
| 401 | while gt i 0 |
| 402 | for j ulong n |
| 403 | put cc add mul i n j get cc add mul sub i 1 n j |
| 404 | end |
| 405 | i = sub i 1 |
| 406 | end |
| 407 | for j ulong n |
| 408 | put cc j 0 |
| 409 | end |
| 410 | end |
| 411 | fn cpost to void |
| 412 | if not fact |
| 413 | ret |
| 414 | end |
| 415 | f = kf KFLT |
| 416 | if eq f 1 |
| 417 | cflip cpos kf KP2 |
| 418 | end |
| 419 | if eq f 2 |
| 420 | for q ulong kf KP1 |
| 421 | cflip cpos cbit kf KP2 |
| 422 | end |
| 423 | end |
| 424 | if fis 4 3 |
| 425 | cshift |
| 426 | end |
| 427 | if fis 4 4 |
| 428 | note Out-of-bounds store: Omega traps 3 (exit 103) before writing. |
| 429 | put cc add mul kf KM kf KN 65536 0 |
| 430 | end |
| 431 | if fis 6 1 |
| 432 | crect 31 |
| 433 | end |
| 434 | if fis 6 3 |
| 435 | crect 32 |
| 436 | end |
| 437 | end |
| 438 | note Child entry: runs the schedule to completion, applies post-run injectors, returns step count. |
| 439 | fn crun to ulong |
| 440 | cinit |
| 441 | note Stream 2 varies with rep and attempt (a retry is a new schedule); stream 3 varies with rep only, |
| 442 | note so a persistent fault lands on the same elements again on retry. |
| 443 | base = add mul kf KSEED 2654435761 mul get krep 0 7919 |
| 444 | rseed 2 add base mul get kat 0 104729 |
| 445 | rseed 3 add base 1 |
| 446 | steps = ulong 0 |
| 447 | while true bound 999999 |
| 448 | w = cpick |
| 449 | if eq w kf KW |
| 450 | if eq ccount 0 |
| 451 | done = true |
| 452 | for v ulong kf KW |
| 453 | if ne get wph v PDONE |
| 454 | done = false |
| 455 | end |
| 456 | end |
| 457 | if done |
| 458 | break |
| 459 | end |
| 460 | chang |
| 461 | end |
| 462 | end |
| 463 | put clast 0 w |
| 464 | put csh 0 fnvw get csh 0 w |
| 465 | cstep w |
| 466 | steps = add steps 1 |
| 467 | end |
| 468 | cpost |
| 469 | ret steps |
| 470 | end |