okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
4786a2e7d
main
1// src/core/arch_defaults_test.cpp - the per-architecture default table (no GPU needed). 2#include "strata/core/arch_defaults.hpp" 3#include "strata/core/gfx12_platform_defaults.hpp" 4#include "strata/core/sm120_series.hpp" 5#include "strata/core/defaults_026.hpp" 6#include "strata/prefill/pf_fused_override.hpp" 7#include "strata/prefill/own_only_switches.hpp" 8#include "strata/core/spill_gate.hpp" 9 10#include <cstdio> 11#include <cstdlib> 12#include <cstring> 13#include <string> 14#include <vector> 15 16static int fails = 0 ; 17#define CHECK (c ) do { if (!(c)) { std::printf("FAIL line %d: %s\n", __LINE__, #c); ++fails; } } while (0) 18 19static void unset (const char * k ) { 20#if defined(_WIN32 ) 21_putenv_s (k ,"" ); 22#else 23unsetenv (k ); 24#endif 25} 26static void put (const char * k ,const char * v ) { 27#if defined(_WIN32 ) 28_putenv_s (k ,v ); 29#else 30setenv (k ,v ,1 ); 31#endif 32} 33 34int main () { 35using namespace strata::core ; 36unset ("STRATA_GFX1151_DEFAULTS" ); 37// 0.2.10: the parallel-request stack, Windows gfx1151 with 2 or more batch slots only 38unset ("STRATA_GFX1151_DEFAULTS" ); 39CHECK (parallel_default_env ("gfx1151" , true,4 ).size ()== 9 ); 40CHECK (parallel_default_env ("gfx1151:sramecc-:xnack-" , true,2 ).size ()== 9 ); 41CHECK (parallel_default_env ("gfx1151" , true,1 ).empty ()); 42CHECK (parallel_default_env ("gfx1151" , true,0 ).empty ()); 43CHECK (parallel_default_env ("gfx1151" , false,4 ).empty ());// Linux: the launcher sets its own stack 44CHECK (parallel_default_env ("gfx1201" , true,4 ).empty ()); 45CHECK (parallel_default_env ("" , true,4 ).empty ()); 46put ("STRATA_GFX1151_DEFAULTS" ,"0" ); 47CHECK (parallel_default_env ("gfx1151" , true,4 ).empty ()); 48unset ("STRATA_GFX1151_DEFAULTS" ); 49for (const auto & kv :parallel_default_env ("gfx1151" , true,4 ))CHECK (kv .first != "STRATA_BATCH_CONCURRENT_READ" ); 50// the same nine on Linux CUDA with 2 or more slots (was serve/server.py PARALLEL_STACK_ENV) 51CHECK (parallel_default_env_cuda (true,2 ).size ()== 9 ); 52CHECK (parallel_default_env_cuda (true,8 ).size ()== 9 ); 53CHECK (parallel_default_env_cuda (true,1 ).empty ()); 54CHECK (parallel_default_env_cuda (true,0 ).empty ()); 55CHECK (parallel_default_env_cuda (false,4 ).empty ());// HIP, Windows, Metal, SYCL builds 56for (const auto & kv :parallel_default_env_cuda (true,4 ))CHECK (kv .first != "STRATA_BATCH_CONCURRENT_READ" ); 57 { 58const auto cuda = parallel_default_env_cuda (true,4 ),gfx = parallel_default_env ("gfx1151" , true,4 ); 59CHECK (cuda == gfx );// one table for both 60unset ("STRATA_QSA_SLOTS" ); 61put ("STRATA_CKPT_POOL" ,"0" );// the user's =0 stays 62const auto set = apply_parallel_defaults_cuda (true,4 ); 63CHECK (set .size ()== 8 ); 64CHECK (std::getenv ("STRATA_CKPT_POOL" )!= nullptr && std::string (std::getenv ("STRATA_CKPT_POOL" ))== "0" ); 65CHECK (std::getenv ("STRATA_QSA_SLOTS" )!= nullptr && std::string (std::getenv ("STRATA_QSA_SLOTS" ))== "1" ); 66for (const auto & kv :cuda )unset (kv .first .c_str ()); 67CHECK (apply_parallel_defaults_cuda (true,1 ).empty ()); 68CHECK (std::getenv ("STRATA_QSA_SLOTS" )== nullptr ); 69 } 70// QUAL-GDN on Linux CUDA 71CHECK (gdn_default_env_cuda (true).size ()== 2 ); 72CHECK (gdn_default_env_cuda (false).empty ()); 73 { 74unset ("STRATA_GDN_TC" );put ("STRATA_GDN_CONVL2" ,"0" ); 75CHECK (apply_gdn_defaults_cuda (true).size ()== 1 ); 76CHECK (std::string (std::getenv ("STRATA_GDN_TC" ))== "1" && std::string (std::getenv ("STRATA_GDN_CONVL2" ))== "0" ); 77unset ("STRATA_GDN_TC" );unset ("STRATA_GDN_CONVL2" ); 78CHECK (apply_gdn_defaults_cuda (false).empty ()&& std::getenv ("STRATA_GDN_TC" )== nullptr ); 79 } 80// the chunked GDN scan: Linux, every card gfx12 81CHECK (gdn_chunked_default_env (true, true).size ()== 1 ); 82CHECK (gdn_chunked_default_env (true, false).empty ()); 83CHECK (gdn_chunked_default_env (false, true).empty ()); 84 { 85unset ("STRATA_GDN_CHUNKED" ); 86CHECK (apply_gdn_chunked_default (true, true).size ()== 1 && std::string (std::getenv ("STRATA_GDN_CHUNKED" ))== "1" ); 87put ("STRATA_GDN_CHUNKED" ,"0" ); 88CHECK (apply_gdn_chunked_default (true, true).empty ()&& std::string (std::getenv ("STRATA_GDN_CHUNKED" ))== "0" ); 89unset ("STRATA_GDN_CHUNKED" ); 90 } 91// 0.2.10 (STRIX-TDR): the helper-thread launch, Windows gfx1151 only 92unset ("STRATA_GFX1151_DEFAULTS" ); 93CHECK (launch_default_env ("gfx1151" , true).size ()== 1 && launch_default_env ("gfx1151" , true)[0 ].first == "STRATA_VERIFY_ASYNC_LAUNCH" ); 94CHECK (launch_default_env ("gfx1151:sramecc-:xnack-" , true).size ()== 1 ); 95CHECK (launch_default_env ("gfx1151" , false).empty ()); 96CHECK (launch_default_env ("gfx1201" , true).empty ()); 97CHECK (launch_default_env ("" , true).empty ()); 98put ("STRATA_GFX1151_DEFAULTS" ,"0" ); 99CHECK (launch_default_env ("gfx1151" , true).empty ()); 100unset ("STRATA_GFX1151_DEFAULTS" ); 101// other architectures (and CUDA, which passes an empty name): nothing 102CHECK (arch_default_env ("gfx1100" ).empty ()); 103CHECK (arch_default_env ("gfx1150" ).empty ()); 104CHECK (arch_default_env ("gfx1152" ).empty ()); 105CHECK (arch_default_env ("gfx11510" ).empty ());// not a prefix match 106CHECK (arch_default_env ("" ).empty ()); 107CHECK (arch_default_env (nullptr ).empty ()); 108// gfx1151, plain and with its feature suffix: the table, and no bit-changing switch in it 109for (const char * a : {"gfx1151" ,"gfx1151:sramecc-:xnack-" }) { 110const auto t = arch_default_env (a ); 111CHECK (t .size () >=10 ); 112for (const auto & kv :t ) { 113CHECK (kv .first .rfind ("STRATA_" ,0 )== 0 ); 114for (const char * bits : {"STRATA_PF_GEMM" ,"STRATA_PF_FUSED" ,"STRATA_HC_UPMIX" ,"STRATA_PA_FAST" ,"STRATA_HIP_WMMA" , 115"STRATA_SELECT_WMMA" ,"STRATA_HC_Q8" ,"STRATA_PF_HCDOWN" ,"STRATA_WMMA_GEMM" }) 116CHECK (kv .first != bits ); 117 } 118 } 119// 0.2.7: STRATA_SH_STREAM. Windows gfx1151 leaves the shared-expert fork off (it measured slower there, same ids); Linux gfx1151, 120// the 026 master switch and every other architecture are unchanged. Pure rule: the platform is an argument. 121 { 122auto find = [](const std::vector < std::pair < std::string , std::string >>& t ,const char * k )-> const std::string * { 123for (const auto & kv :t )if (kv .first == k )return & kv .second ; 124return static_cast < const std::string *> (nullptr ); 125 }; 126for (const char * a : {"gfx1151" ,"gfx1151:sramecc-:xnack-" }) { 127const auto lin = arch_default_env (a , false, false); 128const auto win = arch_default_env (a , false, true); 129const auto lin26 = arch_default_env (a , true, false); 130const auto win26 = arch_default_env (a , true, true); 131const std::string * l = find (lin ,"STRATA_SH_STREAM" ); 132CHECK (l != nullptr && * l == "1" );// Linux gfx1151: unchanged, the fork is on 133CHECK (find (win ,"STRATA_SH_STREAM" )== nullptr );// Windows gfx1151: not in the table, so the HIP default (off) applies 134CHECK (find (win26 ,"STRATA_SH_STREAM" )!= nullptr );// STRATA_DEFAULTS=026: v0.2.6's table on Windows too 135CHECK (find (lin26 ,"STRATA_SH_STREAM" )!= nullptr ); 136CHECK (win26 == lin26 && win26 == lin );// under 026 and on Linux the whole table is the same 137CHECK (win .size ()== lin .size ()+ 1 );// Windows loses SH_STREAM and gains the two round-0215 decode switches 138CHECK (find (win ,"STRATA_SMALL_UNR" )!= nullptr && * find (win ,"STRATA_SMALL_UNR" )== "3" && find (lin ,"STRATA_SMALL_UNR" )== nullptr ); 139CHECK (find (win ,"STRATA_GR_Q8_PFS" )!= nullptr && * find (win ,"STRATA_GR_Q8_PFS" )== "1" && find (lin ,"STRATA_GR_Q8_PFS" )== nullptr ); 140CHECK (find (win26 ,"STRATA_SMALL_UNR" )== nullptr && find (win26 ,"STRATA_GR_Q8_PFS" )== nullptr );// STRATA_DEFAULTS=026 keeps v0.2.6's table 141for (const auto & kv :win ) { 142if (kv .first == "STRATA_SMALL_UNR" || kv .first == "STRATA_GR_Q8_PFS" )continue ; 143CHECK (find (lin ,kv .first .c_str ())!= nullptr && * find (lin ,kv .first .c_str ())== kv .second ); 144 } 145 } 146// other architectures: the platform changes nothing 147for (const char * a : {"gfx1100" ,"gfx1030" ,"gfx1103" ,"gfx1150" ,"gfx1152" ,"gfx1201" ,"gfx1200" ,"" }) { 148CHECK (arch_default_env (a , false, true)== arch_default_env (a , false, false)); 149CHECK (arch_default_env (a , true, true)== arch_default_env (a , true, false)); 150 } 151CHECK (arch_default_env (nullptr , false, true).empty ()); 152// the build's own platform answers like the explicit form (the one-argument form reads STRATA_DEFAULTS, unset here) 153unset ("STRATA_DEFAULTS" ); 154#if defined(_WIN32 ) 155CHECK (arch_default_env ("gfx1151" )== arch_default_env ("gfx1151" , false, true)); 156CHECK (find (arch_default_env ("gfx1151" ),"STRATA_SH_STREAM" )== nullptr ); 157#else 158CHECK (arch_default_env ("gfx1151" )== arch_default_env ("gfx1151" , false, false)); 159CHECK (find (arch_default_env ("gfx1151" ),"STRATA_SH_STREAM" )!= nullptr ); 160#endif 161// applying the table: an explicit STRATA_SH_STREAM=1 stays 1, an explicit 0 stays 0, and the Windows table does not set it 162unset ("STRATA_QFUSE" ); 163put ("STRATA_SH_STREAM" ,"1" ); 164apply_arch_defaults ("gfx1151" ); 165CHECK (std::getenv ("STRATA_SH_STREAM" )!= nullptr && std::string (std::getenv ("STRATA_SH_STREAM" ))== "1" ); 166put ("STRATA_SH_STREAM" ,"0" ); 167apply_arch_defaults ("gfx1151" ); 168CHECK (std::string (std::getenv ("STRATA_SH_STREAM" ))== "0" ); 169unset ("STRATA_SH_STREAM" ); 170unset ("STRATA_QFUSE" ); 171const auto applied = apply_arch_defaults ("gfx1151" ); 172bool sh_set = false; 173for (const auto & n :applied )sh_set = sh_set || n == "STRATA_SH_STREAM" ; 174#if defined(_WIN32 ) 175CHECK (!sh_set ); 176CHECK (std::getenv ("STRATA_SH_STREAM" )== nullptr || std::string (std::getenv ("STRATA_SH_STREAM" )).empty ()); 177#else 178CHECK (sh_set ); 179CHECK (std::getenv ("STRATA_SH_STREAM" )!= nullptr && std::string (std::getenv ("STRATA_SH_STREAM" ))== "1" ); 180#endif 181unset ("STRATA_SH_STREAM" ); 182unset ("STRATA_QFUSE" ); 183unset ("STRATA_TSUM" ); 184 } 185// AMD-Q: the CPU prefill share is a default of a gfx12 card only (the caller adds single card / experts missing) 186unset ("STRATA_GFX12_DEFAULTS" ); 187CHECK (gfx12_prefill_share_default ("gfx1201" , false)&& gfx12_prefill_share_default ("gfx1200" , false)&& 188gfx12_prefill_share_default ("gfx1201:sramecc-:xnack-" , false)); 189CHECK (!gfx12_prefill_share_default ("gfx1201" , true));// STRATA_DEFAULTS=026 190for (const char * a : {"gfx1151" ,"gfx1150" ,"gfx1103" ,"gfx1100" ,"gfx1030" ,"gfx906" ,"gfx90a" ,"" })CHECK (!gfx12_prefill_share_default (a , false)); 191put ("STRATA_GFX12_DEFAULTS" ,"0" ); 192CHECK (!gfx12_prefill_share_default ("gfx1201" , false)); 193unset ("STRATA_GFX12_DEFAULTS" ); 194// gfx12: the five prompt switches and seven bit-identical decode switches, no bit-changing one 195unset ("STRATA_GFX12_DEFAULTS" ); 196for (const char * a : {"gfx1200" ,"gfx1201" ,"gfx1201:sramecc-:xnack-" }) { 197const auto t = arch_default_env (a ); 198CHECK (t .size ()== 12 ); 199bool attn_lane = false,attn_merge = false,tsum = false,expdec = false; 200for (const auto & kv :t ) { 201if (kv .first == "STRATA_ATTN_LANECELL" )attn_lane = kv .second == "1" ; 202if (kv .first == "STRATA_ATTN_MERGE_V2" )attn_merge = kv .second == "1" ; 203if (kv .first == "STRATA_TSUM" )tsum = kv .second == "1" ; 204if (kv .first == "STRATA_EXPDEC" )expdec = kv .second == "1" ; 205 } 206CHECK (attn_lane && attn_merge && tsum && expdec );// the 0.2.7 R9700 decode measurement, bit-identical 207for (const auto & kv :t )CHECK (kv .first != "STRATA_HCD_EXACT" ); 208for (const auto & kv :t ) { 209CHECK (kv .first != "STRATA_Q8_PACKED" && kv .first != "STRATA_SH_STREAM" && kv .first != "STRATA_PF_GEMM" && 210kv .first != "STRATA_PF_FUSED" ); 211 } 212 } 213CHECK (arch_default_env ("gfx12010" ).empty ()); 214put ("STRATA_GFX12_DEFAULTS" ,"0" ); 215CHECK (arch_default_env ("gfx1201" ).empty ()); 216unset ("STRATA_GFX12_DEFAULTS" ); 217// a user's setting wins, whatever it is; the rest are set 218put ("STRATA_TSUM" ,"0" ); 219unset ("STRATA_QFUSE" ); 220const auto set = apply_arch_defaults ("gfx1151" ); 221CHECK (std::getenv ("STRATA_TSUM" )!= nullptr && std::string (std::getenv ("STRATA_TSUM" ))== "0" ); 222CHECK (std::getenv ("STRATA_QFUSE" )!= nullptr && std::string (std::getenv ("STRATA_QFUSE" ))== "1" ); 223for (const auto & n :set )CHECK (n != "STRATA_TSUM" ); 224// the opt-out 225put ("STRATA_GFX1151_DEFAULTS" ,"0" ); 226CHECK (arch_default_env ("gfx1151" ).empty ()); 227CHECK (apply_arch_defaults ("gfx1151" ).empty ()); 228// the two approved gfx12 prompt defaults (WMMA attention, Q2_0 fused experts): on for Linux, off for Windows 229CHECK (gfx12_prompt_defaults_on (false)); 230CHECK (!gfx12_prompt_defaults_on (true)); 231#if defined(_WIN32 ) 232CHECK (!kGfx12PromptDefaultsOn ); 233#else 234CHECK (kGfx12PromptDefaultsOn ); 235#endif 236// 153-igpu: the matrix-core prompt set of the integrated Radeons, chosen by the UMA flag AND the architecture. 237// Mock device properties: {gcnArchName, integrated}. 238struct Mock {const char * name ;const char * gcn ;bool integrated ;bool expect_on ; }; 239const Mock mocks []= { 240 {"Radeon 780M (Phoenix, UMA)" ,"gfx1103" , true, true}, 241 {"Radeon 780M with feature suffix" ,"gfx1103:sramecc-:xnack-" , true, true}, 242 {"Radeon 890M (Strix Point, UMA)" ,"gfx1150" , true, true}, 243 {"Radeon 8060S (Strix Halo, UMA)" ,"gfx1151" , true, true}, 244 {"RX 7900 XTX (dGPU)" ,"gfx1100" , false, false}, 245 {"RX 7800 XT (dGPU)" ,"gfx1101" , false, false}, 246 {"R9700 (dGPU)" ,"gfx1201" , false, false}, 247 {"RX 9060 (dGPU)" ,"gfx1200" , false, false}, 248 {"RX 6800 (dGPU)" ,"gfx1030" , false, false}, 249 {"a gfx1103 reported as a discrete card" ,"gfx1103" , false, false}, 250 {"a gfx1151 reported as a discrete card" ,"gfx1151" , false, false}, 251 {"Radeon 860M (Krackan, no kernels)" ,"gfx1152" , true, false}, 252 {"older iGPU (gfx1036, no kernels)" ,"gfx1036" , true, false}, 253 {"an integrated gfx1201 would not get it" ,"gfx1201" , true, false}, 254 {"CUDA (no gcn name)" ,"" , true, false}, 255 }; 256unset ("STRATA_IGPU_DEFAULTS" ); 257unset ("STRATA_IGPU_PROMPT_SET" ); 258// 021-minipc: with nothing set the prompt set is the default of the Radeon 780M only (gfx1103, integrated, not Windows) 259CHECK (kIgpuPromptSetDefaultOn ); 260CHECK (igpu_prompt_set_enabled ("gfx1103" , false)); 261CHECK (igpu_prompt_set_enabled ("gfx1103:sramecc-:xnack-" , false)); 262CHECK (!igpu_prompt_set_enabled ("gfx1103" , true));// Windows: not tested 263for (const char * g : {"gfx1150" ,"gfx1151" ,"gfx1100" ,"gfx1201" ,"gfx1152" ,"" ,"gfx11030" })CHECK (!igpu_prompt_set_enabled (g , false)); 264CHECK (!igpu_prompt_set_enabled (nullptr , false)); 265for (const Mock & m :mocks ) { 266const bool want = m .expect_on && std::string (m .gcn ).rfind ("gfx1103" ,0 )== 0 ; 267#if defined(_WIN32 ) 268// 0.2.8: Strix Halo (gfx1151, integrated) gets the matrix-core prompt set on Windows; the 780M and the 890M are 269// not measured there and stay off 270const bool win_on = m .expect_on && m .integrated && std::string (m .gcn ).rfind ("gfx1151" ,0 )== 0 ; 271CHECK (igpu_default_env (m .gcn ,m .integrated ).size ()== (win_on ?9u :0u )); 272#else 273CHECK (igpu_default_env (m .gcn ,m .integrated ).size ()== (want ?5u :0u )); 274#endif 275 } 276#if !defined(_WIN32 ) 277for (const char * k : {"STRATA_HIP_WMMA" ,"STRATA_PF_GEMM" ,"STRATA_PA_FAST" ,"STRATA_SELECT_WMMA" ,"STRATA_HC_UPMIX" })unset (k ); 278CHECK (apply_arch_defaults ("gfx1103" , true).size ()== 5 );// a 780M gets the set with nothing set 279for (const char * k : {"STRATA_HIP_WMMA" ,"STRATA_PF_GEMM" ,"STRATA_PA_FAST" ,"STRATA_SELECT_WMMA" ,"STRATA_HC_UPMIX" })unset (k ); 280CHECK (apply_arch_defaults ("gfx1150" , true).empty ());// 880M / 890M: no hardware, stays as it was 281for (const char * k : {"STRATA_HIP_WMMA" ,"STRATA_PF_GEMM" ,"STRATA_PA_FAST" ,"STRATA_SELECT_WMMA" ,"STRATA_HC_UPMIX" })unset (k ); 282CHECK (std::getenv ("STRATA_PF_FUSED" )!= nullptr );// the Linux integrated gfx11 class also took the fused prompt experts (silent; igpu_fused_prompt_default) 283unset ("STRATA_PF_FUSED" ); 284#endif 285// the off switches 286put ("STRATA_IGPU_PROMPT_SET" ,"0" ); 287CHECK (!igpu_prompt_set_enabled ("gfx1103" , false)); 288CHECK (igpu_default_env ("gfx1103" , true).empty ()); 289unset ("STRATA_IGPU_PROMPT_SET" ); 290put ("STRATA_IGPU_DEFAULTS" ,"0" ); 291CHECK (!igpu_prompt_set_enabled ("gfx1103" , false)); 292unset ("STRATA_IGPU_DEFAULTS" ); 293// opt-in per run for the other arches: STRATA_IGPU_PROMPT_SET=1; the checks below run with it on (every mock arch of the list) 294put ("STRATA_IGPU_PROMPT_SET" ,"1" ); 295CHECK (igpu_prompt_set_enabled ("gfx1150" , false)); 296put ("STRATA_IGPU_DEFAULTS" ,"0" ); 297CHECK (!igpu_prompt_set_enabled ("gfx1150" , false));// the whole-set off switch wins 298unset ("STRATA_IGPU_DEFAULTS" ); 299for (const Mock & m :mocks ) { 300const auto t = igpu_default_env (m .gcn ,m .integrated ); 301CHECK (t .empty ()== !m .expect_on ); 302if (m .expect_on ) { 303bool halo_win = false; 304#if defined(_WIN32 ) 305halo_win = std::string (m .gcn ).rfind ("gfx1151" ,0 )== 0 ; 306#endif 307CHECK (t .size ()== (halo_win ?9u :5u )); 308 std::vector < const char *> want = {"STRATA_HIP_WMMA" ,"STRATA_PF_GEMM" ,"STRATA_PA_FAST" ,"STRATA_HC_UPMIX" }; 309want .push_back ("STRATA_SELECT_WMMA" ); 310if (halo_win ) {want .push_back ("STRATA_PF_FUSED" );want .push_back ("STRATA_PF_F16" );want .push_back ("STRATA_PF_DM16" );want .push_back ("STRATA_PF_P1A" ); } 311for (const char * w :want ) { 312bool found = false; 313for (const auto & kv :t )found = found || (kv .first == w && kv .second == "1" ); 314CHECK (found ); 315 } 316for (const auto & kv :t )CHECK (kv .first != "STRATA_HC_Q8" && kv .first != "STRATA_PF_HCDOWN" ); 317if (!halo_win ) {for (const auto & kv :t )CHECK (kv .first != "STRATA_PF_FUSED" ); } 318 } 319if (!m .expect_on ) std::printf (" (not on) %s\n" ,m .name ); 320 } 321CHECK (igpu_default_env (nullptr , true).empty ()); 322CHECK (igpu_prompt_defaults_arch ("gfx1103" )&& igpu_prompt_defaults_arch ("gfx1150" )&& igpu_prompt_defaults_arch ("gfx1151" )); 323CHECK (!igpu_prompt_defaults_arch ("gfx11030" )&& !igpu_prompt_defaults_arch ("gfx1100" )&& !igpu_prompt_defaults_arch ("gfx1201" )); 324// the exact tables are untouched: gfx1103 / gfx1150 stay out of arch_default_env, gfx1151 keeps no bit-changing switch 325CHECK (arch_default_env ("gfx1103" ).empty ()); 326// the opt-out of the whole set 327put ("STRATA_IGPU_DEFAULTS" ,"0" ); 328CHECK (igpu_default_env ("gfx1103" , true).empty ()); 329unset ("STRATA_IGPU_DEFAULTS" ); 330put ("STRATA_IGPU_PROMPT_SET" ,"0" ); 331CHECK (igpu_default_env ("gfx1103" , true).empty ()); 332put ("STRATA_IGPU_PROMPT_SET" ,"1" ); 333// apply: a discrete card sets nothing, an iGPU sets the five, a switch the user set (even to 0) is kept 334const char * five []= {"STRATA_HIP_WMMA" ,"STRATA_PF_GEMM" ,"STRATA_PA_FAST" ,"STRATA_SELECT_WMMA" ,"STRATA_HC_UPMIX" }; 335for (const char * k :five )unset (k ); 336CHECK (apply_arch_defaults ("gfx1100" , false).empty ()); 337// gfx12: a discrete RDNA4 card gets its own twelve switches (five prompt, seven decode); a second call has nothing to do 338const char * g12 []= {"STRATA_GDN_HEAD" ,"STRATA_GDN_PP" ,"STRATA_GDN_CONVL2" ,"STRATA_GDN_NOY" ,"STRATA_CVEC_FUSE" , 339"STRATA_ATTN_LANECELL" ,"STRATA_ATTN_MERGE_V2" ,"STRATA_TSUM" ,"STRATA_EXPDEC" }; 340for (const char * k :g12 )unset (k ); 341unset ("STRATA_SMALL_UNR" );unset ("STRATA_GR_Q32_G" );unset ("STRATA_GR_Q8_PFS" ); 342const auto g12set = apply_arch_defaults ("gfx1201" , false); 343CHECK (g12set .size ()== 12 ); 344for (const char * k :g12 ) { 345CHECK (std::getenv (k )!= nullptr ); 346CHECK (std::string (std::getenv (k ))== (std::strcmp (k ,"STRATA_GDN_PP" )== 0 ?"2" :"1" )); 347 } 348CHECK (std::string (std::getenv ("STRATA_SMALL_UNR" ))== "3" && std::string (std::getenv ("STRATA_GR_Q32_G" ))== "2" && 349 std::string (std::getenv ("STRATA_GR_Q8_PFS" ))== "1" ); 350CHECK (apply_arch_defaults ("gfx1201" , false).empty ()); 351unset ("STRATA_SELECT_WMMA" );unset ("STRATA_SELECT_ALT_MIN_TOKENS" );unset ("STRATA_HEAD_MIX_MULTI" );// gfx12_extra.hpp's defaults (own test: gfx12_extra_test) 352CHECK (apply_arch_defaults ("gfx1103" , false).empty ());// integrated == false: a mixed box (iGPU + dGPU) keeps the old defaults 353for (const char * k :five )CHECK (std::getenv (k )== nullptr ); 354put ("STRATA_HC_UPMIX" ,"0" ); 355const auto on = apply_arch_defaults ("gfx1103" , true); 356CHECK (on .size ()== 4 ); 357for (const char * k : {"STRATA_HIP_WMMA" ,"STRATA_PF_GEMM" ,"STRATA_PA_FAST" ,"STRATA_SELECT_WMMA" }) 358CHECK (std::getenv (k )!= nullptr && std::string (std::getenv (k ))== "1" ); 359CHECK (std::getenv ("STRATA_HC_UPMIX" )!= nullptr && std::string (std::getenv ("STRATA_HC_UPMIX" ))== "0" ); 360for (const char * k :five )unset (k ); 361unset ("STRATA_IGPU_PROMPT_SET" ); 362#if defined(_WIN32 ) 363// 0.2.8: Strix Halo (gfx1151) on Windows gets the matrix-core prompt set with nothing asked. Measured on the strix 364// box (Qwen3.8-Flash-Next IQ3_S, engine 0.1.52, 4K / 8K ids prompts): 4K 690 -> 1,090, 8K 785 -> 1,183 (x1.58 / 365// x1.51), KL 0.0088 mean against the HC_Q8 bar of 0.0228. The set is HIP_WMMA + PF_GEMM + PA_FAST + HC_UPMIX + 366// PF_FUSED (0.2.9 adds SELECT_WMMA and PF_F16 to the Windows gfx1151 set), and the 780M / 890M keep exactly what was measured on them. 367unset ("STRATA_IGPU_DEFAULTS" ); 368unset ("STRATA_GFX1151_DEFAULTS" );// the 19-switch gfx1151 table is live in this block (the checks above turned it off) 369CHECK (igpu_prompt_set_enabled ("gfx1151" , true)); 370CHECK (igpu_prompt_set_enabled ("gfx1151:sramecc-:xnack-" , true)); 371CHECK (!igpu_prompt_set_enabled ("gfx1151" , false));// Linux gfx1151: still opt-in 372CHECK (!igpu_prompt_set_enabled ("gfx1150" , true)); 373CHECK (!igpu_prompt_set_enabled ("gfx1103" , true)); 374 { 375const auto t = igpu_default_env ("gfx1151" , true); 376CHECK (t .size ()== 9 ); 377auto has = [& t ](const char * k ) { 378for (const auto & kv :t )if (kv .first == k )return kv .second == "1" ; 379return false; 380 }; 381CHECK (has ("STRATA_HIP_WMMA" )&& has ("STRATA_PF_GEMM" )&& has ("STRATA_PA_FAST" )&& has ("STRATA_HC_UPMIX" )&& 382has ("STRATA_PF_FUSED" )&& has ("STRATA_SELECT_WMMA" )&& has ("STRATA_PF_F16" )&& has ("STRATA_PF_DM16" )&& has ("STRATA_PF_P1A" )); 383CHECK (igpu_default_env ("gfx1151" , false).empty ());// a gfx1151 reported as a discrete card 384CHECK (igpu_default_env ("gfx1150" , true).empty ());// 890M: unchanged 385CHECK (igpu_default_env ("gfx1103" , true).empty ());// 780M on Windows: unchanged 386 } 387 { 388const char * halo []= {"STRATA_HIP_WMMA" ,"STRATA_PF_GEMM" ,"STRATA_PA_FAST" ,"STRATA_HC_UPMIX" ,"STRATA_PF_FUSED" , 389"STRATA_SELECT_WMMA" ,"STRATA_PF_F16" ,"STRATA_PF_DM16" ,"STRATA_PF_P1A" }; 390for (const char * k :halo )unset (k ); 391const auto set = apply_arch_defaults ("gfx1151" , true); 392for (const char * k :halo ) { 393bool in = false; 394for (const auto & n :set )in = in || n == k ; 395CHECK (in ); 396CHECK (std::getenv (k )!= nullptr && std::string (std::getenv (k ))== "1" ); 397 } 398// a switch the user set (even to 0) is kept, and the whole set turns off with either switch 399for (const char * k :halo )unset (k ); 400put ("STRATA_HC_UPMIX" ,"0" ); 401const auto set2 = apply_arch_defaults ("gfx1151" , true); 402CHECK (std::getenv ("STRATA_HC_UPMIX" )!= nullptr && std::string (std::getenv ("STRATA_HC_UPMIX" ))== "0" ); 403for (const auto & n :set2 )CHECK (n != "STRATA_HC_UPMIX" ); 404CHECK (std::getenv ("STRATA_PF_FUSED" )!= nullptr ); 405unset ("STRATA_HC_UPMIX" ); 406for (const char * k :halo )unset (k ); 407put ("STRATA_IGPU_PROMPT_SET" ,"0" ); 408CHECK (igpu_default_env ("gfx1151" , true).empty ()); 409unset ("STRATA_IGPU_PROMPT_SET" ); 410put ("STRATA_IGPU_DEFAULTS" ,"0" ); 411CHECK (igpu_default_env ("gfx1151" , true).empty ()); 412unset ("STRATA_IGPU_DEFAULTS" ); 413put ("STRATA_GFX1151_DEFAULTS" ,"0" );// back to the state this block found (the 026 checks below rely on it) 414 } 415#endif 416// the registered arena asks for no transparent huge pages on an integrated gfx11 GPU under Linux (780M, 880M / 890M, Strix Halo), 417// detected from the device (integrated + arch), with or without the target-feature suffix; never on Windows, never on a discrete card 418for (const char * g : {"gfx1103" ,"gfx1150" ,"gfx1151" ,"gfx1103:sramecc-:xnack-" ,"gfx1151:sramecc+:xnack-" }) { 419CHECK (igpu_arena_no_thp_default (g , true, false)); 420CHECK (!igpu_arena_no_thp_default (g , true, true));// Windows: unchanged 421CHECK (!igpu_arena_no_thp_default (g , false, false));// not integrated 422 } 423for (const char * g : {"gfx1152" ,"gfx1100" ,"gfx1101" ,"gfx1102" ,"gfx1200" ,"gfx1201" ,"gfx1030" ,"gfx1036" ,"gfx11030" ,"gfx11031" ,"" ,"gfx90a" }) 424CHECK (!igpu_arena_no_thp_default (g , true, false)); 425// the wait before READY (kfd_settle.hpp) is for the same class: integrated gfx1103 / gfx1150 / gfx1151 under Linux, nothing else 426for (const char * g : {"gfx1103" ,"gfx1150" ,"gfx1151" ,"gfx1103:sramecc-:xnack-" }) { 427CHECK (igpu_kfd_settle_default (g , true, false)); 428CHECK (!igpu_kfd_settle_default (g , true, true));// Windows 429CHECK (!igpu_kfd_settle_default (g , false, false));// not integrated 430 } 431for (const char * g : {"gfx1100" ,"gfx1201" ,"gfx90a" ,"gfx1030" ,"gfx1152" ,"" })CHECK (!igpu_kfd_settle_default (g , true, false)); 432// the file-cache give-back during and after the expert load (page_cache_drop.hpp): the same class 433for (const char * g : {"gfx1103" ,"gfx1150" ,"gfx1151" ,"gfx1103:sramecc-:xnack-" }) { 434CHECK (igpu_cache_drop_default (g , true, false)); 435CHECK (!igpu_cache_drop_default (g , true, true));// Windows 436CHECK (!igpu_cache_drop_default (g , false, false));// not integrated 437 } 438for (const char * g : {"gfx1100" ,"gfx1201" ,"gfx90a" ,"gfx1030" ,"gfx1152" ,"" })CHECK (!igpu_cache_drop_default (g , true, false)); 439// the fused int8 prompt experts (STRATA_PF_FUSED=1 instead of llama.cpp's MMQ): the same class again, nothing else 440for (const char * g : {"gfx1103" ,"gfx1150" ,"gfx1151" ,"gfx1103:sramecc-:xnack-" ,"gfx1151:sramecc+:xnack-" }) { 441CHECK (igpu_fused_prompt_default (g , true, false)); 442CHECK (!igpu_fused_prompt_default (g , true, true));// Windows: gfx1151 has it in igpu_default_env, the others unchanged 443CHECK (!igpu_fused_prompt_default (g , false, false));// not integrated 444 } 445for (const char * g : {"gfx1152" ,"gfx1100" ,"gfx1101" ,"gfx1102" ,"gfx1200" ,"gfx1201" ,"gfx1030" ,"gfx1031" ,"gfx11030" ,"" ,"gfx90a" }) 446CHECK (!igpu_fused_prompt_default (g , true, false)); 447#if !defined(_WIN32 ) 448 {// apply: nothing set -> STRATA_PF_FUSED=1 on the class, =0 (the way back) and =1 as the user set them are kept, other devices get nothing 449unset ("STRATA_PF_FUSED" ); 450apply_arch_defaults ("gfx1100" , false); 451CHECK (std::getenv ("STRATA_PF_FUSED" )== nullptr );// discrete 452apply_arch_defaults ("gfx1103" , false); 453CHECK (std::getenv ("STRATA_PF_FUSED" )== nullptr );// a mixed box (iGPU + dGPU) 454apply_arch_defaults ("gfx1201" , false); 455CHECK (std::getenv ("STRATA_PF_FUSED" )== nullptr ); 456apply_arch_defaults ("gfx1152" , true); 457CHECK (std::getenv ("STRATA_PF_FUSED" )== nullptr ); 458apply_arch_defaults ("gfx1103" , true); 459CHECK (std::getenv ("STRATA_PF_FUSED" )!= nullptr && std::string (std::getenv ("STRATA_PF_FUSED" ))== "1" ); 460put ("STRATA_PF_FUSED" ,"0" ); 461apply_arch_defaults ("gfx1150" , true); 462CHECK (std::string (std::getenv ("STRATA_PF_FUSED" ))== "0" );// the way back is kept 463unset ("STRATA_PF_FUSED" ); 464apply_arch_defaults ("gfx1150" , true); 465CHECK (std::getenv ("STRATA_PF_FUSED" )!= nullptr && std::string (std::getenv ("STRATA_PF_FUSED" ))== "1" ); 466unset ("STRATA_PF_FUSED" ); 467for (const char * k : {"STRATA_HIP_WMMA" ,"STRATA_PF_GEMM" ,"STRATA_PA_FAST" ,"STRATA_SELECT_WMMA" ,"STRATA_HC_UPMIX" })unset (k ); 468 } 469#endif 470// STRATA_HIP_PROMPT_F16 (gemm.cu prompt_f16): "1" = on anywhere, any other set value = off (the way back), unset = on for the Linux integrated 780M only 471for (const char * g : {"gfx1103" ,"gfx1103:sramecc-:xnack-" }) { 472CHECK (prompt_f16_resolve (nullptr ,g , true, false)); 473CHECK (!prompt_f16_resolve (nullptr ,g , true, true));// Windows 474CHECK (!prompt_f16_resolve (nullptr ,g , false, false));// a discrete card of that name / a mixed report 475CHECK (!prompt_f16_resolve ("0" ,g , true, false));// the way back 476CHECK (!prompt_f16_resolve ("" ,g , true, false)); 477CHECK (prompt_f16_resolve ("1" ,g , true, false)); 478 } 479for (const char * g : {"gfx1150" ,"gfx1151" ,"gfx1152" ,"gfx1100" ,"gfx1101" ,"gfx1102" ,"gfx1200" ,"gfx1201" ,"gfx1030" ,"gfx1031" ,"gfx1032" ,"gfx11030" ,"" ,"gfx90a" }) { 480CHECK (!prompt_f16_resolve (nullptr ,g , true, false));// unchanged: opt-in 481CHECK (!prompt_f16_resolve (nullptr ,g , false, false)); 482CHECK (prompt_f16_resolve ("1" ,g , false, false));// =1 still turns it on anywhere 483CHECK (!prompt_f16_resolve ("0" ,g , true, false)); 484 } 485CHECK (!prompt_f16_resolve (nullptr ,nullptr , true, false)); 486// STRATA_NO_ARENA_THP: unset = the device rule decides; "0" = ask for the huge pages (also on such a device); any other value = skip them 487CHECK (arena_skip_thp_request (nullptr , false, true));// integrated gfx11, nothing set: skipped 488CHECK (!arena_skip_thp_request (nullptr , false, false));// any other device, nothing set: requested (as before) 489CHECK (!arena_skip_thp_request ("0" , false, true));// the user asks for them on the integrated gfx11 490CHECK (!arena_skip_thp_request ("0" , false, false)); 491CHECK (arena_skip_thp_request ("1" , false, false));// =1 skips on any device (as before) 492CHECK (arena_skip_thp_request ("1" , false, true)); 493CHECK (arena_skip_thp_request ("" , false, false));// set but empty: skipped, as before 494CHECK (arena_skip_thp_request (nullptr , true, false));// THP "always": never requested (#771) 495CHECK (arena_skip_thp_request ("0" , true, true)); 496// 021-minipc: UMA mode is NOT a default (slower, resets not fixed): off with nothing asked; the logic below runs with on=true 497CHECK (!kIgpuUmaArenaDefaultOn ); 498CHECK (!igpu_uma_arena_default ("gfx1103" , true, false)); 499// 021-minipc: UMA mode (the expert arena stays unregistered) is chosen for the Radeon 780M only: gfx1103 + integrated + not Windows 500unset ("STRATA_UMA_REGISTER" ); 501CHECK (igpu_uma_arena_default ("gfx1103" , true, false, true)); 502CHECK (igpu_uma_arena_default ("gfx1103:sramecc-:xnack-" , true, false, true)); 503CHECK (!igpu_uma_arena_default ("gfx1103" , true, true, true));// Windows: not measured 504CHECK (!igpu_uma_arena_default ("gfx1103" , false, false, true));// a gfx1103 that is not integrated 505for (const char * g : {"gfx1150" ,"gfx1151" ,"gfx1152" ,"gfx1100" ,"gfx1101" ,"gfx1200" ,"gfx1201" ,"gfx1030" ,"gfx11030" ,"" ,"gfx90a" }) 506CHECK (!igpu_uma_arena_default (g , true, false, true)); 507// 0.2.1.2: Strix Halo on Windows is unregistered by default (on or off), nothing else on Windows; Linux gfx1151 unchanged 508CHECK (igpu_uma_arena_default ("gfx1151" , true, true)); 509CHECK (igpu_uma_arena_default ("gfx1151:sramecc+:xnack-" , true, true)); 510CHECK (!igpu_uma_arena_default ("gfx1151" , false, true));// not integrated 511CHECK (!igpu_uma_arena_default ("gfx1151" , true, false));// Linux 512for (const char * g : {"gfx1150" ,"gfx1152" ,"gfx1103" ,"gfx1100" ,"gfx1101" ,"gfx1102" ,"gfx1200" ,"gfx1201" ,"gfx1030" ,"" ,"gfx90a" }) 513CHECK (!igpu_uma_arena_default (g , true, true)); 514CHECK (!igpu_uma_arena_default (nullptr , true, true)); 515put ("STRATA_UMA_REGISTER" ,"1" ); 516CHECK (!igpu_uma_arena_default ("gfx1151" , true, true)); 517unset ("STRATA_UMA_REGISTER" ); 518CHECK (!igpu_uma_arena_default (nullptr , true, false, true)); 519put ("STRATA_UMA_REGISTER" ,"1" ); 520CHECK (!igpu_uma_arena_default ("gfx1103" , true, false, true));// the user registers the arena as before 521unset ("STRATA_UMA_REGISTER" ); 522// both platforms: no Windows guard on the iGPU set (the owner wants it there too; untested on Windows is only said in the log) 523// ---- STRATA_DEFAULTS=026 (defaults_026.hpp): every 0.2.7 Qwen default gives v0.2.6's answer; an explicit variable is decided by the caller first 524 { 525const double GiB = 1073741824.0 ; 526using namespace strata ; 527CHECK (is_026_token ("026" )&& is_026_token ("0.2.6" )&& is_026_token ("v0.2.6" )); 528CHECK (!is_026_token (nullptr )&& !is_026_token ("" )&& !is_026_token ("0" )&& !is_026_token ("027" )); 529// residency-biased routing: 0 with the master switch on or off (0.2.8: off by default on every card, 026 or not) 530CHECK (route_prior_default (false, false,12.0 * GiB , false)== 0.0f ); 531CHECK (route_prior_default (false, false,12.0 * GiB , true)== 0.0f ); 532CHECK (route_prior_default (false, false,8.0 * GiB , true)== 0.0f ); 533// an explicit STRATA_ROUTE_PRIOR=1.5 wins over 026 as well 534CHECK (route_prior_resolve ("1.5" , false, false,12.0 * GiB , true)== 1.5f ); 535// the wide HC up read: on for a 12.0 card on CUDA, off under 026, off in HIP, off on sm_86 / sm_121 536CHECK (gr_up_wide_default (false,12 ,0 )); 537CHECK (!gr_up_wide_default (false,12 ,0 , true)); 538CHECK (!gr_up_wide_default (true,12 ,0 )); 539CHECK (!gr_up_wide_default (false,8 ,6 )); 540CHECK (!gr_up_wide_default (false,12 ,1 )); 541// #3453: the sm_89 MMVQ-IL tables: on by default for compute capability 8.9 only, off under 026 and in HIP; "1" and "0" win 542CHECK (mmvq_il_89_default (false,89 )); 543CHECK (!mmvq_il_89_default (false,86 )&& !mmvq_il_89_default (false,80 )&& !mmvq_il_89_default (false,90 )&& 544 !mmvq_il_89_default (false,120 )&& !mmvq_il_89_default (false,75 )&& !mmvq_il_89_default (false,70 )&& 545 !mmvq_il_89_default (false,60 )&& !mmvq_il_89_default (false,0 )); 546CHECK (!mmvq_il_89_default (true,89 )); 547CHECK (!mmvq_il_89_default (false,89 , true));// STRATA_DEFAULTS=026 548CHECK (mmvq_il_89_resolve (nullptr , false,89 , false));// unset: the rule 549CHECK (!mmvq_il_89_resolve (nullptr , false,89 , true));// unset + 026: off 550CHECK (!mmvq_il_89_resolve (nullptr , false,86 , false));// another card: off 551CHECK (!mmvq_il_89_resolve ("0" , false,89 , false));// STRATA_MMVQ_IL_89=0 turns it off 552CHECK (mmvq_il_89_resolve ("1" , false,89 , true));// an explicit =1 wins over the master switch 553CHECK (mmvq_il_89_resolve ("1" , false,86 , false));// (the tables are only looked up for cc 89 anyway) 554CHECK (mmvq_il_89_resolve ("" , false,89 , false)&& !mmvq_il_89_resolve ("" , false,89 , true));// empty text: the rule 555// #3779: the two sm_80-only defaults (wide dequant, MMVQ-IL sm_80 tables): on unless STRATA_DEFAULTS=026; "1" and "0" win 556CHECK (sm80_default_on (nullptr , false)&& !sm80_default_on (nullptr , true)); 557CHECK (!sm80_default_on ("0" , false)&& sm80_default_on ("1" , true)); 558CHECK (sm80_default_on ("" , false)&& !sm80_default_on ("" , true)); 559// GR_V3 and IMMA 560CHECK (gr_v3_default (false,12 ,0 , false,72.0 * GiB , false)); 561CHECK (!gr_v3_default (false,12 ,0 , false,72.0 * GiB , true)); 562CHECK (prompt_attn_imma_default (false,86 , false)); 563CHECK (!prompt_attn_imma_default (false,86 , true)); 564CHECK (!prompt_attn_imma_default (false,120 , true)); 565// the gfx12 decode switches: the arch table is v0.2.6's five prompt switches under 026, twelve otherwise; gfx1151 and the others do not move 566 { 567const auto t26 = strata::core::arch_default_env ("gfx1201" , true); 568const auto t27 = strata::core::arch_default_env ("gfx1201" , false); 569auto has = [](const std::vector < std::pair < std::string , std::string >>& t ,const char * k ) { 570for (const auto & kv :t )if (kv .first == k )return true; 571return false; 572 }; 573CHECK (t26 .size ()== 5 && t27 .size ()== 12 ); 574CHECK (has (t26 ,"STRATA_GDN_HEAD" )&& has (t26 ,"STRATA_CVEC_FUSE" )); 575CHECK (!has (t26 ,"STRATA_ATTN_LANECELL" )&& !has (t26 ,"STRATA_ATTN_MERGE_V2" )&& !has (t26 ,"STRATA_TSUM" )&& !has (t26 ,"STRATA_EXPDEC" )); 576CHECK (has (t27 ,"STRATA_ATTN_LANECELL" )&& has (t27 ,"STRATA_ATTN_MERGE_V2" )&& has (t27 ,"STRATA_TSUM" )&& has (t27 ,"STRATA_EXPDEC" )); 577CHECK (has (t27 ,"STRATA_SMALL_UNR" )&& has (t27 ,"STRATA_GR_Q32_G" )&& has (t27 ,"STRATA_GR_Q8_PFS" ));// AMD-Q: bitwise load-ordering switches 578CHECK (!has (t26 ,"STRATA_SMALL_UNR" )&& !has (t26 ,"STRATA_GR_Q32_G" )&& !has (t26 ,"STRATA_GR_Q8_PFS" )); 579CHECK (strata::core::arch_default_env ("gfx1200" , true).size ()== 5 ); 580CHECK (strata::core::arch_default_env ("gfx1151" , true)== strata::core::arch_default_env ("gfx1151" , false)); 581CHECK (strata::core::arch_default_env ("gfx1100" , true).empty ()&& strata::core::arch_default_env ("gfx1100" , false).empty ()); 582 } 583// the decode miss split start value: 0.15 on gfx12 native packs, 0.55 under 026 or STRATA_PCIE_FRAC_DEFAULT=old; the others do not move 584CHECK (pcie_start_frac (false, true, true, false, false)== 0.15 ); 585CHECK (pcie_start_frac (false, true, true, false, true)== 0.55 ); 586CHECK (pcie_start_frac (false, true, true, true, false)== 0.55 ); 587CHECK (pcie_start_frac (false, true, false, false, false)== 0.55 ); 588CHECK (pcie_start_frac (true, true, true, false, true)== 0.25 ); 589CHECK (pcie_start_frac (true, true, true, false, false)== 0.25 ); 590CHECK (pcie_start_frac (false, false, true, false, true)== 0.2 ); 591CHECK (pcie_start_frac (false, false, true, false, false)== 0.2 ); 592 } 593 std::printf (fails ?"arch_defaults_test: %d FAILED\n" :"arch_defaults_test: OK\n" ,fails ); 594// ---- 0.2.7 CUDA defaults (sm120_series.hpp): which cards get which, and which never do 595 { 596const double GiB = 1073741824.0 ; 597using namespace strata ; 598// residency-biased routing (owner decision of 2026-10-29, #4402): OFF by default on every card, the 0.2.6 / STRATA_ROUTE_PRIOR=0 answer. 599// 0.2.7 gave 1.5 to a discrete CUDA card of 13 GiB or less; the same cards are listed so the table says where the default went. 600const double cards []= {0.0 ,4.0 * GiB ,8.0 * GiB ,11.9 * GiB ,12.0 * GiB ,13.0 * GiB ,13.5 * GiB ,15.7 * GiB ,24.0 * GiB ,31.4 * GiB ,48.0 * GiB ,72.0 * GiB }; 601for (const double bytes :cards ) 602for (const bool hip : {false, true}) 603for (const bool integrated : {false, true}) 604for (const bool v026 : {false, true}) { 605CHECK (route_prior_default (hip ,integrated ,bytes ,v026 )== 0.0f ); 606CHECK (route_prior_resolve (nullptr ,hip ,integrated ,bytes ,v026 )== 0.0f );// nothing set: off, = STRATA_ROUTE_PRIOR=0 607CHECK (route_prior_resolve (nullptr ,hip ,integrated ,bytes ,v026 )== route_prior_resolve ("0" ,hip ,integrated ,bytes ,v026 )); 608 } 609CHECK (route_prior_default (false, false,11.9 * GiB )== 0.0f );// RTX 3060 / 5070 12 GB: was 1.5 in 0.2.7 610CHECK (route_prior_default (false, false,13.0 * GiB )== 0.0f );// the old boundary 611// the explicit opt-in still works: any set value wins on every card (the Expert-settings row writes 1.5) 612CHECK (strata::kRoutePriorSmallCard == 1.5f );// the one place the opt-in value lives 613CHECK (route_prior_resolve ("1.5" , false, false,12.0 * GiB )== 1.5f ); 614CHECK (route_prior_resolve ("1.5" , false, false,12.0 * GiB )== strata::kRoutePriorSmallCard ); 615CHECK (route_prior_resolve ("1.5" , false, false,8.0 * GiB , true)== 1.5f );// also under STRATA_DEFAULTS=026 616CHECK (route_prior_resolve ("1.5" , false, false,72.0 * GiB )== 1.5f );// and on a card the 0.2.7 default never touched 617CHECK (route_prior_resolve ("1.5" , true, false,12.0 * GiB )== 1.5f );// the variable is the user's own on any build 618CHECK (route_prior_resolve ("2.0" , false, false,12.0 * GiB )== 2.0f ); 619CHECK (route_prior_resolve ("0.5" , false, false,12.0 * GiB )== 0.5f ); 620CHECK (route_prior_resolve ("0" , false, false,12.0 * GiB )== 0.0f ); 621CHECK (route_prior_resolve ("" , false, false,12.0 * GiB )== 0.0f );// set but empty reads as 0, as atof always did here 622CHECK (route_prior_resolve ("off" , false, false,12.0 * GiB )== 0.0f ); 623// the stream-split hyper-connection read: a discrete 12.0 card above 13 GiB (RTX PRO 5000 72 GB, RTX 5090 32 GB), nothing else 624CHECK (gr_v3_default (false,12 ,0 , false,72.0 * GiB )); 625CHECK (gr_v3_default (false,12 ,0 , false,31.4 * GiB ));// RTX 5090 626CHECK (!gr_v3_default (false,12 ,0 , false,11.9 * GiB ));// RTX 5070 12 GB: streams most experts, unmeasured 627CHECK (gr_v3_default (false,12 ,0 , false,15.6 * GiB ));// a 16 GB sm_120 card (RTX 5060 Ti / 5070 Ti): above 13 GiB, on (unmeasured size, same arch) 628CHECK (!gr_v3_default (false,8 ,6 , false,15.7 * GiB ));// 2x RTX A4000 (sm_86): measured -3.0% / -5.9% 629CHECK (!gr_v3_default (false,8 ,6 , false,72.0 * GiB ));// any sm_86 630CHECK (!gr_v3_default (false,8 ,9 , false,24.0 * GiB ));// sm_89 631CHECK (!gr_v3_default (false,12 ,1 , false,128.0 * GiB ));// sm_121 (DGX Spark class): not 12.0 632CHECK (!gr_v3_default (false,12 ,0 , true,128.0 * GiB ));// integrated 633CHECK (!gr_v3_default (true,12 ,0 , false,32.0 * GiB ));// a HIP build: gfx1201 reports 12.0 too 634CHECK (!gr_v3_default (false,6 ,0 , false,16.0 * GiB ));// P100 635 } 636 { 637using namespace strata ; 638// the prompt attention on int8 tensor cores: every CUDA card from sm_80 on, not Turing / Volta / Pascal, not HIP 639CHECK (prompt_attn_imma_default (false,120 ));// RTX PRO 5000 / RTX 50: measured +1.6-1.8% 640CHECK (prompt_attn_imma_default (false,86 ));// 2x RTX A4000 / RTX 3060: measured +1.1-1.3% 641CHECK (prompt_attn_imma_default (false,80 )); 642CHECK (prompt_attn_imma_default (false,89 )); 643CHECK (!prompt_attn_imma_default (false,75 ));// Turing (also a forced STRATA_QSA_WARP=1 card) 644CHECK (!prompt_attn_imma_default (false,70 ));// Volta 645CHECK (!prompt_attn_imma_default (false,60 ));// Pascal (P100) 646CHECK (!prompt_attn_imma_default (true,120 ));// HIP 647 } 648 { 649using namespace strata ; 650// the small-card prompt path: one CUDA card, a native pack, a default prompt chunk below 8,192 tokens 651auto sc = [](long long chunk ,bool hip = false,int stages = 1 ,bool native = true,bool v026 = false,bool fe = false,bool le = false) { 652return small_card_prompt_path (chunk ,hip ,stages ,native ,v026 ,fe ,le ); 653 }; 654CHECK (sc (2048 ).fused_off && sc (2048 ).layer_major );// ~1.3K engine slots (measured -29% / -44% / -50%) 655CHECK (sc (3840 ).fused_off && sc (3840 ).layer_major ); 656CHECK (sc (5888 ).fused_off && sc (5888 ).layer_major );// ~1.9K slots: still a win (-9..-16%) 657CHECK (sc (8191 ).any ());// the boundary: below 8,192 ... 658CHECK (!sc (8192 ).any ());// ... and not at it (the default is the faster path from there: +7..+25%) 659CHECK (!sc (16384 ).any ()); 660CHECK (!sc (0 ).any ());// no chunk (no borrowing, or an explicit --prefill): nothing to decide on 661CHECK (!sc (-1 ).any ()); 662CHECK (!sc (2048 , true).any ());// a HIP build: no layer-major, the fused experts differ 663CHECK (!sc (2048 , false,2 ).any ());// a layer split: the owner has not decided that one 664CHECK (!sc (2048 , false,4 ).any ()); 665CHECK (sc (2048 , false,0 ).any ());// (stages 0 = not counted: one card) 666CHECK (!sc (2048 , false,1 , false).any ());// a non-native (Q2_0) pack: not measured 667CHECK (!sc (2048 , false,1 , true, true).any ());// STRATA_DEFAULTS=026 668CHECK (!sc (2048 , false,1 , true, false, true).any ());// STRATA_PF_FUSED named by the user (either value): the user's path 669CHECK (sc (2048 , false,1 , true, false, false, true).fused_off );// STRATA_PREFILL_LAYER_MAJOR named: the walk is theirs ... 670CHECK (!sc (2048 , false,1 , true, false, false, true).layer_major );// ... the expert path still follows the rule 671CHECK (!sc (2048 , false,1 , true, false, true, true).any ());// both named: nothing changes 672 } 673 { 674using namespace strata ; 675// the small-card path over the card sizes of the measured grid (RTX A4000 held to N MiB free, IQ2_XS, no MTP; default chunk the rule sees): 676// where it fires, and what it does with the fused kernels (on, unless STRATA_PF_SMALL_FUSED=0) 677struct Row {long long mib ,dflt ;bool fires ; }; 678const Row rows []= {{7000 ,2048 , true}, {8000 ,4096 , true}, {8500 ,5120 , true}, {9000 ,6144 , true}, {9500 ,7168 , true}, 679 {10000 ,8192 , false}, {12000 ,12288 , false}, {16376 ,20480 , false}}; 680for (const Row & r :rows ) { 681const SmallCardPromptPath pp = small_card_prompt_path (r .dflt , false,1 , true, false, false, false); 682CHECK (pp .any ()== r .fires ); 683CHECK (pp .fused_off == r .fires && pp .layer_major == r .fires ); 684if (pp .fused_off ) { 685CHECK (prefill::small_card_kernels_on (nullptr ));// unset: the native fused kernels run in MMQ's buffer layout 686CHECK (prefill::small_card_kernels_on ("" )); 687CHECK (prefill::small_card_kernels_on ("1" )); 688CHECK (!prefill::small_card_kernels_on ("0" ));// the way back: MMQ's kernels, as before 689 } 690const int ov = pp .fused_off ? (prefill::small_card_kernels_on (nullptr ) ? prefill::kPfFusedKernelsOnly :0 ) :-1 ; 691// STRATA_PF_FUSED as the fused kernels' rule reads it: unset reads as 1 on the small-card path only 692CHECK (prefill::pf_fused_env_effective (-1 ,ov )== (r .fires ?1 :-1 )); 693CHECK (prefill::pf_fused_env_effective (0 ,ov )== 0 );// "0" stays off 694CHECK (prefill::pf_fused_env_effective (1 ,ov )== 1 ); 695 } 696CHECK (prefill::pf_fused_env_effective (-1 ,0 )== -1 );// the way back (override 0): the variable as it is 697CHECK (prefill::pf_fused_env_effective (-1 ,-1 )== -1 );// nothing decided 698CHECK (small_card_prompt_path (2048 , false,1 , true, false, true, false).any ()== false);// STRATA_PF_FUSED named by hand: the user's path, no rule 699CHECK (small_card_prompt_path (2048 , true,1 , true, false, false, false).any ()== false);// HIP: unchanged 700 } 701 { 702using namespace strata ; 703// a build without MMQ sets STRATA_PF_FUSED=1 itself before main: the rule reads "named by the user" (prefill::own_only_user_named), not "non-empty" 704const std::vector < std::string > by_build = {"STRATA_PF_FUSED" ,"STRATA_PF_FUSED_Q50" };// what the build's initialiser recorded 705const std::vector < std::string > none ;// the user named it first (or a build with MMQ) 706const auto fused_named = [](const std::vector < std::string >& rec ) {return prefill::own_only_user_named ("STRATA_PF_FUSED" ,"1" ,rec ); }; 707const auto pp = [& ](long long dflt ,const std::vector < std::string >& rec ) {return small_card_prompt_path (dflt , false,1 , true, false,fused_named (rec ), false); }; 708CHECK (pp (2048 ,by_build ).any ());// the build's own value: the small-card rule runs (RTX 3060 Ti, default chunk 2,048) 709CHECK (pp (2048 ,by_build ).fused_off && pp (2048 ,by_build ).layer_major ); 710CHECK (!pp (2048 ,none ).any ());// the same text from the user: theirs, the rule steps aside 711CHECK (!small_card_prompt_path (2048 , false,1 , true, false, prefill::own_only_user_named ("STRATA_PF_FUSED" ,"0" ,none ), false).any ());// "0" from the user too 712for (long long dflt : {8192LL ,12288LL ,20480LL })CHECK (!pp (dflt ,by_build ).any ());// a card whose default chunk is 8,192 or more: unchanged either way 713CHECK (!small_card_prompt_path (2048 , true,1 , true, false, false, false).any ());// HIP: unchanged 714CHECK (!small_card_prompt_path (2048 , false,1 , true, true, false, false).any ());// STRATA_DEFAULTS=026: unchanged 715// the user named the walk's own variable: the expert path still follows the rule, the walk stays theirs 716CHECK (small_card_prompt_path (2048 , false,1 , true, false,fused_named (by_build ), true).fused_off ); 717CHECK (!small_card_prompt_path (2048 , false,1 , true, false,fused_named (by_build ), true).layer_major ); 718 } 719 { 720using namespace strata ; 721// the layer-major prompt walk (#3976): off by default on every build (owner's yes 2026-11-02: a layer split reads 32K 37-55% sooner chunk-major on 722// 2x A6000, 8K level); it was on for a CUDA layer split 723CHECK (!prefill_layer_major_default (false,2 ));// 2x RTX A4000 / A6000 (was on) 724CHECK (!prefill_layer_major_default (false,4 )); 725CHECK (!prefill_layer_major_default (false,1 ));// one GPU: opt-in only 726CHECK (!prefill_layer_major_default (false,0 )); 727CHECK (!prefill_layer_major_default (true,2 ));// HIP builds 728CHECK (!prefill_layer_major_default (false,2 , true));// STRATA_DEFAULTS=026 729CHECK (!prefill_layer_major_default (true,1 , true)); 730// the variable wins in both directions, whatever the rule says 731CHECK (!prefill_layer_major_resolve ("0" , false,2 ));// the off switch 732CHECK (prefill_layer_major_resolve ("1" , false,1 ));// the opt-in of the first ports: one GPU too 733CHECK (prefill_layer_major_resolve ("1" , false,2 , true));// explicit beats STRATA_DEFAULTS=026 734CHECK (!prefill_layer_major_resolve ("0" , false,2 , false)); 735CHECK (!prefill_layer_major_resolve ("0" , true,2 )); 736CHECK (prefill_layer_major_resolve ("2" , false,1 ));// any non-zero number is on 737CHECK (!prefill_layer_major_resolve ("off" , false,2 ));// text that reads as 0 is off (atoi), as before this rule existed 738// unset or empty: the rule 739CHECK (!prefill_layer_major_resolve (nullptr , false,2 ));// unset on a layer split: chunk-major 740CHECK (!prefill_layer_major_resolve ("" , false,2 ));// (empty text is unset) 741CHECK (prefill_layer_major_resolve ("1" , false,2 ));// by hand it still turns it on on a split 742CHECK (prefill_layer_major_resolve ("1" , false,4 , true));// and beats STRATA_DEFAULTS=026 743CHECK (!prefill_layer_major_resolve ("0" , false,3 )); 744CHECK (!prefill_layer_major_resolve (nullptr , false,1 )); 745CHECK (!prefill_layer_major_resolve (nullptr , false,2 , true)); 746CHECK (!prefill_layer_major_resolve (nullptr , true,2 )); 747 } 748 {// STRATA_PLE_BATCH: on everywhere but an engine built with CUDA 12.8 on a compute capability 12.0 card (issues #220, #224) 749using strata::ple_batch_default ; 750using strata::ple_batch_resolve ; 751const int rt128 = 12080 ,rt129 = 12090 ,rt130 = 13000 ,rt132 = 13020 ,rt127 = 12070 ; 752// the one case that is off: CUDA 12.8 build, cc 12.0 753CHECK (!ple_batch_default (rt128 , false,12 ,0 )); 754CHECK (!ple_batch_default (12089 , false,12 ,0 ));// any 12.8.x 755// every other toolkit keeps it on on the same card 756CHECK (ple_batch_default (rt130 , false,12 ,0 ));// the released cuda13 package 757CHECK (ple_batch_default (rt132 , false,12 ,0 )); 758CHECK (ple_batch_default (rt129 , false,12 ,0 )); 759CHECK (ple_batch_default (rt127 , false,12 ,0 )); 760// every other card keeps it on with 12.8 761CHECK (ple_batch_default (rt128 , false,8 ,6 ));// sm_86 762CHECK (ple_batch_default (rt128 , false,8 ,9 )); 763CHECK (ple_batch_default (rt128 , false,7 ,5 )); 764CHECK (ple_batch_default (rt128 , false,12 ,1 ));// GB10 (sm_121) is not the 12.0 card 765CHECK (ple_batch_default (rt128 , false,9 ,0 )); 766// a HIP build never turns it off (a gfx12 card reports 12.0 as well; there is no CUDART there) 767CHECK (ple_batch_default (0 , true,12 ,0 )); 768CHECK (ple_batch_default (rt128 , true,12 ,0 )); 769// the variable wins both ways, on any toolkit and card 770CHECK (ple_batch_resolve ("1" ,rt128 , false,12 ,0 ));// on anyway 771CHECK (!ple_batch_resolve ("0" ,rt130 , false,12 ,0 )); 772CHECK (!ple_batch_resolve ("0" ,rt128 , false,8 ,6 )); 773CHECK (ple_batch_resolve ("2" ,rt128 , false,12 ,0 )); 774CHECK (!ple_batch_resolve ("off" ,rt130 , false,8 ,6 ));// text that reads as 0 is off (atoi), as before 775// unset: the rule 776CHECK (!ple_batch_resolve (nullptr ,rt128 , false,12 ,0 )); 777CHECK (ple_batch_resolve (nullptr ,rt130 , false,12 ,0 )); 778CHECK (ple_batch_resolve (nullptr ,rt128 , false,8 ,6 )); 779 } 780 {// the spill gate: only a discrete GPU may have its start moved off VRAM (draft layer dropped, head on the host, loan of 16, KV window below 20480) 781using strata::spill_allowed ; 782CHECK (spill_allowed (false, false));// CUDA / HIP discrete 783CHECK (!spill_allowed (true, false));// Metal: one pool, "free VRAM" is the OS's available RAM 784CHECK (!spill_allowed (false, true));// an integrated GPU (Strix Halo gfx1151, APUs): the same 785CHECK (!spill_allowed (true, true)); 786 } 787return fails ?1 :0 ; 788}