diff --git a/engine/include/strata/program/split_rules.hpp b/engine/include/strata/program/split_rules.hpp index 9a327d590f..e9c6c235cf 100644 --- a/engine/include/strata/program/split_rules.hpp +++ b/engine/include/strata/program/split_rules.hpp @@ -8,6 +8,7 @@ #include #include +#include #include namespace strata::program::split_rules { @@ -144,6 +145,16 @@ inline size_t pick_with_headroom(const std::vector& c, double tol) { constexpr double kLinkScaleMin = 4.0; +/// STRATA_SPLIT_LINK_MIN (BW-MG, opt-in): the gap (the fastest stage's link / this stage's) from which the miss term is scaled; unset, empty or anything that is not a number >= 1 keeps kLinkScaleMin. +/// 2x RTX 5090 on a PCIe 4.0 x8 + x2 board (14.1 and 3.6 GB/s probed, a gap of 3.92): auto K=24 reads a 4K prompt in 5,950 ms against 4,270 on the x8 card alone; with the gap read as 3 the split +/// puts fewer layers on the x2 card (RESULTS-BW-E.md). +inline double link_scale_min_resolve(const char* env) { + if (env == nullptr || env[0] == '\0') return kLinkScaleMin; + char* end = nullptr; + const double v = std::strtod(env, &end); + return end != env && v >= 1.0 ? v : kLinkScaleMin; +} + /// Per stage: the factor on its miss term, from the probed H2D GB/s of each stage (<= 0: not probed -> 1.0). inline std::vector link_miss_scale(const std::vector& gbps, double min_ratio = kLinkScaleMin) { double fastest = 0.0; diff --git a/engine/src/program/generate.cpp b/engine/src/program/generate.cpp index 08273c35c5..f018902b01 100644 --- a/engine/src/program/generate.cpp +++ b/engine/src/program/generate.cpp @@ -6681,7 +6681,9 @@ int main(int argc, char** argv) { // where any scaling moves auto off the balanced placement. static const bool link_abs = [] { const char* v = std::getenv("STRATA_SPLIT_LINK_ABS"); return v && v[0] == '1'; }(); static const bool split_uniform = [] { const char* v = std::getenv("STRATA_SPLIT_UNIFORM"); return v && v[0] == '1'; }(); - std::vector link_scale = strata::program::split_rules::link_miss_scale(link_gbps); + // STRATA_SPLIT_LINK_MIN=r (BW-MG, opt-in): the gap from which the scale applies, 4 unless set (a x8 beside a x2 slot is a gap of 3.9: unscaled by default) + static const double link_min = strata::program::split_rules::link_scale_min_resolve(std::getenv("STRATA_SPLIT_LINK_MIN")); + std::vector link_scale = strata::program::split_rules::link_miss_scale(link_gbps, link_min); for (int i = 0; i < ns; ++i) { const double bw = link_gbps[(size_t) i]; if (split_uniform) link_scale[(size_t) i] = 1.0; diff --git a/engine/tests/program/split_rules_test.cpp b/engine/tests/program/split_rules_test.cpp index d2493908f9..2a06b77864 100644 --- a/engine/tests/program/split_rules_test.cpp +++ b/engine/tests/program/split_rules_test.cpp @@ -90,6 +90,15 @@ int main() { const std::vector big = link_miss_scale({26.0, 6.0, 0.2, -1.0}); CHECK(big[0] == 1.0 && big[1] > 4.3 && big[1] < 4.4 && big[2] == 64.0 && big[3] == 1.0); CHECK(link_miss_scale({-1.0, -1.0})[1] == 1.0); + // BW-MG: PCIe 4.0 x2 (3.6 GB/s) beside x8 (14.1 GB/s) is a gap of 3.92: unscaled by default, scaled from STRATA_SPLIT_LINK_MIN=3 + const std::vector x2x8 = link_miss_scale({3.6, 14.1}); + CHECK(x2x8[0] == 1.0 && x2x8[1] == 1.0); + const std::vector x2x8s = link_miss_scale({14.1, 3.6}, 3.0); + CHECK(x2x8s[0] == 1.0 && x2x8s[1] > 3.9 && x2x8s[1] < 3.93); + // the variable's text: unset / empty / not a number / below 1 keep the default + CHECK(link_scale_min_resolve(nullptr) == kLinkScaleMin && link_scale_min_resolve("") == kLinkScaleMin); + CHECK(link_scale_min_resolve("banana") == kLinkScaleMin && link_scale_min_resolve("0.5") == kLinkScaleMin); + CHECK(link_scale_min_resolve("3") == 3.0 && link_scale_min_resolve("2.5") == 2.5); } // #2644: RTX 4060 Ti 16 GB + RTX 3060 12 GB, 48 layers. The reporter's numbers: CUDA1 5.50 GiB free of 11.63 (the // 3060 side), CUDA0 the 16 GB card with ~14.2 GiB room. The #1616 retry alone took K=3 (3 layers on the second card)