Skip to content

Commit 13b8826

Browse files
authored
Revert " [OpenMP][NFC] Remove DelayedBinDesc" (#74679)
Reverts #74360 As I wrote in the analysis of #74360: Since bc4e0c0 we will not add PluginAdaptors into the container of all plugin adaptors before the plugin is not ready. The error is thereby gone. When and old HSA loads other libraries they can call register_image but that will simply not register the image with the plugin we are currently initializing. That seems like reasonable behavior, thought it is good to keep in mind if we ever want a kernel library (@jhuber6 @mjklemm). We can still have a standalone kernel library though or load it late after all plugins are setup (which seems reasonable). I did not expect one our tests actually doing exactly what this will not allow anymore, at least when you use rocm <5.5.0. Need to figure out if we want this behavior (for rocm <5.5.0).
1 parent 78e2b74 commit 13b8826

File tree

5 files changed

+25
-7
lines changed

5 files changed

+25
-7
lines changed

openmp/libomptarget/include/PluginManager.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,24 @@ struct PluginManager {
150150
HostPtrToTableMapTy HostPtrToTableMap;
151151
std::mutex TblMapMtx; ///< For HostPtrToTableMap
152152

153+
// Work around for plugins that call dlopen on shared libraries that call
154+
// tgt_register_lib during their initialisation. Stash the pointers in a
155+
// vector until the plugins are all initialised and then register them.
156+
bool delayRegisterLib(__tgt_bin_desc *Desc) {
157+
if (RTLsLoaded)
158+
return false;
159+
DelayedBinDesc.push_back(Desc);
160+
return true;
161+
}
162+
163+
void registerDelayedLibraries() {
164+
// Only called by libomptarget constructor
165+
RTLsLoaded = true;
166+
for (auto *Desc : DelayedBinDesc)
167+
__tgt_register_lib(Desc);
168+
DelayedBinDesc.clear();
169+
}
170+
153171
/// Return the number of usable devices.
154172
int getNumDevices() { return getExclusiveDevicesAccessor()->size(); }
155173

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

180198
private:
199+
bool RTLsLoaded = false;
200+
llvm::SmallVector<__tgt_bin_desc *> DelayedBinDesc;
201+
181202
// List of all plugin adaptors, in use or not.
182203
llvm::SmallVector<std::unique_ptr<PluginAdaptorTy>> PluginAdaptors;
183204

openmp/libomptarget/src/interface.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ EXTERN void __tgt_register_requires(int64_t Flags) {
4646
/// adds a target shared library to the target execution image
4747
EXTERN void __tgt_register_lib(__tgt_bin_desc *Desc) {
4848
TIMESCOPE();
49+
if (PM->delayRegisterLib(Desc))
50+
return;
51+
4952
PM->registerLib(Desc);
5053
}
5154

openmp/libomptarget/src/rtl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ __attribute__((constructor(101))) void init() {
5151
PM->init();
5252

5353
Profiler::get();
54+
PM->registerDelayedLibraries();
5455
}
5556

5657
__attribute__((destructor(101))) void deinit() {

openmp/libomptarget/test/Inputs/empty.c

Lines changed: 0 additions & 1 deletion
This file was deleted.

openmp/libomptarget/test/offloading/bug60119.c

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)