diff --git a/openmp/libomptarget/include/SourceInfo.h b/openmp/libomptarget/include/SourceInfo.h new file mode 100644 --- /dev/null +++ b/openmp/libomptarget/include/SourceInfo.h @@ -0,0 +1,80 @@ +//===------- SourceInfo.h - Target independent OpenMP target RTL -- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Methods used to describe source information in target regions +// +//===----------------------------------------------------------------------===// + +#ifndef _SOURCE_INFO_H_ +#define _SOURCE_INFO_H_ + +#include + +#ifdef _WIN32 +static const bool OS_WINDOWS = true; +#else +static const bool OS_WINDOWS = false; +#endif + +/// Type alias for source location information for variable mappings with +/// data layout ";name;filename;row;col;;\0" from clang. +using map_var_info_t = void *; + +/// Struct to hold source individual location information. +class SourceInfo { + /// Underlying string copy of the original source information. + const std::string str; + + std::string initStr(const map_var_info_t name) { + if (!name) + return ";unknown;unknown;0;0;;"; + else + return std::string(reinterpret_cast(name)); + } + + /// Get n-th substring in an expression separated by ;. + std::string getSubstring(const int n) { + std::size_t begin = str.find(';'); + std::size_t end = str.find(';', begin + 1); + for (int i = 0; i < n; i++) { + begin = end; + end = str.find(';', begin + 1); + } + return str.substr(begin + 1, end - begin - 1); + }; + + /// Get the filename from a full path. + std::string removePath(const std::string &path) { + std::size_t pos = (OS_WINDOWS) ? path.rfind('\\') : path.rfind('/'); + return path.substr(pos + 1); + }; + +public: + SourceInfo(const map_var_info_t name) + : str(initStr(name)), name(getSubstring(0)), + filename(removePath(getSubstring(1))), line(std::stoi(getSubstring(2))), + column(std::stoi(getSubstring(3))) {} + + const std::string name; + const std::string filename; + const int32_t line; + const int32_t column; +}; + +/// Standalone function for getting the variable name of a mapping. +static inline std::string getNameFromMapping(const map_var_info_t name) { + if (!name) + return "unknown"; + + const std::string name_str(reinterpret_cast(name)); + std::size_t begin = name_str.find(';'); + std::size_t end = name_str.find(';', begin + 1); + return name_str.substr(begin + 1, end - begin - 1); +} + +#endif diff --git a/openmp/libomptarget/include/omptarget.h b/openmp/libomptarget/include/omptarget.h --- a/openmp/libomptarget/include/omptarget.h +++ b/openmp/libomptarget/include/omptarget.h @@ -17,6 +17,8 @@ #include #include +#include + #define OFFLOAD_SUCCESS (0) #define OFFLOAD_FAIL (~0) @@ -164,14 +166,13 @@ void __tgt_target_data_begin_mapper(int64_t device_id, int32_t arg_num, void **args_base, void **args, int64_t *arg_sizes, int64_t *arg_types, - void **arg_names, void **arg_mappers); -void __tgt_target_data_begin_nowait_mapper(int64_t device_id, int32_t arg_num, - void **args_base, void **args, - int64_t *arg_sizes, - int64_t *arg_types, void **arg_names, - void **arg_mappers, int32_t depNum, - void *depList, int32_t noAliasDepNum, - void *noAliasDepList); + map_var_info_t *arg_names, + void **arg_mappers); +void __tgt_target_data_begin_nowait_mapper( + int64_t device_id, int32_t arg_num, void **args_base, void **args, + int64_t *arg_sizes, int64_t *arg_types, map_var_info_t *arg_names, + void **arg_mappers, int32_t depNum, void *depList, int32_t noAliasDepNum, + void *noAliasDepList); // passes data from the target, release target memory and destroys the // host-target mapping (top entry from the stack of data maps) created by @@ -186,13 +187,14 @@ void __tgt_target_data_end_mapper(int64_t device_id, int32_t arg_num, void **args_base, void **args, int64_t *arg_sizes, int64_t *arg_types, - void **arg_names, void **arg_mappers); + map_var_info_t *arg_names, + void **arg_mappers); void __tgt_target_data_end_nowait_mapper(int64_t device_id, int32_t arg_num, void **args_base, void **args, int64_t *arg_sizes, int64_t *arg_types, - void **arg_names, void **arg_mappers, - int32_t depNum, void *depList, - int32_t noAliasDepNum, + map_var_info_t *arg_names, + void **arg_mappers, int32_t depNum, + void *depList, int32_t noAliasDepNum, void *noAliasDepList); /// passes data to/from the target @@ -208,10 +210,11 @@ void __tgt_target_data_update_mapper(int64_t device_id, int32_t arg_num, void **args_base, void **args, int64_t *arg_sizes, int64_t *arg_types, - void **arg_names, void **arg_mappers); + map_var_info_t *arg_names, + void **arg_mappers); void __tgt_target_data_update_nowait_mapper( int64_t device_id, int32_t arg_num, void **args_base, void **args, - int64_t *arg_sizes, int64_t *arg_types, void **arg_names, + int64_t *arg_sizes, int64_t *arg_types, map_var_info_t *arg_names, void **arg_mappers, int32_t depNum, void *depList, int32_t noAliasDepNum, void *noAliasDepList); @@ -230,12 +233,12 @@ int32_t noAliasDepNum, void *noAliasDepList); int __tgt_target_mapper(int64_t device_id, void *host_ptr, int32_t arg_num, void **args_base, void **args, int64_t *arg_sizes, - int64_t *arg_types, void **arg_names, + int64_t *arg_types, map_var_info_t *arg_names, void **arg_mappers); int __tgt_target_nowait_mapper(int64_t device_id, void *host_ptr, int32_t arg_num, void **args_base, void **args, int64_t *arg_sizes, int64_t *arg_types, - void **arg_names, void **arg_mappers, + map_var_info_t *arg_names, void **arg_mappers, int32_t depNum, void *depList, int32_t noAliasDepNum, void *noAliasDepList); @@ -252,13 +255,14 @@ int __tgt_target_teams_mapper(int64_t device_id, void *host_ptr, int32_t arg_num, void **args_base, void **args, int64_t *arg_sizes, int64_t *arg_types, - void **arg_names, void **arg_mappers, + map_var_info_t *arg_names, void **arg_mappers, int32_t num_teams, int32_t thread_limit); int __tgt_target_teams_nowait_mapper( int64_t device_id, void *host_ptr, int32_t arg_num, void **args_base, - void **args, int64_t *arg_sizes, int64_t *arg_types, void **arg_names, - void **arg_mappers, int32_t num_teams, int32_t thread_limit, int32_t depNum, - void *depList, int32_t noAliasDepNum, void *noAliasDepList); + void **args, int64_t *arg_sizes, int64_t *arg_types, + map_var_info_t *arg_names, void **arg_mappers, int32_t num_teams, + int32_t thread_limit, int32_t depNum, void *depList, int32_t noAliasDepNum, + void *noAliasDepList); void __kmpc_push_target_tripcount(int64_t device_id, uint64_t loop_tripcount); 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 @@ -29,11 +29,14 @@ struct __tgt_async_info; class MemoryManagerTy; +using map_var_info_t = void *; + /// Map between host data and target data. struct HostDataToTargetTy { uintptr_t HstPtrBase; // host info. uintptr_t HstPtrBegin; uintptr_t HstPtrEnd; // non-inclusive. + map_var_info_t HstPtrName; // Source name of mapped variable uintptr_t TgtPtrBegin; // target info. @@ -44,8 +47,8 @@ public: HostDataToTargetTy(uintptr_t BP, uintptr_t B, uintptr_t E, uintptr_t TB, - bool IsINF = false) - : HstPtrBase(BP), HstPtrBegin(B), HstPtrEnd(E), + map_var_info_t Name = nullptr, bool IsINF = false) + : HstPtrBase(BP), HstPtrBegin(B), HstPtrEnd(E), HstPtrName(Name), TgtPtrBegin(TB), RefCount(IsINF ? INFRefCount : 1) {} uint64_t getRefCount() const { @@ -163,9 +166,9 @@ uint64_t getMapEntryRefCnt(void *HstPtrBegin); LookupResult lookupMapping(void *HstPtrBegin, int64_t Size); void *getOrAllocTgtPtr(void *HstPtrBegin, void *HstPtrBase, int64_t Size, - bool &IsNew, bool &IsHostPtr, bool IsImplicit, - bool UpdateRefCount, bool HasCloseModifier, - bool HasPresentModifier); + map_var_info_t HstPtrName, bool &IsNew, + bool &IsHostPtr, bool IsImplicit, bool UpdateRefCount, + bool HasCloseModifier, bool HasPresentModifier); void *getTgtPtrBegin(void *HstPtrBegin, int64_t Size); void *getTgtPtrBegin(void *HstPtrBegin, int64_t Size, bool &IsLast, bool UpdateRefCount, bool &IsHostPtr, diff --git a/openmp/libomptarget/src/device.cpp b/openmp/libomptarget/src/device.cpp --- a/openmp/libomptarget/src/device.cpp +++ b/openmp/libomptarget/src/device.cpp @@ -80,10 +80,10 @@ } // Mapping does not exist, allocate it with refCount=INF - HostDataToTargetTy newEntry((uintptr_t) HstPtrBegin /*HstPtrBase*/, - (uintptr_t) HstPtrBegin /*HstPtrBegin*/, - (uintptr_t) HstPtrBegin + Size /*HstPtrEnd*/, - (uintptr_t) TgtPtrBegin /*TgtPtrBegin*/, + HostDataToTargetTy newEntry((uintptr_t)HstPtrBegin /*HstPtrBase*/, + (uintptr_t)HstPtrBegin /*HstPtrBegin*/, + (uintptr_t)HstPtrBegin + Size /*HstPtrEnd*/, + (uintptr_t)TgtPtrBegin /*TgtPtrBegin*/, nullptr, true /*IsRefCountINF*/); DP("Creating new map entry: HstBase=" DPxMOD ", HstBegin=" DPxMOD ", HstEnd=" @@ -197,9 +197,9 @@ // If NULL is returned, then either data allocation failed or the user tried // to do an illegal mapping. void *DeviceTy::getOrAllocTgtPtr(void *HstPtrBegin, void *HstPtrBase, - int64_t Size, bool &IsNew, bool &IsHostPtr, - bool IsImplicit, bool UpdateRefCount, - bool HasCloseModifier, + int64_t Size, map_var_info_t HstPtrName, + bool &IsNew, bool &IsHostPtr, bool IsImplicit, + bool UpdateRefCount, bool HasCloseModifier, bool HasPresentModifier) { void *rc = NULL; IsHostPtr = false; @@ -223,10 +223,11 @@ INFO(DeviceID, "Mapping exists%s with HstPtrBegin=" DPxMOD ", TgtPtrBegin=" DPxMOD ", " - "Size=%" PRId64 ",%s RefCount=%s\n", + "Size=%" PRId64 ",%s RefCount=%s, Name=%s\n", (IsImplicit ? " (implicit)" : ""), DPxPTR(HstPtrBegin), DPxPTR(tp), Size, (UpdateRefCount ? " updated" : ""), - HT.isRefCountInf() ? "INF" : std::to_string(HT.getRefCount()).c_str()); + HT.isRefCountInf() ? "INF" : std::to_string(HT.getRefCount()).c_str(), + (HstPtrName) ? getNameFromMapping(HstPtrName).c_str() : "(null)"); rc = (void *)tp; } else if ((lr.Flags.ExtendsBefore || lr.Flags.ExtendsAfter) && !IsImplicit) { // Explicit extension of mapped data - not allowed. @@ -271,7 +272,7 @@ DPxPTR((uintptr_t)HstPtrBegin + Size), DPxPTR(tp)); HostDataToTargetMap.emplace( HostDataToTargetTy((uintptr_t)HstPtrBase, (uintptr_t)HstPtrBegin, - (uintptr_t)HstPtrBegin + Size, tp)); + (uintptr_t)HstPtrBegin + Size, tp, HstPtrName)); rc = (void *)tp; } diff --git a/openmp/libomptarget/src/interface.cpp b/openmp/libomptarget/src/interface.cpp --- a/openmp/libomptarget/src/interface.cpp +++ b/openmp/libomptarget/src/interface.cpp @@ -64,7 +64,7 @@ for (const auto &Device : Devices) dumpTargetPointerMappings(Device); else - FAILURE_MESSAGE("run with env LIBOMPTARGET_INFO>1 to dump host-target" + 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"); @@ -114,7 +114,8 @@ EXTERN void __tgt_target_data_begin_mapper(int64_t device_id, int32_t arg_num, void **args_base, void **args, int64_t *arg_sizes, - int64_t *arg_types, void **arg_names, + int64_t *arg_types, + map_var_info_t *arg_names, void **arg_mappers) { if (IsOffloadDisabled()) return; @@ -138,19 +139,20 @@ #ifdef OMPTARGET_DEBUG for (int i = 0; i < arg_num; ++i) { DP("Entry %2d: Base=" DPxMOD ", Begin=" DPxMOD ", Size=%" PRId64 - ", Type=0x%" PRIx64 "\n", - i, DPxPTR(args_base[i]), DPxPTR(args[i]), arg_sizes[i], arg_types[i]); + ", Type=0x%" PRIx64 ", Name=%s\n", + i, DPxPTR(args_base[i]), DPxPTR(args[i]), arg_sizes[i], arg_types[i], + (arg_names) ? getNameFromMapping(arg_names[i]).c_str() : "(null)"); } #endif int rc = targetDataBegin(Device, arg_num, args_base, args, arg_sizes, - arg_types, arg_mappers, nullptr); + arg_types, arg_names, arg_mappers, nullptr); HandleTargetOutcome(rc == OFFLOAD_SUCCESS); } EXTERN void __tgt_target_data_begin_nowait_mapper( int64_t device_id, int32_t arg_num, void **args_base, void **args, - int64_t *arg_sizes, int64_t *arg_types, void **arg_names, + int64_t *arg_sizes, int64_t *arg_types, map_var_info_t *arg_names, void **arg_mappers, int32_t depNum, void *depList, int32_t noAliasDepNum, void *noAliasDepList) { if (depNum + noAliasDepNum > 0) @@ -183,7 +185,8 @@ EXTERN void __tgt_target_data_end_mapper(int64_t device_id, int32_t arg_num, void **args_base, void **args, int64_t *arg_sizes, int64_t *arg_types, - void **arg_names, void **arg_mappers) { + map_var_info_t *arg_names, + void **arg_mappers) { if (IsOffloadDisabled()) return; DP("Entering data end region with %d mappings\n", arg_num); @@ -211,19 +214,20 @@ #ifdef OMPTARGET_DEBUG for (int i=0; i 0) @@ -254,7 +258,7 @@ void **args_base, void **args, int64_t *arg_sizes, int64_t *arg_types, - void **arg_names, + map_var_info_t *arg_names, void **arg_mappers) { if (IsOffloadDisabled()) return; DP("Entering data update with %d mappings\n", arg_num); @@ -271,14 +275,14 @@ } DeviceTy& Device = Devices[device_id]; - int rc = target_data_update(Device, arg_num, args_base, - args, arg_sizes, arg_types, arg_mappers); + int rc = target_data_update(Device, arg_num, args_base, args, arg_sizes, + arg_types, arg_names, arg_mappers); HandleTargetOutcome(rc == OFFLOAD_SUCCESS); } EXTERN void __tgt_target_data_update_nowait_mapper( int64_t device_id, int32_t arg_num, void **args_base, void **args, - int64_t *arg_sizes, int64_t *arg_types, void **arg_names, + int64_t *arg_sizes, int64_t *arg_types, map_var_info_t *arg_names, void **arg_mappers, int32_t depNum, void *depList, int32_t noAliasDepNum, void *noAliasDepList) { if (depNum + noAliasDepNum > 0) @@ -308,7 +312,7 @@ EXTERN int __tgt_target_mapper(int64_t device_id, void *host_ptr, int32_t arg_num, void **args_base, void **args, int64_t *arg_sizes, int64_t *arg_types, - void **arg_names, void **arg_mappers) { + map_var_info_t *arg_names, void **arg_mappers) { if (IsOffloadDisabled()) return OFFLOAD_FAIL; DP("Entering target region with entry point " DPxMOD " and device Id %" PRId64 "\n", DPxPTR(host_ptr), device_id); @@ -326,24 +330,24 @@ #ifdef OMPTARGET_DEBUG for (int i=0; i 0) __kmpc_omp_taskwait(NULL, __kmpc_global_thread_num(NULL)); @@ -374,7 +378,8 @@ EXTERN int __tgt_target_teams_mapper(int64_t device_id, void *host_ptr, int32_t arg_num, void **args_base, void **args, int64_t *arg_sizes, - int64_t *arg_types, void **arg_names, + int64_t *arg_types, + map_var_info_t *arg_names, void **arg_mappers, int32_t team_num, int32_t thread_limit) { if (IsOffloadDisabled()) return OFFLOAD_FAIL; @@ -394,13 +399,15 @@ #ifdef OMPTARGET_DEBUG for (int i=0; i 0) __kmpc_omp_taskwait(NULL, __kmpc_global_thread_num(NULL)); 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 @@ -135,7 +135,7 @@ (uintptr_t)CurrHostEntry->addr /*HstPtrBase*/, (uintptr_t)CurrHostEntry->addr /*HstPtrBegin*/, (uintptr_t)CurrHostEntry->addr + CurrHostEntry->size /*HstPtrEnd*/, - (uintptr_t)CurrDeviceEntry->addr /*TgtPtrBegin*/, + (uintptr_t)CurrDeviceEntry->addr /*TgtPtrBegin*/, nullptr, true /*IsRefCountINF*/); } } @@ -158,8 +158,8 @@ DP("Has pending ctors... call now\n"); for (auto &entry : lib.second.PendingCtors) { void *ctor = entry; - int rc = target(device_id, ctor, 0, NULL, NULL, NULL, NULL, NULL, 1, - 1, true /*team*/); + int rc = target(device_id, ctor, 0, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, 1, 1, true /*team*/); if (rc != OFFLOAD_SUCCESS) { REPORT("Running ctor " DPxMOD " failed.\n", DPxPTR(ctor)); Device.PendingGlobalsMtx.unlock(); @@ -240,7 +240,7 @@ int rc = target_data_function(Device, MapperComponents.Components.size(), MapperArgsBase.data(), MapperArgs.data(), MapperArgSizes.data(), MapperArgTypes.data(), - /*arg_mappers*/ nullptr, + /*arg_names*/ nullptr, /*arg_mappers*/ nullptr, /*__tgt_async_info*/ nullptr); return rc; @@ -249,7 +249,8 @@ /// Internal function to do the mapping and transfer the data to the device int targetDataBegin(DeviceTy &Device, int32_t arg_num, void **args_base, void **args, int64_t *arg_sizes, int64_t *arg_types, - void **arg_mappers, __tgt_async_info *async_info_ptr) { + map_var_info_t *arg_names, void **arg_mappers, + __tgt_async_info *async_info_ptr) { // process each input. for (int32_t i = 0; i < arg_num; ++i) { // Ignore private variables and arrays - there is no mapping for them. @@ -279,6 +280,7 @@ void *HstPtrBegin = args[i]; void *HstPtrBase = args_base[i]; int64_t data_size = arg_sizes[i]; + map_var_info_t HstPtrName = (!arg_names) ? nullptr : arg_names[i]; // Adjust for proper alignment if this is a combined entry (for structs). // Look at the next argument - if that is MEMBER_OF this one, then this one @@ -327,8 +329,9 @@ // PTR_AND_OBJ entry is handled below, and so the allocation might fail // when HasPresentModifier. PointerTgtPtrBegin = Device.getOrAllocTgtPtr( - HstPtrBase, HstPtrBase, sizeof(void *), Pointer_IsNew, IsHostPtr, - IsImplicit, UpdateRef, HasCloseModifier, HasPresentModifier); + HstPtrBase, HstPtrBase, sizeof(void *), HstPtrName, Pointer_IsNew, + IsHostPtr, IsImplicit, UpdateRef, HasCloseModifier, + HasPresentModifier); if (!PointerTgtPtrBegin) { REPORT("Call to getOrAllocTgtPtr returned null pointer (%s).\n", HasPresentModifier ? "'present' map type modifier" @@ -345,8 +348,8 @@ } void *TgtPtrBegin = Device.getOrAllocTgtPtr( - HstPtrBegin, HstPtrBase, data_size, IsNew, IsHostPtr, IsImplicit, - UpdateRef, HasCloseModifier, HasPresentModifier); + HstPtrBegin, HstPtrBase, data_size, HstPtrName, IsNew, IsHostPtr, + IsImplicit, UpdateRef, HasCloseModifier, HasPresentModifier); // If data_size==0, then the argument could be a zero-length pointer to // NULL, so getOrAlloc() returning NULL is not an error. if (!TgtPtrBegin && (data_size || HasPresentModifier)) { @@ -443,7 +446,8 @@ /// Internal function to undo the mapping and retrieve the data from the device. int targetDataEnd(DeviceTy &Device, int32_t ArgNum, void **ArgBases, void **Args, int64_t *ArgSizes, int64_t *ArgTypes, - void **ArgMappers, __tgt_async_info *AsyncInfo) { + map_var_info_t *ArgNames, void **ArgMappers, + __tgt_async_info *AsyncInfo) { int Ret; std::vector DeallocTgtPtrs; // process each input. @@ -638,9 +642,10 @@ /// Internal function to pass data to/from the target. // async_info_ptr is currently unused, added here so target_data_update has the // same signature as targetDataBegin and targetDataEnd. -int target_data_update(DeviceTy &Device, int32_t arg_num, - void **args_base, void **args, int64_t *arg_sizes, int64_t *arg_types, - void **arg_mappers, __tgt_async_info *async_info_ptr) { +int target_data_update(DeviceTy &Device, int32_t arg_num, void **args_base, + void **args, int64_t *arg_sizes, int64_t *arg_types, + map_var_info_t *arg_names, void **arg_mappers, + __tgt_async_info *async_info_ptr) { // process each input. for (int32_t i = 0; i < arg_num; ++i) { if ((arg_types[i] & OMP_TGT_MAPTYPE_LITERAL) || @@ -832,10 +837,14 @@ const char *HstPtrEnd; /// Aligned size const int64_t AlignedSize; + /// Host pointer name + const map_var_info_t HstPtrName = nullptr; - FirstPrivateArgInfoTy(int Index, const void *HstPtr, int64_t Size) + FirstPrivateArgInfoTy(int Index, const void *HstPtr, int64_t Size, + const map_var_info_t HstPtrName = nullptr) : Index(Index), HstPtrBegin(reinterpret_cast(HstPtr)), - HstPtrEnd(HstPtrBegin + Size), AlignedSize(Size + Size % Alignment) {} + HstPtrEnd(HstPtrBegin + Size), AlignedSize(Size + Size % Alignment), + HstPtrName(HstPtrName) {} }; /// A vector of target pointers for all private arguments @@ -863,9 +872,10 @@ PrivateArgumentManagerTy(DeviceTy &Dev, __tgt_async_info *AsyncInfo) : Device(Dev), AsyncInfo(AsyncInfo) {} - /// A a private argument + /// Add a private argument int addArg(void *HstPtr, int64_t ArgSize, int64_t ArgOffset, - bool IsFirstPrivate, void *&TgtPtr, int TgtArgsIndex) { + bool IsFirstPrivate, void *&TgtPtr, int TgtArgsIndex, + const map_var_info_t HstPtrName = nullptr) { // If the argument is not first-private, or its size is greater than a // predefined threshold, we will allocate memory and issue the transfer // immediately. @@ -909,7 +919,8 @@ // Placeholder value TgtPtr = nullptr; - FirstPrivateArgInfo.emplace_back(TgtArgsIndex, HstPtr, ArgSize); + FirstPrivateArgInfo.emplace_back(TgtArgsIndex, HstPtr, ArgSize, + HstPtrName); FirstPrivateArgSize += FirstPrivateArgInfo.back().AlignedSize; } @@ -984,14 +995,14 @@ /// variables. int processDataBefore(int64_t DeviceId, void *HostPtr, int32_t ArgNum, void **ArgBases, void **Args, int64_t *ArgSizes, - int64_t *ArgTypes, void **ArgMappers, - std::vector &TgtArgs, + int64_t *ArgTypes, map_var_info_t *ArgNames, + void **ArgMappers, std::vector &TgtArgs, std::vector &TgtOffsets, PrivateArgumentManagerTy &PrivateArgumentManager, __tgt_async_info *AsyncInfo) { DeviceTy &Device = Devices[DeviceId]; int Ret = targetDataBegin(Device, ArgNum, ArgBases, Args, ArgSizes, ArgTypes, - ArgMappers, AsyncInfo); + ArgNames, ArgMappers, AsyncInfo); if (Ret != OFFLOAD_SUCCESS) { REPORT("Call to targetDataBegin failed, abort target.\n"); return OFFLOAD_FAIL; @@ -1049,6 +1060,7 @@ void *HstPtrBegin = Args[I]; void *HstPtrBase = ArgBases[I]; void *TgtPtrBegin; + map_var_info_t HstPtrName = (!ArgNames) ? nullptr : ArgNames[I]; ptrdiff_t TgtBaseOffset; bool IsLast, IsHostPtr; // unused. if (ArgTypes[I] & OMP_TGT_MAPTYPE_LITERAL) { @@ -1062,9 +1074,9 @@ // depend on this one. const bool IsFirstPrivate = (I >= ArgNum - 1 || !(ArgTypes[I + 1] & OMP_TGT_MAPTYPE_MEMBER_OF)); - Ret = PrivateArgumentManager.addArg(HstPtrBegin, ArgSizes[I], - TgtBaseOffset, IsFirstPrivate, - TgtPtrBegin, TgtArgs.size()); + Ret = PrivateArgumentManager.addArg( + HstPtrBegin, ArgSizes[I], TgtBaseOffset, IsFirstPrivate, TgtPtrBegin, + TgtArgs.size(), HstPtrName); if (Ret != OFFLOAD_SUCCESS) { REPORT("Failed to process %sprivate argument " DPxMOD "\n", (IsFirstPrivate ? "first-" : ""), DPxPTR(HstPtrBegin)); @@ -1104,14 +1116,15 @@ /// host if needed and deallocating target memory of (first-)private variables. int processDataAfter(int64_t DeviceId, void *HostPtr, int32_t ArgNum, void **ArgBases, void **Args, int64_t *ArgSizes, - int64_t *ArgTypes, void **ArgMappers, + int64_t *ArgTypes, map_var_info_t *ArgNames, + void **ArgMappers, PrivateArgumentManagerTy &PrivateArgumentManager, __tgt_async_info *AsyncInfo) { DeviceTy &Device = Devices[DeviceId]; // Move data from device. int Ret = targetDataEnd(Device, ArgNum, ArgBases, Args, ArgSizes, ArgTypes, - ArgMappers, AsyncInfo); + ArgNames, ArgMappers, AsyncInfo); if (Ret != OFFLOAD_SUCCESS) { REPORT("Call to targetDataEnd failed, abort target.\n"); return OFFLOAD_FAIL; @@ -1135,8 +1148,9 @@ /// returns 0 if it was able to transfer the execution to a target and an /// integer different from zero otherwise. int target(int64_t DeviceId, void *HostPtr, int32_t ArgNum, void **ArgBases, - void **Args, int64_t *ArgSizes, int64_t *ArgTypes, void **ArgMappers, - int32_t TeamNum, int32_t ThreadLimit, int IsTeamConstruct) { + void **Args, int64_t *ArgSizes, int64_t *ArgTypes, + map_var_info_t *ArgNames, void **ArgMappers, int32_t TeamNum, + int32_t ThreadLimit, int IsTeamConstruct) { DeviceTy &Device = Devices[DeviceId]; TableMap *TM = getTableMap(HostPtr); @@ -1166,7 +1180,7 @@ // Process data, such as data mapping, before launching the kernel int Ret = processDataBefore(DeviceId, HostPtr, ArgNum, ArgBases, Args, - ArgSizes, ArgTypes, ArgMappers, TgtArgs, + ArgSizes, ArgTypes, ArgNames, ArgMappers, TgtArgs, TgtOffsets, PrivateArgumentManager, &AsyncInfo); if (Ret != OFFLOAD_SUCCESS) { REPORT("Failed to process data before launching the kernel.\n"); @@ -1197,7 +1211,7 @@ // Transfer data back and deallocate target memory for (first-)private // variables Ret = processDataAfter(DeviceId, HostPtr, ArgNum, ArgBases, Args, ArgSizes, - ArgTypes, ArgMappers, PrivateArgumentManager, + ArgTypes, ArgNames, ArgMappers, PrivateArgumentManager, &AsyncInfo); if (Ret != OFFLOAD_SUCCESS) { REPORT("Failed to process data after launching the kernel.\n"); diff --git a/openmp/libomptarget/src/private.h b/openmp/libomptarget/src/private.h --- a/openmp/libomptarget/src/private.h +++ b/openmp/libomptarget/src/private.h @@ -20,23 +20,25 @@ extern int targetDataBegin(DeviceTy &Device, int32_t arg_num, void **args_base, void **args, int64_t *arg_sizes, int64_t *arg_types, - void **arg_mappers, + map_var_info_t *arg_names, void **arg_mappers, __tgt_async_info *async_info_ptr); extern int targetDataEnd(DeviceTy &Device, int32_t ArgNum, void **ArgBases, void **Args, int64_t *ArgSizes, int64_t *ArgTypes, - void **ArgMappers, __tgt_async_info *AsyncInfo); + map_var_info_t *arg_names, void **ArgMappers, + __tgt_async_info *AsyncInfo); extern int target_data_update(DeviceTy &Device, int32_t arg_num, - void **args_base, void **args, - int64_t *arg_sizes, int64_t *arg_types, + void **args_base, void **args, int64_t *arg_sizes, + int64_t *arg_types, map_var_info_t *arg_names, void **arg_mappers, __tgt_async_info *async_info_ptr = nullptr); extern int target(int64_t DeviceId, void *HostPtr, int32_t ArgNum, void **ArgBases, void **Args, int64_t *ArgSizes, - int64_t *ArgTypes, void **ArgMappers, int32_t TeamNum, - int32_t ThreadLimit, int IsTeamConstruct); + int64_t *ArgTypes, map_var_info_t *arg_names, + void **ArgMappers, int32_t TeamNum, int32_t ThreadLimit, + int IsTeamConstruct); extern int CheckDeviceAndCtors(int64_t device_id); @@ -77,8 +79,8 @@ // Function pointer type for target_data_* functions (targetDataBegin, // targetDataEnd and target_data_update). typedef int (*TargetDataFuncPtrTy)(DeviceTy &, int32_t, void **, void **, - int64_t *, int64_t *, void **, - __tgt_async_info *); + int64_t *, int64_t *, map_var_info_t *, + void **, __tgt_async_info *); // Implemented in libomp, they are called from within __tgt_* functions. #ifdef __cplusplus @@ -103,12 +105,15 @@ return; fprintf(stderr, "Device %d Host-Device Pointer Mappings:\n", Device.DeviceID); - fprintf(stderr, "%-18s %-18s %s\n", "Host Ptr", "Target Ptr", "Size (B)"); + fprintf(stderr, "%-18s %-18s %s %s\n", "Host Ptr", "Target Ptr", "Size (B)", + "Declaration"); for (const auto &HostTargetMap : Device.HostDataToTargetMap) { - fprintf(stderr, DPxMOD " " DPxMOD " %lu\n", + SourceInfo info(HostTargetMap.HstPtrName); + fprintf(stderr, DPxMOD " " DPxMOD " %-8lu %s at %s:%d:%d\n", DPxPTR(HostTargetMap.HstPtrBegin), DPxPTR(HostTargetMap.TgtPtrBegin), - HostTargetMap.HstPtrEnd - HostTargetMap.HstPtrBegin); + HostTargetMap.HstPtrEnd - HostTargetMap.HstPtrBegin, + info.name.c_str(), info.filename.c_str(), info.line, info.column); } } 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 @@ -383,8 +383,8 @@ Device.PendingGlobalsMtx.lock(); if (Device.PendingCtorsDtors[desc].PendingCtors.empty()) { for (auto &dtor : Device.PendingCtorsDtors[desc].PendingDtors) { - int rc = target(Device.DeviceID, dtor, 0, NULL, NULL, NULL, NULL, - NULL, 1, 1, true /*team*/); + int rc = target(Device.DeviceID, dtor, 0, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, 1, 1, true /*team*/); if (rc != OFFLOAD_SUCCESS) { DP("Running destructor " DPxMOD " failed.\n", DPxPTR(dtor)); }