okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
271eb25a6
main
1// The park pools' sizes from the conversation cache's budget (park_pool_policy.hpp), with the cache sizes small machines get. 2#include "strata/core/conversation_memory.hpp" 3#include "strata/core/park_pool_policy.hpp" 4 5#include <cstdio> 6#include <cstdlib> 7 8using namespace strata::core ; 9 10namespace { 11int checks = 0 ; 12void check (bool value ,const char * description ) { 13++ checks ; 14if (!value ) { std::fprintf (stderr ,"FAIL: %s\n" ,description ); std::exit (1 ); } 15} 16constexpr uint64_t MiB = uint64_t (1 ) <<20 ,GiB = uint64_t (1 ) <<30 ; 17constexpr uint64_t kCkpt = 112 * MiB ;// one ready checkpoint on Qwen3.8-Flash-Next (the running state, ~118 MB) 18} 19 20int main () { 21// no cache, no pool 22check (park_pool_plan (0 ,kCkpt ).segpool_mib == 0 && park_pool_plan (0 ,kCkpt ).ckpt_ready == 0 ,"a cache that is off gets no pool" ); 23// the sizes at the cache sizes the automatic rule gives (free RAM after the model is loaded, floor 2560 MiB) 24struct Row {uint64_t free_gib ;int64_t cache ;size_t seg ,ready ; }; 25const Row rows []= { 26 {4 ,0 ,0 ,0 },// under ~5 GiB free: the cache is off, so no pool 27 {8 ,2048 ,512 ,1 },// a 16 GB machine with ~8 GiB free 28 {12 ,3840 ,960 ,2 }, 29 {20 ,7168 ,1792 ,4 },// a 32 GB machine with ~20 GiB free 30 {40 ,8192 ,2048 ,4 },// a 64 GB machine with 40 GiB or more free 31 {200 ,8192 ,2048 ,4 },// a big server: the cache cap is 8 GiB, so the pools stay at 2 GiB and 4 32 }; 33for (const Row & r :rows ) { 34const int64_t cache = auto_conversation_cache_mib (r .free_gib * GiB ,2560 ); 35check (cache == r .cache ,"the automatic cache size for this free RAM" ); 36const ParkPoolPlan p = park_pool_plan ((uint64_t )cache ,kCkpt ); 37check (p .segpool_mib == r .seg && p .ckpt_ready == r .ready ,"the pools for this cache" ); 38// what is held idle at most: the arena plus the ready checkpoints, never more than a third of the cache (34% with rounding) 39check (cache == 0 || (p .segpool_mib * MiB + p .ckpt_ready * kCkpt )* 100 <= (uint64_t )cache * MiB * 34 ,"held idle: at most 34% of the cache" ); 40 } 41// small explicit budgets 42check (park_pool_plan (512 ,kCkpt ).segpool_mib == 128 && park_pool_plan (512 ,kCkpt ).ckpt_ready == 0 ,"a 512 MiB cache: a 128 MiB arena (a quarter), no ready checkpoint (a twelfth is 43 MiB)" ); 43check (park_pool_plan (448 ,kCkpt ).segpool_mib == 0 ,"a 448 MiB cache: a quarter is 112 MiB, under the minimum: no arena" ); 44check (park_pool_plan (1024 ,kCkpt ).segpool_mib == 256 && park_pool_plan (1024 ,kCkpt ).ckpt_ready == 0 ,"a 1 GiB cache: a 256 MiB arena, no ready checkpoint" ); 45check (park_pool_plan (1536 ,kCkpt ).ckpt_ready == 1 && park_pool_plan (1536 ,kCkpt ).segpool_mib == 384 ,"1.5 GiB: one ready checkpoint, a 384 MiB arena" ); 46check (park_pool_plan (4096 ,kCkpt ).ckpt_ready == 3 && park_pool_plan (4096 ,kCkpt ).segpool_mib == 1024 ,"4 GiB: 3 ready checkpoints, a 1 GiB arena" ); 47check (park_pool_plan (1 <<20 ,kCkpt ).segpool_mib == 2048 && park_pool_plan (1 <<20 ,kCkpt ).ckpt_ready == 4 ,"a huge cache: the caps, 2 GiB and 4" ); 48check (park_pool_plan (8192 ,0 ).ckpt_ready == 0 && park_pool_plan (8192 ,0 ).segpool_mib == 2048 ,"an unknown checkpoint size: none ready, the arena as usual" ); 49// a bigger checkpoint (another model) gets fewer ready ones, never more than 4 50check (park_pool_plan (8192 ,400 * MiB ).ckpt_ready == 1 && park_pool_plan (8192 ,30 * MiB ).ckpt_ready == 4 ,"ready checkpoints scale with their size" ); 51// the segment pool is a multiple of 64 MiB (granules and 2 MiB alignment hold) 52for (uint64_t c = 1 ;c < 20000 ;c += 37 ) { 53const size_t s = park_pool_plan (c ,kCkpt ).segpool_mib ; 54check (s == 0 || (s %64 == 0 && s >=kSegpoolMinMib && s <=kSegpoolMaxMib && s <=c /4 ),"an arena is whole 64 MiB steps, between 128 MiB and 2 GiB, within a quarter of the cache" ); 55 } 56// upkeep only while the engine is idle 57check (park_pool_permit (true,64 * MiB )== 0 && park_pool_permit (true,1 )== 0 ,"a request in flight: the upkeep may make nothing" ); 58check (park_pool_permit (false,64 * MiB )== 64 * MiB && park_pool_permit (false,0 )== 0 ,"idle: the upkeep may make what it wants" ); 59 std::printf ("park_pool_policy_test: %d checks passed\n" ,checks ); 60return 0 ; 61}