okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
2716defb8
main
1// The window limits (include/strata/kernels/window_limits.hpp) and the pipelined-window probe 2// (include/strata/program/pipe_probe.hpp): CPU only, header-only. 3#include "strata/kernels/cpu/expert.hpp" 4#include "strata/kernels/fused_gr.hpp" 5#include "strata/kernels/verify_kernels.hpp" 6#include "strata/program/pipe_probe.hpp" 7 8#include <cstdio> 9#include <cstdlib> 10 11namespace { 12#if defined(_WIN32 ) 13void setenv (const char * k ,const char * v ,int ) {_putenv_s (k ,v ); }// MSVC has _putenv_s only; an empty value unsets it 14void unsetenv (const char * k ) {_putenv_s (k ,"" ); } 15#endif 16int checks = 0 ; 17void check (bool ok ,const char * label ) { 18++ checks ; 19if (!ok ) { std::fprintf (stderr ,"FAIL: %s\n" ,label ); std::exit (1 ); } 20} 21}// namespace 22 23int main () { 24using namespace strata::kernels ; 25check (kVerifyNarrowT == 8 ,"the narrow window is the 0.2.7 one: 8 rows" ); 26check (kWindowMaxT == 8 || kWindowMaxT == 12 || kWindowMaxT == 16 ,"a window holds 8, 12 or 16 rows" ); 27check (kVerifyMaxT == kWindowMaxT ,"kVerifyMaxT is the window limit" ); 28check (kVerifyMaxT >=kVerifyNarrowT ,"the wide window is not narrower than the narrow one" ); 29check (cpu::MAXT == 8 ,"the CPU kernels' tokens per job stay 8 (a wider window is split into jobs)" ); 30check (kFusedGrMaxT == 8 ,"the hyper-connection kernels are built for 8 tokens (a wider window is read in slices)" ); 31check (kFusedGrWideT == kWindowMaxT ,"the caller's token arrays follow the window" ); 32check (kVerifyMaxT * 10 <=256 ,"the resident plan's block holds a full window of 10 routed experts a row" ); 33 34// the probe: off without the environment (no clock read), and a full cycle of events does not fail when it is on 35unsetenv ("STRATA_P4_TIMING" ); 36unsetenv ("STRATA_P4_TRACE" ); 37 { 38 strata::program::PipeProbe off (4 ,4 ); 39check (!off .on ()&& !off .timing (),"the probe is off by default" ); 40check (off .now ()== strata::program::PipeProbe ::Time {},"an off probe reads no clock" ); 41 { strata::program::PipeProbe ::PumpScope s (off ); } 42off .launched (0 ,1 ,off .now ()); 43off .done (0 ,1 ); 44off .flush (); 45 } 46setenv ("STRATA_P4_TIMING" ,"1" ,1 ); 47 { 48 strata::program::PipeProbe on (4 ,4 ); 49check (on .timing (),"STRATA_P4_TIMING turns the timing on" ); 50on .span_start (on .now ()); 51for (int w = 0 ;w < 3 ;++ w ) 52for (int k = 0 ;k < 4 ;++ k ) { 53 strata::program::PipeProbe ::PumpScope s (on ); 54on .busy (2 ,3 ); 55on .free_stage (1 ,k %2 == 0 ); 56const auto before = on .now (); 57on .launched (k ,w ,before ); 58on .polled (before ); 59on .done (k ,w ); 60 strata::program::PipeProbe ::VerdictScope v (on ); 61 } 62on .span_end (10.0 ); 63on .flush (); 64 } 65unsetenv ("STRATA_P4_TIMING" ); 66 std::printf ("window_limits_test: %d checks passed (window %d rows)\n" ,checks , (int )kVerifyMaxT ); 67return 0 ; 68}