Round 20 Track C Audit: gdn_pre Key-Head t >= 3 Vectorized conv_w Fast Path + gdn_scan_r 32-Bit Base Offset Hoisting & Final-Token Dead-Lookahead Elimination #
1. Summary of Changes (metal/kernels/gdn_prompt.metal) #
-
gp_conv&gdn_preKey-Headt >= 3Fast Path (lines 26–105):- In
gp_conv(t < 3fallback), replaced 4 scalarcw[ch * 4 + k]loads with a single 128-bitfloat4 w = *(device const float4*)(cw + ch * 4);load and unrolled the 4-tap FMA loop. - In
gdn_pre's key-head branch (if (x < k_tgs)), added at >= 3branchless fast path preserving the exact lane-to-channel mappingd = int(lane) + m * 32(m = 0..3). - Hoisted
pq = qkv + (t - 3) * C + kh * S + int(lane)andpk = qkv + (t - 3) * C + (hk_n + kh) * S + int(lane), loaded 128-bitfloat4 wqandwkfromconv_w, and evaluated the 4-tap FMA chain at offsets0, C, 2*C, 3*Cwithoutsrc >= 0ternary branches.
- In
-
gdn_scan_rState Offset Hoisting, 32-Bit Base Offsets, and Final-Token Dead-Lookahead Elimination (lines 261–351, 421–423):- Hardware Register Discovery (64-bit VGPR vs 32-bit base offset): Holding 64-bit
devicepointers (sp,kn_p,qn_p,gb_p,vc_p,kq_p,o_p) live across thethreadgroup_barrierinside the token scan loop consumes 2 VGPRs per pointer per lane on Apple Silicon, crossing an occupancy cliff (192.2 ms -> 197.8 ms). - Instead, hoisted 32-bit integer strides and base offsets (
const int rs = hv * S, s0 = (i0 * hv + h) * S + j;,const int ks = hkn * S, k0 = hk * S + i0 + int(lr), v0 = h * S + j;), keepingdevicebase pointers in uniform argument registers and indexing(state + s0)[i * rs],kn[tn * ks + k0 + c * 32],qn[tn * ks + k0 + c * 32],vc[tn * rs + v0], ando[t * rs + v0]. - Split the
TB == 0loop intofor (int t = 0; t < T - 1; ++t)(withtn = t + 1, eliminatingmin(t + 1, T - 1)) followed by aif (T > 0)final-token epilogue fort = T - 1that skips the deadkn_l,qn_l,g_b_n,v_nglobal loads and skips the 64 deadsimd_broadcasts (knr,qnr) and 64 deadka/qaFMAs.
- Hardware Register Discovery (64-bit VGPR vs 32-bit base offset): Holding 64-bit
2. Bitwise Parity Verification (memcmp == 0) #
Verified via /tmp/argon_r20_gdn/strata/build-metal/gdn_prompt_parity (standalone suite + --ab bitwise comparison against baseline gdn_prompt.metal):
- All
gdn_preoutputs (qn,kn,vc,gb,kq,history),gdn_scanr_4outputs (o,state), andgdn_postoutputs (yh,y) pass with 100% bitwisememcmp == 0acrossT = 1, 2, 3, 4, 64, 512, 1024, 2048.
3. Paired A/B Timings (Apple M5, 36 GDN Layers, Quiet GPU) #
Token Count T |
Stage | Baseline Median (ms) | Candidate Median (ms) | Delta (ms) | Ratio (cand / base) |
|---|---|---|---|---|---|
512 |
stage 0 (gdn_pre) |
11.563 |
11.600 |
+0.037 |
1.0022 |
512 |
stage 1 (gdn_scanr_4) |
48.780 |
47.757 |
-1.023 |
0.9791 (-2.09%) |
512 |
stage 2 (gdn_post) |
7.423 |
7.427 |
+0.004 |
0.9988 |
1024 |
stage 0 (gdn_pre) |
23.221 |
23.175 |
-0.046 |
0.9978 (-0.22%) |
1024 |
stage 1 (gdn_scanr_4) |
96.569 |
93.866 |
-2.703 |
0.9729 (-2.71%) |
1024 |
stage 2 (gdn_post) |
16.501 |
16.458 |
-0.043 |
0.9960 |
2048 |
stage 0 (gdn_pre) |
46.118 |
46.262 |
+0.144 |
1.0036 |
2048 |
stage 1 (gdn_scanr_4) |
192.239 |
187.765 |
-4.474 |
0.9764 (-2.36%) |
2048 |
stage 2 (gdn_post) |
34.228 |
34.211 |
-0.017 |
0.9995 |
4. Artifacts #
- Clean unified diff:
/tmp/argon_r20_gdn/argon_r20_gdn.patch(verified withgit -C vendor/strata apply --check). - Isolated build & test binaries:
/tmp/argon_r20_gdn/strata/build-metal/gdn_prompt_parityand/tmp/argon_r20_gdn/strata/build-metal/strata_window_cli.