Skip to content

Commit 4213f4a

Browse files
committed
[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.
1 parent f546b6e commit 4213f4a

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

openmp/libomptarget/plugins-nextgen/common/include/RPC.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
namespace llvm::omp::target {
2525
namespace plugin {
26+
struct GenericPluginTy;
2627
struct GenericDeviceTy;
2728
class GenericGlobalHandlerTy;
2829
class DeviceImageTy;
@@ -33,6 +34,9 @@ class DeviceImageTy;
3334
/// these routines will perform no action.
3435
struct RPCServerTy {
3536
public:
37+
/// Initializes the handles to the number of devices we may need to service.
38+
RPCServerTy(plugin::GenericPluginTy &Plugin);
39+
3640
/// Check if this device image is using an RPC server. This checks for the
3741
/// precense of an externally visible symbol in the device image that will
3842
/// be present whenever RPC code is called.

openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,7 @@ Error GenericPluginTy::init() {
14921492
GlobalHandler = createGlobalHandler();
14931493
assert(GlobalHandler && "Invalid global handler");
14941494

1495-
RPCServer = new RPCServerTy();
1495+
RPCServer = new RPCServerTy(*this);
14961496
assert(RPCServer && "Invalid RPC server");
14971497

14981498
return Plugin::success();

openmp/libomptarget/plugins-nextgen/common/src/RPC.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ using namespace llvm;
2121
using namespace omp;
2222
using namespace target;
2323

24+
RPCServerTy::RPCServerTy(plugin::GenericPluginTy &Plugin)
25+
: Handles(Plugin.getNumDevices()) {}
26+
2427
llvm::Expected<bool>
2528
RPCServerTy::isDeviceUsingRPC(plugin::GenericDeviceTy &Device,
2629
plugin::GenericGlobalHandlerTy &Handler,
@@ -101,7 +104,6 @@ Error RPCServerTy::initDevice(plugin::GenericDeviceTy &Device,
101104
if (auto Err = Device.dataSubmit(ClientPtr, ClientBuffer,
102105
rpc_get_client_size(), nullptr))
103106
return Err;
104-
Handles.resize(Device.getDeviceId() + 1);
105107
Handles[Device.getDeviceId()] = RPCDevice.handle;
106108
#endif
107109
return Error::success();

0 commit comments

Comments
 (0)