interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / gpu / runtime / classes.om

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