mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-05 15:58:53 +00:00
On Windows HIP, an auto expert cache with no --vram-reserve-mib kept a floor of 2560 MiB free on any card of 15 GiB or more (#1376, made for a 20 GB discrete card that paged). On a Strix Halo that room is not free: the RAM budget's page-locked complement takes it straight back (cache + complement 71.72 GiB at 2560 and 71.73 GiB at 700 on UD-Q4_K_XL), so the prompt path's own buffers found 0 MiB and the engine stepped its chunk down 16384 ... 1024 for ever; strata launch of a UD-Q4_K_XL config with no reserve (pictures off, or a model with no picture reader) never started. The floor now goes through strata::core::wddm_auto_reserve_mib(integrated, total, current, floor): a discrete card of 15 GiB or more still gets 2560, an integrated GPU (the device property the UMA sizing already reads) keeps the engine's default 700. Discrete cards, Linux and every config that passes --vram-reserve-mib are unchanged (the block is under _WIN32 + STRATA_USE_HIP and behind !vram_reserve_given). Unit test in uma_cache_test. CUDA sm_120 sm build (vendored ggml), base vs change from the same path: the binaries are bit-identical (sha256 2b603395...). Strix (gfx1151, public-0.2.12-style config with no reserve) with the new engine: starts in 77 s and answers 3 chats; the old engine never started it.
46 lines
2.9 KiB
C++
46 lines
2.9 KiB
C++
// include/strata/core/uma_cache.hpp - sizing the GPU expert cache on a device whose memory IS the system RAM.
|
|
//
|
|
// On a Strix Halo (or any APU) "free VRAM" is the GPU-addressable pool: the BIOS carve-out plus the GTT, up to nearly all of the RAM when
|
|
// the kernel was told ttm.pages_limit (docs/STRIX_HALO.md recommends 112 GiB of a 128 GiB box). The expert arena (every expert, in RAM) is
|
|
// already counted in what the OS has used, but the cache copies experts INTO that same RAM, so a cache sized from the pool alone can ask for
|
|
// more bytes than the OS has left - the OOM killer then takes the engine, or the desktop. The auto cache is therefore sized from
|
|
// min(what the GPU says is free, the RAM the OS says is available - a reserve for the desktop). Only the AUTO size: --expert-cache N is
|
|
// kept as asked (the engine warns). STRATA_UMA_RESERVE_GIB=N sets the reserve (0 = no reserve: the old sizing).
|
|
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <cstdlib>
|
|
|
|
namespace strata::core {
|
|
|
|
/// The RAM an integrated GPU's expert cache leaves to the OS and the desktop: STRATA_UMA_RESERVE_GIB when set (0 = none), else the larger of
|
|
/// 8 GiB and 8% of the installed RAM (a desktop session with a browser needs ~6 GiB; 8% is ~10 GiB on 128 GB).
|
|
inline uint64_t uma_desktop_reserve_bytes(uint64_t total_ram, const char* env_gib = std::getenv("STRATA_UMA_RESERVE_GIB")) {
|
|
constexpr uint64_t GiB = 1ull << 30;
|
|
if (env_gib != nullptr && env_gib[0] != '\0') {
|
|
char* end = nullptr;
|
|
const double v = std::strtod(env_gib, &end);
|
|
if (end != env_gib && v >= 0.0) return (uint64_t) (v * (double) GiB);
|
|
}
|
|
const uint64_t pct = total_ram / 100 * 8;
|
|
return pct > 8 * GiB ? pct : 8 * GiB;
|
|
}
|
|
|
|
/// The bytes the auto cache may use: the RAM available now, less the reserve (0 when that is already gone).
|
|
inline uint64_t uma_cache_room_bytes(uint64_t available, uint64_t reserve) {
|
|
return available > reserve ? available - reserve : 0;
|
|
}
|
|
|
|
/// G16 (Q4-P8, 2026-11-08): the reserve the auto cache keeps free on Windows HIP when none was given. A DISCRETE card of 15 GiB or more gets the floor (#1376: a
|
|
/// 20 GB card ended with 323 MiB free at the default 700 and Windows paged); an INTEGRATED GPU (the device property `integrated`, the same test the UMA sizing above
|
|
/// uses) does not: its pool is the RAM, the room the floor frees is taken straight back by the RAM budget's page-locked complement, and on a Strix Halo with
|
|
/// UD-Q4_K_XL the prompt path's own buffers then found 0 MiB and the engine stepped its chunk down for ever. `current_mib` is what the engine would use without
|
|
/// the floor (the default 700); a reserve given on the command line never comes here.
|
|
inline int wddm_auto_reserve_mib(bool integrated, uint64_t total_bytes, int current_mib, int floor_mib = 2560) {
|
|
constexpr uint64_t GiB = 1ull << 30;
|
|
if (integrated || total_bytes < 15 * GiB || current_mib >= floor_mib) return current_mib;
|
|
return floor_mib;
|
|
}
|
|
|
|
} // namespace strata::core
|