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 / trace / htrec.om

324 lines · 6803 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note Host-side event recorder for the unified trace (docs/trace/UNIFIED_TRACE.md). Handwritten
3note seeded Omega, program mode only (it reads monons and realns and writes a descriptor).
4note
5note The recorder is off until htinit. Every recording call checks the flag first and returns at
6note once while it is off; wrappers should test htlive themselves so that the off path is one load
7note and one branch. A unit that does not concatenate this file carries no trace code at all.
8note
9note Storage is fixed: HTCAP events, HTNCAP names, HTNBYT name bytes. Nothing is allocated. An event
10note past capacity is counted in dropped and not stored; a malformed call (unknown kind, kind used
11note in the wrong form, unknown name, bad slot, second end, end before begin) is counted in refused
12note and stores nothing. The dump writes the OTR1 wire layout of docs/trace/UNIFIED_TRACE.md.
13note Times are host CLOCK_MONOTONIC nanoseconds (clock domain 1). No device clock is read here.
14note Event arguments are counts, sizes, stages and status codes only: never addresses, payload
15note bytes or user data.
16const HTCAP ulong 4096
17const HTNCAP ulong 256
18const HTNBYT ulong 16384
19global htst ulong 16
20global htkind uint 4096
21global htname uint 4096
22global htfl uchar 4096
23global htt0 ulong 4096
24global htt1 ulong 4096
25global hta0 ulong 4096
26global hta1 ulong 4096
27global htrc long 4096
28global htnid uint 256
29global htnoff ulong 256
30global htnln ulong 256
31global htnb uchar 16384
32global htout uchar 262144
33note htst slots: 0 on, 1 events, 2 dropped, 3 refused, 4 mono0, 5 real0, 6 names, 7 open spans,
34note 8 name bytes used, 9 name being built (index + 1, 0 none), 10 pid.
35fn htlive to bool
36ret eq get htst 0 1
37end
38fn htrefuse to bool
39put htst 3 add get htst 3 1
40ret false
41end
42note Kinds 1..11. Span kinds: 1 compile.phase, 3 gpu.open, 4 kernel.launch, 6 mem.copy, 7 host.wait,
43note 9 user.span. Instant kinds: 2 diag, 5 mem.alloc, 8 trap, 10 user.mark, 11 mem.moved (bytes moved
44note inside an enclosing span and not timed on their own).
45fn htspan k uint to bool
46if or eq k 1 eq k 3
47ret true
48end
49if or eq k 4 eq k 6
50ret true
51end
52ret or eq k 7 eq k 9
53end
54fn htinst k uint to bool
55if or eq k 2 eq k 5
56ret true
57end
58if or eq k 8 eq k 10
59ret true
60end
61ret eq k 11
62end
63note htinit starts a new session: counters and events reset; registered names (slots 6, 8) stay.
64fn htinit to bool
65put htst 0 0
66for i ulong 6
67put htst i 0
68end
69put htst 7 0
70put htst 9 0
71put htst 4 ulong monons
72put htst 5 ulong realns
73put htst 10 ulong getpid
74put htst 0 1
75ret true
76end
77fn htstop to void
78put htst 0 0
79end
80note Name registration: htnbeg id, then htnbyte for each byte, then htnend. A name is 1..63 bytes of
81note A-Z a-z 0-9 . _ : / - and its id is unique and nonzero. Registration works while recording is
82note off too, so a program can name its sites once at start.
83fn htnok b uchar to bool
84if and ge b 48 le b 57
85ret true
86end
87if and ge b 65 le b 90
88ret true
89end
90if and ge b 97 le b 122
91ret true
92end
93if or eq b 46 eq b 95
94ret true
95end
96ret or or eq b 58 eq b 47 eq b 45
97end
98fn htnfind id uint to ulong
99n = get htst 6
100for i ulong n
101if eq get htnid i id
102ret add i 1
103end
104end
105ret 0
106end
107fn htnbeg id uint to bool
108if ne get htst 9 0
109put htst 9 0
110ret htrefuse
111end
112if or eq id 0 ne htnfind id 0
113ret htrefuse
114end
115n = get htst 6
116if ge n HTNCAP
117ret htrefuse
118end
119put htnid n id
120put htnoff n get htst 8
121put htnln n 0
122put htst 9 add n 1
123ret true
124end
125fn htnbyte b uchar to bool
126s = get htst 9
127if eq s 0
128ret htrefuse
129end
130i = sub s 1
131at = add get htnoff i get htnln i
132if or ge at HTNBYT ge get htnln i 64
133put htnln i 64
134ret false
135end
136put htnb at b
137put htnln i add get htnln i 1
138ret true
139end
140fn htnend to bool
141s = get htst 9
142put htst 9 0
143if eq s 0
144ret htrefuse
145end
146i = sub s 1
147n = get htnln i
148if or eq n 0 gt n 63
149ret htrefuse
150end
151o = get htnoff i
152for j ulong n
153if not htnok get htnb add o j
154ret htrefuse
155end
156end
157put htst 6 add i 1
158put htst 8 add o n
159ret true
160end
161note htbeg: open a span; the result is the slot + 1, or 0 when nothing was stored (off, dropped or
162note refused). htend with slot 0 is a no-op that returns false, so a caller need not branch.
163fn htslot k uint nm uint to ulong
164if not htlive
165ret 0
166end
167if eq htnfind nm 0
168b = htrefuse
169ret 0
170end
171n = get htst 1
172if ge n HTCAP
173put htst 2 add get htst 2 1
174ret 0
175end
176put htkind n k
177put htname n nm
178put htfl n 0
179put hta0 n 0
180put hta1 n 0
181put htrc n 0
182put htst 1 add n 1
183ret add n 1
184end
185fn htbeg k uint nm uint to uint
186if not htlive
187ret 0
188end
189if not htspan k
190b = htrefuse
191ret 0
192end
193s = htslot k nm
194if eq s 0
195ret 0
196end
197i = sub s 1
198put htt0 i ulong monons
199put htt1 i get htt0 i
200put htst 7 add get htst 7 1
201ret uint s
202end
203fn htend s uint a0 ulong a1 ulong rc long to bool
204if or eq s 0 not htlive
205ret false
206end
207if gt ulong s get htst 1
208ret htrefuse
209end
210i = sub ulong s 1
211if ne get htfl i 0
212ret htrefuse
213end
214t = ulong monons
215if lt t get htt0 i
216ret htrefuse
217end
218put htt1 i t
219put hta0 i a0
220put hta1 i a1
221put htrc i rc
222put htfl i 1
223put htst 7 sub get htst 7 1
224ret true
225end
226fn htmark k uint nm uint a0 ulong a1 ulong rc long to bool
227if not htlive
228ret false
229end
230if not htinst k
231ret htrefuse
232end
233s = htslot k nm
234if eq s 0
235ret false
236end
237i = sub s 1
238put htt0 i ulong monons
239put htt1 i get htt0 i
240put hta0 i a0
241put hta1 i a1
242put htrc i rc
243put htfl i 1
244ret true
245end
246note ---- OTR1 dump. Little-endian fields into htout, then one write loop.
247fn htw at ulong v ulong k ulong to void
248for i ulong k
249put htout add at i uchar and shr v mul i 8 255
250end
251end
252fn hthead to void
253put htout 0 79
254put htout 1 84
255put htout 2 82
256put htout 3 49
257htw 4 1 2
258htw 6 48 2
259htw 8 get htst 1 4
260htw 12 get htst 2 4
261htw 16 get htst 3 4
262htw 20 1 4
263htw 24 get htst 4 8
264htw 32 get htst 5 8
265htw 40 get htst 10 4
266htw 44 get htst 6 4
267htw 48 get htst 7 4
268htw 52 0 4
269htw 56 0 8
270end
271fn htrecw i ulong to void
272at = add 64 mul i 48
273htw at ulong get htkind i 2
274htw add at 2 ulong get htfl i 2
275htw add at 4 ulong get htname i 4
276htw add at 8 get htt0 i 8
277htw add at 16 get htt1 i 8
278htw add at 24 get hta0 i 8
279htw add at 32 get hta1 i 8
280htw add at 40 bitcast ulong get htrc i 8
281end
282fn htnamew at ulong i ulong to ulong
283htw at ulong get htnid i 4
284n = get htnln i
285htw add at 4 n 2
286o = get htnoff i
287for j ulong n
288put htout add add at 6 j get htnb add o j
289end
290ret add add at 6 n
291end
292note htbytes: the dump length. The image is complete only after htdump.
293fn htbytes to ulong
294n = get htst 1
295at = add 64 mul n 48
296for i ulong get htst 6
297at = add add at 6 get htnln i
298end
299ret at
300end
301fn htimage to ulong
302hthead
303n = get htst 1
304for i ulong n
305htrecw i
306end
307at = add 64 mul n 48
308for i ulong get htst 6
309at = htnamew at i
310end
311ret at
312end
313fn htdump fd int to long
314n = htimage
315done = ulong 0
316while lt done n bound 262144
317w = write fd htout done sub n done
318if le w 0
319ret -5
320end
321done = add done ulong w
322end
323ret long n
324end