From fe2b8cd7fe91680a5f298ee20c59b233a0f6e7e7 Mon Sep 17 00:00:00 2001 From: Adam Zhang Date: Tue, 27 Oct 2026 23:47:11 -0500 Subject: [PATCH] r4d_selftest: --perfhc times the prefill-tile forms a row count is served by Pinned at 8 rows up to the wide row tile, the wide kernels refuse the shape (RAD_E_SHAPE: they serve only the wide tile), and --perfhc stopped at that FAIL before timing anything, so hc_read could not be timed at a verify step's 8 to 32 rows (two to eight streams at MTP 3). A pinned form that refuses with RAD_E_SHAPE is now a skip; the forms that serve run, compare byte for byte and time as before. The decode tiles' kernels, the first form, must still serve, and any other error fails as before. --perfhc 8 / 32 / 64, cold, one R9700: the decode tiles' kernels 46.5 / 51.2 / 81.0 us a call, where each stopped at the FAIL before. --- libr4d/r4d_selftest.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/libr4d/r4d_selftest.cpp b/libr4d/r4d_selftest.cpp index 25ae1e30..cbb88bbb 100644 --- a/libr4d/r4d_selftest.cpp +++ b/libr4d/r4d_selftest.cpp @@ -18198,11 +18198,20 @@ static void hc_prefill(const Plugin& pl, int64_t M, int iters, bool timed, bool static const char* const kForm[] = { "the launcher's rule", "the decode tiles' kernels", "the wide kernels", "the PF2 kernels" }; std::vector outs; + std::vector ran; /* the form each of `outs` came from */ for (int form = f_lo; form <= f_hi; ++form) { if (pl.pin_hc) pl.pin_hc(form); st_memset(d_x, 0, xb); st_memset(d_inj, 0, ib); st_memset(d_q, 0, qb); st_memset(d_qs, 0, sb); st_memset(d_rq, 0, qb); st_memset(d_rs, 0, sb); const int rc = r->launch(&a, rst); + /* A pinned form refusing the shape is not a failure: the wide kernels serve only the wide + * row tile, so from 8 rows up to it --perfhc times the decode tiles' kernels alone. The + * first form (the decode tiles') must serve. */ + if (rc == RAD_E_SHAPE && pl.pin_hc && form > f_lo) { + skip(fmt("%s prefill form '%s' at M=%lld", rn, kForm[form], (long long)M).c_str(), + "not served at this row count"); + continue; + } if (rc != RAD_OK || st_stream_sync(hs) != hipSuccess) { ok(fmt("%s prefill form '%s' at M=%lld is served", rn, kForm[form], (long long)M).c_str(), false, fmt("rc=%d", rc)); @@ -18217,6 +18226,7 @@ static void hc_prefill(const Plugin& pl, int64_t M, int iters, bool timed, bool get(o.x, d_x, xb); get(o.inj, d_inj, ib); get(o.q, d_q, qb); get(o.qs, d_qs, sb); get(o.rq, d_rq, qb); get(o.rs, d_rs, sb); outs.push_back(std::move(o)); + ran.push_back(form); } /* Form f against the decode tiles' kernels, outs[0]. */ auto same = [&](size_t f, const char* what) { @@ -18235,10 +18245,10 @@ static void hc_prefill(const Plugin& pl, int64_t M, int iters, bool timed, bool bad.empty() && nz > qb / 2, bad.empty() ? fmt("%zu of %zu codes non-zero", nz, qb) : "differs in" + bad); }; - for (size_t f = 1; f < outs.size(); ++f) same(f, kForm[f_lo + (int)f]); + for (size_t f = 1; f < outs.size(); ++f) same(f, kForm[ran[f]]); if (timed) { - for (int form = f_lo; form <= f_hi; ++form) { + for (const int form : ran) { if (pl.pin_hc) pl.pin_hc(form); hipEvent_t w0, w1; st_ev_create(&w0); st_ev_create(&w1); @@ -31409,8 +31419,8 @@ static void usage(void) { " rows -- at one shape, each with its TFLOP/s.\n" " --perfw2 N K M [iters]: the int2 DFlash2 draft head at every variant it has.\n" " --perfhc M [iters]: hc_read_e4m3 at Qwen3.8-Flash-Next's shape and M rows, every\n" - " prefill-tile form (PF2 from M=512) compared byte for byte and timed\n" - " as one op each;\n" + " prefill-tile form that serves M (the wide kernels at the wide tile,\n" + " PF2 from M=512) compared byte for byte and timed as one op each;\n" " run it under libr4d/isa/trace.sh for its launches.\n" " --cold MIB: with a --perf mode, time cold: read MIB through the caches before\n" " every timed launch (256 empties this card's L2 and last level) and\n"