mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-06 00:08:52 +00:00
Merge f-numa-card2: on two-socket Linux machines the engine runs on the graphics card's NUMA node
On a Linux machine with two or more memory nodes, the engine now restricts itself at start-up to the CPUs of the node the graphics card is attached to, before the CPU pool and the helper threads start. Decode with CPU experts on a two-socket RTX 5090 host: a 32-worker pool on one node read 1.11-1.18 of the two-node default over three rounds (UD 4-bit set). The process is left as it is when any of these is not met: Linux, the process's CPUs span more than one node, every card used reports the same known node, that node can hold the pinned K/V copy and staging buffers, the threads were not placed by hand (--pool-cores, STRATA_NUMA_SPLIT, --aux-cpus), the CPU is not hybrid, and the pool keeps its worker count on that node alone. A taskset, numactl or cpuset restriction is kept. The background copy threads (checkpoints and parking) now also stay inside the process's CPU set. STRATA_NUMA_CARD=0 turns it off. On one-node machines the output is identical to STRATA_NUMA_CARD=0. With STRATA_TRACE the engine prints one "strata trace: card node: ..." line with the inputs and the decision. No user text changes outside STRATA_TRACE.
This commit is contained in:
commit
2e279f7583
7 files changed
+970
-10
No files matched your search
@@ -63,6 +63,9 @@
|
||||
#include "strata/kernels/gfx_arch.hpp"
|
||||
#include "strata/kernels/cpu/expert.hpp"
|
||||
#include "strata/kernels/cpu/pool.hpp"
|
||||
#include "strata/kernels/cpu/card_node.hpp"
|
||||
#include "strata/kernels/cpu/numa_pool.hpp"
|
||||
#include "strata/platform/home_cpus.hpp"
|
||||
#include "strata/platform/aux_cpus.hpp"
|
||||
#include "strata/kernels/cpu/expert_layout.hpp"
|
||||
#include "strata/kernels/cpu/hadamard.hpp"
|
||||
@@ -2495,11 +2498,9 @@ public:
|
||||
static void spread_current_thread() {
|
||||
#if defined(__linux__)
|
||||
// wide first: the mask the aux placement keeps as this thread's own is the one restore() puts back (a request
|
||||
// with aux_cpus=0), and the host's one CPU must not be it
|
||||
cpu_set_t all;
|
||||
CPU_ZERO(&all);
|
||||
for (int c = 0; c < CPU_SETSIZE; ++c) CPU_SET(c, &all);
|
||||
(void) sched_setaffinity(0, sizeof all, &all); // the kernel keeps the CPUs the process may use
|
||||
// with aux_cpus=0), and the host's one CPU must not be it; wide = the process's CPU set from the start-up
|
||||
// (strata/platform/home_cpus.hpp)
|
||||
strata::platform::widen_to_home(); // the kernel keeps the CPUs the cgroup allows
|
||||
strata::aux_cpus::pin_current_thread(); // (a no-op while the feature is off)
|
||||
#endif
|
||||
}
|
||||
@@ -4171,6 +4172,87 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
#endif
|
||||
strata::core::set_coupled_draft(o.coupled_draft);
|
||||
#if defined(__linux__) && !defined(STRATA_GPU_METAL)
|
||||
{ // THE CARD'S NUMA NODE (strata/kernels/cpu/card_node.hpp): on a machine with two or more memory nodes the process
|
||||
// restricts itself to the CPUs of the card's node, here, before the pool, the host thread and the stagers exist
|
||||
// and before the first large allocation, so every thread and the pinned memory they touch first follow. One node,
|
||||
// STRATA_NUMA_CARD=0, or any case decide_card_node leaves as it is: nothing changes.
|
||||
namespace kc = strata::kernels::cpu;
|
||||
kc::CardNodeInput ci;
|
||||
ci.switch_off = kc::card_node_switch_off(std::getenv("STRATA_NUMA_CARD"));
|
||||
const std::map<int, std::vector<int>> node_cpus =
|
||||
ci.switch_off ? std::map<int, std::vector<int>>{} : kc::card_node_node_cpus("/sys");
|
||||
ci.nodes_with_cpus = ci.switch_off ? 1 : (std::max)(1, (int) node_cpus.size());
|
||||
std::string cards_text;
|
||||
if (!ci.switch_off && ci.nodes_with_cpus >= 2) {
|
||||
ci.mask = kc::card_node_describe("/sys", kc::card_node_thread_cpus(), node_cpus);
|
||||
std::string status;
|
||||
if (kc::card_node_read_file("/proc/self/status", status)) ci.mems_known = kc::card_node_mems_allowed(status, ci.mems_allowed);
|
||||
// the cards the run uses: the primary one; with a layer split, helper caches or a peer card, every visible one
|
||||
const char* pv = std::getenv("STRATA_PRIMARY_DEVICE");
|
||||
const int primary = pv != nullptr && std::atoi(pv) > 0 ? std::atoi(pv) : 0;
|
||||
bool several = !o.layer_split.empty() || o.peer_device >= 1;
|
||||
for (int r = 0; r < 3; ++r) several = several || o.expert_cache_remote[(size_t) r] > 0 || o.expert_cache_remote_auto[(size_t) r];
|
||||
int n_dev = 0;
|
||||
if (cudaGetDeviceCount(&n_dev) != cudaSuccess) n_dev = 0;
|
||||
(void) cudaGetLastError();
|
||||
for (int d = several ? 0 : primary; d < n_dev && (several || d == primary); ++d) {
|
||||
cudaDeviceProp p{};
|
||||
int node = -1;
|
||||
std::string bdf = "?";
|
||||
if (cudaGetDeviceProperties(&p, d) == cudaSuccess) {
|
||||
bdf = kc::card_node_bdf((unsigned) p.pciDomainID, (unsigned) p.pciBusID, (unsigned) p.pciDeviceID);
|
||||
node = kc::card_node_pci_node("/sys", bdf);
|
||||
} else {
|
||||
(void) cudaGetLastError();
|
||||
}
|
||||
ci.card_nodes.push_back(node);
|
||||
cards_text += (cards_text.empty() ? "" : ", ") + std::string("CUDA") + std::to_string(d) + " " + bdf + " node " + std::to_string(node);
|
||||
}
|
||||
if (ci.card_nodes.empty() && primary >= n_dev) ci.card_nodes.push_back(-1); // the primary is not visible: unknown
|
||||
if (!ci.card_nodes.empty()) ci.card_node_free_bytes = kc::card_node_free_bytes("/sys", ci.card_nodes.front());
|
||||
ci.pinned_need_bytes = kc::card_node_pinned_need(o.max_context);
|
||||
// the person placed the threads: their placement stays
|
||||
std::string pc = o.pool_cores, ac = o.aux_cpus;
|
||||
if (pc.empty())
|
||||
if (const char* e = std::getenv("STRATA_POOL_CORES")) pc = e;
|
||||
if (ac.empty())
|
||||
if (const char* e = std::getenv("STRATA_AUX_CPUS")) ac = e;
|
||||
const char* split_env = std::getenv("STRATA_NUMA_SPLIT");
|
||||
if (!pc.empty()) ci.user_placed = "--pool-cores is set";
|
||||
else if (split_env != nullptr && *split_env != '\0') ci.user_placed = "STRATA_NUMA_SPLIT is set";
|
||||
else if (!ac.empty() && ac != "auto" && ac != "off") ci.user_placed = "an --aux-cpus list is set";
|
||||
// the pool's worker count without the rule, as ExpertPool picks it (the span plan when the per-node split may run)
|
||||
const kc::CpuTopology topo = kc::detect_cpu_topology(true, o.pool_affinity);
|
||||
ci.hybrid = topo.is_hybrid;
|
||||
ci.cpu_quota = topo.cpu_quota;
|
||||
ci.user_workers = o.pool_workers > 0 ? o.pool_workers : 0;
|
||||
kc::PoolPlanInput pin = kc::pool_plan_input(topo);
|
||||
pin.span_packages = kc::pick_numa_pool(std::getenv("STRATA_NUMA_POOL"), split_env, ci.nodes_with_cpus).choice ==
|
||||
kc::NumaPoolChoice::Auto;
|
||||
ci.today_workers = ci.user_workers > 0 ? ci.user_workers
|
||||
: (std::min)(kc::plan_pool_workers(pin).workers,
|
||||
(std::max)(1, (int) topo.worker_cores.size()));
|
||||
}
|
||||
const kc::CardNodeDecision cd = kc::decide_card_node(ci);
|
||||
int moved = 0, refused = 0;
|
||||
if (cd.on) moved = kc::restrict_process_cpus(cd.cpus, refused);
|
||||
// the threads that widen their mask later (background copies, checkpoint helpers) widen to the process's CPU set
|
||||
// as it is now: the card's node, or the set the process was started with (a taskset is kept); the switch off:
|
||||
// every CPU, as before
|
||||
if (!ci.switch_off) strata::platform::set_home_cpus(kc::card_node_thread_cpus());
|
||||
if (std::getenv("STRATA_TRACE") != nullptr) {
|
||||
std::string cpus;
|
||||
for (size_t i = 0; i < cd.cpus.size(); ++i) cpus += (i ? "," : "") + std::to_string(cd.cpus[i]);
|
||||
std::fprintf(stderr, "strata trace: card node: %d nodes with CPUs; cards: %s; card node free %lld MiB, pinned need %llu MiB; "
|
||||
"pool workers now %d, on the card's node %d (%d cores); %s%s (%d threads changed, %d refused)\n",
|
||||
ci.nodes_with_cpus, cards_text.empty() ? "not read" : cards_text.c_str(),
|
||||
(long long) (ci.card_node_free_bytes < 0 ? -1 : ci.card_node_free_bytes >> 20),
|
||||
(unsigned long long) (ci.pinned_need_bytes >> 20), ci.today_workers, cd.node_workers, cd.node_cores,
|
||||
cd.on ? "restricted to CPUs " : "left as is: ", cd.on ? cpus.c_str() : cd.why.c_str(), moved, refused);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
{ // --host-core / STRATA_HOST_CORE, before the pool and the session pin any thread
|
||||
std::string hc = o.host_core;
|
||||
if (hc.empty())
|
||||
|
||||
Reference in new issue
Block a user