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++
F12: --host-core first|last (fork 5137b33)
Niko1221076108957c61
diff --git a/include/strata/kernels/cpu/pool.hpp b/include/strata/kernels/cpu/pool.hppindex 662bb03c1..1b25493bc 100644--- a/include/strata/kernels/cpu/pool.hpp+++ b/include/strata/kernels/cpu/pool.hpp@@ -80,8 +80,21 @@ struct CpuTopology {int host_core = -1; ///< Logical core reserved for host thread};+/// Which core the host thread - the layer loop that spins on the GPU's flags - takes when `skip_first` reserves one+/// (--host-core first|last, STRATA_HOST_CORE). `First` is the layout the pool has always used. `Last` (eddoursul's+/// fork, F12) puts the host on the last physical core and lets the workers have the first: Windows sends a GPU's+/// interrupts to one logical processor, usually the first, and every copy that lands raises one (~13 us in the ISR+/// and a DPC), which delays a spinning host there. The placement changes no result, only where threads run. A hybrid+/// CPU keeps `First` (its first core is the best P-core).+enum class HostCore { First, Last };+void set_host_core(HostCore where);+HostCore host_core_setting();+CpuTopology detect_cpu_topology(bool skip_first, PoolAffinity affinity = PoolAffinity::All);+/// The logical processor the host thread is pinned to under the current setting (-1: no topology).+int planned_host_core(PoolAffinity affinity = PoolAffinity::All);+/// One logical processor per PHYSICAL core, so a worker is never scheduled onto an SMT sibling of another/// worker. On the 6-core/12-thread machine this project measures on, `hardware_concurrency()/2` workers on/// logical processors 0..5 would put every worker on a sibling pair and halve the useful bandwidth - which isdiff --git a/src/core/session.cpp b/src/core/session.cppindex 40a44bd12..d87452d0c 100644--- a/src/core/session.cpp+++ b/src/core/session.cpp@@ -544,10 +544,17 @@ bool SessionLoopScratch::init(size_t parts_bytes_in, std::string& err) {// core or its SMT sibling. The symptom is not an error: it is a CPU path at 26.9 GB/s where the same pool// runs at 36.32. It was being done and undone on EVERY token, which is a syscall pair on the critical path// for a property that wants to hold for the whole session.- const std::vector<int> cores = strata::kernels::cpu::physical_cores(false);- if (!cores.empty()) {- pinned_core = strata::kernels::cpu::pin_current_thread(cores[0]);+ // The host's core is the pool's reserved one: the first physical core, or the last with --host-core last (F12).+ const int host_core = strata::kernels::cpu::planned_host_core();+ if (host_core >= 0) {+ pinned_core = strata::kernels::cpu::pin_current_thread(host_core);pinned = pinned_core.valid;+ } else {+ const std::vector<int> cores = strata::kernels::cpu::physical_cores(false);+ if (!cores.empty()) {+ pinned_core = strata::kernels::cpu::pin_current_thread(cores[0]);+ pinned = pinned_core.valid;+ }}return true;}diff --git a/src/kernels/cpu/pool.cpp b/src/kernels/cpu/pool.cppindex 4d0d4fbe8..69411ee92 100644--- a/src/kernels/cpu/pool.cpp+++ b/src/kernels/cpu/pool.cpp@@ -4,6 +4,7 @@#include "strata/kernels/cpu/expert_layout.hpp"#include <algorithm>+#include <atomic>#include <cmath>#include <chrono>#include <immintrin.h>@@ -29,7 +30,31 @@ constexpr uint64_t pack_head(uint32_t epoch, uint32_t n, uint32_t i) {}} // namespace+namespace {+std::atomic<int> g_host_core{(int) HostCore::First};+} // namespace++void set_host_core(HostCore where) { g_host_core.store((int) where); }+HostCore host_core_setting() { return (HostCore) g_host_core.load(); }++static CpuTopology detect_cpu_topology_impl(bool skip_first, PoolAffinity affinity);+CpuTopology detect_cpu_topology(bool skip_first, PoolAffinity affinity) {+ CpuTopology topo = detect_cpu_topology_impl(skip_first, affinity);+ // --host-core last: the host takes the last core, the workers the others (the first included)+ if (skip_first && host_core_setting() == HostCore::Last && !topo.is_hybrid && topo.host_core >= 0 &&+ !topo.worker_cores.empty()) {+ const int last = topo.worker_cores.back();+ topo.worker_cores.pop_back();+ topo.worker_cores.insert(topo.worker_cores.begin(), topo.host_core);+ topo.host_core = last;+ }+ return topo;+}++int planned_host_core(PoolAffinity affinity) { return detect_cpu_topology(true, affinity).host_core; }++static CpuTopology detect_cpu_topology_impl(bool skip_first, PoolAffinity affinity) {CpuTopology topo;#if defined(_WIN32)// Ask the OS rather than assuming a layout. `hardware_concurrency()` returns LOGICAL processors, and ondiff --git a/src/program/generate.cpp b/src/program/generate.cppindex d077d6393..3b551f3aa 100644--- a/src/program/generate.cpp+++ b/src/program/generate.cpp@@ -409,6 +409,8 @@ struct Options {int pool_workers = 0; ///< R2.2: 0 = "all physical cores minus the host's"; >0 overrides/// #272: the pool's core layout; `all` (the default) is the layout it always had, auto / p-cores are opt-instrata::kernels::cpu::PoolAffinity pool_affinity = strata::kernels::cpu::PoolAffinity::All;+ /// --host-core first|last (STRATA_HOST_CORE): the host thread's core (see HostCore in pool.hpp)+ std::string host_core;/// R2.2's first half, as an A/B arm. **ON by default**, because the measurement that justifies it is the/// pool's own drain: 33.7 GB/s against 5/6 x 44.14 = 36.8 for five workers, on a machine whose sixth core/// is reserved for a host thread that has nothing to do while the drain runs.@@ -828,6 +830,11 @@ void usage() {" except the one the host loop spins on (with --pool-affinity auto or\n"" p-cores on a hybrid CPU: P-cores minus 1). A sweep is how the pool's\n"" deviation from `cpu_s2` is attributed.\n"+ " --host-core WHERE The host thread's core: first (the default: the first physical core, as always) or\n"+ " last (the last physical core, the workers on the others). Windows sends a GPU's\n"+ " interrupts to one logical processor, usually the first, and every copy that lands\n"+ " raises one: a spinning host there waits for them. Moves threads only, never a\n"+ " result. Not on hybrid CPUs (STRATA_HOST_CORE sets it too).\n"" --pool-affinity MODE Worker CPU affinity: all (default: one worker per physical core, as\n"" always), auto (hybrid CPUs: P-cores first, then their SMT siblings,\n"" then E-cores) or p-cores (P-cores and their siblings only).\n"@@ -1614,6 +1621,13 @@ int main(int argc, char** argv) {else if (a == "--graph-only") o.graph_only = true;else if (a == "--gpu-only-full") o.gpu_only_full = true;else if (a == "--pool-workers") o.pool_workers = std::atoi(next("--pool-workers"));+ else if (a == "--host-core") {+ o.host_core = next("--host-core");+ if (o.host_core != "first" && o.host_core != "last") {+ std::fprintf(stderr, "strata generate: unknown --host-core value '%s' (expected first or last)\n", o.host_core.c_str());+ return 2;+ }+ }else if (a == "--pool-affinity") {const std::string v = next("--pool-affinity");if (v == "auto") o.pool_affinity = strata::kernels::cpu::PoolAffinity::Auto;@@ -1835,6 +1849,12 @@ int main(int argc, char** argv) {}#endifstrata::core::set_coupled_draft(o.coupled_draft);+ { // --host-core / STRATA_HOST_CORE, before the pool and the session pin any thread+ std::string hc = o.host_core;+ if (hc.empty())+ if (const char* e = std::getenv("STRATA_HOST_CORE")) hc = e;+ if (hc == "last") strata::kernels::cpu::set_host_core(strata::kernels::cpu::HostCore::Last);+ }strata::core::set_peer_portable(o.peer_device >= 1); // multi-GPU: the Portable flag on mapped host buffers only with a peer device (before any allocation)if (o.serve && o.conversation_cache_mib > 0 && (o.prompt_cache == 0 || o.conversation_cache_slots == 0))std::fprintf(stderr, "strata serve: warning: conversation caching is disabled by %s\n",@@ -3760,6 +3780,16 @@ int main(int argc, char** argv) {std::fprintf(stderr, "strata generate: hybrid CPU detected (%d P-cores / %d threads, %d E-cores), pool workers: %d, affinity: %s\n",pool.p_cores(), pool.p_threads(), pool.e_cores(), pool.workers(), aff_str);}+ { // where the threads run (--host-core)+ const strata::kernels::cpu::CpuTopology ht = strata::kernels::cpu::detect_cpu_topology(true, o.pool_affinity);+ std::string on;+ for (int i = 0; i < pool.workers() && i < (int) ht.worker_cores.size(); ++i)+ on += (i > 0 ? "," : "") + std::to_string(ht.worker_cores[(size_t) i]);+ std::fprintf(stderr, "strata generate: %d pool workers on logical processors %s, the host thread on %d%s "+ "(--host-core %s)\n", pool.workers(), on.c_str(), ht.host_core,+ pool.host_works() ? " (draining too)" : "",+ strata::kernels::cpu::host_core_setting() == strata::kernels::cpu::HostCore::Last ? "last" : "first");+ }if (o.no_ple_prefetch) strata::kernels::ple_prefetch_enable(false);// ---- R4's slot storage. Allocated AFTER the weights and the session, so `cudaMemGetInfo` inside `open`// sees the memory this process actually has left rather than the card's idle figure - and refuses with both