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