--aux-cpus: put the engine's threads that are neither pool workers nor the host on spare CPUs (Linux, off by default)
Header-only placement (include/strata/platform/aux_cpus.hpp): the spare CPU set (the host core's SMT siblings, then CPUs of physical cores with no worker; never a CPU that shares a core with a worker), the list parser, threads the engine creates pin themselves, threads somebody else created (the CUDA driver's) are moved by a sweep over /proc/self/task after the pool exists and at every request; pool workers and the host thread are never moved. --aux-cpus off|auto|LIST / STRATA_AUX_CPUS; per request strata_tune aux_cpus=0|1 (serve/server.py). Default off: the hooks do nothing. tests/platform/aux_cpus_test covers the derivation and live threads (CPU only).
This commit is contained in:
1 parent
f47349002c
commit
91f1e85dd1
13 files changed
+714
-10
No files matched your search
@@ -36,6 +36,7 @@
|
||||
#include "strata/core/weights.hpp"
|
||||
#include "strata/kernels/cpu/expert.hpp"
|
||||
#include "strata/kernels/cpu/pool.hpp"
|
||||
#include "strata/platform/aux_cpus.hpp"
|
||||
#include "strata/kernels/cpu/expert_layout.hpp"
|
||||
#include "strata/kernels/ngram.hpp"
|
||||
#include "strata/kernels/iq_kernels.hpp"
|
||||
@@ -415,6 +416,8 @@ struct Options {
|
||||
strata::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;
|
||||
/// --aux-cpus off|auto|LIST (STRATA_AUX_CPUS): where the non-pool, non-host threads run (strata/platform/aux_cpus.hpp)
|
||||
std::string aux_cpus;
|
||||
/// 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.
|
||||
@@ -852,6 +855,13 @@ void usage() {
|
||||
" 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"
|
||||
" --aux-cpus SET Where the threads that are neither pool workers nor the host thread run (the\n"
|
||||
" adaptive tier's job thread, the prefill helpers, the CUDA driver's threads, ...):\n"
|
||||
" off (the default: wherever they were created), auto (the SMT siblings of the host's\n"
|
||||
" core, then physical cores with no worker; never a CPU that shares a core with a\n"
|
||||
" worker; nothing is done when none is spare) or a CPU list such as 24,26 (Linux; the\n"
|
||||
" host's and the workers' CPUs are dropped from it). Moves threads only, never a\n"
|
||||
" result. STRATA_AUX_CPUS sets it too; a request's strata_tune aux_cpus=0|1 beats it.\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"
|
||||
@@ -1320,10 +1330,13 @@ private:
|
||||
}
|
||||
void loop() {
|
||||
// the job's memcpys stay off the host's core and the pool's: by default the spare SMT sibling of the last
|
||||
// two-thread core (Windows); STRATA_ADAPT_JOB_CPU=<logical cpu>, or -1 for no pinning
|
||||
// two-thread core (Windows); STRATA_ADAPT_JOB_CPU=<logical cpu>, or -1 for no pinning. Without either, --aux-cpus
|
||||
// (off by default) puts the thread on the spare CPUs; an explicit STRATA_ADAPT_JOB_CPU is the user's word over it.
|
||||
const char* c = std::getenv("STRATA_ADAPT_JOB_CPU");
|
||||
const int cpu = c != nullptr ? std::atoi(c) : smt_spare_cpu();
|
||||
if (cpu >= 0) (void) strata::kernels::cpu::pin_current_thread(cpu);
|
||||
if (c != nullptr) strata::aux_cpus::note_owned_thread();
|
||||
else if (cpu < 0) strata::aux_cpus::pin_current_thread();
|
||||
for (;;) {
|
||||
std::function<void()> f;
|
||||
{
|
||||
@@ -1733,6 +1746,15 @@ int main(int argc, char** argv) {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
else if (a == "--aux-cpus") {
|
||||
o.aux_cpus = next("--aux-cpus");
|
||||
std::string aerr;
|
||||
strata::aux_cpus::Config acfg;
|
||||
if (!strata::aux_cpus::parse_spec(o.aux_cpus, acfg, aerr)) {
|
||||
std::fprintf(stderr, "strata generate: %s\n", aerr.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;
|
||||
@@ -1965,6 +1987,17 @@ int main(int argc, char** argv) {
|
||||
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);
|
||||
}
|
||||
{ // --aux-cpus / STRATA_AUX_CPUS: read the CPUs this process may use now, before any thread is pinned; the plan
|
||||
// follows once the pool exists (it needs the workers' CPUs)
|
||||
std::string ac = o.aux_cpus;
|
||||
if (ac.empty())
|
||||
if (const char* e = std::getenv("STRATA_AUX_CPUS")) ac = e;
|
||||
std::string aerr;
|
||||
if (!strata::aux_cpus::configure(ac, aerr)) {
|
||||
std::fprintf(stderr, "strata generate: STRATA_AUX_CPUS: %s\n", aerr.c_str());
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
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",
|
||||
@@ -4273,6 +4306,12 @@ int main(int argc, char** argv) {
|
||||
"(--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");
|
||||
// --aux-cpus: the plan, now the workers' CPUs are known; the threads that exist already (the CUDA driver's) move
|
||||
// now when it is on, the ones created later pin themselves (strata/platform/aux_cpus.hpp)
|
||||
const size_t nw = std::min<size_t>((size_t) pool.workers(), ht.worker_cores.size());
|
||||
std::fprintf(stderr, "%s\n",
|
||||
strata::aux_cpus::set_topology(ht.host_core, std::vector<int>(ht.worker_cores.begin(),
|
||||
ht.worker_cores.begin() + (long) nw)).c_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`
|
||||
@@ -4669,7 +4708,7 @@ int main(int argc, char** argv) {
|
||||
if (!per_layer && srcp == &src && src.unbuffered() && i % 64 == 0) {
|
||||
if (ahead.valid()) ahead.get();
|
||||
else read_batch(i);
|
||||
if (i + 64 < want) ahead = std::async(std::launch::async, read_batch, i + 64);
|
||||
if (i + 64 < want) ahead = std::async(std::launch::async, [&read_batch](int64_t b) { strata::aux_cpus::pin_current_thread(); read_batch(b); }, i + 64);
|
||||
}
|
||||
if (fill_ahead > 0 && i + fill_ahead < want) (void) src.advise_pairs(profile.data() + i + fill_ahead, 1);
|
||||
const int32_t slot = xcache.admit(profile[(size_t) i].first, profile[(size_t) i].second);
|
||||
@@ -8007,6 +8046,7 @@ int main(int argc, char** argv) {
|
||||
std::deque<std::string> in_lines;
|
||||
bool in_eof = false;
|
||||
std::thread([&] {
|
||||
strata::aux_cpus::pin_current_thread();
|
||||
// read(2) on the descriptor, not std::cin: glibc's exit() flushes every stdio stream and waits for
|
||||
// stdin's lock, which getline holds while it waits for input - an engine ending on an error (every
|
||||
// std::exit) would hang in exit() on Linux, and the server would wait for it forever
|
||||
@@ -8152,6 +8192,7 @@ int main(int argc, char** argv) {
|
||||
const int io_limit = wio ? std::atoi(wio) : limit * 10;
|
||||
if (limit > 0)
|
||||
std::thread([limit, io_limit] {
|
||||
strata::aux_cpus::pin_current_thread();
|
||||
strata::core::Progress& p = strata::core::progress();
|
||||
uint64_t last = p.beats.load(), ticks_at = p.ticks.load();
|
||||
auto since = std::chrono::steady_clock::now();
|
||||
@@ -9016,6 +9057,7 @@ int main(int argc, char** argv) {
|
||||
// tuning keys (setup's calibration measures settings without restarting the engine): the PCIe share of
|
||||
// the missed experts and the draft-probability floor, for this request only
|
||||
double req_pcie_frac = o.pcie_frac, req_spec_min_p = o.spec_min_p;
|
||||
int req_aux_cpus = -1; // aux_cpus=0|1: --aux-cpus for this request (-1 = the start-up value)
|
||||
if (endp != nullptr) { // GENI takes the same keys (#75: image requests were always greedy); its
|
||||
// embedding file path is the first token without an =
|
||||
for (;;) {
|
||||
@@ -9042,6 +9084,7 @@ int main(int argc, char** argv) {
|
||||
else if (key == "seed") req_seed = std::strtoull(tok.c_str() + eq + 1, nullptr, 10);
|
||||
else if (key == "pcie_frac") req_pcie_frac = std::clamp((double) fv, 0.0, 1.0);
|
||||
else if (key == "spec_min_p") req_spec_min_p = std::clamp((double) fv, 0.0, 1.0);
|
||||
else if (key == "aux_cpus") req_aux_cpus = std::atoi(tok.c_str() + eq + 1) != 0 ? 1 : 0;
|
||||
// unknown keys are skipped: the ids start at the first token without '='
|
||||
}
|
||||
}
|
||||
@@ -9878,6 +9921,16 @@ int main(int argc, char** argv) {
|
||||
ver.set_sampling(req_sp);
|
||||
if (pipe) ver_b.set_sampling(req_sp); // (reaches the later stage's odd verifier)
|
||||
if (use_mtp) mtp.set_draft_sampling(req_sp); // STRATA_SPEC_COUPLED=1: sampled drafts (a no-op otherwise)
|
||||
{ // aux_cpus=0|1: where the non-pool, non-host threads run for this request (-1 = the start-up --aux-cpus); moves
|
||||
// threads only. An enabled placement is swept at every request: it catches threads created since.
|
||||
static const bool aux_start = strata::aux_cpus::enabled();
|
||||
const bool was_on = strata::aux_cpus::enabled();
|
||||
const bool want = req_aux_cpus < 0 ? aux_start : req_aux_cpus != 0;
|
||||
strata::aux_cpus::set_enabled(want);
|
||||
if (want != was_on)
|
||||
std::fprintf(stderr, "strata serve: aux cpus %s for this request%s\n", strata::aux_cpus::enabled() ? "ON" : "off",
|
||||
want && !strata::aux_cpus::enabled() ? " (asked for, but no CPU is spare: see the start-up line)" : "");
|
||||
}
|
||||
drive.d.pcie_num = std::max(0, std::min(256, (int) (req_pcie_frac * 256.0 + 0.5)));
|
||||
// a layer split: CUDA0's share as asked; a later GPU keeps its own (its link) unless the request sets one
|
||||
for (int st = 0; st < split_drive.n; ++st)
|
||||
@@ -10297,7 +10350,7 @@ int main(int argc, char** argv) {
|
||||
if (!drive.d.usage.empty() && o.adapt_every > 0 && (rounds % o.adapt_every) == 0 && pending.empty() &&
|
||||
!exch_wait) {
|
||||
pl_adapt_done = false;
|
||||
pl_adapt_thr = std::thread([&] { pl_adapt_ok = adapt(); pl_adapt_done = true; });
|
||||
pl_adapt_thr = std::thread([&] { strata::aux_cpus::pin_current_thread(); pl_adapt_ok = adapt(); pl_adapt_done = true; });
|
||||
}
|
||||
return true;
|
||||
};
|
||||
@@ -10794,7 +10847,7 @@ int main(int argc, char** argv) {
|
||||
bool adapt_ok = true;
|
||||
// (--adapt-async 1: the asynchronous tier above instead, ticked before the window)
|
||||
if (!drive.d.usage.empty() && !ajob && ((rounds + 1) % o.adapt_every) == 0)
|
||||
adapt_thr = std::thread([&] { adapt_ok = adapt(); });
|
||||
adapt_thr = std::thread([&] { strata::aux_cpus::pin_current_thread(); adapt_ok = adapt(); });
|
||||
if (!ver.commit(a + 1, err)) {
|
||||
if (adapt_thr.joinable()) adapt_thr.join();
|
||||
std::printf("ERR %s\n", err.c_str());
|
||||
@@ -11907,7 +11960,7 @@ int main(int argc, char** argv) {
|
||||
std::thread adapt_thr;
|
||||
bool adapt_ok = true;
|
||||
if (!drive.d.usage.empty() && ((rounds + 1) % o.adapt_every) == 0)
|
||||
adapt_thr = std::thread([&] { adapt_ok = adapt(); });
|
||||
adapt_thr = std::thread([&] { strata::aux_cpus::pin_current_thread(); adapt_ok = adapt(); });
|
||||
if (!ver.commit(a + 1, err)) {
|
||||
if (adapt_thr.joinable()) adapt_thr.join();
|
||||
std::fprintf(stderr, "strata generate: %s\n", err.c_str());
|
||||
|
||||
Reference in new issue
Block a user