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/om/encoder/primary_parity.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 / om / encoder / primary_parity.om` 385 lines · 7805 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 note Compose after bw_enc_sm121.om. Host only. No device and no new instruction forms. 3 note t emits 128-byte records for the existing C test adapter, c checks its 24-byte responses. 4 note Each opcode 0..79 (#280 numbering: main op 64 ATOMG MIN, integ ops moved to 65..79) has eight operand forms, each with 1024 register/control/predicate samples. 5 note Form bits: uniform-source selector, absent src2, absent src3. Samples also vary absent dst, src1 and ureg. 6 note Then opcodes 0..81 (the two past the last op are unknown) each get PP_EDGES refusal-edge samples (pp_edge), printed as "edge op=" rows. 7 note The oracle adapter only marshals fields and calls the independent C encoder. 8 text pp_ok " parity samples=" 9 text pp_yes " accepted=" 10 text pp_no " refused=" 11 text pp_op "op=" 12 text pp_edg "edge " 13 text pp_form " form=" 14 text pp_nl "\n" 15 text pp_bad "ENCODER PARITY FAIL\n" 16 fn pp_num n ulong to void 17 b = new uchar 32 0 18 v = n 19 pos = ulong 32 20 while true bound 32 21 pos = sub pos 1 22 put b pos uchar add rem v 10 48 23 v = div v 10 24 if eq v 0 25 break 26 end 27 end 28 r = write 2 b pos sub 32 pos 29 if ne r long sub 32 pos 30 exit 2 31 end 32 end 33 fn pp_text b view uchar * to void 34 r = write 2 b 0 len b 35 if ne r long len b 36 exit 2 37 end 38 end 39 fn pp_case a edit ulong 16 op ulong j ulong to void 40 for k ulong 16 41 put a k 0 42 end 43 note Registers 0..251: 37 is prime to 252, so 252 consecutive indices give every residue, odd and high-bit included; 44 note src3 = reg + 4 stays at or below 255. WolframLanguageEvaluator: Length[Union[Mod[37 Range[0,1023],252]]] -> 252. 45 reg = rem mul shr j 3 37 252 46 put a 0 op 47 put a 1 reg 48 if isuld op 49 put a 1 rem reg 32 50 end 51 put a 2 reg 52 put a 3 add reg 2 53 put a 4 add reg 4 54 put a 5 rem j 32 55 put a 6 and j 31 56 if eq op 54 57 put a 6 add and j 31 2 58 end 59 if or eq op 18 eq op 29 60 put a 6 and j 255 61 end 62 if eq op 51 63 put a 6 and j 255 64 end 65 if ne and j 8 0 66 note Control (passed through by both encoders) varies all 32 bits and is never 0: `2654435761` is odd, so j+1 below 2^32 67 note never maps to 0. WolframLanguageEvaluator over the 4096 samples with j bit 3 set: 32 of 32 bits take both values. 68 put a 7 rem mul add j 1 `2654435761` `4294967296` 69 end 70 form = shr j 10 71 put a 8 and form 1 72 if ne rem j 3 0 73 put a 9 1 74 end 75 if eq rem j 3 2 76 put a 10 1 77 end 78 put a 11 and shr j 6 15 79 note Subregs 0/1 on dst, src1, src2 and src3: both encoders use phys + subreg. On uniform loads both encoders ignore 80 note dst_subreg; sampling it there keeps that rule under parity too. 81 note src3 = reg + 4 + subreg stays at or below 255 because its subreg is set only while reg is below 251. 82 put a 12 and shr j 4 1 83 put a 13 and shr j 5 1 84 put a 14 and shr j 9 1 85 if lt reg 251 86 put a 15 and shr j 2 1 87 end 88 note Absent operands exercise RZ/default routing independently of the physical register samples. 89 if ne and form 2 0 90 put a 3 `18446744073709551615` 91 end 92 if ne and form 4 0 93 put a 4 `18446744073709551615` 94 end 95 if ne and j 64 0 96 put a 2 `18446744073709551615` 97 end 98 if ne and j 128 0 99 put a 1 `18446744073709551615` 100 end 101 if ne and j 256 0 102 put a 5 `18446744073709551615` 103 end 104 end 105 note Refusal edges. pp_case keeps imm below 288, barrier registers below 16, dst and src1 at or below 252 and the 106 note opcode at or below 78, so it never reaches these refusal bounds of the two encoders: the signed 24-bit offsets 107 note (LDG, STG, fragment loads: -2^23 accepted, -2^23-1 refused, 2^23-1 accepted, 2^23 refused), the LDS offset 108 note (2^23 refused), the BSSY delta (0 and 1 refused, 2 accepted), the BSSY/BSYNC barrier limit (15 accepted, 16 and 109 note 255 refused), the f64 pair bound (252 accepted, 254 refused, on dst, src1, src2 and src3, and 253 through a 110 note subreg), the top uniform register 31, and unknown opcodes 79 and 80. Each case sets one field to one edge on 111 note a fixed even-register base (dst 10, src1 12, src2 14, src3 16, ureg 4, imm 64, control `2654435761`); cases 112 note 22..43 repeat 0..21 with src2 and src3 absent, so ops that refuse a present src2 or src3 still reach the edge. 113 note A C oracle (or encoder) that moves any of these bounds by one changes an accept or a refusal and fails parity. 114 const PP_EDGES ulong 44 115 fn pp_edge a edit ulong 16 op ulong b ulong to void 116 for k ulong 16 117 put a k 0 118 end 119 e = rem b 22 120 put a 0 op 121 put a 1 10 122 put a 2 12 123 put a 3 14 124 put a 4 16 125 put a 5 4 126 put a 6 64 127 put a 7 `2654435761` 128 if ge b 22 129 put a 3 `18446744073709551615` 130 put a 4 `18446744073709551615` 131 end 132 if eq e 1 133 put a 6 `8388607` 134 end 135 if eq e 2 136 put a 6 `8388608` 137 end 138 if eq e 3 139 put a 6 `4286578688` 140 end 141 if eq e 4 142 put a 6 `4286578687` 143 end 144 if eq e 5 145 put a 6 `4294967295` 146 end 147 if eq e 6 148 put a 6 0 149 end 150 if eq e 7 151 put a 6 1 152 end 153 if eq e 8 154 put a 6 2 155 end 156 if eq e 9 157 put a 11 15 158 end 159 if eq e 10 160 put a 11 16 161 end 162 if eq e 11 163 put a 11 255 164 end 165 if eq e 12 166 put a 1 252 167 end 168 if eq e 13 169 put a 1 254 170 end 171 if eq e 14 172 put a 2 252 173 end 174 if eq e 15 175 put a 2 254 176 end 177 if eq e 16 178 put a 3 254 179 end 180 if eq e 17 181 put a 4 254 182 end 183 if eq e 18 184 put a 4 255 185 end 186 if eq e 19 187 put a 1 252 188 put a 12 1 189 end 190 if eq e 20 191 put a 2 252 192 put a 13 1 193 end 194 if eq e 21 195 put a 5 31 196 end 197 note Uniform destinations index uvreg_to_phys (32 entries), as in pp_case. 198 if isuld op 199 put a 1 rem get a 1 32 200 end 201 end 202 fn pp_pack a view ulong 16 ins edit ulong 8192 to void 203 for k ulong 6 204 put ins k get a k 205 end 206 put ins 6 or get a 6 shl get a 7 32 207 f = or get a 8 shl get a 9 1 208 f = or f shl get a 10 2 209 f = or f shl get a 11 8 210 for k ulong 4 211 f = or f shl get a add k 12 add 16 mul k 8 212 end 213 put ins 7 f 214 end 215 fn pp_tape a view ulong 16 to void 216 b = new uchar 128 0 217 for k ulong 16 218 for h ulong 8 219 put b add mul k 8 h uchar and shr get a k mul h 8 255 220 end 221 end 222 n = write 1 b 0 128 223 if ne n 128 224 exit 2 225 end 226 end 227 fn pp_read b edit uchar 24 to void 228 n = ulong 0 229 while lt n 24 bound 24 230 r = read 0 b n sub 24 n 231 if le r 0 232 exit 2 233 end 234 n = add n ulong r 235 end 236 end 237 fn pp_check b view uchar 24 got ulong code view uchar 16384 to bool 238 if eq got 16 239 for k ulong 8 240 if ne get b k 0 241 ret false 242 end 243 end 244 for k ulong 16 245 if ne get b add k 8 get code k 246 ret false 247 end 248 end 249 else 250 for k ulong 8 251 if ne get b k 255 252 ret false 253 end 254 end 255 end 256 ret true 257 end 258 note The refusal-edge pass: tape mode (m 116) writes the records, any other mode checks the replies in the same order. 259 fn pp_edges m ulong to int 260 a = new ulong 16 0 261 ins = new ulong 8192 0 262 phys = new ulong 288 0 263 code = new uchar 16384 0 264 reply = new uchar 24 0 265 for k ulong 256 266 put phys k k 267 end 268 for k ulong 32 269 put phys add k 256 k 270 end 271 for op ulong 82 272 yes = ulong 0 273 for b ulong PP_EDGES 274 pp_edge a op b 275 if eq m 116 276 pp_tape a 277 else 278 pp_pack a ins 279 got = bw_enc_sm121 ins phys 1 0 code 280 if eq got 16 281 yes = add yes 1 282 end 283 pp_read reply 284 if not pp_check reply got code 285 pp_text pp_bad 286 pp_num op 287 pp_text pp_nl 288 pp_num add 8192 b 289 pp_text pp_nl 290 ret 1 291 end 292 end 293 end 294 if ne m 116 295 pp_text pp_edg 296 pp_text pp_op 297 pp_num op 298 pp_text pp_ok 299 pp_num PP_EDGES 300 pp_text pp_yes 301 pp_num yes 302 pp_text pp_no 303 pp_num sub PP_EDGES yes 304 pp_text pp_nl 305 end 306 end 307 ret 0 308 end 309 fn main to int 310 mode = new uchar 8 0 311 a = new ulong 16 0 312 ins = new ulong 8192 0 313 phys = new ulong 288 0 314 code = new uchar 16384 0 315 reply = new uchar 24 0 316 r = argread 1 mode 0 8 317 if lt r 1 318 ret 2 319 end 320 for k ulong 256 321 put phys k k 322 end 323 for k ulong 32 324 put phys add k 256 k 325 end 326 for op ulong 80 327 for form ulong 8 328 yes = ulong 0 329 for j ulong 1024 330 pp_case a op add mul form 1024 j 331 if eq get mode 0 116 332 pp_tape a 333 else 334 pp_pack a ins 335 got = bw_enc_sm121 ins phys 1 0 code 336 if eq got 16 337 yes = add yes 1 338 end 339 pp_read reply 340 if eq get mode 0 114 341 if eq op 0 342 if eq form 0 343 if eq j 0 344 put reply 8 xor get reply 8 1 345 end 346 end 347 end 348 end 349 if not pp_check reply got code 350 pp_text pp_bad 351 pp_num op 352 pp_text pp_nl 353 pp_num j 354 pp_text pp_nl 355 ret 1 356 end 357 end 358 end 359 if ne get mode 0 116 360 pp_text pp_op 361 pp_num op 362 pp_text pp_form 363 pp_num form 364 pp_text pp_ok 365 pp_num 1024 366 pp_text pp_yes 367 pp_num yes 368 pp_text pp_no 369 pp_num sub 1024 yes 370 pp_text pp_nl 371 end 372 end 373 end 374 er = pp_edges ulong get mode 0 375 if ne er 0 376 ret 1 377 end 378 if ne get mode 0 116 379 r = read 0 reply 0 1 380 if ne r 0 381 ret 2 382 end 383 end 384 ret 0 385 end