okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
4746bfb16
main
1// src/prefill/gdn_harness.cu - production-linked parity and benchmark harness for the prompt GDN path (CUDA). 2// 3// Links the real strata_prefill library and calls the real gdn_gates / gdn_conv / gdn_recurrence: there is not one 4// copy of a kernel in this file. Which recurrence runs is chosen through the GdnProbe (gdn_probe.hpp): a path can be 5// forced, the path that actually ran and the reason a wanted path did not run are read back after every call, and a 6// forced path that is not eligible launches nothing and is reported INELIGIBLE (it is never timed as a fallback). 7// Fixtures and the FP64 oracle are tests/gdn/gdn_fixture.hpp (shared with the other backends' harnesses). 8// Usage and output format: Desktop\30thOctober\results\gdn\HARNESS.md and docs/GDN_CONTRACT.md. 9#include "gdn_fixture.hpp" 10#include "strata/prefill/gdn_probe.hpp" 11#include "strata/prefill/kernels.hpp" 12 13#include <cuda_runtime.h> 14 15#include <algorithm> 16#include <chrono> 17#include <cstdio> 18#include <cstdlib> 19#include <cstring> 20#include <map> 21#include <set> 22#include <string> 23#include <vector> 24 25#ifndef GDN_HARNESS_SHA 26#define GDN_HARNESS_SHA "unknown" 27#endif 28 29using namespace gdnfx; 30namespace sp = strata::prefill; 31 32namespace { 33 34void ck(cudaError_t e, const char* what) { 35 if (e != cudaSuccess) { 36 std::fprintf(stderr, "%s: %s\n", what, cudaGetErrorString(e)); 37 std::exit(2); 38 } 39} 40template <typename T> T* dalloc(size_t n) { 41 T* p = nullptr; 42 ck(cudaMalloc(&p, n * sizeof(T)), "cudaMalloc"); 43 return p; 44} 45template <typename T> T* dupload(const std::vector<T>& v) { 46 T* p = dalloc<T>(v.size()); 47 ck(cudaMemcpy(p, v.data(), v.size() * sizeof(T), cudaMemcpyHostToDevice), "upload"); 48 return p; 49} 50 51struct Args { 52 int64_t T = 4096; 53 std::vector<int64_t> Ts; // --T a,b,c : several lengths (one case each) 54 int64_t chunk = 2048; // tokens per engine call 55 std::vector<int64_t> cuts; // explicit first call sizes (unaligned splits), then `chunk` 56 std::vector<int> paths; // default: auto + every forced path 57 int incumbent = sp::kGdnKeyHead; // the path others are compared with (falls to pipe where ineligible) 58 bool parity = true, bench = false, ref = true; 59 std::vector<int> ref_heads = {0, 17, 34, 5, 22, 47}; 60 int reps = 7, warmup = 2; 61 bool any_sms = false; 62 int gsb = 0; 63 int tiles = 0; 64 bool fallback_incumbent = false; // a forced path takes the incumbent for calls it cannot run (mirrors production) 65 int64_t ld16 = 0; 66 FixtureSpec fx; 67 std::string json; 68 std::string label; 69 bool stress = false; // run the stress fixtures (parity only) 70}; 71 72std::vector<int64_t> parse_list(const char* s) { 73 std::vector<int64_t> v; 74 for (const char* p = s; *p;) { 75 char* e = nullptr; 76 long long x = std::strtoll(p, &e, 10); 77 if (e == p) break; 78 if (*e == 'k' || *e == 'K') { x *= 1024; ++e; } 79 v.push_back(x); 80 p = *e == ',' ? e + 1 : e; 81 } 82 return v; 83} 84int path_from_name(const std::string& n) { 85 for (int p = 0; p < sp::kGdnPathCount; ++p) 86 if (n == sp::gdn_path_name(p)) return p; 87 return -2; 88} 89 90struct Dev { // device-resident fixture 91 int64_t T = 0; 92 float *qkv = nullptr, *ab = nullptr, *dt = nullptr, *ssm_a = nullptr, *conv_w = nullptr, *z = nullptr, *gamma = nullptr; 93 float* state0 = nullptr; // [S*HV*S state | C*3 history] 94 float *gate = nullptr, *beta = nullptr, *h = nullptr, *y = nullptr, *state = nullptr; 95 uint16_t* y16 = nullptr; 96 int64_t ld16 = 0, chunk_max = 0; 97 char* flush = nullptr; 98 size_t flush_bytes = 256u << 20; 99}; 100constexpr size_t kStateFloats = (size_t) S * HV * S; 101 102Dev upload(const Fixture& f, int64_t chunk_max, int64_t ld16) { 103 Dev d; 104 d.T = f.T; 105 d.chunk_max = chunk_max; 106 d.ld16 = ld16 > 0 ? ld16 : (int64_t) HV * S; 107 d.qkv = dupload(f.qkv); 108 d.ab = dupload(f.ab); 109 d.dt = dupload(f.dt); 110 d.ssm_a = dupload(f.ssm_a); 111 d.conv_w = dupload(f.conv_w); 112 d.z = dupload(f.z); 113 d.gamma = dupload(f.gamma); 114 std::vector<float> st(kStateFloats + (size_t) C * 3); 115 std::memcpy(st.data(), f.state0.data(), kStateFloats * 4); 116 std::memcpy(st.data() + kStateFloats, f.hist.data(), (size_t) C * 3 * 4); 117 d.state0 = dupload(st); 118 d.state = dalloc<float>(st.size()); 119 d.gate = dalloc<float>((size_t) chunk_max * HV); 120 d.beta = dalloc<float>((size_t) chunk_max * HV); 121 d.h = dalloc<float>((size_t) chunk_max * C); 122 d.y = dalloc<float>((size_t) chunk_max * HV * S); 123 d.y16 = dalloc<uint16_t>((size_t) f.T * d.ld16 + 64); 124 ck(cudaMemset(d.y16, 0xAB, ((size_t) f.T * d.ld16 + 64) * 2), "memset y16 sentinel"); 125 d.flush = dalloc<char>(d.flush_bytes); 126 return d; 127} 128void release(Dev& d) { 129 for (void* p : {(void*) d.qkv, (void*) d.ab, (void*) d.dt, (void*) d.ssm_a, (void*) d.conv_w, (void*) d.z, (void*) d.gamma, 130 (void*) d.state0, (void*) d.state, (void*) d.gate, (void*) d.beta, (void*) d.h, (void*) d.y, 131 (void*) d.y16, (void*) d.flush}) 132 cudaFree(p); 133 d = Dev(); 134} 135 136std::vector<int64_t> plan_calls(int64_t T, const Args& a) { 137 std::vector<int64_t> v; 138 int64_t left = T; 139 for (int64_t c : a.cuts) { 140 if (left <= 0) break; 141 v.push_back(std::min(c, left)); 142 left -= v.back(); 143 } 144 while (left > 0) { v.push_back(std::min(a.chunk, left)); left -= v.back(); } 145 return v; 146} 147 148struct RunOut { 149 int path = 0; 150 bool eligible = true; 151 std::string reason; 152 std::set<std::string> logged; // distinct "wanted->selected [reason]" over the calls 153 int fallback_calls = 0; 154 double ms_gates = 0, ms_conv = 0, ms_rec = 0; 155 std::vector<uint16_t> y16; // dense [T][HV*S] 156 std::vector<float> state; 157}; 158 159// Runs the layer pipeline for every call of the plan. timed: events around each stage. 160RunOut run_path(Dev& d, const Args& a, const std::vector<int64_t>& calls, int path, bool timed, bool download) { 161 RunOut r; 162 r.path = path; 163 ck(cudaMemcpy(d.state, d.state0, (kStateFloats + (size_t) C * 3) * 4, cudaMemcpyDeviceToDevice), "reset state"); 164 float* conv_hist = d.state + kStateFloats; 165 sp::GdnProbe probe; 166 probe.any_sms = a.any_sms; 167 probe.gsb = a.gsb; 168 probe.tc_tiles = a.tiles; 169 sp::gdn_probe_install(&probe); 170 std::vector<cudaEvent_t> ev; 171 if (timed) { 172 ev.resize(calls.size() * 4); 173 for (auto& e : ev) ck(cudaEventCreate(&e), "event"); 174 } 175 int64_t t0 = 0; 176 size_t ci = 0; 177 for (int64_t T : calls) { 178 if (timed) ck(cudaEventRecord(ev[ci * 4]), "ev"); 179 sp::gdn_gates(d.ab + t0 * 2 * HV, d.dt, d.ssm_a, d.gate, d.beta, T, nullptr); 180 if (timed) ck(cudaEventRecord(ev[ci * 4 + 1]), "ev"); 181 sp::gdn_conv(conv_hist, d.qkv + t0 * C, d.conv_w, d.h, T, EPS, nullptr); 182 if (timed) ck(cudaEventRecord(ev[ci * 4 + 2]), "ev"); 183 probe.force = path; 184 sp::gdn_recurrence(d.state, d.h, d.gate, d.beta, d.z + t0 * HV * S, d.gamma, EPS, d.y, d.y16 + t0 * d.ld16, T, nullptr, d.ld16); 185 if (probe.selected == sp::kGdnNone && a.fallback_incumbent && path != a.incumbent) { 186 probe.force = a.incumbent; 187 sp::gdn_recurrence(d.state, d.h, d.gate, d.beta, d.z + t0 * HV * S, d.gamma, EPS, d.y, d.y16 + t0 * d.ld16, T, nullptr, d.ld16); 188 if (probe.selected == sp::kGdnNone) probe.force = sp::kGdnPipe, sp::gdn_recurrence(d.state, d.h, d.gate, d.beta, d.z + t0 * HV * S, d.gamma, EPS, d.y, d.y16 + t0 * d.ld16, T, nullptr, d.ld16); 189 ++r.fallback_calls; 190 } 191 if (timed) ck(cudaEventRecord(ev[ci * 4 + 3]), "ev"); 192 if (probe.selected == sp::kGdnNone) { 193 r.eligible = false; 194 r.reason = std::string("call of ") + std::to_string((long long) T) + " tokens: " + probe.reason; 195 break; 196 } 197 char b[200]; 198 std::snprintf(b, sizeof b, "%s->%s%s%s", sp::gdn_path_name(probe.wanted), sp::gdn_path_name(probe.selected), 199 probe.reason[0] ? " [" : "", probe.reason[0] ? probe.reason : ""); 200 std::string s = b; 201 if (probe.reason[0]) s += "]"; 202 r.logged.insert(s); 203 t0 += T; 204 ++ci; 205 } 206 ck(cudaDeviceSynchronize(), "run_path sync"); 207 sp::gdn_probe_install(nullptr); 208 if (timed && r.eligible) 209 for (size_t i = 0; i < ci; ++i) { 210 float x = 0; 211 cudaEventElapsedTime(&x, ev[i * 4], ev[i * 4 + 1]); r.ms_gates += x; 212 cudaEventElapsedTime(&x, ev[i * 4 + 1], ev[i * 4 + 2]); r.ms_conv += x; 213 cudaEventElapsedTime(&x, ev[i * 4 + 2], ev[i * 4 + 3]); r.ms_rec += x; 214 } 215 for (auto e : ev) cudaEventDestroy(e); 216 if (download && r.eligible) { 217 r.y16.resize((size_t) d.T * HV * S); 218 if (d.ld16 == (int64_t) HV * S) { 219 ck(cudaMemcpy(r.y16.data(), d.y16, r.y16.size() * 2, cudaMemcpyDeviceToHost), "y16 down"); 220 } else { 221 ck(cudaMemcpy2D(r.y16.data(), (size_t) HV * S * 2, d.y16, (size_t) d.ld16 * 2, (size_t) HV * S * 2, d.T, cudaMemcpyDeviceToHost), "y16 down 2d"); 222 // padding columns of a padded stride must be untouched (sentinel 0xABAB) 223 std::vector<uint16_t> pad((size_t) d.T * d.ld16); 224 ck(cudaMemcpy(pad.data(), d.y16, pad.size() * 2, cudaMemcpyDeviceToHost), "pad down"); 225 for (int64_t t = 0; t < d.T; ++t) 226 for (int64_t c = HV * S; c < d.ld16; ++c) 227 if (pad[(size_t) t * d.ld16 + c] != 0xABAB) { r.eligible = false; r.reason = "PADDING OVERWRITTEN (stride contract broken)"; return r; } 228 } 229 r.state.resize(kStateFloats + (size_t) C * 3); 230 ck(cudaMemcpy(r.state.data(), d.state, r.state.size() * 4, cudaMemcpyDeviceToHost), "state down"); 231 } 232 return r; 233} 234 235double median(std::vector<double> v) { 236 std::sort(v.begin(), v.end()); 237 return v.empty() ? 0 : v[v.size() / 2]; 238} 239 240struct Cmp { double y_nmax = 0, y_rl2 = 0, s_nmax = 0, s_rl2 = 0; long nonfinite = 0; }; 241 242Cmp vs_ref(const RunOut& r, const RefResult& ref, int64_t T) { 243 Cmp c; 244 ErrStat ey, es; 245 for (size_t n = 0; n < ref.heads.size(); ++n) { 246 const int vh = ref.heads[n]; 247 for (int64_t t = 0; t < T; ++t) 248 for (int col = 0; col < S; ++col) 249 ey.add(half_to_float(r.y16[(size_t) t * HV * S + (size_t) vh * S + col]), ref.y[n][(size_t) t * S + col]); 250 for (int i = 0; i < S; ++i) 251 for (int col = 0; col < S; ++col) es.add(r.state[((size_t) i * HV + vh) * S + col], ref.state[n][(size_t) i * S + col]); 252 } 253 c.y_nmax = ey.normalized_max(); c.y_rl2 = ey.rel_l2(); c.s_nmax = es.normalized_max(); c.s_rl2 = es.rel_l2(); 254 c.nonfinite = ey.nonfinite + es.nonfinite; 255 return c; 256} 257// candidate against the incumbent over every head, token and state element (not a subset) 258Cmp vs_incumbent(const RunOut& r, const RunOut& inc, int64_t T) { 259 Cmp c; 260 ErrStat ey, es; 261 for (size_t i = 0; i < r.y16.size(); ++i) ey.add(half_to_float(r.y16[i]), half_to_float(inc.y16[i])); 262 for (size_t i = 0; i < kStateFloats; ++i) es.add(r.state[i], inc.state[i]); 263 c.y_nmax = ey.normalized_max(); c.y_rl2 = ey.rel_l2(); c.s_nmax = es.normalized_max(); c.s_rl2 = es.rel_l2(); 264 c.nonfinite = ey.nonfinite + es.nonfinite; 265 (void) T; 266 return c; 267} 268 269std::string join(const std::set<std::string>& s) { 270 std::string o; 271 for (auto& x : s) { if (!o.empty()) o += "; "; o += x; } 272 return o; 273} 274 275void json_line(const Args& a, const char* kind, const char* fixture, int64_t T, const RunOut& r, const Cmp* ref, const Cmp* inc, 276 bool exact, double ms_med, double ms_min, const char* verdict, const cudaDeviceProp& pr) { 277 if (a.json.empty()) return; 278 FILE* f = std::fopen(a.json.c_str(), "a"); 279 if (!f) return; 280 std::fprintf(f, "{\"kind\":\"%s\",\"label\":\"%s\",\"device\":\"%s\",\"sms\":%d,\"cc\":\"%d.%d\",\"sha\":\"%s\",\"fixture\":\"%s\"," 281 "\"T\":%lld,\"chunk\":%lld,\"path\":\"%s\",\"eligible\":%s,\"reason\":\"%s\",\"log\":\"%s\",\"fallback_calls\":%d," 282 "\"ms_gates\":%.4f,\"ms_conv\":%.4f,\"ms_rec\":%.4f,\"ms_total_med\":%.4f,\"ms_total_min\":%.4f,\"exact_vs_incumbent\":%s,\"verdict\":\"%s\"", 283 kind, a.label.c_str(), pr.name, pr.multiProcessorCount, pr.major, pr.minor, GDN_HARNESS_SHA, fixture, (long long) T, 284 (long long) a.chunk, sp::gdn_path_name(r.path), r.eligible ? "true" : "false", r.reason.c_str(), join(r.logged).c_str(), 285 r.fallback_calls, r.ms_gates, r.ms_conv, r.ms_rec, ms_med, ms_min, exact ? "true" : "false", verdict); 286 if (ref) std::fprintf(f, ",\"ref_y_nmax\":%.3e,\"ref_y_rl2\":%.3e,\"ref_s_nmax\":%.3e,\"ref_s_rl2\":%.3e,\"nonfinite\":%ld", ref->y_nmax, ref->y_rl2, ref->s_nmax, ref->s_rl2, ref->nonfinite); 287 if (inc) std::fprintf(f, ",\"inc_y_nmax\":%.3e,\"inc_y_rl2\":%.3e,\"inc_s_nmax\":%.3e,\"inc_s_rl2\":%.3e", inc->y_nmax, inc->y_rl2, inc->s_nmax, inc->s_rl2); 288 std::fprintf(f, "}\n"); 289 std::fclose(f); 290} 291 292// One case: a fixture of T tokens, every wanted path. Returns the number of failed verdicts. 293int run_case(const Args& a, const FixtureSpec& spec, const char* fname, const cudaDeviceProp& pr) { 294 const int64_t T = spec.T; 295 const std::vector<int64_t> calls = plan_calls(T, a); 296 int64_t cmax = 0; 297 for (auto c : calls) cmax = std::max(cmax, c); 298 Fixture f = make_fixture(spec); 299 Dev d = upload(f, cmax, a.ld16); 300 std::printf("\n=== case %s T=%lld calls=%zu (first %lld, max %lld) ld16=%lld device %s (%d SMs, cc %d.%d)\n", fname, (long long) T, 301 calls.size(), (long long) calls[0], (long long) cmax, (long long) d.ld16, pr.name, pr.multiProcessorCount, pr.major, pr.minor); 302 RefResult ref; 303 if (a.parity && a.ref) { 304 auto t0 = std::chrono::steady_clock::now(); 305 ref = ref_run(f, a.ref_heads); 306 std::printf("FP64 oracle for %zu value heads: %.1f s\n", a.ref_heads.size(), 307 std::chrono::duration<double>(std::chrono::steady_clock::now() - t0).count()); 308 } 309 // the incumbent first (it may itself be ineligible: then pipe, which always runs) 310 std::vector<int> order = a.paths; 311 RunOut inc = run_path(d, a, calls, a.incumbent, false, true); 312 int inc_path = a.incumbent; 313 if (!inc.eligible) { 314 std::printf("incumbent %s INELIGIBLE (%s): using pipe\n", sp::gdn_path_name(a.incumbent), inc.reason.c_str()); 315 inc = run_path(d, a, calls, sp::kGdnPipe, false, true); 316 inc_path = sp::kGdnPipe; 317 } 318 std::map<int, RunOut> runs; 319 for (int p : order) { 320 RunOut r = (p == inc_path) ? inc : run_path(d, a, calls, p, false, true); 321 runs[p] = std::move(r); 322 } 323 int fails = 0; 324 std::map<int, std::vector<double>> total_ms; 325 std::map<int, RunOut> timed_last; 326 if (a.bench) { 327 for (int w = 0; w < a.warmup + a.reps; ++w) 328 for (int p : order) { 329 if (!runs[p].eligible) continue; 330 ck(cudaMemset(d.flush, w & 255, d.flush_bytes), "flush"); 331 RunOut t = run_path(d, a, calls, p, true, false); 332 if (w >= a.warmup) { 333 total_ms[p].push_back(t.ms_gates + t.ms_conv + t.ms_rec); 334 timed_last[p].ms_gates += t.ms_gates / a.reps; 335 timed_last[p].ms_conv += t.ms_conv / a.reps; 336 timed_last[p].ms_rec += t.ms_rec / a.reps; 337 } 338 } 339 } 340 std::printf("%-8s %-6s %-9s %9s %9s %9s %9s %-34s %s\n", "path", "elig", "bitwise", "ref_y", "ref_state", "inc_y", "inc_state", "ms gates/conv/rec (mean)", "ran"); 341 for (int p : order) { 342 RunOut& r = runs[p]; 343 const char* name = sp::gdn_path_name(p); 344 if (!r.eligible) { 345 std::printf("%-8s %-6s %s\n", name, "NO", r.reason.c_str()); 346 json_line(a, "case", fname, T, r, nullptr, nullptr, false, 0, 0, "INELIGIBLE", pr); 347 continue; 348 } 349 Cmp cr{}, ci{}; 350 const bool have_ref = a.parity && a.ref; 351 if (have_ref) cr = vs_ref(r, ref, T); 352 ci = vs_incumbent(r, inc, T); 353 const bool exact = r.y16 == inc.y16 && std::memcmp(r.state.data(), inc.state.data(), (kStateFloats + C * 3) * 4) == 0; 354 // conv history after the last call is a copy of inputs: it must match the oracle's exactly 355 bool hist_ok = true; 356 if (have_ref) hist_ok = std::memcmp(r.state.data() + kStateFloats, ref.hist.data(), (size_t) C * 3 * 4) == 0; 357 // verdict: finite, history exact, and not worse than max(floor, 3 x the incumbent's own error vs the oracle) 358 const char* verdict = "PASS"; 359 if (have_ref) { 360 const Cmp ir = vs_ref(inc, ref, T); 361 const double ys = std::max(2e-3, 3 * ir.y_nmax), ss = std::max(1e-4, 3 * ir.s_nmax); 362 if (cr.nonfinite || !hist_ok) verdict = "FAIL-nonfinite-or-history"; 363 else if (cr.y_nmax > ys) verdict = "FAIL-output-vs-oracle"; 364 else if (cr.s_nmax > ss) verdict = "FAIL-state-vs-oracle"; 365 else if (exact) verdict = "PASS-bitwise"; 366 } else if (exact) verdict = "PASS-bitwise"; 367 else verdict = "NO-ORACLE"; 368 if (!std::strncmp(verdict, "FAIL", 4)) ++fails; 369 double med = 0, mn = 0; 370 if (a.bench && !total_ms[p].empty()) { 371 med = median(total_ms[p]); 372 mn = *std::min_element(total_ms[p].begin(), total_ms[p].end()); 373 r.ms_gates = timed_last[p].ms_gates; r.ms_conv = timed_last[p].ms_conv; r.ms_rec = timed_last[p].ms_rec; 374 } 375 char tb[120] = ""; 376 if (a.bench) std::snprintf(tb, sizeof tb, "%.3f/%.3f/%.3f (tot med %.3f min %.3f)", r.ms_gates, r.ms_conv, r.ms_rec, med, mn); 377 std::printf("%-8s %-6s %-9s %9.2e %9.2e %9.2e %9.2e %-34s %s %s h=%08llx\n", name, "yes", exact ? "identical" : "differs", cr.y_nmax, cr.s_nmax, 378 ci.y_nmax, ci.s_nmax, tb, join(r.logged).c_str(), verdict, 379 (unsigned long long) (fnv1a(r.y16.data(), r.y16.size() * 2) & 0xffffffffULL)); 380 if (r.fallback_calls) std::printf(" (%d call(s) ran on the incumbent: the forced path could not take them)\n", r.fallback_calls); 381 json_line(a, "case", fname, T, r, have_ref ? &cr : nullptr, &ci, exact, med, mn, verdict, pr); 382 } 383 release(d); 384 return fails; 385} 386 387} // namespace 388 389int main(int argc, char** argv) { 390 Args a; 391 bool paths_given = false; 392 for (int i = 1; i < argc; ++i) { 393 std::string k = argv[i]; 394 auto val = [&]() -> const char* { if (i + 1 >= argc) { std::fprintf(stderr, "%s needs a value\n", k.c_str()); std::exit(2); } return argv[++i]; }; 395 if (k == "--T") { a.Ts = parse_list(val()); } 396 else if (k == "--chunk") a.chunk = parse_list(val())[0]; 397 else if (k == "--cuts") a.cuts = parse_list(val()); 398 else if (k == "--paths") { 399 paths_given = true; 400 std::string s = val(); 401 for (size_t p = 0; p <= s.size();) { 402 size_t e = s.find(',', p); 403 if (e == std::string::npos) e = s.size(); 404 const int id = path_from_name(s.substr(p, e - p)); 405 if (id < 0) { std::fprintf(stderr, "unknown path %s (auto,keyhead,pipe,cols,chunked,tc,tcs)\n", s.substr(p, e - p).c_str()); return 2; } 406 a.paths.push_back(id); 407 p = e + 1; 408 } 409 } 410 else if (k == "--incumbent") a.incumbent = path_from_name(val()); 411 else if (k == "--parity") a.parity = true; 412 else if (k == "--no-parity") a.parity = false; 413 else if (k == "--bench") a.bench = true; 414 else if (k == "--no-ref") a.ref = false; 415 else if (k == "--ref-heads") { a.ref_heads.clear(); for (auto x : parse_list(val())) a.ref_heads.push_back((int) x); } 416 else if (k == "--reps") a.reps = std::atoi(val()); 417 else if (k == "--warmup") a.warmup = std::atoi(val()); 418 else if (k == "--any-sms") a.any_sms = true; 419 else if (k == "--gsb") a.gsb = std::atoi(val()); 420 else if (k == "--tiles") a.tiles = std::atoi(val()); 421 else if (k == "--fallback-incumbent") a.fallback_incumbent = true; 422 else if (k == "--ld16") a.ld16 = parse_list(val())[0]; 423 else if (k == "--state") a.fx.state = argv[++i]; 424 else if (k == "--v-scale") a.fx.v_scale = (float) std::atof(val()); 425 else if (k == "--gate-scale") a.fx.gate_scale = (float) std::atof(val()); 426 else if (k == "--coherent-keys") a.fx.coherent_keys = true; 427 else if (k == "--alt-beta") a.fx.alt_beta = true; 428 else if (k == "--tiny-k") a.fx.tiny_k = true; 429 else if (k == "--stress") a.stress = true; 430 else if (k == "--seed") a.fx.seed = (uint64_t) std::atoll(val()); 431 else if (k == "--json") a.json = val(); 432 else if (k == "--label") a.label = val(); 433 else { 434 std::fprintf(stderr, "unknown option %s (see Desktop\\30thOctober\\results\\gdn\\HARNESS.md)\n", k.c_str()); 435 return 2; 436 } 437 } 438 if (a.Ts.empty()) a.Ts = {a.T}; 439 if (!paths_given) a.paths = {sp::kGdnAuto, sp::kGdnKeyHead, sp::kGdnPipe, sp::kGdnChunked, sp::kGdnTc, sp::kGdnTcSplit}; 440 if (a.incumbent < 0) { std::fprintf(stderr, "bad --incumbent\n"); return 2; } 441 int dev = 0; 442 ck(cudaGetDevice(&dev), "device"); 443 cudaDeviceProp pr{}; 444 ck(cudaGetDeviceProperties(&pr, dev), "props"); 445 int drv = 0, rt = 0; 446 cudaDriverGetVersion(&drv); 447 cudaRuntimeGetVersion(&rt); 448 std::printf("gdn_harness sha=%s device=%s sms=%d cc=%d.%d driver=%d runtime=%d smem_optin=%zu\n", GDN_HARNESS_SHA, pr.name, 449 pr.multiProcessorCount, pr.major, pr.minor, drv, rt, (size_t) pr.sharedMemPerBlockOptin); 450 for (const char* e : {"STRATA_GDN_CHUNKED", "STRATA_GDN_TC", "STRATA_GDN_KEYHEAD", "STRATA_GDN_PIPELINE", "STRATA_GDN_REC_WARP", 451 "STRATA_GDN_CONVL2", "STRATA_GDN_CONV_SERIAL", "STRATA_GDN_REC_HEADS", "STRATA_PF_PAD"}) 452 if (const char* v = std::getenv(e)) std::printf("env %s=%s\n", e, v); 453 int fails = 0; 454 for (int64_t T : a.Ts) { 455 FixtureSpec s = a.fx; 456 s.T = T; 457 fails += run_case(a, s, "default", pr); 458 if (a.stress) { 459 struct { const char* n; const char* st; float v, g; bool coh, alt, tiny; } cases[] = { 460 {"state-zero", "zero", 1, 1, false, false, false}, {"state-big", "big", 1, 1, false, false, false}, 461 {"state-small", "small", 1, 1, false, false, false}, {"v-x50", "random", 50, 1, false, false, false}, 462 {"slow-gates", "random", 1, 0.005f, false, false, false}, {"fast-gates", "random", 1, 3, false, false, false}, 463 {"coherent-keys", "random", 1, 1, true, false, false}, {"beta-endpoints", "random", 1, 1, false, true, false}, 464 {"tiny-keys", "random", 1, 1, false, false, true}}; 465 for (auto& c : cases) { 466 FixtureSpec t = a.fx; 467 t.T = T; t.state = c.st; t.v_scale = c.v; t.gate_scale = c.g; t.coherent_keys = c.coh; t.alt_beta = c.alt; t.tiny_k = c.tiny; 468 fails += run_case(a, t, c.n, pr); 469 } 470 } 471 } 472 std::printf("\n%s: %d failed verdict(s)\n", fails ? "FAIL" : "OK", fails); 473 return fails ? 1 : 0; 474}