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 / nvidia / checks / avtab.om

389 lines · 9638 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note gpu/nvidia/checks/avtab.om: the table units of gpu/nvidia/om/api (av_gtab, av_range, av_total, av_best, av_max,
3note av_blks, av_rfit, av_hmap, av_eff, av_reset, av_gath with av_cseg, av_fold of attn_tables.om, and av_table with
4note av_touch) against the pending C bodies of CUDApp src/omega_attn_tables.h (CUDAPP_MIGRATION_PENDING_ATTN_VIEWS,
5note with the pending C of api_plan): the table calls of tests/attn_views_cases.c (the fixture of
6note tests/attn_views_diff.c) and sweeps around them. Each unit is called the way the C binding calls it (the same
7note views, the same q words, the same chunks for av_touch). attn_om2.om carries om2, so it is the head. Rows:
8note OP A B C D Q0..Q7 X r h
9note Each of A B C D is l a b m k c p1 v1 p2 v2: element i (< l) is (a*i + b) mod m, or word b+i of X (16 hex
10note digits each, - when no spec uses it) when m is 0; then c when k > 0 and i mod k is 0; then v1 at i = p1 and
11note v2 at i = p2; cut to the element width (uint; uchar for gath; the bits of an f32 for fold). r is the answer
12note (the unit's rc for a call the C makes void, its answer cut to 32 bits where the binding cuts); h is the FNV-1a
13note digest (h = (h xor e) * 1099511628211 from 1469598103934665603) of the arrays the call writes, each over its l
14note elements, in the order A B C D, or of A for a call that only reads. A and B above 1000003 elements and C and
15note D above 16384 are ckbad, as is a count beyond its array. The OP words:
16note gtab lo A, hi B, tab C; n Q0, off Q1, stride Q2 av_gtab twice (which 0, 1); r ors the rcs
17note range d A; n Q0, q0..q4 Q1..Q5 av_range over 2n words of A
18note total best max blocks rfit: A; n Q0 and Q1.. as the C call takes them
19note hmap d A; nqh Q0, nkv Q1, hb Q2, mutant Q3 av_hmap over nqh words
20note eff d A, ctx B, nb C (B when C is empty); n Q0, bs Q1 ctx copied into d, then av_eff
21note reset slots A, ids B; nb Q0, n Q1
22note gath s A, d B; q0..q5 Q0..Q5, sn Q6, dn Q7
23note fold p A, out B; rows Q0, S Q1, HD Q2
24note table ids A, tab B, slots C, touched D; q0..q4 Q0..Q4, g Q5, nb Q6
25note The C binding passes some views by capacity (av_touch takes up to 1000000 ids; the bridge reads only the count
26note it is given), while an Omega sized view is exactly its size: the table call fills the last touch chunk with its
27note last id, which touching twice leaves unchanged.
28text t_name "AVTAB"
29text t_gtab "gtab"
30text t_range "range"
31text t_total "total"
32text t_best "best"
33text t_max "max"
34text t_blocks "blocks"
35text t_rfit "rfit"
36text t_hmap "hmap"
37text t_eff "eff"
38text t_reset "reset"
39text t_gath "gath"
40text t_fold "fold"
41text t_table "table"
42note at_l: the l of A B C D; at_r: r, h and 1 once an OP ran
43global at_l ulong 4
44global at_r ulong 3
45fn cname to void
46for i ulong len t_name bound 64
47ckoc ulong get t_name i
48end
49end
50fn atq j ulong to ulong
51ret cknum add 41 j
52end
53note word w of X
54fn atxw w ulong to ulong
55x = ulong 0
56for j ulong 8
57x = or shl x 8 ckhex 49 add mul w 8 j
58end
59ret x
60end
61note spec k into s; its l, which must fit cap and, for an X spec, X
62fn atsp s edit ulong 10 k ulong cap ulong to ulong
63for j ulong 10
64put s j cknum add add 1 mul k 10 j
65end
66l = get s 0
67if gt l cap
68ckbad
69end
70if and eq get s 3 0 gt l 0
71if lt ckhexn 49 mul add get s 2 l 8
72ckbad
73end
74end
75put at_l k l
76ret l
77end
78fn atel s view ulong 10 i ulong to ulong
79x = ulong 0
80if eq get s 3 0
81x = atxw add get s 2 i
82else
83x = rem add mul get s 1 i get s 2 get s 3
84end
85k = get s 4
86if gt k 0
87if eq rem i k 0
88x = get s 5
89end
90end
91if eq i get s 6
92x = get s 7
93end
94if eq i get s 8
95x = get s 9
96end
97ret x
98end
99fn atgu d edit uint * k ulong to void
100s = new ulong 10 0
101l = atsp s k len d
102for i ulong l bound 1000003
103put d i uint and atel s i 4294967295
104end
105end
106fn atgc d edit uchar * k ulong to void
107s = new ulong 10 0
108l = atsp s k len d
109for i ulong l bound 1000003
110put d i uchar and atel s i 255
111end
112end
113fn atgf d edit f32 * k ulong to void
114s = new ulong 10 0
115l = atsp s k len d
116for i ulong l bound 1000003
117put d i bitcast f32 uint and atel s i 4294967295
118end
119end
120fn athu d view uint * l ulong h ulong to ulong
121for i ulong l bound 1000003
122h = mul xor h ulong get d i 1099511628211
123end
124ret h
125end
126fn athc d view uchar * l ulong h ulong to ulong
127for i ulong l bound 1000003
128h = mul xor h ulong get d i 1099511628211
129end
130ret h
131end
132fn athf d view f32 * l ulong h ulong to ulong
133for i ulong l bound 1000003
134h = mul xor h ulong bitcast uint get d i 1099511628211
135end
136ret h
137end
138note r, h, and the OP ran
139fn atset r ulong h ulong to void
140put at_r 0 r
141put at_r 1 h
142put at_r 2 1
143end
144fn atneed c bool to void
145if not c
146ckbad
147end
148end
149fn atgtab a edit uint 1000003 b edit uint 1000003 c edit uint 16384 to void
150n = atq 0
151n4 = mul n 4
152atneed and and le n get at_l 0 le n get at_l 1 le n4 get at_l 2
153q = new ulong 16 0
154put q 0 n
155put q 1 atq 1
156put q 2 atq 2
157r0 = av_gtab part a 0 n part c 0 n4 q 0
158r1 = av_gtab part b 0 n part c 0 n4 q 1
159atset or r0 r1 athu c get at_l 2 1469598103934665603
160end
161fn atrange a edit uint 1000003 to void
162n = atq 0
163n2 = mul n 2
164atneed le n2 get at_l 0
165q = new ulong 16 0
166for j ulong 5
167put q j atq add j 1
168end
169rc = av_range q part a 0 n2 n
170atset rc athu a get at_l 0 1469598103934665603
171end
172note total, best, max, blocks, rfit: A is read only; r is the answer's low 32 bits
173fn atread a edit uint 1000003 to void
174n = atq 0
175atneed le n get at_l 0
176q = new ulong 16 0
177r = ulong 0
178if ckis 0 t_total
179r = av_total part a 0 n n atq 1
180end
181if ckis 0 t_best
182r = av_best part a 0 n n atq 1
183end
184if ckis 0 t_max
185r = av_max part a 0 n n
186end
187if ckis 0 t_blocks
188for j ulong 5
189put q add j 1 atq add j 1
190end
191r = av_blks part a 0 n q n
192end
193if ckis 0 t_rfit
194put q 0 atq 1
195put q 1 atq 2
196r = av_rfit part a 0 n q n
197end
198atset and r 4294967295 athu a get at_l 0 1469598103934665603
199end
200fn athmap a edit uint 1000003 to void
201n = atq 0
202atneed le n get at_l 0
203q = new ulong 16 0
204for j ulong 4
205put q add j 1 atq j
206end
207rc = av_hmap part a 0 n q
208atset rc athu a get at_l 0 1469598103934665603
209end
210fn ateff a edit uint 1000003 b edit uint 1000003 c edit uint 16384 to void
211n = atq 0
212atneed and le n get at_l 0 le n get at_l 1
213for i ulong n bound 1000003
214put a i get b i
215end
216rc = ulong 0
217if eq get at_l 2 0
218rc = av_eff part b 0 n part a 0 n atq 1
219else
220atneed le n get at_l 2
221rc = av_eff part c 0 n part a 0 n atq 1
222end
223atset rc athu a get at_l 0 1469598103934665603
224end
225fn atreset a edit uint 1000003 b edit uint 1000003 to void
226nb = atq 0
227n = atq 1
228atneed and le nb get at_l 0 le n get at_l 1
229rc = av_reset part a 0 nb part b 0 n n
230atset rc athu a get at_l 0 1469598103934665603
231end
232fn atu3 a edit uint 1000003 b edit uint 1000003 to void
233c = new uint 16384 0
234d = new uint 16384 0
235atgu a 0
236atgu b 1
237atgu c 2
238atgu d 3
239if ckis 0 t_gtab
240atgtab a b c
241end
242if ckis 0 t_range
243atrange a
244end
245if or or or ckis 0 t_total ckis 0 t_best ckis 0 t_max or ckis 0 t_blocks ckis 0 t_rfit
246atread a
247end
248if ckis 0 t_hmap
249athmap a
250end
251if ckis 0 t_eff
252ateff a b c
253end
254if ckis 0 t_reset
255atreset a b
256end
257end
258fn atu2 a edit uint 1000003 to void
259b = new uint 1000003 0
260atu3 a b
261end
262fn atu1 to void
263a = new uint 1000003 0
264atu2 a
265end
266fn atgath to void
267a = new uchar 1000003 0
268b = new uchar 1000003 0
269atgc a 0
270atgc b 1
271sn = atq 6
272dn = atq 7
273atneed and le sn get at_l 0 le dn get at_l 1
274q = new ulong 16 0
275for j ulong 6
276put q j atq j
277end
278rc = av_gath part a 0 sn part b 0 dn q
279atset rc athc b get at_l 1 1469598103934665603
280end
281fn atfold2 a edit f32 1000003 to void
282b = new f32 1000003 f32 0
283atgf b 1
284q = new ulong 16 0
285for j ulong 3
286put q j atq j
287end
288pn = mul mul atq 0 atq 1 add atq 2 2
289on = mul atq 0 atq 2
290atneed and le pn get at_l 0 le on get at_l 1
291rc = av_fold part a 0 pn part b 0 on q
292atset rc athf b get at_l 1 1469598103934665603
293end
294fn atfold to void
295a = new f32 1000003 f32 0
296atgf a 0
297atfold2 a
298end
299note av_touch over ids start..start+cnt of A, the last id repeated to fill the view
300fn attouch c edit uint 16384 d edit uint 16384 start ulong cnt ulong to void
301t = new uint 1000000 0
302s = new ulong 10 0
303l0 = atsp s 0 1000003
304for i ulong 1000000
305j = add start sub cnt 1
306if lt i cnt
307j = add start i
308end
309put t i uint and atel s j 4294967295
310end
311nb = atq 6
312rc = av_touch t part c 0 nb part d 0 nb atq 5
313end
314note ids fit A, the row fits B, the last write lands in B, nb fits C and D
315fn attabok la ulong to void
316atneed and le atq 0 la le add atq 2 atq 0 get at_l 1
317atneed and lt atq 3 get at_l 1 and le atq 6 get at_l 2 le atq 6 get at_l 3
318end
319note the touch chunks of the C binding: at most 1000000 ids each, none when there are no ids
320fn attouchs c edit uint 16384 d edit uint 16384 to void
321n = atq 0
322for bb ulong add div n 1000000 1
323st = mul bb 1000000
324cnt = sub n st
325if gt cnt 1000000
326cnt = ulong 1000000
327end
328if gt cnt 0
329attouch c d st cnt
330end
331end
332end
333fn attab2 b edit uint 1000003 to void
334c = new uint 16384 0
335d = new uint 16384 0
336s = new ulong 10 0
337atgu b 1
338atgu c 2
339atgu d 3
340la = atsp s 0 1000003
341n = atq 0
342off = atq 2
343attabok la
344for i ulong n bound 1000003
345put b add off i uint and atel s i 4294967295
346end
347q = new ulong 16 0
348for j ulong 5
349put q j atq j
350end
351r = av_table part b off n part c 0 atq 6 q atq 5
352if and ne atq 1 0 ne atq 1 2
353attouchs c d
354end
355put b atq 3 uint atq 4
356h = athu b get at_l 1 1469598103934665603
357h = athu c get at_l 2 h
358atset and r 4294967295 athu d get at_l 3 h
359end
360fn attab to void
361b = new uint 1000003 0
362attab2 b
363end
364fn crow to bool
365if ne ckcnt 52
366ckbad
367end
368put at_r 2 0
369if ckis 0 t_gath
370atgath
371else
372if ckis 0 t_fold
373atfold
374else
375if ckis 0 t_table
376attab
377else
378atu1
379end
380end
381end
382if eq get at_r 2 0
383ckbad
384end
385if ne get at_r 0 cknum 50
386ret false
387end
388ret eq get at_r 1 cknum 51
389end