libr3d: value-init the GEMM's by-value structs so the tape audit sees no padding

The recorded-pass audit (Ctx::tapes_agree -> a_tape_diff) byte-compares the serialized
kernel arguments of a pass against its recording, and on the first disagreement it concludes
"the pass depends on something the recording's key does not carry" and stops the engine. On
gfx1102 with the dspark drafter that self-stop fired on the third request:

  E rank 0: draft pass -1 at 23 tokens issued differently from its recording after 0 plays,
    so the pass depends on something the recording's key does not carry:
    record 1: kernel fp8a8_tiled_kernel: its arguments differ at byte 28

Byte 28 is not a pointer offset. With ActQ = 24 bytes (a pointer, a long long, an int, and a
4-byte trailing hole) and WQ = 64 bytes (with a 4-byte trailing hole), the argument block is
a[0,8) aq[8,32) b[32,40) h[40,104) ...; inside aq, gmode ends at 28 and bytes 28..32 are
padding. The audit found the first difference at 28, so every real field before it -- a,
aq.scale, aq.row, aq.gmode -- was identical: only the padding differed.

The launcher built those structs with aggregate-init (ActQ aq{ptr, ll, int};), which
initializes the three members and leaves the trailing padding indeterminate. HIP serializes
the whole struct, padding included, into the kernel-argument block, so the record and the
audit each captured whatever garbage was on the stack. Whether the two garbage patterns match
is a coin flip per run -- a Heisenbug that only surfaced once the stack states diverged.

Value-init the structs (ActQ aq{}; WQ h{}; MxWQ h{};) and assign the fields: value-init
zeroes the entire object including padding, aggregate-init does not. The kernel reads none of
the padding, so behaviour is unchanged -- only the serialized bytes become deterministic, and
the audit can no longer mistake a padding byte for a missing key. Applied to both the
fp8a8_tiled and mxfp4a8_tiled launchers, the only two libr3d kernels that pass a struct by
value.

Verified on the box (RX 7600, gfx1102): r3d_selftest 109 rows clean, 0 failed; the rig with
the dspark drafter armed (speculation at its auto depth) now serves back-to-back requests
past the point that self-stopped it before, with no schema or tape refusal.
This commit is contained in:
Asim Siddiqui authored and StillDeadcode committed 2026-11-03 19:06:47 +01:00
1 parent 798fb21e51
commit 702a0970cc
2 files changed
+31 -5

No files matched your search

+19 -3
View File
@@ -467,9 +467,25 @@ int launch(long av, long asv, long bvc, long bsv, long yv, int M, int N, int K,
const dim3 blk(kBlockThreads);
const dim3 grd((unsigned)((N + kTN - 1) / kTN), (unsigned)((M + kTM - 1) / kTM));
ActQ aq{ (const float*)(uintptr_t)asv, (long long)as_ld, as_ld != 1 };
WQ h{ (const uint8_t*)(uintptr_t)bvc, (const uint8_t*)(uintptr_t)bsv,
(const uint8_t*)(uintptr_t)zv, b_row, bs_row, z_row, sdt, cdt, srows };
/* Value-init (not aggregate-init): the tape audit byte-compares the serialized kernel
* arguments, and aggregate-init leaves a struct's trailing padding indeterminate. A padding
* byte that differs between a pass's recording and its audit is read as "the key does not
* carry" this argument and stops the engine (the ActQ/WQ holes are 4 bytes each). Zero the
* whole struct so the padding is deterministic; the kernel reads none of it. */
ActQ aq{};
aq.scale = (const float*)(uintptr_t)asv;
aq.row = as_ld;
aq.gmode = as_ld != 1;
WQ h{};
h.codes = (const uint8_t*)(uintptr_t)bvc;
h.scale = (const uint8_t*)(uintptr_t)bsv;
h.zero = (const uint8_t*)(uintptr_t)zv;
h.code_row = b_row;
h.scale_row = bs_row;
h.zero_row = z_row;
h.sdt = sdt;
h.cdt = cdt;
h.srows = srows;
hipStream_t s = (hipStream_t)(uintptr_t)stream;
#define R3D_RUN(NT, ARM, CD, AL) \
fp8a8_tiled_kernel<NT, ARM, CD, AL><<<grd, blk, 0, s>>>( \
+12 -2
View File
@@ -482,8 +482,18 @@ int launch_mxfp4a8_tiled(long av, long asv, long bvc, long bsv, long yv, int M,
const dim3 blk(kBlockThreads);
const dim3 grd((unsigned)((N + kTN - 1) / kTN), (unsigned)((M + kTM - 1) / kTM));
ActQ aq{(const float*)(uintptr_t)asv, (long long)as_ld, 1};
MxWQ h{(const uint8_t*)(uintptr_t)bvc, (const uint8_t*)(uintptr_t)bsv, b_row, e8_row};
/* Value-init so the ActQ's 4-byte padding hole is deterministic: the tape audit byte-compares
* the serialized kernel arguments, and aggregate-init leaves that padding indeterminate, which
* reads as "the key does not carry" the argument and stops the engine. See fp8a8's launcher. */
ActQ aq{};
aq.scale = (const float*)(uintptr_t)asv;
aq.row = as_ld;
aq.gmode = 1;
MxWQ h{};
h.codes = (const uint8_t*)(uintptr_t)bvc;
h.e8 = (const uint8_t*)(uintptr_t)bsv;
h.code_row = b_row;
h.e8_row = e8_row;
hipStream_t s = (hipStream_t)(uintptr_t)stream;
if (alu) {
if (nt) mxfp4a8_tiled_kernel<1,1><<<grd, blk, 0, s>>>(