# Kernel-level ledger: where the port loses time against the unmodified Original (`claude/ledger`) RTX 5090 (PCIe 5 x16), driver 595.99, CUDA 13.2, CUPTI 13.2.86, Ryzen 9 9950X3D. Port head `7330ddb` (the `rt-base` test binary) against the Original `~/work/numerics-orig/build/strata`, both traced with the same CUPTI Activity tracer inside holder jobs (one profiling pass per scenario, not an A/B of the Original; the tracer costs 2.4 % of a 16,000-token prefill: 4,335.6 ms traced against 4,234.2 ms untraced, same binary). ## 1. Tools and how to rerun | piece | where | what | | --- | --- | --- | | tracer | `tools/cupti-trace/` (C++, not shipped; `build.sh` in WSL, copy `libleleka_cupti_trace.so` to the server) | CUPTI Activity: concurrent kernels (graph-launched ones per node with `graphId`), memcpy/memcpy2 (kind, bytes, stream, source/destination memory kind), memset, stream/event/context synchronization, driver+runtime API of launch/copy/sync/event/graph/alloc calls. Loaded without touching the process: `CUDA_INJECTION64_PATH=.../libleleka_cupti_trace.so` (or `LD_PRELOAD`). Off until a window is requested, so an armed process costs one 50 ms `stat()` poll. | | windows | trigger file `LELEKA_CUPTI_TRIGGER=`: write `{"seconds": N, "out": "/abs/prefix", "label": "x"}` atomically; the library renames it `.active`, records N s (cap 120, `LCT_MAX_SECONDS`), writes the data to `.lct/` and the summary `.done` (unix-ms bounds of the window), renames the trigger `.done`; `.stop` ends a window early; any number of windows per process, a failure to initialise CUPTI only writes `.error`. Env-only variants: `LCT_START_AFTER_S`, `LCT_START_FILE`, `LCT_START_API=cuMemcpyHtoDAsync:N`, `LCT_START_SYM=:N`, `LCT_DURATION_S`. `LCT_API=0` drops the API records. | used by the holder jobs below and by the e2e CRM job (`scripts/e2e/cupti_trigger.sh`) | | format | per window a directory of fixed-size little-endian record files (`kernel.bin memcpy.bin memset.bin sync.bin api.bin graph.bin`, `strings.tsv`, `threads.tsv`, `meta.txt`), no per-record syscalls | `scripts/profile/lct.py` loads it (pure Python, no numpy; `window_ms=` skips records while loading; kernel names are demangled with `c++filt`, cached) | | single window | `python3 scripts/profile/lct_report.py [--stamps job.full --chunk N]` | kernel families, copies (kind, memory kinds, sizes, achieved GB/s of every H2D copy), GPU idle gaps with the host-side cause, copy/compute overlap, API time | | port vs Original | `python3 scripts/profile/lct_ledger.py PORT.lct ORIG.lct --p-marker leleka_prefill_embed_broadcast --o-marker gr_broadcast --chunk 1` (or `--p-t0/--p-t1/--o-t0/--o-t1` in ms from each window start); step names are mapped by `scripts/profile/steps.map` | the tables below | | decode round | `python3 scripts/profile/lct_decode.py --t0 MS --t1 MS` | per graph launch (verify window, MTP draft/commit steps) GPU span, idle between graphs, per-category kernel time, copies, host calls | | jobs | `scripts/profile/jobs/*.sh` (copy next to `ledger-common.sh` into `~/work/ledger/` and the numbered job into `~/work/gpu-runs/holder2/jobs/`): `901` port 16k, `902/9021` Original 16k, `903/904` 180k, `905/906` decode, `9062` decode with a corpus-own profile, `9001` H2D probe, `9002/9003` fix gates, `9004` aligned decode windows; binaries: `scripts/profile/build_rt.sh TAG` builds the test binary of the worktree in WSL | | Align a trace with the engine's own profile lines: the job logs (`