okami.mom/strata

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

bitaccesscomauExact two-pass QSA prompt selection (opt-in STRATA_SELECT_TWO_PASS=1)386f9959f

main
3.5 KiB80 linesraw
1// STRATA_SELECT_TWO_PASS's request and its line where the two-pass scorer cannot run (qsa_two_pass_status.hpp).
2// GPU-free: the parse, quiet when unset or supported, one line per process where unsupported.
3#include "strata/kernels/qsa_two_pass_status.hpp"
4
5#include <cstdio>
6#include <cstdlib>
7#include <string>
8
9namespace tp = strata::kernels::two_pass;
10
11static void check(bool ok, const char* why) {
12    if (!ok) {
13        std::fprintf(stderr, "FAIL: %s\n", why);
14        std::exit(1);
15    }
16}
17
18static std::string output(FILE* log) {
19    check(std::fflush(log) == 0 && std::fseek(log, 0, SEEK_SET) == 0, "rewind the log");
20    std::string text;
21    char buf[512];
22    while (const size_t n = std::fread(buf, 1, sizeof(buf), log)) text.append(buf, n);
23    check(!std::ferror(log), "read the log");
24    return text;
25}
26
27static std::string line(const char* where) {
28    return std::string("strata: STRATA_SELECT_TWO_PASS=1 is not used on ") + where +
29           ": the two-pass scorer runs only in the CUDA prompt path's tensor-core selection (sm_80+); the selection is "
30           "unchanged\n";
31}
32
33int main(int argc, char** argv) {
34    check(argc == 2, "pass a scratch log path (no GPU or model needed)");
35    FILE* log = std::fopen(argv[1], "w+");
36    check(log != nullptr, "open the log");
37
38    // exactly "1" is on, as the scorer parsed it before; unset or anything else is off and prints nothing anywhere
39    check(tp::requested_from("1"), "1: on");
40    const char* off[] = {nullptr, "", "0", "01", "1x", "true", "1 ", "2"};
41    for (const char* flag : off) {
42        check(!tp::requested_from(flag), "not exactly 1: off");
43        tp::RequestStatus status(flag);
44        check(!status.requested(), "not requested");
45        check(!status.on("HIP", log), "off stays off where unsupported");
46        check(!status.on(nullptr, log), "off stays off where supported");
47    }
48    check(output(log).empty(), "no line without the switch");
49
50    // a supported path returns the request and prints nothing (the engine's per-segment line reports what ran)
51    tp::RequestStatus cuda("1");
52    check(cuda.on(nullptr, log) && cuda.on(nullptr, log), "supported: on");
53    check(output(log).empty(), "supported: no line");
54
55    // each unsupported path the engine names: off, one line, never repeated
56    const char* where[] = {"HIP", "Metal", "SYCL", "this CUDA card or with STRATA_QSA_WARP",
57                           "the layer-major prompt path"};
58    std::string expected;
59    for (const char* w : where) {
60        tp::RequestStatus status("1");
61        check(!status.on(w, log), "unsupported: off");
62        expected += line(w);
63        check(output(log) == expected, "unsupported: one line naming the path");
64        check(!status.on(w, log) && !status.on(w, log), "unsupported again: off");
65        check(output(log) == expected, "unsupported: the line is printed once");
66    }
67
68    // a layer split can mix cards: a supported query neither uses up the line nor is turned off by an unsupported one
69    tp::RequestStatus mixed("1");
70    check(mixed.on(nullptr, log), "supported card first");
71    check(!mixed.on("this CUDA card or with STRATA_QSA_WARP", log), "then an unsupported card");
72    check(mixed.on(nullptr, log), "the supported card stays on");
73    expected += line("this CUDA card or with STRATA_QSA_WARP");
74    check(output(log) == expected, "the unsupported card's line once");
75
76    check(std::fclose(log) == 0, "close the log");
77    check(std::remove(argv[1]) == 0, "remove the log");
78    std::puts("qsa_two_pass_status_test: OK");
79    return 0;
80}