Round 27 Track C Audit Report: gdn_step_t (gdn.metal) Barrier Elimination (5 -> 4 Barriers/Token) + dt/ssm_a Hoist + part[8]/red2[IB-1] Shrink #
- Agent:
argon-r27-gdn-and-gr-opt(gemini-4-argon) - Patch:
/tmp/argon_r27_gdn/argon_r27_gdn.patch(git -C vendor/strata apply --check /tmp/argon_r27_gdn/argon_r27_gdn.patchpasses cleanly) - Owned files:
metal/kernels/gdn.metal,metal/tests/gdn_parity.cpp(vendor/strata/untouched)
1. Summary of Changes #
-
Barrier Elimination (
5 -> 4threadgroup_barriers per Token) +part[32] -> part[8]Shrink (metal/kernels/gdn.metal):- Before the first barrier of each token, threads
0..127(sg = 0..3) and128..255(sg = 4..7) already hold rawcvin registers: they now write rawqs[tid] = cvandks[tid - 128] = cvdirectly to shared memory alongside theirsimd_sum(cv * cv)write topart[sg], while threads256..383(sg = 8..11) writevs[tid - 256] = cv(skipping redundantsimd_sum(cv * cv)ontid >= 256and shrinkingthreadgroup float part[32]topart[8]) and idle lanes384/416computegb[0]/gb[1]. - After that single barrier, each thread computes
rsq = rsqrt(tot_q / float(S) + a.eps / float(S))andrsk = rsqrt(tot_k / float(S) + a.eps / float(S))frompart[0..7]and normalizeskl = (rsk * ks[qk_idx]) * scaleandql = (rsq * qs[qk_idx]) * scaleon the fly before broadcasting across the simdgroup. - Because
(rsk * ks[qk_idx]) * scaleand(rsq * qs[qk_idx]) * scaleexecute the exact same two IEEE-754 roundings(rs * cv) * scalein the exact same order on the exact samecvvalue, the result is 100% bitwise identical while eliminatingGDN_NTOK512-thread barriers per dispatch (144barriers per 4-token verify window across 36 GDN layers). - Write-after-read safety across tokens
t -> t + 1holds with three subsequent barriers in tokentseparating all reads ofqs,ks,vs,part, andgbfrom their next-token writes.
- Before the first barrier of each token, threads
-
Token-Invariant
dt[h]&ssm_a[h]Hoist +red2[IB][S] -> red2[IB - 1][S]Shrink (metal/kernels/gdn.metal):- Preloaded
dth = tid == 384 ? dt[h] : 0.0fandssm_ah = tid == 384 ? ssm_a[h] : 0.0fbefore thestateload loop and token loop so their device loads issue in parallel withqkv,hist,conv_w,gamma, andstate. - Shrunk
threadgroup float red2[IB][S]tored2[IB - 1][S](saving512 Bof threadgroup memory; total threadgroup memory drops5784 B -> 5176 BforIB = 4):ib == 0keeps its partial readoutoin its register across the barrier and accumulatesfor (int k = 0; k < IB - 1; ++k) o += red2[k][j], preserving the exact IEEE-754 addition order((o_0 + o_1) + o_2) + o_3while eliminating 128 shared stores and 128 shared loads + additions per token. - Tested
#pragma clang loop unroll(full)onfor (int t = 0; t < GDN_NTOK; ++t)and ruled it out: full unrolling of the outer token loop degradedntok >= 4performance by+6% .. +16%due to register pressure under[[max_total_threads_per_threadgroup(512)]].
- Preloaded
-
Extended
gdn_parity --abCoverage tontok = 1..8(metal/tests/gdn_parity.cpp):- Updated
--abbitwise parity and paired A/B benchmark loops inmetal/tests/gdn_parity.cppfromntok = 1..4to1..MAXT(1..8), covering all 88(ntok, commit, plane)combinations (commit = 0,1,0x101 .. 0x107;plane = 0,49152) in< 4.2stotal runtime.
- Updated
2. Verification & Paired A/B Benchmark Results on Apple M5 #
- Pipeline threadgroup occupancy:
gdn_step(IB = 4):maxTotalThreadsPerThreadgroup = 512(needs512) for allGDN_NTOK = 1..8.gdn_step8(IB = 8):maxTotalThreadsPerThreadgroup = 1024(needs1024) for allGDN_NTOK = 1..8.
- Bitwise parity (
gdn_parity --ab /tmp/argon_r27_gdn/base_gdn.metal):gdn_step(IB = 4): 88 / 88 PASS (0 fail(s) ALL PASS,memcmp == 0ony,state,histacross allntok = 1..8,commit = 0/1/partial,plane = 0/49152).gdn_step8(IB = 8): 88 / 88 PASS (0 fail(s) ALL PASS).
- Paired A/B Benchmark (
./build-metal/gdn_parity --ab /tmp/argon_r27_gdn/base_gdn.metal --bench, 36 layers rotated = 113 MB state):
ab bench plane 0 ntok 1 commit base 59.03 us cand 58.54 us ratio 0.9885 (x36: 2.125 -> 2.107 ms)
ab bench plane 0 ntok 1 verify base 35.23 us cand 34.51 us ratio 1.0120 (x36: 1.268 -> 1.242 ms)
ab bench plane 0 ntok 2 commit base 67.51 us cand 66.34 us ratio 0.9924 (x36: 2.430 -> 2.388 ms)
ab bench plane 0 ntok 2 verify base 41.03 us cand 40.69 us ratio 0.9915 (x36: 1.477 -> 1.465 ms)
ab bench plane 0 ntok 3 commit base 67.96 us cand 73.18 us ratio 1.0698 (x36: 2.447 -> 2.635 ms)
ab bench plane 0 ntok 3 verify base 53.70 us cand 49.92 us ratio 0.9458 (x36: 1.933 -> 1.797 ms)
ab bench plane 0 ntok 4 commit base 85.32 us cand 82.23 us ratio 0.9813 (x36: 3.071 -> 2.960 ms)
ab bench plane 0 ntok 4 verify base 66.33 us cand 61.44 us ratio 0.9449 (x36: 2.388 -> 2.212 ms)
ab bench plane 0 ntok 5 commit base 97.72 us cand 97.38 us ratio 0.9693 (x36: 3.518 -> 3.506 ms)
ab bench plane 0 ntok 5 verify base 76.71 us cand 71.98 us ratio 0.9729 (x36: 2.762 -> 2.591 ms)
ab bench plane 0 ntok 6 commit base 105.55 us cand 107.56 us ratio 1.0220 (x36: 3.800 -> 3.872 ms)
ab bench plane 0 ntok 6 verify base 85.64 us cand 80.99 us ratio 0.9284 (x36: 3.083 -> 2.916 ms)
ab bench plane 0 ntok 7 commit base 115.73 us cand 109.36 us ratio 0.9450 (x36: 4.166 -> 3.937 ms)
ab bench plane 0 ntok 7 verify base 92.26 us cand 83.80 us ratio 0.9412 (x36: 3.321 -> 3.017 ms)
ab bench plane 0 ntok 8 commit base 121.96 us cand 113.98 us ratio 0.9386 (x36: 4.390 -> 4.103 ms)
ab bench plane 0 ntok 8 verify base 98.90 us cand 93.92 us ratio 0.9496 (x36: 3.561 -> 3.381 ms)
ab bench plane 49152 ntok 1 commit base 61.16 us cand 60.90 us ratio 0.9698 (x36: 2.202 -> 2.193 ms)
ab bench plane 49152 ntok 1 verify base 39.40 us cand 38.15 us ratio 0.9683 (x36: 1.418 -> 1.373 ms)
ab bench plane 49152 ntok 2 commit base 69.72 us cand 67.33 us ratio 0.9847 (x36: 2.510 -> 2.424 ms)
ab bench plane 49152 ntok 2 verify base 47.07 us cand 46.84 us ratio 0.9995 (x36: 1.695 -> 1.686 ms)
ab bench plane 49152 ntok 3 commit base 77.60 us cand 75.86 us ratio 0.9621 (x36: 2.794 -> 2.731 ms)
ab bench plane 49152 ntok 3 verify base 57.29 us cand 56.05 us ratio 0.9837 (x36: 2.062 -> 2.018 ms)
ab bench plane 49152 ntok 4 commit base 94.69 us cand 86.28 us ratio 0.9218 (x36: 3.409 -> 3.106 ms)
ab bench plane 49152 ntok 4 verify base 67.10 us cand 64.39 us ratio 0.9207 (x36: 2.415 -> 2.318 ms)
ab bench plane 49152 ntok 5 commit base 106.59 us cand 101.82 us ratio 0.9709 (x36: 3.837 -> 3.666 ms)
ab bench plane 49152 ntok 5 verify base 79.16 us cand 75.86 us ratio 0.9398 (x36: 2.850 -> 2.731 ms)
ab bench plane 49152 ntok 6 commit base 115.77 us cand 109.96 us ratio 0.9570 (x36: 4.168 -> 3.959 ms)
ab bench plane 49152 ntok 6 verify base 95.05 us cand 88.38 us ratio 0.9473 (x36: 3.422 -> 3.182 ms)
ab bench plane 49152 ntok 7 commit base 126.66 us cand 118.77 us ratio 0.9567 (x36: 4.560 -> 4.276 ms)
ab bench plane 49152 ntok 7 verify base 102.09 us cand 96.49 us ratio 0.9493 (x36: 3.675 -> 3.474 ms)
ab bench plane 49152 ntok 8 commit base 127.43 us cand 120.34 us ratio 0.9517 (x36: 4.587 -> 4.332 ms)
ab bench plane 49152 ntok 8 verify base 109.12 us cand 102.96 us ratio 0.9830 (x36: 3.928 -> 3.707 ms)