#include <cassert>
#include <climits>
+#include <cstdio>
#include <string>
/// Map between Device ID (i.e. openmp device id) and its DeviceTy.
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();
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.
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() {
TargetOffloadMtx.lock();
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");
}
#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