# Hyper-connection down kernel: upstream `gr_down_v3_kernel` (masks 133 / 5) against our `chain_gr_down_t2w8_nb4`, per window rows (ledger row U5) Status: the program is written, built and frozen on the server; it has **not been run** (the GPU is a queue; the orchestrator installs and queues the stub). Nothing in this note is measured. Base: `6b2a69f1d` (branch `claude/speed-vs-strata-08143a`, contains `05e9acdaa`), upstream `strata-upstream/main` = `504b143342a9fe1aa8320a7b31e11f5c0ac265c3`. Ledger rows: `step-ledger.md` K8 (`chain_gr_down_t2w8_nb4` 11.1 us against `gr_down_staged` 11.5 us), U4 (batched staging/read loads, `STRATA_GR_V3_PF` bits 0 and 2), U5 (bit 7, two rows a warp for windows of 5+ rows, mask 133, upstream commits `4ab81c796`, `5f24b96db`, `08b20b104`). **Correction (claude/u5a-gr-down-fused, 2026-11-10): the byte compare of the first run is invalid, and not because of the input values.** The generated inputs are finite (normal distributions, bf16 weights; the harness now counts non-finite input values and prints `inputs: 0 non-finite values`). The NaN words in the `DIFF` lines are the 0xff poison that `reset_work` and `new_work` write with `cudaMemset`/`cudaMemcpy` on the legacy default stream while the kernels run on `s`, a non-blocking stream: the runtime does not order the two, so a poison memset could land after (or beside) the kernel that was meant to overwrite it. `reset_work` and `new_work` now end with `cudaDeviceSynchronize()`. The timing loops are unlikely to be affected (their memsets, at creation, finish long before the two seconds of warm-up are over), but the harness has to be re-run to get a valid correctness section. ## 1. Question Per window rows T = 1..8 on the RTX 5090: is upstream's down kernel (mask 133 = 128 + 4 + 1, and for reference mask 5 and the plain mask 0) faster than ours, by how many microseconds, and are the outputs bitwise equal? ## 2. What the two kernels are (read from the code, not from the ledger) | | upstream `gr_down_v3_kernel` (`src/kernels/cuda/fused_gr.cu`) | ours `chain_gr_down_t2w8_nb4` (`crates/cuda-driver/src/chain_window.cu`) | | --- | --- | --- | | input | `R`, `bo_prev`, `inj_prev`, `w_norm` of every token: the kernel itself builds `R' * w_norm` in shared memory and sums `R'^2` | `xn` = normalised activations, written before by the separate kernel `chain_gr_split` (3 us in K10) | | output | **unscaled partial dots** `part[token][stream][row]` (324 rows: 320 down + 4 inject) and `ssg` (sum of squares per stream); `lo`, `rs` and `inject_out` come out of the prologue of the following `gr_up_v3_kernel` | final `lo = silu(dot / hc)` and `inject_out` per token, `rs` from `chain_gr_split` | | summation | per stream (2560 columns, 10 chunks a lane), then `fmaf(rs[c], part_c, sum)` over the 4 streams | one 10240-column dot in tile order, on activations already multiplied by `rs` | | grid (T = 1..4) | mask 5 and 133: `gr_down_v3_kernel<1,T,exact,R2V=1,PF=1>`, grid (41, 4), 256 threads, dynamic shared `T * 10240` B | grid (41, ceil(T/2)), 256 threads, dynamic shared 4 tiles of 2 tokens = 40960 B (20480 B at T = 1) | | grid (T = 5..8) | mask 133: `<1,T,exact,R2V=2,PF=0,RB=true>`, grid (21, 4), shared `T * 10240` B (up to 81920 B); mask 5: as above (41, 4) | the same formula, ceil(T/2) = 3 / 3 / 4 / 4 | Consequences, stated so the result is not over-read: * **Not bitwise.** The two kernels sum the same products in a different order and place the rms scale differently (upstream's own header says "ANOTHER SUMMATION ORDER"). Equality to the bit is not expected; the harness reports how large the difference is (section 5). Upstream's masks 0 / 5 / 133 are claimed bitwise equal to each other (`gr_v3_screen`); the harness checks that claim on `part` and `ssg`. * **Upstream's down kernel does more than ours** (it stages `R' * w_norm` and reduces the sum of squares; ours has that in `chain_gr_split`). The fair pair for "the HC read up to the low-rank activation" is therefore reported both ways: our down kernel alone, and our split + down. The whole read (down + up for upstream, split + down + up8 for ours) is measured as a third comparison. * Upstream's default on cc 12.0 is mask 133 (`include/strata/core/bw_dense_defaults.hpp`, `gr_v3_pf_default`). Its dispatch for mask 133 is bit 7 for n >= 5 (R2V = 2 register-blocked), else bit 0 (`PF=1`, staging loads of all tokens in flight) for n <= 4; bit 2 belongs to the up kernel. The harness copies that selection ladder (`upstream_down_launch.inc`) and calls upstream's own launch helpers. ## 3. Method One program, `scripts/e2e/codex/speed/verify-hc-down-kernel-microbench-vs-upstream/microbench.cu` (+ `upstream_down_launch.inc`, `compare_outputs.inc`, `summarize.py`, `build.sh`, `ours-shim/`): * Upstream: `fused_gr.cu` is `#include`d whole and unmodified (so kernels, constants and helpers are upstream's own); compiled with nvcc 13.2.2 `-O3 -DNDEBUG -arch=sm_120 -std=c++17` (see assumptions). The down kernels are launched directly (masks 0, 5, 133). For the pipeline and for the real `rs` / `inject_out` / `mixed` outputs upstream's own entry point `fused_gr_read_multi` runs with `STRATA_GR_V3=1` and `fused_gr_v3_pf(mask)`. * Ours: the **sealed `chain_window.ptx` through `cuModuleLoadData`** (how the product loads it), launched with `cuLaunchKernel` with the 912-byte by-value `GrMulti` filled the way `multi_words` in `original_verify_window_gr/assets.rs` does; geometry from `tiled_down_geometry` (grid `(41, ceil(T/2))`, 256 threads, 40960 B shared), `chain_gr_split` grid `(T, 4)`, `chain_gr_up8` 320 blocks. The same source built by nvcc 13.2.2 to a cubin (flags of `extra-seal-plan.json`: `-O3 -arch=sm_120 -std=c++17 --fmad=true --ftz=false`) is measured next to it, which separates the driver's PTX JIT from the kernel (`build.sh` also checks that the regenerated PTX is the sealed one: the three HC kernels are identical, differences are only in mangled-name hashes and in the sampler and swiglu kernels). * Inputs (same for every variant): the distributions and the seed (7) of upstream's `gr_v3_screen.cpp`: `R ~ N(0,1)`, `bo ~ 0.5 N`, `inj ~ N(0,1)`, `w_norm = 1 + 0.3 N`, `w_down ~ 0.02 N` (bf16, `[320][10240]`), `w_up ~ 0.05 N` (bf16, `[10240][320]`), `w_inject ~ 0.02 N` (bf16, `[4][10240]`), `apply = 1`, inject on (a layer read). Model dims: `N = 2560`, `HC = 4`, `LR = 320`, `D = 10240`, from `fused_gr.cu` (`kCompiledGeometry`) and `chain_window.cu`, equal in both. Weight values do not change the timing; the bit comparison uses the same finite values in both. * Timing, three views, interleaved over variants and rounds (7 rounds, the start variant rotated each round): 1. **graph, cold weights (headline)**: 64 launches captured in one CUDA graph, each on its own copy of the layer weights (64 sets, 13.2 MB each, 845 MB; the 5090's L2 is 96 MB, so the weights come from DRAM as in the engine, where 96 layer halves rotate). Per-launch time = graph time / 64; 40 replays a round, so `n = 280` graph replays a variant and T. Median, p10, p90 over the replays, and the range of the per-round medians (the noise bound). 2. **graph, warm weights**: the same, all 64 launches on set 0 (weights stay in L2): the kernel's compute/issue floor. 3. **single launch**: a 50 us spin kernel keeps the stream ahead of the host, then event, launch, event; 120 launches a round; includes the event overhead, which the two empty-kernel rows measure. Also timed in every view: an **empty kernel with the same grid, block, dynamic shared memory and by-value argument** as upstream's mask 133 launch and as ours (the launch-shape floor; subtract it to compare kernel bodies, or compare it between the two shapes), and the **whole read** (graph, cold weights). * A 2 s warm-up of the real kernels runs first; the stub samples SM clock, power and throttle reasons once a second (`smi.csv`). * Correctness (`compare_outputs.inc`), per T, window rows with `apply = 1`: A. upstream masks 5 / 133 against mask 0, byte for byte on `part` and `ssg` (upstream's claim); B. our sealed PTX against our nvcc cubin, byte for byte on `lo`, `inject_out`, `rs`; C. our down stage (`lo`, `inject_out`, `rs`) against each upstream mask. Upstream's `lo` never leaves shared memory, so it is rebuilt from `part` / `ssg` by `mb_finalize_down`, a transcription of the prologue lines of `gr_up_v3_kernel` (marked as such in the source); `rs` and `inject_out` are also compared from upstream's real up kernel (D); D. the whole read: `R` (updated in place), `rs`, `inject_out`, `mixed` of ours (split + down + up8) against upstream's real `fused_gr_read_multi`, each mask. Each comparison prints the number of words, the number that differ bitwise, the largest absolute and relative difference, the largest distance in ulps, and non-finite counts. ## 4. Inputs (sha256; the full list of 419 files is `MANIFEST.sha256` on the server) Server directory `/data/leleka-e2e/spd-gap/microbench/verify-hc-down-kernel-microbench-vs-upstream/` (frozen read-only; the stub runs `sha256sum -c MANIFEST.sha256` first and refuses to start on a mismatch): | file | sha256 | | --- | --- | | `upstream-src/src/kernels/cuda/fused_gr.cu` (`strata-upstream/main:src/kernels/cuda/fused_gr.cu`) | `35a9f21a5eeaa187c8f20cc8ae35e31ccb563f663f199b305e104a4c81fc589f` | | `upstream-src/include/**` (228 files) and `s26_tsum.cuh`, `gr_v3_screen.cpp`, `fused_gr_bench.cpp` | in `MANIFEST.sha256` | | `ours-src/crates/cuda-driver/src/chain_window.cu` (git blob `4cb96e8bd`) | `54ff6a3d96ac6c5ebbc30b7d9f3dea021c6589892eaefd777300d7d80645f9af` | | `ours-src/crates/cuda-driver/src/chain_window.ptx` (sealed; git blob `716a0d24e`) | `a3abdc4186b66d51a80c8ef52f636f1893a2136b887cd6548786fea279ef71ba` | | `harness/microbench.cu` | `bd5d6f768af1d50e9897f12138488676a628a06b5cfc5c46fff23e5db6290505` | | `harness/upstream_down_launch.inc` | `923c4edeabffc2d24128134ee29842ba2ae34e1517077a37ed4fd5b4d4e7b7c4` | | `harness/compare_outputs.inc` | `6a184d3399a3eb9b9cd92e198397ec4c584c7fc1615e526ddd1672d2f2d9e417` | | `harness/summarize.py` | `d2625d2e35029437078f551c73d58b7b89bfdb71359a6c23d2c7282784185ec1` | | `harness/build.sh` | `516b2d3751f615f3dfd0b0590c307a816e84e40ec8a1f04349ba28e25ee90da5` | | `harness/ours-shim/strata/kernels/fused_gr.hpp` | `3022f1d2362bc2eb6ac2c8a59015e90a920ce272440682763b76c3b001e93942` | | `build/microbench` | `0601fa9c1790ceba12d7f66935912b6128c26bd3bef5da3f1d40461fbc419c31` | | `build/chain_window.cubin` | `fdeb42ab660991bc84ddc5bcb201671eedcc962d0f3068a9a3624f80b227f0c1` | ## 5. How to read `result.txt` Written to `