@@ -1133,6 +1133,10 @@ GenericDeviceTy::loadBinary(GenericPluginTy &Plugin,
1133
1133
} else if (auto Err = setupDeviceMemoryPool (Plugin, *Image, HeapSize))
1134
1134
return std::move (Err);
1135
1135
}
1136
+
1137
+ if (auto Err = setupRPCServer (Plugin, *Image))
1138
+ return std::move (Err);
1139
+
1136
1140
#ifdef OMPT_SUPPORT
1137
1141
if (ompt::Initialized) {
1138
1142
size_t Bytes =
@@ -1246,6 +1250,33 @@ Error GenericDeviceTy::setupDeviceMemoryPool(GenericPluginTy &Plugin,
1246
1250
return GHandler.writeGlobalToDevice (*this , Image, DevEnvGlobal);
1247
1251
}
1248
1252
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
+
1249
1280
Error PinnedAllocationMapTy::insertEntry (void *HstPtr, void *DevAccessiblePtr,
1250
1281
size_t Size, bool ExternallyLocked) {
1251
1282
// Insert the new entry into the map.
@@ -1864,13 +1895,12 @@ Error GenericPluginTy::deinit() {
1864
1895
if (GlobalHandler)
1865
1896
delete GlobalHandler;
1866
1897
1867
- #if RPC_FIXME
1868
- if (RPCServer) {
1898
+ if (RPCServer && RPCServer->Thread ->Running .load (std::memory_order_relaxed))
1869
1899
if (Error Err = RPCServer->shutDown ())
1870
1900
return Err;
1901
+
1902
+ if (RPCServer)
1871
1903
delete RPCServer;
1872
- }
1873
- #endif
1874
1904
1875
1905
if (RecordReplay)
1876
1906
delete RecordReplay;
0 commit comments