engine: the shared-memory page drop only in a Linux CUDA build, its line only when pages were given back

The block that gives the GGUF's cached expert pages back (generate.cpp, after the prompt path is set up) was under no
backend guard. cudaDevAttrIntegrated is true on AMD APUs under HIP (hipDeviceAttributeIntegrated) and on every Mac under
the Metal layer, the gfx906 layer has no such attribute, and Windows has no page drop, so on those builds the block either
ran ungated on a class it was not measured on, printed its line with nothing freed, or did not compile. The whole block
(call and log line) is now inside #if __linux__ && !STRATA_USE_HIP && !STRATA_HIP_GFX906 && !STRATA_GPU_METAL, and the
[DRAFT] line prints only when pages were actually given back. tools/test_uma_drop_guard.py checks that the call, the
setting's reads and the line all sit inside that guard. The register's two read lines follow the move.
This commit is contained in:
Niko1221 committed 2026-11-11 15:45:26 +01:00
1 parent d3d4d16120
commit a5104df5bf
3 files changed
+65 -5

No files matched your search

+2 -2
View File
@@ -40153,13 +40153,13 @@
"reads": [
{
"file": "src/program/generate.cpp",
"line": 11242,
"line": 11246,
"backend": "cuda-hip",
"fn": "getenv"
},
{
"file": "src/program/generate.cpp",
"line": 11259,
"line": 11264,
"backend": "cuda-hip",
"fn": "getenv"
}
+9 -3
View File
@@ -11238,6 +11238,10 @@ int main(int argc, char** argv) {
// ~1 GiB and fell back to the CPU (91 s for a 2048x1536 picture against about 0.5 s on the card). The engine gives
// those pages back; the experts of the slots the prompt path borrows keep theirs (their refill reads them). The
// cache holds the same bytes either way, so no output bit changes. STRATA_UMA_DROP_PAGES=0 keeps the pages (the A/B arm).
// Linux CUDA builds only: an AMD APU (HIP maps the attribute to hipDeviceAttributeIntegrated) is not measured with it, the
// gfx906 layer has no such attribute, Metal reports every Mac as integrated, and Windows has no page drop
// (tools/test_uma_drop_guard.py checks this guard).
#if defined(__linux__) && !defined(STRATA_USE_HIP) && !defined(STRATA_HIP_GFX906) && !defined(STRATA_GPU_METAL) // SPARK-UMA-DROP
if (srcp == &src && gpu_holds_all && !multi_gpu && stages.empty() && [] {
const char* v = std::getenv("STRATA_UMA_DROP_PAGES");
return v == nullptr || v[0] != '0';
@@ -11253,9 +11257,10 @@ int main(int argc, char** argv) {
return sl != strata::core::kNotResident && sl >= keep_from;
});
(void) cudaMemGetInfo(&f1, &tb);
// [DRAFT]: the owner words this line (par/OWNER-WORDING-1111.md, SPARK)
std::fprintf(stderr, "[DRAFT] strata serve: this GPU shares the system memory and holds every expert, so the "
"model file's cached copy of them is given back.\n");
// [DRAFT]: the owner words this line (par/OWNER-WORDING-1111.md, SPARK); only when pages were given back
if (freed > 0)
std::fprintf(stderr, "[DRAFT] strata serve: this GPU shares the system memory and holds every expert, so the "
"model file's cached copy of them is given back.\n");
const char* tr = std::getenv("STRATA_UMA_DROP_PAGES"); // 2: the numbers too (research)
if (tr != nullptr && tr[0] == '2')
std::fprintf(stderr, "strata serve: STRATA_UMA_DROP_PAGES: %.2f GiB of expert pages given back in %.1f ms; "
@@ -11266,6 +11271,7 @@ int main(int argc, char** argv) {
(void) cudaGetLastError();
}
}
#endif // SPARK-UMA-DROP
rss_probe("the prompt path set up");
// layer split across GPUs: a prompt path per stage, each handing its chunk's rows to the next.
// THE CHUNK STEPS DOWN INSTEAD OF EXITING. A split's stage caches are sized after the arena is registered, and
+54
View File
@@ -0,0 +1,54 @@
"""The shared-memory page drop (STRATA_UMA_DROP_PAGES) runs and prints only in a Linux CUDA build.
src/program/generate.cpp gives the GGUF's cached expert pages back on a GPU that reports cudaDevAttrIntegrated (the DGX Spark).
The same attribute is true on AMD APUs under HIP and on every Mac under the Metal layer, the gfx906 layer has no such attribute,
and Windows has no page drop, so the whole block (the call and its log line) must sit inside the one guard that excludes them.
"""
import re
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
GEN = ROOT / "src" / "program" / "generate.cpp"
GUARD = ("#if defined(__linux__) && !defined(STRATA_USE_HIP) && !defined(STRATA_HIP_GFX906) && !defined(STRATA_GPU_METAL)"
" // SPARK-UMA-DROP")
def guarded_span(lines):
"""(first, last) line index of the guarded block: the guard line and its matching #endif."""
start = next(i for i, l in enumerate(lines) if l.strip() == GUARD.strip())
depth = 0
for i in range(start, len(lines)):
s = lines[i].lstrip()
if re.match(r"#\s*if", s):
depth += 1
elif re.match(r"#\s*endif", s):
depth -= 1
if depth == 0:
return start, i
raise AssertionError("the guard has no matching #endif")
class UmaDropGuard(unittest.TestCase):
def setUp(self):
self.lines = GEN.read_text(encoding="utf-8").splitlines()
def test_guard_present_once(self):
self.assertEqual(sum(1 for l in self.lines if l.strip() == GUARD.strip()), 1)
def test_call_and_line_inside_the_guard(self):
first, last = guarded_span(self.lines)
for needle in ("drop_cached_pages(", "holds every expert, so the", "getenv(\"STRATA_UMA_DROP_PAGES\")"):
at = [i for i, l in enumerate(self.lines) if needle in l]
self.assertTrue(at, needle)
for i in at:
self.assertTrue(first < i < last, f"{needle!r} at line {i + 1} is outside the Linux-CUDA guard ({first + 1}-{last + 1})")
def test_line_only_when_pages_were_given_back(self):
first, last = guarded_span(self.lines)
block = "\n".join(self.lines[first:last + 1])
self.assertRegex(block, r"if \(freed > 0\)\s*\n\s*std::fprintf\(stderr, \"\[DRAFT\] strata serve: this GPU shares")
if __name__ == "__main__":
unittest.main()