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 / om / apiviews / hostrest.om

372 lines · 5674 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note FP8/GDN host-only policy; effect acquisition remains in the C caller.
3fn ah_flag c ulong tail ulong dflt ulong to ulong
4if eq tail 0
5if eq c 48
6ret 0
7end
8if eq c 49
9ret 1
10end
11end
12ret dflt
13end
14fn ah_var c ulong tail ulong to ulong
15if and eq c 50 eq tail 0
16ret 2
17end
18ret 1
19end
20fn ah_shape k uint over uint kind uint to uint
21if ne over 0
22ret over
23end
24if eq kind 0
25if eq rem k 512 0
26ret 16
27end
28ret 8
29end
30if eq kind 1
31ret 1
32end
33ret 8
34end
35fn ah_reg threads ulong decl ulong to ulong
36if le mul threads decl 65536
37ret 1
38end
39ret 0
40end
41fn ah_group groups uint forced uint wave ulong to uint
42if and gt forced 0 le forced 256
43ret forced
44end
45if or eq wave 0 eq groups 0
46ret 6
47end
48n = div uint 48 groups
49if eq n 0
50ret 1
51end
52if lt n 6
53ret n
54end
55ret 6
56end
57fn ah_digit n uint c uint to ulong
58if or lt c 48 gt c 57
59ret 4294967296
60end
61if ge n 1000
62ret 4294967296
63end
64ret ulong add mul n 10 sub c 48
65end
66fn ah_warps k uint groups uint over uint bigk ulong variant ulong to uint
67if ne over 0
68ret over
69end
70if eq variant 2
71ret 16
72end
73if gt groups 1
74ret 32
75end
76if and and eq groups 1 gt k 4096 ne bigk 0
77ret 16
78end
79ret 8
80end
81fn ah_coal on ulong warps uint rows uint to uint
82if and ne on 0 le mul warps rows 32
83ret 1
84end
85ret 0
86end
87fn ah_depth k uint lb uint rows uint warps uint groups uint bigk ulong to ulong
88ks = div k mul uint 32 lb
89partial = false
90if gt mul mul ks rows lb 128
91if gt k 4096
92if eq groups 1
93partial = ne bigk 0
94end
95end
96end
97if partial
98full = ks
99ks = sub ks 1
100while gt ks 1
101if eq rem full ks 0
102if le mul mul ks rows lb 128
103break
104end
105end
106ks = sub ks 1
107end
108if lt ks 2
109ret 0
110end
111end
112if gt mul mul ks rows lb 128
113ret 0
114end
115if ne rem k mul uint 32 warps 0
116ret 0
117end
118if gt k mul uint 512 warps
119ret 0
120end
121if partial
122ret or ulong ks 4294967296
123end
124ret ulong ks
125end
126fn ah_refuse n uint rows uint support ulong to ulong
127if ne rem n rows 0
128ret 1
129end
130if eq support 0
131ret 1
132end
133ret 0
134end
135fn ah_grid n uint rows uint warps uint budget uint bigk ulong to uint
136rg = div n rows
137gx = div add rg sub warps 1 warps
138if ne bigk 0
139waves = div add gx 383 384
140if lt waves 2
141waves = 2
142end
143gx = div add gx sub waves 1 waves
144budget = gx
145end
146if gt gx budget
147gx = budget
148end
149if eq gx 0
150gx = 1
151end
152ret gx
153end
154fn ah_cache valid ulong equal ulong rec ulong to ulong
155if and ne valid 0 ne equal 0
156ret 1
157end
158if and ne valid 0 ne rec 0
159ret 2
160end
161ret 0
162end
163fn ah_move kind ulong dst ulong bytes ulong per ulong to ulong
164if or or or and ne kind 4 ne kind 5 eq dst 0 eq bytes 0 ne rem bytes per 0
165ret 0
166end
167if gt div bytes per 2147483647
168ret 0
169end
170ret div bytes per
171end
172fn ah_tokens layer uint layers uint t uint low uint high uint to ulong
173if or or ge layer layers lt t low gt t high
174ret 0
175end
176ret 1
177end
178fn ah_scratch rec ulong present ulong cap ulong bytes ulong to ulong
179if and ne rec 0 or eq present 0 lt cap bytes
180ret 0
181end
182ret 1
183end
184fn ah_pfgx t uint prep uint ratio uint stage uint to uint
185if eq stage 0
186ret div add t sub prep 1 prep
187end
188if eq stage 1
189ret ratio
190end
191ret t
192end
193fn ah_dcall p view ulong 16 to ulong
194a = uint get p 0
195b = uint get p 1
196c = uint get p 2
197d = uint get p 3
198e = uint get p 4
199f = get p 5
200ret ah_depth a b c d e f
201end
202fn ah_tcall p view ulong 16 to ulong
203a = uint get p 0
204b = uint get p 1
205c = uint get p 2
206d = uint get p 3
207e = uint get p 4
208ret ah_tokens a b c d e
209end
210fn ah_admit p view ulong 16 to ulong
211if eq get p 0 0
212if ne get p 1 0
213if or or eq get p 2 0 eq get p 3 0 eq get p 4 0
214ret 0
215end
216end
217ret 1
218end
219if eq get p 0 1
220if eq get p 1 0
221ret 0
222end
223if and eq get p 2 0 eq get p 3 0
224ret 0
225end
226if and and eq get p 4 0 eq get p 5 0 eq get p 6 0
227ret 0
228end
229if and eq get p 7 0 eq get p 8 0
230ret 0
231end
232ret 1
233end
234if ne get p 1 0
235if or or eq get p 2 0 eq get p 3 0 eq get p 4 0
236ret 0
237end
238else
239if or or or eq get p 5 0 eq get p 6 0 eq get p 7 0 eq get p 8 0
240ret 0
241end
242end
243ret 1
244end
245fn ah_extra op ulong p view ulong 16 to ulong
246if eq op 24
247k = uint get p 0
248lb = uint get p 1
249r = uint get p 2
250ks = div k mul uint 32 lb
251if gt mul mul ks r lb 128
252if and gt k 4096 eq get p 3 1
253ret 1
254end
255end
256ret 0
257end
258if eq op 23
259ret ah_admit p
260end
261if eq op 16
262for i ulong 8
263if ne get p i 0
264ret 0
265end
266end
267ret 1
268end
269if eq op 17
270if eq get p 0 0
271ret 0
272end
273if or eq get p 1 1 eq get p 1 get p 0
274ret 1
275end
276ret 0
277end
278if eq op 18
279if ne get p 0 0
280ret get p 1
281end
282if gt get p 2 1
283if eq get p 3 2
284ret 12
285end
286ret get p 4
287end
288ret 256
289end
290if eq op 19
291if ne get p 0 0
292ret 0
293end
294if ne get p 1 1
295ret 0
296end
297if le get p 2 4096
298ret 0
299end
300ret get p 3
301end
302if eq op 20
303if ne get p 0 1
304ret 0
305end
306if eq get p 1 0
307ret 0
308end
309if gt get p 2 get p 3
310ret 0
311end
312ret 1
313end
314if eq op 21
315if gt get p 0 get p 1
316ret 1
317end
318ret 0
319end
320ret div get p 0 get p 1
321end
322fn ah_rest op ulong p view ulong 16 to ulong
323if ge op 16
324ret ah_extra op p
325end
326if eq op 0
327ret ah_flag get p 0 get p 1 get p 2
328end
329if eq op 1
330ret ah_var get p 0 get p 1
331end
332if eq op 2
333ret ulong ah_shape uint get p 0 uint get p 1 uint get p 2
334end
335if eq op 3
336ret ah_reg get p 0 get p 1
337end
338if eq op 4
339ret ulong ah_group uint get p 0 uint get p 1 get p 2
340end
341if eq op 5
342ret ah_digit uint get p 0 uint get p 1
343end
344if eq op 6
345ret ulong ah_warps uint get p 0 uint get p 1 uint get p 2 get p 3 get p 4
346end
347if eq op 7
348ret ulong ah_coal get p 0 uint get p 1 uint get p 2
349end
350if eq op 8
351ret ah_dcall p
352end
353if eq op 9
354ret ah_refuse uint get p 0 uint get p 1 get p 2
355end
356if eq op 10
357ret ulong ah_grid uint get p 0 uint get p 1 uint get p 2 uint get p 3 get p 4
358end
359if eq op 11
360ret ah_cache get p 0 get p 1 get p 2
361end
362if eq op 12
363ret ah_move get p 0 get p 1 get p 2 get p 3
364end
365if eq op 13
366ret ah_tcall p
367end
368if eq op 14
369ret ah_scratch get p 0 get p 1 get p 2 get p 3
370end
371ret ulong ah_pfgx uint get p 0 uint get p 1 uint get p 2 uint get p 3
372end