Files
Niko1221 06fd2f0700 mgpu: strata_mgpu phase 0, the shared multi-GPU layer's foundation (no engine behaviour change)
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.
2026-11-30 23:49:37 +01:00

50 lines
2.7 KiB
C++

// tests/mgpu/pcie_link_test.cpp - the sysfs text parsers and the shared-bridge rule behind the P2P safety check (#2666). CPU only, no GPU.
#include "strata/mgpu/pcie_link.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;
}
} // namespace
int main() {
// link speed text as sysfs writes it
check(pcie_gen_from_speed_text("2.5 GT/s PCIe") == 1, "2.5 GT/s is gen1");
check(pcie_gen_from_speed_text("5.0 GT/s PCIe") == 2, "5 GT/s is gen2");
check(pcie_gen_from_speed_text("8.0 GT/s PCIe") == 3, "8 GT/s is gen3");
check(pcie_gen_from_speed_text("16.0 GT/s PCIe") == 4, "16 GT/s is gen4");
check(pcie_gen_from_speed_text("32.0 GT/s PCIe") == 5, "32 GT/s is gen5");
check(pcie_gen_from_speed_text("64.0 GT/s PCIe") == 6, "64 GT/s is gen6");
check(pcie_gen_from_speed_text("Unknown") == 0 && pcie_gen_from_speed_text("") == 0 && pcie_gen_from_speed_text("0 GT/s") == 0, "not a speed: 0");
// two GPUs behind one switch share a bridge; two on separate root ports do not (the 2x RTX A4000 host-bridge board of #2666)
const std::string a = "/sys/devices/pci0000:00/0000:00:01.0/0000:02:00.0/0000:03:08.0/0000:04:00.0";
const std::string b = "/sys/devices/pci0000:00/0000:00:01.0/0000:02:00.0/0000:03:10.0/0000:05:00.0";
check(common_bridges_of_paths(a, b) == 2, "behind one switch: two shared bridges (0000:00:01.0 and 0000:02:00.0)");
const std::string c = "/sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0";
const std::string d = "/sys/devices/pci0000:00/0000:00:03.1/0000:41:00.0";
check(common_bridges_of_paths(c, d) == 0, "two root ports of one root complex: no shared bridge");
const std::string e = "/sys/devices/pci0000:80/0000:80:01.0/0000:81:00.0";
check(common_bridges_of_paths(c, e) == 0, "two root complexes: none");
check(common_bridges_of_paths(c, c) == 1, "the same slot shares its one root port (the last component is the device itself)");
check(common_bridges_of_paths("", c) == 0 && common_bridges_of_paths("", "") == 0, "an empty path shares nothing");
// unreadable or unknown devices are 'not ok' / unknown, never a guess
check(!read_pcie_link("").ok, "an empty address reads nothing");
check(!read_pcie_link("ffff:ff:ff.7").ok, "a device that does not exist reads nothing");
check(common_bridges("", "") == -1, "unknown paths: -1");
check(common_bridges("ffff:ff:ff.7", "ffff:ff:ff.6") == -1, "devices that do not exist: -1");
if (g_fail != 0) { std::fprintf(stderr, "%d check(s) failed\n", g_fail); return 1; }
std::puts("mgpu_pcie_link_test: all checks passed");
return 0;
}