diff --git a/CMakeLists.txt b/CMakeLists.txt index 65f86a8649..760867e5ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -277,6 +277,10 @@ if(STRATA_BUILD_TESTS) add_executable(stream_watch_test tests/core/stream_watch_test.cpp) target_include_directories(stream_watch_test PRIVATE include) add_test(NAME stream_watch_test COMMAND stream_watch_test) + # the picture reader's room in the resident RAM mode (owner 11-11, reader on demand): the reserve rule, no GPU + add_executable(reader_room_test tests/core/reader_room_test.cpp) + target_include_directories(reader_room_test PRIVATE include) + add_test(NAME reader_room_test COMMAND reader_room_test) add_executable(logit_bias_test src/core/logit_bias_test.cpp) target_include_directories(logit_bias_test PRIVATE include) add_test(NAME logit_bias_test COMMAND logit_bias_test) diff --git a/include/strata/core/reader_room.hpp b/include/strata/core/reader_room.hpp new file mode 100644 index 0000000000..2656959f1e --- /dev/null +++ b/include/strata/core/reader_room.hpp @@ -0,0 +1,26 @@ +#pragma once +// The picture reader's room when the expert cache cannot give it (owner 11-11, item "picture reader on demand, no reserve up front"). +// +// On one NVIDIA card the server starts the GPU picture reader with the first picture and asks the engine's expert cache to make the +// reader's room then (`VRAM `, --vram-elastic); before the first picture nothing is held back beyond the reserve setup wrote +// (700 MiB). In the resident RAM mode (the RAM copy of the experts the cache does not hold: --resident-experts, --resident-budget-gib, +// or the start's own fallback when RAM is short for the arena) the engine refuses that command ("VRAM: not with the resident low-RAM +// mode"), so the reader would find about 0.4 GiB free and go to the processor (measured on l620, IQ3_S on a card held to 32 GB: +// pictures 1.4-7.7 s on the processor against 0.4-2.1 s on the card). The engine knows that mode before it sizes the cache, so there it +// keeps the reader's room in the reserve, as before the change: the server then finds it free and starts the reader on the card. +// The mode is decided once, at start (the arena / file pass loop); nothing enters it later. + +namespace strata::core { + +/// The reader's room, the same number as the server's VISION_RESERVE_MIB (serve/server.py) and the reader's elastic_mib. +inline constexpr int kReaderRoomMib = 2048; + +/// The VRAM reserve the expert cache is sized with. `vision`: the engine serves pictures (--vision); `vram_elastic`: the cache was +/// asked to give the reader its room on demand (--vram-elastic); `ram_copy_mode`: the resident RAM mode, in which the cache refuses +/// to resize. Only all three together raise the reserve, and never above what was asked when that is larger. +inline int reader_room_reserve_mib(int reserve_mib, bool vision, bool vram_elastic, bool ram_copy_mode) { + if (vision && vram_elastic && ram_copy_mode && reserve_mib < kReaderRoomMib) return kReaderRoomMib; + return reserve_mib; +} + +} // namespace strata::core diff --git a/src/program/generate.cpp b/src/program/generate.cpp index f497177440..d44ee0f08f 100644 --- a/src/program/generate.cpp +++ b/src/program/generate.cpp @@ -19,6 +19,7 @@ #include "strata/platform/io_priority.hpp" #include "strata/core/adapt_async_default.hpp" #include "strata/core/arch_defaults.hpp" +#include "strata/core/reader_room.hpp" #include "strata/core/gfx12_chunk.hpp" #include "strata/core/nv_chunk.hpp" #include "strata/core/nv_defaults.hpp" @@ -7844,6 +7845,16 @@ int main(int argc, char** argv) { srcp = &arena_src; } } // the arena / file pass loop (#4846) + // The picture reader's room in the resident RAM mode (strata/core/reader_room.hpp): there the cache refuses the server's VRAM + // command, so an on-demand reader keeps its room in the reserve, as before the reader went on demand. Decided here, once, before + // the cache is sized; the mode is not entered later. + if (const int keep = strata::core::reader_room_reserve_mib(o.vram_reserve_mib, o.vision, o.vram_elastic && o.serve, + o.resident_cpu_experts); + keep != o.vram_reserve_mib) { + std::fprintf(stderr, "strata generate: the resident RAM mode cannot resize the expert cache, so the picture reader's %d MiB " + "stay in the reserve (%d MiB asked)\n", keep, o.vram_reserve_mib); + o.vram_reserve_mib = keep; + } #if defined(__linux__) // 0.1.43.1: on by default (STRATA_ADAPT_CALLBACK_WARMUP=0 turns it off). Linux threads inherit the creator's CPU mask, and // the host pins itself to one CPU later; a callback thread the driver creates lazily after that would run on the diff --git a/tests/core/reader_room_test.cpp b/tests/core/reader_room_test.cpp new file mode 100644 index 0000000000..4c5cac3f23 --- /dev/null +++ b/tests/core/reader_room_test.cpp @@ -0,0 +1,33 @@ +// The picture reader's room in the resident RAM mode (strata/core/reader_room.hpp): only an engine that serves pictures, was asked for +// the shrinking cache and runs the resident RAM mode keeps the reader's 2,048 MiB in its reserve; every other start keeps its reserve. +#include "strata/core/reader_room.hpp" + +#include + +using namespace strata::core; + +namespace { +int failed = 0; +#define CHECK(x) do { if (!(x)) { std::fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #x); ++failed; } } while (0) +} // namespace + +int main() { + CHECK(kReaderRoomMib == 2048); + // the case: setup's 700 MiB, pictures on, the shrinking cache asked for, the resident RAM mode -> the reader's room is kept + CHECK(reader_room_reserve_mib(700, true, true, true) == 2048); + CHECK(reader_room_reserve_mib(0, true, true, true) == 2048); + // a larger reserve (the person's, the app's, Windows' own) is never lowered + CHECK(reader_room_reserve_mib(2048, true, true, true) == 2048); + CHECK(reader_room_reserve_mib(3000, true, true, true) == 3000); + // any one of the three missing: the reserve as asked (the arena mode shrinks; no pictures; no on-demand reader) + for (int v = 0; v < 2; ++v) + for (int e = 0; e < 2; ++e) + for (int r = 0; r < 2; ++r) + if (!(v && e && r)) CHECK(reader_room_reserve_mib(700, v, e, r) == 700); + if (failed) { + std::fprintf(stderr, "reader_room_test: %d failed\n", failed); + return 1; + } + std::printf("reader_room_test: ok\n"); + return 0; +}