okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
420e03b12
main
1// own_only_switches (include/strata/prefill/own_only_switches.hpp): the opt-in fused-kernel switches a build without MMQ turns on by default. No GPU, no model. 2#include <cstdio> 3#include <cstring> 4#include <string> 5#include <utility> 6#include <vector> 7 8#include "strata/prefill/own_only_switches.hpp" 9 10using strata::prefill::own_only_default_switches ; 11using strata::prefill::own_only_switch_on ; 12 13static int failed = 0 ; 14#define CHECK (x ) do { if (!(x)) { std::fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #x); ++failed; } } while (0) 15 16int main () { 17// CUDA: the list the build had before the Q2_0 kernel joined, in its order, then the Q2_0 / Q2_0 switch last 18const std::vector < std::string > cuda_before = {"STRATA_PF_FUSED" ,"STRATA_PF_FUSED_Q50" ,"STRATA_PF_FUSED_Q8D" ,"STRATA_PF_FUSED_Q8GU" , 19"STRATA_PF_FUSED_Q6K" ,"STRATA_PF_FUSED_KQ" ,"STRATA_PF_FUSED_TQ" ,"STRATA_PF_FUSED_SM75" }; 20const auto cuda = own_only_default_switches (false); 21CHECK (cuda .size ()== cuda_before .size ()+ 1 ); 22for (size_t i = 0 ;i < cuda_before .size ()&& i < cuda .size ();++ i )CHECK (cuda_before [i ]== cuda [i ]); 23CHECK (own_only_switch_on ("STRATA_PF_FUSED_Q2N" , false)); 24// HIP: unchanged (the gfx12 Q2_0 kernel is a default of its own there); no Turing switch, no Q2N 25const std::vector < std::string > hip_before = {"STRATA_PF_FUSED" ,"STRATA_PF_FUSED_Q50" ,"STRATA_PF_FUSED_Q8D" ,"STRATA_PF_FUSED_Q8GU" , 26"STRATA_PF_FUSED_Q6K" ,"STRATA_PF_FUSED_KQ" ,"STRATA_PF_FUSED_TQ" }; 27const auto hip = own_only_default_switches (true); 28CHECK (hip .size ()== hip_before .size ()); 29for (size_t i = 0 ;i < hip_before .size ()&& i < hip .size ();++ i )CHECK (hip_before [i ]== hip [i ]); 30CHECK (!own_only_switch_on ("STRATA_PF_FUSED_Q2N" , true)); 31CHECK (!own_only_switch_on ("STRATA_PF_FUSED_SM75" , true)); 32CHECK (own_only_switch_on ("STRATA_PF_FUSED_SM75" , false)); 33// names that are not in the list stay off (the other opt-ins of the kernels are not defaults) 34CHECK (!own_only_switch_on ("STRATA_PF_FUSED_SM86" , false)); 35CHECK (!own_only_switch_on ("STRATA_PF_FUSED_IQ2S" , false)); 36CHECK (!own_only_switch_on ("" , false)); 37// no name twice 38for (size_t i = 0 ;i < cuda .size ();++ i ) 39for (size_t j = i + 1 ;j < cuda .size ();++ j )CHECK (std::strcmp (cuda [i ],cuda [j ])!= 0 ); 40// the recorder: a fake environment; a name that was there before the initialiser ran is the user's and is not recorded, the others are set and recorded in list order 41 { 42 std::vector < std::pair < std::string , std::string >> env ;// name -> value 43const auto get = [& ](const char * k )-> const char * { 44for (const auto & kv :env ) 45if (kv .first == k )return kv .second .c_str (); 46return nullptr ; 47 }; 48const auto set = [& ](const char * k ) {env .emplace_back (k ,"1" ); }; 49 std::vector < std::string > rec ; 50env .emplace_back ("STRATA_PF_FUSED_Q8D" ,"0" );// the user named one of them (their way back) 51 strata::prefill::own_only_apply_defaults (false,get ,set ,rec ); 52CHECK (rec .size ()== cuda .size ()- 1 ); 53CHECK (!strata::prefill::own_only_set_by_build ("STRATA_PF_FUSED_Q8D" ,rec )); 54CHECK (std::string (get ("STRATA_PF_FUSED_Q8D" ))== "0" );// kept 55CHECK (strata::prefill::own_only_set_by_build ("STRATA_PF_FUSED" ,rec )); 56CHECK (std::string (get ("STRATA_PF_FUSED" ))== "1" ); 57CHECK (strata::prefill::own_only_set_by_build ("STRATA_PF_FUSED_Q2N" ,rec )); 58// "named by the user" (what the small-card rule reads): the build's own STRATA_PF_FUSED=1 is not, the same text from the user is, "" is neither 59CHECK (!strata::prefill::own_only_user_named ("STRATA_PF_FUSED" ,get ("STRATA_PF_FUSED" ),rec )); 60CHECK (strata::prefill::own_only_user_named ("STRATA_PF_FUSED_Q8D" ,get ("STRATA_PF_FUSED_Q8D" ),rec )); 61CHECK (!strata::prefill::own_only_user_named ("STRATA_PF_FUSED" ,nullptr ,rec )); 62CHECK (!strata::prefill::own_only_user_named ("STRATA_PF_FUSED_Q8D" ,"" ,rec )); 63// a user who set STRATA_PF_FUSED itself (either value) before the initialiser: not recorded, so still the user's 64for (const char * v : {"1" ,"0" }) { 65env .clear (); 66rec .clear (); 67env .emplace_back ("STRATA_PF_FUSED" ,v ); 68 strata::prefill::own_only_apply_defaults (false,get ,set ,rec ); 69CHECK (!strata::prefill::own_only_set_by_build ("STRATA_PF_FUSED" ,rec )); 70CHECK (strata::prefill::own_only_user_named ("STRATA_PF_FUSED" ,get ("STRATA_PF_FUSED" ),rec )); 71CHECK (std::string (get ("STRATA_PF_FUSED" ))== v ); 72 } 73// nothing set: every name of the list is the build's; the HIP list is shorter 74env .clear (); 75rec .clear (); 76 strata::prefill::own_only_apply_defaults (true,get ,set ,rec ); 77CHECK (rec .size ()== hip .size ()); 78CHECK (strata::prefill::own_only_set_by_build ("STRATA_PF_FUSED" ,rec )); 79CHECK (!strata::prefill::own_only_set_by_build ("STRATA_PF_FUSED_SM75" ,rec )); 80// the process-wide list is empty until the engine's initialiser (a binary that does not link prefill.cpp) runs 81CHECK (strata::prefill::own_only_recorded ().empty ()); 82CHECK (!strata::prefill::own_only_user_named ("STRATA_PF_FUSED" ,nullptr )); 83CHECK (strata::prefill::own_only_user_named ("STRATA_PF_FUSED" ,"1" ));// no record: the user's 84CHECK (!strata::prefill::own_only_build ());// not an engine without MMQ until its initialiser says so 85 strata::prefill::own_only_build_flag ()= true; 86CHECK (strata::prefill::own_only_build ()); 87 } 88if (failed ) { 89 std::fprintf (stderr ,"own_only_switches_test: %d check(s) failed\n" ,failed ); 90return 1 ; 91 } 92 std::printf ("own_only_switches_test: OK\n" ); 93return 0 ; 94}