[Openmp-commits] [openmp] 22d71e7 - [Libomptarget] Do not check for valid binaries twice.

Joseph Huber via Openmp-commits openmp-commits at lists.llvm.org
Mon Aug 29 06:37:04 PDT 2022


Author: Joseph Huber
Date: 2022-08-29T08:36:50-05:00
New Revision: 22d71e72c9fd9c0cb73ba065fd25efe459d4f81c

URL: https://github.com/llvm/llvm-project/commit/22d71e72c9fd9c0cb73ba065fd25efe459d4f81c
DIFF: https://github.com/llvm/llvm-project/commit/22d71e72c9fd9c0cb73ba065fd25efe459d4f81c.diff

LOG: [Libomptarget] Do not check for valid binaries twice.

The only RTLs that get added to the `UsedRTLs` list have already been
checked is they were valid binaries. We shouldn't need to do this again
when we unregister all the used binaries as they wouldn't have been used
if they were invalid anyway. Let me know if I'm incorrect in this
assumption.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D131443

Added: 
    

Modified: 
    openmp/libomptarget/include/rtl.h
    openmp/libomptarget/src/rtl.cpp

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/include/rtl.h b/openmp/libomptarget/include/rtl.h
index a5ab5164ff275..186b37cde6bd6 100644
--- a/openmp/libomptarget/include/rtl.h
+++ b/openmp/libomptarget/include/rtl.h
@@ -13,6 +13,8 @@
 #ifndef _OMPTARGET_RTL_H
 #define _OMPTARGET_RTL_H
 
+#include "omptarget.h"
+#include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/DynamicLibrary.h"
 
@@ -127,6 +129,8 @@ struct RTLInfoTy {
   // Are there images associated with this RTL.
   bool IsUsed = false;
 
+  llvm::DenseSet<const __tgt_device_image *> UsedImages;
+
   // Mutex for thread-safety when calling RTL interface functions.
   // It is easier to enforce thread-safety at the libomptarget level,
   // so that developers of new RTLs do not have to worry about it.

diff  --git a/openmp/libomptarget/src/rtl.cpp b/openmp/libomptarget/src/rtl.cpp
index 90fa1b04bdd11..d0b5eb5b4d75c 100644
--- a/openmp/libomptarget/src/rtl.cpp
+++ b/openmp/libomptarget/src/rtl.cpp
@@ -479,6 +479,8 @@ void RTLsTy::registerLib(__tgt_bin_desc *Desc) {
       DP("Registering image " DPxMOD " with RTL %s!\n", DPxPTR(Img->ImageStart),
          R.RTLName.c_str());
       registerImageIntoTranslationTable(TransTable, R, Img);
+      R.UsedImages.insert(Img);
+
       PM->TrlTblMtx.unlock();
       FoundRTL = &R;
 
@@ -506,7 +508,6 @@ void RTLsTy::unregisterLib(__tgt_bin_desc *Desc) {
   for (auto &ImageAndInfo : PM->Images) {
     // Obtain the image and information that was previously extracted.
     __tgt_device_image *Img = &ImageAndInfo.first;
-    __tgt_image_info *Info = &ImageAndInfo.second;
 
     RTLInfoTy *FoundRTL = NULL;
 
@@ -516,20 +517,9 @@ void RTLsTy::unregisterLib(__tgt_bin_desc *Desc) {
 
       assert(R->IsUsed && "Expecting used RTLs.");
 
-      if (R->is_valid_binary_info) {
-        if (!R->is_valid_binary_info(Img, Info)) {
-          DP("Image " DPxMOD " is NOT compatible with RTL %s!\n",
-             DPxPTR(Img->ImageStart), R->RTLName.c_str());
-          continue;
-        }
-      } else if (!R->is_valid_binary(Img)) {
-        DP("Image " DPxMOD " is NOT compatible with RTL %s!\n",
-           DPxPTR(Img->ImageStart), R->RTLName.c_str());
+      // Ensure that we do not use any unused images associated with this RTL.
+      if (!R->UsedImages.contains(Img))
         continue;
-      }
-
-      DP("Image " DPxMOD " is compatible with RTL " DPxMOD "!\n",
-         DPxPTR(Img->ImageStart), DPxPTR(R->LibraryHandler.get()));
 
       FoundRTL = R;
 


        


More information about the Openmp-commits mailing list