okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
2613b4de5
main
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 16unsetenv (k ); 17#endif 18} 19static void put (const char * k ,const char * v ) { 20#if defined(_WIN32 ) 21_putenv_s (k ,v ); 22#else 23setenv (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 ) { 27for (const auto & kv :t )if (kv .first == k && kv .second == v )return true; 28return false; 29} 30 31int main () { 32using namespace strata::core ; 33unset ("STRATA_GFX12_DEFAULTS" ); 34unset ("STRATA_DEFAULTS" ); 35unset ("STRATA_HEAD_MIX_MULTI" ); 36// the exact extra: gfx12 only 37CHECK (has (gfx12_exact_extra_env ("gfx1201" ),"STRATA_HEAD_MIX_MULTI" ,"1" )); 38CHECK (has (gfx12_exact_extra_env ("gfx1200:xnack-" ),"STRATA_HEAD_MIX_MULTI" ,"1" )); 39for (const char * other : {"gfx1100" ,"gfx1151" ,"gfx1030" ,"gfx906" ,"gfx1010" ,"" ,"gfx12010" })CHECK (gfx12_exact_extra_env (other ).empty ()); 40CHECK (gfx12_exact_extra_env (nullptr ).empty ()); 41// the off switches 42put ("STRATA_GFX12_DEFAULTS" ,"0" ); 43CHECK (gfx12_exact_extra_env ("gfx1201" ).empty ()); 44unset ("STRATA_GFX12_DEFAULTS" ); 45CHECK (gfx12_exact_extra_env ("gfx1201" , true).empty ());// STRATA_DEFAULTS=026 46CHECK (!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 48apply_arch_defaults ("gfx1201" , false); 49CHECK (std::getenv ("STRATA_HEAD_MIX_MULTI" )!= nullptr && std::string (std::getenv ("STRATA_HEAD_MIX_MULTI" ))== "1" ); 50unset ("STRATA_HEAD_MIX_MULTI" ); 51put ("STRATA_HEAD_MIX_MULTI" ,"0" ); 52apply_arch_defaults ("gfx1201" , false); 53CHECK (std::string (std::getenv ("STRATA_HEAD_MIX_MULTI" ))== "0" ); 54unset ("STRATA_HEAD_MIX_MULTI" ); 55apply_arch_defaults ("gfx1100" , false); 56CHECK (std::getenv ("STRATA_HEAD_MIX_MULTI" )== nullptr ); 57put ("STRATA_GFX12_DEFAULTS" ,"0" ); 58apply_arch_defaults ("gfx1201" , false); 59CHECK (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 61unset ("STRATA_GFX12_DEFAULTS" );unset ("STRATA_SELECT_WMMA" );unset ("STRATA_SELECT_ALT_MIN_TOKENS" ); 62CHECK (has (gfx12_value_changing_env ("gfx1201" , false),"STRATA_SELECT_WMMA" ,"1" )); 63CHECK (has (gfx12_value_changing_env ("gfx1201" , false),"STRATA_SELECT_ALT_MIN_TOKENS" ,"28672" )); 64CHECK (gfx12_value_changing_env ("gfx1201" , true).empty ()); 65for (const char * other : {"gfx1100" ,"gfx1151" ,"gfx1030" ,"gfx906" ,"" ,"gfx12010" })CHECK (gfx12_value_changing_env (other , false).empty ()); 66apply_arch_defaults ("gfx1201" , false); 67CHECK (std::getenv ("STRATA_SELECT_WMMA" )!= nullptr && std::string (std::getenv ("STRATA_SELECT_WMMA" ))== "1" ); 68CHECK (std::getenv ("STRATA_SELECT_ALT_MIN_TOKENS" )!= nullptr && std::string (std::getenv ("STRATA_SELECT_ALT_MIN_TOKENS" ))== "28672" ); 69unset ("STRATA_SELECT_WMMA" );unset ("STRATA_SELECT_ALT_MIN_TOKENS" ); 70put ("STRATA_SELECT_WMMA" ,"0" );// the off switch 71apply_arch_defaults ("gfx1201" , false); 72CHECK (std::string (std::getenv ("STRATA_SELECT_WMMA" ))== "0" ); 73unset ("STRATA_SELECT_WMMA" );unset ("STRATA_SELECT_ALT_MIN_TOKENS" ); 74apply_arch_defaults ("gfx1100" , false); 75CHECK (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 77unset ("STRATA_GFX12_DEFAULTS" );unset ("STRATA_DEFAULTS" );unset ("STRATA_MMQ_KQ" ); 78#if defined(_WIN32 ) 79CHECK (!has (gfx12_value_changing_env ("gfx1201" , false),"STRATA_MMQ_KQ" ,"1" )); 80#else 81CHECK (has (gfx12_value_changing_env ("gfx1201" , false),"STRATA_MMQ_KQ" ,"1" )); 82CHECK (has (gfx12_value_changing_env ("gfx1200:xnack-" , false),"STRATA_MMQ_KQ" ,"1" )); 83for (const char * other : {"gfx1100" ,"gfx1151" ,"gfx1030" ,"gfx906" ,"" ,"gfx12010" })CHECK (!has (gfx12_value_changing_env (other , false),"STRATA_MMQ_KQ" ,"1" )); 84CHECK (!has (gfx12_value_changing_env ("gfx1201" , true),"STRATA_MMQ_KQ" ,"1" ));// STRATA_DEFAULTS=026 85apply_arch_defaults ("gfx1201" , false); 86CHECK (std::getenv ("STRATA_MMQ_KQ" )!= nullptr && std::string (std::getenv ("STRATA_MMQ_KQ" ))== "1" ); 87unset ("STRATA_MMQ_KQ" );unset ("STRATA_SELECT_WMMA" );unset ("STRATA_SELECT_ALT_MIN_TOKENS" ); 88put ("STRATA_MMQ_KQ" ,"0" );// the off switch 89apply_arch_defaults ("gfx1201" , false); 90CHECK (std::string (std::getenv ("STRATA_MMQ_KQ" ))== "0" ); 91unset ("STRATA_MMQ_KQ" );unset ("STRATA_SELECT_WMMA" );unset ("STRATA_SELECT_ALT_MIN_TOKENS" ); 92apply_arch_defaults ("gfx1100" , false); 93CHECK (std::getenv ("STRATA_MMQ_KQ" )== nullptr ); 94put ("STRATA_GFX12_DEFAULTS" ,"0" ); 95apply_arch_defaults ("gfx1201" , false); 96CHECK (std::getenv ("STRATA_MMQ_KQ" )== nullptr ); 97unset ("STRATA_GFX12_DEFAULTS" ); 98#endif 99unset ("STRATA_SELECT_WMMA" );unset ("STRATA_SELECT_ALT_MIN_TOKENS" ); 100put ("STRATA_GFX12_DEFAULTS" ,"0" ); 101apply_arch_defaults ("gfx1201" , false); 102CHECK (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 105CHECK (gfx12_chunk_ceiling (nullptr )== 32768 ); 106CHECK (gfx12_chunk_ceiling ("1" )== 32768 ); 107CHECK (gfx12_chunk_ceiling ("16" )== 16384 ); 108CHECK (gfx12_chunk_ceiling ("0" )== 0 ); 109CHECK (gfx12_chunk_step_down (32768 )== 16384 ); 110CHECK (gfx12_chunk_step_down (16384 )== 8192 ); 111CHECK (gfx12_chunk_step_down (12288 )== 8192 ); 112if (fails == 0 ) std::printf ("gfx12_extra_test: OK\n" ); 113return fails == 0 ?0 :1 ; 114}