okami.mom/strata

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

Niko1221Merge f-0211-r9700one into f-0211-int2613b4de5

main
6.1 KiB114 linesraw
1// src/core/gfx12_extra_test.cpp - the gfx12 extra defaults (gfx12_extra.hpp) and their off switches (no GPU needed).
2#include "strata/core/arch_defaults.hpp"
3#include "strata/core/gfx12_chunk.hpp"
4#include "strata/core/gfx12_extra.hpp"
5
6#include <cstdio>
7#include <cstdlib>
8#include <string>
9
10static int fails = 0;
11#define CHECK(c) do { if (!(c)) { std::printf("FAIL line %d: %s\n", __LINE__, #c); ++fails; } } while (0)
12static void unset(const char* k) {
13#if defined(_WIN32)
14    _putenv_s(k, "");
15#else
16    unsetenv(k);
17#endif
18}
19static void put(const char* k, const char* v) {
20#if defined(_WIN32)
21    _putenv_s(k, v);
22#else
23    setenv(k, v, 1);
24#endif
25}
26static bool has(const std::vector<std::pair<std::string, std::string>>& t, const char* k, const char* v) {
27    for (const auto& kv : t) if (kv.first == k && kv.second == v) return true;
28    return false;
29}
30
31int main() {
32    using namespace strata::core;
33    unset("STRATA_GFX12_DEFAULTS");
34    unset("STRATA_DEFAULTS");
35    unset("STRATA_HEAD_MIX_MULTI");
36    // the exact extra: gfx12 only
37    CHECK(has(gfx12_exact_extra_env("gfx1201"), "STRATA_HEAD_MIX_MULTI", "1"));
38    CHECK(has(gfx12_exact_extra_env("gfx1200:xnack-"), "STRATA_HEAD_MIX_MULTI", "1"));
39    for (const char* other : {"gfx1100", "gfx1151", "gfx1030", "gfx906", "gfx1010", "", "gfx12010"}) CHECK(gfx12_exact_extra_env(other).empty());
40    CHECK(gfx12_exact_extra_env(nullptr).empty());
41    // the off switches
42    put("STRATA_GFX12_DEFAULTS", "0");
43    CHECK(gfx12_exact_extra_env("gfx1201").empty());
44    unset("STRATA_GFX12_DEFAULTS");
45    CHECK(gfx12_exact_extra_env("gfx1201", true).empty());     // STRATA_DEFAULTS=026
46    CHECK(!gfx12_exact_extra_env("gfx1201", false).empty());
47    // apply: sets it, keeps a value the user set, does nothing off gfx12 or with the switch off
48    apply_arch_defaults("gfx1201", false);
49    CHECK(std::getenv("STRATA_HEAD_MIX_MULTI") != nullptr && std::string(std::getenv("STRATA_HEAD_MIX_MULTI")) == "1");
50    unset("STRATA_HEAD_MIX_MULTI");
51    put("STRATA_HEAD_MIX_MULTI", "0");
52    apply_arch_defaults("gfx1201", false);
53    CHECK(std::string(std::getenv("STRATA_HEAD_MIX_MULTI")) == "0");
54    unset("STRATA_HEAD_MIX_MULTI");
55    apply_arch_defaults("gfx1100", false);
56    CHECK(std::getenv("STRATA_HEAD_MIX_MULTI") == nullptr);
57    put("STRATA_GFX12_DEFAULTS", "0");
58    apply_arch_defaults("gfx1201", false);
59    CHECK(std::getenv("STRATA_HEAD_MIX_MULTI") == nullptr);
60    // the value-changing default (separate commit): gfx12 only, the same off switches, and the user's own setting wins
61    unset("STRATA_GFX12_DEFAULTS"); unset("STRATA_SELECT_WMMA"); unset("STRATA_SELECT_ALT_MIN_TOKENS");
62    CHECK(has(gfx12_value_changing_env("gfx1201", false), "STRATA_SELECT_WMMA", "1"));
63    CHECK(has(gfx12_value_changing_env("gfx1201", false), "STRATA_SELECT_ALT_MIN_TOKENS", "28672"));
64    CHECK(gfx12_value_changing_env("gfx1201", true).empty());
65    for (const char* other : {"gfx1100", "gfx1151", "gfx1030", "gfx906", "", "gfx12010"}) CHECK(gfx12_value_changing_env(other, false).empty());
66    apply_arch_defaults("gfx1201", false);
67    CHECK(std::getenv("STRATA_SELECT_WMMA") != nullptr && std::string(std::getenv("STRATA_SELECT_WMMA")) == "1");
68    CHECK(std::getenv("STRATA_SELECT_ALT_MIN_TOKENS") != nullptr && std::string(std::getenv("STRATA_SELECT_ALT_MIN_TOKENS")) == "28672");
69    unset("STRATA_SELECT_WMMA"); unset("STRATA_SELECT_ALT_MIN_TOKENS");
70    put("STRATA_SELECT_WMMA", "0");   // the off switch
71    apply_arch_defaults("gfx1201", false);
72    CHECK(std::string(std::getenv("STRATA_SELECT_WMMA")) == "0");
73    unset("STRATA_SELECT_WMMA"); unset("STRATA_SELECT_ALT_MIN_TOKENS");
74    apply_arch_defaults("gfx1100", false);
75    CHECK(std::getenv("STRATA_SELECT_WMMA") == nullptr);
76    // STRATA_MMQ_KQ (the K-quant experts' prompt products on MMQ): Linux gfx12 only, the same off switches, the user's own value wins
77    unset("STRATA_GFX12_DEFAULTS"); unset("STRATA_DEFAULTS"); unset("STRATA_MMQ_KQ");
78#if defined(_WIN32)
79    CHECK(!has(gfx12_value_changing_env("gfx1201", false), "STRATA_MMQ_KQ", "1"));
80#else
81    CHECK(has(gfx12_value_changing_env("gfx1201", false), "STRATA_MMQ_KQ", "1"));
82    CHECK(has(gfx12_value_changing_env("gfx1200:xnack-", false), "STRATA_MMQ_KQ", "1"));
83    for (const char* other : {"gfx1100", "gfx1151", "gfx1030", "gfx906", "", "gfx12010"}) CHECK(!has(gfx12_value_changing_env(other, false), "STRATA_MMQ_KQ", "1"));
84    CHECK(!has(gfx12_value_changing_env("gfx1201", true), "STRATA_MMQ_KQ", "1"));     // STRATA_DEFAULTS=026
85    apply_arch_defaults("gfx1201", false);
86    CHECK(std::getenv("STRATA_MMQ_KQ") != nullptr && std::string(std::getenv("STRATA_MMQ_KQ")) == "1");
87    unset("STRATA_MMQ_KQ"); unset("STRATA_SELECT_WMMA"); unset("STRATA_SELECT_ALT_MIN_TOKENS");
88    put("STRATA_MMQ_KQ", "0");                                                           // the off switch
89    apply_arch_defaults("gfx1201", false);
90    CHECK(std::string(std::getenv("STRATA_MMQ_KQ")) == "0");
91    unset("STRATA_MMQ_KQ"); unset("STRATA_SELECT_WMMA"); unset("STRATA_SELECT_ALT_MIN_TOKENS");
92    apply_arch_defaults("gfx1100", false);
93    CHECK(std::getenv("STRATA_MMQ_KQ") == nullptr);
94    put("STRATA_GFX12_DEFAULTS", "0");
95    apply_arch_defaults("gfx1201", false);
96    CHECK(std::getenv("STRATA_MMQ_KQ") == nullptr);
97    unset("STRATA_GFX12_DEFAULTS");
98#endif
99    unset("STRATA_SELECT_WMMA"); unset("STRATA_SELECT_ALT_MIN_TOKENS");
100    put("STRATA_GFX12_DEFAULTS", "0");
101    apply_arch_defaults("gfx1201", false);
102    CHECK(std::getenv("STRATA_SELECT_WMMA") == nullptr && std::getenv("STRATA_SELECT_ALT_MIN_TOKENS") == nullptr);
103    // the gfx12 prompt-chunk ceiling of a bare --prefill auto (gfx12_chunk.hpp): 32768 by default, 16384 with STRATA_GFX12_CHUNK=16, none with =0,
104    // and the RAM guard steps 32768 -> 16384 -> 8192
105    CHECK(gfx12_chunk_ceiling(nullptr) == 32768);
106    CHECK(gfx12_chunk_ceiling("1") == 32768);
107    CHECK(gfx12_chunk_ceiling("16") == 16384);
108    CHECK(gfx12_chunk_ceiling("0") == 0);
109    CHECK(gfx12_chunk_step_down(32768) == 16384);
110    CHECK(gfx12_chunk_step_down(16384) == 8192);
111    CHECK(gfx12_chunk_step_down(12288) == 8192);
112    if (fails == 0) std::printf("gfx12_extra_test: OK\n");
113    return fails == 0 ? 0 : 1;
114}