Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions offload/include/OffloadPolicy.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#include "PluginManager.h"

using namespace llvm::omp::target::debug;

enum kmp_target_offload_kind_t {
tgt_disabled = 0,
tgt_default = 1,
Expand All @@ -35,12 +37,12 @@ class OffloadPolicy {
return;
default:
if (PM.getNumDevices()) {
DP("Default TARGET OFFLOAD policy is now mandatory "
"(devices were found)\n");
ODBG(ODT_Init) << "Default TARGET OFFLOAD policy is now mandatory "
<< "(devices were found)";
Kind = MANDATORY;
} else {
DP("Default TARGET OFFLOAD policy is now disabled "
"(no devices were found)\n");
ODBG(ODT_Init) << "Default TARGET OFFLOAD policy is now disabled "
<< "(no devices were found)";
Kind = DISABLED;
}
return;
Expand Down
11 changes: 7 additions & 4 deletions offload/include/OpenMP/OMPT/Connector.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

#include "Shared/Debug.h"

using namespace llvm::omp::target::debug;

#pragma push_macro("DEBUG_PREFIX")
#undef DEBUG_PREFIX
#define DEBUG_PREFIX "OMPT"
Expand Down Expand Up @@ -76,7 +78,7 @@ class OmptLibraryConnectorTy {
std::string LibName = LibIdent;
LibName += ".so";

DP("OMPT: Trying to load library %s\n", LibName.c_str());
ODBG(ODT_Tool) << "OMPT: Trying to load library " << LibName;
auto DynLibHandle = std::make_unique<llvm::sys::DynamicLibrary>(
llvm::sys::DynamicLibrary::getPermanentLibrary(LibName.c_str(),
&ErrMsg));
Expand All @@ -85,12 +87,13 @@ class OmptLibraryConnectorTy {
LibConnHandle = nullptr;
} else {
auto LibConnRtn = "ompt_" + LibIdent + "_connect";
DP("OMPT: Trying to get address of connection routine %s\n",
LibConnRtn.c_str());
ODBG(ODT_Tool) << "OMPT: Trying to get address of connection routine "
<< LibConnRtn;
LibConnHandle = reinterpret_cast<OmptConnectRtnTy>(
DynLibHandle->getAddressOfSymbol(LibConnRtn.c_str()));
}
DP("OMPT: Library connection handle = %p\n", LibConnHandle);
ODBG(ODT_Tool) << "OMPT: Library connection handle = "
<< reinterpret_cast<void *>(LibConnHandle);
IsInitialized = true;
}

Expand Down
1 change: 1 addition & 0 deletions offload/include/Shared/Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ constexpr const char *ODT_EmptyMapping = "EmptyMapping";
constexpr const char *ODT_Device = "Device";
constexpr const char *ODT_Interface = "Interface";
constexpr const char *ODT_Alloc = "Alloc";
constexpr const char *ODT_Tool = "Tool";

static inline odbg_ostream reportErrorStream() {
#ifdef OMPTARGET_DEBUG
Expand Down
12 changes: 8 additions & 4 deletions offload/include/Shared/EnvironmentVar.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <sstream>
#include <string>

using namespace llvm::omp::target::debug;

/// Utility class for parsing strings to other types.
struct StringParser {
/// Parse a string to another type.
Expand Down Expand Up @@ -61,7 +63,8 @@ template <typename Ty> class Envar {
IsPresent = StringParser::parse<Ty>(EnvStr, Data);

if (!IsPresent) {
DP("Ignoring invalid value %s for envar %s\n", EnvStr, Name.data());
ODBG(ODT_Init) << "Ignoring invalid value " << EnvStr << " for envar "
<< Name;
Data = Default;
}
}
Expand Down Expand Up @@ -180,12 +183,13 @@ inline llvm::Error Envar<Ty>::init(llvm::StringRef Name, GetterFunctor Getter,
// not present and reset to the getter value (default).
IsPresent = false;
Data = Default;
DP("Setter of envar %s failed, resetting to %s\n", Name.data(),
std::to_string(Data).data());
ODBG(ODT_Init) << "Setter of envar " << Name << " failed, resetting to "
<< std::to_string(Data);
consumeError(std::move(Err));
}
} else {
DP("Ignoring invalid value %s for envar %s\n", EnvStr, Name.data());
ODBG(ODT_Init) << "Ignoring invalid value " << EnvStr << " for envar "
<< Name;
Data = Default;
}
} else {
Expand Down
87 changes: 44 additions & 43 deletions offload/libomptarget/OpenMP/Mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "Shared/Requirements.h"
#include "device.h"

using namespace llvm::omp::target::debug;

/// Dump a table of all the host-target pointer pairs on failure
void dumpTargetPointerMappings(const ident_t *Loc, DeviceTy &Device,
bool toStdOut) {
Expand Down Expand Up @@ -59,12 +61,13 @@ int MappingInfoTy::associatePtr(void *HstPtrBegin, void *TgtPtrBegin,
bool IsValid = HDTT.HstPtrEnd == (uintptr_t)HstPtrBegin + Size &&
HDTT.TgtPtrBegin == (uintptr_t)TgtPtrBegin;
if (IsValid) {
DP("Attempt to re-associate the same device ptr+offset with the same "
"host ptr, nothing to do\n");
ODBG(ODT_MappingExists) << "Attempt to re-associate the same device "
<< "ptr+offset with the same "
<< "host ptr, nothing to do";
return OFFLOAD_SUCCESS;
}
REPORT("Not allowed to re-associate a different device ptr+offset with "
"the same host ptr\n");
REPORT() << "Not allowed to re-associate a different device ptr+offset "
<< "with the same host ptr";
return OFFLOAD_FAIL;
}

Expand All @@ -80,12 +83,12 @@ int MappingInfoTy::associatePtr(void *HstPtrBegin, void *TgtPtrBegin,
/*UseHoldRefCount=*/false, /*Name=*/nullptr,
/*IsRefCountINF=*/true))
.first->HDTT;
DP("Creating new map entry: HstBase=" DPxMOD ", HstBegin=" DPxMOD
", HstEnd=" DPxMOD ", TgtBegin=" DPxMOD ", DynRefCount=%s, "
"HoldRefCount=%s\n",
DPxPTR(NewEntry.HstPtrBase), DPxPTR(NewEntry.HstPtrBegin),
DPxPTR(NewEntry.HstPtrEnd), DPxPTR(NewEntry.TgtPtrBegin),
NewEntry.dynRefCountToStr().c_str(), NewEntry.holdRefCountToStr().c_str());
ODBG(ODT_Mapping) << "Creating new map entry: HstBase=" << NewEntry.HstPtrBase
<< ", HstBegin=" << NewEntry.HstPtrBegin
<< ", HstEnd=" << NewEntry.HstPtrEnd
<< ", TgtBegin=" << NewEntry.TgtPtrBegin
<< ", DynRefCount=" << NewEntry.dynRefCountToStr()
<< ", HoldRefCount=" << NewEntry.holdRefCountToStr();
(void)NewEntry;

// Notify the plugin about the new mapping.
Expand All @@ -97,7 +100,7 @@ int MappingInfoTy::disassociatePtr(void *HstPtrBegin) {

auto It = HDTTMap->find(HstPtrBegin);
if (It == HDTTMap->end()) {
REPORT("Association not found\n");
REPORT() << "Association not found";
return OFFLOAD_FAIL;
}
// Mapping exists
Expand All @@ -108,13 +111,13 @@ int MappingInfoTy::disassociatePtr(void *HstPtrBegin) {
// This is based on OpenACC 3.1, sec 3.2.33 "acc_unmap_data", L3656-3657:
// "It is an error to call acc_unmap_data if the structured reference
// count for the pointer is not zero."
REPORT("Trying to disassociate a pointer with a non-zero hold reference "
"count\n");
REPORT() << "Trying to disassociate a pointer with a non-zero "
<< "hold reference count";
return OFFLOAD_FAIL;
}

if (HDTT.isDynRefCountInf()) {
DP("Association found, removing it\n");
ODBG(ODT_Mapping) << "Association found, removing it";
void *Event = HDTT.getEvent();
delete &HDTT;
if (Event)
Expand All @@ -123,8 +126,8 @@ int MappingInfoTy::disassociatePtr(void *HstPtrBegin) {
return Device.notifyDataUnmapped(HstPtrBegin);
}

REPORT("Trying to disassociate a pointer which was not mapped via "
"omp_target_associate_ptr\n");
REPORT() << "Trying to disassociate a pointer which was not mapped via "
<< "omp_target_associate_ptr";
return OFFLOAD_FAIL;
}

Expand All @@ -135,8 +138,8 @@ LookupResult MappingInfoTy::lookupMapping(HDTTMapAccessorTy &HDTTMap,
uintptr_t HP = (uintptr_t)HstPtrBegin;
LookupResult LR;

DP("Looking up mapping(HstPtrBegin=" DPxMOD ", Size=%" PRId64 ")...\n",
DPxPTR(HP), Size);
ODBG(ODT_Mapping) << "Looking up mapping(HstPtrBegin=" << HP
<< ", Size=" << Size << ")...";

if (HDTTMap->empty())
return LR;
Expand Down Expand Up @@ -185,12 +188,12 @@ LookupResult MappingInfoTy::lookupMapping(HDTTMapAccessorTy &HDTTMap,
}

if (LR.Flags.ExtendsBefore) {
DP("WARNING: Pointer is not mapped but section extends into already "
"mapped data\n");
ODBG(ODT_Mapping) << "WARNING: Pointer is not mapped but section extends "
<< "into already mapped data";
}
if (LR.Flags.ExtendsAfter) {
DP("WARNING: Pointer is already mapped but section extends beyond mapped "
"region\n");
ODBG(ODT_Mapping) << "WARNING: Pointer is already mapped but section "
<< "extends beyond mapped region";
}
}

Expand Down Expand Up @@ -269,17 +272,16 @@ TargetPointerResultTy MappingInfoTy::getTargetPointer(
"Return HstPtrBegin " DPxMOD " Size=%" PRId64 " for unified shared "
"memory\n",
DPxPTR((uintptr_t)HstPtrBegin), Size);
DP("Return HstPtrBegin " DPxMOD " Size=%" PRId64 " for unified shared "
"memory\n",
DPxPTR((uintptr_t)HstPtrBegin), Size);
ODBG(ODT_Mapping) << "Return HstPtrBegin " << HstPtrBegin
<< " Size=" << Size << " for unified shared memory";
LR.TPR.Flags.IsPresent = false;
LR.TPR.Flags.IsHostPointer = true;
LR.TPR.TargetPointer = HstPtrBegin;
}
} else if (HasPresentModifier) {
DP("Mapping required by 'present' map type modifier does not exist for "
"HstPtrBegin=" DPxMOD ", Size=%" PRId64 "\n",
DPxPTR(HstPtrBegin), Size);
ODBG(ODT_Mapping) << "Mapping required by 'present' map type modifier does "
<< "not exist for HstPtrBegin=" << HstPtrBegin
<< ", Size=" << Size;
MESSAGE("device mapping required by 'present' map type modifier does not "
"exist for host address " DPxMOD " (%" PRId64 " bytes)",
DPxPTR(HstPtrBegin), Size);
Expand Down Expand Up @@ -342,19 +344,19 @@ TargetPointerResultTy MappingInfoTy::getTargetPointer(
};
if (LR.TPR.getEntry()->foreachShadowPointerInfo(FailOnPtrFound) ==
OFFLOAD_FAIL) {
DP("Multiple new mappings of %" PRId64 " bytes detected (hst:" DPxMOD
") -> (tgt:" DPxMOD ")\n",
Size, DPxPTR(HstPtrBegin), DPxPTR(LR.TPR.TargetPointer));
ODBG(ODT_Mapping) << "Multiple new mappings of " << Size
<< " bytes detected (hst:" << HstPtrBegin
<< ") -> (tgt:" << LR.TPR.TargetPointer;
return std::move(LR.TPR);
}

DP("Moving %" PRId64 " bytes (hst:" DPxMOD ") -> (tgt:" DPxMOD ")\n", Size,
DPxPTR(HstPtrBegin), DPxPTR(LR.TPR.TargetPointer));
ODBG(ODT_Mapping) << "Moving " << Size << " bytes (hst:" << HstPtrBegin
<< ") -> (tgt:" << LR.TPR.TargetPointer;

int Ret = Device.submitData(LR.TPR.TargetPointer, HstPtrBegin, Size,
AsyncInfo, LR.TPR.getEntry());
if (Ret != OFFLOAD_SUCCESS) {
REPORT("Copying data to device failed.\n");
REPORT() << "Copying data to device failed.";
// We will also return nullptr if the data movement fails because that
// pointer points to a corrupted memory region so it doesn't make any
// sense to continue to use it.
Expand All @@ -374,7 +376,7 @@ TargetPointerResultTy MappingInfoTy::getTargetPointer(
if (Ret != OFFLOAD_SUCCESS) {
// If it fails to wait for the event, we need to return nullptr in
// case of any data race.
REPORT("Failed to wait for event " DPxMOD ".\n", DPxPTR(Event));
REPORT() << "Failed to wait for event " << Event << ".";
return TargetPointerResultTy{};
}
}
Expand Down Expand Up @@ -444,9 +446,8 @@ TargetPointerResultTy MappingInfoTy::getTgtPtrBegin(
// If the value isn't found in the mapping and unified shared memory
// is on then it means we have stumbled upon a value which we need to
// use directly from the host.
DP("Get HstPtrBegin " DPxMOD " Size=%" PRId64 " for unified shared "
"memory\n",
DPxPTR((uintptr_t)HstPtrBegin), Size);
ODBG(ODT_Mapping) << "Get HstPtrBegin " << HstPtrBegin << " Size=" << Size
<< " for unified shared memory";
LR.TPR.Flags.IsPresent = false;
LR.TPR.Flags.IsHostPointer = true;
LR.TPR.TargetPointer = HstPtrBegin;
Expand Down Expand Up @@ -490,7 +491,7 @@ int MappingInfoTy::eraseMapEntry(HDTTMapAccessorTy &HDTTMap,
: "unknown");

if (HDTTMap->erase(Entry) == 0) {
REPORT("Trying to remove a non-existent map entry\n");
REPORT() << "Trying to remove a non-existent map entry";
return OFFLOAD_FAIL;
}

Expand All @@ -501,13 +502,13 @@ int MappingInfoTy::deallocTgtPtrAndEntry(HostDataToTargetTy *Entry,
int64_t Size) {
assert(Entry && "Trying to deallocate a null entry.");

DP("Deleting tgt data " DPxMOD " of size %" PRId64 " by freeing allocation "
"starting at " DPxMOD "\n",
DPxPTR(Entry->TgtPtrBegin), Size, DPxPTR(Entry->TgtAllocBegin));
ODBG(ODT_Mapping) << "Deleting tgt data " << Entry->TgtPtrBegin << " of size "
<< Size << " by freeing allocation "
<< "starting at " << Entry->TgtAllocBegin;

void *Event = Entry->getEvent();
if (Event && Device.destroyEvent(Event) != OFFLOAD_SUCCESS) {
REPORT("Failed to destroy event " DPxMOD "\n", DPxPTR(Event));
REPORT() << "Failed to destroy event " << Event;
return OFFLOAD_FAIL;
}

Expand Down
19 changes: 11 additions & 8 deletions offload/libomptarget/OpenMP/OMPT/Callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ FOREACH_OMPT_EMI_EVENT(defineOmptCallback)
#undef defineOmptCallback

using namespace llvm::omp::target::ompt;
using namespace llvm::omp::target::debug;

/// Forward declaration
class LibomptargetRtlFinalizer;
Expand Down Expand Up @@ -410,11 +411,13 @@ void Interface::endTarget(int64_t DeviceId, void *Code) {
}

void Interface::beginTargetDataOperation() {
DP("in ompt_target_region_begin (TargetRegionId = %lu)\n", TargetData.value);
ODBG(ODT_Tool) << "in ompt_target_region_begin (TargetRegionId = "
<< TargetData.value << ")";
}

void Interface::endTargetDataOperation() {
DP("in ompt_target_region_end (TargetRegionId = %lu)\n", TargetData.value);
ODBG(ODT_Tool) << "in ompt_target_region_end (TargetRegionId = "
<< TargetData.value << ")";
}

void Interface::beginTargetRegion() {
Expand Down Expand Up @@ -462,12 +465,12 @@ class LibomptargetRtlFinalizer {
int llvm::omp::target::ompt::initializeLibrary(ompt_function_lookup_t lookup,
int initial_device_num,
ompt_data_t *tool_data) {
DP("Executing initializeLibrary\n");
ODBG(ODT_Tool) << "Executing initializeLibrary";
#define bindOmptFunctionName(OmptFunction, DestinationFunction) \
if (lookup) \
DestinationFunction = (OmptFunction##_t)lookup(#OmptFunction); \
DP("initializeLibrary bound %s=%p\n", #DestinationFunction, \
((void *)(uint64_t)DestinationFunction));
ODBG(ODT_Tool) << "initializeLibrary bound " << #DestinationFunction << "=" \
<< ((void *)(uint64_t)DestinationFunction);

bindOmptFunctionName(ompt_get_callback, lookupCallbackByCode);
bindOmptFunctionName(ompt_get_task_data, ompt_get_task_data_fn);
Expand All @@ -493,7 +496,7 @@ int llvm::omp::target::ompt::initializeLibrary(ompt_function_lookup_t lookup,
}

void llvm::omp::target::ompt::finalizeLibrary(ompt_data_t *data) {
DP("Executing finalizeLibrary\n");
ODBG(ODT_Tool) << "Executing finalizeLibrary";
// Before disabling OMPT, call the (plugin) finalizations that were registered
// with this library
LibraryFinalizer->finalize();
Expand All @@ -502,7 +505,7 @@ void llvm::omp::target::ompt::finalizeLibrary(ompt_data_t *data) {
}

void llvm::omp::target::ompt::connectLibrary() {
DP("Entering connectLibrary\n");
ODBG(ODT_Tool) << "Entering connectLibrary";
// Connect with libomp
static OmptLibraryConnectorTy LibompConnector("libomp");
static ompt_start_tool_result_t OmptResult;
Expand All @@ -525,7 +528,7 @@ void llvm::omp::target::ompt::connectLibrary() {
FOREACH_OMPT_EMI_EVENT(bindOmptCallback)
#undef bindOmptCallback

DP("Exiting connectLibrary\n");
ODBG(ODT_Tool) << "Exiting connectLibrary";
}

#endif // OMPT_SUPPORT
Loading
Loading