From 17ebb94433bf0dc14eda09b22cf07f07f82da4d6 Mon Sep 17 00:00:00 2001 From: sergiywith Date: Thu, 1 Oct 2026 17:32:32 +0300 Subject: [PATCH] gr_parity: compare the split read (STRATA_GR_V3=1) within float rounding With STRATA_GR_V3=1 "fused GR multi max-T=8 LDS launch and changing graph replay" failed: the test compares the multi-token read with the single-token kernel bit for bit, and v3 sums `down` in another order (row group x stream blocks). It also compared `lo`, the default kernels' workspace between down and up, which v3 keeps in shared memory and never writes. Under v3 the test now checks R_out, rs, inject and mixed within 2e-6 of the largest reference value and leaves `lo` out; without it, bit for bit as before. Passes both ways. --- src/kernels/gr_parity.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/kernels/gr_parity.cpp b/src/kernels/gr_parity.cpp index d1f79fa3..b5ceb76c 100644 --- a/src/kernels/gr_parity.cpp +++ b/src/kernels/gr_parity.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -331,7 +332,22 @@ int fused_multi_lds_parity(const float* d_norm, const uint16_t* d_down, const ui check(cudaMemcpy(s.mixed.data(), d_mixed, s.mixed.size() * sizeof(float), cudaMemcpyDeviceToHost), "multi read mixed"); return s; }; - auto same = [](const Snapshot& a, const Snapshot& b) { + // the split read (STRATA_GR_V3=1) sums in another order than the single-token kernel: equal within float + // rounding, not to the bit, so it is compared with a relative tolerance; the default kernels bit for bit + static const bool v3 = [] { const char* v = std::getenv("STRATA_GR_V3"); return v != nullptr && std::atoi(v) != 0; }(); + auto close = [](const std::vector& x, const std::vector& y) { + double worst = 0.0, mag = 1e-30; + for (size_t i = 0; i < x.size(); ++i) { + worst = std::max(worst, (double) std::fabs(x[i] - y[i])); + mag = std::max(mag, (double) std::fabs(y[i])); + } + if (worst > 2e-6 * mag) + std::printf(" tolerance: worst %.3e of max |ref| %.3e (rel %.3e), n %zu\n", worst, mag, worst / mag, x.size()); + return worst <= 2e-6 * mag; + }; + auto same = [&](const Snapshot& a, const Snapshot& b) { + if (v3) // `lo` is the default kernels' workspace between down and up; the split read keeps it in shared memory + return close(a.r_out, b.r_out) && close(a.rs, b.rs) && close(a.inject, b.inject) && close(a.mixed, b.mixed); return std::memcmp(a.r_out.data(), b.r_out.data(), a.r_out.size() * sizeof(float)) == 0 && std::memcmp(a.lo.data(), b.lo.data(), a.lo.size() * sizeof(float)) == 0 && std::memcmp(a.rs.data(), b.rs.data(), a.rs.size() * sizeof(float)) == 0 &&