okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
47d46ccce
main
1// src/core/uma_cache_test.cpp - the RAM reserve of an integrated GPU's auto expert cache (no GPU needed). 2#include "strata/core/uma_cache.hpp" 3 4#include <cstdio> 5 6static int fails = 0 ; 7#define CHECK (c ) do { if (!(c)) { std::printf("FAIL line %d: %s\n", __LINE__, #c); ++fails; } } while (0) 8 9int main () { 10using namespace strata::core ; 11constexpr uint64_t GiB = 1ull <<30 ; 12// the larger of 8 GiB and 8% of the RAM 13CHECK (uma_desktop_reserve_bytes (32 * GiB ,nullptr )== 8 * GiB ); 14CHECK (uma_desktop_reserve_bytes (64 * GiB ,nullptr )== 8 * GiB );// 8% = 5.1 GiB 15CHECK (uma_desktop_reserve_bytes (128 * GiB ,nullptr )> 10 * GiB );// 8% = 10.2 GiB 16CHECK (uma_desktop_reserve_bytes (128 * GiB ,nullptr )< 11 * GiB ); 17CHECK (uma_desktop_reserve_bytes (0 ,nullptr )== 8 * GiB );// RAM unknown: the floor 18// the person's own figure, 0 included 19CHECK (uma_desktop_reserve_bytes (128 * GiB ,"0" )== 0 ); 20CHECK (uma_desktop_reserve_bytes (128 * GiB ,"4" )== 4 * GiB ); 21CHECK (uma_desktop_reserve_bytes (128 * GiB ,"2.5" )== 2 * GiB + GiB /2 ); 22CHECK (uma_desktop_reserve_bytes (128 * GiB ,"" )> 10 * GiB );// empty: not set 23CHECK (uma_desktop_reserve_bytes (64 * GiB ,"x" )== 8 * GiB );// not a number: ignored 24CHECK (uma_desktop_reserve_bytes (64 * GiB ,"-3" )== 8 * GiB ); 25// the room 26CHECK (uma_cache_room_bytes (100 * GiB ,10 * GiB )== 90 * GiB ); 27CHECK (uma_cache_room_bytes (10 * GiB ,10 * GiB )== 0 ); 28CHECK (uma_cache_room_bytes (5 * GiB ,10 * GiB )== 0 ); 29CHECK (uma_cache_room_bytes (5 * GiB ,0 )== 5 * GiB ); 30// G16: the Windows HIP floor of the auto cache's reserve is for a discrete card of 15 GiB or more only 31CHECK (wddm_auto_reserve_mib (false,20 * GiB ,700 )== 2560 );// a 20 GB discrete card (#1376): the floor 32CHECK (wddm_auto_reserve_mib (false,15 * GiB ,700 )== 2560 );// 15 GiB: the floor (#1709) 33CHECK (wddm_auto_reserve_mib (false,16 * GiB - 1 ,700 )== 2560 );// a 16 GB card reports just under 16 34CHECK (wddm_auto_reserve_mib (false,8 * GiB ,700 )== 700 );// a smaller card keeps its own sizing 35CHECK (wddm_auto_reserve_mib (false,15 * GiB - 1 ,700 )== 700 ); 36CHECK (wddm_auto_reserve_mib (true,94027ull <<20 ,700 )== 700 );// a Strix Halo (94,027 MiB pool): no floor 37CHECK (wddm_auto_reserve_mib (true,20 * GiB ,700 )== 700 );// integrated wins whatever the size 38CHECK (wddm_auto_reserve_mib (false,20 * GiB ,3000 )== 3000 );// a larger reserve is never lowered 39CHECK (wddm_auto_reserve_mib (true,94027ull <<20 ,3000 )== 3000 ); 40// the pinned complement cap with batch slots (UD-Q4_K_XL, 131,072 tokens: 1.55 GiB of pinned K/V a session, the main one and each slot) 41 { 42const uint64_t kv = GiB * 155 /100 ; 43const uint64_t budget38 = 38 * GiB ; 44auto capped = [& ](int sessions ) {const uint64_t c = uma_pinned_complement_cap_bytes (kv * (uint64_t )sessions );return c < budget38 ?c :budget38 ; }; 45// the starts that worked keep their complement: 1 session (solo) 4.62 GiB, 3 (2 slots) 12.47, 4 (3 slots) 16.40 46CHECK (capped (1 )> 4 * GiB + GiB * 62 /100 ); 47CHECK (capped (3 ) >=12 * GiB + GiB * 47 /100 ); 48CHECK (capped (4 ) >=16 * GiB + GiB * 40 /100 ); 49// 4 slots (5 sessions): 22.75 - 7.75 = 15.0 GiB, the largest budget that started (job strix-20261112-1937-7dbd) 50CHECK (capped (5 ) >=14 * GiB + GiB * 99 /100 && capped (5 ) <=15 * GiB + GiB /100 ); 51CHECK (capped (5 )< 18 * GiB );// 18 failed 52// many slots: the K/V alone is over the level (15 sessions x 1.55 GiB = 23.25 > 22.75): the cap is 0 = no RAM copy, and the budget handed to the pin is 1 byte 53// (0 would mean "no limit"): a start with every expert outside the GPU cache read from the SSD, never an error, never a wrapped (negative) size 54CHECK (uma_pinned_complement_cap_bytes (30 * GiB )== 0 ); 55CHECK (uma_pinned_complement_cap_bytes (kv * 15 )== 0 ); 56CHECK (uma_pinned_complement_budget_bytes (30 * GiB )== 1 ); 57CHECK (uma_pinned_complement_budget_bytes (kv * 15 )== 1 ); 58CHECK (uma_pinned_complement_budget_bytes (~0ull )== 1 );// the largest input 59CHECK (uma_pinned_complement_cap_bytes (0 )== GiB * 2275 /100 );// no session at all: the whole level 60CHECK (uma_pinned_complement_cap_bytes (kv * 9 )> 8 * GiB + GiB * 50 /100 );// 8 slots + the main session (9 x 1.55 = 13.95): 8.8 GiB, still a copy 61CHECK (uma_pinned_complement_cap_bytes (kv * 14 )> 0 );// 14 sessions: 1.05 GiB left 62CHECK (uma_pinned_complement_budget_bytes (kv * 5 )== uma_pinned_complement_cap_bytes (kv * 5 ));// above zero the budget is the cap itself 63 } 64if (fails == 0 ) std::printf ("uma_cache_test: all checks passed\n" ); 65return fails == 0 ?0 :1 ; 66}