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