okami.mom/strata

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

Niko1221Trial2 merge f-0291-pr-nv2 (64bf69080)2716defb8

main
2.9 KiB68 linesraw
1// The window limits (include/strata/kernels/window_limits.hpp) and the pipelined-window probe
2// (include/strata/program/pipe_probe.hpp): CPU only, header-only.
3#include "strata/kernels/cpu/expert.hpp"
4#include "strata/kernels/fused_gr.hpp"
5#include "strata/kernels/verify_kernels.hpp"
6#include "strata/program/pipe_probe.hpp"
7
8#include <cstdio>
9#include <cstdlib>
10
11namespace {
12#if defined(_WIN32)
13void setenv(const char* k, const char* v, int) { _putenv_s(k, v); }   // MSVC has _putenv_s only; an empty value unsets it
14void unsetenv(const char* k) { _putenv_s(k, ""); }
15#endif
16int checks = 0;
17void check(bool ok, const char* label) {
18    ++checks;
19    if (!ok) { std::fprintf(stderr, "FAIL: %s\n", label); std::exit(1); }
20}
21}  // namespace
22
23int main() {
24    using namespace strata::kernels;
25    check(kVerifyNarrowT == 8, "the narrow window is the 0.2.7 one: 8 rows");
26    check(kWindowMaxT == 8 || kWindowMaxT == 12 || kWindowMaxT == 16, "a window holds 8, 12 or 16 rows");
27    check(kVerifyMaxT == kWindowMaxT, "kVerifyMaxT is the window limit");
28    check(kVerifyMaxT >= kVerifyNarrowT, "the wide window is not narrower than the narrow one");
29    check(cpu::MAXT == 8, "the CPU kernels' tokens per job stay 8 (a wider window is split into jobs)");
30    check(kFusedGrMaxT == 8, "the hyper-connection kernels are built for 8 tokens (a wider window is read in slices)");
31    check(kFusedGrWideT == kWindowMaxT, "the caller's token arrays follow the window");
32    check(kVerifyMaxT * 10 <= 256, "the resident plan's block holds a full window of 10 routed experts a row");
33
34    // the probe: off without the environment (no clock read), and a full cycle of events does not fail when it is on
35    unsetenv("STRATA_P4_TIMING");
36    unsetenv("STRATA_P4_TRACE");
37    {
38        strata::program::PipeProbe off(4, 4);
39        check(!off.on() && !off.timing(), "the probe is off by default");
40        check(off.now() == strata::program::PipeProbe::Time{}, "an off probe reads no clock");
41        { strata::program::PipeProbe::PumpScope s(off); }
42        off.launched(0, 1, off.now());
43        off.done(0, 1);
44        off.flush();
45    }
46    setenv("STRATA_P4_TIMING", "1", 1);
47    {
48        strata::program::PipeProbe on(4, 4);
49        check(on.timing(), "STRATA_P4_TIMING turns the timing on");
50        on.span_start(on.now());
51        for (int w = 0; w < 3; ++w)
52            for (int k = 0; k < 4; ++k) {
53                strata::program::PipeProbe::PumpScope s(on);
54                on.busy(2, 3);
55                on.free_stage(1, k % 2 == 0);
56                const auto before = on.now();
57                on.launched(k, w, before);
58                on.polled(before);
59                on.done(k, w);
60                strata::program::PipeProbe::VerdictScope v(on);
61            }
62        on.span_end(10.0);
63        on.flush();
64    }
65    unsetenv("STRATA_P4_TIMING");
66    std::printf("window_limits_test: %d checks passed (window %d rows)\n", checks, (int) kVerifyMaxT);
67    return 0;
68}