[Openmp-commits] [openmp] 4213f4a - [Libomptarget] Fix resizing the buffer of RPC handles

Joseph Huber via Openmp-commits openmp-commits at lists.llvm.org
Mon Apr 1 05:30:10 PDT 2024


Author: Joseph Huber
Date: 2024-04-01T07:29:57-05:00
New Revision: 4213f4a9ae0ef70e02da9f40653b4e04eea00c74

URL: https://github.com/llvm/llvm-project/commit/4213f4a9ae0ef70e02da9f40653b4e04eea00c74
DIFF: https://github.com/llvm/llvm-project/commit/4213f4a9ae0ef70e02da9f40653b4e04eea00c74.diff

LOG: [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.

Added: 
    

Modified: 
    openmp/libomptarget/plugins-nextgen/common/include/RPC.h
    openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp
    openmp/libomptarget/plugins-nextgen/common/src/RPC.cpp

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/plugins-nextgen/common/include/RPC.h b/openmp/libomptarget/plugins-nextgen/common/include/RPC.h
index b621cc0da4587d..01bf539bcb3f32 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 55e2865d6aae42..b5f3c45c835fdb 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 fab0f6838f4a87..faa2cbd4f02fe1 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();


        


More information about the Openmp-commits mailing list