aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Huber <huberjn@outlook.com>2024-04-01 07:28:34 -0500
committerJoseph Huber <huberjn@outlook.com>2024-04-01 07:29:57 -0500
commit4213f4a9ae0ef70e02da9f40653b4e04eea00c74 (patch)
tree7112c9c6e8c5f60b3f616eb27cfba0043dce3de2
parentf546b6ef3c15a156959dde16fa5f03a350a0a2be (diff)
downloadllvm-4213f4a9ae0ef70e02da9f40653b4e04eea00c74.zip
llvm-4213f4a9ae0ef70e02da9f40653b4e04eea00c74.tar.gz
llvm-4213f4a9ae0ef70e02da9f40653b4e04eea00c74.tar.bz2
[Libomptarget] Fix resizing the buffer of RPC handles
Summary: The previous code would potentially make it smaller if a device with a lower ID touched it later. Also we should minimize changes to the state for multi threaded reasons. This just sets up an owned slot for each at initialization time.
-rw-r--r--openmp/libomptarget/plugins-nextgen/common/include/RPC.h4
-rw-r--r--openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp2
-rw-r--r--openmp/libomptarget/plugins-nextgen/common/src/RPC.cpp4
3 files changed, 8 insertions, 2 deletions
diff --git a/openmp/libomptarget/plugins-nextgen/common/include/RPC.h b/openmp/libomptarget/plugins-nextgen/common/include/RPC.h
index b621cc0..01bf539 100644
--- a/openmp/libomptarget/plugins-nextgen/common/include/RPC.h
+++ b/openmp/libomptarget/plugins-nextgen/common/include/RPC.h
@@ -23,6 +23,7 @@
namespace llvm::omp::target {
namespace plugin {
+struct GenericPluginTy;
struct GenericDeviceTy;
class GenericGlobalHandlerTy;
class DeviceImageTy;
@@ -33,6 +34,9 @@ class DeviceImageTy;
/// these routines will perform no action.
struct RPCServerTy {
public:
+ /// Initializes the handles to the number of devices we may need to service.
+ RPCServerTy(plugin::GenericPluginTy &Plugin);
+
/// Check if this device image is using an RPC server. This checks for the
/// precense of an externally visible symbol in the device image that will
/// be present whenever RPC code is called.
diff --git a/openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp b/openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp
index 55e2865..b5f3c45 100644
--- a/openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp
+++ b/openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp
@@ -1492,7 +1492,7 @@ Error GenericPluginTy::init() {
GlobalHandler = createGlobalHandler();
assert(GlobalHandler && "Invalid global handler");
- RPCServer = new RPCServerTy();
+ RPCServer = new RPCServerTy(*this);
assert(RPCServer && "Invalid RPC server");
return Plugin::success();
diff --git a/openmp/libomptarget/plugins-nextgen/common/src/RPC.cpp b/openmp/libomptarget/plugins-nextgen/common/src/RPC.cpp
index fab0f68..faa2cbd 100644
--- a/openmp/libomptarget/plugins-nextgen/common/src/RPC.cpp
+++ b/openmp/libomptarget/plugins-nextgen/common/src/RPC.cpp
@@ -21,6 +21,9 @@ using namespace llvm;
using namespace omp;
using namespace target;
+RPCServerTy::RPCServerTy(plugin::GenericPluginTy &Plugin)
+ : Handles(Plugin.getNumDevices()) {}
+
llvm::Expected<bool>
RPCServerTy::isDeviceUsingRPC(plugin::GenericDeviceTy &Device,
plugin::GenericGlobalHandlerTy &Handler,
@@ -101,7 +104,6 @@ Error RPCServerTy::initDevice(plugin::GenericDeviceTy &Device,
if (auto Err = Device.dataSubmit(ClientPtr, ClientBuffer,
rpc_get_client_size(), nullptr))
return Err;
- Handles.resize(Device.getDeviceId() + 1);
Handles[Device.getDeviceId()] = RPCDevice.handle;
#endif
return Error::success();