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 / om / c1 / predicate.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | #include "bw_warp_sim.h" |
| 3 | |
| 4 | /* WolframLanguageEvaluator: |
| 5 | * {IntegerString[BitShiftLeft[127,23],16,8], |
| 6 | * Table[Xor[p,i],{p,{False,True}},{i,{False,True}}]} |
| 7 | * -> {"3f800000", {{False, True}, {True, False}}}. |
| 8 | * 0xfeedface is the existing simulator's canary (bw_warp_sim.h). */ |
| 9 | int main(void) { |
| 10 | static BlackwellIRProgram p; |
| 11 | static const struct { BlackwellIROpcode op; uint32_t input, want; } cases[] = { |
| 12 | {BW_IR_I2FP_U32, 1, 0x3f800000u}, |
| 13 | {BW_IR_F2I_U32, 0x3f800000u, 1}, |
| 14 | {BW_IR_MOV_IMM, 1, 1}, |
| 15 | {BW_IR_SHFL_DOWN, 1, 1} |
| 16 | }; |
| 17 | size_t checks = 0; |
| 18 | p.count = 2; |
| 19 | p.regalloc.vreg_to_phys[0] = 0; |
| 20 | p.regalloc.vreg_to_phys[1] = 1; |
| 21 | p.insns[1] = (BlackwellIRInsn){.op = BW_IR_EXIT}; |
| 22 | for (size_t c = 0; c < sizeof cases / sizeof cases[0]; ++c) { |
| 23 | for (unsigned pattern = 0; pattern < 3; ++pattern) for (unsigned inv = 0; inv < 2; ++inv) { |
| 24 | p.insns[0] = (BlackwellIRInsn){ |
| 25 | .op = cases[c].op, .dst_vreg = 0, .src1_vreg = 1, |
| 26 | .src2_vreg = -1, .src3_vreg = -1, .imm = 1, |
| 27 | .predicate_p0 = 1, .predicate_not = inv |
| 28 | }; |
| 29 | WsWarp w = {0}; |
| 30 | WsSim s = {.p = &p}; |
| 31 | w.present = UINT32_MAX; |
| 32 | w.nfrag = 1; |
| 33 | w.frag[0].mask = UINT32_MAX; |
| 34 | for (unsigned lane = 0; lane < WS_WARP; ++lane) { |
| 35 | w.lane[lane].p0 = (uint8_t)(pattern == 2 ? lane & 1u : pattern); |
| 36 | w.lane[lane].r[0] = 0xfeedfaceu; |
| 37 | w.lane[lane].r[1] = cases[c].input; |
| 38 | } |
| 39 | /* An inactive shuffle must walk past an exited lane, while the |
| 40 | * corresponding active shuffle must retain the existing refusal. */ |
| 41 | if (cases[c].op == BW_IR_SHFL_DOWN && pattern == 0 && inv == 0) { |
| 42 | w.exited = 1u; |
| 43 | w.frag[0].mask &= ~1u; |
| 44 | } |
| 45 | if (ws_run_warp(&s, &w, 0, 0, 0, 0) != 0) { |
| 46 | fprintf(stderr, "C1 PREDICATE FAIL op=%u: %s\n", (unsigned)cases[c].op, s.msg); |
| 47 | return 1; |
| 48 | } |
| 49 | for (unsigned lane = 0; lane < WS_WARP; ++lane) { |
| 50 | uint32_t want = w.lane[lane].p0 != inv ? cases[c].want : 0xfeedfaceu; |
| 51 | ++checks; |
| 52 | if (w.lane[lane].r[0] != want) { |
| 53 | fprintf(stderr, "C1 PREDICATE FAIL op=%u pattern=%u inv=%u lane=%u got=%08x want=%08x\n", |
| 54 | (unsigned)cases[c].op, pattern, inv, lane, w.lane[lane].r[0], want); |
| 55 | return 1; |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | { |
| 61 | WsWarp w = {0}; |
| 62 | WsSim s = {.p = &p}; |
| 63 | p.insns[0].op = BW_IR_SHFL_DOWN; |
| 64 | p.insns[0].predicate_not = 0; |
| 65 | w.present = UINT32_MAX; |
| 66 | w.exited = 1u; |
| 67 | w.nfrag = 1; |
| 68 | w.frag[0].mask = UINT32_MAX & ~1u; |
| 69 | for (unsigned lane = 0; lane < WS_WARP; ++lane) w.lane[lane].p0 = 1; |
| 70 | ++checks; |
| 71 | if (ws_run_warp(&s, &w, 0, 0, 0, 0) == 0 || s.err != WS_E_SHFL_EXITED) { |
| 72 | fprintf(stderr, "C1 PREDICATE FAIL active SHFL structural refusal changed\n"); |
| 73 | return 1; |
| 74 | } |
| 75 | } |
| 76 | printf("C1 PREDICATE PASS checks=%zu (guarded unsigned conversions, MOV and SHFL)\n", checks); |
| 77 | return 0; |
| 78 | } |