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