[llvm] [Offload] Store device info tree in device handle (PR #145913)
Joseph Huber via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 26 09:26:58 PDT 2025
================
@@ -167,31 +167,39 @@ void initPlugins() {
for (auto DevNum = 0; DevNum < Platform.Plugin->number_of_devices();
DevNum++) {
if (Platform.Plugin->init_device(DevNum) == OFFLOAD_SUCCESS) {
- Platform.Devices.emplace_back(ol_device_impl_t{
- DevNum, &Platform.Plugin->getDevice(DevNum), &Platform});
+ auto Device = &Platform.Plugin->getDevice(DevNum);
+ auto Info = Device->obtainInfoImpl();
+ if (auto Err = Info.takeError())
+ return Err;
+ Platform.Devices.emplace_back(DevNum, Device, &Platform,
+ std::move(*Info));
}
}
}
// Add the special host device
auto &HostPlatform = Context->Platforms.emplace_back(
- ol_platform_impl_t{nullptr,
- {ol_device_impl_t{-1, nullptr, nullptr}},
- OL_PLATFORM_BACKEND_HOST});
+ ol_platform_impl_t{nullptr, OL_PLATFORM_BACKEND_HOST});
+ HostPlatform.Devices.emplace_back(-1, nullptr, nullptr, InfoTreeNode{});
Context->HostDevice()->Platform = &HostPlatform;
Context->TracingEnabled = std::getenv("OFFLOAD_TRACE");
Context->ValidationEnabled = !std::getenv("OFFLOAD_DISABLE_VALIDATION");
OffloadContextVal = Context;
+
+ return Plugin::success();
}
// TODO: We can properly reference count here and manage the resources in a more
// clever way
Error olInit_impl() {
static std::once_flag InitFlag;
- std::call_once(InitFlag, initPlugins);
+ std::optional<Error> InitResult{};
+ std::call_once(InitFlag, [&] { InitResult = initPlugins(); });
+ if (InitResult)
+ return std::move(*InitResult);
----------------
jhuber6 wrote:
Didn't we have a patch for this? We want the following to work as expected.
```
init()
deinit()
init()
deinit()
```
https://github.com/llvm/llvm-project/pull/145913
More information about the llvm-commits
mailing list