[Openmp-commits] [PATCH] D95530: [libomptarget] Load images in order of registration
Manoel Roemmer via Phabricator via Openmp-commits
openmp-commits at lists.llvm.org
Wed Jan 27 07:49:29 PST 2021
manorom created this revision.
manorom requested review of this revision.
Herald added a project: OpenMP.
Herald added a subscriber: openmp-commits.
This makes sure that images are loaded in the order in which they are registered with libomptarget.
If a target can load multiple images and these images depend on each other (for example if one image contains the programs target regions and one image contains library code), then the order in which images are loaded can be important for symbol resolution (for example, in the VE plugin).
In this case: because the same code exist in the host binaries, the order in which the host linker loads them (which is also the order in which images are registered with libomptarget) is the order in which the images have to be loaded onto the device.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D95530
Files:
openmp/libomptarget/src/device.h
openmp/libomptarget/src/omptarget.cpp
openmp/libomptarget/src/rtl.cpp
openmp/libomptarget/src/rtl.h
Index: openmp/libomptarget/src/rtl.h
===================================================================
--- openmp/libomptarget/src/rtl.h
+++ 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;
Index: openmp/libomptarget/src/rtl.cpp
===================================================================
--- openmp/libomptarget/src/rtl.cpp
+++ 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;
Index: openmp/libomptarget/src/omptarget.cpp
===================================================================
--- openmp/libomptarget/src/omptarget.cpp
+++ 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;
Index: openmp/libomptarget/src/device.h
===================================================================
--- openmp/libomptarget/src/device.h
+++ 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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95530.319576.patch
Type: text/x-patch
Size: 3211 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20210127/5b4437b7/attachment.bin>
More information about the Openmp-commits
mailing list