From 4374bea1c4bca1c00c59890d10b799a274d5e8b4 Mon Sep 17 00:00:00 2001 From: Adam Zhang Date: Wed, 28 Oct 2026 08:13:25 -0500 Subject: [PATCH] hc_read: the one-grid form's wait traps past its deadline instead of reading a stale d hc_role_wait, where hc_read_fused_kernel's B blocks wait for every A block, gave up after half a second and went on, so a counter fault would have read a stale `d` and its scales and written wrong values with no error. The all-reduce handshakes trap on the same condition (r4d_ar_seq.h, r4d_ar_oneshot_2rank_exact.hip: a handshake that cannot complete is a lockstep violation); this does the same. It cannot fire with the counters in order (each launch's last B block clears them), so nothing that runs today changes. libr4d/isa/res.sh: no hc kernel spills, hc_read_fused_kernel 126-147 VGPRs. r4d_selftest --case hc_read_e4m3 and hc_read_bf16 on 890715f: 67 ok, 0 FAIL, the 24 byte-for-byte comparisons against the previous decode kernels among them. --perfhc 4: 25.4 us a call (the previous decode kernels 34.6), as before the change. --- libr4d/r4d_hc_bf16.hip | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libr4d/r4d_hc_bf16.hip b/libr4d/r4d_hc_bf16.hip index db362345..f8cda02a 100644 --- a/libr4d/r4d_hc_bf16.hip +++ b/libr4d/r4d_hc_bf16.hip @@ -1232,7 +1232,9 @@ __device__ __forceinline__ void hc_role_wait(unsigned int* __restrict__ sync, un * vector caches, and a poll of them would keep emptying them under the A blocks. */ while (__hip_atomic_load(&sync[1], __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_AGENT) < na) { __builtin_amdgcn_s_sleep(1); - if (wall_clock64() - t0 > 50000000ull) break; /* 0.5 s at the 100 MHz wall clock */ + /* 0.5 s at the 100 MHz wall clock. A blocks that never finish are a counter fault: + * trap rather than read a stale `d`, as the all-reduce handshakes do. */ + if (wall_clock64() - t0 > 50000000ull) __builtin_trap(); } __builtin_amdgcn_fence(__ATOMIC_ACQUIRE, "agent"); if (__hip_atomic_fetch_add(&sync[2], 1u, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_AGENT) + 1u @@ -1516,8 +1518,8 @@ void hc_up_mix_kernel(const void* __restrict__ upv, long uld, * smaller ticket has already started, so the blocks it waits on are resident and finish whatever * the waiters do: no co-residency is assumed and none can deadlock. The last B block past the * wait clears the three counters for the next launch on this stream (stream order publishes it). - * A wait that runs past half a second gives up rather than hang the card; it cannot happen with - * the counters in order. + * A wait that runs past half a second traps rather than hang the card or read a stale `d`; it + * cannot happen with the counters in order. * * Bit-identical to the two launches: the same bodies, the same per-block work. */ template