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 / backend / spirv / conform.om

324 lines · 5584 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note conform.om: host reference and bit-exact compare for the emit.om kernels (seeded Omega, AArch64).
3note vadd uses hello_gpu's inputs and operation exactly (examples/hello_gpu/hello_gpu.c inputs/check):
4note a[i] = f32(i) * 0.25, b[i] = 1.0 / f32(1 + i % 7), c[i] = a[i] + b[i], n = 1048576 (N_TOTAL).
5note fsum16 is the frozen left-to-right row sum of 16 floats over 65536 rows; its inputs mix
6note magnitudes (every fifth column scaled by 65536) so that a different summation order changes bits:
7note x[16r+k] = f32((31r + 17k) % 101) * 0.37 - 18.0, times 65536.0 when k % 5 == 0
8note o[r] = (((x[16r] + x[16r+1]) + x[16r+2]) ... ) + x[16r+15]
9note Every operation is one IEEE binary32 operation rounded to nearest (omc f32, OMEGESE 9.9), so the
10note reference is the exact bit pattern a conforming FP32 device must produce for these kernels.
11note
12note Usage:
13note conform in vadd A.bin B.bin write the two vadd inputs (little-endian binary32)
14note conform in fsum16 X.bin write the fsum16 input
15note conform ref vadd|fsum16 OUT.bin write the reference output
16note conform check vadd|fsum16 OUT.bin compare OUT.bin with the reference bit for bit
17note check prints one line: CONFORM <kernel> n=<n> wrong=<w> unwritten=<u> first=<index or none>
18note Loops run in blocks of 4096 because a for count above 1000000 traps 4 (OMEGESE 9.1).
19note (unwritten counts the launcher's poison 0xFFC0FFEE). Exit: 0 every element equal; 1 a mismatch;
20note 2 usage; 3 I/O or wrong file size. Traps exit 100 + code.
21om2
22
23text tuse "usage: conform in vadd A B | in fsum16 X | ref K OUT | check K OUT\n"
24text tio "conform: I/O error or wrong file size\n"
25text tin "in"
26text tref "ref"
27text tchk "check"
28text tvadd "vadd"
29text tfsum "fsum16"
30text tcf "CONFORM "
31text tn " n="
32text twr " wrong="
33text tun " unwritten="
34text tfi " first="
35text tnone "none"
36text tnl "\n"
37
38const NVADD ulong 1048576
39const NROWS ulong 65536
40const POISON uint 4290838510
41
42global gio uchar 4194304
43global gpath uchar 4096
44global garg uchar 16
45global gob uchar 256
46note gst: 0 kernel (0 vadd, 1 fsum16), 1 output fill
47global gst ulong 4
48
49fn fail code int msg view uchar * to void
50n = write 2 msg 0 len msg
51exit code
52end
53
54fn argis i ulong t view uchar * to bool
55n = argread i garg 0 len garg
56if ne n long len t
57ret false
58end
59for k ulong len t
60if ne get garg k get t k
61ret false
62end
63end
64ret true
65end
66
67fn oc b uchar to void
68f = get gst 1
69put gob f b
70put gst 1 add f 1
71end
72
73fn ot t view uchar * to void
74for i ulong len t
75oc get t i
76end
77end
78
79fn odec v ulong to void
80d = new uchar 20 0
81k = ulong 0
82x = v
83while true bound 21
84put d k uchar add rem x 10 48
85k = add k 1
86x = div x 10
87if eq x 0
88break
89end
90end
91for i ulong k
92oc get d sub sub k i 1
93end
94end
95
96fn oflush to void
97n = write 1 gob 0 get gst 1
98put gst 1 0
99end
100
101fn va i ulong to f32
102ret mul f32 i 0.25f32
103end
104
105fn vb i ulong to f32
106ret div 1.0f32 f32 add 1 rem i 7
107end
108
109fn vx i ulong to f32
110r = div i 16
111k = rem i 16
112v = sub mul f32 rem add mul r 31 mul k 17 101 0.37f32 18.0f32
113if eq rem k 5 0
114v = mul v 65536.0f32
115end
116ret v
117end
118
119fn rsum r ulong to f32
120b = mul r 16
121acc = vx b
122for k ulong 15
123acc = add acc vx add b add k 1
124end
125ret acc
126end
127
128fn count to ulong
129if eq get gst 0 0
130ret NVADD
131end
132ret NROWS
133end
134
135fn refv i ulong to f32
136if eq get gst 0 0
137ret add va i vb i
138end
139ret rsum i
140end
141
142fn putu i ulong v uint to void
143o = mul i 4
144for k ulong 4
145put gio add o k uchar and shr v mul uint k 8 255
146end
147end
148
149fn getu i ulong to uint
150o = mul i 4
151v = uint 0
152for k ulong 4
153v = or v shl uint get gio add o k mul uint k 8
154end
155ret v
156end
157
158fn wfile ai ulong nb ulong to void
159n = argread ai gpath 0 len gpath
160if le n 0
161fail 2 tuse
162end
163fd = fopen gpath 0 ulong n 577 420
164if lt fd 0
165fail 3 tio
166end
167r = write int fd gio 0 nb
168if ne r long nb
169fail 3 tio
170end
171c = fclose int fd
172end
173
174fn rfile ai ulong nb ulong to void
175n = argread ai gpath 0 len gpath
176if le n 0
177fail 2 tuse
178end
179fd = fopen gpath 0 ulong n 0 0
180if lt fd 0
181fail 3 tio
182end
183sz = fseek int fd 0 2
184if ne sz long nb
185fail 3 tio
186end
187r = pread int fd gio 0 nb 0
188if ne r long nb
189fail 3 tio
190end
191c = fclose int fd
192end
193
194fn kind ai ulong to void
195put gst 0 9
196if argis ai tvadd
197put gst 0 0
198end
199if argis ai tfsum
200put gst 0 1
201end
202if eq get gst 0 9
203fail 2 tuse
204end
205end
206
207fn doin to void
208ac = argcnt
209if eq get gst 0 0
210if ne ac 5
211fail 2 tuse
212end
213for h ulong div NVADD 4096
214for l ulong 4096
215i = add mul h 4096 l
216putu i bitcast uint va i
217end
218end
219wfile 3 mul NVADD 4
220for h ulong div NVADD 4096
221for l ulong 4096
222i = add mul h 4096 l
223putu i bitcast uint vb i
224end
225end
226wfile 4 mul NVADD 4
227ret
228end
229if ne ac 4
230fail 2 tuse
231end
232n = mul NROWS 16
233for h ulong div n 4096
234for l ulong 4096
235i = add mul h 4096 l
236putu i bitcast uint vx i
237end
238end
239wfile 3 mul n 4
240end
241
242fn doref to void
243n = count
244for h ulong div n 4096
245for l ulong 4096
246i = add mul h 4096 l
247putu i bitcast uint refv i
248end
249end
250wfile 3 mul n 4
251end
252
253fn docheck to int
254n = count
255rfile 3 mul n 4
256wr = ulong 0
257un = ulong 0
258fi = ulong 0
259for h ulong div n 4096
260for l ulong 4096
261i = add mul h 4096 l
262g = getu i
263if eq g POISON
264un = add un 1
265end
266if ne g bitcast uint refv i
267if eq wr 0
268fi = i
269end
270wr = add wr 1
271end
272end
273end
274ot tcf
275if eq get gst 0 0
276ot tvadd
277end
278if eq get gst 0 1
279ot tfsum
280end
281ot tn
282odec n
283ot twr
284odec wr
285ot tun
286odec un
287ot tfi
288if eq wr 0
289ot tnone
290end
291if gt wr 0
292odec fi
293end
294ot tnl
295oflush
296if gt wr 0
297ret 1
298end
299ret 0
300end
301
302fn main to int
303ac = argcnt
304if lt ac 4
305fail 2 tuse
306end
307kind 2
308if argis 1 tin
309doin
310ret 0
311end
312if ne ac 4
313fail 2 tuse
314end
315if argis 1 tref
316doref
317ret 0
318end
319if argis 1 tchk
320ret docheck
321end
322fail 2 tuse
323ret 2
324end