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 / runtime / check / hostrest-check.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note gpu/runtime/check/hostrest-check.om: runs ah_rest of gpu/nvidia/om/apiviews/hostrest.om for every op 0..24 on |
| 3 | note xorshift64 inputs with boundary values, and prints what the C oracle printed for omega_ah_c of CUDApp |
| 4 | note src/omega_gpu_api_hostrest.h (gpu/runtime/README.md). gpu/runtime/check/hostrest.expect.txt is that oracle's |
| 5 | note output. Composed after hostrest.om. |
| 6 | global hk_s ulong 1 |
| 7 | global hk_o uchar * |
| 8 | global hk_n ulong 1 |
| 9 | global hk_b ulong 32 |
| 10 | text hk_to "op " |
| 11 | text hk_tc " case " |
| 12 | text hk_tr " r=" |
| 13 | text hk_tp " p=" |
| 14 | text hk_tn " cases=" |
| 15 | text hk_tz " nonzero=" |
| 16 | text hk_th " fnv=" |
| 17 | text hk_mem "hostrest-check: the host refused memory\n" |
| 18 | fn hkdie to void |
| 19 | w = write 2 hk_mem 0 len hk_mem |
| 20 | exit 4 |
| 21 | end |
| 22 | fn hkoc c ulong to void |
| 23 | n = get hk_n 0 |
| 24 | if ge n len hk_o |
| 25 | r = enlarge hk_o add mul n 2 4096 |
| 26 | if ne r 0 |
| 27 | hkdie |
| 28 | end |
| 29 | end |
| 30 | put hk_o n uchar c |
| 31 | put hk_n 0 add n 1 |
| 32 | end |
| 33 | fn hkt t view uchar * to void |
| 34 | for i ulong len t |
| 35 | hkoc ulong get t i |
| 36 | end |
| 37 | end |
| 38 | fn hknum v ulong to void |
| 39 | if ge v 10 |
| 40 | hknum div v 10 |
| 41 | end |
| 42 | hkoc add 48 rem v 10 |
| 43 | end |
| 44 | fn hkhex v ulong to void |
| 45 | for i ulong 16 |
| 46 | c = and shr v mul 4 sub 15 i 15 |
| 47 | if lt c 10 |
| 48 | hkoc add 48 c |
| 49 | else |
| 50 | hkoc add 87 c |
| 51 | end |
| 52 | end |
| 53 | end |
| 54 | fn hkflush to void |
| 55 | n = get hk_n 0 |
| 56 | o = ulong 0 |
| 57 | while lt o n bound 9223372036854775807 |
| 58 | x = write 1 hk_o o sub n o |
| 59 | if le x 0 |
| 60 | exit 3 |
| 61 | end |
| 62 | o = add o ulong x |
| 63 | end |
| 64 | put hk_n 0 0 |
| 65 | end |
| 66 | fn hkrnd to ulong |
| 67 | s = get hk_s 0 |
| 68 | s = xor s shl s 13 |
| 69 | s = xor s shr s 7 |
| 70 | s = xor s shl s 17 |
| 71 | put hk_s 0 s |
| 72 | ret s |
| 73 | end |
| 74 | fn hkval to ulong |
| 75 | r = hkrnd |
| 76 | sel = and r 7 |
| 77 | if lt sel 4 |
| 78 | ret get hk_b and shr r 3 31 |
| 79 | end |
| 80 | if lt sel 6 |
| 81 | ret and shr r 3 127 |
| 82 | end |
| 83 | ret hkrnd |
| 84 | end |
| 85 | fn hkfnv h ulong w ulong to ulong |
| 86 | for b ulong 8 |
| 87 | h = mul xor h and shr w mul 8 b 255 1099511628211 |
| 88 | end |
| 89 | ret h |
| 90 | end |
| 91 | fn hknz v ulong to ulong |
| 92 | if eq v 0 |
| 93 | ret 1 |
| 94 | end |
| 95 | ret v |
| 96 | end |
| 97 | note the oracle's dom(): keeps a case where the C is defined (no division by zero) and the Omega takes 32-bit |
| 98 | note values (uint get is a checked conversion); the same rewrites in the same order |
| 99 | fn hkdom op ulong p edit ulong 16 to void |
| 100 | u = or eq op 2 or and ge op 4 le op 10 or eq op 13 or eq op 15 eq op 24 |
| 101 | if u |
| 102 | for i ulong 5 |
| 103 | put p i and get p i 4294967295 |
| 104 | end |
| 105 | end |
| 106 | if eq op 8 |
| 107 | put p 0 and get p 0 16777215 |
| 108 | put p 1 add 1 rem get p 1 134217727 |
| 109 | put p 3 add 1 rem get p 3 134217727 |
| 110 | end |
| 111 | if or eq op 9 or eq op 15 eq op 22 |
| 112 | put p 1 hknz get p 1 |
| 113 | end |
| 114 | if eq op 10 |
| 115 | put p 1 hknz get p 1 |
| 116 | put p 2 hknz get p 2 |
| 117 | end |
| 118 | if eq op 12 |
| 119 | put p 3 hknz get p 3 |
| 120 | end |
| 121 | if eq op 24 |
| 122 | put p 1 add 1 rem get p 1 134217727 |
| 123 | end |
| 124 | note op 19: the C answers 1 and ah_rest answers p[3]; both CUDApp callers (src/omega_gpu_fp8_api.c) pass p[3] = 1 |
| 125 | if and eq op 19 ne get p 3 0 |
| 126 | put p 3 1 |
| 127 | end |
| 128 | end |
| 129 | note the oracle's shape(): every other case of ops 8, 16 and 19 takes the shape of CUDApp |
| 130 | note tests/api_hostrest_test.c, so that their accepting answers are reached |
| 131 | fn hkshape op ulong c ulong p edit ulong 16 to void |
| 132 | if ne rem c 2 0 |
| 133 | ret |
| 134 | end |
| 135 | if eq op 8 |
| 136 | put p 0 mul rem get p 0 129 512 |
| 137 | put p 1 16 |
| 138 | put p 2 1 |
| 139 | put p 3 8 |
| 140 | put p 4 rem get p 4 3 |
| 141 | put p 5 1 |
| 142 | end |
| 143 | if eq op 16 |
| 144 | for i ulong 8 |
| 145 | put p i 0 |
| 146 | end |
| 147 | end |
| 148 | if eq op 19 |
| 149 | put p 0 0 |
| 150 | put p 1 1 |
| 151 | end |
| 152 | end |
| 153 | fn hkline op ulong c ulong r ulong p view ulong 16 to void |
| 154 | hkt hk_to |
| 155 | hknum op |
| 156 | hkt hk_tc |
| 157 | hknum c |
| 158 | hkt hk_tr |
| 159 | hknum r |
| 160 | hkt hk_tp |
| 161 | for i ulong 9 |
| 162 | hknum get p i |
| 163 | if lt i 8 |
| 164 | hkoc 44 |
| 165 | else |
| 166 | hkoc 10 |
| 167 | end |
| 168 | end |
| 169 | end |
| 170 | fn hkop op ulong to void |
| 171 | nc = ulong 4096 |
| 172 | p = new ulong 16 0 |
| 173 | h = ulong 14695981039346656037 |
| 174 | nz = ulong 0 |
| 175 | for c ulong nc |
| 176 | for i ulong 9 |
| 177 | put p i hkval |
| 178 | end |
| 179 | for i ulong 7 |
| 180 | put p add i 9 0 |
| 181 | end |
| 182 | hkdom op p |
| 183 | hkshape op c p |
| 184 | r = ah_rest op p |
| 185 | if lt c 2 |
| 186 | hkline op c r p |
| 187 | end |
| 188 | h = hkfnv h r |
| 189 | if ne r 0 |
| 190 | nz = add nz 1 |
| 191 | end |
| 192 | end |
| 193 | hkt hk_to |
| 194 | hknum op |
| 195 | hkt hk_tn |
| 196 | hknum nc |
| 197 | hkt hk_tz |
| 198 | hknum nz |
| 199 | hkt hk_th |
| 200 | hkhex h |
| 201 | hkoc 10 |
| 202 | hkflush |
| 203 | end |
| 204 | fn main to int |
| 205 | put hk_s 0 88172645463325252 |
| 206 | put hk_b 0 0 |
| 207 | put hk_b 1 1 |
| 208 | put hk_b 2 2 |
| 209 | put hk_b 3 3 |
| 210 | put hk_b 4 4 |
| 211 | put hk_b 5 8 |
| 212 | put hk_b 6 15 |
| 213 | put hk_b 7 16 |
| 214 | put hk_b 8 47 |
| 215 | put hk_b 9 48 |
| 216 | put hk_b 10 49 |
| 217 | put hk_b 11 57 |
| 218 | put hk_b 12 128 |
| 219 | put hk_b 13 256 |
| 220 | put hk_b 14 383 |
| 221 | put hk_b 15 384 |
| 222 | put hk_b 16 512 |
| 223 | put hk_b 17 1000 |
| 224 | put hk_b 18 4095 |
| 225 | put hk_b 19 4096 |
| 226 | put hk_b 20 4097 |
| 227 | put hk_b 21 65535 |
| 228 | put hk_b 22 65536 |
| 229 | put hk_b 23 999999 |
| 230 | put hk_b 24 2147483647 |
| 231 | put hk_b 25 4294967295 |
| 232 | put hk_b 26 4294967296 |
| 233 | put hk_b 27 1099511627776 |
| 234 | put hk_b 28 9223372036854775808 |
| 235 | put hk_b 29 18446744073709551615 |
| 236 | put hk_b 30 32 |
| 237 | put hk_b 31 129 |
| 238 | for op ulong 25 |
| 239 | hkop op |
| 240 | end |
| 241 | ret 0 |
| 242 | end |