Skip to content

Commit

Permalink
Revert " [OpenMP][NFC] Remove DelayedBinDesc (#74360)"
Browse files Browse the repository at this point in the history
This reverts commit d552ce2.
  • Loading branch information
jdoerfert committed Dec 7, 2023
1 parent 78e2b74 commit 57dd853
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
21 changes: 21 additions & 0 deletions openmp/libomptarget/include/PluginManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,24 @@ struct PluginManager {
HostPtrToTableMapTy HostPtrToTableMap;
std::mutex TblMapMtx; ///< For HostPtrToTableMap

// 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();
}

/// Return the number of usable devices.
int getNumDevices() { return getExclusiveDevicesAccessor()->size(); }

Expand Down Expand Up @@ -178,6 +196,9 @@ struct PluginManager {
void addRequirements(int64_t Flags) { Requirements.addRequirements(Flags); }

private:
bool RTLsLoaded = false;
llvm::SmallVector<__tgt_bin_desc *> DelayedBinDesc;

// List of all plugin adaptors, in use or not.
llvm::SmallVector<std::unique_ptr<PluginAdaptorTy>> PluginAdaptors;

Expand Down
3 changes: 3 additions & 0 deletions openmp/libomptarget/src/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ EXTERN void __tgt_register_requires(int64_t Flags) {
/// adds a target shared library to the target execution image
EXTERN void __tgt_register_lib(__tgt_bin_desc *Desc) {
TIMESCOPE();
if (PM->delayRegisterLib(Desc))
return;

PM->registerLib(Desc);
}

Expand Down
1 change: 1 addition & 0 deletions openmp/libomptarget/src/rtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ __attribute__((constructor(101))) void init() {
PM->init();

Profiler::get();
PM->registerDelayedLibraries();
}

__attribute__((destructor(101))) void deinit() {
Expand Down
1 change: 0 additions & 1 deletion openmp/libomptarget/test/Inputs/empty.c

This file was deleted.

6 changes: 0 additions & 6 deletions openmp/libomptarget/test/offloading/bug60119.c

This file was deleted.

0 comments on commit 57dd853

Please sign in to comment.