From 6c0a5fc1f07d6a79639eb853f4c04173ff0841af Mon Sep 17 00:00:00 2001 From: Pavlo Ratushnyi Date: Wed, 11 Nov 2026 01:24:28 +0100 Subject: [PATCH] Windows of S11, S9, U5a: section deltas with the repeat as noise (reader script and note) window_increment_report.py reads CUPTI windows offline (extract on the server, report on the laptop): switches that really ran (kernel names, engine log), per-T per-launch durations, increment deltas against the CZ-CD repeat. The note records that the windows of verify-s11-s9-u5a-cupti-windows are cumulative and the deltas per switch. Co-Authored-By: Claude Sonnet 5.5 --- docs/experiments/verify-s11-s9-u5a-windows.md | 376 ++++++++++++++++++ .../codex/speed/window_increment_report.py | 356 +++++++++++++++++ 2 files changed, 732 insertions(+) create mode 100644 docs/experiments/verify-s11-s9-u5a-windows.md create mode 100644 scripts/e2e/codex/speed/window_increment_report.py diff --git a/docs/experiments/verify-s11-s9-u5a-windows.md b/docs/experiments/verify-s11-s9-u5a-windows.md new file mode 100644 index 00000000..b99082de --- /dev/null +++ b/docs/experiments/verify-s11-s9-u5a-windows.md @@ -0,0 +1,376 @@ +# Verify switches S11, S9, U5a: section deltas from the CUPTI windows (2026-11-11) + +Source: `/data/leleka-e2e/spd-gap/runs/verify-s11-s9-u5a-cupti-windows/{CP,CS,CH,CD,CZ}.1/win-r29.lct` (job log +`job-233307.log`; request 29 of the replay, 15 s windows, floor profile, 2026-11-10 23:33 to 00:11). Read offline with +`scripts/e2e/codex/speed/window_increment_report.py` (stdlib, no GPU; the traces were only read on `rnr5090`). Nothing here +is an end-to-end result: these are section deltas inside the verify graph, kernel durations and spans from CUPTI. The e2e +A/B stays the one group A/B at the end of the stage. + +## Summary + +| step | switch | what really ran | section delta (CUPTI, in-graph) | noise | resolved | recommendation | +| --- | --- | --- | --- | --- | --- | --- | +| S11 | `LELEKA_SM120_COMBINE_VEC4` | CS vs CP | combine `mtp_full_combine` 1.50 -> `leleka_verify_combine_k10_vec4` 1.15 us per launch (-0.35 us, 48 launches): **-0.0144 .. -0.0174 ms per graph** (T 1..6), -0.0164 weighted by CP's T mix | <= 0.0004 ms per graph, <= 0.03 us per launch | yes, every T | **enable by default in the 5090 profiles** (identity PASS 2057/2057, delta > 0 beyond the noise); it is small | +| S9 | `LELEKA_SM120_HEAD_MIX_MULTI` | CH vs CS | head launches 5T -> 3 (-(5T-3) a graph, confirmed), head span **-0.0004 / -0.0118 / -0.0244 / -0.0368 / -0.0482 / -0.0605 ms per graph** at T 1..6, -0.0233 weighted | <= 0.0001 ms | yes (grows with T) | stays OFF (not bitwise: 25 of 2057 rows differ, d_top1 max 0.0015) whatever the delta; the delta is small | +| U5a | `LELEKA_SM120_GR_DOWN_FUSED` | CD vs CH | the fused kernel is **slower** than split + down: pair per layer half +1.47 / +2.46 / +1.69 / +1.44 / +0.32 / -0.10 us at T 1..6 (p50), **+0.144 / +0.238 / +0.160 / +0.146 / +0.033 / +0.026 ms per graph**, +0.145 weighted | <= 0.003 ms, <= 0.03 us per launch | yes (a loss) | **do not enable**; the microbench prediction (-3..6 us per layer half, -0.30..-0.56 ms) did not carry over to the graph | + +Sign convention: delta = later window minus earlier, so negative is faster. Deltas are p50 over graphs of the same T within +one window (the mean agrees to the third decimal); the table values are the T mix weighted ones of section 4 of the +appendix where "weighted" is said. + +## 1. The windows are cumulative (confound), and which switches each really ran + +The job script did not unset the per-variant switches between variants (a `CS` export leaked into `CH` and `CD`; fixed in +`8b2bd4d5e`, which also adds the independent variants WD/WH/WW/WZ for later windows). Evidence is in two independent +places that agree: the switch line the engine printed (`requested Sm120Switches` in each `engine.log`) and the kernel +names launched in the verify graphs (appendix, section 1): + +| window | engine log (combine_vec4 / head_mix_multi / gr_down_fused) | kernels | really ran | +| --- | --- | --- | --- | +| CP | false / false / false | `mtp_full_combine` 48 per graph, `mtp_full_gr_norm` 3.13 (5 launches per token), `chain_gr_split` 96 | none (the profile set only: attn_daily, gu_swiglu, side mixer/qsa/shared, fused qsa prelude) | +| CS | true / false / false | `leleka_verify_combine_k10_vec4` 48, `mtp_full_combine` 0, head chain still 5 per token | S11 | +| CH | true / true / false | head chain gone (`mtp_full_gr_norm` 0), head = `chain_gr_split` + down + `chain_gr_up8` (3 launches), `chain_gr_split` 97 | S11 + S9 | +| CD | true / true / true | `leleka_gr_down_fused_t2w8` 96, `chain_gr_split` 1 and `chain_gr_down_t2w8_nb4` 1 (the head's own read, which U5a does not touch), `chain_gr_up8` 97 | S11 + S9 + U5a | +| CZ | true / true / true | as CD | S11 + S9 + U5a (the repeat of CD) | + +So the increments are S11 = CS - CP, S9 = CH - CS, U5a = CD - CH, noise = CZ - CD. Nothing in the data is an isolated +S9 or U5a (each also runs on top of S11, and U5a on top of S9); the increments are valid as section deltas because the +sections do not overlap: the combine kernel (S11), the five-launch head chain after the last layer (S9), and the layer +halves' hyper-connection split + down (U5a). The unchanged kernels are the control: `chain_gr_up8` is 7.36 / 7.36 / 7.36 / +7.39 / 7.39 us at T 2 across the five windows and `chain_gr_split` / `chain_gr_down_t2w8_nb4` are identical in CP, CS, CH +to 0.03 us. The traces' `meta.txt` record exe `/data/leleka-e2e/codex-compare/ours-prefix/bin/leleka-inference` (the job +names `bin-s11-s9-u5a`); the kernels above show the new code is in it. + +## 2. Windows and sections + +Verify graph = at least 900 kernels per correlation id, the first and last two dropped (the same rule as +`ffn_phase_timeline.py`); T = the grid of `chain_copy_rows_from_mapped_kernel` / 10. Kept graphs 845 / 864 / 785 / 767 / +920 (CP/CS/CH/CD/CZ); per T (CP/CS/CH/CD/CZ): T1 38/44/55/29/50, T2 271/295/149/224/278, T3 286/269/297/150/372, T4 +114/181/100/167/132, T5 88/41/137/94/57, T6 27/17/27/38/21 (T7, T8 have 2-34 graphs and are left out; T5 and T6 are thin in +some windows). Sections (all per graph; "span" includes the gaps between the kernels): + +* combine: the routed-expert combine, one launch per layer (48 a graph). +* head: the kernels after the last `mtp_full_native_write` up to the `head_quant` that feeds the language-model head. +* pair: a layer half's `chain_gr_split` + `chain_gr_down_t2w8_nb4` (96 per graph), or `leleka_gr_down_fused_t2w8`. +* read: that instance up to the end of `chain_gr_up8` (the whole hyper-connection read of a layer half). +* GR role: every hyper-connection kernel of the graph (layers and head). + +## 3. Per-launch durations (p50, us; launches per graph in the appendix) + +At T=3 (T=2 and T=3 are the commonest windows; all T in the appendix, section 2): + +| kernel | CP | CS | CH | CD | CZ | +| --- | ---: | ---: | ---: | ---: | ---: | +| `mtp_full_combine` / `leleka_verify_combine_k10_vec4` (48 per graph) | 1.50 | 1.15 | 1.15 | 1.15 | 1.15 | +| K10 `chain_gr_split` (96 per graph, 97 with the head's) | 3.04 | 3.04 | 3.04 | gone (1 per graph) | gone | +| `chain_gr_down_t2w8_nb4` | 10.53 | 10.53 | 10.53 | gone | gone | +| `leleka_gr_down_fused_t2w8` (96 per graph) | - | - | - | 15.29 | 15.26 | +| pair (split + down, or fused), per layer half | 13.60 | 13.60 | 13.60 | 15.29 | 15.26 | +| `chain_gr_up8` | 8.00 | 8.00 | 8.00 | 8.03 | 8.03 | +| read span per layer half (split/fused start to up8 end) | 21.95 | 21.92 | 21.92 | 23.55 | 23.52 | +| head launches per graph | 15 | 15 | 3 | 3 | 3 | +| head kernel time / head span, us per graph | 44.3 / 45.9 | 44.2 / 45.7 | 20.9 / 21.4 | 20.9 / 21.4 | 20.8 / 21.3 | +| GR role kernel time, us per graph | 2076 | 2075 | 2097 | 2259 | 2256 | + +Fused kernel by window rows (p50 us, CD): T1 12.64, T2 15.52, T3 15.29, T4 15.68, T5 16.13, T6 16.74. The pair it replaces +(CH): 11.17, 13.06, 13.60, 14.24, 15.84, 16.80. The fused kernel's cost is nearly flat in T while the pair's grows, so it +loses at T 1-4 (where most graphs are) and breaks even at T 5-6. K10: `chain_gr_split` is 3.04-3.14 us (96 per graph = 0.29-0.30 ms +a graph) in the three windows that have it; U5a removes it but costs more than it removes. The back-to-back launch gap +inside the pair is only 0.1 us (pair span minus pair kernel time), so there is no launch saving for the fuse to win. + +Kernel counts: S11 changes none; S9 removes 7 / 12 / 17 / 22 / 27 kernels at T 2..6 (CH minus CS kernels per graph += `5T - 3`, appendix section 5); U5a removes 96. + +## 4. Section deltas, noise and resolvability (ms per graph; p50 delta, T 1..6) + +| increment | section | T1 | T2 | T3 | T4 | T5 | T6 | weighted | noise (CZ-CD), T1..T6 | +| --- | --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | --- | +| S11 (CS-CP) | combine kernel time | -0.0174 | -0.0166 | -0.0167 | -0.0165 | -0.0150 | -0.0144 | -0.0164 | -0.0001 .. +0.0004 | +| S9 (CH-CS) | head kernel time | -0.0004 | -0.0112 | -0.0233 | -0.0354 | -0.0464 | -0.0583 | -0.0223 | <= 0.0001 | +| S9 (CH-CS) | head span (gaps incl.) | -0.0004 | -0.0118 | -0.0244 | -0.0368 | -0.0482 | -0.0605 | -0.0233 | <= 0.0001 | +| U5a (CD-CH) | pair kernel time (96 layer halves) | +0.1438 | +0.2379 | +0.1598 | +0.1460 | +0.0325 | +0.0256 | +0.1445 | -0.0046 .. +0.0005 | +| U5a (CD-CH) | pair span | +0.1344 | +0.2285 | +0.1504 | +0.1365 | +0.0229 | +0.0161 | +0.1351 | same | +| U5a (CD-CH) | GR role kernel time | +0.1408 | +0.2399 | +0.1619 | +0.1485 | +0.0339 | +0.0272 | +0.1462 | -0.0042 .. +0.0017 | + +Per launch (us; p50): S11 combine -0.38 / -0.35 / -0.35 / -0.35 / -0.32 / -0.29; U5a pair per layer half +1.47 / +2.46 / ++1.69 / +1.44 / +0.32 / -0.10 (the mean at T6 is +0.31, so T6 is a tie at best), noise within 0.03 us (the p50 of the +combine moves in steps of about 0.03 us). Per layer half for S11, whose launch is one per layer, divide by two: +about -0.17 us per layer half. + +How to read the noise: CZ and CD are the same configuration in two sessions. Their section values differ by at most 0.005 +ms per graph and 0.03 us per launch, so every delta above is at least 3 times the repeat's own delta (S11 more than 30 times) and is resolved by the +script's rule (p50 and mean agree in sign, the mean delta above two standard errors, both above the repeat). Spread across +T is not noise: S9 follows the 5T-3 launches saved (1.6-2.2 us per saved launch, below); U5a depends on T +because the pair cost does; S11 is flat (one launch a layer). + +What the noise does not cover: a systematic difference that every window of one configuration shares (clock state, the +placement of the weights in memory), because there is one repeat pair only and it is the configuration with all three +switches. The controls (kernels no switch touches) agree across the five windows to 0.03-0.04 us, so no such offset is +visible. + +S9 per saved launch: head kernel time falls by 11.2 / 23.3 / 35.5 / 46.5 / 58.3 us (T 2..6) for 7 / 12 / 17 / 22 / 27 saved +launches, about 1.6-2.2 us each (these include the work of the removed norm / gemv / silu / gemv / pre-final kernels +against the multi-token kernels, not only the launch). + +## 5. What to enable + +* S11 `COMBINE_VEC4`: bitwise (identity P2 PASS, 2057/2057 rows, draft trace 1036/1036, A/A identical) and its section delta + is -0.0144 .. -0.0174 ms per graph (-0.35 us on each of 48 launches) with a noise of <= 0.0004. By the rule of this + step it is enabled by default in the 5090 profiles. The gain is about 0.15 % of a T=3 graph (11 ms, p50 of the windows; + graph totals are session dependent, section 6), well under the ledger's first estimate (0.05-0.10 ms; the ledger's own + expectation of 0.01-0.02 was right). +* S9 `HEAD_MIX_MULTI`: not bitwise (25 of 2057 rows, d_top1 max 0.0015, argmax flips 0), so OFF regardless of the delta, + which is real but small: -0.012 to -0.060 ms per graph for T 2..6 (weighted -0.023), well below the ledger's estimate of + 0.06-0.10. It would need its own quality gate; the data above is its section delta for that decision. +* U5a `GR_DOWN_FUSED`: bitwise (identity PASS per the orchestrator; the ledger row still lists P4/P5 as queued) but the fused + kernel is slower in the graph than the two kernels it replaces at T 1-6 (+0.03 .. +0.24 ms per graph, +0.145 weighted), so do not enable. The earlier microbench + (`verify-hc-down-kernel-microbench-vs-upstream`: ours slower than upstream's by 3.1-5.9 us per layer half, cold weights) + suggested a gain from overlapping the weights' DRAM fetch with staging; in the graph the fused kernel (191 registers, + 81,920 B shared) takes 15.3-16.7 us against 13.1-16.8 us for the pair. The reason is not measured here (candidates: the + shared-memory staging in front of the dots is serial inside one block, occupancy at 191 registers); a per-instruction + look at the kernel would settle it. The remaining gap of ours to upstream's `gr_down_v3` is therefore still open (K8-K10). + +Not decided by these windows: how the three behave together in the e2e A/B (the group A/B), and any effect through the +side streams (the fused kernel's 81,920 B shared block could interact with concurrent side-stream kernels; its duration +here already includes that). + +## 6. Verify graph duration (sanity total only) + +Graph span p50 per window and T is in the appendix (section 5). It cannot resolve any of the increments: the repeat pair +CZ and CD (same configuration) differs by -214 / -385 / -717 / -157 / -1383 / -729 us at T 1..6 (CZ-CD), i.e. 0.16-1.4 ms, +as large as or far larger than every section delta (S11 0.014-0.017, S9 up to 0.06, U5a 0.03-0.24 ms). The windows are separate sessions with different expert-tier state (the +FFN phase differs between sessions, as in C2v), and T mixes inside a T are not controlled. The graph totals do not track +the switches (for example CH is above CS at T 1-3). Only the section deltas above are comparable across windows. + +## Reproduce + +``` +R=/data/leleka-e2e/spd-gap/runs/verify-s11-s9-u5a-cupti-windows +for v in CP CS CH CD CZ; do + ssh rnr5090 "nice python3 -B - extract $R/$v.1/win-r29.lct $v --engine-log $R/$v.1/engine.log" \ + < scripts/e2e/codex/speed/window_increment_report.py > $v.json +done +python3 scripts/e2e/codex/speed/window_increment_report.py report CP.json CS.json CH.json CD.json CZ.json +``` + +The script is read-only on the server (the script goes in on stdin; `lct.py` may write its demangled-name cache next to the +trace as it does for every reader). The extracted JSON summaries (25 KB each) are not committed. + +Method limits: kernel durations and spans are CUPTI timestamps; a section's span is its first kernel's start to its last +kernel's end. The combine, head and pair are on the main stream (serial), so their duration deltas are critical-path time +within the graph unless a wait absorbs them (the combine waits for the join; a saving before a wait could be absorbed by +that wait's slack, as in the ffn-phase design note). The pair and read spans were measured in the layers only; the head's own +read is counted under S9 (the head section) and in the GR role total. + +## Appendix: full output of `window_increment_report.py report` + +Windows: CP = /data/leleka-e2e/spd-gap/runs/verify-s11-s9-u5a-cupti-windows/CP.1/win-r29.lct, CS = /data/leleka-e2e/spd-gap/runs/verify-s11-s9-u5a-cupti-windows/CS.1/win-r29.lct, CH = /data/leleka-e2e/spd-gap/runs/verify-s11-s9-u5a-cupti-windows/CH.1/win-r29.lct, CD = /data/leleka-e2e/spd-gap/runs/verify-s11-s9-u5a-cupti-windows/CD.1/win-r29.lct, CZ = /data/leleka-e2e/spd-gap/runs/verify-s11-s9-u5a-cupti-windows/CZ.1/win-r29.lct +T values with at least 15 graphs in every window: [1, 2, 3, 4, 5, 6] + +### 1. Switches each window ran + +Launches per verify graph of the switch kernels (all graphs of the window), and the switch line of the engine log (`requested Sm120Switches`). + +| kernel | CP | CS | CH | CD | CZ | +| --- | ---: | ---: | ---: | ---: | ---: | +| `mtp_full_combine` | 48.00 | 0.00 | 0.00 | 0.00 | 0.00 | +| `leleka_verify_combine_k10_vec4` | 0.00 | 48.00 | 48.00 | 48.00 | 48.00 | +| `mtp_full_gr_norm` | 3.13 | 3.00 | 0.00 | 0.00 | 0.00 | +| `mtp_full_down_silu` | 3.13 | 3.00 | 0.00 | 0.00 | 0.00 | +| `mtp_full_pre_final` | 3.13 | 3.00 | 0.00 | 0.00 | 0.00 | +| `mtp_full_native_write` | 6.27 | 6.01 | 6.74 | 7.25 | 5.94 | +| `chain_gr_split` | 96.00 | 96.00 | 97.00 | 1.00 | 1.00 | +| `chain_gr_down_t2w8_nb4` | 96.00 | 96.00 | 97.00 | 1.00 | 1.00 | +| `leleka_gr_down_fused_t2w8` | 0.00 | 0.00 | 0.00 | 96.00 | 96.00 | +| `chain_gr_up8` | 96.00 | 96.00 | 97.00 | 97.00 | 97.00 | +| engine log: combine_vec4 / head_mix_multi / gr_down_fused | false/false/false | true/false/false | true/true/false | true/true/true | true/true/true | +| **ran** (from the kernels) | none | S11 | S11+S9 | S11+S9+U5a | S11+S9+U5a | + +### 2. Per-launch p50 duration (us) and launches per graph, by window rows T + +Cell: p50 per-launch duration (launches per graph). `pair_dur` = split + down kernel time (U5a: the fused kernel), `pair_span` = split start to down end, `read_span` = split/fused start to `chain_gr_up8` end, all per layer half. + +T=1 (graphs 38 / 44 / 55 / 29 / 50) + +| kernel | CP | CS | CH | CD | CZ | +| --- | ---: | ---: | ---: | ---: | ---: | +| combine | 1.47 (48.0) | 1.09 (48.0) | 1.09 (48.0) | 1.12 (48.0) | 1.09 (48.0) | +| split | 3.07 (96.0) | 3.07 (96.0) | 3.07 (96.0) | - | - | +| down | 8.03 (96.0) | 8.06 (96.0) | 8.03 (96.0) | - | - | +| fused | - | - | - | 12.64 (96.0) | 12.64 (96.0) | +| up | 6.43 (96.0) | 6.43 (96.0) | 6.43 (96.0) | 6.37 (96.0) | 6.37 (96.0) | +| pair_dur | 11.17 (96.0) | 11.20 (96.0) | 11.17 (96.0) | 12.64 (96.0) | 12.64 (96.0) | +| pair_span | 11.30 (96.0) | 11.30 (96.0) | 11.26 (96.0) | 12.64 (96.0) | 12.64 (96.0) | +| read_span | 17.92 (96.0) | 17.92 (96.0) | 17.92 (96.0) | 19.26 (96.0) | 19.26 (96.0) | +| head launches per graph (mean) | 5.00 | 5.00 | 3.00 | 3.00 | 3.00 | +| head kernel time, us per graph (p50) | 17.25 | 17.15 | 16.77 | 16.93 | 16.80 | +| head span, us per graph (p50) | 17.82 | 17.70 | 17.25 | 17.44 | 17.31 | +| GR kernels per graph (mean) | 288.00 | 288.00 | 291.00 | 195.00 | 195.00 | +| GR kernel time, us per graph (p50) | 1690.23 | 1691.43 | 1706.37 | 1847.15 | 1848.84 | + +T=2 (graphs 271 / 295 / 149 / 224 / 278) + +| kernel | CP | CS | CH | CD | CZ | +| --- | ---: | ---: | ---: | ---: | ---: | +| combine | 1.50 (48.0) | 1.15 (48.0) | 1.15 (48.0) | 1.15 (48.0) | 1.15 (48.0) | +| split | 3.14 (96.0) | 3.14 (96.0) | 3.14 (96.0) | - | - | +| down | 9.89 (96.0) | 9.89 (96.0) | 9.89 (96.0) | - | - | +| fused | - | - | - | 15.52 (96.0) | 15.49 (96.0) | +| up | 7.36 (96.0) | 7.36 (96.0) | 7.36 (96.0) | 7.39 (96.0) | 7.39 (96.0) | +| pair_dur | 13.06 (96.0) | 13.06 (96.0) | 13.06 (96.0) | 15.52 (96.0) | 15.49 (96.0) | +| pair_span | 13.15 (96.0) | 13.15 (96.0) | 13.15 (96.0) | 15.52 (96.0) | 15.49 (96.0) | +| read_span | 20.70 (96.0) | 20.74 (96.0) | 20.74 (96.0) | 23.14 (96.0) | 23.10 (96.0) | +| head launches per graph (mean) | 10.00 | 10.00 | 3.00 | 3.00 | 3.00 | +| head kernel time, us per graph (p50) | 30.75 | 30.88 | 19.65 | 19.62 | 19.62 | +| head span, us per graph (p50) | 31.81 | 31.94 | 20.16 | 20.13 | 20.10 | +| GR kernels per graph (mean) | 288.00 | 288.00 | 291.00 | 195.00 | 195.00 | +| GR kernel time, us per graph (p50) | 1961.51 | 1962.07 | 1981.00 | 2220.94 | 2217.74 | + +T=3 (graphs 286 / 269 / 297 / 150 / 372) + +| kernel | CP | CS | CH | CD | CZ | +| --- | ---: | ---: | ---: | ---: | ---: | +| combine | 1.50 (48.0) | 1.15 (48.0) | 1.15 (48.0) | 1.15 (48.0) | 1.15 (48.0) | +| split | 3.04 (96.0) | 3.04 (96.0) | 3.04 (96.0) | - | - | +| down | 10.53 (96.0) | 10.53 (96.0) | 10.53 (96.0) | - | - | +| fused | - | - | - | 15.29 (96.0) | 15.26 (96.0) | +| up | 8.00 (96.0) | 8.00 (96.0) | 8.00 (96.0) | 8.03 (96.0) | 8.03 (96.0) | +| pair_dur | 13.60 (96.0) | 13.60 (96.0) | 13.60 (96.0) | 15.29 (96.0) | 15.26 (96.0) | +| pair_span | 13.70 (96.0) | 13.70 (96.0) | 13.70 (96.0) | 15.29 (96.0) | 15.26 (96.0) | +| read_span | 21.95 (96.0) | 21.92 (96.0) | 21.92 (96.0) | 23.55 (96.0) | 23.52 (96.0) | +| head launches per graph (mean) | 15.00 | 15.00 | 3.00 | 3.00 | 3.00 | +| head kernel time, us per graph (p50) | 44.32 | 44.19 | 20.86 | 20.87 | 20.83 | +| head span, us per graph (p50) | 45.86 | 45.73 | 21.38 | 21.38 | 21.34 | +| GR kernels per graph (mean) | 288.00 | 288.00 | 291.00 | 195.00 | 195.00 | +| GR kernel time, us per graph (p50) | 2076.20 | 2075.18 | 2096.91 | 2258.83 | 2255.82 | + +T=4 (graphs 114 / 181 / 100 / 167 / 132) + +| kernel | CP | CS | CH | CD | CZ | +| --- | ---: | ---: | ---: | ---: | ---: | +| combine | 1.50 (48.0) | 1.15 (48.0) | 1.15 (48.0) | 1.15 (48.0) | 1.18 (48.0) | +| split | 3.07 (96.0) | 3.07 (96.0) | 3.07 (96.0) | - | - | +| down | 11.14 (96.0) | 11.14 (96.0) | 11.17 (96.0) | - | - | +| fused | - | - | - | 15.68 (96.0) | 15.65 (96.0) | +| up | 8.80 (96.0) | 8.80 (96.0) | 8.80 (96.0) | 8.83 (96.0) | 8.83 (96.0) | +| pair_dur | 14.24 (96.0) | 14.24 (96.0) | 14.24 (96.0) | 15.68 (96.0) | 15.65 (96.0) | +| pair_span | 14.34 (96.0) | 14.34 (96.0) | 14.34 (96.0) | 15.68 (96.0) | 15.65 (96.0) | +| read_span | 23.36 (96.0) | 23.36 (96.0) | 23.39 (96.0) | 24.70 (96.0) | 24.67 (96.0) | +| head launches per graph (mean) | 20.00 | 20.00 | 3.00 | 3.00 | 3.00 | +| head kernel time, us per graph (p50) | 57.60 | 57.54 | 22.14 | 22.14 | 22.05 | +| head span, us per graph (p50) | 59.65 | 59.55 | 22.72 | 22.72 | 22.66 | +| GR kernels per graph (mean) | 288.00 | 288.00 | 291.00 | 195.00 | 195.00 | +| GR kernel time, us per graph (p50) | 2213.10 | 2213.97 | 2238.99 | 2387.47 | 2385.33 | + +T=5 (graphs 88 / 41 / 137 / 94 / 57) + +| kernel | CP | CS | CH | CD | CZ | +| --- | ---: | ---: | ---: | ---: | ---: | +| combine | 1.54 (48.0) | 1.22 (48.0) | 1.22 (48.0) | 1.22 (48.0) | 1.22 (48.0) | +| split | 3.10 (96.0) | 3.10 (96.0) | 3.10 (96.0) | - | - | +| down | 12.70 (96.0) | 12.70 (96.0) | 12.70 (96.0) | - | - | +| fused | - | - | - | 16.13 (96.0) | 16.10 (96.0) | +| up | 9.82 (96.0) | 9.86 (96.0) | 9.82 (96.0) | 9.86 (96.0) | 9.82 (96.0) | +| pair_dur | 15.84 (96.0) | 15.84 (96.0) | 15.81 (96.0) | 16.13 (96.0) | 16.10 (96.0) | +| pair_span | 15.94 (96.0) | 15.94 (96.0) | 15.94 (96.0) | 16.13 (96.0) | 16.10 (96.0) | +| read_span | 25.98 (96.0) | 25.98 (96.0) | 25.98 (96.0) | 26.18 (96.0) | 26.14 (96.0) | +| head launches per graph (mean) | 25.00 | 25.00 | 3.00 | 3.00 | 3.00 | +| head kernel time, us per graph (p50) | 71.26 | 71.20 | 24.80 | 24.80 | 24.77 | +| head span, us per graph (p50) | 73.76 | 73.70 | 25.47 | 25.47 | 25.44 | +| GR kernels per graph (mean) | 288.00 | 288.00 | 291.00 | 195.00 | 195.00 | +| GR kernel time, us per graph (p50) | 2466.25 | 2464.31 | 2489.36 | 2523.24 | 2520.98 | + +T=6 (graphs 27 / 17 / 27 / 38 / 21) + +| kernel | CP | CS | CH | CD | CZ | +| --- | ---: | ---: | ---: | ---: | ---: | +| combine | 1.54 (48.0) | 1.25 (48.0) | 1.25 (48.0) | 1.28 (48.0) | 1.28 (48.0) | +| split | 3.10 (96.0) | 3.10 (96.0) | 3.10 (96.0) | - | - | +| down | 13.66 (96.0) | 13.70 (96.0) | 13.66 (96.0) | - | - | +| fused | - | - | - | 16.74 (96.0) | 16.70 (96.0) | +| up | 10.75 (96.0) | 10.75 (96.0) | 10.75 (96.0) | 10.72 (96.0) | 10.72 (96.0) | +| pair_dur | 16.80 (96.0) | 16.80 (96.0) | 16.83 (96.0) | 16.74 (96.0) | 16.70 (96.0) | +| pair_span | 16.90 (96.0) | 16.90 (96.0) | 16.93 (96.0) | 16.74 (96.0) | 16.70 (96.0) | +| read_span | 27.84 (96.0) | 27.87 (96.0) | 27.87 (96.0) | 27.68 (96.0) | 27.68 (96.0) | +| head launches per graph (mean) | 30.00 | 30.00 | 3.00 | 3.00 | 3.00 | +| head kernel time, us per graph (p50) | 84.83 | 84.74 | 26.46 | 26.43 | 26.37 | +| head span, us per graph (p50) | 87.84 | 87.71 | 27.17 | 27.10 | 27.07 | +| GR kernels per graph (mean) | 288.00 | 288.00 | 291.00 | 195.00 | 195.00 | +| GR kernel time, us per graph (p50) | 2649.94 | 2649.74 | 2675.83 | 2702.99 | 2702.51 | + +### 3. Increments and noise + +Delta = later window minus earlier. Cell: p50 / mean of the per-graph value in ms per graph (negative = the later window is faster), then the verdict against the repeat pair (CZ minus CD, the same configuration). Noise rows give that repeat's own p50 / mean delta. + +**S11 combine vec4 (CS - CP)** + +| section | T=1 | T=2 | T=3 | T=4 | T=5 | T=6 | +| --- | ---: | ---: | ---: | ---: | ---: | ---: | +| combine kernel time per graph | -0.0174 / -0.0173 (resolved) | -0.0166 / -0.0166 (resolved) | -0.0167 / -0.0167 (resolved) | -0.0165 / -0.0166 (resolved) | -0.0150 / -0.0152 (resolved) | -0.0144 / -0.0145 (resolved) | +| noise: combine kernel time per graph | -0.0001 / -0.0001 | -0.0001 / -0.0002 | +0.0001 / +0.0001 | +0.0001 / +0.0001 | +0.0003 / +0.0004 | +0.0004 / +0.0003 | + +Per launch (us, p50 / mean; the combine is one launch per layer, the pair one per layer half): + +| per launch | T=1 | T=2 | T=3 | T=4 | T=5 | T=6 | +| --- | ---: | ---: | ---: | ---: | ---: | ---: | +| combine launch | -0.38 / -0.36 | -0.35 / -0.35 | -0.35 / -0.35 | -0.35 / -0.34 | -0.32 / -0.32 | -0.29 / -0.30 | +| noise: combine launch | -0.03 / -0.00 | +0.00 / -0.00 | +0.00 / +0.00 | +0.03 / +0.00 | +0.00 / +0.01 | +0.00 / +0.01 | + +**S9 head mix multi (CH - CS)** + +| section | T=1 | T=2 | T=3 | T=4 | T=5 | T=6 | +| --- | ---: | ---: | ---: | ---: | ---: | ---: | +| head kernel time per graph | -0.0004 / -0.0004 (resolved) | -0.0112 / -0.0112 (resolved) | -0.0233 / -0.0233 (resolved) | -0.0354 / -0.0355 (resolved) | -0.0464 / -0.0465 (resolved) | -0.0583 / -0.0582 (resolved) | +| noise: head kernel time per graph | -0.0001 / -0.0000 | +0.0000 / -0.0000 | -0.0000 / -0.0001 | -0.0001 / -0.0000 | -0.0000 / -0.0000 | -0.0001 / +0.0000 | +| head span per graph | -0.0004 / -0.0005 (resolved) | -0.0118 / -0.0118 (resolved) | -0.0244 / -0.0243 (resolved) | -0.0368 / -0.0369 (resolved) | -0.0482 / -0.0483 (resolved) | -0.0605 / -0.0605 (resolved) | +| noise: head span per graph | -0.0001 / -0.0000 | -0.0000 / -0.0000 | -0.0000 / -0.0001 | -0.0001 / -0.0000 | -0.0000 / -0.0000 | -0.0000 / +0.0000 | + +**U5a fused HC down (CD - CH)** + +| section | T=1 | T=2 | T=3 | T=4 | T=5 | T=6 | +| --- | ---: | ---: | ---: | ---: | ---: | ---: | +| pair kernel time per graph (layers) | +0.1438 / +0.1438 (resolved) | +0.2379 / +0.2380 (resolved) | +0.1598 / +0.1604 (resolved) | +0.1460 / +0.1471 (resolved) | +0.0325 / +0.0327 (resolved) | +0.0256 / +0.0299 (resolved) | +| noise: pair kernel time per graph (layers) | +0.0005 / +0.0006 | -0.0026 / -0.0029 | -0.0023 / -0.0026 | -0.0012 / -0.0021 | -0.0023 / -0.0023 | +0.0005 / -0.0046 | +| pair span per graph (layers) | +0.1344 / +0.1344 (resolved) | +0.2285 / +0.2285 (resolved) | +0.1504 / +0.1509 (resolved) | +0.1365 / +0.1376 (resolved) | +0.0229 / +0.0233 (resolved) | +0.0161 / +0.0205 (resolved) | +| noise: pair span per graph (layers) | +0.0005 / +0.0006 | -0.0026 / -0.0029 | -0.0023 / -0.0026 | -0.0012 / -0.0021 | -0.0023 / -0.0023 | +0.0005 / -0.0046 | +| read span per graph (layers) | +0.1318 / +0.1318 (resolved) | +0.2298 / +0.2300 (resolved) | +0.1523 / +0.1532 (resolved) | +0.1391 / +0.1387 (resolved) | +0.0244 / +0.0252 (resolved) | +0.0169 / +0.0185 (resolved) | +| noise: read span per graph (layers) | +0.0017 / +0.0010 | -0.0032 / -0.0029 | -0.0029 / -0.0033 | -0.0019 / -0.0021 | -0.0028 / -0.0037 | -0.0003 / -0.0044 | +| GR role kernel time per graph | +0.1408 / +0.1410 (resolved) | +0.2399 / +0.2399 (resolved) | +0.1619 / +0.1629 (resolved) | +0.1485 / +0.1485 (resolved) | +0.0339 / +0.0349 (resolved) | +0.0272 / +0.0283 (resolved) | +| noise: GR role kernel time per graph | +0.0017 / +0.0010 | -0.0032 / -0.0029 | -0.0030 / -0.0035 | -0.0021 / -0.0021 | -0.0023 / -0.0038 | -0.0005 / -0.0042 | + +Per launch (us, p50 / mean; the combine is one launch per layer, the pair one per layer half): + +| per launch | T=1 | T=2 | T=3 | T=4 | T=5 | T=6 | +| --- | ---: | ---: | ---: | ---: | ---: | ---: | +| pair kernel time per layer half | +1.47 / +1.50 | +2.46 / +2.48 | +1.69 / +1.67 | +1.44 / +1.53 | +0.32 / +0.34 | -0.10 / +0.31 | +| noise: pair kernel time per layer half | +0.00 / +0.01 | -0.03 / -0.03 | -0.03 / -0.03 | -0.03 / -0.02 | -0.03 / -0.02 | -0.03 / -0.05 | +| pair span per layer half | +1.38 / +1.40 | +2.37 / +2.38 | +1.60 / +1.57 | +1.34 / +1.43 | +0.19 / +0.24 | -0.19 / +0.21 | +| noise: pair span per layer half | +0.00 / +0.01 | -0.03 / -0.03 | -0.03 / -0.03 | -0.03 / -0.02 | -0.03 / -0.02 | -0.03 / -0.05 | +| read span per layer half | +1.34 / +1.37 | +2.40 / +2.40 | +1.63 / +1.60 | +1.31 / +1.44 | +0.19 / +0.26 | -0.19 / +0.19 | +| noise: read span per layer half | +0.00 / +0.01 | -0.03 / -0.03 | -0.03 / -0.03 | -0.03 / -0.02 | -0.03 / -0.04 | +0.00 / -0.05 | + +### 4. Section delta weighted by the earlier window's T mix (ms per graph, p50 deltas) + +| increment | section | delta | repeat delta | spread over T (min .. max) | +| --- | --- | ---: | ---: | --- | +| S11 combine vec4 | combine kernel time per graph | -0.0164 | +0.0001 | -0.0174 .. -0.0144 | +| S9 head mix multi | head kernel time per graph | -0.0223 | -0.0000 | -0.0583 .. -0.0004 | +| S9 head mix multi | head span per graph | -0.0233 | -0.0000 | -0.0605 .. -0.0004 | +| U5a fused HC down | pair kernel time per graph (layers) | +0.1445 | -0.0019 | +0.0256 .. +0.2379 | +| U5a fused HC down | pair span per graph (layers) | +0.1351 | -0.0019 | +0.0161 .. +0.2285 | +| U5a fused HC down | read span per graph (layers) | +0.1365 | -0.0024 | +0.0169 .. +0.2298 | +| U5a fused HC down | GR role kernel time per graph | +0.1462 | -0.0024 | +0.0272 .. +0.2399 | + +### 5. Verify graph duration (first kernel start to last kernel end), p50 us (kernels per graph, p50) + +Sanity total only: each window is its own session, so the expert-tier state differs between windows (compare within one T and one window, not as a section delta). + +| T | CP | CS | CH | CD | CZ | +| --- | ---: | ---: | ---: | ---: | ---: | +| 1 | 7890.20 (1947.00) | 8027.41 (1947.00) | 8156.21 (1945.00) | 7821.84 (1849.00) | 7608.08 (1849.00) | +| 2 | 9604.35 (1964.00) | 9661.09 (1964.00) | 9975.27 (1957.00) | 9612.25 (1861.00) | 9227.32 (1861.00) | +| 3 | 11301.74 (1981.00) | 10905.99 (1981.00) | 11348.62 (1969.00) | 11265.48 (1873.00) | 10548.71 (1873.00) | +| 4 | 12680.79 (1998.00) | 13328.28 (1998.00) | 13666.17 (1981.00) | 12973.65 (1885.00) | 12816.12 (1885.00) | +| 5 | 16565.90 (2015.00) | 16159.98 (2015.00) | 16004.52 (1993.00) | 16082.47 (1897.00) | 14699.87 (1897.00) | +| 6 | 20303.08 (2032.00) | 22917.43 (2032.00) | 20295.30 (2005.00) | 18194.33 (1909.00) | 17465.17 (1909.00) | + diff --git a/scripts/e2e/codex/speed/window_increment_report.py b/scripts/e2e/codex/speed/window_increment_report.py new file mode 100644 index 00000000..b61bbcae --- /dev/null +++ b/scripts/e2e/codex/speed/window_increment_report.py @@ -0,0 +1,356 @@ +"""Section deltas between CUPTI windows that differ by one verify switch (ledger rows S11, S9, U5a, K10). + +Offline analysis of CUPTI trace directories (tools/cupti-trace, `lct.py`); host-side Python, stdlib only, no GPU. + + extract TRACE_DIR LABEL [--lct DIR] [--engine-log FILE] (python3 -B; reads the trace, writes JSON on stdout) + per window row count T (the CPU-row copy grid is T * 10 blocks) of every verify graph (>= 900 kernels per + correlation id, first and last two dropped): per-graph metrics and per-launch durations of the section kernels + (summaries n / mean / sd / p10 / p50 / p90), kernel names with launches per graph, the switch line of the + engine log. `--lct` defaults to /data/leleka-e2e/decode/tools (read only). + report CONTROL STEP1 STEP2 STEP3 REPEAT (five extract JSON files; markdown on stdout) + the switches each window ran (kernel-name evidence), per-T section tables, increments STEP1-CONTROL, + STEP2-STEP1, STEP3-STEP2 with their noise REPEAT-STEP3 (REPEAT is the same configuration as STEP3) and the verify + graph duration. + +Sections (all per graph, kernel time = sum of kernel durations, span = first start to last end, gaps included): + combine `mtp_full_combine` (S11 off) or `leleka_verify_combine_k10_vec4` (S11 on): one launch per layer + head kernels after the last `mtp_full_native_write` up to the `head_quant` of the language-model head: + 5 launches per token (S9 off) or the multi read (S9 on); span = from that write's end to that quantize + pair layer halves' hyper-connection split + down (`chain_gr_split` + `chain_gr_down*`) or the fused + `leleka_gr_down_fused*` (U5a); the head's instance is not counted here + read the same instance up to `chain_gr_up*` (the whole hyper-connection read of a layer half) + gr every hyper-connection kernel of the graph (layers and head) +A verdict of "resolved" needs the p50 and the mean delta to agree in sign, |delta of the mean| above two standard errors +of the difference, and both above the repeat window pair's own delta. +""" +import argparse +import collections +import json +import re +import statistics as st +import sys + +COMBINE_NAMES = ("mtp_full_combine", "leleka_verify_combine_k10_vec4") +SPLIT, DOWN, FUSED, UP = "chain_gr_split", "chain_gr_down", "leleka_gr_down_fused", "chain_gr_up" +SWITCH_RE = re.compile(r"combine_vec4: (\w+), head_mix_multi: (\w+), gr_down_fused: (\w+)") +KEY_NAMES = ("mtp_full_combine", "leleka_verify_combine_k10_vec4", "mtp_full_gr_norm", "mtp_full_down_silu", + "mtp_full_pre_final", "mtp_full_native_write", "chain_gr_split", "chain_gr_down_t2w8_nb4", + "leleka_gr_down_fused_t2w8", "chain_gr_up8") +MIN_GRAPHS = 15 + + +def summary(values): + v = sorted(values) + if not v: + return None + at = lambda p: v[min(len(v) - 1, int(p * len(v)))] # noqa: E731 + return {"n": len(v), "mean": st.mean(v), "sd": st.pstdev(v) if len(v) > 1 else 0.0, "p10": at(.1), "p50": at(.5), + "p90": at(.9)} + + +# ---------------------------------------------------------------- extract +def verify_graphs(trace): + by = collections.defaultdict(list) + for k in trace.kernels: + by[k.corr].append(k) + ids = sorted((c for c, v in by.items() if len(v) >= 900), key=lambda c: min(k.start for k in by[c])) + return [sorted(by[c], key=lambda k: k.start) for c in ids[2:-2]] + + +def window_rows(ks, name): + rows = collections.Counter(k.gx // 10 for k in ks if "copy_rows" in name(k)) + return rows.most_common(1)[0][0] if rows else -1 + + +def hc_instances(ks, name, last_combine_start): + """(first, down, up, is_head) per hyper-connection read: split or fused kernel, the down kernel after a split, the + up kernel; the instances after the last combine are the head's.""" + streams = collections.defaultdict(list) + for k in ks: + streams[k.stream].append(k) + out = [] + for seq in streams.values(): + for i, k in enumerate(seq): + n = name(k) + if n != SPLIT and not n.startswith(FUSED): + continue + nxt = seq[i + 1:i + 4] + down = nxt[0] if n == SPLIT and nxt and name(nxt[0]).startswith(DOWN) else None + up = next((x for x in nxt if name(x).startswith(UP)), None) + if up is not None: + out.append((k, down, up, k.start > last_combine_start)) + return out + + +def graph_record(ks, name): + """One graph: its metrics (us) and the per-launch lists of the section kernels.""" + us = lambda x: x / 1e3 # noqa: E731 + dur = lambda k: us(k.end - k.start) # noqa: E731 + combines = [k for k in ks if name(k) in COMBINE_NAMES] + writes = [k for k in ks if name(k) == "mtp_full_native_write"] + quant = [k for k in ks if name(k) == "head_quant"] + if not combines or not writes or not quant: + return None + last_write, last_quant = writes[-1], quant[-1] + head = [k for k in ks if last_write.end <= k.start < last_quant.start] + inst = hc_instances(ks, name, combines[-1].start) + layer = [i for i in inst if not i[3]] + gr_all = [k for i in inst for k in (i[0], i[1], i[2]) if k is not None] + pair_dur = [dur(a) + (dur(d) if d else 0.0) for a, d, u, _ in layer] + pair_span = [us((d or a).end - a.start) for a, d, u, _ in layer] + read_span = [us(u.end - a.start) for a, d, u, _ in layer] + return { + "metrics": { + "kernels": len(ks), "graph_span": us(max(k.end for k in ks) - ks[0].start), + "kernel_sum": sum(dur(k) for k in ks), + "combine_n": len(combines), "combine_sum": sum(dur(k) for k in combines), + "head_n": len(head), "head_sum": sum(dur(k) for k in head), + "head_span": us(last_quant.start - last_write.end), + "pair_n": len(layer), "pair_sum": sum(pair_dur), "pair_span_sum": sum(pair_span), + "read_span_sum": sum(read_span), "gr_n": len(gr_all), "gr_sum": sum(dur(k) for k in gr_all), + }, + "launch": { + "combine": [dur(k) for k in combines], + "split": [dur(a) for a, d, u, h in layer if d], "down": [dur(d) for a, d, u, h in layer if d], + "fused": [dur(a) for a, d, u, h in layer if not d], "up": [dur(u) for a, d, u, h in layer], + "pair_dur": pair_dur, "pair_span": pair_span, "read_span": read_span, + }, + } + + +def switch_line(engine_log): + if not engine_log: + return None + for line in open(engine_log, errors="replace"): + m = SWITCH_RE.search(line) + if m and "sm120 switches" in line: + return {"combine_vec4": m.group(1), "head_mix_multi": m.group(2), "gr_down_fused": m.group(3)} + return None + + +def extract(path, label, lct_dir, engine_log): + sys.path.insert(0, lct_dir) + sys.dont_write_bytecode = True + import lct + trace = lct.Trace(path) + name = lambda k: trace.names.get(k.name, "?") # noqa: E731 + graphs = verify_graphs(trace) + by_t = collections.defaultdict(list) + names = collections.defaultdict(lambda: [0, 0.0]) + for ks in graphs: + for k in ks: + e = names[name(k)] + e[0] += 1 + e[1] += (k.end - k.start) / 1e3 + rec = graph_record(ks, name) + if rec: + by_t[window_rows(ks, name)].append(rec) + out = {"label": label, "trace": path, "graphs": len(graphs), "switch_line": switch_line(engine_log), "byT": {}, + "names": {n: {"per_graph": c / len(graphs), "mean_us": us / c} for n, (c, us) in names.items()}} + for t, recs in sorted(by_t.items()): + out["byT"][str(t)] = { + "graphs": len(recs), + "graph": {m: summary([r["metrics"][m] for r in recs]) for m in recs[0]["metrics"]}, + "launch": {k: summary([x for r in recs for x in r["launch"][k]]) for k in recs[0]["launch"]}, + } + json.dump(out, sys.stdout, separators=(",", ":")) + + +# ---------------------------------------------------------------- report +def per_launch(window, kind, t): + return window["byT"].get(str(t), {}).get("launch", {}).get(kind) + + +def get(window, t, metric): + return window["byT"].get(str(t), {}).get("graph", {}).get(metric) + + +def usable_ts(windows): + sets = [{int(t) for t, v in w["byT"].items() if v["graphs"] >= MIN_GRAPHS and int(t) > 0} for w in windows] + return sorted(set.intersection(*sets)) + + +def inferred(w): + n = lambda k: w["names"].get(k, {"per_graph": 0})["per_graph"] # noqa: E731 + on = [] + if n("leleka_verify_combine_k10_vec4") > 0 and n("mtp_full_combine") == 0: + on.append("S11") + if n("mtp_full_gr_norm") == 0: + on.append("S9") + if n("leleka_gr_down_fused_t2w8") > 0 and n("chain_gr_split") <= 1: # the head's own read keeps split + down + on.append("U5a") + return "+".join(on) or "none" + + +def evidence(windows): + print("### 1. Switches each window ran\n") + print("Launches per verify graph of the switch kernels (all graphs of the window), and the switch line of the " + "engine log (`requested Sm120Switches`).\n") + print("| kernel | " + " | ".join(w["label"] for w in windows) + " |") + print("| --- |" + " ---: |" * len(windows)) + for n in KEY_NAMES: + cells = ["%.2f" % w["names"].get(n, {"per_graph": 0})["per_graph"] for w in windows] + print("| `%s` | " % n + " | ".join(cells) + " |") + log = ["/".join(w["switch_line"][k] for k in ("combine_vec4", "head_mix_multi", "gr_down_fused")) + if w["switch_line"] else "n/a" for w in windows] + print("| engine log: combine_vec4 / head_mix_multi / gr_down_fused | " + " | ".join(log) + " |") + print("| **ran** (from the kernels) | " + " | ".join(inferred(w) for w in windows) + " |\n") + + +def fmt(s, key="p50"): + return "%.2f" % s[key] if s else "-" + + +LAUNCH_KINDS = ("combine", "split", "down", "fused", "up", "pair_dur", "pair_span", "read_span") + + +def launch_tables(windows, ts): + print("### 2. Per-launch p50 duration (us) and launches per graph, by window rows T\n") + print("Cell: p50 per-launch duration (launches per graph). `pair_dur` = split + down kernel time (U5a: the fused " + "kernel), `pair_span` = split start to down end, `read_span` = split/fused start to `chain_gr_up8` end, " + "all per layer half.\n") + for t in ts: + print("T=%d (graphs %s)\n" % (t, " / ".join(str(w["byT"][str(t)]["graphs"]) for w in windows))) + print("| kernel | " + " | ".join(w["label"] for w in windows) + " |") + print("| --- |" + " ---: |" * len(windows)) + for kind in LAUNCH_KINDS: + cells = [] + for w in windows: + s = per_launch(w, kind, t) + cells.append("%s (%.1f)" % (fmt(s), s["n"] / w["byT"][str(t)]["graphs"]) if s else "-") + print("| %s | " % kind + " | ".join(cells) + " |") + rows = (("head launches per graph (mean)", "head_n", "mean"), + ("head kernel time, us per graph (p50)", "head_sum", "p50"), + ("head span, us per graph (p50)", "head_span", "p50"), + ("GR kernels per graph (mean)", "gr_n", "mean"), + ("GR kernel time, us per graph (p50)", "gr_sum", "p50")) + for label, metric, key in rows: + print("| %s | " % label + " | ".join(fmt(get(w, t, metric), key) for w in windows) + " |") + print() + + +def diff(a, b): + """b minus a for one metric at one T: (delta p50, delta mean, standard error of the delta of the means).""" + if not a or not b: + return None + se = (a["sd"] ** 2 / a["n"] + b["sd"] ** 2 / b["n"]) ** .5 + return b["p50"] - a["p50"], b["mean"] - a["mean"], se + + +def verdict(d, noise): + if not d or not noise: + return "n/a" + p50, mean, se = d + if (p50 > 0) == (mean > 0) and abs(mean) > 2 * se and min(abs(p50), abs(mean)) > max(abs(noise[0]), abs(noise[1])): + return "resolved" + return "below noise" + + +INCREMENTS = (("S11 combine vec4 (CS - CP)", 0), ("S9 head mix multi (CH - CS)", 1), ("U5a fused HC down (CD - CH)", 2)) +SECTIONS = { + 0: (("combine kernel time per graph", "combine_sum"),), + 1: (("head kernel time per graph", "head_sum"), ("head span per graph", "head_span")), + 2: (("pair kernel time per graph (layers)", "pair_sum"), ("pair span per graph (layers)", "pair_span_sum"), + ("read span per graph (layers)", "read_span_sum"), ("GR role kernel time per graph", "gr_sum")), +} +LAUNCH_ROWS = {0: (("combine launch", "combine"),), 1: (), + 2: (("pair kernel time per layer half", "pair_dur"), ("pair span per layer half", "pair_span"), + ("read span per layer half", "read_span"))} + + +def increments(w, ts): + print("### 3. Increments and noise\n") + print("Delta = later window minus earlier. Cell: p50 / mean of the per-graph value in ms per graph (negative = the " + "later window is faster), then the verdict against the repeat pair (CZ minus CD, the same configuration). " + "Noise rows give that repeat's own p50 / mean delta.\n") + for title, i in INCREMENTS: + a, b = w[i], w[i + 1] + print("**%s**\n" % title) + print("| section | " + " | ".join("T=%d" % t for t in ts) + " |\n| --- |" + " ---: |" * len(ts)) + for label, metric in SECTIONS[i]: + ds = [diff(get(a, t, metric), get(b, t, metric)) for t in ts] + ns = [diff(get(w[3], t, metric), get(w[4], t, metric)) for t in ts] + print("| %s | " % label + " | ".join( + "%+.4f / %+.4f (%s)" % (d[0] / 1e3, d[1] / 1e3, verdict(d, n)) if d else "-" + for d, n in zip(ds, ns)) + " |") + print("| noise: %s | " % label + " | ".join( + "%+.4f / %+.4f" % (n[0] / 1e3, n[1] / 1e3) if n else "-" for n in ns) + " |") + print() + launch_increment(w, i, ts) + mix_summary(w, ts) + + +def launch_increment(w, i, ts): + if not LAUNCH_ROWS[i]: + return + a, b = w[i], w[i + 1] + print("Per launch (us, p50 / mean; the combine is one launch per layer, the pair one per layer half):\n") + print("| per launch | " + " | ".join("T=%d" % t for t in ts) + " |\n| --- |" + " ---: |" * len(ts)) + for label, kind in LAUNCH_ROWS[i]: + ds = [diff(per_launch(a, kind, t), per_launch(b, kind, t)) for t in ts] + ns = [diff(per_launch(w[3], kind, t), per_launch(w[4], kind, t)) for t in ts] + print("| %s | " % label + " | ".join("%+.2f / %+.2f" % d[:2] if d else "-" for d in ds) + " |") + print("| noise: %s | " % label + " | ".join("%+.2f / %+.2f" % n[:2] if n else "-" for n in ns) + " |") + print() + + +def mix_summary(w, ts): + print("### 4. Section delta weighted by the earlier window's T mix (ms per graph, p50 deltas)\n") + print("| increment | section | delta | repeat delta | spread over T (min .. max) |") + print("| --- | --- | ---: | ---: | --- |") + for title, i in INCREMENTS: + a, b = w[i], w[i + 1] + weights = {t: a["byT"][str(t)]["graphs"] for t in ts} + total = sum(weights.values()) + for label, metric in SECTIONS[i]: + ds = {t: diff(get(a, t, metric), get(b, t, metric)) for t in ts} + ns = {t: diff(get(w[3], t, metric), get(w[4], t, metric)) for t in ts} + mixed = sum(weights[t] * ds[t][0] for t in ts) / total / 1e3 + repeat = sum(weights[t] * ns[t][0] for t in ts) / total / 1e3 + lo, hi = min(d[0] for d in ds.values()) / 1e3, max(d[0] for d in ds.values()) / 1e3 + print("| %s | %s | %+.4f | %+.4f | %+.4f .. %+.4f |" % (title.split(" (")[0], label, mixed, repeat, lo, hi)) + print() + + +def graph_totals(windows, ts): + print("### 5. Verify graph duration (first kernel start to last kernel end), p50 us (kernels per graph, p50)\n") + print("Sanity total only: each window is its own session, so the expert-tier state differs between windows " + "(compare within one T and one window, not as a section delta).\n") + print("| T | " + " | ".join(w["label"] for w in windows) + " |") + print("| --- |" + " ---: |" * len(windows)) + for t in ts: + cells = ["%s (%s)" % (fmt(get(w, t, "graph_span")), fmt(get(w, t, "kernels"))) for w in windows] + print("| %d | " % t + " | ".join(cells) + " |") + print() + + +def report(paths): + w = [json.load(open(p)) for p in paths] + ts = usable_ts(w) + print("Windows: " + ", ".join("%s = %s" % (x["label"], x["trace"]) for x in w)) + print("T values with at least %d graphs in every window: %s\n" % (MIN_GRAPHS, ts)) + evidence(w) + launch_tables(w, ts) + increments(w, ts) + graph_totals(w, ts) + + +def main(): + ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) + sub = ap.add_subparsers(dest="cmd", required=True) + e = sub.add_parser("extract") + e.add_argument("trace") + e.add_argument("label") + e.add_argument("--lct", default="/data/leleka-e2e/decode/tools") + e.add_argument("--engine-log") + r = sub.add_parser("report") + r.add_argument("files", nargs=5) + a = ap.parse_args() + if a.cmd == "extract": + extract(a.trace, a.label, a.lct, a.engine_log) + else: + report(a.files) + + +if __name__ == "__main__": + main()