okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
95901fe8a
main
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 () { 14using namespace fnx ; 15int calls = 0 ; 16auto 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 18auto 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 21unsetenv ("FNX_RCCL_LIB" ); 22RcclDecision d = rccl_decide ("0" , true, true,pass ); 23CHECK (!d .use && d .line .empty ()&& calls == 0 ); 24d = rccl_decide (nullptr , true, false,pass ); 25CHECK (!d .use && d .line .empty ()&& calls == 0 ); 26// =1 without the peer push: the host exchange stays, one line, no open 27d = rccl_decide ("1" , false, false,pass ); 28CHECK (!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 30calls = 0 ; 31d = rccl_decide (nullptr , false, true,pass ); 32CHECK (!d .use && calls == 0 && d .line .empty ()); 33calls = 0 ; 34// =1 with the peer push and a library that opens: used, the line says which 35d = rccl_decide ("1" , true, false,pass ); 36CHECK (d .use && calls == 1 && d .line == "The prompt sums use RCCL (librccl.so.1)." ); 37// unset and the default on behaves like =1 38calls = 0 ; 39d = rccl_decide (nullptr , true, true,pass ); 40CHECK (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 43setenv ("FNX_RCCL_LIB" ,"/nonexistent/librccl.so.1" ,1 ); 44calls = 0 ; 45d = rccl_decide ("1" , true, false,missing ); 46CHECK (!d .use && calls == 1 ); 47CHECK (d .line .rfind ("RCCL is not available here (cannot load /nonexistent/librccl.so.1" ,0 )== 0 ); 48CHECK (d .line .find ("): the prompt sums use the host exchange." )!= std::string::npos ); 49CHECK (d .line .find ('\n' )== std::string::npos ); 50// the same through the default 51d = rccl_decide (nullptr , true, true,missing ); 52CHECK (!d .use ); 53// FNX_PF_RCCL=0 stays silent whatever FNX_RCCL_LIB says 54d = rccl_decide ("0" , true, true,missing ); 55CHECK (!d .use && d .line .empty ()); 56 57// a library that opens but is not RCCL (the C library): no ncclCommInitAll, the same fallback line 58setenv ("FNX_RCCL_LIB" ,"libm.so.6" ,1 ); 59d = rccl_decide ("1" , true, false,missing ); 60CHECK (!d .use && d .line == "RCCL is not available here (libm.so.6 has no ncclCommInitAll): the prompt sums use the host exchange." ); 61unsetenv ("FNX_RCCL_LIB" ); 62 std::printf (bad ?"rccl_policy_test: %d FAILED\n" :"rccl_policy_test: ok\n" ,bad ); 63return bad ?1 :0 ; 64}