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 / classes.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note gpu/runtime/classes.om: what still blocks each C file of CUDApp src/ that no generator wrote and no Omega unit |
| 3 | note replaces, in seeded Omega (OM-2 program mode, Linux AArch64). Build and run from the repository root: |
| 4 | note { printf 'om2\n'; cat gpu/runtime/classes.om; } | seed/out/omc > classes && ./classes > gpu/runtime/CLASSES.tsv |
| 5 | note Inputs: gpu/runtime/INVENTORY.tsv (written by inventory.om) and gpu/runtime/cudapp-cfacts.tsv (written by |
| 6 | note cfacts.om from a CUDApp checkout; the README says how). Every INVENTORY row of kind c, h or inc must have |
| 7 | note exactly one cudapp-cfacts.tsv row and the other way round, or the program refuses with exit 3. |
| 8 | note Output: a header, one row per INVENTORY row whose origin is unrecorded, tab separated |
| 9 | note path kind class gen act pend fns omfn devfn hostl shell (the last eight are cudapp-cfacts.tsv's facts) |
| 10 | note then summary lines starting with #. The class, applied in this order: |
| 11 | note r an Omega file in this repository replaces it (INVENTORY omega = rewritten) |
| 12 | note c a generator wrote it (gen = 1): the generator, not the file, is what to rewrite |
| 13 | note d no function in the default build, and lines kept only behind a pending flag (pend > 0), not a header: |
| 14 | note the C kept as a reference for comparison |
| 15 | note b no function in the default build otherwise (a header of a C interface), or more lines in functions that |
| 16 | note hand work to Omega or call a device word (shell) than in functions of host logic (hostl): a C entry point |
| 17 | note over Omega or the chip, waiting for Omega to produce a C-callable library |
| 18 | note a more lines of host logic than of shell: C logic that an Omega rewrite can be checked against now |
| 19 | note Exit 0, 3 an input is missing, malformed or the two inputs disagree, 4 the host refused memory. |
| 20 | text cl_finv "gpu/runtime/INVENTORY.tsv" |
| 21 | text cl_fcf "gpu/runtime/cudapp-cfacts.tsv" |
| 22 | text cl_hinv "path\tkind\tomega_src\torigin\tomega\tdetail" |
| 23 | text cl_hcf "path\tgen\tact\tpend\tfns\tomfn\tdevfn\thostl\tshell" |
| 24 | text cl_hout "path\tkind\tclass\tgen\tact\tpend\tfns\tomfn\tdevfn\thostl\tshell\n" |
| 25 | text cl_unrec "unrecorded" |
| 26 | text cl_rewr "rewritten" |
| 27 | text cl_kc "c" |
| 28 | text cl_kh "h" |
| 29 | text cl_kinc "inc" |
| 30 | text cl_s_rows "# rows=" |
| 31 | text cl_s_a "# class a: hostl=" |
| 32 | text cl_s_b "# class b: shell=" |
| 33 | text cl_s_d "# class d: pend=" |
| 34 | text cl_s_shell " shell=" |
| 35 | text cl_s_hostl " hostl=" |
| 36 | text cl_s_files " files=" |
| 37 | text cl_v "rabcd" |
| 38 | text cl_e_read "classes: cannot read " |
| 39 | text cl_e_hdr "classes: an input does not start with its header: " |
| 40 | text cl_e_num "classes: a cudapp-cfacts.tsv field is not a decimal number\n" |
| 41 | text cl_e_miss "classes: an INVENTORY row of kind c, h or inc has no cudapp-cfacts.tsv row: " |
| 42 | text cl_e_count "classes: cudapp-cfacts.tsv has rows that INVENTORY.tsv does not list as c, h or inc\n" |
| 43 | text cl_e_mem "classes: the host refused memory\n" |
| 44 | global cl_t uchar * |
| 45 | global cl_o uchar * |
| 46 | global cl_pa uchar 4096 |
| 47 | note cl_n: 0 pool length, 1 output length, 2 3 INVENTORY.tsv's range, 4 5 cudapp-cfacts.tsv's range, |
| 48 | note 8 c/h/inc INVENTORY rows, 9 rows out, 10..14 rows of class r a b c d, 15 16 class a hostl shell, |
| 49 | note 17 18 class b shell hostl, 19 class d pend |
| 50 | global cl_n ulong 32 |
| 51 | fn cldie t view uchar * code int to void |
| 52 | r = write 2 t 0 len t |
| 53 | exit code |
| 54 | end |
| 55 | fn cldier t view uchar * a ulong b ulong to void |
| 56 | r = write 2 t 0 len t |
| 57 | r = write 2 cl_t a sub b a |
| 58 | q = new uchar 1 10 |
| 59 | r = write 2 q 0 1 |
| 60 | exit 3 |
| 61 | end |
| 62 | fn clgrow n ulong to void |
| 63 | if ge n len cl_t |
| 64 | r = enlarge cl_t add mul n 2 131072 |
| 65 | if ne r 0 |
| 66 | cldie cl_e_mem 4 |
| 67 | end |
| 68 | end |
| 69 | end |
| 70 | note ---- output |
| 71 | fn cloc c ulong to void |
| 72 | n = get cl_n 1 |
| 73 | if ge n len cl_o |
| 74 | r = enlarge cl_o add mul n 2 65536 |
| 75 | if ne r 0 |
| 76 | cldie cl_e_mem 4 |
| 77 | end |
| 78 | end |
| 79 | put cl_o n uchar c |
| 80 | put cl_n 1 add n 1 |
| 81 | end |
| 82 | fn clot t view uchar * to void |
| 83 | for i ulong len t bound 4096 |
| 84 | cloc ulong get t i |
| 85 | end |
| 86 | end |
| 87 | fn clor a ulong b ulong to void |
| 88 | for i ulong sub b a bound 9223372036854775807 |
| 89 | cloc ulong get cl_t add a i |
| 90 | end |
| 91 | end |
| 92 | fn clnum v ulong to void |
| 93 | if ge v 10 |
| 94 | clnum div v 10 |
| 95 | end |
| 96 | cloc add 48 rem v 10 |
| 97 | end |
| 98 | fn clflush to void |
| 99 | n = get cl_n 1 |
| 100 | o = ulong 0 |
| 101 | while lt o n bound 9223372036854775807 |
| 102 | x = write 1 cl_o o sub n o |
| 103 | if le x 0 |
| 104 | exit 3 |
| 105 | end |
| 106 | o = add o ulong x |
| 107 | end |
| 108 | end |
| 109 | note ---- input: the file named t appended to cl_t; slot k gets its start, k+1 its end |
| 110 | fn clload t view uchar * k ulong to void |
| 111 | for i ulong len t bound 4096 |
| 112 | put cl_pa i get t i |
| 113 | end |
| 114 | f0 = fopen cl_pa 0 len t int 524288 int 0 |
| 115 | fd = int f0 |
| 116 | if lt fd 0 |
| 117 | r = write 2 cl_e_read 0 len cl_e_read |
| 118 | cldie t 3 |
| 119 | end |
| 120 | s = get cl_n 0 |
| 121 | n = s |
| 122 | while true bound 9223372036854775807 |
| 123 | clgrow add n 65536 |
| 124 | x = read fd cl_t n sub len cl_t n |
| 125 | if lt x 0 |
| 126 | r = write 2 cl_e_read 0 len cl_e_read |
| 127 | cldie t 3 |
| 128 | end |
| 129 | if eq x 0 |
| 130 | break |
| 131 | end |
| 132 | n = add n ulong x |
| 133 | end |
| 134 | r = fclose fd |
| 135 | put cl_n 0 n |
| 136 | put cl_n k s |
| 137 | put cl_n add k 1 n |
| 138 | end |
| 139 | note ---- ranges of cl_t |
| 140 | fn cleol p ulong e ulong to ulong |
| 141 | q = p |
| 142 | while lt q e bound 9223372036854775807 |
| 143 | if eq get cl_t q 10 |
| 144 | ret q |
| 145 | end |
| 146 | q = add q 1 |
| 147 | end |
| 148 | ret e |
| 149 | end |
| 150 | note the end of the field that starts at p in a line ending at q |
| 151 | fn clfe p ulong q ulong to ulong |
| 152 | x = p |
| 153 | while lt x q bound 9223372036854775807 |
| 154 | if eq get cl_t x 9 |
| 155 | ret x |
| 156 | end |
| 157 | x = add x 1 |
| 158 | end |
| 159 | ret q |
| 160 | end |
| 161 | note the start of field k of the line [p, q), or q when it has fewer fields |
| 162 | fn clfs p ulong q ulong k ulong to ulong |
| 163 | x = p |
| 164 | for j ulong k bound 9223372036854775807 |
| 165 | x = clfe x q |
| 166 | if ge x q |
| 167 | ret q |
| 168 | end |
| 169 | x = add x 1 |
| 170 | end |
| 171 | ret x |
| 172 | end |
| 173 | fn cleqt a ulong b ulong t view uchar * to bool |
| 174 | if ne sub b a len t |
| 175 | ret false |
| 176 | end |
| 177 | for i ulong len t bound 4096 |
| 178 | if ne get cl_t add a i get t i |
| 179 | ret false |
| 180 | end |
| 181 | end |
| 182 | ret true |
| 183 | end |
| 184 | fn cleqr a ulong b ulong c ulong d ulong to bool |
| 185 | if ne sub b a sub d c |
| 186 | ret false |
| 187 | end |
| 188 | for i ulong sub b a bound 9223372036854775807 |
| 189 | if ne get cl_t add a i get cl_t add c i |
| 190 | ret false |
| 191 | end |
| 192 | end |
| 193 | ret true |
| 194 | end |
| 195 | note field k of the line [p, q) as a decimal number |
| 196 | fn clfnum p ulong q ulong k ulong to ulong |
| 197 | a = clfs p q k |
| 198 | b = clfe a q |
| 199 | if ge a b |
| 200 | cldie cl_e_num 3 |
| 201 | end |
| 202 | v = ulong 0 |
| 203 | for i ulong sub b a bound 9223372036854775807 |
| 204 | c = ulong get cl_t add a i |
| 205 | if or lt c 48 gt c 57 |
| 206 | cldie cl_e_num 3 |
| 207 | end |
| 208 | v = add mul v 10 sub c 48 |
| 209 | end |
| 210 | ret v |
| 211 | end |
| 212 | note the cudapp-cfacts.tsv line (its start) whose path is cl_t[a, b), or the end of that file when none |
| 213 | fn clfind a ulong b ulong to ulong |
| 214 | e = get cl_n 5 |
| 215 | p = cleol get cl_n 4 e |
| 216 | p = add p 1 |
| 217 | while lt p e bound 9223372036854775807 |
| 218 | q = cleol p e |
| 219 | f = clfe p q |
| 220 | if cleqr p f a b |
| 221 | ret p |
| 222 | end |
| 223 | p = add q 1 |
| 224 | end |
| 225 | ret e |
| 226 | end |
| 227 | note each input starts with its header line |
| 228 | fn clhdr k ulong t view uchar * to void |
| 229 | s = get cl_n k |
| 230 | e = get cl_n add k 1 |
| 231 | q = cleol s e |
| 232 | if not cleqt s q t |
| 233 | cldier cl_e_hdr s q |
| 234 | end |
| 235 | end |
| 236 | note the class of the INVENTORY line [p, q) whose facts line starts at c |
| 237 | fn clclass p ulong q ulong c ulong to ulong |
| 238 | o = clfs p q 4 |
| 239 | if cleqt o clfe o q cl_rewr |
| 240 | ret 114 |
| 241 | end |
| 242 | e = cleol c get cl_n 5 |
| 243 | if eq clfnum c e 1 1 |
| 244 | ret 99 |
| 245 | end |
| 246 | if eq clfnum c e 4 0 |
| 247 | k = clfs p q 1 |
| 248 | if and gt clfnum c e 3 0 not cleqt k clfe k q cl_kh |
| 249 | ret 100 |
| 250 | end |
| 251 | ret 98 |
| 252 | end |
| 253 | if gt clfnum c e 7 clfnum c e 8 |
| 254 | ret 97 |
| 255 | end |
| 256 | ret 98 |
| 257 | end |
| 258 | fn cladd k ulong v ulong to void |
| 259 | put cl_n k add get cl_n k v |
| 260 | end |
| 261 | note write the row of the INVENTORY line [p, q) and add it to the summary |
| 262 | fn clrow p ulong q ulong c ulong to void |
| 263 | e = cleol c get cl_n 5 |
| 264 | cl = clclass p q c |
| 265 | k = clfs p q 1 |
| 266 | clor p clfe p q |
| 267 | cloc 9 |
| 268 | clor k clfe k q |
| 269 | cloc 9 |
| 270 | cloc cl |
| 271 | cloc 9 |
| 272 | f = clfs c e 1 |
| 273 | clor f e |
| 274 | cloc 10 |
| 275 | cladd 9 1 |
| 276 | if eq cl 114 |
| 277 | cladd 10 1 |
| 278 | end |
| 279 | if eq cl 97 |
| 280 | cladd 11 1 |
| 281 | cladd 15 clfnum c e 7 |
| 282 | cladd 16 clfnum c e 8 |
| 283 | end |
| 284 | if eq cl 98 |
| 285 | cladd 12 1 |
| 286 | cladd 17 clfnum c e 8 |
| 287 | cladd 18 clfnum c e 7 |
| 288 | end |
| 289 | if eq cl 99 |
| 290 | cladd 13 1 |
| 291 | end |
| 292 | if eq cl 100 |
| 293 | cladd 14 1 |
| 294 | cladd 19 clfnum c e 3 |
| 295 | end |
| 296 | end |
| 297 | note one INVENTORY line [p, q): check that a c, h or inc row has facts; write the row when unrecorded |
| 298 | fn clline p ulong q ulong to void |
| 299 | k = clfs p q 1 |
| 300 | ke = clfe k q |
| 301 | if or or cleqt k ke cl_kc cleqt k ke cl_kh cleqt k ke cl_kinc |
| 302 | cladd 8 1 |
| 303 | c = clfind p clfe p q |
| 304 | if ge c get cl_n 5 |
| 305 | cldier cl_e_miss p clfe p q |
| 306 | end |
| 307 | o = clfs p q 3 |
| 308 | if cleqt o clfe o q cl_unrec |
| 309 | clrow p q c |
| 310 | end |
| 311 | end |
| 312 | end |
| 313 | fn clsum to void |
| 314 | clot cl_s_rows |
| 315 | clnum get cl_n 9 |
| 316 | cloc 32 |
| 317 | for j ulong 5 |
| 318 | cloc ulong get cl_v j |
| 319 | cloc 61 |
| 320 | clnum get cl_n add 10 j |
| 321 | if lt j 4 |
| 322 | cloc 32 |
| 323 | end |
| 324 | end |
| 325 | cloc 10 |
| 326 | clot cl_s_a |
| 327 | clnum get cl_n 15 |
| 328 | clot cl_s_shell |
| 329 | clnum get cl_n 16 |
| 330 | clot cl_s_files |
| 331 | clnum get cl_n 11 |
| 332 | cloc 10 |
| 333 | clot cl_s_b |
| 334 | clnum get cl_n 17 |
| 335 | clot cl_s_hostl |
| 336 | clnum get cl_n 18 |
| 337 | clot cl_s_files |
| 338 | clnum get cl_n 12 |
| 339 | cloc 10 |
| 340 | clot cl_s_d |
| 341 | clnum get cl_n 19 |
| 342 | clot cl_s_files |
| 343 | clnum get cl_n 14 |
| 344 | cloc 10 |
| 345 | end |
| 346 | note every facts row has eight decimal fields after its path and no more |
| 347 | fn clrowok p ulong q ulong to void |
| 348 | for k ulong 8 |
| 349 | v = clfnum p q add k 1 |
| 350 | end |
| 351 | if lt clfs p q 9 q |
| 352 | cldie cl_e_num 3 |
| 353 | end |
| 354 | end |
| 355 | fn main to int |
| 356 | clload cl_finv 2 |
| 357 | clload cl_fcf 4 |
| 358 | clhdr 2 cl_hinv |
| 359 | clhdr 4 cl_hcf |
| 360 | nf = ulong 0 |
| 361 | e = get cl_n 5 |
| 362 | p = add cleol get cl_n 4 e 1 |
| 363 | while lt p e bound 9223372036854775807 |
| 364 | q = cleol p e |
| 365 | clrowok p q |
| 366 | p = add q 1 |
| 367 | nf = add nf 1 |
| 368 | end |
| 369 | clot cl_hout |
| 370 | e = get cl_n 3 |
| 371 | p = add cleol get cl_n 2 e 1 |
| 372 | while lt p e bound 9223372036854775807 |
| 373 | q = cleol p e |
| 374 | if ne get cl_t p 35 |
| 375 | clline p q |
| 376 | end |
| 377 | p = add q 1 |
| 378 | end |
| 379 | if ne nf get cl_n 8 |
| 380 | cldie cl_e_count 3 |
| 381 | end |
| 382 | clsum |
| 383 | clflush |
| 384 | ret 0 |
| 385 | end |