okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

bsorensen110tests: the tuning-header gate's test builds on Windows, and RDNA1/RDNA2 stays rejected (#695)fd98b2384

main
5.1 KiB107 linesraw
1// TuningTable::load header gate, synthetic tables: no model, no GPU.  gfx1200 and gfx1201 are the same RDNA4
2// (gfx12) family and share hipBLASLt solution IDs, so a table calibrated on one must load on the other: a card
3// reporting the sibling architecture - an R9700 under HSA_OVERRIDE_GFX_VERSION=12.0.0 reports gfx1200 - otherwise
4// rejects its own calibration and loses the tuned prefill route entirely.  The per-solution runtime gate
5// (getAlgosFromIndex + matmulIsAlgoSupported, hipBLASEx fallback) is what keeps a wrong solution ID from running,
6// so the header gate can be family-wide over the SIBLING SETS the gate names: RDNA4 (gfx1200/gfx1201) and RDNA3
7// (gfx1100/gfx1101/gfx1102).  Every other pair stays rejected, including architectures that merely share a
8// prefix - gfx1010 (RDNA1) and gfx1030 (RDNA2) are not siblings and must not pass a table to each other.
9#include "hipblaslt_tuning.hpp"
10
11#include <chrono>
12#include <cstdio>
13#include <filesystem>
14#include <fstream>
15#include <string>
16
17namespace fs = std::filesystem;
18
19using strata::prefill::hipblaslt::TuningTable;
20
21namespace {
22
23// A portable scratch directory.  This test is host-only but builds on Windows/MSVC too, so it cannot use
24// <unistd.h>/getpid() or a hard-coded /tmp: std::filesystem::temp_directory_path plus a steady-clock token is
25// the shape tests/core/gguf_split_test.cpp uses.
26struct TempDir {
27    fs::path path;
28    TempDir() {
29        path = fs::temp_directory_path() /
30               ("strata-tuning-header-" +
31                std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()));
32        fs::create_directories(path);
33    }
34    ~TempDir() {
35        std::error_code ignored;
36        fs::remove_all(path, ignored);
37    }
38};
39
40bool load(const fs::path& dir, const std::string& file_arch, int file_version, const std::string& runtime_arch,
41          int runtime_version, std::string& err, size_t& rows) {
42    const fs::path path = dir / ("case-" + file_arch + "-" + std::to_string(file_version) + "-" + runtime_arch +
43                                 "-" + std::to_string(runtime_version) + ".txt");
44    {
45        std::ofstream out(path);
46        out << "# solution IDs are scoped to this hipBLASLt version and device architecture\n"
47            << "STRATA_HIPBLASLT_TUNING_V1 " << file_arch << " " << file_version << "\n"
48            << "bf16 1 2560 1 4096 110508\n"
49            << "bf16 2560 320 2560 8192 135699\n";
50        if (!out) {   // otherwise a write failure reads as a gate rejection and the case "passes" for the wrong reason
51            err = "cannot write the synthetic table at " + path.string();
52            rows = 0;
53            return false;
54        }
55    }
56    TuningTable table;
57    const bool ok = table.load(path.string(), runtime_arch, runtime_version, err);
58    rows = table.rows().size();
59    std::error_code ignored;
60    fs::remove(path, ignored);
61    return ok;
62}
63
64struct Expect {
65    const char* file_arch;
66    int file_version;
67    const char* runtime_arch;
68    int runtime_version;
69    bool accept;
70    const char* why;
71};
72
73}  // namespace
74
75int main() {
76    TempDir dir;
77    const Expect cases[] = {
78        {"gfx1201", 100500, "gfx1201", 100500, true, "exact match"},
79        {"gfx1200", 100500, "gfx1200", 100500, true, "exact match"},
80        {"gfx1201", 100500, "gfx1200", 100500, true, "RDNA4 sibling: gfx1201 table on a card reporting gfx1200"},
81        {"gfx1200", 100500, "gfx1201", 100500, true, "RDNA4 sibling, symmetric direction"},
82        {"gfx1201", 100202, "gfx1201", 100500, false, "the version gate rejects on its own"},
83        {"gfx1200", 100202, "gfx1201", 100500, false, "cross-family and wrong version"},
84        {"gfx1100", 100202, "gfx1201", 100202, false, "RDNA3 table on RDNA4"},
85        {"gfx1201", 100202, "gfx1100", 100202, false, "RDNA4 table on RDNA3"},
86        {"gfx1100", 100202, "gfx1101", 100202, true, "RDNA3 siblings share the family rule"},
87        {"gfx1102", 100202, "gfx1101", 100202, true, "RDNA3 siblings, the third member of the set"},
88        {"gfx1030", 100202, "gfx1201", 100202, false, "RDNA2 table on RDNA4"},
89        // The pair a five-character prefix match would wrongly group: both are "gfx10", neither is a sibling.
90        {"gfx1010", 100202, "gfx1030", 100202, false, "RDNA1 table on RDNA2: a shared prefix is not a family"},
91        {"gfx1030", 100202, "gfx1010", 100202, false, "RDNA2 table on RDNA1, symmetric direction"},
92    };
93    int failures = 0;
94    for (const auto& c : cases) {
95        std::string err;
96        size_t rows = 0;
97        const bool ok = load(dir.path, c.file_arch, c.file_version, c.runtime_arch, c.runtime_version, err, rows);
98        const bool good = ok == c.accept && (!ok || rows == 2);
99        if (!good) ++failures;
100        std::printf("%s %s/%d vs %s/%d rows=%zu  %s\n", good ? "ok  " : "FAIL", c.file_arch, c.file_version,
101                    c.runtime_arch, c.runtime_version, rows, c.why);
102        if (!ok) std::printf("      err: %s\n", err.c_str());
103    }
104    const int total = int(sizeof(cases) / sizeof(cases[0]));
105    std::printf("tuning_header_arch_family_test: %d cases, %d failures\n", total, failures);
106    return failures == 0 ? 0 : 1;
107}