okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-0291-split-hip e3563ff3d: AMD split final candidate (batched draft layer, RCCL sums, strata-split-2/3/4-amd)95901fe8a

main
3.3 KiB64 linesraw
1// The RCCL decision and loader (src/hip/rccl_dl.hpp): a missing librccl leaves the host exchange for the prompt sums with one plain line (forced here with
2// FNX_RCCL_LIB pointing nowhere, and at a library that exists but is not RCCL), FNX_PF_RCCL=0 or unset is silent, RCCL is not tried without the peer push, and a
3// library that opens is used with a line saying which. CPU only (the loader holds no HIP header).
4#include <cstdio>
5#include <cstdlib>
6#include <string>
7
8#include "../src/hip/rccl_dl.hpp"
9
10static int bad = 0;
11#define CHECK(c) do { if (!(c)) { std::printf("FAIL line %d: %s\n", __LINE__, #c); ++bad; } } while (0)
12
13int main() {
14    using namespace fnx;
15    int calls = 0;
16    auto pass = [&](std::string& why) { ++calls; why = "librccl.so.1"; return true; };
17    // the real loader, pointed at a library that is not there: the engine's open() would return exactly this
18    auto missing = [&](std::string& why) { ++calls; RcclApi api; return rccl_load(api, "", why); };
19
20    // FNX_PF_RCCL=0 or unset with the default off: nothing, no open, no line
21    unsetenv("FNX_RCCL_LIB");
22    RcclDecision d = rccl_decide("0", true, true, pass);
23    CHECK(!d.use && d.line.empty() && calls == 0);
24    d = rccl_decide(nullptr, true, false, pass);
25    CHECK(!d.use && d.line.empty() && calls == 0);
26    // =1 without the peer push: the host exchange stays, one line, no open
27    d = rccl_decide("1", false, false, pass);
28    CHECK(!d.use && calls == 0 && d.line == "RCCL is not used for the prompt sums: the peer push between the cards is off, so the host exchange stays.");
29    // the default alone (unset) without the peer push: the host exchange, quiet
30    calls = 0;
31    d = rccl_decide(nullptr, false, true, pass);
32    CHECK(!d.use && calls == 0 && d.line.empty());
33    calls = 0;
34    // =1 with the peer push and a library that opens: used, the line says which
35    d = rccl_decide("1", true, false, pass);
36    CHECK(d.use && calls == 1 && d.line == "The prompt sums use RCCL (librccl.so.1).");
37    // unset and the default on behaves like =1
38    calls = 0;
39    d = rccl_decide(nullptr, true, true, pass);
40    CHECK(d.use && calls == 1);
41
42    // the library is missing (FNX_RCCL_LIB points nowhere): the host exchange, one plain line naming the library and the loader's reason
43    setenv("FNX_RCCL_LIB", "/nonexistent/librccl.so.1", 1);
44    calls = 0;
45    d = rccl_decide("1", true, false, missing);
46    CHECK(!d.use && calls == 1);
47    CHECK(d.line.rfind("RCCL is not available here (cannot load /nonexistent/librccl.so.1", 0) == 0);
48    CHECK(d.line.find("): the prompt sums use the host exchange.") != std::string::npos);
49    CHECK(d.line.find('\n') == std::string::npos);
50    // the same through the default
51    d = rccl_decide(nullptr, true, true, missing);
52    CHECK(!d.use);
53    // FNX_PF_RCCL=0 stays silent whatever FNX_RCCL_LIB says
54    d = rccl_decide("0", true, true, missing);
55    CHECK(!d.use && d.line.empty());
56
57    // a library that opens but is not RCCL (the C library): no ncclCommInitAll, the same fallback line
58    setenv("FNX_RCCL_LIB", "libm.so.6", 1);
59    d = rccl_decide("1", true, false, missing);
60    CHECK(!d.use && d.line == "RCCL is not available here (libm.so.6 has no ncclCommInitAll): the prompt sums use the host exchange.");
61    unsetenv("FNX_RCCL_LIB");
62    std::printf(bad ? "rccl_policy_test: %d FAILED\n" : "rccl_policy_test: ok\n", bad);
63    return bad ? 1 : 0;
64}