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 / native / abft / cand.om

470 lines · 7344 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note native/abft candidate: a tiled GEMM run by W simulated workers that share tile buffers sa/sb and
3note meet at two barriers per K tile (after loads, after compute). It runs only in a forked child; its
4note one channel back to the evaluator is the memfd bytes plus its exit status. The scheduler applies
5note the evaluator's perturbation (sched.om validated it before fork). Fault injectors are labelled
6note controls selected by the frozen plan row, never by candidate logic. Label: SIMULATED.
7note Element order is k ascending for every element under every schedule, so a fault-free run is
8note bitwise schedule independent; any schedule dependence in the output is a fault.
9const TK ulong 8
10const PLOAD ulong 0
11const PB1 ulong 1
12const PCOMP ulong 2
13const PB2 ulong 3
14const PDONE ulong 4
15const KDT ulong 1
16const KM ulong 2
17const KN ulong 3
18const KK ulong 4
19const KW ulong 5
20const KPOL ulong 6
21const KTGT ulong 7
22const KSITE ulong 8
23const KFLT ulong 9
24const KSUB ulong 10
25const KP1 ulong 11
26const KP2 ulong 12
27const KSEED ulong 13
28const KFLG ulong 15
29global kp ulong 16
30global kat ulong 1
31global krep ulong 1
32global cc ulong 65536
33global sa ulong 2048
34global sb ulong 2048
35global wph ulong 64
36global wt ulong 64
37global wu ulong 64
38global warr ulong 64
39global clast ulong 1
40global csh ulong 1
41global gprev ulong 65536
42global gref ulong 65536
43fn kf f ulong to ulong
44ret get kp f
45end
46fn fact to bool
47if eq kf KFLT 0
48ret false
49end
50if eq and kf KFLG 1 1
51ret eq get kat 0 0
52end
53ret true
54end
55fn fis f ulong s ulong to bool
56if fact
57ret and eq kf KFLT f eq kf KSUB s
58end
59ret false
60end
61fn ntiles to ulong
62ret div add kf KK sub TK 1 TK
63end
64fn ctk t ulong to ulong
65k0 = mul t TK
66tk = sub kf KK k0
67if gt tk TK
68tk = TK
69end
70if fis 4 1
71if eq t sub ntiles 1
72tk = sub tk 1
73end
74end
75ret tk
76end
77fn rowskip i ulong to bool
78if fact
79if eq kf KFLT 3
80if ge kf KSUB 2
81p1 = kf KP1
82ret and ge i p1 lt i add p1 kf KP2
83end
84end
85end
86ret false
87end
88fn cloada w ulong k0 ulong tk ulong to void
89e = w
90while lt e mul kf KM tk
91i = div e tk
92q = rem e tk
93s = add mul i kf KK add k0 q
94v = get ga s
95put sa add mul i TK q v
96e = add e kf KW
97end
98end
99fn cloadb w ulong k0 ulong tk ulong to void
100n = kf KN
101e = w
102while lt e mul tk n
103q = div e n
104j = rem e n
105s = add mul add k0 q n j
106if fis 4 2
107s = add mul j n add k0 q
108end
109v = get gb s
110put sb add mul q n j v
111e = add e kf KW
112end
113end
114fn cload w ulong t ulong to void
115k0 = mul t TK
116tk = sub kf KK k0
117if gt tk TK
118tk = TK
119end
120cloada w k0 tk
121cloadb w k0 tk
122end
123fn bfu v ulong to f32
124ret bitcast f32 uint shl and v 65535 16
125end
126fn crowf i ulong tk ulong to void
127n = kf KN
128for j ulong n
129p = add mul i n j
130acc = bitcast f32 uint get cc p
131for q ulong tk
132a = bfu get sa add mul i TK q
133b = bfu get sb add mul q n j
134acc = add acc mul a b
135end
136put cc p fbits acc
137end
138end
139fn crowx i ulong tk ulong to void
140n = kf KN
141for j ulong n
142p = add mul i n j
143acc = get cc p
144for q ulong tk
145a = get sa add mul i TK q
146b = get sb add mul q n j
147acc = and add acc mul a b MASK
148end
149put cc p acc
150end
151end
152fn crow i ulong t ulong to void
153if rowskip i
154ret
155end
156if eq kf KDT 0
157crowx i ctk t
158else
159crowf i ctk t
160end
161end
162fn bset v ulong to bool
163if fis 5 3
164ret lt v 2
165end
166ret true
167end
168fn bpass c ulong to bool
169ok = true
170for v ulong kf KW
171if bset v
172if lt get warr v c
173ok = false
174end
175end
176end
177ret ok
178end
179fn cready w ulong to bool
180ph = get wph w
181if eq ph PDONE
182ret false
183end
184t = get wt w
185if eq ph PB1
186ret bpass add mul t 2 1
187end
188if eq ph PB2
189ret bpass add mul t 2 2
190end
191ret true
192end
193fn cnext w ulong to void
194t = add get wt w 1
195put wt w t
196if eq t ntiles
197put wph w PDONE
198ret
199end
200if fis 5 4
201if eq w 0
202put wph w PDONE
203ret
204end
205end
206put wph w PLOAD
207end
208fn carrive w ulong to void
209put warr w add get warr w 1
210end
211fn cstep w ulong to void
212ph = get wph w
213t = get wt w
214if eq ph PLOAD
215cload w t
216carrive w
217put wu w 0
218if fis 5 1
219put wph w PCOMP
220else
221put wph w PB1
222end
223ret
224end
225if eq ph PB1
226put wph w PCOMP
227put wu w 0
228ret
229end
230if eq ph PB2
231cnext w
232ret
233end
234i = add w mul get wu w kf KW
235if lt i kf KM
236crow i t
237put wu w add get wu w 1
238i = add w mul get wu w kf KW
239end
240if ge i kf KM
241carrive w
242if fis 5 2
243cnext w
244else
245put wph w PB2
246end
247end
248end
249fn csite w ulong to ulong
250ph = get wph w
251if eq ph PLOAD
252ret 1
253end
254if eq ph PCOMP
255ret 2
256end
257ret 3
258end
259fn crr ex ulong to ulong
260w = kf KW
261s = get clast 0
262for q ulong w
263v = rem add add s 1 q w
264if ne v ex
265if cready v
266ret v
267end
268end
269end
270ret w
271end
272fn ccount to ulong
273c = ulong 0
274for v ulong kf KW
275if cready v
276c = add c 1
277end
278end
279ret c
280end
281fn ckth k ulong to ulong
282c = ulong 0
283for v ulong kf KW
284if cready v
285if eq c k
286ret v
287end
288c = add c 1
289end
290end
291ret kf KW
292end
293fn cpick to ulong
294w = kf KW
295n = ccount
296if eq n 0
297ret w
298end
299pol = kf KPOL
300tg = kf KTGT
301if eq pol 1
302ret ckth rbelow 2 n
303end
304if eq pol 2
305if cready tg
306ret tg
307end
308end
309if eq pol 3
310if cready tg
311if eq csite tg kf KSITE
312if gt n 1
313ret crr tg
314end
315end
316end
317end
318ret crr w
319end
320fn chang to void
321note Simulated device hang: no worker can advance; the evaluator deadline kills this process.
322for q ulong 1000000
323z = sleepns 1000000
324if lt z 0
325trap 9
326end
327end
328trap 10
329end
330fn cinit to void
331m = kf KM
332n = kf KN
333for e ulong mul m n
334put cc e 0
335end
336if fact
337if eq kf KFLT 3
338for e ulong mul m n
339i = div e n
340if and ge i kf KP1 lt i add kf KP1 kf KP2
341if eq kf KSUB 3
342put cc e get gref e
343else
344put cc e get gprev e
345end
346end
347end
348end
349end
350for w ulong kf KW
351put wph w PLOAD
352put wt w 0
353put wu w 0
354put warr w 0
355end
356put clast 0 sub kf KW 1
357put csh 0 14695981039346656037
358end
359fn cflip e ulong b ulong to void
360put cc e xor get cc e shl ulong 1 b
361end
362fn cbit c ulong to ulong
363if eq c 1
364ret add 23 rbelow 3 9
365end
366if eq c 2
367ret rbelow 3 8
368end
369ret rbelow 3 32
370end
371fn cpos to ulong
372ret rbelow 3 mul kf KM kf KN
373end
374fn cfadd e ulong d f32 to void
375put cc e fbits add bitcast f32 uint get cc e d
376end
377fn crect b ulong to void
378m = kf KM
379n = kf KN
380i1 = rbelow 3 m
381i2 = rem add add i1 1 rbelow 3 sub m 1 m
382j1 = rbelow 3 n
383j2 = rem add add j1 1 rbelow 3 sub n 1 n
384if eq b 32
385e = f32 shl ulong 1 kf KP1
386cfadd add mul i1 n j1 e
387cfadd add mul i1 n j2 neg e
388cfadd add mul i2 n j1 neg e
389cfadd add mul i2 n j2 e
390ret
391end
392cflip add mul i1 n j1 b
393cflip add mul i1 n j2 b
394cflip add mul i2 n j1 b
395cflip add mul i2 n j2 b
396end
397fn cshift to void
398m = kf KM
399n = kf KN
400i = sub m 1
401while gt i 0
402for j ulong n
403put cc add mul i n j get cc add mul sub i 1 n j
404end
405i = sub i 1
406end
407for j ulong n
408put cc j 0
409end
410end
411fn cpost to void
412if not fact
413ret
414end
415f = kf KFLT
416if eq f 1
417cflip cpos kf KP2
418end
419if eq f 2
420for q ulong kf KP1
421cflip cpos cbit kf KP2
422end
423end
424if fis 4 3
425cshift
426end
427if fis 4 4
428note Out-of-bounds store: Omega traps 3 (exit 103) before writing.
429put cc add mul kf KM kf KN 65536 0
430end
431if fis 6 1
432crect 31
433end
434if fis 6 3
435crect 32
436end
437end
438note Child entry: runs the schedule to completion, applies post-run injectors, returns step count.
439fn crun to ulong
440cinit
441note Stream 2 varies with rep and attempt (a retry is a new schedule); stream 3 varies with rep only,
442note so a persistent fault lands on the same elements again on retry.
443base = add mul kf KSEED 2654435761 mul get krep 0 7919
444rseed 2 add base mul get kat 0 104729
445rseed 3 add base 1
446steps = ulong 0
447while true bound 999999
448w = cpick
449if eq w kf KW
450if eq ccount 0
451done = true
452for v ulong kf KW
453if ne get wph v PDONE
454done = false
455end
456end
457if done
458break
459end
460chang
461end
462end
463put clast 0 w
464put csh 0 fnvw get csh 0 w
465cstep w
466steps = add steps 1
467end
468cpost
469ret steps
470end