gfx12: matrix-core QSA scorer (STRATA_SELECT_WMMA) past 28,672 tokens by default (changes the answers there; separate, droppable commit)

Needs the owner's yes: the existing opt-in STRATA_SELECT_WMMA=1 with STRATA_SELECT_ALT_MIN_TOKENS=28672 becomes the gfx12 default in
gfx12_extra.hpp, with its own log line.  A chunk whose context is below the floor keeps the warp kernel, so a prompt that stays under about
28K tokens is bit-identical (first-token KL 0.00000 on twelve 8K-24K prompts).  Off: STRATA_SELECT_WMMA=0, STRATA_GFX12_DEFAULTS=0 or
STRATA_DEFAULTS=026; a variable the user sets is kept.  Chosen over PR 3073's simt2 (author Vop3p) on the data.
R9700 (p620, IQ3_S, serve, interleaved pairs, prompt tok/s against unset, 3 pairs): 32K +1.83% (3/3), 98K +5.74% (3/3); first-token KL on seven
30K-96K prompts mean 0.0018, max 0.0055, top-1 7/7; needle recall 25/25 (8K to 96K, 5 depths).  Without a floor: 24K +3.34%, 32K +4.5..6.0%,
98K +6.9..7.3% but values change from 8K up (KL 0.0056); simt2 is slower below 32K.  arch_defaults_test now clears the variables this
default sets before its integrated-GPU checks; gfx12_extra_test covers the default and its off switches.
This commit is contained in:
Niko1221 committed 2026-11-01 04:50:11 +01:00
1 parent 82eaeb4221
commit c31f1fa31b
4 files changed
+59

No files matched your search

+27
View File
@@ -7,6 +7,18 @@
// instead of one gr_read per token (#3264, bsorensen110). R9700 (p620, IQ3_S, serve, static residency,
// 8 interleaved pairs, A/A beside it): json_extract +0.82% (6/8 pairs), agent +0.63% (6/8), code_py -0.96%
// (3/8; that prompt's A/A moves +-3.5% a pair), greedy ids identical in 16/16 and 15/16 request sets.
//
// Changes the answers (needs the owner's yes; this is the separate, droppable commit):
// STRATA_SELECT_WMMA=1 + STRATA_SELECT_ALT_MIN_TOKENS=28672 the gfx12 matrix-core QSA block scorer (already in the engine as an opt-in) for
// chunks whose context so far is 28,672 tokens or more; a read that stays below that is bit-identical to the warp
// kernel (first-token KL 0.00000 on twelve 8K-24K prompts). R9700 (p620, IQ3_S, serve, interleaved pairs, prompt
// tok/s vs unset, 3 pairs): 32K +1.83% (3/3), 98K +5.74% (3/3, steady). First-token KL against unset on seven 30K-96K
// prompts: mean 0.0018, max 0.0055, top-1 7/7; needle recall 25/25 at 8K..96K x 5 depths. Without the floor (STRATA_SELECT_WMMA=1
// alone, 4 pairs): 4K +0.34%, 8K +0.94%, 16K +1.73%, 24K +3.34%, 32K +4.5..6.0%, 98K +6.9..7.3%, but the values change from 8K
// up (KL mean 0.0056, max 0.0193, top-1 11/12 at 8K-24K); a floor of 16,384 was no better (32K -0.27%, noisy). The floor is
// the owner's trade between "ordinary prompts keep their exact answers" and a few percent more at 32K.
// Chosen over PR 3073's simt2 (author Vop3p), which is slower below 32K, has KL 0.0029 / 0.0095 and yields to WMMA on gfx12.
// Off: STRATA_SELECT_WMMA=0, STRATA_GFX12_DEFAULTS=0, STRATA_DEFAULTS=026.
#pragma once
#include <cstdlib>
@@ -33,4 +45,19 @@ inline std::vector<std::pair<std::string, std::string>> gfx12_exact_extra_env(co
return gfx12_exact_extra_env(gcn_arch, strata::qwen_defaults_026());
}
/// The value-changing defaults of gfx12 (see above). `defaults026`: STRATA_DEFAULTS=026.
inline std::vector<std::pair<std::string, std::string>> gfx12_value_changing_env(const char* gcn_arch, bool defaults026) {
std::vector<std::pair<std::string, std::string>> t;
if (!strata::kernels::gfx_arch_is_gfx12(gcn_arch)) return t;
const char* off = std::getenv("STRATA_GFX12_DEFAULTS");
if (off != nullptr && off[0] == '0') return t;
if (defaults026) return t;
t.push_back({"STRATA_SELECT_WMMA", "1"});
t.push_back({"STRATA_SELECT_ALT_MIN_TOKENS", "28672"});
return t;
}
inline std::vector<std::pair<std::string, std::string>> gfx12_value_changing_env(const char* gcn_arch) {
return gfx12_value_changing_env(gcn_arch, strata::qwen_defaults_026());
}
} // namespace strata::core
+12
View File
@@ -222,6 +222,18 @@ std::vector<std::string> apply_arch_defaults(const char* gcn_arch, bool integrat
std::fprintf(stderr, "\n");
}
}
{ // gfx12 defaults that change the answers (gfx12_extra.hpp): the matrix-core QSA scorer from 28,672 tokens; its own line
const auto vc = gfx12_value_changing_env(gcn_arch);
bool any = false;
for (const auto& kv : vc) {
if (std::getenv(kv.first.c_str()) != nullptr) continue;
set_default(kv);
any = true;
}
if (any)
std::fprintf(stderr, "strata: gfx12 (RDNA4): the matrix-core QSA block scorer is on once a prompt is past 28,672 tokens (+5.7%% prompt speed at 98K on an R9700, shorter prompts unchanged; "
"the first-token KL against the warp kernel is 0.002 on average above 30K; STRATA_SELECT_WMMA=0 or STRATA_GFX12_DEFAULTS=0 turns it off)\n");
}
if (!set.empty()) {
const bool g12 = strata::kernels::gfx_arch_is_gfx12(gcn_arch);
std::fprintf(stderr, "strata: %s: %zu exact speed switches on by default (%s=0 turns "
+1
View File
@@ -276,6 +276,7 @@ int main() {
CHECK(std::string(std::getenv("STRATA_SMALL_UNR")) == "3" && std::string(std::getenv("STRATA_GR_Q32_G")) == "2" &&
std::string(std::getenv("STRATA_GR_Q8_PFS")) == "1");
CHECK(apply_arch_defaults("gfx1201", false).empty());
unset("STRATA_SELECT_WMMA"); unset("STRATA_SELECT_ALT_MIN_TOKENS"); unset("STRATA_HEAD_MIX_MULTI"); // gfx12_extra.hpp's defaults (own test: gfx12_extra_test)
CHECK(apply_arch_defaults("gfx1103", false).empty()); // integrated == false: a mixed box (iGPU + dGPU) keeps the old defaults
for (const char* k : five) CHECK(std::getenv(k) == nullptr);
put("STRATA_HC_UPMIX", "0");
+19
View File
@@ -56,6 +56,25 @@ int main() {
put("STRATA_GFX12_DEFAULTS", "0");
apply_arch_defaults("gfx1201", false);
CHECK(std::getenv("STRATA_HEAD_MIX_MULTI") == nullptr);
// the value-changing default (separate commit): gfx12 only, the same off switches, and the user's own setting wins
unset("STRATA_GFX12_DEFAULTS"); unset("STRATA_SELECT_WMMA"); unset("STRATA_SELECT_ALT_MIN_TOKENS");
CHECK(has(gfx12_value_changing_env("gfx1201", false), "STRATA_SELECT_WMMA", "1"));
CHECK(has(gfx12_value_changing_env("gfx1201", false), "STRATA_SELECT_ALT_MIN_TOKENS", "28672"));
CHECK(gfx12_value_changing_env("gfx1201", true).empty());
for (const char* other : {"gfx1100", "gfx1151", "gfx1030", "gfx906", "", "gfx12010"}) CHECK(gfx12_value_changing_env(other, false).empty());
apply_arch_defaults("gfx1201", false);
CHECK(std::getenv("STRATA_SELECT_WMMA") != nullptr && std::string(std::getenv("STRATA_SELECT_WMMA")) == "1");
CHECK(std::getenv("STRATA_SELECT_ALT_MIN_TOKENS") != nullptr && std::string(std::getenv("STRATA_SELECT_ALT_MIN_TOKENS")) == "28672");
unset("STRATA_SELECT_WMMA"); unset("STRATA_SELECT_ALT_MIN_TOKENS");
put("STRATA_SELECT_WMMA", "0"); // the off switch
apply_arch_defaults("gfx1201", false);
CHECK(std::string(std::getenv("STRATA_SELECT_WMMA")) == "0");
unset("STRATA_SELECT_WMMA"); unset("STRATA_SELECT_ALT_MIN_TOKENS");
apply_arch_defaults("gfx1100", false);
CHECK(std::getenv("STRATA_SELECT_WMMA") == nullptr);
put("STRATA_GFX12_DEFAULTS", "0");
apply_arch_defaults("gfx1201", false);
CHECK(std::getenv("STRATA_SELECT_WMMA") == nullptr && std::getenv("STRATA_SELECT_ALT_MIN_TOKENS") == nullptr);
if (fails == 0) std::printf("gfx12_extra_test: OK\n");
return fails == 0 ? 0 : 1;
}