Skip to content

Commit 9ded9e6

Browse files
gregrodgersronlieb
authored andcommitted
[OPENMP] rpc fix from Joseph. Now consistent with trunk
1 parent dc7d034 commit 9ded9e6

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

offload/plugins-nextgen/common/include/PluginInterface.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,12 @@ struct GenericDeviceTy : public DeviceAllocatorTy {
797797
/// Setup the global device memory pool, if the plugin requires one.
798798
Error setupDeviceMemoryPool(GenericPluginTy &Plugin, DeviceImageTy &Image,
799799
uint64_t PoolSize);
800+
801+
// Setup the RPC server for this device if needed. This may not run on some
802+
// plugins like the CPU targets. By default, it will not be executed so it is
803+
// up to the target to override this using the shouldSetupRPCServer function.
804+
Error setupRPCServer(GenericPluginTy &Plugin, DeviceImageTy &Image);
805+
800806
/// Synchronize the current thread with the pending operations on the
801807
/// __tgt_async_info structure.
802808
Error synchronize(__tgt_async_info *AsyncInfo);

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

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,10 @@ GenericDeviceTy::loadBinary(GenericPluginTy &Plugin,
11331133
} else if (auto Err = setupDeviceMemoryPool(Plugin, *Image, HeapSize))
11341134
return std::move(Err);
11351135
}
1136+
1137+
if (auto Err = setupRPCServer(Plugin, *Image))
1138+
return std::move(Err);
1139+
11361140
#ifdef OMPT_SUPPORT
11371141
if (ompt::Initialized) {
11381142
size_t Bytes =
@@ -1246,6 +1250,33 @@ Error GenericDeviceTy::setupDeviceMemoryPool(GenericPluginTy &Plugin,
12461250
return GHandler.writeGlobalToDevice(*this, Image, DevEnvGlobal);
12471251
}
12481252

1253+
Error GenericDeviceTy::setupRPCServer(GenericPluginTy &Plugin,
1254+
DeviceImageTy &Image) {
1255+
// The plugin either does not need an RPC server or it is unavailable.
1256+
if (!shouldSetupRPCServer())
1257+
return Plugin::success();
1258+
1259+
// Check if this device needs to run an RPC server.
1260+
RPCServerTy &Server = Plugin.getRPCServer();
1261+
auto UsingOrErr =
1262+
Server.isDeviceUsingRPC(*this, Plugin.getGlobalHandler(), Image);
1263+
if (!UsingOrErr)
1264+
return UsingOrErr.takeError();
1265+
1266+
if (!UsingOrErr.get())
1267+
return Plugin::success();
1268+
1269+
if (auto Err = Server.initDevice(*this, Plugin.getGlobalHandler(), Image))
1270+
return Err;
1271+
1272+
if (auto Err = Server.startThread())
1273+
return Err;
1274+
1275+
RPCServer = &Server;
1276+
DP("Running an RPC server on device %d\n", getDeviceId());
1277+
return Plugin::success();
1278+
}
1279+
12491280
Error PinnedAllocationMapTy::insertEntry(void *HstPtr, void *DevAccessiblePtr,
12501281
size_t Size, bool ExternallyLocked) {
12511282
// Insert the new entry into the map.
@@ -1864,13 +1895,12 @@ Error GenericPluginTy::deinit() {
18641895
if (GlobalHandler)
18651896
delete GlobalHandler;
18661897

1867-
#if RPC_FIXME
1868-
if (RPCServer) {
1898+
if (RPCServer && RPCServer->Thread->Running.load(std::memory_order_relaxed))
18691899
if (Error Err = RPCServer->shutDown())
18701900
return Err;
1901+
1902+
if (RPCServer)
18711903
delete RPCServer;
1872-
}
1873-
#endif
18741904

18751905
if (RecordReplay)
18761906
delete RecordReplay;

0 commit comments

Comments
 (0)