mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-05 07:48:45 +00:00
New library engine/include/strata/mgpu + engine/src/mgpu, wired in cmake/backends/mgpu.cmake: - DeviceSet: the topology data model (devices, per-pair links, measured figures), the primary-card rule, JSON in and out (schema_version 1), synthetic builders for tests. - DeviceGuard: RAII current-device switching. - probe: PCIe link (sysfs / NVML), copy and memory bandwidth, mapped-host access, per pair the staged route, peer copy where proven (the #2666 host-bridge rule and an exact data test first), and the mapped-flag round trip. CUDA, and HIP through the hip_compat shim. - strata-topo program and `strata topo [--json]` in the Terminal (new subcommand only). - Transport interface: peer copy and host-staged implemented, doorbell a stub for P1; choose_mode is a pure function of the measured link. - Placement planner: plan_experts (cost model of one decode window, f = argmin instead of STRATA_PEER_HOT; Rows / OrderedPartials / SumPartials; N cards) and plan_layers (the layer split's fitted model as a pure function). Unit tests on synthetic pairs and quads. - terminal/tools/mgpu_identity.py: greedy token-hash identity of a family's goldens, one GPU against several. Nothing in the engine calls any of it yet.
89 lines
4.5 KiB
C++
89 lines
4.5 KiB
C++
// tests/mgpu/probe_test.cpp - the topology probe on the real devices: sane figures, a consistent pair matrix, a JSON round trip, and no peer
|
|
// access left behind. Needs one GPU (two for the pair checks); exit 77 = a stated skip. Prints the report, so a log shows what was measured.
|
|
#include "strata/mgpu/probe.hpp"
|
|
|
|
#include <cstdio>
|
|
#include <string>
|
|
|
|
using namespace strata::mgpu;
|
|
|
|
namespace {
|
|
int g_fail = 0;
|
|
void check(bool ok, const std::string& what) {
|
|
if (ok) return;
|
|
std::fprintf(stderr, "FAIL: %s\n", what.c_str());
|
|
++g_fail;
|
|
}
|
|
bool p2p(Path p) { return p == Path::P2PNvlink || p == Path::P2PDirect; }
|
|
} // namespace
|
|
|
|
int main() {
|
|
ProbeOptions opt;
|
|
opt.bw_bytes = 16u << 20;
|
|
opt.reps = 3;
|
|
opt.lat_samples = 50;
|
|
const DeviceSet s = probe(opt);
|
|
std::fputs(s.to_text().c_str(), stdout);
|
|
if (s.size() == 0) { std::puts("SKIPPED: mgpu_probe_test needs a GPU"); return 77; }
|
|
|
|
// every device: the static facts and the measured ones are there and plausible
|
|
for (size_t i = 0; i < s.size(); ++i) {
|
|
const DeviceInfo& d = s.dev(i);
|
|
const std::string t = "device " + std::to_string(i) + ": ";
|
|
check(!d.name.empty() && d.ordinal == (int) i, t + "name and ordinal");
|
|
check(d.sms > 0 && d.clock_ghz > 0.2 && d.clock_ghz < 6.0, t + "SMs and clock");
|
|
check(d.vram_total >= (256ull << 20) && d.vram_free <= d.vram_total && d.vram_free > 0, t + "VRAM");
|
|
check(d.mem_bw_gbps > 20.0 && d.mem_bw_gbps < 20000.0, t + "device memory bandwidth in a believable range");
|
|
check(d.h2d_gbps > 0.5 && d.h2d_gbps < 2000.0 && d.d2h_gbps > 0.5 && d.d2h_gbps < 2000.0, t + "host copy bandwidth in a believable range");
|
|
check(d.h2d_us > 0.0 && d.h2d_us < 5000.0 && d.d2h_us > 0.0 && d.d2h_us < 5000.0, t + "host copy latency in a believable range");
|
|
check(d.mapped_read_gbps > 0.0 && d.mapped_write_gbps > 0.0, t + "kernels reach mapped host memory");
|
|
check(!d.arch_name.empty(), t + "arch name");
|
|
}
|
|
check(s.primary() >= 0 && s.primary() < (int) s.size(), "a primary is chosen");
|
|
|
|
// every pair: both directions filled, symmetric path, a data-proven P2P or no P2P
|
|
for (size_t i = 0; i < s.size(); ++i)
|
|
for (size_t j = 0; j < s.size(); ++j) {
|
|
if (i == j) continue;
|
|
const Link& l = s.link(i, j);
|
|
const std::string t = "link " + std::to_string(i) + "->" + std::to_string(j) + ": ";
|
|
check(l.path != Path::None, t + "has a path");
|
|
check(l.gbps_staged > 0.3 && l.gbps_staged < 2000.0 && l.lat_staged_us > 0.0, t + "staged figures present");
|
|
check(l.path == s.link(j, i).path, t + "the path is the same both ways");
|
|
if (p2p(l.path)) check(l.data_ok && l.gbps_p2p > 0.0 && l.lat_p2p_us > 0.0 && l.can_access, t + "a P2P path was proven and measured");
|
|
if (!p2p(l.path)) check(l.gbps_p2p == 0.0, t + "no P2P figure without a P2P path");
|
|
if (!p2p(l.path) && l.can_access && l.topology_safe) check(!l.why.empty(), t + "a pair that could do P2P but does not says why");
|
|
}
|
|
|
|
// JSON round trip of the real report
|
|
{
|
|
DeviceSet r;
|
|
std::string err;
|
|
check(DeviceSet::from_json(s.to_json(), r, err) && r.to_json() == s.to_json(), "the probe's JSON reads back unchanged: " + err);
|
|
}
|
|
// the switch that keeps peer access off
|
|
if (s.size() >= 2) {
|
|
ProbeOptions off = opt;
|
|
off.allow_p2p = false;
|
|
const DeviceSet t = probe(off);
|
|
for (size_t i = 0; i < t.size(); ++i)
|
|
for (size_t j = 0; j < t.size(); ++j)
|
|
if (i != j) check(t.link(i, j).path == Path::HostStaged && t.link(i, j).gbps_p2p == 0.0, "allow_p2p = false never uses P2P");
|
|
// a second probe after the first: peer access was not left enabled, so the answer is the same
|
|
const DeviceSet u = probe(opt);
|
|
check(u.link(0, 1).path == s.link(0, 1).path, "probing twice gives the same path");
|
|
} else {
|
|
std::puts("one device: the pair checks are skipped");
|
|
}
|
|
// static-only probe: no copies, no kernels
|
|
{
|
|
ProbeOptions st;
|
|
st.measure = false;
|
|
const DeviceSet t = probe(st);
|
|
check(t.size() == s.size() && t.dev(0).mem_bw_gbps == 0.0 && t.dev(0).h2d_gbps == 0.0 && t.dev(0).sms == s.dev(0).sms, "measure = false reads the static facts only");
|
|
}
|
|
if (g_fail != 0) { std::fprintf(stderr, "%d check(s) failed\n", g_fail); return 1; }
|
|
std::puts("mgpu_probe_test: all checks passed");
|
|
return 0;
|
|
}
|