okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
77287f13e
main
1#include "strata/core/auto_cache.hpp" 2 3#include <cstdio> 4#include <cstdlib> 5 6using namespace strata::core ; 7namespace { 8int checks = 0 ; 9void check (bool ok ,const char * label ) { 10++ checks ; 11if (!ok ) { std::fprintf (stderr ,"FAIL: %s\n" ,label ); std::exit (1 ); } 12} 13constexpr int64_t MiB = 1ll <<20 ; 14} 15 16int main () { 17const int64_t blob = 2560ll * 1024 ;// 2.5 MiB 18const int64_t min_slots = 300 ; 19// the A4000 of #4474: 9951 MiB free after the weights, 700 reserved + 184 draft head 20const int64_t free_b = 9951 * MiB ,reserve_b = (700 + 184 )* MiB ; 21const AutoCacheSlots a = auto_cache_slots (free_b ,reserve_b ,blob ,min_slots ); 22const AutoCacheSlots plain = auto_cache_slots (free_b ,reserve_b ,blob ,min_slots ,0 ); 23check (a .late_priced && !plain .late_priced ,"the late allocation is priced by default and off with late_mib 0" ); 24check (plain .slots == (free_b - reserve_b ) /blob ,"late_mib 0 is the old sizing" ); 25check (a .slots == (free_b - reserve_b - kLateAllocMib * MiB ) /blob ,"the cache leaves reserve + late allocation" ); 26check (plain .slots - a .slots == kLateAllocMib * MiB /blob || plain .slots - a .slots == kLateAllocMib * MiB /blob + 1 , 27"256 MiB fewer bytes: about 100 slots of 2.5 MiB" ); 28// the card ends with the reserve: free - slots*blob - priced - 244 MiB unpriced >= reserve 29check (free_b - a .slots * blob - (184 + 244 )* MiB >=700 * MiB - blob ,"the end free is the reserve, not 241 MiB under it" ); 30// a small card: not enough for min_slots after the late allocation -> the old sizing (#496 lowers the reserve elsewhere) 31const AutoCacheSlots small = auto_cache_slots (1200 * MiB ,700 * MiB ,blob ,min_slots ); 32check (!small .late_priced && small .slots == (500 * MiB ) /blob ,"a card that cannot spare it keeps the old number" ); 33const AutoCacheSlots tiny = auto_cache_slots (900 * MiB ,700 * MiB ,blob ,min_slots ); 34check (!tiny .late_priced && tiny .slots == 80 ,"less than min_slots stays as it was" ); 35check (auto_cache_slots (500 * MiB ,700 * MiB ,blob ,min_slots ).slots == 0 ,"a negative room is no slots" ); 36check (auto_cache_slots (1000 * MiB ,700 * MiB ,0 ,min_slots ).slots == 0 ,"no blob size: no slots, no division" ); 37// exactly at the limit: min_slots after the late allocation 38const int64_t edge_free = reserve_b + (kLateAllocMib * MiB )+ min_slots * blob ; 39check (auto_cache_slots (edge_free ,reserve_b ,blob ,min_slots ).late_priced ,"exactly min_slots after the late allocation: priced" ); 40check (!auto_cache_slots (edge_free - 1 ,reserve_b ,blob ,min_slots ).late_priced ,"one byte less: the old sizing" ); 41 std::printf ("auto_cache_test: %d checks passed\n" ,checks ); 42return 0 ; 43}