okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
513fd0cff
main
1// The elastic K/V once the expert cache is known (strata/core/kv_grow_rules.hpp): pools made elastic always grow, from 2// the cache's slots only when the cache can give them, else from new VRAM; a grow covers the request, never past the context. 3#include "strata/core/kv_grow_rules.hpp" 4 5#include <cstdio> 6 7using namespace strata::core ; 8 9namespace { 10int failed = 0 ; 11#define CHECK (x ) do { if (!(x)) { std::fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #x); ++failed; } } while (0) 12}// namespace 13 14int main () { 15// pools not elastic (no --kv-grow, or it was turned off at init): nothing to grow 16CHECK (!kv_grow_start (false, true, true, true,9000 ,128 ).on ); 17CHECK (!kv_grow_start (false, true, true, true,9000 ,128 ).from_cache ); 18// every condition met: grows from the cache's slots 19CHECK (kv_grow_start (true, true, true, true,9000 ,128 ).on ); 20CHECK (kv_grow_start (true, true, true, true,9000 ,128 ).from_cache ); 21// the refused states: the pools are elastic, so the K/V still grows (new VRAM), the cache gives nothing 22const KvGrowStart floor_hit = kv_grow_start (true, true, true, true,128 ,128 );// --expert-cache 100 -> 128 slots 23CHECK (floor_hit .on && !floor_hit .from_cache ); 24CHECK (kv_grow_start (true, true, true, true,0 ,128 ).on );// a loan that starts at slot 0 25CHECK (!kv_grow_start (true, true, true, true,0 ,128 ).from_cache ); 26CHECK (kv_grow_start (true, false, true, true,9000 ,128 ).on );// no VMM range for the cache 27CHECK (!kv_grow_start (true, false, true, true,9000 ,128 ).from_cache ); 28CHECK (kv_grow_start (true, true, false, true,9000 ,128 ).on );// no residency table 29CHECK (!kv_grow_start (true, true, false, true,9000 ,128 ).from_cache ); 30CHECK (kv_grow_start (true, true, true, false,9000 ,128 ).on );// no expert source 31CHECK (!kv_grow_start (true, true, true, false,9000 ,128 ).from_cache ); 32CHECK (kv_grow_start (true, true, true, true,129 ,128 ).from_cache );// one slot above the floor 33// the grow target: whole steps, covering the request, at most the context (never a smaller context) 34CHECK (kv_grow_target (20256 ,8192 ,131072 )== 24576 ); 35CHECK (kv_grow_target (16384 ,8192 ,131072 )== 16384 ); 36CHECK (kv_grow_target (16385 ,8192 ,131072 )== 24576 ); 37CHECK (kv_grow_target (1 ,8192 ,131072 )== 8192 ); 38CHECK (kv_grow_target (130000 ,8192 ,131072 )== 131072 ); 39CHECK (kv_grow_target (131072 + 256 ,8192 ,131072 )== 131072 ); 40for (int64_t c = 1 ;c <=131072 ;c += 997 ) { 41const int64_t t = kv_grow_target (c ,8192 ,131072 ); 42CHECK (t >=c && t <=131072 && t %8192 == 0 ); 43 } 44for (int64_t c = 1 ;c <=100000 ;c += 991 )CHECK (kv_grow_target (c ,8192 ,100000 ) >=c ); 45if (failed ) { 46 std::fprintf (stderr ,"kv_grow_rules_test: %d failed\n" ,failed ); 47return 1 ; 48 } 49 std::printf ("kv_grow_rules_test: ok\n" ); 50return 0 ; 51}