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/docs/trace/UNIFIED_TRACE.md # 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 / docs / trace / UNIFIED_TRACE.md` 234 lines · 13193 bytes Raw Blame History Rendered 1 # Unified trace: one timeline from Omega source to launch 2 3 Status: **PROPOSED** schema `aien.unified-trace/1`. The host recorder, the `omtrace` tool and their 4 host checks are IMPLEMENTED and EXERCISED on the host. Device-side timing is **NOT_RUN**: nothing 5 here reads a GPU clock, and no GPU was opened to produce any number in this file. 6 7 ## What it gives you 8 9 One trace that follows a program from the Omega compiler through the CUDA++ runtime: 10 11 ``` 12 omtrace (host process: compile and run) 13 ├─ source.read compose omc.compile diag.decode compile phases 14 ├─ omc.error file.om:3:13, error 3 compiler diagnostic, in the unit that caused it 15 └─ program.run the traced program 16 ├─ gpu.open launch.om:gbopen bytes allocated, code bytes, status 17 │ └─ mem.alloc launch.om:gbmem x8 bytes, buffer slot 18 ├─ mem.copy host.upload:a.b bytes, direction 19 ├─ kernel.launch kernel:VECTOR_1D/vector.om:gbvec elements, last stage reached, status 20 │ └─ mem.moved launch.om:gbcmd command bytes written 21 └─ trap range, candidates t1.om:3 Omega trap code and the source lines that raise it 22 device (NOT_RUN: no device clock recorded) 23 ``` 24 25 Names are semantic (Omega unit, function, kernel), not driver handles. The same file opens in 26 Perfetto and Chrome's trace viewer, and the same events export as OpenTelemetry spans, so one 27 schema serves a desktop viewer and a fleet collector. 28 29 It uses no CUPTI, NVTX, Nsight, libcuda or other NVIDIA interface. The runtime records what its own 30 code does; every timestamp is the host's `CLOCK_MONOTONIC`. 31 32 ## Pieces 33 34 | File | Role | 35 |---|---| 36 | `native/trace/htrec.om` | The recorder. Fixed tables (4096 events, 256 names, 16 KiB of name bytes), off until `htinit`, writes the binary OTR1 file with `htdump`. | 37 | `native/trace/htlaunch.om` | `htopen` / `htlaunch`: traced entry points for `native/blackwell/launch.om`. They behave exactly like `gbopen` / `gblaunch`. `launch.om` is not changed. | 38 | `tools/omtrace/omtrace.om` | Wraps the pinned `omc`: times the compile phases, decodes diagnostics, optionally runs the program, merges the OTR1 file it writes, validates it, and writes Chrome JSON and OTLP JSON. | 39 | `docs/trace/unified-trace.chrome.schema.json` | JSON Schema (2020-12) for the Chrome export. | 40 | `tests/host-trace/` | Host checks with negative controls and the overhead driver (below). | 41 42 All three are handwritten seeded Omega. A unit that does not concatenate `htrec.om` and 43 `htlaunch.om` contains no trace code at all. 44 45 ## Using it 46 47 ```sh 48 O=/path/to/omega-mv/seed/out/omc 49 cat native/trace/htrec.om tools/omtrace/omtrace.om | $O > omtrace && chmod +x omtrace 50 51 # compile only: ./omtrace c $O out/prog - unit1.om unit2.om ... 52 # compile and run: ./omtrace r $O out/prog - unit1.om unit2.om ... 53 # compile, run, merge OTR1: ./omtrace f $O out/prog out/prog.otr unit1.om ... 54 # (the program is run as `out/prog.bin out/prog.otr` and must write its recording there) 55 # validate a recording: ./omtrace v out/prog.otr 56 ``` 57 58 Outputs: `PREFIX.unit.om` (the composed unit), `PREFIX.bin`, `PREFIX.omc.err`, 59 `PREFIX.trace.json` (Chrome/Perfetto), `PREFIX.otlp.json` (OTLP/JSON). 60 61 Exit codes: 0 traced; 2 usage; 3 compile failed (the trace is still written and shows where); 62 4 output too large; 5 cannot write; 6 fragment unreadable; 20..31 fragment rejected, reason on 63 stderr as `OMTRACE_REJECT `. A traced program's exit status 100+N means it hit trap N. 64 65 In a program: compose `htrec.om` (and `htlaunch.om` for launches), call `htinit` to start, use 66 `htopen` / `htlaunch` in place of `gbopen` / `gblaunch`, add your own spans with 67 `s = htbeg 9 ID` … `htend s a0 a1 rc` and marks with `htmark 10 ID a0 a1 rc`, register names with 68 `htnbeg ID` / `htnbyte b` / `htnend`, and call `htdump fd` at the end. 69 70 ### Viewing 71 72 1. Open , choose **Open trace file**, pick `PREFIX.trace.json`. The UI 73 parses the file in the browser. Chrome's `chrome://tracing` also opens it. 74 2. SQL over the same file with Perfetto's trace processor: 75 `trace_processor -q q.sql PREFIX.trace.json` with 76 `select name, category, ts, dur from slice order by ts;` 77 3. OpenTelemetry: `PREFIX.otlp.json` is an OTLP/JSON `TracesData` body. A collector with an OTLP/HTTP 78 receiver accepts it at `/v1/traces` with `Content-Type: application/json`. (Posting to a collector 79 was not exercised; see NOT_RUN.) 80 81 A sample from the host launch test is in 82 `evidence/host-trace-2026-10-26/sample/`. 83 84 ## Event kinds 85 86 Every event has a kind, a name id, a start and end time, two unsigned arguments `a0`, `a1` and a 87 signed status `rc`. Exports label `a0`/`a1` per kind: 88 89 | id | kind | form | a0 | a1 | status | 90 |---|---|---|---|---|---| 91 | 1 | compile.phase | span | bytes | count | phase result | 92 | 2 | diag | instant | line | col | omc error number | 93 | 3 | gpu.open | span | bytes_allocated | code_bytes | nverr | 94 | 4 | kernel.launch | span | elements | stage (+ `stage_name`) | nverr | 95 | 5 | mem.alloc | instant | bytes | slot | handle sign | 96 | 6 | mem.copy | span | bytes | direction (1 to device, 2 to host) | result | 97 | 7 | host.wait | span | a0 | a1 | result | 98 | 8 | trap | instant | code (+ `trap_name`) | count | program exit | 99 | 9 | user.span | span | a0 | a1 | rc | 100 | 10 | user.mark | instant | a0 | a1 | rc | 101 | 11 | mem.moved | instant | bytes | direction | rc | 102 103 Arguments are counts, sizes, stages and status codes only, never addresses, payload bytes or user 104 data. Launch stages: 40 build.upload, 41 submit, 42 host.wait, 43 complete.check, 0 refused. 105 Because `launch.om` has no hook between stages, a host wait inside `gblaunch` appears as a 106 `kernel.launch` span whose last stage is `host.wait` (42), not as a separate `host.wait` span. 107 108 Trap names: 1 overflow, 2 divzero, 3 range, 4 loopbound, 6 stack, 7 shift, 9 requires, 109 10 ensures (also invariant and seal), others `codeN`. 110 111 ## OTR1 recording (binary, little-endian) 112 113 Header, 64 bytes: 114 115 | offset | type | field | 116 |---|---|---| 117 | 0 | u32 | magic `827479119` (`OTR1`) | 118 | 4 | u16 | version 1 | 119 | 6 | u16 | record size 48 | 120 | 8 | u32 | event count | 121 | 12 | u32 | dropped (past capacity) | 122 | 16 | u32 | refused (malformed calls) | 123 | 20 | u32 | clock domain, 1 = host CLOCK_MONOTONIC ns | 124 | 24 | u64 | monotonic time at `htinit` | 125 | 32 | u64 | realtime at `htinit` (ns since the Unix epoch) | 126 | 40 | u32 | process id | 127 | 44 | u32 | name count | 128 | 48 | u32 | spans still open at dump | 129 | 52 | 12 bytes | zero | 130 131 Then `count` records of 48 bytes: u16 kind, u16 flags (bit 0 closed), u32 name id, u64 t0, u64 t1, 132 u64 a0, u64 a1, i64 rc. Then `name count` names: u32 id, u16 length (1..63), bytes from 133 `[A-Za-z0-9._:/-]`. The largest recording is 214592 bytes. 134 135 The recorder refuses, and counts, a call with an unknown kind, a kind in the wrong form, an unknown 136 name, a bad span slot, a second end or an end before its begin. Events past capacity are counted as 137 dropped. Both counts, and the number of spans left open, are in the header; the exports carry the 138 totals (see Exports) so a trace that lost events never looks complete. 139 140 `omtrace v` and `omtrace f` reject a recording, with a distinct exit, when the magic (20), version 141 (21), record size (22), clock domain (23), file size (24), count (25), kind (26), form (27), times 142 (28), a name (29), a name reference (30) or the open-span count (31) is wrong. 143 144 ## Clocks 145 146 Times are host monotonic nanoseconds. `omtrace` and the program each record their monotonic and 147 real time at start, so the exporter places both on one axis: Chrome `ts`/`dur` are microseconds from 148 the first event; OTLP times are Unix nanoseconds (`real0 + t - mono0`). No device clock exists in 149 this schema version; a future clock domain 2 (device) needs GPU-side evidence first. 150 151 ## Exports 152 153 **Chrome trace JSON** (`displayTimeUnit` ns). Process `omtrace` for compile phases, process `program` 154 for runtime events, and a `device` row carrying the instant `device.timing.NOT_RUN`. Spans are `X` 155 events, instants `i` events with process scope; `cat` is the kind; `args` hold the labels above. 156 `otherData` records the schema, the clock, `device_timing: NOT_RUN`, and `dropped`, `refused` and 157 `open_spans`: dropped and refused add omtrace's own recorder to the program's header counts; 158 `open_spans` is the program's header count (omtrace's own root span is always closed by export). 159 Names are pooled once per name, not per event, so a full 4096-event recording exports. 160 161 **OTLP/JSON** (`TracesData`). One resource (`service.name=omtrace`, `aien.trace.schema`, 162 `aien.device_timing=NOT_RUN`, and integer `aien.dropped`, `aien.refused`, `aien.open_spans` with the 163 same values as `otherData`), scope `aien.unified-trace` version 1. `traceId` is the hex of 164 omtrace's real start time and pid; `spanId` is the event index + 1; the parent is the smallest span 165 that contains the event (so program events sit under `program.run`). Instants become zero-length 166 spans. Attributes: `aien.kind`, `aien.source`, the per-kind labels as `aien.