[Openmp-commits] [openmp] c3e6054 - [OpenMP] Additional Information for Libomptarget Mappings

via Openmp-commits openmp-commits at lists.llvm.org
Tue Sep 15 15:13:20 PDT 2020


Author: Joseph Huber
Date: 2020-09-15T18:12:57-04:00
New Revision: c3e6054b07be1340fb255abe1e3c85b911710059

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

LOG: [OpenMP] Additional Information for Libomptarget Mappings

Summary:
This patch adds additonal support for priting infromation from Libomptarget for
already existing maps and printing the final data mapped on the device at
device destruction.

Reviewers: jdoerfort gkistanova

Subscribers: guansong openmp-commits sstefan1 yaxunl

Tags: #OpenMP

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

Added: 
    

Modified: 
    openmp/libomptarget/src/device.cpp
    openmp/libomptarget/src/interface.cpp
    openmp/libomptarget/src/private.h

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/src/device.cpp b/openmp/libomptarget/src/device.cpp
index fdf625cb71f6..79feebe6f32b 100644
--- a/openmp/libomptarget/src/device.cpp
+++ b/openmp/libomptarget/src/device.cpp
@@ -17,6 +17,7 @@
 
 #include <cassert>
 #include <climits>
+#include <cstdio>
 #include <string>
 
 /// Map between Device ID (i.e. openmp device id) and its DeviceTy.
@@ -50,7 +51,12 @@ DeviceTy::DeviceTy(RTLInfoTy *RTL)
       ShadowPtrMap(), DataMapMtx(), PendingGlobalsMtx(), ShadowMtx(),
       MemoryManager(nullptr) {}
 
-DeviceTy::~DeviceTy() = default;
+DeviceTy::~DeviceTy() {
+  if (DeviceID == -1 || getInfoLevel() < 1)
+    return;
+
+  dumpTargetPointerMappings(*this);
+}
 
 int DeviceTy::associatePtr(void *HstPtrBegin, void *TgtPtrBegin, int64_t Size) {
   DataMapMtx.lock();
@@ -214,11 +220,13 @@ void *DeviceTy::getOrAllocTgtPtr(void *HstPtrBegin, void *HstPtrBase,
       HT.incRefCount();
 
     uintptr_t tp = HT.TgtPtrBegin + ((uintptr_t)HstPtrBegin - HT.HstPtrBegin);
-    DP("Mapping exists%s with HstPtrBegin=" DPxMOD ", TgtPtrBegin=" DPxMOD ", "
-        "Size=%" PRId64 ",%s RefCount=%s\n", (IsImplicit ? " (implicit)" : ""),
-        DPxPTR(HstPtrBegin), DPxPTR(tp), Size,
-        (UpdateRefCount ? " updated" : ""),
-        HT.isRefCountInf() ? "INF" : std::to_string(HT.getRefCount()).c_str());
+    INFO(DeviceID,
+         "Mapping exists%s with HstPtrBegin=" DPxMOD ", TgtPtrBegin=" DPxMOD
+         ", "
+         "Size=%" PRId64 ",%s RefCount=%s\n",
+         (IsImplicit ? " (implicit)" : ""), DPxPTR(HstPtrBegin), DPxPTR(tp),
+         Size, (UpdateRefCount ? " updated" : ""),
+         HT.isRefCountInf() ? "INF" : std::to_string(HT.getRefCount()).c_str());
     rc = (void *)tp;
   } else if ((lr.Flags.ExtendsBefore || lr.Flags.ExtendsAfter) && !IsImplicit) {
     // Explicit extension of mapped data - not allowed.

diff  --git a/openmp/libomptarget/src/interface.cpp b/openmp/libomptarget/src/interface.cpp
index 084f2ac5aee3..76a9e766ec76 100644
--- a/openmp/libomptarget/src/interface.cpp
+++ b/openmp/libomptarget/src/interface.cpp
@@ -24,21 +24,6 @@
 kmp_target_offload_kind_t TargetOffloadPolicy = tgt_default;
 std::mutex TargetOffloadMtx;
 
-////////////////////////////////////////////////////////////////////////////////
-/// dump a table of all the host-target pointer pairs on failure
-static void dumpTargetPointerMappings() {
-  for (const auto &Device : Devices) {
-    fprintf(stderr, "Device %d:\n", Device.DeviceID);
-    fprintf(stderr, "%-18s %-18s %s\n", "Host Ptr", "Target Ptr", "Size (B)");
-    for (const auto &HostTargetMap : Device.HostDataToTargetMap) {
-      fprintf(stderr, DPxMOD " " DPxMOD " %lu\n",
-              DPxPTR(HostTargetMap.HstPtrBegin),
-              DPxPTR(HostTargetMap.TgtPtrBegin),
-              HostTargetMap.HstPtrEnd - HostTargetMap.HstPtrBegin);
-    }
-  }
-}
-
 ////////////////////////////////////////////////////////////////////////////////
 /// manage the success or failure of a target construct
 static void HandleDefaultTargetOffload() {
@@ -76,9 +61,11 @@ static void HandleTargetOutcome(bool success) {
     case tgt_mandatory:
       if (!success) {
         if (getInfoLevel() > 1)
-          dumpTargetPointerMappings();
+          for (const auto &Device : Devices)
+            dumpTargetPointerMappings(Device);
         else
-          FAILURE_MESSAGE("run with env LIBOMPTARGET_INFO>1 to dump tables\n");
+          FAILURE_MESSAGE("run with env LIBOMPTARGET_INFO>1 to dump host-target"
+                          "pointer maps\n");
 
         FATAL_MESSAGE0(1, "failure of target construct while offloading is mandatory");
       }

diff  --git a/openmp/libomptarget/src/private.h b/openmp/libomptarget/src/private.h
index f01714808dd4..17ca81e353f1 100644
--- a/openmp/libomptarget/src/private.h
+++ b/openmp/libomptarget/src/private.h
@@ -96,4 +96,20 @@ int __kmpc_get_target_offload(void) __attribute__((weak));
 #define TARGET_NAME Libomptarget
 #define DEBUG_PREFIX GETNAME(TARGET_NAME)
 
+////////////////////////////////////////////////////////////////////////////////
+/// dump a table of all the host-target pointer pairs on failure
+static inline void dumpTargetPointerMappings(const DeviceTy &Device) {
+  if (Device.HostDataToTargetMap.empty())
+    return;
+
+  fprintf(stderr, "Device %d Host-Device Pointer Mappings:\n", Device.DeviceID);
+  fprintf(stderr, "%-18s %-18s %s\n", "Host Ptr", "Target Ptr", "Size (B)");
+  for (const auto &HostTargetMap : Device.HostDataToTargetMap) {
+    fprintf(stderr, DPxMOD " " DPxMOD " %lu\n",
+            DPxPTR(HostTargetMap.HstPtrBegin),
+            DPxPTR(HostTargetMap.TgtPtrBegin),
+            HostTargetMap.HstPtrEnd - HostTargetMap.HstPtrBegin);
+  }
+}
+
 #endif


        


More information about the Openmp-commits mailing list