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

Alex Duran via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Sep 8 05:47:48 PDT 2026


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

>From cdd1baeb2f65b2b47b5ae9e75dce296b55f45d20 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/exports             |  1 -
 offload/liboffload/src/OffloadImpl.cpp |  4 ++++
 offload/libomptarget/interface.cpp     | 10 +++++++---
 3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/offload/liboffload/exports b/offload/liboffload/exports
index bcd3302f6e963..309fd3364c31f 100644
--- a/offload/liboffload/exports
+++ b/offload/liboffload/exports
@@ -7,7 +7,6 @@ global:
   extern "C++" {
     error::OffloadError::ID;
     "error::OffloadErrCategory()";
-    "llvm::omp::target::RPCServerTy::registerCallback(unsigned int (*)(void*, unsigned int))";
     "llvm::omp::target::plugin::GenericPluginTy::async_barrier(omp_interop_val_t*)";
     "llvm::omp::target::plugin::GenericPluginTy::create_interop(int, int, interop_spec_t*)";
     "llvm::omp::target::plugin::GenericPluginTy::data_alloc(int, long, void*, int)";
diff --git a/offload/liboffload/src/OffloadImpl.cpp b/offload/liboffload/src/OffloadImpl.cpp
index a03b160fe5b2f..36ae800d047ca 100644
--- a/offload/liboffload/src/OffloadImpl.cpp
+++ b/offload/liboffload/src/OffloadImpl.cpp
@@ -465,6 +465,10 @@ Error olGetPlatformInfoSize_impl(ol_platform_handle_t Platform,
 
 Error olPlatformRegisterRPCCallback_impl(ol_platform_handle_t Platform,
                                          ol_platform_rpc_cb_t Callback) {
+  if (!Platform->Plugin || !Platform->Plugin->is_initialized() ||
+      Platform->Plugin->getNumDevices() == 0)
+    return Error::success();
+
   Platform->Plugin->getRPCServer().registerCallback(Callback);
   return Error::success();
 }
diff --git a/offload/libomptarget/interface.cpp b/offload/libomptarget/interface.cpp
index 5b5cc310b1b31..1afc2a7fe51eb 100644
--- a/offload/libomptarget/interface.cpp
+++ b/offload/libomptarget/interface.cpp
@@ -652,7 +652,11 @@ 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));
 }

>From 6aede1c496ff6ee87f3d0f28495594ca55ec5c37 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/liboffload/exports                               | 1 -
 offload/plugins-nextgen/common/include/PluginInterface.h | 3 ---
 offload/plugins-nextgen/common/src/PluginInterface.cpp   | 2 --
 3 files changed, 6 deletions(-)

diff --git a/offload/liboffload/exports b/offload/liboffload/exports
index 309fd3364c31f..76c7f9bc75787 100644
--- a/offload/liboffload/exports
+++ b/offload/liboffload/exports
@@ -22,7 +22,6 @@ global:
     "llvm::omp::target::plugin::GenericPluginTy::is_initialized() const";
     "llvm::omp::target::plugin::GenericPluginTy::launch_kernel(int, void*, llvm::omp::target::plugin::KernelLaunchArgsTy&, __tgt_async_info*)";
     "llvm::omp::target::plugin::GenericPluginTy::load_binary(int, __tgt_device_image*, __tgt_device_binary*)";
-    "llvm::omp::target::plugin::GenericPluginTy::number_of_devices()";
     "llvm::omp::target::plugin::GenericPluginTy::release_interop(int, omp_interop_val_t*)";
     "llvm::omp::target::plugin::GenericPluginTy::set_device_identifier(int, int)";
     "llvm::omp::target::plugin::GenericPluginTy::sync_barrier(omp_interop_val_t*)";
diff --git a/offload/plugins-nextgen/common/include/PluginInterface.h b/offload/plugins-nextgen/common/include/PluginInterface.h
index 2e9340daa8c13..658f439f261ca 100644
--- a/offload/plugins-nextgen/common/include/PluginInterface.h
+++ b/offload/plugins-nextgen/common/include/PluginInterface.h
@@ -1699,9 +1699,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 4b5591a0064f3..cc5de4a2dfcaa 100644
--- a/offload/plugins-nextgen/common/src/PluginInterface.cpp
+++ b/offload/plugins-nextgen/common/src/PluginInterface.cpp
@@ -1485,8 +1485,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