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 / tests / device-trace / emitter-test.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note Host checks for the device-side trace emitter (CUDApp #82 first slice). |
| 3 | note Run: cat native/blackwell/trace-emit.om tests/device-trace/emitter-test.om | seed/out/omc > t; ./t |
| 4 | note Prints one line per check: "id 0" pass, "id 1" fail. Exit status is the failure count. |
| 5 | note The instruction words themselves are decoded independently by nvdisasm 13.0 in |
| 6 | note tests/device-trace/run-emitter-checks.sh against hand-written expectations; this file checks the |
| 7 | note emitter's own invariants so a regression shows up without the external tool. |
| 8 | |
| 9 | global Fails ulong 1 |
| 10 | global Checks ulong 1 |
| 11 | global Ob uchar 256 |
| 12 | global Obn ulong 1 |
| 13 | |
| 14 | fn obc c uchar to void |
| 15 | put Ob get Obn 0 c |
| 16 | put Obn 0 add get Obn 0 1 |
| 17 | end |
| 18 | |
| 19 | fn obn v ulong to void |
| 20 | d = new uchar 20 0 |
| 21 | n = ulong 0 |
| 22 | x = v |
| 23 | put d n uchar add rem x 10 48 |
| 24 | n = add n 1 |
| 25 | x = div x 10 |
| 26 | while gt x 0 |
| 27 | put d n uchar add rem x 10 48 |
| 28 | n = add n 1 |
| 29 | x = div x 10 |
| 30 | end |
| 31 | while gt n 0 |
| 32 | n = sub n 1 |
| 33 | obc get d n |
| 34 | end |
| 35 | end |
| 36 | |
| 37 | fn chk ok bool id ulong to void |
| 38 | put Checks 0 add get Checks 0 1 |
| 39 | put Obn 0 0 |
| 40 | obn id |
| 41 | obc 32 |
| 42 | if ok |
| 43 | obc 48 |
| 44 | else |
| 45 | put Fails 0 add get Fails 0 1 |
| 46 | obc 49 |
| 47 | end |
| 48 | obc 10 |
| 49 | r = write 1 Ob 0 get Obn 0 |
| 50 | end |
| 51 | |
| 52 | fn wrd i ulong to ulong |
| 53 | note 32-bit little-endian word at instruction index i of the emitted stream. |
| 54 | b = mul i 16 |
| 55 | a = shl ulong get gbout b 0 |
| 56 | a = or a shl ulong get gbout add b 1 8 |
| 57 | a = or a shl ulong get gbout add b 2 16 |
| 58 | a = or a shl ulong get gbout add b 3 24 |
| 59 | ret a |
| 60 | end |
| 61 | |
| 62 | fn fill n ulong to void |
| 63 | for i ulong n |
| 64 | put gbin i uchar add 160 rem i 251 |
| 65 | end |
| 66 | put gbinlen 0 n |
| 67 | end |
| 68 | |
| 69 | fn same to bool |
| 70 | if ne get gboutlen 0 get gbinlen 0 |
| 71 | ret false |
| 72 | end |
| 73 | for i ulong get gbinlen 0 |
| 74 | if ne get gbout i get gbin i |
| 75 | ret false |
| 76 | end |
| 77 | end |
| 78 | ret true |
| 79 | end |
| 80 | |
| 81 | fn main to int |
| 82 | put gtchecks 0 1 |
| 83 | fill 64 |
| 84 | ok = gtewrap 0 4 |
| 85 | chk ok 1 |
| 86 | sm = same |
| 87 | chk sm 2 |
| 88 | v = get gboutlen 0 |
| 89 | chk eq v 64 3 |
| 90 | |
| 91 | ok = gtewrap 1 4 |
| 92 | chk ok 4 |
| 93 | v = get gboutlen 0 |
| 94 | chk eq v 704 5 |
| 95 | note Disabled output is exactly the input; enabled output is prologue + input + epilogue. |
| 96 | w = wrd 0 |
| 97 | chk ne w 0 6 |
| 98 | note The caller's kernel bytes ride verbatim in the middle of the enabled stream. |
| 99 | bb = get gbout 320 |
| 100 | chk eq bb 160 7 |
| 101 | bb = get gbout 383 |
| 102 | chk eq bb 223 8 |
| 103 | note Emitting twice with the same inputs gives the same bytes. |
| 104 | ok = gtewrap 1 4 |
| 105 | v = get gboutlen 0 |
| 106 | chk eq v 704 9 |
| 107 | w = wrd 0 |
| 108 | chk eq w 30732 10 |
| 109 | |
| 110 | note Enabled without the instruction checks passed must refuse and emit nothing. |
| 111 | put gtchecks 0 0 |
| 112 | put gboutlen 0 7 |
| 113 | ok = gtewrap 1 4 |
| 114 | chk not ok 11 |
| 115 | v = get gterr 0 |
| 116 | chk eq v 4 12 |
| 117 | v = get gboutlen 0 |
| 118 | chk eq v 7 13 |
| 119 | note Disabled still works with the checks unset and stays byte identical. |
| 120 | ok = gtewrap 0 4 |
| 121 | chk ok 14 |
| 122 | sm = same |
| 123 | chk sm 15 |
| 124 | |
| 125 | note Bounds and refusals. |
| 126 | ok = gtewrap 1 0 |
| 127 | chk not ok 16 |
| 128 | v = get gterr 0 |
| 129 | chk eq v 1 17 |
| 130 | ok = gtewrap 1 1 |
| 131 | chk not ok 18 |
| 132 | v = get gterr 0 |
| 133 | chk eq v 1 19 |
| 134 | ok = gtewrap 1 65 |
| 135 | chk not ok 20 |
| 136 | v = get gterr 0 |
| 137 | chk eq v 2 21 |
| 138 | fill 5 |
| 139 | ok = gtewrap 1 4 |
| 140 | chk not ok 22 |
| 141 | v = get gterr 0 |
| 142 | chk eq v 3 23 |
| 143 | note A refusal must not leave partial output. |
| 144 | v = get gboutlen 0 |
| 145 | chk ne v 704 24 |
| 146 | |
| 147 | note Negative control: mutate one byte of the enabled stream and the length check still holds |
| 148 | note but the byte comparison against the input must fail for the affected region. |
| 149 | fill 64 |
| 150 | put gtchecks 0 1 |
| 151 | ok = gtewrap 1 4 |
| 152 | bb = get gbout 320 |
| 153 | put gbout 320 uchar add bb 1 |
| 154 | bb = get gbout 320 |
| 155 | chk ne bb 160 25 |
| 156 | ret int get Fails 0 |
| 157 | end |