[llvm-branch-commits] [openmp] fce4c0a - [OpenMP] Start organizing PluginManager, PluginAdaptors (#73875)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sat Dec 2 16:43:21 PST 2023
Author: Johannes Doerfert
Date: 2023-11-30T13:47:47-08:00
New Revision: fce4c0acd6db4bd8598db7eb471ccca60dc05406
URL: https://github.com/llvm/llvm-project/commit/fce4c0acd6db4bd8598db7eb471ccca60dc05406
DIFF: https://github.com/llvm/llvm-project/commit/fce4c0acd6db4bd8598db7eb471ccca60dc05406.diff
LOG: [OpenMP] Start organizing PluginManager, PluginAdaptors (#73875)
Added:
openmp/libomptarget/include/PluginManager.h
openmp/libomptarget/src/PluginManager.cpp
Modified:
openmp/libomptarget/include/device.h
openmp/libomptarget/include/rtl.h
openmp/libomptarget/src/CMakeLists.txt
openmp/libomptarget/src/OpenMP/InteropAPI.cpp
openmp/libomptarget/src/api.cpp
openmp/libomptarget/src/device.cpp
openmp/libomptarget/src/interface.cpp
openmp/libomptarget/src/omptarget.cpp
openmp/libomptarget/src/rtl.cpp
Removed:
################################################################################
diff --git a/openmp/libomptarget/include/PluginManager.h b/openmp/libomptarget/include/PluginManager.h
new file mode 100644
index 0000000000000..6a91e245453c8
--- /dev/null
+++ b/openmp/libomptarget/include/PluginManager.h
@@ -0,0 +1,226 @@
+//===-- PluginManager.h - Plugin loading and communication API --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Declarations for managing devices that are handled by RTL plugins.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef OMPTARGET_PLUGIN_MANAGER_H
+#define OMPTARGET_PLUGIN_MANAGER_H
+
+#include "Shared/APITypes.h"
+
+#include "device.h"
+
+#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/DynamicLibrary.h"
+
+#include <list>
+#include <mutex>
+
+struct PluginAdaptorTy {
+ typedef int32_t(init_plugin_ty)();
+ typedef int32_t(is_valid_binary_ty)(void *);
+ typedef int32_t(is_valid_binary_info_ty)(void *, void *);
+ typedef int32_t(is_data_exchangable_ty)(int32_t, int32_t);
+ typedef int32_t(number_of_devices_ty)();
+ typedef int32_t(init_device_ty)(int32_t);
+ typedef __tgt_target_table *(load_binary_ty)(int32_t, void *);
+ typedef void *(data_alloc_ty)(int32_t, int64_t, void *, int32_t);
+ typedef int32_t(data_submit_ty)(int32_t, void *, void *, int64_t);
+ typedef int32_t(data_submit_async_ty)(int32_t, void *, void *, int64_t,
+ __tgt_async_info *);
+ typedef int32_t(data_retrieve_ty)(int32_t, void *, void *, int64_t);
+ typedef int32_t(data_retrieve_async_ty)(int32_t, void *, void *, int64_t,
+ __tgt_async_info *);
+ typedef int32_t(data_exchange_ty)(int32_t, void *, int32_t, void *, int64_t);
+ typedef int32_t(data_exchange_async_ty)(int32_t, void *, int32_t, void *,
+ int64_t, __tgt_async_info *);
+ typedef int32_t(data_delete_ty)(int32_t, void *, int32_t);
+ typedef int32_t(launch_kernel_ty)(int32_t, void *, void **, ptr
diff _t *,
+ const KernelArgsTy *, __tgt_async_info *);
+ typedef int64_t(init_requires_ty)(int64_t);
+ typedef int32_t(synchronize_ty)(int32_t, __tgt_async_info *);
+ typedef int32_t(query_async_ty)(int32_t, __tgt_async_info *);
+ typedef int32_t(supports_empty_images_ty)();
+ typedef void(print_device_info_ty)(int32_t);
+ typedef void(set_info_flag_ty)(uint32_t);
+ typedef int32_t(create_event_ty)(int32_t, void **);
+ typedef int32_t(record_event_ty)(int32_t, void *, __tgt_async_info *);
+ typedef int32_t(wait_event_ty)(int32_t, void *, __tgt_async_info *);
+ typedef int32_t(sync_event_ty)(int32_t, void *);
+ typedef int32_t(destroy_event_ty)(int32_t, void *);
+ typedef int32_t(release_async_info_ty)(int32_t, __tgt_async_info *);
+ typedef int32_t(init_async_info_ty)(int32_t, __tgt_async_info **);
+ typedef int64_t(init_device_into_ty)(int64_t, __tgt_device_info *,
+ const char **);
+ typedef int32_t(data_lock_ty)(int32_t, void *, int64_t, void **);
+ typedef int32_t(data_unlock_ty)(int32_t, void *);
+ typedef int32_t(data_notify_mapped_ty)(int32_t, void *, int64_t);
+ typedef int32_t(data_notify_unmapped_ty)(int32_t, void *);
+ typedef int32_t(set_device_offset_ty)(int32_t);
+ typedef int32_t(activate_record_replay_ty)(int32_t, uint64_t, void *, bool,
+ bool, uint64_t &);
+
+ int32_t Idx = -1; // RTL index, index is the number of devices
+ // of other RTLs that were registered before,
+ // i.e. the OpenMP index of the first device
+ // to be registered with this RTL.
+ int32_t NumberOfDevices = -1; // Number of devices this RTL deals with.
+
+ std::unique_ptr<llvm::sys::DynamicLibrary> LibraryHandler;
+
+#ifdef OMPTARGET_DEBUG
+ std::string RTLName;
+#endif
+
+ // Functions implemented in the RTL.
+ init_plugin_ty *init_plugin = nullptr;
+ is_valid_binary_ty *is_valid_binary = nullptr;
+ is_valid_binary_info_ty *is_valid_binary_info = nullptr;
+ is_data_exchangable_ty *is_data_exchangable = nullptr;
+ number_of_devices_ty *number_of_devices = nullptr;
+ init_device_ty *init_device = nullptr;
+ load_binary_ty *load_binary = nullptr;
+ data_alloc_ty *data_alloc = nullptr;
+ data_submit_ty *data_submit = nullptr;
+ data_submit_async_ty *data_submit_async = nullptr;
+ data_retrieve_ty *data_retrieve = nullptr;
+ data_retrieve_async_ty *data_retrieve_async = nullptr;
+ data_exchange_ty *data_exchange = nullptr;
+ data_exchange_async_ty *data_exchange_async = nullptr;
+ data_delete_ty *data_delete = nullptr;
+ launch_kernel_ty *launch_kernel = nullptr;
+ init_requires_ty *init_requires = nullptr;
+ synchronize_ty *synchronize = nullptr;
+ query_async_ty *query_async = nullptr;
+ supports_empty_images_ty *supports_empty_images = nullptr;
+ set_info_flag_ty *set_info_flag = nullptr;
+ print_device_info_ty *print_device_info = nullptr;
+ create_event_ty *create_event = nullptr;
+ record_event_ty *record_event = nullptr;
+ wait_event_ty *wait_event = nullptr;
+ sync_event_ty *sync_event = nullptr;
+ destroy_event_ty *destroy_event = nullptr;
+ init_async_info_ty *init_async_info = nullptr;
+ init_device_into_ty *init_device_info = nullptr;
+ release_async_info_ty *release_async_info = nullptr;
+ data_lock_ty *data_lock = nullptr;
+ data_unlock_ty *data_unlock = nullptr;
+ data_notify_mapped_ty *data_notify_mapped = nullptr;
+ data_notify_unmapped_ty *data_notify_unmapped = nullptr;
+ set_device_offset_ty *set_device_offset = nullptr;
+ activate_record_replay_ty *activate_record_replay = nullptr;
+
+ // Are there images associated with this RTL.
+ bool IsUsed = false;
+
+ llvm::DenseSet<const __tgt_device_image *> UsedImages;
+
+ // Mutex for thread-safety when calling RTL interface functions.
+ // It is easier to enforce thread-safety at the libomptarget level,
+ // so that developers of new RTLs do not have to worry about it.
+ std::mutex Mtx;
+};
+
+/// RTLs identified in the system.
+struct PluginAdaptorManagerTy {
+ // List of the detected runtime libraries.
+ std::list<PluginAdaptorTy> AllRTLs;
+
+ // Array of pointers to the detected runtime libraries that have compatible
+ // binaries.
+ llvm::SmallVector<PluginAdaptorTy *> UsedRTLs;
+
+ int64_t RequiresFlags = OMP_REQ_UNDEFINED;
+
+ explicit PluginAdaptorManagerTy() = default;
+
+ // Register the clauses of the requires directive.
+ void registerRequires(int64_t Flags);
+
+ // Initialize RTL if it has not been initialized
+ void initRTLonce(PluginAdaptorTy &RTL);
+
+ // Initialize all RTLs
+ void initAllRTLs();
+
+ // Register a shared library with all (compatible) RTLs.
+ void registerLib(__tgt_bin_desc *Desc);
+
+ // Unregister a shared library from all RTLs.
+ void unregisterLib(__tgt_bin_desc *Desc);
+
+ // not thread-safe, called from global constructor (i.e. once)
+ void loadRTLs();
+
+private:
+ static bool attemptLoadRTL(const std::string &RTLName, PluginAdaptorTy &RTL);
+};
+
+/// Struct for the data required to handle plugins
+struct PluginManager {
+ PluginManager(bool UseEventsForAtomicTransfers)
+ : UseEventsForAtomicTransfers(UseEventsForAtomicTransfers) {}
+
+ /// RTLs identified on the host
+ PluginAdaptorManagerTy RTLs;
+
+ /// Executable images and information extracted from the input images passed
+ /// to the runtime.
+ std::list<std::pair<__tgt_device_image, __tgt_image_info>> Images;
+
+ /// Devices associated with RTLs
+ llvm::SmallVector<std::unique_ptr<DeviceTy>> Devices;
+ std::mutex RTLsMtx; ///< For RTLs and Devices
+
+ /// Translation table retreived from the binary
+ HostEntriesBeginToTransTableTy HostEntriesBeginToTransTable;
+ std::mutex TrlTblMtx; ///< For Translation Table
+ /// Host offload entries in order of image registration
+ llvm::SmallVector<__tgt_offload_entry *> HostEntriesBeginRegistrationOrder;
+
+ /// Map from ptrs on the host to an entry in the Translation Table
+ HostPtrToTableMapTy HostPtrToTableMap;
+ std::mutex TblMapMtx; ///< For HostPtrToTableMap
+
+ // Store target policy (disabled, mandatory, default)
+ kmp_target_offload_kind_t TargetOffloadPolicy = tgt_default;
+ std::mutex TargetOffloadMtx; ///< For TargetOffloadPolicy
+
+ /// Flag to indicate if we use events to ensure the atomicity of
+ /// map clauses or not. Can be modified with an environment variable.
+ const bool UseEventsForAtomicTransfers;
+
+ // Work around for plugins that call dlopen on shared libraries that call
+ // tgt_register_lib during their initialisation. Stash the pointers in a
+ // vector until the plugins are all initialised and then register them.
+ bool delayRegisterLib(__tgt_bin_desc *Desc) {
+ if (RTLsLoaded)
+ return false;
+ DelayedBinDesc.push_back(Desc);
+ return true;
+ }
+
+ void registerDelayedLibraries() {
+ // Only called by libomptarget constructor
+ RTLsLoaded = true;
+ for (auto *Desc : DelayedBinDesc)
+ __tgt_register_lib(Desc);
+ DelayedBinDesc.clear();
+ }
+
+private:
+ bool RTLsLoaded = false;
+ llvm::SmallVector<__tgt_bin_desc *> DelayedBinDesc;
+};
+
+extern PluginManager *PM;
+
+#endif // OMPTARGET_PLUGIN_MANAGER_H
diff --git a/openmp/libomptarget/include/device.h b/openmp/libomptarget/include/device.h
index 9cea6e6c93930..5e58879bd738b 100644
--- a/openmp/libomptarget/include/device.h
+++ b/openmp/libomptarget/include/device.h
@@ -28,10 +28,8 @@
#include "OpenMP/Mapping.h"
-#include "llvm/ADT/SmallVector.h"
-
// Forward declarations.
-struct RTLInfoTy;
+struct PluginAdaptorTy;
struct __tgt_bin_desc;
struct __tgt_target_table;
@@ -53,7 +51,7 @@ typedef std::map<__tgt_bin_desc *, PendingCtorDtorListsTy>
struct DeviceTy {
int32_t DeviceID;
- RTLInfoTy *RTL;
+ PluginAdaptorTy *RTL;
int32_t RTLDeviceID;
bool IsInit;
@@ -77,7 +75,7 @@ struct DeviceTy {
std::mutex PendingGlobalsMtx;
- DeviceTy(RTLInfoTy *RTL);
+ DeviceTy(PluginAdaptorTy *RTL);
// DeviceTy is not copyable
DeviceTy(const DeviceTy &D) = delete;
DeviceTy &operator=(const DeviceTy &D) = delete;
@@ -243,63 +241,4 @@ struct DeviceTy {
extern bool deviceIsReady(int DeviceNum);
-/// Struct for the data required to handle plugins
-struct PluginManager {
- PluginManager(bool UseEventsForAtomicTransfers)
- : UseEventsForAtomicTransfers(UseEventsForAtomicTransfers) {}
-
- /// RTLs identified on the host
- RTLsTy RTLs;
-
- /// Executable images and information extracted from the input images passed
- /// to the runtime.
- std::list<std::pair<__tgt_device_image, __tgt_image_info>> Images;
-
- /// Devices associated with RTLs
- llvm::SmallVector<std::unique_ptr<DeviceTy>> Devices;
- std::mutex RTLsMtx; ///< For RTLs and Devices
-
- /// Translation table retreived from the binary
- HostEntriesBeginToTransTableTy HostEntriesBeginToTransTable;
- std::mutex TrlTblMtx; ///< For Translation Table
- /// Host offload entries in order of image registration
- llvm::SmallVector<__tgt_offload_entry *> HostEntriesBeginRegistrationOrder;
-
- /// Map from ptrs on the host to an entry in the Translation Table
- HostPtrToTableMapTy HostPtrToTableMap;
- std::mutex TblMapMtx; ///< For HostPtrToTableMap
-
- // Store target policy (disabled, mandatory, default)
- kmp_target_offload_kind_t TargetOffloadPolicy = tgt_default;
- std::mutex TargetOffloadMtx; ///< For TargetOffloadPolicy
-
- /// Flag to indicate if we use events to ensure the atomicity of
- /// map clauses or not. Can be modified with an environment variable.
- const bool UseEventsForAtomicTransfers;
-
- // Work around for plugins that call dlopen on shared libraries that call
- // tgt_register_lib during their initialisation. Stash the pointers in a
- // vector until the plugins are all initialised and then register them.
- bool delayRegisterLib(__tgt_bin_desc *Desc) {
- if (RTLsLoaded)
- return false;
- DelayedBinDesc.push_back(Desc);
- return true;
- }
-
- void registerDelayedLibraries() {
- // Only called by libomptarget constructor
- RTLsLoaded = true;
- for (auto *Desc : DelayedBinDesc)
- __tgt_register_lib(Desc);
- DelayedBinDesc.clear();
- }
-
-private:
- bool RTLsLoaded = false;
- llvm::SmallVector<__tgt_bin_desc *> DelayedBinDesc;
-};
-
-extern PluginManager *PM;
-
#endif
diff --git a/openmp/libomptarget/include/rtl.h b/openmp/libomptarget/include/rtl.h
index 49a62685dcdbf..d110e89de5f14 100644
--- a/openmp/libomptarget/include/rtl.h
+++ b/openmp/libomptarget/include/rtl.h
@@ -13,162 +13,12 @@
#ifndef _OMPTARGET_RTL_H
#define _OMPTARGET_RTL_H
-#include "omptarget.h"
-#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/SmallVector.h"
-#include "llvm/Support/DynamicLibrary.h"
#include "omptarget.h"
#include <cstdint>
-#include <list>
#include <map>
-#include <mutex>
-#include <string>
-
-// Forward declarations.
-struct DeviceTy;
-struct __tgt_bin_desc;
-
-struct RTLInfoTy {
- typedef int32_t(init_plugin_ty)();
- typedef int32_t(is_valid_binary_ty)(void *);
- typedef int32_t(is_valid_binary_info_ty)(void *, void *);
- typedef int32_t(is_data_exchangable_ty)(int32_t, int32_t);
- typedef int32_t(number_of_devices_ty)();
- typedef int32_t(init_device_ty)(int32_t);
- typedef __tgt_target_table *(load_binary_ty)(int32_t, void *);
- typedef void *(data_alloc_ty)(int32_t, int64_t, void *, int32_t);
- typedef int32_t(data_submit_ty)(int32_t, void *, void *, int64_t);
- typedef int32_t(data_submit_async_ty)(int32_t, void *, void *, int64_t,
- __tgt_async_info *);
- typedef int32_t(data_retrieve_ty)(int32_t, void *, void *, int64_t);
- typedef int32_t(data_retrieve_async_ty)(int32_t, void *, void *, int64_t,
- __tgt_async_info *);
- typedef int32_t(data_exchange_ty)(int32_t, void *, int32_t, void *, int64_t);
- typedef int32_t(data_exchange_async_ty)(int32_t, void *, int32_t, void *,
- int64_t, __tgt_async_info *);
- typedef int32_t(data_delete_ty)(int32_t, void *, int32_t);
- typedef int32_t(launch_kernel_ty)(int32_t, void *, void **, ptr
diff _t *,
- const KernelArgsTy *, __tgt_async_info *);
- typedef int64_t(init_requires_ty)(int64_t);
- typedef int32_t(synchronize_ty)(int32_t, __tgt_async_info *);
- typedef int32_t(query_async_ty)(int32_t, __tgt_async_info *);
- typedef int32_t(supports_empty_images_ty)();
- typedef void(print_device_info_ty)(int32_t);
- typedef void(set_info_flag_ty)(uint32_t);
- typedef int32_t(create_event_ty)(int32_t, void **);
- typedef int32_t(record_event_ty)(int32_t, void *, __tgt_async_info *);
- typedef int32_t(wait_event_ty)(int32_t, void *, __tgt_async_info *);
- typedef int32_t(sync_event_ty)(int32_t, void *);
- typedef int32_t(destroy_event_ty)(int32_t, void *);
- typedef int32_t(release_async_info_ty)(int32_t, __tgt_async_info *);
- typedef int32_t(init_async_info_ty)(int32_t, __tgt_async_info **);
- typedef int64_t(init_device_into_ty)(int64_t, __tgt_device_info *,
- const char **);
- typedef int32_t(data_lock_ty)(int32_t, void *, int64_t, void **);
- typedef int32_t(data_unlock_ty)(int32_t, void *);
- typedef int32_t(data_notify_mapped_ty)(int32_t, void *, int64_t);
- typedef int32_t(data_notify_unmapped_ty)(int32_t, void *);
- typedef int32_t(set_device_offset_ty)(int32_t);
- typedef int32_t(activate_record_replay_ty)(int32_t, uint64_t, void *, bool,
- bool, uint64_t &);
-
- int32_t Idx = -1; // RTL index, index is the number of devices
- // of other RTLs that were registered before,
- // i.e. the OpenMP index of the first device
- // to be registered with this RTL.
- int32_t NumberOfDevices = -1; // Number of devices this RTL deals with.
-
- std::unique_ptr<llvm::sys::DynamicLibrary> LibraryHandler;
-
-#ifdef OMPTARGET_DEBUG
- std::string RTLName;
-#endif
-
- // Functions implemented in the RTL.
- init_plugin_ty *init_plugin = nullptr;
- is_valid_binary_ty *is_valid_binary = nullptr;
- is_valid_binary_info_ty *is_valid_binary_info = nullptr;
- is_data_exchangable_ty *is_data_exchangable = nullptr;
- number_of_devices_ty *number_of_devices = nullptr;
- init_device_ty *init_device = nullptr;
- load_binary_ty *load_binary = nullptr;
- data_alloc_ty *data_alloc = nullptr;
- data_submit_ty *data_submit = nullptr;
- data_submit_async_ty *data_submit_async = nullptr;
- data_retrieve_ty *data_retrieve = nullptr;
- data_retrieve_async_ty *data_retrieve_async = nullptr;
- data_exchange_ty *data_exchange = nullptr;
- data_exchange_async_ty *data_exchange_async = nullptr;
- data_delete_ty *data_delete = nullptr;
- launch_kernel_ty *launch_kernel = nullptr;
- init_requires_ty *init_requires = nullptr;
- synchronize_ty *synchronize = nullptr;
- query_async_ty *query_async = nullptr;
- supports_empty_images_ty *supports_empty_images = nullptr;
- set_info_flag_ty *set_info_flag = nullptr;
- print_device_info_ty *print_device_info = nullptr;
- create_event_ty *create_event = nullptr;
- record_event_ty *record_event = nullptr;
- wait_event_ty *wait_event = nullptr;
- sync_event_ty *sync_event = nullptr;
- destroy_event_ty *destroy_event = nullptr;
- init_async_info_ty *init_async_info = nullptr;
- init_device_into_ty *init_device_info = nullptr;
- release_async_info_ty *release_async_info = nullptr;
- data_lock_ty *data_lock = nullptr;
- data_unlock_ty *data_unlock = nullptr;
- data_notify_mapped_ty *data_notify_mapped = nullptr;
- data_notify_unmapped_ty *data_notify_unmapped = nullptr;
- set_device_offset_ty *set_device_offset = nullptr;
- activate_record_replay_ty *activate_record_replay = nullptr;
-
- // Are there images associated with this RTL.
- bool IsUsed = false;
-
- llvm::DenseSet<const __tgt_device_image *> UsedImages;
-
- // Mutex for thread-safety when calling RTL interface functions.
- // It is easier to enforce thread-safety at the libomptarget level,
- // so that developers of new RTLs do not have to worry about it.
- std::mutex Mtx;
-};
-
-/// RTLs identified in the system.
-struct RTLsTy {
- // List of the detected runtime libraries.
- std::list<RTLInfoTy> AllRTLs;
-
- // Array of pointers to the detected runtime libraries that have compatible
- // binaries.
- llvm::SmallVector<RTLInfoTy *> UsedRTLs;
-
- int64_t RequiresFlags = OMP_REQ_UNDEFINED;
-
- explicit RTLsTy() = default;
-
- // Register the clauses of the requires directive.
- void registerRequires(int64_t Flags);
-
- // Initialize RTL if it has not been initialized
- void initRTLonce(RTLInfoTy &RTL);
-
- // Initialize all RTLs
- void initAllRTLs();
-
- // Register a shared library with all (compatible) RTLs.
- void registerLib(__tgt_bin_desc *Desc);
-
- // Unregister a shared library from all RTLs.
- void unregisterLib(__tgt_bin_desc *Desc);
-
- // not thread-safe, called from global constructor (i.e. once)
- void loadRTLs();
-
-private:
- static bool attemptLoadRTL(const std::string &RTLName, RTLInfoTy &RTL);
-};
/// Map between the host entry begin and the translation table. Each
/// registered library gets one TranslationTable. Use the map from
diff --git a/openmp/libomptarget/src/CMakeLists.txt b/openmp/libomptarget/src/CMakeLists.txt
index 8daa448a57e90..ca40ace456458 100644
--- a/openmp/libomptarget/src/CMakeLists.txt
+++ b/openmp/libomptarget/src/CMakeLists.txt
@@ -21,6 +21,7 @@ add_llvm_library(omptarget
omptarget.cpp
rtl.cpp
LegacyAPI.cpp
+ PluginManager.cpp
OpenMP/Mapping.cpp
OpenMP/InteropAPI.cpp
diff --git a/openmp/libomptarget/src/OpenMP/InteropAPI.cpp b/openmp/libomptarget/src/OpenMP/InteropAPI.cpp
index ace0fecd0a436..6a40dbca87afd 100644
--- a/openmp/libomptarget/src/OpenMP/InteropAPI.cpp
+++ b/openmp/libomptarget/src/OpenMP/InteropAPI.cpp
@@ -10,6 +10,7 @@
#include "OpenMP/InternalTypes.h"
#include "OpenMP/omp.h"
+#include "PluginManager.h"
#include "device.h"
#include "omptarget.h"
diff --git a/openmp/libomptarget/src/PluginManager.cpp b/openmp/libomptarget/src/PluginManager.cpp
new file mode 100644
index 0000000000000..260aecd47659b
--- /dev/null
+++ b/openmp/libomptarget/src/PluginManager.cpp
@@ -0,0 +1,15 @@
+//===-- PluginManager.cpp - Plugin loading and communication API ---------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Functionality for handling plugins.
+//
+//===----------------------------------------------------------------------===//
+
+#include "PluginManager.h"
+
+PluginManager *PM;
diff --git a/openmp/libomptarget/src/api.cpp b/openmp/libomptarget/src/api.cpp
index 42379f42d43ba..e44421428adab 100644
--- a/openmp/libomptarget/src/api.cpp
+++ b/openmp/libomptarget/src/api.cpp
@@ -10,6 +10,7 @@
//
//===----------------------------------------------------------------------===//
+#include "PluginManager.h"
#include "device.h"
#include "omptarget.h"
#include "private.h"
diff --git a/openmp/libomptarget/src/device.cpp b/openmp/libomptarget/src/device.cpp
index 742ab156da317..8e292eb7b4fdc 100644
--- a/openmp/libomptarget/src/device.cpp
+++ b/openmp/libomptarget/src/device.cpp
@@ -13,6 +13,7 @@
#include "device.h"
#include "OpenMP/OMPT/Callback.h"
#include "OpenMP/OMPT/Interface.h"
+#include "PluginManager.h"
#include "omptarget.h"
#include "private.h"
#include "rtl.h"
@@ -58,7 +59,7 @@ int HostDataToTargetTy::addEventIfNecessary(DeviceTy &Device,
return OFFLOAD_SUCCESS;
}
-DeviceTy::DeviceTy(RTLInfoTy *RTL)
+DeviceTy::DeviceTy(PluginAdaptorTy *RTL)
: DeviceID(-1), RTL(RTL), RTLDeviceID(-1), IsInit(false), InitFlag(),
HasPendingGlobals(false), PendingCtorsDtors(), PendingGlobalsMtx() {}
diff --git a/openmp/libomptarget/src/interface.cpp b/openmp/libomptarget/src/interface.cpp
index 3dda2e28e7cb7..97cada94527f0 100644
--- a/openmp/libomptarget/src/interface.cpp
+++ b/openmp/libomptarget/src/interface.cpp
@@ -13,6 +13,7 @@
#include "OpenMP/OMPT/Interface.h"
#include "OpenMP/OMPT/Callback.h"
+#include "PluginManager.h"
#include "device.h"
#include "omptarget.h"
#include "private.h"
diff --git a/openmp/libomptarget/src/omptarget.cpp b/openmp/libomptarget/src/omptarget.cpp
index f549afe24f1ae..5b43c7e67eaf7 100644
--- a/openmp/libomptarget/src/omptarget.cpp
+++ b/openmp/libomptarget/src/omptarget.cpp
@@ -14,6 +14,7 @@
#include "omptarget.h"
#include "OpenMP/OMPT/Callback.h"
#include "OpenMP/OMPT/Interface.h"
+#include "PluginManager.h"
#include "device.h"
#include "private.h"
#include "rtl.h"
diff --git a/openmp/libomptarget/src/rtl.cpp b/openmp/libomptarget/src/rtl.cpp
index 2a89eebcc0adb..6248acff686dc 100644
--- a/openmp/libomptarget/src/rtl.cpp
+++ b/openmp/libomptarget/src/rtl.cpp
@@ -13,6 +13,7 @@
#include "llvm/Object/OffloadBinary.h"
#include "OpenMP/OMPT/Callback.h"
+#include "PluginManager.h"
#include "device.h"
#include "private.h"
#include "rtl.h"
@@ -39,8 +40,6 @@ static const char *RTLNames[] = {
/* AMDGPU target */ "libomptarget.rtl.amdgpu",
};
-PluginManager *PM;
-
static char *ProfileTraceFile = nullptr;
#ifdef OMPT_SUPPORT
@@ -91,7 +90,7 @@ __attribute__((destructor(101))) void deinit() {
}
}
-void RTLsTy::loadRTLs() {
+void PluginAdaptorManagerTy::loadRTLs() {
// Parse environment variable OMP_TARGET_OFFLOAD (if set)
PM->TargetOffloadPolicy =
(kmp_target_offload_kind_t)__kmpc_get_target_offload();
@@ -106,7 +105,7 @@ void RTLsTy::loadRTLs() {
for (const char *Name : RTLNames) {
AllRTLs.emplace_back();
- RTLInfoTy &RTL = AllRTLs.back();
+ PluginAdaptorTy &RTL = AllRTLs.back();
const std::string BaseRTLName(Name);
if (!attemptLoadRTL(BaseRTLName + ".so", RTL))
@@ -116,7 +115,7 @@ void RTLsTy::loadRTLs() {
DP("RTLs loaded!\n");
}
-bool RTLsTy::attemptLoadRTL(const std::string &RTLName, RTLInfoTy &RTL) {
+bool PluginAdaptorManagerTy::attemptLoadRTL(const std::string &RTLName, PluginAdaptorTy &RTL) {
const char *Name = RTLName.c_str();
DP("Loading library '%s'...\n", Name);
@@ -259,7 +258,7 @@ bool RTLsTy::attemptLoadRTL(const std::string &RTLName, RTLInfoTy &RTL) {
// Functionality for registering libs
static void registerImageIntoTranslationTable(TranslationTable &TT,
- RTLInfoTy &RTL,
+ PluginAdaptorTy &RTL,
__tgt_device_image *Image) {
// same size, as when we increase one, we also increase the other.
@@ -290,7 +289,7 @@ static void registerImageIntoTranslationTable(TranslationTable &TT,
static void registerGlobalCtorsDtorsForImage(__tgt_bin_desc *Desc,
__tgt_device_image *Img,
- RTLInfoTy *RTL) {
+ PluginAdaptorTy *RTL) {
for (int32_t I = 0; I < RTL->NumberOfDevices; ++I) {
DeviceTy &Device = *PM->Devices[RTL->Idx + I];
@@ -361,7 +360,7 @@ static __tgt_image_info getImageInfo(__tgt_device_image *Image) {
return __tgt_image_info{(*BinaryOrErr)->getArch().data()};
}
-void RTLsTy::registerRequires(int64_t Flags) {
+void PluginAdaptorManagerTy::registerRequires(int64_t Flags) {
// TODO: add more elaborate check.
// Minimal check: only set requires flags if previous value
// is undefined. This ensures that only the first call to this
@@ -402,7 +401,7 @@ void RTLsTy::registerRequires(int64_t Flags) {
Flags, RequiresFlags);
}
-void RTLsTy::initRTLonce(RTLInfoTy &R) {
+void PluginAdaptorManagerTy::initRTLonce(PluginAdaptorTy &R) {
// If this RTL is not already in use, initialize it.
if (R.IsUsed || !R.NumberOfDevices)
return;
@@ -430,12 +429,12 @@ void RTLsTy::initRTLonce(RTLInfoTy &R) {
DP("RTL " DPxMOD " has index %d!\n", DPxPTR(R.LibraryHandler.get()), R.Idx);
}
-void RTLsTy::initAllRTLs() {
+void PluginAdaptorManagerTy::initAllRTLs() {
for (auto &R : AllRTLs)
initRTLonce(R);
}
-void RTLsTy::registerLib(__tgt_bin_desc *Desc) {
+void PluginAdaptorManagerTy::registerLib(__tgt_bin_desc *Desc) {
PM->RTLsMtx.lock();
// Extract the exectuable image and extra information if availible.
@@ -449,7 +448,7 @@ void RTLsTy::registerLib(__tgt_bin_desc *Desc) {
__tgt_device_image *Img = &ImageAndInfo.first;
__tgt_image_info *Info = &ImageAndInfo.second;
- RTLInfoTy *FoundRTL = nullptr;
+ PluginAdaptorTy *FoundRTL = nullptr;
// Scan the RTLs that have associated images until we find one that supports
// the current image.
@@ -509,7 +508,7 @@ void RTLsTy::registerLib(__tgt_bin_desc *Desc) {
DP("Done registering entries!\n");
}
-void RTLsTy::unregisterLib(__tgt_bin_desc *Desc) {
+void PluginAdaptorManagerTy::unregisterLib(__tgt_bin_desc *Desc) {
DP("Unloading target library!\n");
PM->RTLsMtx.lock();
@@ -518,7 +517,7 @@ void RTLsTy::unregisterLib(__tgt_bin_desc *Desc) {
// Obtain the image and information that was previously extracted.
__tgt_device_image *Img = &ImageAndInfo.first;
- RTLInfoTy *FoundRTL = NULL;
+ PluginAdaptorTy *FoundRTL = NULL;
// Scan the RTLs that have associated images until we find one that supports
// the current image. We only need to scan RTLs that are already being used.
More information about the llvm-branch-commits
mailing list