interplane.Get Omega
Read in your language

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

branch main Branches Tags History

CUDApp / tests / device-trace / emitter-test.om

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