Skip to content

Commit 6a15e2d

Browse files
authored
[Offload] Fix ordering with RPC teardown and global destructors (#205594)
Summary: There's a bit of a chicken and egg problem for the RPC server if we want to do something creative with the device's image for things like DWARF dumping. The problem was that destructors can make RPC calls, but the RPC server also needed the images to be valid. Simple fix is to just split the destructor calling out and do it first so we can deinitialize RPC with valid device images.
1 parent 62c0eff commit 6a15e2d

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

offload/plugins-nextgen/common/src/PluginInterface.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -608,9 +608,6 @@ Error GenericDeviceTy::init(GenericPluginTy &Plugin) {
608608
}
609609

610610
Error GenericDeviceTy::unloadBinary(DeviceImageTy *Image) {
611-
if (auto Err = callGlobalDestructors(Plugin, *Image))
612-
return Err;
613-
614611
GenericGlobalHandlerTy &Handler = Plugin.getGlobalHandler();
615612
auto ProfOrErr = Handler.readProfilingGlobals(*this, *Image);
616613
if (!ProfOrErr)
@@ -631,6 +628,18 @@ Error GenericDeviceTy::unloadBinary(DeviceImageTy *Image) {
631628
}
632629

633630
Error GenericDeviceTy::deinit(GenericPluginTy &Plugin) {
631+
// Run the global destructors first in case they required the RPC server.
632+
for (auto &I : LoadedImages) {
633+
if (auto Err = callGlobalDestructors(Plugin, *I))
634+
return Err;
635+
}
636+
637+
if (RPCServer) {
638+
if (auto Err = RPCServer->deinitDevice(*this))
639+
return Err;
640+
RPCServer = nullptr;
641+
}
642+
634643
for (auto &I : LoadedImages)
635644
if (auto Err = unloadBinary(I))
636645
return Err;
@@ -649,10 +658,6 @@ Error GenericDeviceTy::deinit(GenericPluginTy &Plugin) {
649658
RecordReplay = nullptr;
650659
}
651660

652-
if (RPCServer)
653-
if (auto Err = RPCServer->deinitDevice(*this))
654-
return Err;
655-
656661
#ifdef OMPT_SUPPORT
657662
if (ompt::Initialized) {
658663
bool ExpectedStatus = true;

0 commit comments

Comments
 (0)