[llvm] [Offload] Do not do not re-initialize RPC server (PR #218757)

Joseph Huber via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 25 12:51:16 PDT 2026


https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/218757

Summary:
This was done for every executable that was loaded. In the current
OpenMP use this never caused issues, but we need to check if this was
already done so we don't leak the memory.


>From 620a0f360c24dfcfb5d26e768a206f1db0e2d7ed Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Tue, 25 Aug 2026 14:46:58 -0500
Subject: [PATCH] [Offload] Do not do not re-initialize RPC server

Summary:
This was done for every executable that was loaded. In the current
OpenMP use this never caused issues, but we need to check if this was
already done so we don't leak the memory.
---
 offload/plugins-nextgen/common/src/RPC.cpp | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/offload/plugins-nextgen/common/src/RPC.cpp b/offload/plugins-nextgen/common/src/RPC.cpp
index 7c03c916058fb..35b7a88f00585 100644
--- a/offload/plugins-nextgen/common/src/RPC.cpp
+++ b/offload/plugins-nextgen/common/src/RPC.cpp
@@ -207,6 +207,12 @@ RPCServerTy::isDeviceUsingRPC(plugin::GenericDeviceTy &Device,
 Error RPCServerTy::initDevice(plugin::GenericDeviceTy &Device,
                               plugin::GenericGlobalHandlerTy &Handler,
                               plugin::DeviceImageTy &Image) {
+  {
+    std::lock_guard<decltype(BufferMutex)> Lock(BufferMutex);
+    if (Buffers[Device.getDeviceId()])
+      return Error::success();
+  }
+
   uint64_t NumPorts =
       std::min(Device.requestedRPCPortCount(), rpc::MAX_PORT_COUNT);
   auto RPCBufferOrErr = Device.allocate(



More information about the llvm-commits mailing list