Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
CPU prefill share: not armed by default when the cache holds every expert (#1595)
Niko1221eaaa237e8561
diff --git a/CMakeLists.txt b/CMakeLists.txtindex 782f5caf8..02dd84fe7 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -255,6 +255,11 @@ if(STRATA_BUILD_TESTS)add_executable(split_rules_test tests/program/split_rules_test.cpp)target_include_directories(split_rules_test PRIVATE include)add_test(NAME split_rules_test COMMAND split_rules_test)++ # the default CPU prefill share is not armed when every expert is resident (#1595): header-only rule, no GPU+ add_executable(share_rules_test tests/prefill/share_rules_test.cpp)+ target_include_directories(share_rules_test PRIVATE include)+ add_test(NAME share_rules_test COMMAND share_rules_test)endif()# ---- strata_plan ----------------------------------------------------------diff --git a/include/strata/prefill/share_rules.hpp b/include/strata/prefill/share_rules.hppnew file mode 100644index 000000000..30163430f--- /dev/null+++ b/include/strata/prefill/share_rules.hpp@@ -0,0 +1,18 @@+// include/strata/prefill/share_rules.hpp - when the default CPU prefill share is worth arming (no GPU needed to check).+//+// The share hands the idle CPU pool experts the GPU would otherwise stream over PCIe. With every expert resident in+// the GPU's cache nothing is streamed, so there is nothing to take; arming the default only moves the staged-chunk+// limit and costs ~5% at 1,000 tokens (#1595: V100, 3 rounds x 3 runs). An explicit STRATA_PREFILL_CPU_SHARE is+// honoured by Prefill::arm_cpu_share whatever this says.+#pragma once++#include <cstdint>++namespace strata::prefill::share_rules {++/// resident_slots: the expert cache's live slots; total_pairs: layers x routed experts per layer (<= 0: unknown, arm).+constexpr bool default_share_has_work(int64_t resident_slots, int64_t total_pairs) {+ return total_pairs <= 0 || resident_slots < total_pairs;+}++} // namespace strata::prefill::share_rulesdiff --git a/src/program/generate.cpp b/src/program/generate.cppindex 285954dd6..8b6be7a4d 100644--- a/src/program/generate.cpp+++ b/src/program/generate.cpp@@ -61,6 +61,7 @@#include "strata/program/logits_selection.hpp"#include "strata/program/conv_cache.hpp"#include "strata/program/split_rules.hpp"+#include "strata/prefill/share_rules.hpp"#include "strata/program/message_boundary.hpp"#include "strata/spec/draft_policy.hpp"#include "strata/spec/draft_source.hpp"@@ -6247,7 +6248,13 @@ int main(int argc, char** argv) {// the pool is idle while a prompt is read unless batch slots decode between its parts; with// STRATA_PREFILL_CPU_SHARE the staged-chunk limit before the chunk below sizes the loans (bytes_needed reads it)const bool share_pool = o.batch <= 0 && !o.no_pool;- strata::prefill::Prefill::arm_cpu_share(share_pool, share_pool && stages.empty() && !multi_gpu);+ const bool share_has_work = strata::prefill::share_rules::default_share_has_work(+ (int64_t) xcache.slots(), (int64_t) (g.n_layers * g.n_expert)); // #1595+ if (!share_has_work)+ std::fprintf(stderr, "strata serve: every expert is in the GPU cache (%lld of %lld): the CPU prefill share has "+ "nothing to take, so it is not armed by default (STRATA_PREFILL_CPU_SHARE=auto forces it)\n",+ (long long) xcache.slots(), (long long) (g.n_layers * g.n_expert));+ strata::prefill::Prefill::arm_cpu_share(share_pool, share_pool && stages.empty() && !multi_gpu && share_has_work);void* borrow = nullptr;uint64_t borrow_bytes = 0;int32_t lend_first = -1; // the first slot the prompt path may borrow (its largest chunk)@@ -11166,7 +11173,10 @@ int main(int argc, char** argv) {int64_t pos_start = 0;int64_t spec_pos = 0; // plan v0.3 P6: where the speculative loop starts (0 = not used)strata::prefill::Prefill prefill;- strata::prefill::Prefill::arm_cpu_share(!multi_gpu && !o.no_pool, !multi_gpu && !o.no_pool && o.batch <= 0); // before the chunk below sizes the loan+ // #1595: not by default when the cache holds every expert (nothing to take)+ strata::prefill::Prefill::arm_cpu_share(!multi_gpu && !o.no_pool,+ !multi_gpu && !o.no_pool && o.batch <= 0 &&+ strata::prefill::share_rules::default_share_has_work((int64_t) xcache.slots(), (int64_t) (g.n_layers * g.n_expert))); // before the chunk below sizes the loanbool kvg_started = false; // the elastic K/V took this run's cellsdouble prefill_batched_ms = 0;std::FILE* final_r = o.dump_final_r.empty() ? nullptr : std::fopen(o.dump_final_r.c_str(), "wb");diff --git a/tests/prefill/share_rules_test.cpp b/tests/prefill/share_rules_test.cppnew file mode 100644index 000000000..1789a7081--- /dev/null+++ b/tests/prefill/share_rules_test.cpp@@ -0,0 +1,22 @@+// The default CPU share is not armed when every expert is resident (#1595): no GPU, no model.+#include <cstdio>++#include "strata/prefill/share_rules.hpp"++using strata::prefill::share_rules::default_share_has_work;++static int failed = 0;+#define CHECK(x) do { if (!(x)) { std::fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #x); ++failed; } } while (0)++int main() {+ const long long pairs = 48 * 512;+ CHECK(default_share_has_work(pairs - 1, pairs)); // one expert streams: the share has something to take+ CHECK(default_share_has_work(1500, pairs)); // a 12 GB card: most of them stream+ CHECK(!default_share_has_work(pairs, pairs)); // every expert resident: nothing to take+ CHECK(!default_share_has_work(pairs + 100, pairs)); // a cache with spare slots+ CHECK(default_share_has_work(0, pairs)); // empty cache+ CHECK(default_share_has_work(100000, 0)); // total unknown: keep today's behaviour+ static_assert(!default_share_has_work(10, 10), "constexpr");+ if (failed == 0) std::printf("share_rules_test: ok\n");+ return failed ? 1 : 0;+}