[llvm-branch-commits] [llvm] [offload][omp] Route RPC callback registration through liboffload (PR #226448)

Alex Duran via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Sep 25 07:59:49 PDT 2026


https://github.com/adurang updated https://github.com/llvm/llvm-project/pull/226448

>From 039335cfd42d4996d186dbebb9a7885cdf4e0db8 Mon Sep 17 00:00:00 2001
From: "Duran, Alex" <alejandro.duran at intel.com>
Date: Mon, 7 Sep 2026 14:27:10 -0700
Subject: [PATCH 1/2] [offload][omp] Route RPC callback registration through
 liboffload

Replace __tgt_register_rpc_callback's direct iteration over plugins
with olIteratePlatforms + olPlatformRegisterRPCCallback, and drop the
now-unused RPCServerTy::registerCallback export. Move the
initialized/has-devices guard that used to live in libomptarget into
olPlatformRegisterRPCCallback_impl.
---
 offload/liboffload/src/OffloadImpl.cpp |  5 ++++-
 offload/libomptarget/interface.cpp     | 10 +++++++---
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/offload/liboffload/src/OffloadImpl.cpp b/offload/liboffload/src/OffloadImpl.cpp
index 237356f460a8fa..007d42dae5c4d9 100644
--- a/offload/liboffload/src/OffloadImpl.cpp
+++ b/offload/liboffload/src/OffloadImpl.cpp
@@ -475,8 +475,11 @@ Error olPlatformRegisterRPCCallback_impl(ol_platform_handle_t Platform,
   auto PluginOrErr = Platform->getPlugin();
   if (!PluginOrErr)
     return PluginOrErr.takeError();
+  GenericPluginTy *Plugin = *PluginOrErr;
+  if (Plugin->getNumDevices() == 0)
+    return Error::success();
 
-  (*PluginOrErr)->getRPCServer().registerCallback(Callback);
+  Plugin->getRPCServer().registerCallback(Callback);
   return Error::success();
 }
 
diff --git a/offload/libomptarget/interface.cpp b/offload/libomptarget/interface.cpp
index 5833925209fee4..17726b889a55b4 100644
--- a/offload/libomptarget/interface.cpp
+++ b/offload/libomptarget/interface.cpp
@@ -649,9 +649,13 @@ EXTERN void __tgt_register_rpc_callback(unsigned (*Callback)(void *,
   if (!PM)
     return;
 
-  for (auto &Plugin : PM->plugins())
-    if (Plugin.is_initialized() && Plugin.getNumDevices() > 0)
-      Plugin.getRPCServer().registerCallback(Callback);
+  olIteratePlatforms(
+      [](ol_platform_handle_t Platform, void *Data) {
+        olPlatformRegisterRPCCallback(
+            Platform, reinterpret_cast<ol_platform_rpc_cb_t>(Data));
+        return true;
+      },
+      reinterpret_cast<void *>(Callback));
 }
 
 EXTERN void *__tgt_get_mapped_ptr(int64_t DeviceId, const void *HostPtr) {

>From 44d8216c92f987e2fff436e01e1038999705edb9 Mon Sep 17 00:00:00 2001
From: "Duran, Alex" <alejandro.duran at intel.com>
Date: Tue, 8 Sep 2026 05:41:02 -0700
Subject: [PATCH 2/2] Remove number_of_devices

---
 offload/plugins-nextgen/common/include/PluginInterface.h | 3 ---
 offload/plugins-nextgen/common/src/PluginInterface.cpp   | 2 --
 2 files changed, 5 deletions(-)

diff --git a/offload/plugins-nextgen/common/include/PluginInterface.h b/offload/plugins-nextgen/common/include/PluginInterface.h
index 30ca13bdd01a3c..0537a38de5cabd 100644
--- a/offload/plugins-nextgen/common/include/PluginInterface.h
+++ b/offload/plugins-nextgen/common/include/PluginInterface.h
@@ -1734,9 +1734,6 @@ struct GenericPluginTy {
   /// Returns non-zero if the \p Image is compatible with the device.
   int32_t isDeviceCompatible(int32_t DeviceId, StringRef Image);
 
-  /// Return the number of devices this plugin can support.
-  int32_t number_of_devices();
-
   /// Initializes the record and replay mechanism inside the plugin.
   int32_t initialize_record_replay(int32_t DeviceId, int64_t MemorySize,
                                    void *VAddr, bool IsRecord, bool IsNative,
diff --git a/offload/plugins-nextgen/common/src/PluginInterface.cpp b/offload/plugins-nextgen/common/src/PluginInterface.cpp
index 355045de7541b7..2ffea87faad3c2 100644
--- a/offload/plugins-nextgen/common/src/PluginInterface.cpp
+++ b/offload/plugins-nextgen/common/src/PluginInterface.cpp
@@ -1511,8 +1511,6 @@ int32_t GenericPluginTy::isDeviceCompatible(int32_t DeviceId, StringRef Image) {
   }
 }
 
-int32_t GenericPluginTy::number_of_devices() { return getNumDevices(); }
-
 int32_t GenericPluginTy::initialize_record_replay(
     int32_t DeviceId, int64_t MemorySize, void *VAddr, bool IsRecord,
     bool IsNative, bool SaveOutput, bool EmitReport, const char *ReportFilename,



More information about the llvm-branch-commits mailing list