Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
openmp/libomptarget/include/rtl.h
Show All 9 Lines | |||||
// | // | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
#ifndef _OMPTARGET_RTL_H | #ifndef _OMPTARGET_RTL_H | ||||
#define _OMPTARGET_RTL_H | #define _OMPTARGET_RTL_H | ||||
#include "omptarget.h" | #include "omptarget.h" | ||||
#include "llvm/ADT/DenseSet.h" | #include "llvm/ADT/DenseSet.h" | ||||
#include "llvm/ADT/SmallVector.h" | #include "llvm/ADT/SmallPtrSet.h" | ||||
#include "llvm/Support/DynamicLibrary.h" | #include "llvm/Support/DynamicLibrary.h" | ||||
#include "omptarget.h" | #include "omptarget.h" | ||||
#include <list> | #include <list> | ||||
#include <map> | #include <map> | ||||
#include <mutex> | #include <mutex> | ||||
#include <string> | #include <string> | ||||
#include <thread> | |||||
#include <atomic> | |||||
// Forward declarations. | // Forward declarations. | ||||
struct DeviceTy; | struct DeviceTy; | ||||
struct __tgt_bin_desc; | struct __tgt_bin_desc; | ||||
struct RTLInfoTy { | struct RTLInfoTy { | ||||
typedef int32_t(init_plugin_ty)(); | typedef int32_t(init_plugin_ty)(); | ||||
typedef int32_t(deinit_plugin_ty)(); | typedef int32_t(deinit_plugin_ty)(); | ||||
▲ Show 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | struct RTLsTy { | ||||
std::list<RTLInfoTy> AllRTLs; | std::list<RTLInfoTy> AllRTLs; | ||||
// Array of pointers to the detected runtime libraries that have compatible | // Array of pointers to the detected runtime libraries that have compatible | ||||
// binaries. | // binaries. | ||||
llvm::SmallVector<RTLInfoTy *> UsedRTLs; | llvm::SmallVector<RTLInfoTy *> UsedRTLs; | ||||
int64_t RequiresFlags = OMP_REQ_UNDEFINED; | int64_t RequiresFlags = OMP_REQ_UNDEFINED; | ||||
explicit RTLsTy() = default; | explicit RTLsTy() = default; | ||||
jdoerfert: Let's move this into the PluginManager without static and without thread_local. Also, consider… | |||||
// Register the clauses of the requires directive. | // Register the clauses of the requires directive. | ||||
void registerRequires(int64_t Flags); | void registerRequires(int64_t Flags); | ||||
// Initialize RTL if it has not been initialized | // Initialize RTL if it has not been initialized | ||||
void initRTLonce(RTLInfoTy &RTL); | void initRTLonce(RTLInfoTy &RTL); | ||||
// Initialize all RTLs | // Initialize all RTLs | ||||
void initAllRTLs(); | void initAllRTLs(); | ||||
// Register a shared library with all (compatible) RTLs. | // Register a shared library with all (compatible) RTLs. | ||||
void registerLib(__tgt_bin_desc *Desc); | void registerLib(__tgt_bin_desc *Desc); | ||||
// Unregister a shared library from all RTLs. | // Unregister a shared library from all RTLs. | ||||
void unregisterLib(__tgt_bin_desc *Desc); | void unregisterLib(__tgt_bin_desc *Desc); | ||||
// Mutex-like object to guarantee thread-safety and unique initialization | // Mutex-like object to guarantee thread-safety and unique initialization | ||||
// (i.e. the library attempts to load the RTLs (plugins) only once). | // (i.e. the library attempts to load the RTLs (plugins) only once). | ||||
std::once_flag InitFlag; | std::once_flag InitFlag; | ||||
void loadRTLs(); // not thread-safe | void loadRTLs(); // not thread-safe | ||||
void registerToAllRTLs(__tgt_bin_desc* Desc); | |||||
// `loadRTLs` `dlopen`s the runtime plugins, which might load other libraries finally | |||||
// trying to load another library recursively. | |||||
// When this happens delay the loading of the libraries until the outermost call finishes, | |||||
// to ensure that the plugins are initialized before any library is loaded. | |||||
// returns true if the registration was delayed and the caller should skip registration | |||||
bool delayRegistration(__tgt_bin_desc* DelayedDesc); | |||||
// Libraries might also be unregistered during `loadRTLs`, | |||||
// when this happens just cancel their delayed registration. | |||||
// returns true if the registration was delayed and the caller should skip de-registration | |||||
bool cancelDelayedRegistration(__tgt_bin_desc* DelayedDesc); | |||||
private: | private: | ||||
// The thread that is currently loading the RTLs | |||||
std::atomic<std::thread::id> LoadingThread; | |||||
llvm::SmallPtrSet<__tgt_bin_desc*, 1> DelayedDescs; | |||||
void runDelayedRegistrations(); | |||||
static bool attemptLoadRTL(const std::string &RTLName, RTLInfoTy &RTL); | static bool attemptLoadRTL(const std::string &RTLName, RTLInfoTy &RTL); | ||||
}; | }; | ||||
/// Map between the host entry begin and the translation table. Each | /// Map between the host entry begin and the translation table. Each | ||||
/// registered library gets one TranslationTable. Use the map from | /// registered library gets one TranslationTable. Use the map from | ||||
/// __tgt_offload_entry so that we may quickly determine whether we | /// __tgt_offload_entry so that we may quickly determine whether we | ||||
/// are trying to (re)register an existing lib or really have a new one. | /// are trying to (re)register an existing lib or really have a new one. | ||||
struct TranslationTable { | struct TranslationTable { | ||||
Show All 24 Lines |
Let's move this into the PluginManager without static and without thread_local. Also, consider a small ptr set to avoid the linear search.