interplane.Get Omega
Read in your language

CUDApp

CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.

Brought by drakestapleton

branch main Branches Tags History

CUDApp / om / api / attn_art.om

193 lines · 3005 bytes Raw Blame History
1om2
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3fn ar_rd b view uchar * o ulong n ulong to ulong
4v = ulong 0
5for i ulong n
6v = or v shl ulong get b add o i mul i 8
7end
8ret v
9end
10fn ar_eq b view uchar * off ulong s view uchar * to bool
11if gt off len b
12ret false
13end
14if gt len s sub len b off
15ret false
16end
17for i ulong len s
18if ne get b add off i get s i
19ret false
20end
21end
22ret true
23end
24fn ar_sect b view uchar * sh ulong str view ulong 2 fnm view uchar * to bool
25name = ar_rd b sh 4
26if ge name get str 1
27ret false
28end
29off = add get str 0 name
30left = sub get str 1 name
31if le left add len fnm 6
32ret false
33end
34if ne get b off 46
35ret false
36end
37if ne get b add off 1 116
38ret false
39end
40if ne get b add off 2 101
41ret false
42end
43if ne get b add off 3 120
44ret false
45end
46if ne get b add off 4 116
47ret false
48end
49if ne get b add off 5 46
50ret false
51end
52if not ar_eq b add off 6 fnm
53ret false
54end
55ret eq get b add add off 6 len fnm 0
56end
57fn ar_data b view uchar * sh ulong txt view uchar * to bool
58off = ar_rd b add sh 24 8
59sz = ar_rd b add sh 32 8
60if or gt off len b ne sz len txt
61ret false
62end
63ret ar_eq b off txt
64end
65fn ar_cubin b view uchar * fnm view uchar * txt view uchar * to bool
66if lt len b 64
67ret false
68end
69if ne ar_rd b 0 4 1179403647
70ret false
71end
72if ne ar_rd b 18 2 190
73ret false
74end
75shoff = ar_rd b 40 8
76num = ar_rd b 60 2
77idx = ar_rd b 62 2
78if or ne ar_rd b 58 2 64 or eq num 0 ge idx num
79ret false
80end
81if gt shoff len b
82ret false
83end
84if gt mul num 64 sub len b shoff
85ret false
86end
87str = new ulong 2 0
88put str 0 ar_rd b add add shoff mul idx 64 24 8
89put str 1 ar_rd b add add shoff mul idx 64 32 8
90if gt get str 0 len b
91ret false
92end
93if gt get str 1 sub len b get str 0
94ret false
95end
96note snprintf want[128] requires 6-byte prefix plus fn plus terminator to fit.
97if ge add len fnm 6 128
98ret false
99end
100for i ulong num
101sh = add shoff mul i 64
102if ar_sect b sh str fnm
103ret ar_data b sh txt
104end
105end
106ret false
107end
108fn ar_layout b view uchar * keys view uchar * cap ulong to bool
109if ge len b cap
110ret false
111end
112for i ulong len b
113if or eq get b i 0 eq get b i 13
114ret false
115end
116end
117pos = ulong 0
118idx = ulong 0
119first = true
120while lt idx len keys
121if eq get keys idx 0
122idx = add idx 1
123continue
124end
125while ne get keys idx 0
126if ge pos len b
127ret false
128end
129if ne get keys idx get b pos
130ret false
131end
132idx = add idx 1
133pos = add pos 1
134end
135idx = add idx 1
136if first
137first = false
138else
139while lt pos len b
140c = get b pos
141pos = add pos 1
142if eq c 10
143break
144end
145end
146if eq pos 0
147ret false
148end
149if ne get b sub pos 1 10
150ret false
151end
152end
153end
154ret eq pos len b
155end
156fn ar_version h view uint 3 n view uint 3 to bool
157for i ulong 3
158if ne get h i get n i
159ret gt get h i get n i
160end
161end
162ret true
163end
164fn ar_json c uchar d edit uchar 6 to ulong
165if or eq c 34 eq c 92
166put d 0 92
167put d 1 c
168ret 2
169end
170if or lt c 32 eq c 127
171put d 0 92
172put d 1 117
173put d 2 48
174put d 3 48
175v = shr c 4
176if gt v 9
177v = add v 87
178else
179v = add v 48
180end
181put d 4 v
182v = and c 15
183if gt v 9
184v = add v 87
185else
186v = add v 48
187end
188put d 5 v
189ret 6
190end
191put d 0 c
192ret 1
193end