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 / native / blackwell / trace-emit.om

209 lines · 6473 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note Device-side trace emitter for CUDApp #82, first slice. Handwritten seeded Omega.
3note It emits the instruction words for one selected producer (thread 0 of the launched CTA)
4note that records two bounded mark records around one synchronous region, and returns the
5note input words unchanged when tracing is disabled. Enabled input is a prepared linear body
6note fragment, not a complete kernel: the caller must initialise and preserve R0 = TID.X,
7note launch exactly one CTA, and allow both markers to fall through. Branches, calls, returns
8note and early exits are unsupported. EXIT instructions are explicitly refused, but the
9note scanner is not a general control-flow verifier. Markers clobber P0, R2, R4:R13 and UR4:UR5;
10note the caller must account for those live-register effects at both insertion points.
11note
12note Wire layout is PR #83 docs/device-trace/CONTRACT.md v1: 64-byte header, 64-byte records,
13note kinds 1 mark / 2 begin / 3 end, clock domain 1 = raw device GLOBALTIMER low 32 bits with
14note units UNKNOWN. The host owns header initialisation (magic, version, extent, capacity,
15note generation, kernel, manifest, status) and finalises it after completion; this emitter
16note writes records only. No 64-bit clock claim, no nanosecond claim.
17note
18note Register numbers are physical and fixed by this emitter: R0 tid, R2 stamp, R4:R5 trace
19note base, R6 scratch, R8:R9 record address, R10:R11 generation, R12:R13 kernel; the global
20note memory descriptor is loaded into UR4. Encodings are ported from the repository's own
21note encoder, src/omega_blackwell_codegen.c encode_single_insn (S2R 0x7919, ISETP.GE 0x780c,
22note BRA 0x947, LDC64 0xff007b82, LDCU64 0xff0077ac, MOV imm 0x7802, IMAD.WIDE 0x7825,
23note STG.E 0x7986), and each emitted stream is decoded by nvdisasm 13.0 as an outside oracle.
24note
25note Record offsets use full-width base addition via the existing IMAD.WIDE.U32 form.
26note The host must supply a valid nonwrapping allocated extent. The enabled path is refused
27note unless gtchecks is exactly 1. This flag is a precondition, not evidence that arbitrary
28note input words, launch geometry, memory visibility or hardware execution have been checked.
29
30const TRBAS ulong 1024
31const TRGEN ulong 1040
32const TRKRN ulong 1048
33const TRDSK ulong 856
34const HDRSZ ulong 64
35const RECSZ ulong 64
36const MAXCAP ulong 64
37const MAXEXT ulong 4160
38const SITE1 ulong 1
39const SITE2 ulong 2
40const KINDMK ulong 1
41const R_S2R ulong 31001
42const R_ISET ulong 30732
43const R_LDC ulong 4278221698
44const R_LDCU ulong 4278220716
45const R_MOVI ulong 30722
46const R_IMADW ulong 30757
47const R_STG ulong 31110
48const SR_TID ulong 33
49const SR_CLK ulong 82
50const R_BRA ulong 2375
51
52global gbin uchar 4096
53global gbinlen ulong 1
54global gbout uchar 8192
55global gboutlen ulong 1
56global gterr ulong 1
57global gtcap ulong 1
58global gten ulong 1
59global gtchecks ulong 1
60
61fn gtword v uint to void
62for j ulong 4
63put gbout get gboutlen 0 uchar and shr v mul j 8 255
64put gboutlen 0 add get gboutlen 0 1
65end
66end
67
68fn gtquad a uint b uint c uint d uint to void
69gtword a
70gtword b
71gtword c
72gtword d
73end
74
75fn gts2r dst ulong sr ulong to void
76gtquad uint or R_S2R shl dst 16 uint 0 uint shl sr 8 uint 926208
77end
78
79fn gtsel to void
80note ISETP.GE P0, R0, 1: predicate true when tid >= 1, so only tid 0 records.
81gtquad uint R_ISET uint 1 uint 66085488 uint 2087424
82end
83
84fn gtmov dst ulong imm ulong to void
85gtquad uint or R_MOVI shl dst 16 uint imm uint 3840 uint 1040896
86end
87
88fn gtstg bse ulong val ulong off ulong to void
89gtquad uint or R_STG shl bse 24 uint or val shl and off 65535 8 uint 202381572 uint 1040896
90end
91
92fn gtldc dst ulong off ulong to void
93note LDC.64 Rd:Rd+1, c[0x0][off]
94gtquad uint or R_LDC shl dst 16 uint and shl off 6 16776960 uint 2560 uint 926208
95end
96
97fn gtldu dst ulong off ulong to void
98note LDCU.64 URd:URd+1, c[0x0][off] -- the global memory descriptor.
99gtquad uint or R_LDCU shl dst 16 uint and shl off 5 16776960 uint 134220288 uint 945664
100end
101
102fn gtaddr off ulong to void
103note MOV R6, off; IMAD.WIDE.U32 R8:R9, R6, 1, R4:R5 computes base + offset with carry.
104note Existing encoding: src/omega_blackwell_codegen.c BW_IR_IMAD_WIDE; vector.om address pairs.
105gtmov 6 off
106gtquad uint or or R_IMADW shl ulong 8 16 shl ulong 6 24 uint 1 uint 126746628 uint 2083840
107end
108
109fn gtbrak to void
110note BRA @P0 over the fixed 20-instruction mark block: delta 19, rel 18, predicate field 0.
111gtquad uint or R_BRA shl ulong 18 18 uint 0 uint 58720256 uint 1042944
112end
113
114fn gtmark site ulong seq ulong to void
115note One bounded mark record at 64*site (sites 1 and 2). Field offsets are contract v1.
116gtsel
117gtbrak
118gtldu 4 TRDSK
119gts2r 2 SR_CLK
120gtldc 4 TRBAS
121gtldc 10 TRGEN
122gtldc 12 TRKRN
123gtaddr mul site 64
124gtmov 6 site
125gtstg 8 6 0
126gtmov 6 KINDMK
127gtstg 8 6 4
128gtmov 6 seq
129gtstg 8 6 8
130gtstg 8 2 12
131gtstg 8 10 16
132gtstg 8 11 20
133gtstg 8 12 24
134gtstg 8 13 28
135end
136
137fn gtinit cap ulong to bool
138note Bound the extent before any word is emitted. Refusal codes: 1 capacity below two records,
139note 2 extent above the contract maximum, 3 the input is not a whole number of instructions.
140put gterr 0 0
141if gt cap MAXCAP
142put gterr 0 2
143ret false
144end
145if lt cap 2
146put gterr 0 1
147ret false
148end
149if ne rem get gbinlen 0 16 0
150put gterr 0 3
151ret false
152end
153put gtcap 0 cap
154ret true
155end
156
157fn gtwrap on ulong to void
158note Disabled: the output is the input byte for byte; no prologue, no store, no allocation.
159note Enabled: mark(site 1), the caller's prepared body fragment, mark(site 2).
160put gboutlen 0 0
161if eq on 0
162for i ulong get gbinlen 0
163put gbout i get gbin i
164end
165put gboutlen 0 get gbinlen 0
166ret
167end
168gtmark SITE1 0
169for i ulong get gbinlen 0
170put gbout get gboutlen 0 uchar get gbin i
171put gboutlen 0 add get gboutlen 0 1
172end
173gtmark SITE2 1
174end
175
176fn gtbody to bool
177note Reject complete-kernel EXIT regardless of its predicate field (bits 12..15).
178note This recognises the repository's EXIT encoding, not every control-flow instruction.
179for i ulong div get gbinlen 0 16
180p = mul i 16
181lo = ulong get gbin p
182hi = ulong and get gbin add p 1 15
183op = or lo shl hi 8
184if eq op 2381
185put gterr 0 5
186ret false
187end
188end
189ret true
190end
191
192fn gtewrap on ulong cap ulong to bool
193note Checked entry point: refuse before emitting anything, then wrap.
194if not gtinit cap
195ret false
196end
197if and ne on 0 ne get gtchecks 0 1
198note Enabled needs the instruction and control-flow checks to have passed.
199put gterr 0 4
200ret false
201end
202if ne on 0
203if not gtbody
204ret false
205end
206end
207gtwrap on
208ret true
209end