[Openmp-commits] [openmp] [Libomptarget][NFC] Remove concept of optional plugin functions (PR #82681)

Joseph Huber via Openmp-commits openmp-commits at lists.llvm.org
Thu Feb 22 12:16:27 PST 2024


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

Summary:
Ever since the introduction of the new plugins we haven't exercised the
concept of "optional" plugin functions. This is done in perparation for
making the plugins use a static interface as it will greatly simplify
the implementation if we assert that every function has the entrypoints.
Currently some unsupported functions will just return failure or some
other default value, so this shouldn't change anything.


>From ee71271631960b3609b7ce09d7634b575d1ab6d2 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Thu, 22 Feb 2024 14:14:22 -0600
Subject: [PATCH] [Libomptarget][NFC] Remove concept of optional plugin
 functions

Summary:
Ever since the introduction of the new plugins we haven't exercised the
concept of "optional" plugin functions. This is done in perparation for
making the plugins use a static interface as it will greatly simplify
the implementation if we assert that every function has the entrypoints.
Currently some unsupported functions will just return failure or some
other default value, so this shouldn't change anything.
---
 openmp/libomptarget/include/PluginManager.h   |  8 ++-
 .../libomptarget/include/Shared/PluginAPI.inc | 72 +++++++++----------
 openmp/libomptarget/src/PluginManager.cpp     |  4 +-
 3 files changed, 43 insertions(+), 41 deletions(-)

diff --git a/openmp/libomptarget/include/PluginManager.h b/openmp/libomptarget/include/PluginManager.h
index 5e5306ac776f05..77684285ddf15e 100644
--- a/openmp/libomptarget/include/PluginManager.h
+++ b/openmp/libomptarget/include/PluginManager.h
@@ -69,7 +69,7 @@ struct PluginAdaptorTy {
   /// Access to the shared object file representing the plugin.
   std::unique_ptr<llvm::sys::DynamicLibrary> LibraryHandler;
 
-#define PLUGIN_API_HANDLE(NAME, MANDATORY)                                     \
+#define PLUGIN_API_HANDLE(NAME)                                                \
   using NAME##_ty = decltype(__tgt_rtl_##NAME);                                \
   NAME##_ty *NAME = nullptr;
 
@@ -114,8 +114,10 @@ struct PluginManager {
   // Unregister a shared library from all RTLs.
   void unregisterLib(__tgt_bin_desc *Desc);
 
-  void addDeviceImage(__tgt_bin_desc &TgtBinDesc, __tgt_device_image &TgtDeviceImage) {
-    DeviceImages.emplace_back(std::make_unique<DeviceImageTy>(TgtBinDesc, TgtDeviceImage));
+  void addDeviceImage(__tgt_bin_desc &TgtBinDesc,
+                      __tgt_device_image &TgtDeviceImage) {
+    DeviceImages.emplace_back(
+        std::make_unique<DeviceImageTy>(TgtBinDesc, TgtDeviceImage));
   }
 
   /// Return the device presented to the user as device \p DeviceNo if it is
diff --git a/openmp/libomptarget/include/Shared/PluginAPI.inc b/openmp/libomptarget/include/Shared/PluginAPI.inc
index 3b982e30307acd..e445da6852f7b4 100644
--- a/openmp/libomptarget/include/Shared/PluginAPI.inc
+++ b/openmp/libomptarget/include/Shared/PluginAPI.inc
@@ -13,39 +13,39 @@
 
 // No include guards!
 
-PLUGIN_API_HANDLE(init_plugin, true);
-PLUGIN_API_HANDLE(is_valid_binary, true);
-PLUGIN_API_HANDLE(is_data_exchangable, false);
-PLUGIN_API_HANDLE(number_of_devices, true);
-PLUGIN_API_HANDLE(init_device, true);
-PLUGIN_API_HANDLE(load_binary, true);
-PLUGIN_API_HANDLE(get_global, true);
-PLUGIN_API_HANDLE(get_function, true);
-PLUGIN_API_HANDLE(data_alloc, true);
-PLUGIN_API_HANDLE(data_submit, true);
-PLUGIN_API_HANDLE(data_submit_async, false);
-PLUGIN_API_HANDLE(data_retrieve, true);
-PLUGIN_API_HANDLE(data_retrieve_async, false);
-PLUGIN_API_HANDLE(data_exchange, false);
-PLUGIN_API_HANDLE(data_exchange_async, false);
-PLUGIN_API_HANDLE(data_delete, true);
-PLUGIN_API_HANDLE(launch_kernel, true);
-PLUGIN_API_HANDLE(init_requires, false);
-PLUGIN_API_HANDLE(synchronize, false);
-PLUGIN_API_HANDLE(query_async, false);
-PLUGIN_API_HANDLE(set_info_flag, false);
-PLUGIN_API_HANDLE(print_device_info, false);
-PLUGIN_API_HANDLE(create_event, false);
-PLUGIN_API_HANDLE(record_event, false);
-PLUGIN_API_HANDLE(wait_event, false);
-PLUGIN_API_HANDLE(sync_event, false);
-PLUGIN_API_HANDLE(destroy_event, false);
-PLUGIN_API_HANDLE(init_async_info, false);
-PLUGIN_API_HANDLE(init_device_info, false);
-PLUGIN_API_HANDLE(data_lock, false);
-PLUGIN_API_HANDLE(data_unlock, false);
-PLUGIN_API_HANDLE(data_notify_mapped, false);
-PLUGIN_API_HANDLE(data_notify_unmapped, false);
-PLUGIN_API_HANDLE(set_device_offset, false);
-PLUGIN_API_HANDLE(initialize_record_replay, false);
-PLUGIN_API_HANDLE(use_auto_zero_copy, false);
+PLUGIN_API_HANDLE(init_plugin);
+PLUGIN_API_HANDLE(is_valid_binary);
+PLUGIN_API_HANDLE(is_data_exchangable);
+PLUGIN_API_HANDLE(number_of_devices);
+PLUGIN_API_HANDLE(init_device);
+PLUGIN_API_HANDLE(load_binary);
+PLUGIN_API_HANDLE(get_global);
+PLUGIN_API_HANDLE(get_function);
+PLUGIN_API_HANDLE(data_alloc);
+PLUGIN_API_HANDLE(data_submit);
+PLUGIN_API_HANDLE(data_submit_async);
+PLUGIN_API_HANDLE(data_retrieve);
+PLUGIN_API_HANDLE(data_retrieve_async);
+PLUGIN_API_HANDLE(data_exchange);
+PLUGIN_API_HANDLE(data_exchange_async);
+PLUGIN_API_HANDLE(data_delete);
+PLUGIN_API_HANDLE(launch_kernel);
+PLUGIN_API_HANDLE(init_requires);
+PLUGIN_API_HANDLE(synchronize);
+PLUGIN_API_HANDLE(query_async);
+PLUGIN_API_HANDLE(set_info_flag);
+PLUGIN_API_HANDLE(print_device_info);
+PLUGIN_API_HANDLE(create_event);
+PLUGIN_API_HANDLE(record_event);
+PLUGIN_API_HANDLE(wait_event);
+PLUGIN_API_HANDLE(sync_event);
+PLUGIN_API_HANDLE(destroy_event);
+PLUGIN_API_HANDLE(init_async_info);
+PLUGIN_API_HANDLE(init_device_info);
+PLUGIN_API_HANDLE(data_lock);
+PLUGIN_API_HANDLE(data_unlock);
+PLUGIN_API_HANDLE(data_notify_mapped);
+PLUGIN_API_HANDLE(data_notify_unmapped);
+PLUGIN_API_HANDLE(set_device_offset);
+PLUGIN_API_HANDLE(initialize_record_replay);
+PLUGIN_API_HANDLE(use_auto_zero_copy);
diff --git a/openmp/libomptarget/src/PluginManager.cpp b/openmp/libomptarget/src/PluginManager.cpp
index 09f9c6400569ca..928913275332c0 100644
--- a/openmp/libomptarget/src/PluginManager.cpp
+++ b/openmp/libomptarget/src/PluginManager.cpp
@@ -56,10 +56,10 @@ PluginAdaptorTy::PluginAdaptorTy(const std::string &Name,
 
 Error PluginAdaptorTy::init() {
 
-#define PLUGIN_API_HANDLE(NAME, MANDATORY)                                     \
+#define PLUGIN_API_HANDLE(NAME)                                                \
   NAME = reinterpret_cast<decltype(NAME)>(                                     \
       LibraryHandler->getAddressOfSymbol(GETNAME(__tgt_rtl_##NAME)));          \
-  if (MANDATORY && !NAME) {                                                    \
+  if (!NAME) {                                                                 \
     return createStringError(inconvertibleErrorCode(),                         \
                              "Invalid plugin as necessary interface function " \
                              "(%s) was not found.\n",                          \



More information about the Openmp-commits mailing list