[Openmp-commits] [PATCH] D142249: [openmp] Workaround for HSA in issue 60119

Jon Chesterfield via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Fri Jan 20 12:51:45 PST 2023


JonChesterfield created this revision.
JonChesterfield added reviewers: Maetveis, jdoerfert, jhuber6, tianshilei1992.
Herald added subscribers: guansong, yaxunl.
Herald added a project: All.
JonChesterfield requested review of this revision.
Herald added subscribers: openmp-commits, sstefan1.
Herald added a project: OpenMP.

Move plugin initialisation to libomptarget initialisation.

Removes the call_once control, probably fractionally faster overall.
Fixes issue 60119 because the plugin initialisation, which might
try to dlopen unrelated shared libraries, is no longer nested within
a call from application code.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142249

Files:
  openmp/libomptarget/src/interface.cpp
  openmp/libomptarget/src/rtl.cpp


Index: openmp/libomptarget/src/rtl.cpp
===================================================================
--- openmp/libomptarget/src/rtl.cpp
+++ openmp/libomptarget/src/rtl.cpp
@@ -39,11 +39,16 @@
     /* Remote target        */ "libomptarget.rtl.rpc",
 };
 
-PluginManager *PM;
+PluginManager *PM = nullptr;
 
 static char *ProfileTraceFile = nullptr;
 
 __attribute__((constructor(101))) void init() {
+  if (PM != nullptr) {
+    // In case one of the plugins chooses to call back into this constructor
+    return;
+  }
+
   DP("Init target library!\n");
 
   bool UseEventsForAtomicTransfers = true;
@@ -64,11 +69,14 @@
   // TODO: add a configuration option for time granularity
   if (ProfileTraceFile)
     timeTraceProfilerInitialize(500 /* us */, "libomptarget");
+
+  PM->RTLs.loadRTLs();
 }
 
 __attribute__((destructor(101))) void deinit() {
   DP("Deinit target library!\n");
   delete PM;
+  PM = nullptr;
 
   if (ProfileTraceFile) {
     // TODO: add env var for file output
Index: openmp/libomptarget/src/interface.cpp
===================================================================
--- openmp/libomptarget/src/interface.cpp
+++ openmp/libomptarget/src/interface.cpp
@@ -35,7 +35,6 @@
 /// adds a target shared library to the target execution image
 EXTERN void __tgt_register_lib(__tgt_bin_desc *Desc) {
   TIMESCOPE();
-  std::call_once(PM->RTLs.InitFlag, &RTLsTy::loadRTLs, &PM->RTLs);
   for (auto &RTL : PM->RTLs.AllRTLs) {
     if (RTL.register_lib) {
       if ((*RTL.register_lib)(Desc) != OFFLOAD_SUCCESS) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142249.490948.patch
Type: text/x-patch
Size: 1541 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20230120/7b1723d2/attachment.bin>


More information about the Openmp-commits mailing list