[llvm] [Offload] Update debug message printig in the plugins (PR #175205)
Hansang Bae via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 9 09:16:09 PST 2026
https://github.com/hansangbae created https://github.com/llvm/llvm-project/pull/175205
* Prepare a set of debug types in llvm::offload::debug to be used in plugin code
* Update debug messages in the plugins
>From a02543d30a9cf84d61b03327fd793ab7ad99e92f Mon Sep 17 00:00:00 2001
From: Hansang Bae <hansang.bae at intel.com>
Date: Fri, 9 Jan 2026 09:12:22 -0600
Subject: [PATCH] [Offload] Update debug message printig in the plugins
* Prepare a set of debug types in llvm::offload::debug to be used
in plugin code
* Update debug messages in the plugins
---
offload/include/Shared/Debug.h | 35 +++++---
offload/include/Shared/EnvironmentVar.h | 14 ++--
.../common/include/MemoryManager.h | 51 +++++------
.../common/include/PluginInterface.h | 10 +--
.../common/src/GlobalHandler.cpp | 26 +++---
.../common/src/PluginInterface.cpp | 30 +++----
.../plugins-nextgen/host/dynamic_ffi/ffi.cpp | 18 ++--
offload/plugins-nextgen/host/src/rtl.cpp | 6 +-
.../level_zero/include/L0Trace.h | 9 +-
.../level_zero/src/L0Context.cpp | 3 +-
.../level_zero/src/L0Device.cpp | 75 +++++++++--------
.../level_zero/src/L0DynWrapper.cpp | 13 ++-
.../level_zero/src/L0Kernel.cpp | 27 +++---
.../level_zero/src/L0Memory.cpp | 74 ++++++++--------
.../level_zero/src/L0Options.cpp | 35 ++++----
.../level_zero/src/L0Plugin.cpp | 56 ++++++-------
.../level_zero/src/L0Program.cpp | 84 ++++++++++---------
17 files changed, 302 insertions(+), 264 deletions(-)
diff --git a/offload/include/Shared/Debug.h b/offload/include/Shared/Debug.h
index 3a71fcfd00184..aee3eda2bd2ad 100644
--- a/offload/include/Shared/Debug.h
+++ b/offload/include/Shared/Debug.h
@@ -535,6 +535,19 @@ inline bool isDebugEnabled() { return false; }
#endif
+// Common debug types in offload.
+constexpr const char *OLDT_Init = "Init";
+constexpr const char *OLDT_Kernel = "Kernel";
+constexpr const char *OLDT_DataTransfer = "DataTransfer";
+constexpr const char *OLDT_Sync = "Sync";
+constexpr const char *OLDT_Deinit = "Deinit";
+constexpr const char *OLDT_Error = "Error";
+constexpr const char *OLDT_Device = "Device";
+constexpr const char *OLDT_Interface = "Interface";
+constexpr const char *OLDT_Alloc = "Alloc";
+constexpr const char *OLDT_Tool = "Tool";
+constexpr const char *OLDT_Module = "Module";
+
} // namespace llvm::offload::debug
namespace llvm::omp::target::debug {
@@ -550,23 +563,25 @@ enum OmpDebugLevel : uint32_t {
};
/* Debug types to use in libomptarget */
-constexpr const char *ODT_Init = "Init";
+constexpr const char *ODT_Init = OLDT_Init;
constexpr const char *ODT_Mapping = "Mapping";
-constexpr const char *ODT_Kernel = "Kernel";
-constexpr const char *ODT_DataTransfer = "DataTransfer";
-constexpr const char *ODT_Sync = "Sync";
-constexpr const char *ODT_Deinit = "Deinit";
-constexpr const char *ODT_Error = "Error";
+constexpr const char *ODT_Kernel = OLDT_Kernel;
+constexpr const char *ODT_DataTransfer = OLDT_DataTransfer;
+constexpr const char *ODT_Sync = OLDT_Sync;
+constexpr const char *ODT_Deinit = OLDT_Deinit;
+constexpr const char *ODT_Error = OLDT_Error;
constexpr const char *ODT_KernelArgs = "KernelArgs";
constexpr const char *ODT_MappingExists = "MappingExists";
constexpr const char *ODT_DumpTable = "DumpTable";
constexpr const char *ODT_MappingChanged = "MappingChanged";
constexpr const char *ODT_PluginKernel = "PluginKernel";
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";
+constexpr const char *ODT_Device = OLDT_Device;
+constexpr const char *ODT_Interface = OLDT_Interface;
+constexpr const char *ODT_Alloc = OLDT_Alloc;
+constexpr const char *ODT_Tool = OLDT_Tool;
+constexpr const char *ODT_Module = OLDT_Module;
+constexpr const char *ODT_Interop = "Interop";
static inline odbg_ostream reportErrorStream() {
#ifdef OMPTARGET_DEBUG
diff --git a/offload/include/Shared/EnvironmentVar.h b/offload/include/Shared/EnvironmentVar.h
index 5acafa3b175bb..bbd2d2cc37994 100644
--- a/offload/include/Shared/EnvironmentVar.h
+++ b/offload/include/Shared/EnvironmentVar.h
@@ -19,7 +19,7 @@
#include <sstream>
#include <string>
-using namespace llvm::omp::target::debug;
+using namespace llvm::offload::debug;
/// Utility class for parsing strings to other types.
struct StringParser {
@@ -63,8 +63,8 @@ template <typename Ty> class Envar {
IsPresent = StringParser::parse<Ty>(EnvStr, Data);
if (!IsPresent) {
- ODBG(ODT_Init) << "Ignoring invalid value " << EnvStr << " for envar "
- << Name;
+ ODBG(OLDT_Init) << "Ignoring invalid value " << EnvStr << " for envar "
+ << Name;
Data = Default;
}
}
@@ -183,13 +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;
- ODBG(ODT_Init) << "Setter of envar " << Name << " failed, resetting to "
- << std::to_string(Data);
+ ODBG(OLDT_Init) << "Setter of envar " << Name
+ << " failed, resetting to " << std::to_string(Data);
consumeError(std::move(Err));
}
} else {
- ODBG(ODT_Init) << "Ignoring invalid value " << EnvStr << " for envar "
- << Name;
+ ODBG(OLDT_Init) << "Ignoring invalid value " << EnvStr << " for envar "
+ << Name;
Data = Default;
}
} else {
diff --git a/offload/plugins-nextgen/common/include/MemoryManager.h b/offload/plugins-nextgen/common/include/MemoryManager.h
index 9b1574525046c..9dd4ee684f85a 100644
--- a/offload/plugins-nextgen/common/include/MemoryManager.h
+++ b/offload/plugins-nextgen/common/include/MemoryManager.h
@@ -27,7 +27,7 @@
#include "llvm/Support/Error.h"
-using namespace llvm::omp::target::debug;
+using namespace llvm::offload::debug;
namespace llvm {
@@ -81,8 +81,8 @@ class MemoryManagerTy {
static int findBucket(size_t Size) {
const size_t F = floorToPowerOfTwo(Size);
- ODBG(ODT_Alloc) << "findBucket: Size " << Size << " is floored to " << F
- << ".";
+ ODBG(OLDT_Alloc) << "findBucket: Size " << Size << " is floored to " << F
+ << ".";
int L = 0, H = NumBuckets - 1;
while (H - L > 1) {
@@ -97,7 +97,7 @@ class MemoryManagerTy {
assert(L >= 0 && L < NumBuckets && "L is out of range");
- ODBG(ODT_Alloc) << "findBucket: Size " << Size << " goes to bucket " << L;
+ ODBG(OLDT_Alloc) << "findBucket: Size " << Size << " goes to bucket " << L;
return L;
}
@@ -195,8 +195,8 @@ class MemoryManagerTy {
// We cannot get memory from the device. It might be due to OOM. Let's
// free all memory in FreeLists and try again.
if (TgtPtr == nullptr) {
- ODBG(ODT_Alloc) << "Failed to get memory on device. Free all memory "
- << "in FreeLists and try again.";
+ ODBG(OLDT_Alloc) << "Failed to get memory on device. Free all memory "
+ << "in FreeLists and try again.";
TgtPtrOrErr = freeAndAllocate(Size, HstPtr);
if (!TgtPtrOrErr)
return TgtPtrOrErr.takeError();
@@ -204,8 +204,8 @@ class MemoryManagerTy {
}
if (TgtPtr == nullptr)
- ODBG(ODT_Alloc) << "Still cannot get memory on device probably because "
- << "the device is OOM.";
+ ODBG(OLDT_Alloc) << "Still cannot get memory on device probably because "
+ << "the device is OOM.";
return TgtPtr;
}
@@ -237,20 +237,20 @@ class MemoryManagerTy {
if (Size == 0)
return nullptr;
- ODBG(ODT_Alloc) << "MemoryManagerTy::allocate: size " << Size
- << " with host pointer " << HstPtr << ".";
+ ODBG(OLDT_Alloc) << "MemoryManagerTy::allocate: size " << Size
+ << " with host pointer " << HstPtr << ".";
// If the size is greater than the threshold, allocate it directly from
// device.
if (Size > SizeThreshold) {
- ODBG(ODT_Alloc) << Size << " is greater than the threshold "
- << SizeThreshold << ". Allocate it directly from device";
+ ODBG(OLDT_Alloc) << Size << " is greater than the threshold "
+ << SizeThreshold << ". Allocate it directly from device";
auto TgtPtrOrErr = allocateOrFreeAndAllocateOnDevice(Size, HstPtr);
if (!TgtPtrOrErr)
return TgtPtrOrErr.takeError();
- ODBG(ODT_Alloc) << "Got target pointer " << *TgtPtrOrErr
- << ". Return directly.";
+ ODBG(OLDT_Alloc) << "Got target pointer " << *TgtPtrOrErr
+ << ". Return directly.";
return *TgtPtrOrErr;
}
@@ -273,13 +273,13 @@ class MemoryManagerTy {
}
if (NodePtr != nullptr)
- ODBG(ODT_Alloc) << "Find one node " << NodePtr << " in the bucket.";
+ ODBG(OLDT_Alloc) << "Find one node " << NodePtr << " in the bucket.";
// We cannot find a valid node in FreeLists. Let's allocate on device and
// create a node for it.
if (NodePtr == nullptr) {
- ODBG(ODT_Alloc) << "Cannot find a node in the FreeLists. "
- << "Allocate on device.";
+ ODBG(OLDT_Alloc) << "Cannot find a node in the FreeLists. "
+ << "Allocate on device.";
// Allocate one on device
auto TgtPtrOrErr = allocateOrFreeAndAllocateOnDevice(Size, HstPtr);
if (!TgtPtrOrErr)
@@ -296,8 +296,8 @@ class MemoryManagerTy {
NodePtr = &Itr.first->second;
}
- ODBG(ODT_Alloc) << "Node address " << NodePtr << ", target pointer "
- << TgtPtr << ", size " << Size;
+ ODBG(OLDT_Alloc) << "Node address " << NodePtr << ", target pointer "
+ << TgtPtr << ", size " << Size;
}
assert(NodePtr && "NodePtr should not be nullptr at this point");
@@ -307,7 +307,8 @@ class MemoryManagerTy {
/// Deallocate memory pointed by \p TgtPtr
Error free(void *TgtPtr) {
- ODBG(ODT_Alloc) << "MemoryManagerTy::free: target memory " << TgtPtr << ".";
+ ODBG(OLDT_Alloc) << "MemoryManagerTy::free: target memory " << TgtPtr
+ << ".";
NodeTy *P = nullptr;
@@ -324,15 +325,15 @@ class MemoryManagerTy {
// The memory is not managed by the manager
if (P == nullptr) {
- ODBG(ODT_Alloc) << "Cannot find its node. Delete it on device directly.";
+ ODBG(OLDT_Alloc) << "Cannot find its node. Delete it on device directly.";
return deleteOnDevice(TgtPtr);
}
// Insert the node to the free list
const int B = findBucket(P->Size);
- ODBG(ODT_Alloc) << "Found its node " << P << ". Insert it to bucket " << B
- << ".";
+ ODBG(OLDT_Alloc) << "Found its node " << P << ". Insert it to bucket " << B
+ << ".";
{
std::lock_guard<std::mutex> G(FreeListLocks[B]);
@@ -355,8 +356,8 @@ class MemoryManagerTy {
size_t Threshold = MemoryManagerThreshold.get();
if (MemoryManagerThreshold.isPresent() && Threshold == 0) {
- ODBG(ODT_Alloc) << "Disabled memory manager as user set "
- << "LIBOMPTARGET_MEMORY_MANAGER_THRESHOLD=0.";
+ ODBG(OLDT_Alloc) << "Disabled memory manager as user set "
+ << "LIBOMPTARGET_MEMORY_MANAGER_THRESHOLD=0.";
return std::make_pair(0, false);
}
diff --git a/offload/plugins-nextgen/common/include/PluginInterface.h b/offload/plugins-nextgen/common/include/PluginInterface.h
index 1851590d4e52b..caf86a921a914 100644
--- a/offload/plugins-nextgen/common/include/PluginInterface.h
+++ b/offload/plugins-nextgen/common/include/PluginInterface.h
@@ -50,7 +50,7 @@
#include "llvm/Support/raw_ostream.h"
#include "llvm/TargetParser/Triple.h"
-using namespace llvm::omp::target::debug;
+using namespace llvm::offload::debug;
namespace llvm {
namespace omp {
@@ -714,8 +714,8 @@ class PinnedAllocationMapTy {
IgnoreLockMappedFailures = false;
} else {
// Disable by default.
- ODBG(ODT_Alloc) << "Invalid value LIBOMPTARGET_LOCK_MAPPED_HOST_BUFFERS="
- << OMPX_LockMappedBuffers.get();
+ ODBG(OLDT_Alloc) << "Invalid value LIBOMPTARGET_LOCK_MAPPED_HOST_BUFFERS="
+ << OMPX_LockMappedBuffers.get();
LockMappedBuffers = false;
}
}
@@ -1656,8 +1656,8 @@ template <typename ResourceRef> class GenericDeviceResourceManagerTy {
/// must be called before the destructor.
virtual Error deinit() {
if (NextAvailable)
- ODBG(ODT_Deinit) << "Missing " << NextAvailable
- << " resources to be returned";
+ ODBG(OLDT_Deinit) << "Missing " << NextAvailable
+ << " resources to be returned";
// TODO: This prevents a bug on libomptarget to make the plugins fail. There
// may be some resources not returned. Do not destroy these ones.
diff --git a/offload/plugins-nextgen/common/src/GlobalHandler.cpp b/offload/plugins-nextgen/common/src/GlobalHandler.cpp
index 1dcadc17fba56..b92c606d14da1 100644
--- a/offload/plugins-nextgen/common/src/GlobalHandler.cpp
+++ b/offload/plugins-nextgen/common/src/GlobalHandler.cpp
@@ -27,7 +27,7 @@ using namespace omp;
using namespace target;
using namespace plugin;
using namespace error;
-using namespace debug;
+using namespace llvm::offload::debug;
Expected<std::unique_ptr<ObjectFile>>
GenericGlobalHandlerTy::getELFObjectFile(DeviceImageTy &Image) {
@@ -76,13 +76,13 @@ Error GenericGlobalHandlerTy::moveGlobalBetweenDeviceAndHost(
return Err;
}
- ODBG(ODT_DataTransfer) << "Successfully " << (Device2Host ? "read" : "write")
- << " " << HostGlobal.getSize()
- << " bytes associated with global symbol '"
- << HostGlobal.getName() << "' "
- << (Device2Host ? "from" : "to") << " the device ("
- << DeviceGlobal.getPtr() << " -> "
- << HostGlobal.getPtr() << ").";
+ ODBG(OLDT_DataTransfer) << "Successfully " << (Device2Host ? "read" : "write")
+ << " " << HostGlobal.getSize()
+ << " bytes associated with global symbol '"
+ << HostGlobal.getName() << "' "
+ << (Device2Host ? "from" : "to") << " the device ("
+ << DeviceGlobal.getPtr() << " -> "
+ << HostGlobal.getPtr() << ").";
return Plugin::success();
}
@@ -159,11 +159,11 @@ Error GenericGlobalHandlerTy::readGlobalFromImage(GenericDeviceTy &Device,
HostGlobal.getName().data(), ImageGlobal.getSize(),
HostGlobal.getSize());
- ODBG(ODT_DataTransfer) << "Global symbol '" << HostGlobal.getName()
- << "' was found in the ELF image and "
- << HostGlobal.getSize() << " bytes will copied from "
- << ImageGlobal.getPtr() << " to "
- << HostGlobal.getPtr() << ".";
+ ODBG(OLDT_DataTransfer) << "Global symbol '" << HostGlobal.getName()
+ << "' was found in the ELF image and "
+ << HostGlobal.getSize() << " bytes will copied from "
+ << ImageGlobal.getPtr() << " to "
+ << HostGlobal.getPtr() << ".";
assert(Image.getStart() <= ImageGlobal.getPtr() &&
utils::advancePtr(ImageGlobal.getPtr(), ImageGlobal.getSize()) <
diff --git a/offload/plugins-nextgen/common/src/PluginInterface.cpp b/offload/plugins-nextgen/common/src/PluginInterface.cpp
index fc5fe7529e3e5..4ec836636b57d 100644
--- a/offload/plugins-nextgen/common/src/PluginInterface.cpp
+++ b/offload/plugins-nextgen/common/src/PluginInterface.cpp
@@ -43,7 +43,7 @@ using namespace omp;
using namespace target;
using namespace plugin;
using namespace error;
-using namespace debug;
+using namespace llvm::offload::debug;
// TODO: Fix any thread safety issues for multi-threaded kernel recording.
namespace llvm::omp::target::plugin {
@@ -100,8 +100,8 @@ struct RecordReplayTy {
VAddr = *VAddrOrErr;
}
- ODBG(ODT_Alloc) << "Request " << MaxMemoryAllocation
- << " bytes allocated at " << VAddr;
+ ODBG(OLDT_Alloc) << "Request " << MaxMemoryAllocation
+ << " bytes allocated at " << VAddr;
if (auto Err = Device->memoryVAMap(&MemoryStart, VAddr, &ASize))
return Err;
@@ -339,7 +339,7 @@ struct RecordReplayTy {
Alloc = MemoryPtr;
MemoryPtr = (char *)MemoryPtr + AlignedSize;
MemorySize += AlignedSize;
- ODBG(ODT_Alloc) << "Memory Allocator return " << Alloc;
+ ODBG(OLDT_Alloc) << "Memory Allocator return " << Alloc;
return Alloc;
}
@@ -413,8 +413,8 @@ Error GenericKernelTy::init(GenericDeviceTy &GenericDevice,
return Err;
} else {
KernelEnvironment = KernelEnvironmentTy{};
- ODBG(ODT_Kernel) << "Failed to read kernel environment for '" << getName()
- << "' Using default Bare (0) execution mode";
+ ODBG(OLDT_Kernel) << "Failed to read kernel environment for '" << getName()
+ << "' Using default Bare (0) execution mode";
}
// Max = Config.Max > 0 ? min(Config.Max, Device.Max) : Device.Max;
@@ -725,8 +725,8 @@ GenericDeviceTy::GenericDeviceTy(GenericPluginTy &Plugin, int32_t DeviceId,
if (ompt::Initialized && ompt::lookupCallbackByCode) { \
ompt::lookupCallbackByCode((ompt_callbacks_t)(Code), \
((ompt_callback_t *)&(Name##_fn))); \
- ODBG(ODT_Tool) << "OMPT: class bound " << #Name << "=" \
- << ((void *)(uint64_t)Name##_fn); \
+ ODBG(OLDT_Tool) << "OMPT: class bound " << #Name << "=" \
+ << ((void *)(uint64_t)Name##_fn); \
}
FOREACH_OMPT_DEVICE_EVENT(bindOmptCallback);
@@ -849,7 +849,7 @@ Error GenericDeviceTy::deinit(GenericPluginTy &Plugin) {
}
Expected<DeviceImageTy *> GenericDeviceTy::loadBinary(GenericPluginTy &Plugin,
StringRef InputTgtImage) {
- ODBG(ODT_Init) << "Load data from image " << InputTgtImage.bytes_begin();
+ ODBG(OLDT_Init) << "Load data from image " << InputTgtImage.bytes_begin();
std::unique_ptr<MemoryBuffer> Buffer;
if (identify_magic(InputTgtImage) == file_magic::bitcode) {
@@ -920,7 +920,7 @@ Error GenericDeviceTy::setupRPCServer(GenericPluginTy &Plugin,
return Err;
RPCServer = &Server;
- ODBG(ODT_Init) << "Running an RPC server on device " << getDeviceId();
+ ODBG(OLDT_Init) << "Running an RPC server on device " << getDeviceId();
return Plugin::success();
}
@@ -1657,8 +1657,8 @@ int32_t GenericPluginTy::is_initialized() const { return Initialized; }
int32_t GenericPluginTy::isPluginCompatible(StringRef Image) {
auto HandleError = [&](Error Err) -> bool {
[[maybe_unused]] std::string ErrStr = toString(std::move(Err));
- ODBG(ODT_Init) << "Failure to check validity of image " << Image.data()
- << ": " << ErrStr;
+ ODBG(OLDT_Init) << "Failure to check validity of image " << Image.data()
+ << ": " << ErrStr;
return false;
};
switch (identify_magic(Image)) {
@@ -1686,8 +1686,8 @@ int32_t GenericPluginTy::isPluginCompatible(StringRef Image) {
int32_t GenericPluginTy::isDeviceCompatible(int32_t DeviceId, StringRef Image) {
auto HandleError = [&](Error Err) -> bool {
[[maybe_unused]] std::string ErrStr = toString(std::move(Err));
- ODBG(ODT_Init) << "Failure to check validity of image " << Image << ": "
- << ErrStr;
+ ODBG(OLDT_Init) << "Failure to check validity of image " << Image << ": "
+ << ErrStr;
return false;
};
switch (identify_magic(Image)) {
@@ -2070,7 +2070,7 @@ int32_t GenericPluginTy::is_accessible_ptr(int32_t DeviceId, const void *Ptr,
size_t Size) {
auto HandleError = [&](Error Err) -> bool {
[[maybe_unused]] std::string ErrStr = toString(std::move(Err));
- ODBG(ODT_Mapping) << "Failure while checking accessibility of pointer "
+ ODBG(OLDT_Device) << "Failure while checking accessibility of pointer "
<< Ptr << " for device " << DeviceId << ": " << ErrStr;
return false;
};
diff --git a/offload/plugins-nextgen/host/dynamic_ffi/ffi.cpp b/offload/plugins-nextgen/host/dynamic_ffi/ffi.cpp
index 8e3d963f2e7dc..28c0223eb71f6 100644
--- a/offload/plugins-nextgen/host/dynamic_ffi/ffi.cpp
+++ b/offload/plugins-nextgen/host/dynamic_ffi/ffi.cpp
@@ -18,7 +18,7 @@
#include "DLWrap.h"
#include "ffi.h"
-using namespace llvm::omp::target::debug;
+using namespace llvm::offload::debug;
DLWRAP_INITIALIZE()
@@ -43,8 +43,8 @@ uint32_t ffi_init() {
llvm::sys::DynamicLibrary::getPermanentLibrary(FFI_PATH, &ErrMsg));
if (!DynlibHandle->isValid()) {
- ODBG(ODT_Init) << "Unable to load library '" << FFI_PATH << "': " << ErrMsg
- << "!";
+ ODBG(OLDT_Init) << "Unable to load library '" << FFI_PATH << "': " << ErrMsg
+ << "!";
return DYNAMIC_FFI_FAIL;
}
@@ -53,12 +53,12 @@ uint32_t ffi_init() {
void *P = DynlibHandle->getAddressOfSymbol(Sym);
if (P == nullptr) {
- ODBG(ODT_Init) << "Unable to find '" << Sym << "' in '" << FFI_PATH
- << "'!";
+ ODBG(OLDT_Init) << "Unable to find '" << Sym << "' in '" << FFI_PATH
+ << "'!";
return DYNAMIC_FFI_FAIL;
}
- ODBG(ODT_Init) << "Implementing " << Sym << " with dlsym(" << Sym << ") -> "
- << P;
+ ODBG(OLDT_Init) << "Implementing " << Sym << " with dlsym(" << Sym
+ << ") -> " << P;
*dlwrap::pointer(I) = P;
}
@@ -67,8 +67,8 @@ uint32_t ffi_init() {
{ \
void *SymbolPtr = DynlibHandle->getAddressOfSymbol(#SYMBOL); \
if (!SymbolPtr) { \
- ODBG(ODT_Init) << "Unable to find '" << #SYMBOL << "' in '" << FFI_PATH \
- << "'!"; \
+ ODBG(OLDT_Init) << "Unable to find '" << #SYMBOL << "' in '" << FFI_PATH \
+ << "'!"; \
return DYNAMIC_FFI_FAIL; \
} \
SYMBOL = *reinterpret_cast<decltype(SYMBOL) *>(SymbolPtr); \
diff --git a/offload/plugins-nextgen/host/src/rtl.cpp b/offload/plugins-nextgen/host/src/rtl.cpp
index 8fa1c3e68b3bf..81fbb671aa88f 100644
--- a/offload/plugins-nextgen/host/src/rtl.cpp
+++ b/offload/plugins-nextgen/host/src/rtl.cpp
@@ -45,6 +45,8 @@
// The number of devices in this plugin.
#define NUM_DEVICES 4
+using namespace llvm::offload::debug;
+
namespace llvm {
namespace omp {
namespace target {
@@ -443,8 +445,8 @@ struct GenELF64PluginTy final : public GenericPluginTy {
if (auto Err = Plugin::check(ffi_init(), "failed to initialize libffi"))
return std::move(Err);
#endif
- ODBG("Init") << "GenELF64 plugin detected " << ODBG_IF_LEVEL(2)
- << NUM_DEVICES << " " << ODBG_RESET_LEVEL() << "devices";
+ ODBG(OLDT_Init) << "GenELF64 plugin detected " << ODBG_IF_LEVEL(2)
+ << NUM_DEVICES << " " << ODBG_RESET_LEVEL() << "devices";
return NUM_DEVICES;
}
diff --git a/offload/plugins-nextgen/level_zero/include/L0Trace.h b/offload/plugins-nextgen/level_zero/include/L0Trace.h
index 4791b72717072..3a60814a028ad 100644
--- a/offload/plugins-nextgen/level_zero/include/L0Trace.h
+++ b/offload/plugins-nextgen/level_zero/include/L0Trace.h
@@ -18,6 +18,7 @@
#include <string>
#include <level_zero/ze_api.h>
+using namespace llvm::offload::debug;
#define CALL_ZE(Rc, Fn, ...) \
do { \
Rc = Fn(__VA_ARGS__); \
@@ -31,8 +32,8 @@
CALL_ZE(rc, Fn, __VA_ARGS__); \
Mtx.unlock(); \
if (rc != ZE_RESULT_SUCCESS) { \
- DP("Error: %s:%s failed with error code %d, %s\n", __func__, #Fn, rc, \
- getZeErrorName(rc)); \
+ ODBG(OLDT_Error) << "Error: " << #Fn << " failed with error code " \
+ << rc << ", " << getZeErrorName(rc); \
return Ret; \
} \
} while (0)
@@ -48,8 +49,8 @@
ze_result_t rc; \
CALL_ZE(rc, Fn, __VA_ARGS__); \
if (rc != ZE_RESULT_SUCCESS) { \
- DP("Error: %s:%s failed with error code %d, %s\n", __func__, #Fn, rc, \
- getZeErrorName(rc)); \
+ ODBG(OLDT_Error) << "Error: " << #Fn << " failed with error code " \
+ << rc << ", " << getZeErrorName(rc); \
return Ret; \
} \
} while (0)
diff --git a/offload/plugins-nextgen/level_zero/src/L0Context.cpp b/offload/plugins-nextgen/level_zero/src/L0Context.cpp
index c526c54fe824f..3d1588bc5fecc 100644
--- a/offload/plugins-nextgen/level_zero/src/L0Context.cpp
+++ b/offload/plugins-nextgen/level_zero/src/L0Context.cpp
@@ -17,7 +17,8 @@ namespace llvm::omp::target::plugin {
Error L0ContextTy::init() {
CALL_ZE_RET_ERROR(zeDriverGetApiVersion, zeDriver, &APIVersion);
- DP("Driver API version is %" PRIx32 "\n", APIVersion);
+ ODBG(OLDT_Init) << "Driver API version is "
+ << llvm::format(PRIx32, APIVersion);
ze_context_desc_t Desc{ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
CALL_ZE_RET_ERROR(zeContextCreate, zeDriver, &Desc, &zeContext);
diff --git a/offload/plugins-nextgen/level_zero/src/L0Device.cpp b/offload/plugins-nextgen/level_zero/src/L0Device.cpp
index edea6da0c9399..2cae1e4899f37 100644
--- a/offload/plugins-nextgen/level_zero/src/L0Device.cpp
+++ b/offload/plugins-nextgen/level_zero/src/L0Device.cpp
@@ -64,7 +64,8 @@ constexpr int DeviceArchMapSize = sizeof(DeviceArchMap) / sizeof(DeviceArchMap[0
DeviceArchTy L0DeviceTy::computeArch() const {
const auto PCIDeviceId = getPCIId();
if (PCIDeviceId == 0) {
- DP("Warning: Cannot decide device arch for %s.\n", getNameCStr());
+ ODBG(OLDT_Device) << "Warning: Cannot decide device arch for " << getName()
+ << ".";
return DeviceArchTy::DeviceArch_None;
}
@@ -79,7 +80,8 @@ DeviceArchTy L0DeviceTy::computeArch() const {
}
}
- DP("Warning: Cannot decide device arch for %s.\n", getNameCStr());
+ ODBG(OLDT_Device) << "Warning: Cannot decide device arch for " << getName()
+ << ".";
return DeviceArchTy::DeviceArch_None;
}
@@ -116,7 +118,7 @@ std::pair<uint32_t, uint32_t> L0DeviceTy::findComputeOrdinal() {
}
}
if (Ordinal.first == MaxOrdinal)
- DP("Error: no command queues are found\n");
+ ODBG(OLDT_Device) << "Error: no command queues are found";
return Ordinal;
}
@@ -141,15 +143,14 @@ std::pair<uint32_t, uint32_t> L0DeviceTy::findCopyOrdinal(bool LinkCopy) {
auto NumQueues = Properties[I].numQueues;
if (LinkCopy && NumQueues > 1) {
Ordinal = {I, NumQueues};
- DP("Found link copy command queue for device " DPxMOD
- ", ordinal = %" PRIu32 ", number of queues = %" PRIu32 "\n",
- DPxPTR(zeDevice), Ordinal.first, Ordinal.second);
+ ODBG(OLDT_Init) << "Found link copy command queue for device "
+ << zeDevice << ", ordinal = " << Ordinal.first
+ << ", number of queues = " << Ordinal.second;
break;
} else if (!LinkCopy && NumQueues == 1) {
Ordinal = {I, NumQueues};
- DP("Found copy command queue for device " DPxMOD ", ordinal = %" PRIu32
- "\n",
- DPxPTR(zeDevice), Ordinal.first);
+ ODBG(OLDT_Init) << "Found copy command queue for device " << zeDevice
+ << ", ordinal = " << Ordinal.first;
break;
}
}
@@ -158,22 +159,25 @@ std::pair<uint32_t, uint32_t> L0DeviceTy::findCopyOrdinal(bool LinkCopy) {
}
void L0DeviceTy::reportDeviceInfo() const {
- DP("Device %" PRIu32 " information\n", DeviceId);
- DP("-- Name : %s\n", getNameCStr());
- DP("-- PCI ID : 0x%" PRIx32 "\n", getPCIId());
- DP("-- UUID : %s\n", getUuid().data());
- DP("-- Number of total EUs : %" PRIu32 "\n", getNumEUs());
- DP("-- Number of threads per EU : %" PRIu32 "\n", getNumThreadsPerEU());
- DP("-- EU SIMD width : %" PRIu32 "\n", getSIMDWidth());
- DP("-- Number of EUs per subslice : %" PRIu32 "\n", getNumEUsPerSubslice());
- DP("-- Number of subslices per slice: %" PRIu32 "\n",
- getNumSubslicesPerSlice());
- DP("-- Number of slices : %" PRIu32 "\n", getNumSlices());
- DP("-- Local memory size (bytes) : %" PRIu32 "\n",
- getMaxSharedLocalMemory());
- DP("-- Global memory size (bytes) : %" PRIu64 "\n", getGlobalMemorySize());
- DP("-- Cache size (bytes) : %" PRIu64 "\n", getCacheSize());
- DP("-- Max clock frequency (MHz) : %" PRIu32 "\n", getClockRate());
+ ODBG_OS(OLDT_Device, [&](llvm::raw_ostream &O) {
+ O << "Device " << DeviceId << " information\n"
+ << "-- Name : " << getName() << "\n"
+ << "-- PCI ID : "
+ << llvm::format("0x%" PRIx32, getPCIId()) << "\n"
+ << "-- UUID : " << getUuid().data() << "\n"
+ << "-- Number of total EUs : " << getNumEUs() << "\n"
+ << "-- Number of threads per EU : " << getNumThreadsPerEU() << "\n"
+ << "-- EU SIMD width : " << getSIMDWidth() << "\n"
+ << "-- Number of EUs per subslice : " << getNumEUsPerSubslice() << "\n"
+ << "-- Number of subslices per slice: " << getNumSubslicesPerSlice()
+ << "\n"
+ << "-- Number of slices : " << getNumSlices() << "\n"
+ << "-- Local memory size (bytes) : " << getMaxSharedLocalMemory()
+ << "\n"
+ << "-- Global memory size (bytes) : " << getGlobalMemorySize() << "\n"
+ << "-- Cache size (bytes) : " << getCacheSize() << "\n"
+ << "-- Max clock frequency (MHz) : " << getClockRate() << "\n";
+ });
}
Error L0DeviceTy::initImpl(GenericPluginTy &Plugin) {
@@ -191,7 +195,7 @@ Error L0DeviceTy::initImpl(GenericPluginTy &Plugin) {
DeviceName =
std::string(DeviceProperties.name, sizeof(DeviceProperties.name));
- DP("Found a GPU device, Name = %s\n", DeviceProperties.name);
+ ODBG(OLDT_Device) << "Found a GPU device, Name = " << DeviceProperties.name;
DeviceArch = computeArch();
// Default allocation kind for this device.
@@ -898,9 +902,9 @@ Expected<ze_command_list_handle_t> L0DeviceTy::createCmdList(
ze_command_list_handle_t cmdList;
CALL_ZE_RET_ERROR(zeCommandListCreate, Context, Device, &cmdListDesc,
&cmdList);
- DP("Created a command list " DPxMOD " (Ordinal: %" PRIu32
- ") for device %s.\n",
- DPxPTR(cmdList), Ordinal, DeviceIdStr.data());
+ ODBG(OLDT_Device) << "Created a command list " << cmdList
+ << " (Ordinal: " << Ordinal << ") for device "
+ << DeviceIdStr.data() << ".";
return cmdList;
}
@@ -944,9 +948,10 @@ L0DeviceTy::createCmdQueue(ze_context_handle_t Context,
ze_command_queue_handle_t cmdQueue;
CALL_ZE_RET_ERROR(zeCommandQueueCreate, Context, Device, &cmdQueueDesc,
&cmdQueue);
- DP("Created a command queue " DPxMOD " (Ordinal: %" PRIu32 ", Index: %" PRIu32
- ", Flags: %" PRIu32 ") for device %s.\n",
- DPxPTR(cmdQueue), Ordinal, Index, Flags, DeviceIdStr.data());
+ ODBG(OLDT_Device) << "Created a command queue " << cmdQueue
+ << " (Ordinal: " << Ordinal << ", Index: " << Index
+ << ", Flags: " << Flags << ") for device "
+ << DeviceIdStr.data() << ".";
return cmdQueue;
}
@@ -983,9 +988,9 @@ L0DeviceTy::createImmCmdList(uint32_t Ordinal, uint32_t Index, bool InOrder) {
ze_command_list_handle_t CmdList = nullptr;
CALL_ZE_RET_ERROR(zeCommandListCreateImmediate, getZeContext(), getZeDevice(),
&Desc, &CmdList);
- DP("Created an immediate command list " DPxMOD " (Ordinal: %" PRIu32
- ", Index: %" PRIu32 ", Flags: %" PRIu32 ") for device %s.\n",
- DPxPTR(CmdList), Ordinal, Index, Flags, getZeIdCStr());
+ ODBG(OLDT_Device) << "Created an immediate command list " << CmdList
+ << " (Ordinal: " << Ordinal << ", Index: " << Index
+ << ", Flags: " << Flags << ") for device " << getZeIdCStr();
return CmdList;
}
diff --git a/offload/plugins-nextgen/level_zero/src/L0DynWrapper.cpp b/offload/plugins-nextgen/level_zero/src/L0DynWrapper.cpp
index edc7e299ee163..38bd6aca0f11f 100644
--- a/offload/plugins-nextgen/level_zero/src/L0DynWrapper.cpp
+++ b/offload/plugins-nextgen/level_zero/src/L0DynWrapper.cpp
@@ -12,6 +12,8 @@
#include "Shared/Debug.h"
#include "llvm/Support/DynamicLibrary.h"
+using namespace llvm::offload::debug;
+
DLWRAP_INITIALIZE()
DLWRAP_INTERNAL(zeInit, 1)
@@ -106,13 +108,14 @@ static bool loadLevelZero() {
const char *L0Library = LEVEL_ZERO_LIBRARY;
std::string ErrMsg;
- DP("Trying to load %s\n", L0Library);
+ ODBG(OLDT_Init) << "Trying to load " << L0Library;
auto DynlibHandle = std::make_unique<llvm::sys::DynamicLibrary>(
llvm::sys::DynamicLibrary::getPermanentLibrary(L0Library, &ErrMsg));
if (!DynlibHandle->isValid()) {
if (ErrMsg.empty())
ErrMsg = "unknown error";
- DP("Unable to load library '%s': %s!\n", L0Library, ErrMsg.c_str());
+ ODBG(OLDT_Init) << "Unable to load library '" << L0Library
+ << "': " << ErrMsg << "!";
return false;
}
@@ -121,10 +124,12 @@ static bool loadLevelZero() {
void *P = DynlibHandle->getAddressOfSymbol(Sym);
if (P == nullptr) {
- DP("Unable to find '%s' in '%s'!\n", Sym, L0Library);
+ ODBG(OLDT_Init) << "Unable to find '" << Sym << "' in '" << L0Library
+ << "'!";
return false;
}
- DP("Implementing %s with dlsym(%s) -> %p\n", Sym, Sym, P);
+ ODBG(OLDT_Init) << "Implementing " << Sym << " with dlsym(" << Sym
+ << ") -> " << P;
*dlwrap::pointer(I) = P;
}
diff --git a/offload/plugins-nextgen/level_zero/src/L0Kernel.cpp b/offload/plugins-nextgen/level_zero/src/L0Kernel.cpp
index e6d7bba305fd8..5659d0c46724b 100644
--- a/offload/plugins-nextgen/level_zero/src/L0Kernel.cpp
+++ b/offload/plugins-nextgen/level_zero/src/L0Kernel.cpp
@@ -203,12 +203,13 @@ Error L0KernelTy::getGroupsShape(L0DeviceTy &Device, int32_t NumTeams,
if (ThreadLimit > 0) {
// use thread_limit clause value default.
- DP("Max team size is set to %" PRId32 " (thread_limit clause)\n",
- ThreadLimit);
+ ODBG(OLDT_Kernel) << "Max team size is set to " << ThreadLimit
+ << " (thread_limit clause)";
} else if (ThreadLimitICV > 0) {
// else use thread-limit-var ICV.
ThreadLimit = ThreadLimitICV;
- DP("Max team size is set to %" PRId32 " (thread-limit-icv)\n", ThreadLimit);
+ ODBG(OLDT_Kernel) << "Max team size is set to " << ThreadLimit
+ << " (thread-limit-icv)";
}
size_t MaxThreadLimit = Device.getMaxGroupSize();
@@ -218,29 +219,28 @@ Error L0KernelTy::getGroupsShape(L0DeviceTy &Device, int32_t NumTeams,
if (KernelPR.MaxThreadGroupSize < MaxThreadLimit) {
MaxThreadLimit = KernelPR.MaxThreadGroupSize;
- DP("Capping maximum team size to %zu due to kernel constraints.\n",
- MaxThreadLimit);
+ ODBG(OLDT_Kernel) << "Capping maximum team size to " << MaxThreadLimit
+ << " due to kernel constraints.";
}
if (ThreadLimit > static_cast<int32_t>(MaxThreadLimit)) {
ThreadLimit = MaxThreadLimit;
- DP("Max team size execceds current maximum %zu. Adjusted\n",
- MaxThreadLimit);
+ ODBG(OLDT_Kernel) << "Max team size exceeds current maximum "
+ << MaxThreadLimit << ". Adjusted";
}
// scope code to ease integration with downstream custom code.
{
if (NumTeams > 0) {
- DP("Number of teams is set to %" PRId32
- "(num_teams clause or no teams construct)\n",
- NumTeams);
+ ODBG(OLDT_Kernel) << "Number of teams is set to " << NumTeams
+ << " (num_teams clause or no teams construct)";
} else if (NumTeamsICV > 0) {
// OMP_NUM_TEAMS only matters, if num_teams() clause is absent.
INFO(OMP_INFOTYPE_PLUGIN_KERNEL, DeviceId,
"OMP_NUM_TEAMS(%" PRId32 ") is ignored\n", NumTeamsICV);
NumTeams = NumTeamsICV;
- DP("Max number of teams is set to %" PRId32 " (OMP_NUM_TEAMS)\n",
- NumTeams);
+ ODBG(OLDT_Kernel) << "Max number of teams is set to " << NumTeams
+ << " (OMP_NUM_TEAMS)";
}
decideKernelGroupArguments(Device, (uint32_t)NumTeams,
@@ -403,7 +403,8 @@ Error L0KernelTy::setIndirectFlags(L0DeviceTy &l0Device,
// Combine with common access flags.
const auto FinalFlags = l0Device.getIndirectFlags() | Flags;
CALL_ZE_RET_ERROR(zeKernelSetIndirectAccess, zeKernel, FinalFlags);
- DP("Setting indirect access flags " DPxMOD "\n", DPxPTR(FinalFlags));
+ ODBG(OLDT_Kernel) << "Setting indirect access flags "
+ << reinterpret_cast<void *>(FinalFlags);
KEnv.KernelPR.IndirectAccessFlags = Flags;
}
diff --git a/offload/plugins-nextgen/level_zero/src/L0Memory.cpp b/offload/plugins-nextgen/level_zero/src/L0Memory.cpp
index 414b86ed9b2e2..f72b33f916797 100644
--- a/offload/plugins-nextgen/level_zero/src/L0Memory.cpp
+++ b/offload/plugins-nextgen/level_zero/src/L0Memory.cpp
@@ -120,9 +120,9 @@ Error MemAllocatorTy::MemPoolTy::init(int32_t Kind, MemAllocatorTy *AllocatorIn,
AllocMax = AllocMin << getBucketId(UserAllocMax * (1 << 20));
if (AllocMin >= AllocMax) {
AllocMax = 2 * AllocMin;
- DP("Warning: Adjusting pool's AllocMax to %zu for %s due to device "
- "requirements.\n",
- AllocMax, AllocKindToStr(AllocKind));
+ ODBG(OLDT_Alloc) << "Warning: Adjusting pool's AllocMax to " << AllocMax
+ << " for " << AllocKindToStr(AllocKind)
+ << " due to device requirements.";
}
assert(AllocMin < AllocMax &&
"Invalid parameters while initializing memory pool");
@@ -151,11 +151,12 @@ Error MemAllocatorTy::MemPoolTy::init(int32_t Kind, MemAllocatorTy *AllocatorIn,
BucketParams.emplace_back(ChunkSize, BlockSize);
}
- DP("Initialized %s pool for device " DPxMOD ": AllocUnit = %zu, "
- "AllocMax = %zu, "
- "Capacity = %" PRIu32 ", PoolSizeMax = %zu\n",
- AllocKindToStr(AllocKind), DPxPTR(Device), AllocUnit, AllocMax,
- BlockCapacity, PoolSizeMax);
+ ODBG(OLDT_Alloc) << "Initialized " << AllocKindToStr(AllocKind)
+ << " pool for device " << Device
+ << ": AllocUnit = " << AllocUnit
+ << ", AllocMax = " << AllocMax
+ << ", Capacity = " << BlockCapacity
+ << ", PoolSizeMax = " << PoolSizeMax;
return Plugin::success();
}
@@ -179,9 +180,10 @@ Error MemAllocatorTy::MemPoolTy::init(MemAllocatorTy *AllocatorIn,
BucketParams.emplace_back(ChunkSize, ChunkSize * BlockCapacity);
}
- DP("Initialized reduction scratch pool for device " DPxMOD
- ": AllocMin = %zu, AllocMax = %zu, PoolSizeMax = %zu\n",
- DPxPTR(Allocator->Device), AllocMin, AllocMax, PoolSizeMax);
+ ODBG(OLDT_Alloc) << "Initialized reduction scratch pool for device "
+ << Allocator->Device << ": AllocMin = " << AllocMin
+ << ", AllocMax = " << AllocMax
+ << ", PoolSizeMax = " << PoolSizeMax;
return Plugin::success();
}
@@ -197,9 +199,10 @@ Error MemAllocatorTy::MemPoolTy::init(MemAllocatorTy *AllocatorIn) {
BucketStats.resize(1, {0, 0});
BucketParams.emplace_back(AllocMax, AllocUnit);
ZeroInit = true;
- DP("Initialized zero-initialized reduction counter pool for "
- "device " DPxMOD ": AllocMin = %zu, AllocMax = %zu, PoolSizeMax = %zu\n",
- DPxPTR(Allocator->Device), AllocMin, AllocMax, PoolSizeMax);
+ ODBG(OLDT_Alloc) << "Initialized zero-initialized reduction counter pool for "
+ << "device " << Allocator->Device
+ << ": AllocMin = " << AllocMin << ", AllocMax = " << AllocMax
+ << ", PoolSizeMax = " << PoolSizeMax;
return Plugin::success();
}
@@ -312,9 +315,9 @@ Expected<void *> MemAllocatorTy::MemPoolTy::alloc(size_t Size,
SmallPoolSize += BlockSize;
else
PoolSize += BlockSize;
- DP("New block allocation for %s pool: base = " DPxMOD
- ", size = %zu, pool size = %zu\n",
- AllocKindToStr(AllocKind), DPxPTR(Base), BlockSize, PoolSize);
+ ODBG(OLDT_Alloc) << "New block allocation for " << AllocKindToStr(AllocKind)
+ << " pool: base = " << Base << ", size = " << BlockSize
+ << ", pool size = " << PoolSize;
BucketStats[BucketId].first++;
} else {
BucketStats[BucketId].second++;
@@ -422,15 +425,15 @@ void MemAllocatorTy::updateMaxAllocSize(L0DeviceTy &L0Device) {
// MaxAllocSize should be the minimum of all devices from the driver.
if (MaxAllocSize > maxMemAllocSize) {
MaxAllocSize = maxMemAllocSize;
- DP("Updated MaxAllocSize for driver " DPxMOD " to %zu\n",
- DPxPTR(L0Context), MaxAllocSize);
+ ODBG(OLDT_Alloc) << "Updated MaxAllocSize for driver " << L0Context
+ << " to " << MaxAllocSize;
}
return;
}
MaxAllocSize = maxMemAllocSize;
- DP("Updated MaxAllocSize for device " DPxMOD " to %zu\n", DPxPTR(Device),
- MaxAllocSize);
+ ODBG(OLDT_Alloc) << "Updated MaxAllocSize for device " << Device << " to "
+ << MaxAllocSize;
}
/// Release resources and report statistics if requested.
@@ -552,8 +555,9 @@ Expected<void *> MemAllocatorTy::allocFromPool(size_t Size, size_t Align,
if (DevMalloc)
MemOwned.push_back(AllocBase);
if (UseDedicatedPool) {
- DP("Allocated %zu bytes from %s pool\n", Size,
- UseScratchPool ? "scratch" : "zero-initialized");
+ ODBG(OLDT_Alloc) << "Allocated " << Size << " bytes from "
+ << (UseScratchPool ? "scratch" : "zero-initialized")
+ << " pool";
}
return Mem;
}
@@ -571,8 +575,9 @@ Expected<void *> MemAllocatorTy::allocFromPool(size_t Size, size_t Align,
MemOwned.push_back(AllocBase);
if (UseDedicatedPool) {
// We do not want this happen in general.
- DP("Allocated %zu bytes from L0 for %s pool\n", Size,
- UseScratchPool ? "scratch" : "zero-initialized");
+ ODBG(OLDT_Alloc) << "Allocated " << Size << " bytes from L0 for "
+ << (UseScratchPool ? "scratch" : "zero-initialized")
+ << " pool";
}
}
return Mem;
@@ -607,7 +612,7 @@ Error MemAllocatorTy::deallocLocked(void *Ptr) {
return Plugin::success();
}
if (!Info.Base) {
- DP("Error: Cannot find base address of " DPxMOD "\n", DPxPTR(Ptr));
+ ODBG(OLDT_Alloc) << "Error: Cannot find base address of " << Ptr;
return Plugin::error(ErrorCode::INVALID_ARGUMENT,
"Cannot find base address of " DPxMOD "\n",
DPxPTR(Ptr));
@@ -616,8 +621,8 @@ Error MemAllocatorTy::deallocLocked(void *Ptr) {
if (auto Err = deallocFromL0(Info.Base))
return Err;
- DP("Deleted device memory " DPxMOD " (Base: " DPxMOD ", Size: %zu)\n",
- DPxPTR(Ptr), DPxPTR(Info.Base), Info.AllocSize);
+ ODBG(OLDT_Alloc) << "Deleted device memory " << Ptr << " (Base: " << Info.Base
+ << ", Size: " << Info.AllocSize << ")";
return Plugin::success();
}
@@ -655,19 +660,18 @@ Expected<void *> MemAllocatorTy::allocFromL0(size_t Size, size_t Align,
MakeResident = true;
CALL_ZE_RET_ERROR(zeMemAllocDevice, ZeContext, &DeviceDesc, Size, Align,
ZeDevice, &Mem);
- DP("Allocated %" PRId64 " bytes of device memory " DPxMOD "\n", Size,
- DPxPTR(Mem));
+ ODBG(OLDT_Alloc) << "Allocated " << Size << " bytes of device memory "
+ << Mem;
break;
case TARGET_ALLOC_HOST:
CALL_ZE_RET_ERROR(zeMemAllocHost, ZeContext, &HostDesc, Size, Align, &Mem);
- DP("Allocated %" PRId64 " bytes of host memory " DPxMOD "\n", Size,
- DPxPTR(Mem));
+ ODBG(OLDT_Alloc) << "Allocated " << Size << " bytes of host memory " << Mem;
break;
case TARGET_ALLOC_SHARED:
CALL_ZE_RET_ERROR(zeMemAllocShared, ZeContext, &DeviceDesc, &HostDesc, Size,
Align, ZeDevice, &Mem);
- DP("Allocated %" PRId64 " bytes of shared memory " DPxMOD "\n", Size,
- DPxPTR(Mem));
+ ODBG(OLDT_Alloc) << "Allocated " << Size << " bytes of shared memory "
+ << Mem;
break;
default:
assert(0 && "Invalid target data allocation kind");
@@ -686,7 +690,7 @@ Expected<void *> MemAllocatorTy::allocFromL0(size_t Size, size_t Align,
Error MemAllocatorTy::deallocFromL0(void *Ptr) {
CALL_ZE_RET_ERROR(zeMemFree, L0Context->getZeContext(), Ptr);
- DP("Freed device pointer " DPxMOD "\n", DPxPTR(Ptr));
+ ODBG(OLDT_Alloc) << "Freed device pointer " << Ptr;
return Plugin::success();
}
diff --git a/offload/plugins-nextgen/level_zero/src/L0Options.cpp b/offload/plugins-nextgen/level_zero/src/L0Options.cpp
index 409e5667b6f16..f1430e9feabb8 100644
--- a/offload/plugins-nextgen/level_zero/src/L0Options.cpp
+++ b/offload/plugins-nextgen/level_zero/src/L0Options.cpp
@@ -117,21 +117,23 @@ void L0OptionsTy::processEnvironmentVars() {
}
}
} else {
- DP("Ignoring incorrect memory pool configuration "
- "LIBOMPTARGET_LEVEL_ZERO_MEMORY_POOL=%s\n",
- MemoryPoolVar.get().c_str());
- DP("LIBOMPTARGET_LEVEL_ZERO_MEMORY_POOL=<Option>\n");
- DP(" <Option> := 0 | <PoolInfoList>\n");
- DP(" <PoolInfoList> := <PoolInfo>[,<PoolInfoList>]\n");
- DP(" <PoolInfo> := "
- "<MemType>[,<AllocMax>[,<Capacity>[,<PoolSize>]]]\n");
- DP(" <MemType> := all | device | host | shared\n");
- DP(" <AllocMax> := non-negative integer or empty, "
- "max allocation size in MB (default: 1)\n");
- DP(" <Capacity> := positive integer or empty, "
- "number of allocations from a single block (default: 4)\n");
- DP(" <PoolSize> := positive integer or empty, "
- "max pool size in MB (default: 256)\n");
+ ODBG_OS(OLDT_Init, [&](llvm::raw_ostream &O) {
+ O << "Ignoring incorrect memory pool configuration "
+ "LIBOMPTARGET_LEVEL_ZERO_MEMORY_POOL="
+ << MemoryPoolVar.get() << "\n";
+ O << "LIBOMPTARGET_LEVEL_ZERO_MEMORY_POOL=<Option>\n";
+ O << " <Option> := 0 | <PoolInfoList>\n";
+ O << " <PoolInfoList> := <PoolInfo>[,<PoolInfoList>]\n";
+ O << " <PoolInfo> := "
+ "<MemType>[,<AllocMax>[,<Capacity>[,<PoolSize>]]]\n";
+ O << " <MemType> := all | device | host | shared\n";
+ O << " <AllocMax> := non-negative integer or empty, "
+ "max allocation size in MB (default: 1)\n";
+ O << " <Capacity> := positive integer or empty, "
+ "number of allocations from a single block (default: 4)\n";
+ O << " <PoolSize> := positive integer or empty, "
+ "max pool size in MB (default: 256)\n";
+ });
}
}
}
@@ -150,7 +152,8 @@ void L0OptionsTy::processEnvironmentVars() {
size_t SizeInKB = StagingBufferSizeVar;
if (SizeInKB > (16 << 10)) {
SizeInKB = (16 << 10);
- DP("Staging buffer size is capped at %zu KB\n", SizeInKB);
+ ODBG(OLDT_Init) << "Staging buffer size is capped at " << SizeInKB
+ << " KB";
}
StagingBufferSize = SizeInKB << 10;
}
diff --git a/offload/plugins-nextgen/level_zero/src/L0Plugin.cpp b/offload/plugins-nextgen/level_zero/src/L0Plugin.cpp
index 5cad8eb140528..49fee797ead91 100644
--- a/offload/plugins-nextgen/level_zero/src/L0Plugin.cpp
+++ b/offload/plugins-nextgen/level_zero/src/L0Plugin.cpp
@@ -32,7 +32,7 @@ Expected<int32_t> LevelZeroPluginTy::findDevices() {
uint32_t NumDrivers = 0;
CALL_ZE_RET_ERROR(zeDriverGet, &NumDrivers, nullptr);
if (NumDrivers == 0) {
- DP("Cannot find any drivers.\n");
+ ODBG(OLDT_Init) << "Cannot find any drivers.";
return 0;
}
@@ -56,7 +56,8 @@ Expected<int32_t> LevelZeroPluginTy::findDevices() {
ze_result_t RC;
CALL_ZE(RC, zeDeviceGet, Driver, &DeviceCount, nullptr);
if (RC != ZE_RESULT_SUCCESS || DeviceCount == 0) {
- DP("Cannot find any devices from driver " DPxMOD ".\n", DPxPTR(Driver));
+ ODBG(OLDT_Init) << "Cannot find any devices from driver " << Driver
+ << ".";
continue;
}
// We have a driver that supports at least one device.
@@ -94,30 +95,31 @@ Expected<int32_t> LevelZeroPluginTy::findDevices() {
}
int32_t NumDevices = DetectedDevices.size();
- DP("Found %" PRIu32 " devices.\n", NumDevices);
- DP("List of devices (DeviceID[.SubID[.CCSID]])\n");
- for (auto &DeviceInfo : DetectedDevices) {
- (void)DeviceInfo; // Avoid unused variable warning in non-debug builds.
- DP("-- Device %" PRIu32 "%s%s\n", DeviceInfo.Id.RootId,
- (DeviceInfo.Id.SubId < 0
- ? ""
- : ("." + std::to_string(DeviceInfo.Id.SubId)).c_str()),
- (DeviceInfo.Id.CCSId < 0
- ? ""
- : ("." + std::to_string(DeviceInfo.Id.CCSId)).c_str()));
- }
+ ODBG_OS(OLDT_Init, [&](llvm::raw_ostream &O) {
+ O << "Found " << NumDevices << " devices.\n"
+ << "List of devices (DeviceID[.SubID[.CCSID]])\n";
+ for (auto &DeviceInfo : DetectedDevices)
+ O << "-- Device " << DeviceInfo.Id.RootId
+ << (DeviceInfo.Id.SubId < 0
+ ? ""
+ : ("." + std::to_string(DeviceInfo.Id.SubId)))
+ << (DeviceInfo.Id.CCSId < 0
+ ? ""
+ : ("." + std::to_string(DeviceInfo.Id.CCSId)))
+ << "\n";
+ });
return NumDevices;
}
Expected<int32_t> LevelZeroPluginTy::initImpl() {
- DP("Level0 NG plugin initialization\n");
+ ODBG(OLDT_Init) << "Level0 NG plugin initialization";
// Process options before anything else.
Options.init();
return findDevices();
}
Error LevelZeroPluginTy::deinitImpl() {
- DP("Deinit Level0 plugin!\n");
+ ODBG(OLDT_Deinit) << "Deinit Level0 plugin!";
if (auto Err = ContextTLSTable.deinit())
return Err;
if (auto Err = DeviceTLSTable.deinit())
@@ -126,7 +128,7 @@ Error LevelZeroPluginTy::deinitImpl() {
if (auto Err = Context.deinit())
return Err;
ContextList.clear();
- DP("Level0 plugin deinitialized successfully\n");
+ ODBG(OLDT_Deinit) << "Level0 plugin deinitialized successfully";
return Plugin::success();
}
@@ -178,17 +180,15 @@ Error LevelZeroPluginTy::syncBarrierImpl(omp_interop_val_t *Interop) {
// We can synchronize both L0 & SYCL objects with the same ze command.
if (l0Device.useImmForInterop()) {
- DP("LevelZeroPluginTy::sync_barrier: Synchronizing " DPxMOD
- " with ImmCmdList barrier\n",
- DPxPTR(Interop));
+ ODBG(OLDT_Sync) << "LevelZeroPluginTy::sync_barrier: Synchronizing "
+ << Interop << " with ImmCmdList barrier";
auto ImmCmdList = L0->ImmCmdList;
CALL_ZE_RET_ERROR(zeCommandListHostSynchronize, ImmCmdList,
L0DefaultTimeout);
} else {
- DP("LevelZeroPluginTy::sync_barrier: Synchronizing " DPxMOD
- " with queue synchronize\n",
- DPxPTR(Interop));
+ ODBG(OLDT_Sync) << "LevelZeroPluginTy::sync_barrier: Synchronizing "
+ << Interop << " with queue synchronize";
auto CmdQueue = L0->CommandQueue;
CALL_ZE_RET_ERROR(zeCommandQueueSynchronize, CmdQueue, L0DefaultTimeout);
}
@@ -212,18 +212,16 @@ Error LevelZeroPluginTy::asyncBarrierImpl(omp_interop_val_t *Interop) {
auto &l0Device = getDeviceFromId(device_id);
if (l0Device.useImmForInterop()) {
- DP("LevelZeroPluginTy::async_barrier: Appending ImmCmdList barrier "
- "to " DPxMOD "\n",
- DPxPTR(Interop));
+ ODBG(OLDT_Sync) << "LevelZeroPluginTy::async_barrier: Appending ImmCmdList "
+ << "barrier to " << Interop;
auto ImmCmdList = L0->ImmCmdList;
CALL_ZE_RET_ERROR(zeCommandListAppendBarrier, ImmCmdList, nullptr, 0,
nullptr);
} else {
#if 0
// TODO: re-enable once we have a way to delay the CmdList reset .
- DP("LevelZeroPluginTy::async_barrier: Appending CmdList barrier to " DPxMOD
- "\n",
- DPxPTR(Interop));
+ ODBG(OLDT_Sync) << "LevelZeroPluginTy::async_barrier: Appending CmdList "
+ << "barrier to " << Interop;
auto CmdQueue = L0->CommandQueue;
ze_command_list_handle_t CmdList = l0Device.getCmdList();
CALL_ZE_RET_ERROR(zeCommandListAppendBarrier, CmdList, nullptr, 0, nullptr);
diff --git a/offload/plugins-nextgen/level_zero/src/L0Program.cpp b/offload/plugins-nextgen/level_zero/src/L0Program.cpp
index 9ba35ef4c042c..4fd7af098fa1f 100644
--- a/offload/plugins-nextgen/level_zero/src/L0Program.cpp
+++ b/offload/plugins-nextgen/level_zero/src/L0Program.cpp
@@ -102,7 +102,7 @@ Error L0ProgramBuilderTy::addModule(size_t Size, const uint8_t *Image,
Error L0ProgramBuilderTy::linkModules() {
auto &l0Device = getL0Device();
if (!RequiresModuleLink) {
- DP("Module link is not required\n");
+ ODBG(OLDT_Module) << "Module link is not required";
return Plugin::success();
}
@@ -150,19 +150,19 @@ bool isValidOneOmpImage(StringRef Image, uint64_t &MajorVer,
auto ExpectedNewE =
ELFObjectFileBase::createELFObjectFile(MB->getMemBufferRef());
if (!ExpectedNewE) {
- DP("Warning: unable to get ELF handle!\n");
+ ODBG(OLDT_Module) << "Warning: unable to get ELF handle!";
return false;
}
bool Res = false;
auto processObjF = [&](const auto ELFObjF) {
if (!ELFObjF) {
- DP("Warning: Unexpected ELF type!\n");
+ ODBG(OLDT_Module) << "Warning: Unexpected ELF type!";
return false;
}
const auto &ELFF = ELFObjF->getELFFile();
auto Sections = ELFF.sections();
if (!Sections) {
- DP("Warning: unable to get ELF sections!\n");
+ ODBG(OLDT_Module) << "Warning: unable to get ELF sections!";
return false;
}
bool SeenOffloadSection = false;
@@ -172,7 +172,7 @@ bool isValidOneOmpImage(StringRef Image, uint64_t &MajorVer,
Error Err = Plugin::success();
for (auto Note : ELFF.notes(Sec, Err)) {
if (Err) {
- DP("Warning: unable to get ELF notes handle!\n");
+ ODBG(OLDT_Module) << "Warning: unable to get ELF notes handle!";
return false;
}
if (Note.getName() != "INTELONEOMPOFFLOAD")
@@ -185,8 +185,8 @@ bool isValidOneOmpImage(StringRef Image, uint64_t &MajorVer,
const auto DelimPos = DescStr.find('.');
if (DelimPos == std::string::npos) {
// The version has to look like "Major#.Minor#".
- DP("Invalid NT_INTEL_ONEOMP_OFFLOAD_VERSION: '%s'\n",
- DescStr.c_str());
+ ODBG(OLDT_Module)
+ << "Invalid NT_INTEL_ONEOMP_OFFLOAD_VERSION: '" << DescStr << "'";
return false;
}
const std::string MajorVerStr = DescStr.substr(0, DelimPos);
@@ -222,7 +222,7 @@ Error L0ProgramBuilderTy::buildModules(const std::string_view BuildOptions) {
uint64_t MajorVer, MinorVer;
if (!isValidOneOmpImage(Image.getBuffer(), MajorVer, MinorVer)) {
- DP("Warning: image is not a valid oneAPI OpenMP image.\n");
+ ODBG(OLDT_Module) << "Warning: image is not a valid oneAPI OpenMP image.";
return Plugin::error(ErrorCode::UNKNOWN, "Invalid oneAPI OpenMP image");
}
@@ -270,14 +270,15 @@ Error L0ProgramBuilderTy::buildModules(const std::string_view BuildOptions) {
auto DescStrRef = Note.getDescAsStringRef(4);
switch (Type) {
default:
- DP("Warning: unrecognized INTELONEOMPOFFLOAD note.\n");
+ ODBG(OLDT_Module) << "Warning: unrecognized INTELONEOMPOFFLOAD note.";
break;
case NT_INTEL_ONEOMP_OFFLOAD_VERSION:
break;
case NT_INTEL_ONEOMP_OFFLOAD_IMAGE_COUNT:
if (DescStrRef.getAsInteger(10, ImageCount)) {
- DP("Warning: invalid NT_INTEL_ONEOMP_OFFLOAD_IMAGE_COUNT: '%s'\n",
- DescStrRef.str().c_str());
+ ODBG(OLDT_Module) << "Warning: invalid "
+ << "NT_INTEL_ONEOMP_OFFLOAD_IMAGE_COUNT: '"
+ << DescStrRef.str() << "'";
ImageCount = 0;
}
break;
@@ -288,31 +289,30 @@ Error L0ProgramBuilderTy::buildModules(const std::string_view BuildOptions) {
// Ignore records with less than 4 strings.
if (Parts.size() != 4) {
- DP("Warning: short NT_INTEL_ONEOMP_OFFLOAD_IMAGE_AUX "
- "record is ignored.\n");
+ ODBG(OLDT_Module) << "Warning: short "
+ << "NT_INTEL_ONEOMP_OFFLOAD_IMAGE_AUX "
+ << "record is ignored.";
continue;
}
uint64_t Idx = 0;
if (Parts[0].getAsInteger(10, Idx)) {
- DP("Warning: ignoring auxiliary information (invalid index "
- "'%s').\n",
- Parts[0].str().c_str());
+ ODBG(OLDT_Module) << "Warning: ignoring auxiliary information "
+ << "(invalid index '" << Parts[0].str() << "').";
continue;
}
MaxImageIdx = (std::max)(MaxImageIdx, Idx);
if (AuxInfo.find(Idx) != AuxInfo.end()) {
- DP("Warning: duplicate auxiliary information for image %" PRIu64
- " is ignored.\n",
- Idx);
+ ODBG(OLDT_Module) << "Warning: duplicate auxiliary information for "
+ << "image " << Idx << " is ignored.";
continue;
}
uint64_t Part1Id;
if (Parts[1].getAsInteger(10, Part1Id)) {
- DP("Warning: ignoring auxiliary information (invalid part id "
- "'%s').\n",
- Parts[1].str().c_str());
+ ODBG(OLDT_Module)
+ << "Warning: ignoring auxiliary information "
+ << "(invalid part id '" << Parts[1].str() << "').";
continue;
}
@@ -325,7 +325,8 @@ Error L0ProgramBuilderTy::buildModules(const std::string_view BuildOptions) {
}
if (MaxImageIdx >= ImageCount)
- DP("Warning: invalid image index found in auxiliary information.\n");
+ ODBG(OLDT_Module) << "Warning: invalid image index found in auxiliary "
+ << "information.";
for (auto Sec : *Sections) {
const char *Prefix = "__openmp_offload_spirv_";
@@ -343,27 +344,26 @@ Error L0ProgramBuilderTy::buildModules(const std::string_view BuildOptions) {
// in the image and we keep the ordering in the runtime.
SectionNameRef = Parts.first;
if (Parts.second.empty()) {
- DP("Found a single section in the image\n");
+ ODBG(OLDT_Module) << "Found a single section in the image";
} else {
- DP("Found a split section in the image\n");
+ ODBG(OLDT_Module) << "Found a split section in the image";
}
uint64_t Idx = 0;
if (SectionNameRef.getAsInteger(10, Idx)) {
- DP("Warning: ignoring image section (invalid index '%s').\n",
- SectionNameRef.str().c_str());
+ ODBG(OLDT_Module) << "Warning: ignoring image section (invalid index '"
+ << SectionNameRef.str() << "').";
continue;
}
if (Idx >= ImageCount) {
- DP("Warning: ignoring image section (index %" PRIu64
- " is out of range).\n",
- Idx);
+ ODBG(OLDT_Module) << "Warning: ignoring image section (index " << Idx
+ << " is out of range).";
continue;
}
auto AuxInfoIt = AuxInfo.find(Idx);
if (AuxInfoIt == AuxInfo.end()) {
- DP("Warning: ignoring image section (no aux info).\n");
+ ODBG(OLDT_Module) << "Warning: ignoring image section (no aux info).";
continue;
}
auto Contents = E.getSectionContents(Sec);
@@ -384,22 +384,23 @@ Error L0ProgramBuilderTy::buildModules(const std::string_view BuildOptions) {
for (uint64_t Idx = 0; Idx < ImageCount; ++Idx) {
const auto It = AuxInfo.find(Idx);
if (It == AuxInfo.end()) {
- DP("Warning: image %" PRIu64
- " without auxiliary information is ingored.\n",
- Idx);
+ ODBG(OLDT_Module) << "Warning: image " << Idx
+ << " without auxiliary information is ingored.";
continue;
}
const auto NumParts = It->second.PartBegin.size();
// Split-kernel is not supported in SPIRV format.
if (NumParts > 1 && It->second.Format != 0) {
- DP("Warning: split-kernel images are not supported in SPIRV format\n");
+ ODBG(OLDT_Module) << "Warning: split-kernel images are not supported in "
+ << "SPIRV format";
continue;
}
// Skip unknown image format.
if (It->second.Format != 0 && It->second.Format != 1) {
- DP("Warning: image %" PRIu64 "is ignored due to unknown format.\n", Idx);
+ ODBG(OLDT_Module) << "Warning: image " << Idx << " is ignored due to "
+ << "unknown format.";
continue;
}
@@ -417,15 +418,16 @@ Error L0ProgramBuilderTy::buildModules(const std::string_view BuildOptions) {
reinterpret_cast<const unsigned char *>(It->second.PartBegin[I]);
size_t ImgSize = It->second.PartSize[I];
- DP("Creating module from %s image part #%" PRIu64 "-%zu.\n",
- IsBinary ? "Binary" : "SPIR-V", Idx, I);
+ ODBG(OLDT_Module) << "Creating module from "
+ << (IsBinary ? "Binary" : "SPIR-V") << " image part #"
+ << Idx << "-" << I << ".";
if (auto Err = addModule(ImgSize, ImgBegin, Options, ModuleFormat))
return Err;
}
- DP("Created module from image #%" PRIu64 ".\n", Idx);
+ ODBG(OLDT_Module) << "Created module from image #" << Idx << ".";
if (RequiresModuleLink) {
- DP("Linking modules after adding image #%" PRIu64 ".\n", Idx);
+ ODBG(OLDT_Module) << "Linking modules after adding image #" << Idx << ".";
if (auto Err = linkModules())
return Err;
}
@@ -451,7 +453,7 @@ Expected<std::unique_ptr<MemoryBuffer>> L0ProgramBuilderTy::getELF() {
}
Expected<void *> L0ProgramTy::getSymbolDeviceAddr(const char *CName) const {
- DP("Looking up OpenMP global variable '%s'.\n", CName);
+ ODBG(OLDT_Module) << "Looking up OpenMP global variable '" << CName << "'.";
if (!GlobalModule || !CName)
return Plugin::error(ErrorCode::INVALID_ARGUMENT,
More information about the llvm-commits
mailing list