okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
7c5e84612
main
1// batch_read.hpp: the pieces of a --batch prompt read, where the concurrent read runs (synthetic: no model, no GPU). 2#include "strata/program/batch_read.hpp" 3 4#include <cstdio> 5#include <cstring> 6#include <iterator> 7 8using strata::program::batch_read_piece ; 9using strata::program::concurrent_read_off ; 10using strata::program::ConcurrentReadSetup ; 11using strata::program::piped_decode_budget_ms ; 12using strata::program::piped_read_lead_in ; 13using strata::program::piped_read_piece ; 14 15static int fails = 0 ; 16#define CHECK (c ) do { if (!(c)) { std::printf("FAIL %s:%d %s\n", __FILE__, __LINE__, #c); ++fails; } } while (0) 17 18int main () { 19// no --batch, or the pipelined groups: one run 20CHECK (batch_read_piece (false, false, false, false,2048 ,8 )== 0 ); 21CHECK (batch_read_piece (true, true, true, false,2048 ,8 )== 0 ); 22// one GPU: a chunk per piece, whether or not a slot decodes (the yield point is the chunk boundary) 23CHECK (batch_read_piece (true, false, false, false,2048 ,8 )== 2048 ); 24CHECK (batch_read_piece (true, false, false, true,2048 ,8 )== 2048 ); 25// layer split with slots decoding: a chunk per piece as before 26CHECK (batch_read_piece (true, false, true, true,2048 ,8 )== 2048 ); 27// layer split, nobody decoding: pieces of 8 chunks - the BYIELD of a shorter request can be taken (it was one run) 28CHECK (batch_read_piece (true, false, true, false,2048 ,8 )== 8 * 2048 ); 29CHECK (batch_read_piece (true, false, true, false,1024 ,4 )== 4096 ); 30// STRATA_BATCH_YIELD_CHUNKS=0 keeps the old single run 31CHECK (batch_read_piece (true, false, true, false,2048 ,0 )== 0 ); 32// a degenerate chunk never gives a zero piece 33CHECK (batch_read_piece (true, false, false, false,0 ,8 )== 1 ); 34// a piece is always a multiple of the chunk 35for (int64_t c : {256 ,1000 ,2048 ,4096 }) 36for (int64_t k : {1 ,3 ,8 ,16 })CHECK (batch_read_piece (true, false, true, false,c ,k ) %c == 0 ); 37// concurrent_read_off (STRATA_PIPED_CONCURRENT): runs with nothing set; each setting alone keeps it off, named 38CHECK (concurrent_read_off ({})== nullptr ); 39bool ConcurrentReadSetup ::* const each []= { 40& ConcurrentReadSetup ::prefill_help ,& ConcurrentReadSetup ::split_mtp_batch ,& ConcurrentReadSetup ::fs_slots , 41& ConcurrentReadSetup ::pcie_dma ,& ConcurrentReadSetup ::helper_caches ,& ConcurrentReadSetup ::staged_source , 42& ConcurrentReadSetup ::other_source }; 43const char * named [std::size (each )]= {}; 44auto same = [](const char * a ,const char * b ) {return a != nullptr && b != nullptr && std::strcmp (a ,b )== 0 ; }; 45for (size_t i = 0 ;i < std::size (each );++ i ) { 46ConcurrentReadSetup s ; 47s .*each [i ]= true; 48named [i ]= concurrent_read_off (s ); 49CHECK (named [i ]!= nullptr ); 50for (size_t j = 0 ;j < i ;++ j )CHECK (!same (named [i ],named [j ]));// a reason of its own 51 } 52CHECK (same (named [0 ],"STRATA_PREFILL_HELP" )); 53CHECK (same (named [3 ],"--pcie-mode dma" )); 54// with several, the first in the struct's order is named 55for (size_t i = 0 ;i < std::size (each );++ i ) { 56ConcurrentReadSetup s ; 57for (size_t j = i ;j < std::size (each );++ j )s .*each [j ]= true; 58CHECK (same (concurrent_read_off (s ),named [i ])); 59 } 60// piped_read_piece (#1906): off -> one run; whole chunks, at least one, at most 32 61CHECK (piped_read_piece (0 ,8192 )== 0 ); 62CHECK (piped_read_piece (-5 ,8192 )== 0 ); 63CHECK (piped_read_piece (32768 ,8192 )== 32768 ); 64CHECK (piped_read_piece (20000 ,8192 )== 16384 );// rounded down to whole chunks 65CHECK (piped_read_piece (4096 ,8192 )== 8192 );// never below one chunk 66CHECK (piped_read_piece (1 <<30 ,8192 )== 32 * 8192 ); 67CHECK (piped_read_piece (5000 ,0 )== 32 );// chunk 0 guarded as 1 (and the cap applies) 68for (int64_t c : {1024 ,2048 ,6144 ,8192 }) 69for (int64_t p : {1 ,1000 ,9000 ,50000 ,300000 })CHECK (piped_read_piece (p ,c ) %c == 0 );// the header's rule 70// piped_decode_budget_ms: share x piece, capped, floored; negatives are 0 71CHECK (piped_decode_budget_ms (2000.0 ,2.0 ,400.0 ,0.0 )== 400.0 ); 72CHECK (piped_decode_budget_ms (2000.0 ,0.35 ,3000.0 ,0.0 )== 700.0 ); 73CHECK (piped_decode_budget_ms (2000.0 ,0.0 ,400.0 ,150.0 )== 150.0 ); 74CHECK (piped_decode_budget_ms (2000.0 ,2.0 ,0.0 ,0.0 )== 4000.0 );// no cap 75CHECK (piped_decode_budget_ms (-5.0 ,-1.0 ,400.0 ,-3.0 )== 0.0 ); 76// piped_read_lead_in: on, beside decoding slots, within 1000 ms + the budget of the previous piecewise read's end 77CHECK (piped_read_lead_in (true, true,0.0 ,400.0 )); 78CHECK (piped_read_lead_in (true, true,1400.0 ,400.0 )); 79CHECK (!piped_read_lead_in (true, true,1401.0 ,400.0 )); 80CHECK (!piped_read_lead_in (true, true,-1.0 ,400.0 )); 81CHECK (!piped_read_lead_in (false, true,0.0 ,400.0 )); 82CHECK (!piped_read_lead_in (true, false,0.0 ,400.0 )); 83if (fails == 0 ) std::printf ("batch_read_test: ok\n" ); 84return fails == 0 ?0 :1 ; 85}