diff --git a/openmp/libomptarget/src/device.h b/openmp/libomptarget/src/device.h --- a/openmp/libomptarget/src/device.h +++ b/openmp/libomptarget/src/device.h @@ -245,6 +245,8 @@ /// Translation table retreived from the binary HostEntriesBeginToTransTableTy HostEntriesBeginToTransTable; std::mutex TrlTblMtx; ///< For Translation Table + /// Host offload entries in order of image registration + std::vector<__tgt_offload_entry *> HostEntriesBeginRegistrationOrder; /// Map from ptrs on the host to an entry in the Translation Table HostPtrToTableMapTy HostPtrToTableMap; diff --git a/openmp/libomptarget/src/omptarget.cpp b/openmp/libomptarget/src/omptarget.cpp --- a/openmp/libomptarget/src/omptarget.cpp +++ b/openmp/libomptarget/src/omptarget.cpp @@ -60,15 +60,16 @@ Device.PendingGlobalsMtx.lock(); PM->TrlTblMtx.lock(); - for (HostEntriesBeginToTransTableTy::iterator entry_it = - PM->HostEntriesBeginToTransTable.begin(); - entry_it != PM->HostEntriesBeginToTransTable.end(); ++entry_it) { - TranslationTable *TransTable = &entry_it->second; + for (auto *HostEntriesBegin : PM->HostEntriesBeginRegistrationOrder) { + TranslationTable *TransTable = + &PM->HostEntriesBeginToTransTable[HostEntriesBegin]; if (TransTable->HostTable.EntriesBegin == - TransTable->HostTable.EntriesEnd) { + TransTable->HostTable.EntriesEnd && + !Device.RTL->handles_library_images) { // No host entry so no need to proceed continue; } + if (TransTable->TargetsTable[device_id] != 0) { // Library entries have already been processed continue; diff --git a/openmp/libomptarget/src/rtl.h b/openmp/libomptarget/src/rtl.h --- a/openmp/libomptarget/src/rtl.h +++ b/openmp/libomptarget/src/rtl.h @@ -67,6 +67,11 @@ std::string RTLName; #endif + // Can this image handle images which do not contain target regions or global + // variables, but might only contain #declare target functions. + // These images will have an empty target table. + bool handles_library_images = false; + // Functions implemented in the RTL. is_valid_binary_ty *is_valid_binary = nullptr; is_data_exchangable_ty *is_data_exchangable = nullptr; diff --git a/openmp/libomptarget/src/rtl.cpp b/openmp/libomptarget/src/rtl.cpp --- a/openmp/libomptarget/src/rtl.cpp +++ b/openmp/libomptarget/src/rtl.cpp @@ -148,6 +148,10 @@ R.RTLName = Name; #endif + if (strcmp(Name, "libomptarget.rtl.ve.so") == 0) { + R.handles_library_images = true; + } + DP("Registering RTL %s supporting %d devices!\n", R.RTLName.c_str(), R.NumberOfDevices); @@ -331,6 +335,7 @@ // Initialize (if necessary) translation table for this library. PM->TrlTblMtx.lock(); if (!PM->HostEntriesBeginToTransTable.count(desc->HostEntriesBegin)) { + PM->HostEntriesBeginRegistrationOrder.push_back(desc->HostEntriesBegin); TranslationTable &TransTable = (PM->HostEntriesBeginToTransTable)[desc->HostEntriesBegin]; TransTable.HostTable.EntriesBegin = desc->HostEntriesBegin;