9class DistributedMpiGpuLibrary :
public DistributedGpuLibrary
12 using Communicator = DistributedGpuApi::MgdMpiCommunicator;
13 using RuntimeInfo = DistributedGpuApi::MgdMpiRuntimeInfo;
14 static std::shared_ptr<DistributedMpiGpuLibrary> GetInstance();
16 void *CreateNative(
int,
int)
override
18 throw std::logic_error(
"MPI GPU states require a communicator");
21 RuntimeInfo GetRuntimeInfo(
const Communicator *comm)
23 std::lock_guard<std::recursive_mutex> lock(mutex);
25 RuntimeInfo info{
sizeof(RuntimeInfo), 0, 0, 0};
26 Check(getInfo(comm, &info),
"GetMpiRuntimeInfo");
30 void GatherDevices(
const Communicator *comm, int32_t device, std::vector<int32_t> &devices)
32 std::lock_guard<std::recursive_mutex> lock(mutex);
34 Check(gather(comm, device, devices.data(), devices.size()),
"GatherMpiDevices");
37 uint64_t GenerateSeed(
const Communicator *comm)
39 std::lock_guard<std::recursive_mutex> lock(mutex);
43 generateSeed = Resolve<decltype(generateSeed)>(
"GenerateMpiSeed");
45 Check(generateSeed(comm, &seed),
"GenerateMpiSeed");
49 void *CreateMpiNative(
const Communicator *comm,
int device,
unsigned p2pBits)
51 std::lock_guard<std::recursive_mutex> lock(mutex);
53 if (!initializationAttempted)
55 initializationAttempted =
true;
56 if (validate(comm, std::getenv(
"MAESTRO_LICENSE_KEY")) != 1)
58 const char *detail = GetLastError();
59 initializationError = detail && *detail ? detail :
"license validation failed";
60 throw std::runtime_error(
"MPI GPU backend unavailable: " + initializationError);
65 const char *detail = GetLastError();
66 initializationError = detail && *detail ? detail :
"InitLib failed";
71 auto obj = create(context, comm, device, p2pBits);
74 if (!initializationError.empty())
75 throw std::runtime_error(
"MPI GPU backend unavailable: " + initializationError);
76 Fail(
"CreateMpiStateVectorRuntime");
83 void FinalizeBackend()
85 std::lock_guard<std::recursive_mutex> lock(mutex);
87 throw std::logic_error(
"Destroy all MPI GPU states before finalizing the backend");
93 Check(finalize(),
"FinalizeMpiBackend");
99 DistributedMpiGpuLibrary() : DistributedGpuLibrary(true)
103 template <
typename T> T Resolve(
const char *name)
105 auto fn =
reinterpret_cast<T
>(GetFunction(name));
107 throw std::runtime_error(std::string(
"MPI GPU plugin missing ") + name +
"; update maestro-gpu-distributed");
111 void RequireRuntime()
114 throw std::runtime_error(
"MPI GPU backend is finalized");
118 getInfo = Resolve<decltype(getInfo)>(
"GetMpiRuntimeInfo");
119 gather = Resolve<decltype(gather)>(
"GatherMpiDevices");
120 validate = Resolve<decltype(validate)>(
"ValidateMpiLicenseRuntime");
121 create = Resolve<decltype(create)>(
"CreateMpiStateVectorRuntime");
122 finalize = Resolve<decltype(finalize)>(
"FinalizeMpiBackend");
123 runtimeLoaded =
true;
126 int (*getInfo)(
const Communicator *, RuntimeInfo *) =
nullptr;
127 int (*gather)(
const Communicator *, int32_t, int32_t *, uint32_t) =
nullptr;
128 int (*generateSeed)(
const Communicator *, uint64_t *) =
nullptr;
129 int (*validate)(
const Communicator *,
const char *) =
nullptr;
130 void *(*create)(
void *,
const Communicator *, int32_t, uint32_t) =
nullptr;
131 int (*finalize)() =
nullptr;
132 bool finalized =
false, runtimeLoaded =
false;
133 bool initializationAttempted =
false;
134 std::string initializationError;
Bounded online routing based on current physical bond dimensions.