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 / check.om

308 lines · 5644 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note native/abft evaluator checkers. Inputs: ga, gb (evaluator-generated), gobs (candidate bytes),
3note gd dims and the evaluator nonce stream 1. The fault-free reference gref is never read here.
4note dt 0: exact u32 products and sums mod 2^32. dt 1: bf16 inputs, f32 output, profile P1
5note (exact bf16 products, f32 sequential accumulation, |c^ - c| <= gamma_K(u) (|A||B|)_ij, u = 2^-24).
6note Checks use f64 (u' = 2^-53). Every comparison is written `not le d t` so NaN is detected.
7const UF f64 5.9604644775390625e-08
8const UD f64 1.1102230246251565e-16
9const SL f64 9.5367431640625e-07
10const MASK ulong 4294967295
11global ga ulong 65536
12global gb ulong 65536
13global gobs ulong 65536
14global gd ulong 8
15global xv f64 256
16global xh f64 256
17global xr f64 256
18global xu ulong 256
19global xq ulong 256
20global xm f64 1
21global xg f64 1
22fn dm to ulong
23ret get gd 1
24end
25fn dn to ulong
26ret get gd 2
27end
28fn dk to ulong
29ret get gd 3
30end
31fn ea i ulong k ulong to ulong
32ret get ga add mul i dk k
33end
34fn eb k ulong j ulong to ulong
35ret get gb add mul k dn j
36end
37fn ec i ulong j ulong to ulong
38ret get gobs add mul i dn j
39end
40fn gam n ulong u f64 to f64
41x = mul f64 n u
42ret div x sub 1.0 x
43end
44note Per-element bound (Wolfram-checked slack, docs/abft/CONTRACT.md section 3).
45fn gfull k ulong to f64
46ret mul add gam k UF gam k UD add 1.0 SL
47end
48note Two-sided checksum bound for one side: n is the summed output extent (N rows side, M cols side).
49fn gside n ulong k ulong to f64
50gp = gam k UF
51a = gam sub n 1 UD
52b = gam k UD
53t = add add gp mul a add 2.0 gp mul b add 1.0 a
54ret mul t add 1.0 SL
55end
56fn xmax d f64 t f64 to void
57if gt t 0.0
58put xm 0 fmax get xm 0 div d t
59end
60end
61fn fdotg i ulong j ulong to f64
62s = 0.0f64
63g = 0.0f64
64for k ulong dk
65p = mul bf ea i k bf eb k j
66s = add s p
67g = add g fabs p
68end
69put xg 0 g
70ret s
71end
72fn felem i ulong j ulong t0 f64 to bool
73s = fdotg i j
74d = fabs sub f3 ec i j s
75t = mul t0 get xg 0
76xmax d t
77ret not le d t
78end
79fn xdot i ulong j ulong to ulong
80s = ulong 0
81for k ulong dk
82s = add s mul ea i k eb k j
83end
84ret and s MASK
85end
86fn xelem i ulong j ulong to bool
87ret ne xdot i j and ec i j MASK
88end
89note Thorough mode: recompute every element.
90fn cfull to ulong
91put xm 0 0.0
92bad = ulong 0
93t0 = gfull dk
94for i ulong dm
95for j ulong dn
96if eq get gd 0 0
97if xelem i j
98bad = add bad 1
99end
100else
101if felem i j t0
102bad = add bad 1
103end
104end
105end
106end
107ret bad
108end
109note Sampled mode: S elements with replacement, positions from the evaluator nonce stream.
110fn csamp s ulong to ulong
111put xm 0 0.0
112bad = ulong 0
113t0 = gfull dk
114for q ulong s
115i = rbelow 1 dm
116j = rbelow 1 dn
117if eq get gd 0 0
118if xelem i j
119bad = add bad 1
120end
121else
122if felem i j t0
123bad = add bad 1
124end
125end
126end
127ret bad
128end
129fn fsign to f64
130if eq and rnext 1 1 0
131ret 1.0
132end
133ret -1.0
134end
135note FP right side: y = B r, rows test |A y - C r| against gside(N,K) (|A| (|B| e)).
136fn frow to ulong
137bad = ulong 0
138for j ulong dn
139put xr j fsign
140end
141for k ulong dk
142y = 0.0f64
143h = 0.0f64
144for j ulong dn
145b = bf eb k j
146y = add y mul b get xr j
147h = add h fabs b
148end
149put xv k y
150put xh k h
151end
152t0 = gside dn dk
153for i ulong dm
154if frowi i t0
155bad = add bad 1
156end
157end
158ret bad
159end
160fn frowi i ulong t0 f64 to bool
161z = 0.0f64
162g = 0.0f64
163for k ulong dk
164a = bf ea i k
165z = add z mul a get xv k
166g = add g mul fabs a get xh k
167end
168w = 0.0f64
169for j ulong dn
170w = add w mul f3 ec i j get xr j
171end
172d = fabs sub z w
173t = mul t0 g
174xmax d t
175ret not le d t
176end
177note FP left side: x = s^T A, columns test |x B - s^T C| against gside(M,K) ((e^T |A|) |B|).
178fn fcol to ulong
179bad = ulong 0
180for i ulong dm
181put xr i fsign
182end
183for k ulong dk
184x = 0.0f64
185h = 0.0f64
186for i ulong dm
187a = bf ea i k
188x = add x mul a get xr i
189h = add h fabs a
190end
191put xv k x
192put xh k h
193end
194t0 = gside dm dk
195for j ulong dn
196if fcolj j t0
197bad = add bad 1
198end
199end
200ret bad
201end
202fn fcolj j ulong t0 f64 to bool
203z = 0.0f64
204g = 0.0f64
205for k ulong dk
206b = bf eb k j
207z = add z mul get xv k b
208g = add g mul get xh k fabs b
209end
210w = 0.0f64
211for i ulong dm
212w = add w mul get xr i f3 ec i j
213end
214d = fabs sub z w
215t = mul t0 g
216xmax d t
217ret not le d t
218end
219note Exact right side: odd u32 multipliers r, y = B r mod 2^32, rows test A y = C r mod 2^32.
220fn xrow to ulong
221bad = ulong 0
222for j ulong dn
223put xu j or and rnext 1 MASK 1
224end
225for k ulong dk
226y = ulong 0
227for j ulong dn
228y = add y mul eb k j get xu j
229end
230put xq k y
231end
232for i ulong dm
233z = ulong 0
234for k ulong dk
235z = add z mul ea i k get xq k
236end
237w = ulong 0
238for j ulong dn
239w = add w mul ec i j get xu j
240end
241if ne and xor z w MASK 0
242bad = add bad 1
243end
244end
245ret bad
246end
247fn xcol to ulong
248bad = ulong 0
249for i ulong dm
250put xu i or and rnext 1 MASK 1
251end
252for k ulong dk
253x = ulong 0
254for i ulong dm
255x = add x mul get xu i ea i k
256end
257put xq k x
258end
259for j ulong dn
260z = ulong 0
261for k ulong dk
262z = add z mul get xq k eb k j
263end
264w = ulong 0
265for i ulong dm
266w = add w mul get xu i ec i j
267end
268if ne and xor z w MASK 0
269bad = add bad 1
270end
271end
272ret bad
273end
274note Checksum mode: one right and one left randomized check (failing rows plus failing columns).
275fn cabft to ulong
276put xm 0 0.0
277if eq get gd 0 0
278ret add xrow xcol
279end
280ret add frow fcol
281end
282note Common-mode guard: FNV-1a over dims and both inputs, compared with the generation-time digest.
283fn cdig to ulong
284h = ulong 14695981039346656037
285for q ulong 4
286h = fnvw h get gd q
287end
288for e ulong mul dm dk
289h = fnvw h get ga e
290end
291for e ulong mul dk dn
292h = fnvw h get gb e
293end
294ret h
295end
296note Structural: nonfinite f32 outputs (exponent all ones) counted; exact mode has none.
297fn cnonfin to ulong
298if eq get gd 0 0
299ret 0
300end
301bad = ulong 0
302for e ulong mul dm dn
303if eq and get gobs e 2139095040 2139095040
304bad = add bad 1
305end
306end
307ret bad
308end