New sealed sm_120 asset sm120_gr_down_fused.ptx (nvcc 13.2.86): leleka_gr_down_fused_t2w8 replaces chain_gr_split + chain_gr_down_t2w8_nb4 (96 launches fewer per verify graph). The block stages R' * w_norm of its two tokens into shared memory, adds the sum of squares in the split kernel's order, scales with rs and runs the down kernel's dots; the operations and their order are those of the two kernels (bitwise by construction; upstream's gr_down_v3 sums in another order). A no-op, said once, without the chain gr pair. Planner, switch resolution (Sm120Switches, GrConfig.down_fused), unit tests, model-free probe tools/gr-down-fused (not run: no GPU). Not measured. Microbench harness: the NaN outputs were a stream race between the poison memsets and the kernels, fixed; inputs are checked finite. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
15 KiB
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 onpartandssg. - Upstream's down kernel does more than ours (it stages
R' * w_normand reduces the sum of squares; ours has that inchain_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.cuis#included 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 realrs/inject_out/mixedoutputs upstream's own entry pointfused_gr_read_multiruns withSTRATA_GR_V3=1andfused_gr_v3_pf(mask). - Ours: the sealed
chain_window.ptxthroughcuModuleLoadData(how the product loads it), launched withcuLaunchKernelwith the 912-byte by-valueGrMultifilled the waymulti_wordsinoriginal_verify_window_gr/assets.rsdoes; geometry fromtiled_down_geometry(grid(41, ceil(T/2)), 256 threads, 40960 B shared),chain_gr_splitgrid(T, 4),chain_gr_up8320 blocks. The same source built by nvcc 13.2.2 to a cubin (flags ofextra-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.shalso 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, fromfused_gr.cu(kCompiledGeometry) andchain_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):
- 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 = 280graph replays a variant and T. Median, p10, p90 over the replays, and the range of the per-round medians (the noise bound). - graph, warm weights: the same, all 64 launches on set 0 (weights stay in L2): the kernel's compute/issue floor.
- 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).
- 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
- 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 withapply = 1: A. upstream masks 5 / 133 against mask 0, byte for byte onpartandssg(upstream's claim); B. our sealed PTX against our nvcc cubin, byte for byte onlo,inject_out,rs; C. our down stage (lo,inject_out,rs) against each upstream mask. Upstream'slonever leaves shared memory, so it is rebuilt frompart/ssgbymb_finalize_down, a transcription of the prologue lines ofgr_up_v3_kernel(marked as such in the source);rsandinject_outare also compared from upstream's real up kernel (D); D. the whole read:R(updated in place),rs,inject_out,mixedof ours (split + down + up8) against upstream's realfused_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 <dir>/result.txt (earlier results are kept as result.<timestamp>.txt; clocks in smi.csv).
- Top: environment, clocks, the sha256 of binary and inputs, then
SHAPElines (grid, block and dynamic shared of each kernel per T), then theCORRECTNESS/DIFFlines (before any timing), thenTIMElines (one per mode, T and variant: median, p10, p90, min, mean, range of the per-round medians, n) andCSV,lines (the same numbers for scripts). - Bottom,
== tables: per mode a table of medians with p10..p90 per T, and delta tablesours - upstream(microseconds and percent; positive = upstream faster). A*marks a delta larger than the sum of the per-round-median ranges of the two variants, i.e. resolved against the run's own noise; no*= not resolved. Delta tables: our down kernel alone, and our split + down, each against mask 133, 5, 0; and the whole read. - The answer to the ledger question per T: row
ours_ptxagainstup_m133andup_m5in "graph-batched, cold weights (headline)" (our down alone), andours_split+downagainst the same for the complete stage;ours_cubinagainstours_ptxshows whether the driver's JIT matters; theempty_*columns give the launch-shape floor of each kernel's grid. - Bitwise:
DIFF ... part/ssgof mask 5 / 133 against mask 0 must saydiffering 0(upstream's claim; if not, say so in the ledger);ours_sealed_ptx vs ours_nvcc_cubinmust say 0;ours_sealed_ptx vs upstream_mask*forlo,inject_out,rsand the whole read (R updated,mixed) is the data the ledger needs:differingwords,max_abs,max_rel,max_ulp. The final lineCORRECTNESS summary: N unexpectedcounts only the first two checks and non-finite outputs; ours-versus-upstream differences are not counted as failures. - Cross-check against upstream's own number (RTX PRO 5000,
step-ledger.mdU5): its down kernel 16.1 / 16.2 / 17.6 / 19.5 -> 13.3 / 14.1 / 14.7 / 15.6 us at T 5-8 (plain -> mask 133, in situ, other card). The mask-0 and mask-133 rows here should show the same direction; the absolute values need not match.
Command (after the orchestrator has installed the stub in ~/work/gpu-runs/holder2/jobs/): the job runs
bash ~/work/gpu-runs/holder2/jobs/verify-hc-down-kernel-microbench-vs-upstream.sh. A short check run: MB_ARGS="--tmin 1 --tmax 2 --rounds 2 --replays 10" bash <stub>.
Run time estimate (not measured): 2 to 4 minutes after the PTX has been JIT-compiled by the driver (the 2.3 MB module).
6. Assumptions and limits
- The program has not run on the GPU. It compiles (nvcc 13.2.2, no warnings beyond a suppressed unreachable-loop remark in upstream's own template) and was
reviewed by reading only, but a first run can still fail at a launch; the stub's exit code and
result.txtshow where. Nothing here was validated on a device. - The headline timing is graph-batched, per launch inside a graph (launch gaps inside a graph are included, about the same for every variant: see the empty
rows). It is not the CUPTI in-situ kernel duration of K8 /
CL.1(11.1 us, 9.35-15.33 us by rows), where the neighbouring kernels, the L2 state and the clock differ; do not compare absolute values with those. The comparison between variants inside one run is the result. - "Cold" means rotating 64 weight sets of 6.6 MB (down + inject) so that none is in L2 at its next use; the 5090 L2 size is printed in the first line. The
activations (
R,xn) are L2-resident in every variant. In the engine the previous kernels have touched other data between two reads; that is not modelled. - Upstream's build flags are taken from
cmake/backends/cuda.cmake/strata_gpu_engine.cmake(Release, architecture 120, no fast-math forfused_gr.cu); the CUDA language standard of the upstream build is not stated there, and-std=c++17is used. nvcc 13.2.2 is the toolchain of both sides; upstream's release builds may use another CUDA version, whose code generation can differ. - Ours through the driver JIT and as an nvcc cubin are both measured; the product uses the former.
- The
ours-shim/fused_gr.hppis needed only for the nvcc rebuild ofchain_window.cu(the header inengine/strata/includehas a 168-byteFusedGrArgs; the sealed kernels use the 112-byte layout). The sealed PTX needs no header. - The
locomparison goes through a transcription of the up kernel's prologue (mb_finalize_down), not through upstream's compiled code; thers,inject_out,R,mixedcomparisons use upstream's real kernels. - The GPU is shared by queue: another process on the card during the run would spoil it; the stub holds
gpu.lockand logs the compute apps and the clocks.