okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
a6859aa7d
main
1// src/core/nv_defaults_test.cpp - the NVIDIA per-architecture default tables (no GPU needed): the sm_121 (GB10, DGX Spark) table, its 2// two off switches, and that no other card's table changed. 3#include "strata/core/nv_chunk.hpp" 4#include "strata/core/nv_defaults.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) 12 13static void unset (const char * k ) { 14#if defined(_WIN32 ) 15_putenv_s (k ,"" ); 16#else 17unsetenv (k ); 18#endif 19} 20static void put (const char * k ,const char * v ) { 21#if defined(_WIN32 ) 22_putenv_s (k ,v ); 23#else 24setenv (k ,v ,1 ); 25#endif 26} 27 28static const std::string * find (const std::vector < std::pair < std::string , std::string >>& t ,const char * k ) { 29for (const auto & kv :t ) 30if (kv .first == k )return & kv .second ; 31return nullptr ; 32} 33 34int main () { 35using namespace strata::core ; 36unset ("STRATA_SM121_PERF" ); 37unset ("STRATA_SM86_PERF" ); 38unset ("STRATA_SM60_PERF" ); 39unset ("STRATA_EMULATE_CC" ); 40// GB10 (12.1): the six measured switches, and nothing else 41 { 42const auto t = nv_default_env (12 ,1 , false); 43CHECK (t .size ()== 6 ); 44CHECK (find (t ,"STRATA_PF_FUSED" )&& * find (t ,"STRATA_PF_FUSED" )== "1" ); 45CHECK (find (t ,"STRATA_PF_FUSED_KQ" )&& * find (t ,"STRATA_PF_FUSED_KQ" )== "1" ); 46CHECK (find (t ,"STRATA_PREFILL_NVFP4" )&& * find (t ,"STRATA_PREFILL_NVFP4" )== "w4a4" ); 47CHECK (find (t ,"STRATA_HC_UPMIX" )&& * find (t ,"STRATA_HC_UPMIX" )== "1" ); 48CHECK (find (t ,"STRATA_SIDE_MIXER" )&& * find (t ,"STRATA_SIDE_MIXER" )== "2" ); 49CHECK (find (t ,"STRATA_SPEC_COST" )&& * find (t ,"STRATA_SPEC_COST" )== "1" ); 50 } 51// STRATA_DEFAULTS=026 (the 0.2.7 master switch; the sm_121 table is newer than 0.2.6) empties it 52CHECK (nv_default_env (12 ,1 , true).empty ()); 53// STRATA_SM121_PERF=0 empties it; any other value keeps it 54put ("STRATA_SM121_PERF" ,"0" ); 55CHECK (nv_default_env (12 ,1 , false).empty ()); 56put ("STRATA_SM121_PERF" ,"1" ); 57CHECK (nv_default_env (12 ,1 , false).size ()== 6 ); 58unset ("STRATA_SM121_PERF" ); 59// the other cards: sm_120 (RTX 50) and sm_100 get nothing from this file; the sm_86 / sm_60 tables are unchanged by the flag 60CHECK (nv_default_env (12 ,0 , false).empty ()); 61CHECK (nv_default_env (10 ,0 , false).empty ()); 62CHECK (nv_default_env (8 ,9 , false).empty ()); 63CHECK (nv_default_env (7 ,5 , false).empty ()); 64 { 65const auto a = nv_default_env (8 ,6 , false),b = nv_default_env (8 ,6 , true); 66CHECK (!a .empty ()&& a == b );// STRATA_DEFAULTS=026 does not touch the 2026-10 sm_86 table 67const auto p = nv_default_env (6 ,0 , false),q = nv_default_env (6 ,0 , true); 68CHECK (!p .empty ()&& p == q ); 69CHECK (!find (a ,"STRATA_PF_FUSED" )&& !find (p ,"STRATA_PF_FUSED" )); 70// repeatable output: sm_86 keeps ADAPT_LAG=2 but no longer turns ADAPT_NOWAIT on (option 2); sm_60 keeps both 71CHECK (!find (a ,"STRATA_ADAPT_NOWAIT" )); 72CHECK (find (a ,"STRATA_ADAPT_LAG" )&& * find (a ,"STRATA_ADAPT_LAG" )== "2" ); 73CHECK (find (p ,"STRATA_ADAPT_NOWAIT" )&& * find (p ,"STRATA_ADAPT_NOWAIT" )== "1" ); 74CHECK (find (p ,"STRATA_ADAPT_LAG" )&& * find (p ,"STRATA_ADAPT_LAG" )== "2" ); 75 } 76// round 0212: STRATA_MMQ_KQ=1 is a default for compute capability 8.0+ (owner yes 11-03), with its own off switches 77unset ("STRATA_NV_KQ_DEFAULT" ); 78CHECK (kNvKqDefaultOn ); 79for (int major : {8 ,9 ,10 ,12 })CHECK (nv_kq_default_env (major ,0 , false).size ()== 1 );// on without any switch 80put ("STRATA_NV_KQ_DEFAULT" ,"1" ); 81for (int major : {8 ,9 ,10 ,12 }) { 82const auto k = nv_kq_default_env (major ,0 , false); 83CHECK (k .size ()== 1 && find (k ,"STRATA_MMQ_KQ" )&& * find (k ,"STRATA_MMQ_KQ" )== "1" ); 84 } 85CHECK (nv_kq_default_env (7 ,5 , false).empty ());// Turing / Volta / Pascal keep the FP16 prompt path 86CHECK (nv_kq_default_env (6 ,0 , false).empty ()); 87CHECK (nv_kq_default_env (12 ,0 , true).empty ());// STRATA_DEFAULTS=026 88put ("STRATA_NV_KQ_DEFAULT" ,"0" ); 89CHECK (nv_kq_default_env (12 ,0 , false).empty ());// its own off switch 90unset ("STRATA_NV_KQ_DEFAULT" ); 91// the start-up line of that default: the earlier line byte for byte where Strata's own kernels do not read the K-quant experts, one that says what happens where they do 92CHECK (nv_kq_default_line (false)== 93"strata: a model with K-quant experts (Unsloth UD-Q4/Q5/Q6_K_XL) reads its prompt on llama.cpp's MMQ kernels (STRATA_MMQ_KQ=0 or STRATA_NV_KQ_DEFAULT=0 turns it off)" ); 94CHECK (nv_kq_default_line (true)== 95"strata: a model with K-quant experts (Unsloth UD-Q4/Q5/Q6_K_XL) reads its prompt on Strata's own kernels where they cover the layer (Q4_K and Q5_K gate/up with a Q5_1 or Q8_0 down) " 96"and on llama.cpp's MMQ kernels for the rest (STRATA_PF_FUSED_KQ=0 gives all of them back to MMQ)" ); 97CHECK (nv_kq_default_line (true, true)== nv_kq_default_line (true)&& nv_kq_default_line (false, true)== nv_kq_default_line (false)); 98// a build without MMQ names no MMQ kernel it does not have 99CHECK (nv_kq_default_line (true, false)== 100"strata: a model with K-quant experts (Unsloth UD-Q4/Q5/Q6_K_XL) reads its prompt on Strata's own kernels (Q4_K and Q5_K gate/up with a Q5_1 or Q8_0 down); " 101"the 'prompt kernels' line below gives the counts" ); 102CHECK (nv_kq_default_line (false, false)== 103"strata: a model with K-quant experts (Unsloth UD-Q4/Q5/Q6_K_XL) reads its prompt on Strata's own int8 kernels (this engine has no MMQ kernels)" ); 104 {// the line is printed only for a loaded set that has K-quant experts (ggml types: IQ2_XS 17, IQ3_S 21, IQ4_NL 20, IQ2_S 22, Q8_0 8, Q5_1 7, Q4_K 12, Q5_K 13, Q6_K 14) 105CHECK (nv_kq_expert_type (12 )&& nv_kq_expert_type (13 )&& nv_kq_expert_type (14 )&& nv_kq_expert_type (7 )); 106CHECK (!nv_kq_expert_type (8 )&& !nv_kq_expert_type (17 )&& !nv_kq_expert_type (21 )&& !nv_kq_expert_type (20 )&& !nv_kq_expert_type (22 )&& !nv_kq_expert_type (-1 )&& !nv_kq_expert_type (0 )); 107CHECK (!nv_kq_line_wanted ({}));// nothing loaded 108CHECK (!nv_kq_line_wanted ({{21 ,20 }, {21 ,20 }, {22 ,20 }, {17 ,20 }}));// IQ3_S / IQ2_S / IQ2_XS with IQ4_NL down: no line 109CHECK (!nv_kq_line_wanted ({{21 ,8 }, {17 ,8 }}));// Q8_0 down only: the switch decides nothing there 110CHECK (nv_kq_line_wanted ({{12 ,7 }}));// UD-Q4_K_XL: Q4_K gate/up, Q5_1 down 111CHECK (nv_kq_line_wanted ({{21 ,20 }, {13 ,8 }, {21 ,20 }}));// one Q5_K layer among i-quant ones is enough 112CHECK (nv_kq_line_wanted ({{12 ,14 }}));// Q6_K down 113CHECK (nv_kq_line_wanted ({{21 ,7 }}));// only a Q5_1 down (i-quant gate/up): the switch decides that product, so the line stands 114CHECK (nv_kq_line_wanted ({{21 ,20 }, {21 ,7 }})); 115// apply_nv_kq_default is not called here: its two-argument path reads strata::qwen_defaults_026(), which caches STRATA_DEFAULTS at its first call, 116// and the one-argument check at the end of main needs that first call to see STRATA_DEFAULTS=026. 117 } 118 {// which cards: fused_tile::kq_takes with the engine's switches (raw compute capability, SM count) 119unset ("STRATA_PF_FUSED" );unset ("STRATA_PF_FUSED_KQ" );unset ("STRATA_PF_FUSED_SM40" );unset ("STRATA_PF_FUSED_SM86" ); 120CHECK (nv_kq_fused_here (8 ,6 ,84 )&& nv_kq_fused_here (8 ,6 ,80 )&& nv_kq_fused_here (12 ,0 ,110 )&& nv_kq_fused_here (12 ,0 ,80 ));// RTX A6000, RTX PRO 5000 class 121CHECK (nv_kq_fused_here (8 ,0 ,108 )&& nv_kq_fused_here (8 ,9 ,128 ));// the sm_86 class 122CHECK (nv_kq_fused_here (8 ,6 ,48 )&& nv_kq_fused_here (12 ,0 ,48 ));// 40-79 SMs: the staged launches 123CHECK (!nv_kq_fused_here (8 ,6 ,39 )&& !nv_kq_fused_here (12 ,1 ,48 )&& !nv_kq_fused_here (7 ,5 ,68 )&& !nv_kq_fused_here (8 ,7 ,16 )&& !nv_kq_fused_here (9 ,0 ,132 ));// under 40 SMs, GB10, Turing, Orin, Hopper 124put ("STRATA_PF_FUSED_SM40" ,"0" ); 125CHECK (!nv_kq_fused_here (8 ,6 ,48 )&& nv_kq_fused_here (8 ,6 ,84 )); 126unset ("STRATA_PF_FUSED_SM40" ); 127put ("STRATA_PF_FUSED_KQ" ,"0" ); 128CHECK (!nv_kq_fused_here (8 ,6 ,84 )&& !nv_kq_fused_here (12 ,0 ,110 ));// the way back 129put ("STRATA_PF_FUSED_KQ" ,"1" ); 130CHECK (nv_kq_fused_here (8 ,6 ,84 )&& nv_kq_fused_here (12 ,1 ,48 )&& nv_kq_fused_here (7 ,5 ,68 ));// the opt-in: every card 131put ("STRATA_PF_FUSED" ,"0" ); 132CHECK (!nv_kq_fused_here (8 ,6 ,84 )&& !nv_kq_fused_here (12 ,1 ,48 ));// STRATA_PF_FUSED=0: every fused kernel off 133unset ("STRATA_PF_FUSED" );unset ("STRATA_PF_FUSED_KQ" ); 134put ("STRATA_PF_FUSED_SM86" ,"0" ); 135CHECK (!nv_kq_fused_here (8 ,6 ,84 )&& nv_kq_fused_here (12 ,0 ,110 ));// the sm_86 class diagnostic switch 136unset ("STRATA_PF_FUSED_SM86" ); 137 } 138// the other tables are unchanged by it 139CHECK (nv_default_env (12 ,0 , false).empty ()); 140// round 0212: the NVIDIA prompt-chunk ceiling of a bare `--prefill auto` (nv_chunk.hpp) 141CHECK (nv_chunk_ceiling (nullptr , false)== 32768 ); 142CHECK (nv_chunk_ceiling ("1" , false)== 32768 ); 143CHECK (nv_chunk_ceiling ("16" , false)== 16384 ); 144CHECK (nv_chunk_ceiling ("0" , false)== 0 );// STRATA_NV_CHUNK=0 keeps 8192 145CHECK (nv_chunk_ceiling (nullptr , true)== 0 );// STRATA_DEFAULTS=026 keeps 8192 146CHECK (nv_chunk_ceiling ("16" , true)== 0 ); 147CHECK (nv_chunk_card_ok (7 ,0 ));// Volta (V100): measured, takes the raise 148CHECK (!nv_chunk_card_ok (7 ,5 ));// Turing: not measured, keeps 8192 149CHECK (!nv_chunk_card_ok (6 ,0 )&& !nv_chunk_card_ok (6 ,1 )&& !nv_chunk_card_ok (6 ,2 ));// Pascal: not measured, keeps 8192 150CHECK (!nv_chunk_card_ok (5 ,2 )&& !nv_chunk_card_ok (0 ,0 )); 151CHECK (nv_chunk_card_ok (8 ,0 )&& nv_chunk_card_ok (8 ,6 )&& nv_chunk_card_ok (9 ,0 )&& nv_chunk_card_ok (12 ,0 )); 152CHECK (nv_chunk_step_down (32768 )== 16384 && nv_chunk_step_down (16384 )== 8192 && nv_chunk_step_down (8192 )== 8192 ); 153// the one-argument form reads STRATA_DEFAULTS 154put ("STRATA_DEFAULTS" ,"026" ); 155CHECK (nv_default_env (12 ,1 ).empty ()); 156unset ("STRATA_DEFAULTS" ); 157if (fails == 0 ) std::printf ("nv_defaults_test: ok\n" ); 158return fails == 0 ?0 :1 ; 159}