mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-04 07:18:50 +00:00
Made by tools/layout/move_0216.py (the commit before this one) on db8e0be9c, the final code head of 0.2.16:
- 75 git mv (renames, so `git log --follow` and blame keep working; packaging/acceptance_matrix.md shows as delete + add because its links
changed too) and 3 removals: SETUP.bat, UPDATE.bat and update.sh (setup.py --update pulls the code now);
- 1,425 path edits in 307 files: root-relative paths in CI, Docker, .gitignore and the release scripts; Markdown links; Python and
Node joins from a root that moved with its folder; explicit edits for code that computes a root or names a moved path; tables of
repository paths inside tests.
engine/ holds what CMake builds (src, include, cmake, metal, sycl, spark, third_party, the C++ tests and benches). app/ is the desktop
app and its host (was apps/). terminal/ is the Terminal in the layout of the installed one (strata.py, setup.py, strata_cli,
strata_control, serve, bin, data, ref, crates, the Python tools and tests). docs/ has the documentation, docs/lang/ the translated
READMEs, docs/history and docs/bench-results. tools/ has the repository's own checks, packaging, docker, research and nix.
tests/core/test_tqp_ref.py is a pytest file and stays with the Python tests (terminal/tests/core/).
AGENTS.md, README.md, LICENSE, setup.sh and START-HERE.bat stay at the root.
No behaviour change: the same command lines, the same sources. For this head a replay of the script gave the same numbers and the path
scan (tools/layout/checks/path_scan.py) reports no hit; the suites and the builds run on this commit next.
65 lines
4.8 KiB
C++
65 lines
4.8 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;
|
|
}
|
|
|
|
/// BATCH SLOTS ON THE STRIX HALO (Windows HIP, integrated GPU): the page-locked memory of a start is the RAM copy of experts (the pinned complement) plus the streamed
|
|
/// K/V that every session pins for the whole --max-context (1.55 GiB a session at 131,072; the main session and every slot). UD-Q4_K_XL, 131,072 tokens, 4 slots,
|
|
/// head 4e1e5f248, complement + pinned K/V in GiB: 20.33 + 7.75 = 28.1 (job strix-20261112-1836-e6f0 / -1854-a210 / -1903-afc9) and 18.00 + 7.75 = 25.75
|
|
/// (-1923-8a6a: the prompt path's 16,384 chunk did not fit, the 6,144 chunk did, then "the OS gave no more page-locked memory" at the verify window) FAILED;
|
|
/// 15.00 + 7.75 = 22.75 (-1937-7dbd) and 8.00 + 7.75 = 15.75 (-1928-0caf) STARTED and served with the 16,384 chunk; three slots at 16.40 + 6.20 = 22.60
|
|
/// (-1834-6629) started. So the RAM copy is capped to what leaves complement + pinned K/V at the level of the largest start that worked, 22.75 GiB (the
|
|
/// largest budget that started, 15 GiB, plus 4 slots' K/V). One bracket (15 works, 18 fails), not a derived limit. The experts left out are read from the SSD.
|
|
inline uint64_t uma_pinned_complement_cap_bytes(uint64_t kv_pinned_bytes) {
|
|
constexpr uint64_t level = (1ull << 30) * 2275 / 100; // 22.75 GiB
|
|
return level > kv_pinned_bytes ? level - kv_pinned_bytes : 0; // 0 = keep no expert in RAM: every expert outside the GPU cache is read from the SSD (a start, not a refusal)
|
|
}
|
|
|
|
/// The cap as the budget that pin_cache_complement takes: a budget of 0 there means "no limit", so "nothing in RAM" is the smallest real budget, 1 byte (no expert's blob
|
|
/// fits in it: the copy is empty and every expert the cache does not hold is read from the SSD). Never an error, never a negative size.
|
|
inline uint64_t uma_pinned_complement_budget_bytes(uint64_t kv_pinned_bytes) {
|
|
const uint64_t cap = uma_pinned_complement_cap_bytes(kv_pinned_bytes);
|
|
return cap > 0 ? cap : 1;
|
|
}
|
|
|
|
} // namespace strata::core
|