okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
386f9959f
main
1// STRATA_SELECT_TWO_PASS's request and its line where the two-pass scorer cannot run (qsa_two_pass_status.hpp). 2// GPU-free: the parse, quiet when unset or supported, one line per process where unsupported. 3#include "strata/kernels/qsa_two_pass_status.hpp" 4 5#include <cstdio> 6#include <cstdlib> 7#include <string> 8 9namespace tp= strata::kernels::two_pass; 10 11static void check (bool ok ,const char * why ) { 12if (!ok ) { 13 std::fprintf (stderr ,"FAIL: %s\n" ,why ); 14 std::exit (1 ); 15 } 16} 17 18static std::string output (FILE * log ) { 19check (std::fflush (log )== 0 && std::fseek (log ,0 ,SEEK_SET )== 0 ,"rewind the log" ); 20 std::string text ; 21char buf [512 ]; 22while (const size_t n = std::fread (buf ,1 ,sizeof (buf ),log ))text .append (buf ,n ); 23check (!std::ferror (log ),"read the log" ); 24return text ; 25} 26 27static std::string line (const char * where ) { 28return std::string ("strata: STRATA_SELECT_TWO_PASS=1 is not used on " )+ where + 29": the two-pass scorer runs only in the CUDA prompt path's tensor-core selection (sm_80+); the selection is " 30"unchanged\n" ; 31} 32 33int main (int argc ,char ** argv ) { 34check (argc == 2 ,"pass a scratch log path (no GPU or model needed)" ); 35FILE * log = std::fopen (argv [1 ],"w+" ); 36check (log != nullptr ,"open the log" ); 37 38// exactly "1" is on, as the scorer parsed it before; unset or anything else is off and prints nothing anywhere 39check (tp::requested_from ("1" ),"1: on" ); 40const char * off []= {nullptr ,"" ,"0" ,"01" ,"1x" ,"true" ,"1 " ,"2" }; 41for (const char * flag :off ) { 42check (!tp::requested_from (flag ),"not exactly 1: off" ); 43 tp::RequestStatus status (flag ); 44check (!status .requested (),"not requested" ); 45check (!status .on ("HIP" ,log ),"off stays off where unsupported" ); 46check (!status .on (nullptr ,log ),"off stays off where supported" ); 47 } 48check (output (log ).empty (),"no line without the switch" ); 49 50// a supported path returns the request and prints nothing (the engine's per-segment line reports what ran) 51 tp::RequestStatus cuda ("1" ); 52check (cuda .on (nullptr ,log )&& cuda .on (nullptr ,log ),"supported: on" ); 53check (output (log ).empty (),"supported: no line" ); 54 55// each unsupported path the engine names: off, one line, never repeated 56const char * where []= {"HIP" ,"Metal" ,"SYCL" ,"this CUDA card or with STRATA_QSA_WARP" , 57"the layer-major prompt path" }; 58 std::string expected ; 59for (const char * w :where ) { 60 tp::RequestStatus status ("1" ); 61check (!status .on (w ,log ),"unsupported: off" ); 62expected += line (w ); 63check (output (log )== expected ,"unsupported: one line naming the path" ); 64check (!status .on (w ,log )&& !status .on (w ,log ),"unsupported again: off" ); 65check (output (log )== expected ,"unsupported: the line is printed once" ); 66 } 67 68// a layer split can mix cards: a supported query neither uses up the line nor is turned off by an unsupported one 69 tp::RequestStatus mixed ("1" ); 70check (mixed .on (nullptr ,log ),"supported card first" ); 71check (!mixed .on ("this CUDA card or with STRATA_QSA_WARP" ,log ),"then an unsupported card" ); 72check (mixed .on (nullptr ,log ),"the supported card stays on" ); 73expected += line ("this CUDA card or with STRATA_QSA_WARP" ); 74check (output (log )== expected ,"the unsupported card's line once" ); 75 76check (std::fclose (log )== 0 ,"close the log" ); 77check (std::remove (argv [1 ])== 0 ,"remove the log" ); 78 std::puts ("qsa_two_pass_status_test: OK" ); 79return 0 ; 80}