feat(cpu): add hybrid architecture awareness and --pool-affinity for P/E-core CPUs

- Add detect_cpu_topology() for Windows (GetLogicalProcessorInformationEx) and Linux (/sys/devices/system/cpu/cpu*/cpu_capacity)
- Identify hybrid P/E-core topology and SMT sibling structures
- Prioritize primary P-cores for worker allocation, reserving core 0 for host thread
- Default pool_workers to (p_cores - 1) on hybrid CPUs when unspecified
- Add --pool-affinity auto|p-cores|all CLI option
- Maintain 100% backward compatibility on non-hybrid CPUs and default configs
This commit is contained in:
Pravesh Khatana authored and Niko1221 committed 2026-10-01 08:47:28 +02:00
1 parent 029e10d9d9
commit 69743d3a5c
3 files changed
+261 -35

No files matched your search

+23 -3
View File
@@ -256,6 +256,7 @@ struct Options {
bool graph_only = false;
bool gpu_only_full = false; ///< R0.3: pre + post + head, the true per-token GPU floor
int pool_workers = 0; ///< R2.2: 0 = "all physical cores minus the host's"; >0 overrides
strata::kernels::cpu::PoolAffinity pool_affinity = strata::kernels::cpu::PoolAffinity::Auto;
/// 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.
@@ -550,8 +551,11 @@ void usage() {
" pool is six threads on six cores instead of five plus an idle core;\n"
" this flag restores the five-worker form for comparison on `pool phases`.\n"
" --pool-workers N R2.2: CPU expert pool worker count. Default 0 = every physical core\n"
" except the one the host loop spins on. A sweep is how the pool's\n"
" deviation from `cpu_s2` is attributed.\n"
" except the one the host loop spins on (or P-core count minus 1 on\n"
" hybrid CPUs). A sweep is how the pool's deviation from `cpu_s2` is attributed.\n"
" --pool-affinity MODE Worker CPU affinity: auto (default: prioritize P-cores), p-cores\n"
" (strictly performance cores), or all (all physical cores without\n"
" hybrid distinction).\n"
" --coupled-draft enable coupled draft sampling for MTP drafter under sampling (STRATA_SPEC_COUPLED)\n"
" --no-coupled-draft disable coupled draft sampling (propose argmax drafts)\n"
" --mmap-experts R2.1: opt OUT of the resident expert arena, back to MapViewOfFile.\n"
@@ -1081,6 +1085,16 @@ 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 == "--pool-affinity") {
const std::string v = next("--pool-affinity");
if (v == "auto") o.pool_affinity = strata::kernels::cpu::PoolAffinity::Auto;
else if (v == "p-cores" || v == "pcores") o.pool_affinity = strata::kernels::cpu::PoolAffinity::PCores;
else if (v == "all") o.pool_affinity = strata::kernels::cpu::PoolAffinity::All;
else {
std::fprintf(stderr, "strata generate: unknown --pool-affinity value '%s' (expected auto, p-cores, or all)\n", v.c_str());
return 2;
}
}
else if (a == "--no-host-worker") o.no_host_worker = true;
else if (a == "--no-ple-prefetch") o.no_ple_prefetch = true;
else if (a == "--coupled-draft") o.coupled_draft = true;
@@ -2521,7 +2535,13 @@ int main(int argc, char** argv) {
#endif
srcp = &arena_src;
}
strata::kernels::cpu::ExpertPool pool(o.pool_workers, /*pin=*/true, /*host_works=*/!o.no_host_worker);
strata::kernels::cpu::ExpertPool pool(o.pool_workers, /*pin=*/true, /*host_works=*/!o.no_host_worker, o.pool_affinity);
if (pool.is_hybrid()) {
const char* aff_str = pool.affinity() == strata::kernels::cpu::PoolAffinity::PCores ? "p-cores" :
pool.affinity() == strata::kernels::cpu::PoolAffinity::All ? "all" : "auto";
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);
}
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