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
CUDApp / docs / trace / UNIFIED_TRACE.md
| 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 <reason>`. 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 <https://ui.perfetto.dev>, 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.<label>`, and for |
| 167 | diagnostics `code.file.path`, `code.line.number`, `code.column.number` (OpenTelemetry semantic |
| 168 | conventions, code registry). Status code 2 (error) when the status is nonzero. Trace and span ids |
| 169 | are hex, as OTLP/JSON requires. |
| 170 | |
| 171 | ## Source locations |
| 172 | |
| 173 | - **Compiler diagnostics** are exact: omc reports a line of the composed unit (and a column for |
| 174 | `om2 diag` units, whose header must be on line 1 of the composed unit); `omtrace` maps it back to |
| 175 | the unit file and line it came from. |
| 176 | - **Runtime traps** are not exact. The pinned omc emits one trap stub per code per function, so the |
| 177 | exit status says which trap code fired but not which statement. `omtrace` lists every explicit |
| 178 | `trap N` line for that code as `candidates`; implicit traps (bounds, overflow checks) have no |
| 179 | candidate line. Exact per-site identity needs a compiler change (an opt-in per-site stub mode, or |
| 180 | a site id in omc's diagnostic records); it is proposed separately and not part of this change. |
| 181 | |
| 182 | ## Cost |
| 183 | |
| 184 | Tracing composed but off costs one load and one branch per wrapped call. Measured with |
| 185 | `tests/host-trace/overhead*.om` (1000 launches of 64 elements on the host stand-in per sample, 300 |
| 186 | samples per arm in 10 interleaved rounds, one process per arm and round pinned to one core with |
| 187 | `taskset`, load average 17.8-19.6): |
| 188 | |
| 189 | | core | absent (median ns / launch) | off minus absent | on minus absent | |
| 190 | |---|---|---|---| |
| 191 | | cpu19 (Cortex-X925) | 6915.2 | +10.4 ns (+0.15%) | +415.0 ns (+6.0%) | |
| 192 | | cpu14 (Cortex-A725) | 14245.5 | -100.7 ns (-0.71%) | +538.2 ns (+3.8%) | |
| 193 | |
| 194 | The off-versus-absent difference changes sign between core classes and is within 1%. It is the |
| 195 | difference between two different binaries (code layout), not a measurable cost of the off flag. |
| 196 | Recording costs about 0.4-0.5 microseconds per launch on this host path (two clock reads and two |
| 197 | events). Raw samples and the Wolfram statistics are in |
| 198 | `evidence/host-trace-2026-10-26/overhead/`. |
| 199 | |
| 200 | ## Checks |
| 201 | |
| 202 | `OMEGA_COMPILER=/path/to/seed/out/omc sh tests/host-trace/run-host-trace.sh [OUTDIR]` compiles and |
| 203 | runs every check with the seeded compiler and prints `HOST TRACE CHECKS PASS`: |
| 204 | |
| 205 | 1. `recorder-test.om`: 68 checks on the recorder, including off by default, refusals, capacity, |
| 206 | name rules and the dump layout. |
| 207 | 2. `launch-test.om` traced through `omtrace f` against the host stand-in for the device |
| 208 | (`fakenv.om`, `fakedev.om`): 45 checks, then the Chrome and OTLP files are checked for the |
| 209 | launch, copy, stage and NOT_RUN events and the recording is revalidated. |
| 210 | 3. A trap and a compiler diagnostic are traced and located in the unit that caused them. |
| 211 | 4. Malformed recordings: `badfrag.om` writes 13 mutants of a good recording; each is rejected |
| 212 | with its own reason; a missing file exits 6. |
| 213 | 5. Source mutations: removing the second-end refusal, the name charset check or the off-by-default |
| 214 | check makes `recorder-test` fail; removing the end-before-start check stops the time rejection. |
| 215 | |
| 216 | The runner is POSIX sh, like `tests/device-trace/run-emitter-checks.sh`: it only composes, runs and |
| 217 | compares exit codes and lines; every check is a seeded Omega program. |
| 218 | |
| 219 | ## NOT_RUN |
| 220 | |
| 221 | - Device-side timing on GB10 (kernel start/end on the device clock): no GPU window was opened. |
| 222 | - Running `htopen`/`htlaunch` against the real `context.om` on a GB10: host stand-in only. |
| 223 | - Posting the OTLP file to a running OpenTelemetry collector. |
| 224 | - A screenshot of the trace in the Perfetto UI (headless browser screenshots failed on the build |
| 225 | host, including on a blank page). |
| 226 | |
| 227 | ## Relation to other work |
| 228 | |
| 229 | - CUDApp #82 / Omega #778 (OMGT device trace) and CUDApp #93 (trace emitter) cover device-side |
| 230 | trace records. This schema is the host timeline those records can join once a device clock |
| 231 | domain exists. |
| 232 | - Omega trace issues #607-#612 (#610 offline CLI, #612 viewer): `omtrace` is an offline CLI and |
| 233 | uses existing viewers instead of a new one. |
| 234 | - Promoting `aien.unified-trace/1` to a shared protocol repository is a decision for the owner. |