https://github.com/hansangbae created 
https://github.com/llvm/llvm-project/pull/171684

Update debug messages based on the new method from #170425. Updated the 
following files.
- plugins-nextgen/common/include/MemoryManager.h
- plugins-nextgen/common/include/PluginInterface.h
- plugins-nextgen/common/src/GlobalHandler.cpp
- plugins-nextgen/common/src/PluginInterface.cpp
- plugins-nextgen/host/dynamic_ffi/ffi.cpp

>From dfd1abdd8caeb29a484092abd686036c8d0dd554 Mon Sep 17 00:00:00 2001
From: Hansang Bae <[email protected]>
Date: Wed, 10 Dec 2025 13:21:41 -0600
Subject: [PATCH] [Offload] Debug message update part 3

Update debug messages based on the new method from #170425.
Updated the following files.
- plugins-nextgen/common/include/MemoryManager.h
- plugins-nextgen/common/include/PluginInterface.h
- plugins-nextgen/common/src/GlobalHandler.cpp
- plugins-nextgen/common/src/PluginInterface.cpp
- plugins-nextgen/host/dynamic_ffi/ffi.cpp
---
 .../common/include/MemoryManager.h            |  49 ++---
 .../common/include/PluginInterface.h          |   9 +-
 .../common/src/GlobalHandler.cpp              |  23 +--
 .../common/src/PluginInterface.cpp            | 170 +++++++++---------
 .../plugins-nextgen/host/dynamic_ffi/ffi.cpp  |  12 +-
 5 files changed, 136 insertions(+), 127 deletions(-)

diff --git a/offload/plugins-nextgen/common/include/MemoryManager.h 
b/offload/plugins-nextgen/common/include/MemoryManager.h
index 8f6c1adcdaa58..5a1db0fde5974 100644
--- a/offload/plugins-nextgen/common/include/MemoryManager.h
+++ b/offload/plugins-nextgen/common/include/MemoryManager.h
@@ -27,6 +27,8 @@
 
 #include "llvm/Support/Error.h"
 
+using namespace llvm::omp::target::debug;
+
 namespace llvm {
 
 /// Base class of per-device allocator.
@@ -79,7 +81,7 @@ class MemoryManagerTy {
   static int findBucket(size_t Size) {
     const size_t F = floorToPowerOfTwo(Size);
 
-    DP("findBucket: Size %zu is floored to %zu.\n", Size, F);
+    ODBG(ODT_Alloc) << "findBucket: Size " << Size << " is floored to " << F;
 
     int L = 0, H = NumBuckets - 1;
     while (H - L > 1) {
@@ -94,7 +96,7 @@ class MemoryManagerTy {
 
     assert(L >= 0 && L < NumBuckets && "L is out of range");
 
-    DP("findBucket: Size %zu goes to bucket %d\n", Size, L);
+    ODBG(ODT_Alloc) << "findBucket: Size " << Size << " goes to bucket " << L;
 
     return L;
   }
@@ -192,8 +194,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) {
-      DP("Failed to get memory on device. Free all memory in FreeLists and "
-         "try again.\n");
+      ODBG(ODT_Alloc) << "Failed to get memory on device. Free all memory "
+                      << "in FreeLists and try again.";
       TgtPtrOrErr = freeAndAllocate(Size, HstPtr);
       if (!TgtPtrOrErr)
         return TgtPtrOrErr.takeError();
@@ -201,8 +203,8 @@ class MemoryManagerTy {
     }
 
     if (TgtPtr == nullptr)
-      DP("Still cannot get memory on device probably because the device is "
-         "OOM.\n");
+      ODBG(ODT_Alloc) << "Still cannot get memory on device probably because "
+                      << "the device is OOM.";
 
     return TgtPtr;
   }
@@ -222,8 +224,7 @@ class MemoryManagerTy {
     for (auto &PtrToNode : PtrToNodeTable) {
       assert(PtrToNode.second.Ptr && "nullptr in map table");
       if (auto Err = deleteOnDevice(PtrToNode.second.Ptr))
-        REPORT("Failure to delete memory: %s\n",
-               toString(std::move(Err)).data());
+        REPORT() << "Failure to delete memory: " << toString(std::move(Err));
     }
   }
 
@@ -235,21 +236,20 @@ class MemoryManagerTy {
     if (Size == 0)
       return nullptr;
 
-    DP("MemoryManagerTy::allocate: size %zu with host pointer " DPxMOD ".\n",
-       Size, DPxPTR(HstPtr));
+    ODBG(ODT_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) {
-      DP("%zu is greater than the threshold %zu. Allocate it directly from "
-         "device\n",
-         Size, SizeThreshold);
+      ODBG(ODT_Alloc) << Size << " is greater than the threshold "
+                      << SizeThreshold << ". Allocate it directly from device";
       auto TgtPtrOrErr = allocateOrFreeAndAllocateOnDevice(Size, HstPtr);
       if (!TgtPtrOrErr)
         return TgtPtrOrErr.takeError();
 
-      DP("Got target pointer " DPxMOD ". Return directly.\n",
-         DPxPTR(*TgtPtrOrErr));
+      ODBG(ODT_Alloc) << "Got target pointer " << *TgtPtrOrErr
+                      << ". Return directly.";
 
       return *TgtPtrOrErr;
     }
@@ -272,12 +272,13 @@ class MemoryManagerTy {
     }
 
     if (NodePtr != nullptr)
-      DP("Find one node " DPxMOD " in the bucket.\n", DPxPTR(NodePtr));
+      ODBG(ODT_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) {
-      DP("Cannot find a node in the FreeLists. Allocate on device.\n");
+      ODBG(ODT_Alloc) << "Cannot find a node in the FreeLists. "
+                      << "Allocate on device.";
       // Allocate one on device
       auto TgtPtrOrErr = allocateOrFreeAndAllocateOnDevice(Size, HstPtr);
       if (!TgtPtrOrErr)
@@ -294,8 +295,8 @@ class MemoryManagerTy {
         NodePtr = &Itr.first->second;
       }
 
-      DP("Node address " DPxMOD ", target pointer " DPxMOD ", size %zu\n",
-         DPxPTR(NodePtr), DPxPTR(TgtPtr), Size);
+      ODBG(ODT_Alloc) << "Node address " << NodePtr << ", target pointer "
+                      << TgtPtr << ", size " << Size;
     }
 
     assert(NodePtr && "NodePtr should not be nullptr at this point");
@@ -305,7 +306,7 @@ class MemoryManagerTy {
 
   /// Deallocate memory pointed by \p TgtPtr
   Error free(void *TgtPtr) {
-    DP("MemoryManagerTy::free: target memory " DPxMOD ".\n", DPxPTR(TgtPtr));
+    ODBG(ODT_Alloc) << "MemoryManagerTy::free: target memory " << TgtPtr;
 
     NodeTy *P = nullptr;
 
@@ -322,14 +323,14 @@ class MemoryManagerTy {
 
     // The memory is not managed by the manager
     if (P == nullptr) {
-      DP("Cannot find its node. Delete it on device directly.\n");
+      ODBG(ODT_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);
 
-    DP("Found its node " DPxMOD ". Insert it to bucket %d.\n", DPxPTR(P), B);
+    ODBG(ODT_Alloc) << "Found its node " << P << ". Insert it to bucket " << B;
 
     {
       std::lock_guard<std::mutex> G(FreeListLocks[B]);
@@ -352,8 +353,8 @@ class MemoryManagerTy {
     size_t Threshold = MemoryManagerThreshold.get();
 
     if (MemoryManagerThreshold.isPresent() && Threshold == 0) {
-      DP("Disabled memory manager as user set "
-         "LIBOMPTARGET_MEMORY_MANAGER_THRESHOLD=0.\n");
+      ODBG(ODT_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 1d52c960b7fde..4a9f670787ba9 100644
--- a/offload/plugins-nextgen/common/include/PluginInterface.h
+++ b/offload/plugins-nextgen/common/include/PluginInterface.h
@@ -50,6 +50,8 @@
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Triple.h"
 
+using namespace llvm::omp::target::debug;
+
 namespace llvm {
 namespace omp {
 namespace target {
@@ -712,8 +714,8 @@ class PinnedAllocationMapTy {
       IgnoreLockMappedFailures = false;
     } else {
       // Disable by default.
-      DP("Invalid value LIBOMPTARGET_LOCK_MAPPED_HOST_BUFFERS=%s\n",
-         OMPX_LockMappedBuffers.get().data());
+      ODBG(ODT_Alloc) << "Invalid value LIBOMPTARGET_LOCK_MAPPED_HOST_BUFFERS="
+                      << OMPX_LockMappedBuffers.get();
       LockMappedBuffers = false;
     }
   }
@@ -1639,7 +1641,8 @@ template <typename ResourceRef> class 
GenericDeviceResourceManagerTy {
   /// must be called before the destructor.
   virtual Error deinit() {
     if (NextAvailable)
-      DP("Missing %d resources to be returned\n", NextAvailable);
+      ODBG(ODT_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 5464c197dba78..4ba6817eaa5fb 100644
--- a/offload/plugins-nextgen/common/src/GlobalHandler.cpp
+++ b/offload/plugins-nextgen/common/src/GlobalHandler.cpp
@@ -27,6 +27,7 @@ using namespace omp;
 using namespace target;
 using namespace plugin;
 using namespace error;
+using namespace debug;
 
 Expected<std::unique_ptr<ObjectFile>>
 GenericGlobalHandlerTy::getELFObjectFile(DeviceImageTy &Image) {
@@ -75,12 +76,13 @@ Error 
GenericGlobalHandlerTy::moveGlobalBetweenDeviceAndHost(
       return Err;
   }
 
-  DP("Successfully %s %u bytes associated with global symbol '%s' %s the "
-     "device "
-     "(%p -> %p).\n",
-     Device2Host ? "read" : "write", HostGlobal.getSize(),
-     HostGlobal.getName().data(), Device2Host ? "from" : "to",
-     DeviceGlobal.getPtr(), HostGlobal.getPtr());
+  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() << ").";
 
   return Plugin::success();
 }
@@ -157,10 +159,11 @@ Error 
GenericGlobalHandlerTy::readGlobalFromImage(GenericDeviceTy &Device,
                          HostGlobal.getName().data(), ImageGlobal.getSize(),
                          HostGlobal.getSize());
 
-  DP("Global symbol '%s' was found in the ELF image and %u bytes will copied "
-     "from %p to %p.\n",
-     HostGlobal.getName().data(), HostGlobal.getSize(), ImageGlobal.getPtr(),
-     HostGlobal.getPtr());
+  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();
 
   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 ee2ecbcfd3098..09272a9a1d8c8 100644
--- a/offload/plugins-nextgen/common/src/PluginInterface.cpp
+++ b/offload/plugins-nextgen/common/src/PluginInterface.cpp
@@ -43,6 +43,7 @@ using namespace omp;
 using namespace target;
 using namespace plugin;
 using namespace error;
+using namespace debug;
 
 // TODO: Fix any thread safety issues for multi-threaded kernel recording.
 namespace llvm::omp::target::plugin {
@@ -99,7 +100,8 @@ struct RecordReplayTy {
       VAddr = *VAddrOrErr;
     }
 
-    DP("Request %ld bytes allocated at %p\n", MaxMemoryAllocation, VAddr);
+    ODBG(ODT_Alloc) << "Request " << MaxMemoryAllocation
+                    << " bytes allocated at " << VAddr;
 
     if (auto Err = Device->memoryVAMap(&MemoryStart, VAddr, &ASize))
       return Err;
@@ -157,10 +159,9 @@ struct RecordReplayTy {
     } else if (MemoryOffset) {
       // If we are off and in a situation we cannot just "waste" memory to 
force
       // a match, we hope adjusting the arguments is sufficient.
-      REPORT(
-          "WARNING Failed to allocate replay memory at required location %p, "
-          "got %p, trying to offset argument pointers by %" PRIi64 "\n",
-          VAddr, MemoryStart, MemoryOffset);
+      REPORT() << "WARNING Failed to allocate replay memory at required "
+               << "location " << VAddr << ", got " << MemoryStart
+               << ", trying to offset argument pointers by " << MemoryOffset;
     }
 
     INFO(OMP_INFOTYPE_PLUGIN_KERNEL, Device->getDeviceId(),
@@ -174,9 +175,8 @@ struct RecordReplayTy {
     if (Device->supportVAManagement()) {
       auto Err = preAllocateVAMemory(DeviceMemorySize, ReqVAddr);
       if (Err) {
-        REPORT("WARNING VA mapping failed, fallback to heuristic: "
-               "(Error: %s)\n",
-               toString(std::move(Err)).data());
+        REPORT() << "WARNING VA mapping failed, fallback to heuristic: "
+                 << "(Error: " << toString(std::move(Err)) << ")";
       }
     }
 
@@ -339,7 +339,7 @@ struct RecordReplayTy {
     Alloc = MemoryPtr;
     MemoryPtr = (char *)MemoryPtr + AlignedSize;
     MemorySize += AlignedSize;
-    DP("Memory Allocator return " DPxMOD "\n", DPxPTR(Alloc));
+    ODBG(ODT_Alloc) << "Memory Allocator return " << Alloc;
     return Alloc;
   }
 
@@ -413,9 +413,8 @@ Error GenericKernelTy::init(GenericDeviceTy &GenericDevice,
       return Err;
   } else {
     KernelEnvironment = KernelEnvironmentTy{};
-    DP("Failed to read kernel environment for '%s' Using default Bare (0) "
-       "execution mode\n",
-       getName());
+    ODBG(ODT_Alloc) << "Failed to read kernel environment for '" << getName()
+                    << "' Using default Bare (0) execution mode";
   }
 
   // Max = Config.Max > 0 ? min(Config.Max, Device.Max) : Device.Max;
@@ -726,7 +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)));             
\
-    DP("OMPT: class bound %s=%p\n", #Name, ((void *)(uint64_t)Name##_fn));     
\
+    ODBG(ODT_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) 
{
-  DP("Load data from image " DPxMOD "\n", DPxPTR(InputTgtImage.bytes_begin()));
+  ODBG(ODT_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;
-  DP("Running an RPC server on device %d\n", getDeviceId());
+  ODBG(ODT_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));
-    DP("Failure to check validity of image %p: %s", Image.data(),
-       ErrStr.c_str());
+    ODBG(ODT_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));
-    DP("Failure to check validity of image %p: %s", Image.data(),
-       ErrStr.c_str());
+    ODBG(ODT_Init) << "Failure to check validity of image " << Image << ": "
+                   << ErrStr;
     return false;
   };
   switch (identify_magic(Image)) {
@@ -1726,8 +1726,8 @@ int32_t GenericPluginTy::is_device_initialized(int32_t 
DeviceId) const {
 int32_t GenericPluginTy::init_device(int32_t DeviceId) {
   auto Err = initDevice(DeviceId);
   if (Err) {
-    REPORT("Failure to initialize device %d: %s\n", DeviceId,
-           toString(std::move(Err)).data());
+    REPORT() << "Failure to initialize device " << DeviceId << ": "
+             << toString(std::move(Err));
     return OFFLOAD_FAIL;
   }
 
@@ -1753,9 +1753,8 @@ int32_t GenericPluginTy::initialize_record_replay(int32_t 
DeviceId,
 
   if (auto Err = RecordReplay->init(&Device, MemorySize, VAddr, Status,
                                     SaveOutput, ReqPtrArgOffset)) {
-    REPORT("WARNING RR did not initialize RR-properly with %lu bytes"
-           "(Error: %s)\n",
-           MemorySize, toString(std::move(Err)).data());
+    REPORT() << "WARNING RR did not initialize RR-properly with " << MemorySize
+             << " bytes (Error: " << toString(std::move(Err)) << ")";
     RecordReplay->setStatus(RecordReplayTy::RRStatusTy::RRDeactivated);
 
     if (!isRecord) {
@@ -1775,8 +1774,8 @@ int32_t GenericPluginTy::load_binary(int32_t DeviceId,
   auto ImageOrErr = Device.loadBinary(*this, Buffer);
   if (!ImageOrErr) {
     auto Err = ImageOrErr.takeError();
-    REPORT("Failure to load binary image %p on device %d: %s\n", TgtImage,
-           DeviceId, toString(std::move(Err)).data());
+    REPORT() << "Failure to load binary image " << TgtImage << " on device "
+             << DeviceId << ": " << toString(std::move(Err));
     return OFFLOAD_FAIL;
   }
 
@@ -1794,8 +1793,8 @@ void *GenericPluginTy::data_alloc(int32_t DeviceId, 
int64_t Size, void *HostPtr,
       getDevice(DeviceId).dataAlloc(Size, HostPtr, (TargetAllocTy)Kind);
   if (!AllocOrErr) {
     auto Err = AllocOrErr.takeError();
-    REPORT("Failure to allocate device memory: %s\n",
-           toString(std::move(Err)).data());
+    REPORT() << "Failure to allocate device memory: "
+             << toString(std::move(Err));
     return nullptr;
   }
   assert(*AllocOrErr && "Null pointer upon successful allocation");
@@ -1808,8 +1807,8 @@ int32_t GenericPluginTy::data_delete(int32_t DeviceId, 
void *TgtPtr,
   auto Err =
       getDevice(DeviceId).dataDelete(TgtPtr, static_cast<TargetAllocTy>(Kind));
   if (Err) {
-    REPORT("Failure to deallocate device pointer %p: %s\n", TgtPtr,
-           toString(std::move(Err)).data());
+    REPORT() << "Failure to deallocate device pointer " << TgtPtr << ": "
+             << toString(std::move(Err));
     return OFFLOAD_FAIL;
   }
 
@@ -1821,13 +1820,14 @@ int32_t GenericPluginTy::data_lock(int32_t DeviceId, 
void *Ptr, int64_t Size,
   auto LockedPtrOrErr = getDevice(DeviceId).dataLock(Ptr, Size);
   if (!LockedPtrOrErr) {
     auto Err = LockedPtrOrErr.takeError();
-    REPORT("Failure to lock memory %p: %s\n", Ptr,
-           toString(std::move(Err)).data());
+    REPORT() << "Failure to lock memory " << Ptr << ": "
+             << toString(std::move(Err));
     return OFFLOAD_FAIL;
   }
 
   if (!(*LockedPtrOrErr)) {
-    REPORT("Failure to lock memory %p: obtained a null locked pointer\n", Ptr);
+    REPORT() << "Failure to lock memory " << Ptr
+             << ": obtained a null locked pointer";
     return OFFLOAD_FAIL;
   }
   *LockedPtr = *LockedPtrOrErr;
@@ -1838,8 +1838,8 @@ int32_t GenericPluginTy::data_lock(int32_t DeviceId, void 
*Ptr, int64_t Size,
 int32_t GenericPluginTy::data_unlock(int32_t DeviceId, void *Ptr) {
   auto Err = getDevice(DeviceId).dataUnlock(Ptr);
   if (Err) {
-    REPORT("Failure to unlock memory %p: %s\n", Ptr,
-           toString(std::move(Err)).data());
+    REPORT() << "Failure to unlock memory " << Ptr << ": "
+             << toString(std::move(Err));
     return OFFLOAD_FAIL;
   }
 
@@ -1850,8 +1850,8 @@ int32_t GenericPluginTy::data_notify_mapped(int32_t 
DeviceId, void *HstPtr,
                                             int64_t Size) {
   auto Err = getDevice(DeviceId).notifyDataMapped(HstPtr, Size);
   if (Err) {
-    REPORT("Failure to notify data mapped %p: %s\n", HstPtr,
-           toString(std::move(Err)).data());
+    REPORT() << "Failure to notify data mapped " << HstPtr << ": "
+             << toString(std::move(Err));
     return OFFLOAD_FAIL;
   }
 
@@ -1861,8 +1861,8 @@ int32_t GenericPluginTy::data_notify_mapped(int32_t 
DeviceId, void *HstPtr,
 int32_t GenericPluginTy::data_notify_unmapped(int32_t DeviceId, void *HstPtr) {
   auto Err = getDevice(DeviceId).notifyDataUnmapped(HstPtr);
   if (Err) {
-    REPORT("Failure to notify data unmapped %p: %s\n", HstPtr,
-           toString(std::move(Err)).data());
+    REPORT() << "Failure to notify data unmapped " << HstPtr << ": "
+             << toString(std::move(Err));
     return OFFLOAD_FAIL;
   }
 
@@ -1880,10 +1880,9 @@ int32_t GenericPluginTy::data_submit_async(int32_t 
DeviceId, void *TgtPtr,
                                            __tgt_async_info *AsyncInfoPtr) {
   auto Err = getDevice(DeviceId).dataSubmit(TgtPtr, HstPtr, Size, 
AsyncInfoPtr);
   if (Err) {
-    REPORT("Failure to copy data from host to device. Pointers: host "
-           "= " DPxMOD ", device = " DPxMOD ", size = %" PRId64 ": %s\n",
-           DPxPTR(HstPtr), DPxPTR(TgtPtr), Size,
-           toString(std::move(Err)).data());
+    REPORT() << "Failure to copy data from host to device. Pointers: host "
+             << "= " << HstPtr << ", device = " << TgtPtr << ", size = " << 
Size
+             << ": " << toString(std::move(Err));
     return OFFLOAD_FAIL;
   }
 
@@ -1902,10 +1901,9 @@ int32_t GenericPluginTy::data_retrieve_async(int32_t 
DeviceId, void *HstPtr,
   auto Err =
       getDevice(DeviceId).dataRetrieve(HstPtr, TgtPtr, Size, AsyncInfoPtr);
   if (Err) {
-    REPORT("Failure to copy data from device to host. Pointers: host "
-           "= " DPxMOD ", device = " DPxMOD ", size = %" PRId64 ": %s\n",
-           DPxPTR(HstPtr), DPxPTR(TgtPtr), Size,
-           toString(std::move(Err)).data());
+    REPORT() << "Failure to copy data from device to host. Pointers: host "
+             << "= " << HstPtr << ", device = " << TgtPtr << ", size = " << 
Size
+             << ": " << toString(std::move(Err));
     return OFFLOAD_FAIL;
   }
 
@@ -1927,10 +1925,10 @@ int32_t GenericPluginTy::data_exchange_async(int32_t 
SrcDeviceId, void *SrcPtr,
   GenericDeviceTy &DstDevice = getDevice(DstDeviceId);
   auto Err = SrcDevice.dataExchange(SrcPtr, DstDevice, DstPtr, Size, 
AsyncInfo);
   if (Err) {
-    REPORT("Failure to copy data from device (%d) to device (%d). Pointers: "
-           "host = " DPxMOD ", device = " DPxMOD ", size = %" PRId64 ": %s\n",
-           SrcDeviceId, DstDeviceId, DPxPTR(SrcPtr), DPxPTR(DstPtr), Size,
-           toString(std::move(Err)).data());
+    REPORT() << "Failure to copy data from device (" << SrcDeviceId
+             << ") to device (" << DstDeviceId
+             << "). Pointers: host = " << SrcPtr << ", device = " << DstPtr
+             << ", size = " << Size << ": " << toString(std::move(Err));
     return OFFLOAD_FAIL;
   }
 
@@ -1944,8 +1942,8 @@ int32_t GenericPluginTy::launch_kernel(int32_t DeviceId, 
void *TgtEntryPtr,
   auto Err = getDevice(DeviceId).launchKernel(TgtEntryPtr, TgtArgs, TgtOffsets,
                                               *KernelArgs, AsyncInfoPtr);
   if (Err) {
-    REPORT("Failure to run target region " DPxMOD " in device %d: %s\n",
-           DPxPTR(TgtEntryPtr), DeviceId, toString(std::move(Err)).data());
+    REPORT() << "Failure to run target region " << TgtEntryPtr << " in device "
+             << DeviceId << ": " << toString(std::move(Err));
     return OFFLOAD_FAIL;
   }
 
@@ -1956,8 +1954,8 @@ int32_t GenericPluginTy::synchronize(int32_t DeviceId,
                                      __tgt_async_info *AsyncInfoPtr) {
   auto Err = getDevice(DeviceId).synchronize(AsyncInfoPtr);
   if (Err) {
-    REPORT("Failure to synchronize stream %p: %s\n", AsyncInfoPtr->Queue,
-           toString(std::move(Err)).data());
+    REPORT() << "Failure to synchronize stream " << AsyncInfoPtr->Queue << ": "
+             << toString(std::move(Err));
     return OFFLOAD_FAIL;
   }
 
@@ -1968,8 +1966,8 @@ int32_t GenericPluginTy::query_async(int32_t DeviceId,
                                      __tgt_async_info *AsyncInfoPtr) {
   auto Err = getDevice(DeviceId).queryAsync(AsyncInfoPtr);
   if (Err) {
-    REPORT("Failure to query stream %p: %s\n", AsyncInfoPtr->Queue,
-           toString(std::move(Err)).data());
+    REPORT() << "Failure to query stream " << AsyncInfoPtr->Queue << ": "
+             << toString(std::move(Err));
     return OFFLOAD_FAIL;
   }
 
@@ -1978,14 +1976,14 @@ int32_t GenericPluginTy::query_async(int32_t DeviceId,
 
 void GenericPluginTy::print_device_info(int32_t DeviceId) {
   if (auto Err = getDevice(DeviceId).printInfo())
-    REPORT("Failure to print device %d info: %s\n", DeviceId,
-           toString(std::move(Err)).data());
+    REPORT() << "Failure to print device " << DeviceId
+             << " info: " << toString(std::move(Err));
 }
 
 int32_t GenericPluginTy::create_event(int32_t DeviceId, void **EventPtr) {
   auto Err = getDevice(DeviceId).createEvent(EventPtr);
   if (Err) {
-    REPORT("Failure to create event: %s\n", toString(std::move(Err)).data());
+    REPORT() << "Failure to create event: " << toString(std::move(Err));
     return OFFLOAD_FAIL;
   }
 
@@ -1996,8 +1994,8 @@ int32_t GenericPluginTy::record_event(int32_t DeviceId, 
void *EventPtr,
                                       __tgt_async_info *AsyncInfoPtr) {
   auto Err = getDevice(DeviceId).recordEvent(EventPtr, AsyncInfoPtr);
   if (Err) {
-    REPORT("Failure to record event %p: %s\n", EventPtr,
-           toString(std::move(Err)).data());
+    REPORT() << "Failure to record event " << EventPtr << ": "
+             << toString(std::move(Err));
     return OFFLOAD_FAIL;
   }
 
@@ -2008,8 +2006,8 @@ int32_t GenericPluginTy::wait_event(int32_t DeviceId, 
void *EventPtr,
                                     __tgt_async_info *AsyncInfoPtr) {
   auto Err = getDevice(DeviceId).waitEvent(EventPtr, AsyncInfoPtr);
   if (Err) {
-    REPORT("Failure to wait event %p: %s\n", EventPtr,
-           toString(std::move(Err)).data());
+    REPORT() << "Failure to wait event " << EventPtr << ": "
+             << toString(std::move(Err));
     return OFFLOAD_FAIL;
   }
 
@@ -2019,8 +2017,8 @@ int32_t GenericPluginTy::wait_event(int32_t DeviceId, 
void *EventPtr,
 int32_t GenericPluginTy::sync_event(int32_t DeviceId, void *EventPtr) {
   auto Err = getDevice(DeviceId).syncEvent(EventPtr);
   if (Err) {
-    REPORT("Failure to synchronize event %p: %s\n", EventPtr,
-           toString(std::move(Err)).data());
+    REPORT() << "Failure to synchronize event " << EventPtr << ": "
+             << toString(std::move(Err));
     return OFFLOAD_FAIL;
   }
 
@@ -2030,8 +2028,8 @@ int32_t GenericPluginTy::sync_event(int32_t DeviceId, 
void *EventPtr) {
 int32_t GenericPluginTy::destroy_event(int32_t DeviceId, void *EventPtr) {
   auto Err = getDevice(DeviceId).destroyEvent(EventPtr);
   if (Err) {
-    REPORT("Failure to destroy event %p: %s\n", EventPtr,
-           toString(std::move(Err)).data());
+    REPORT() << "Failure to destroy event " << EventPtr << ": "
+             << toString(std::move(Err));
     return OFFLOAD_FAIL;
   }
 
@@ -2049,8 +2047,8 @@ int32_t GenericPluginTy::init_async_info(int32_t DeviceId,
 
   auto Err = getDevice(DeviceId).initAsyncInfo(AsyncInfoPtr);
   if (Err) {
-    REPORT("Failure to initialize async info at " DPxMOD " on device %d: %s\n",
-           DPxPTR(*AsyncInfoPtr), DeviceId, toString(std::move(Err)).data());
+    REPORT() << "Failure to initialize async info at " << *AsyncInfoPtr
+             << " on device " << DeviceId << ": " << toString(std::move(Err));
     return OFFLOAD_FAIL;
   }
 
@@ -2072,8 +2070,8 @@ 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));
-    DP("Failure while checking accessibility of pointer %p for device %d: %s",
-       Ptr, DeviceId, ErrStr.c_str());
+    ODBG(ODT_Alloc) << "Failure while checking accessibility of pointer " << 
Ptr
+                    << " for device " << DeviceId << ": " << ErrStr;
     return false;
   };
 
@@ -2119,13 +2117,13 @@ int32_t 
GenericPluginTy::get_function(__tgt_device_binary Binary,
 
   auto KernelOrErr = Device.constructKernel(Name);
   if (Error Err = KernelOrErr.takeError()) {
-    REPORT("Failure to look up kernel: %s\n", toString(std::move(Err)).data());
+    REPORT() << "Failure to look up kernel: " << toString(std::move(Err));
     return OFFLOAD_FAIL;
   }
 
   GenericKernelTy &Kernel = *KernelOrErr;
   if (auto Err = Kernel.init(Device, Image)) {
-    REPORT("Failure to init kernel: %s\n", toString(std::move(Err)).data());
+    REPORT() << "Failure to init kernel: " << toString(std::move(Err));
     return OFFLOAD_FAIL;
   }
 
@@ -2142,8 +2140,8 @@ GenericPluginTy::create_interop(int32_t ID, int32_t 
InteropContext,
   auto &Device = getDevice(ID);
   auto InteropOrErr = Device.createInterop(InteropContext, *InteropSpec);
   if (!InteropOrErr) {
-    REPORT("Failure to create interop object for device " DPxMOD ": %s\n",
-           DPxPTR(InteropSpec), toString(InteropOrErr.takeError()).c_str());
+    REPORT() << "Failure to create interop object for device " << InteropSpec
+             << ": " << toString(InteropOrErr.takeError());
     return nullptr;
   }
   return *InteropOrErr;
@@ -2157,8 +2155,8 @@ int32_t GenericPluginTy::release_interop(int32_t ID,
   auto &Device = getDevice(ID);
   auto Err = Device.releaseInterop(Interop);
   if (Err) {
-    REPORT("Failure to release interop object " DPxMOD ": %s\n",
-           DPxPTR(Interop), toString(std::move(Err)).c_str());
+    REPORT() << "Failure to release interop object " << Interop << ": "
+             << toString(std::move(Err));
     return OFFLOAD_FAIL;
   }
   return OFFLOAD_SUCCESS;
@@ -2169,8 +2167,8 @@ int32_t GenericPluginTy::flush_queue(omp_interop_val_t 
*Interop) {
   assert(Interop && "Interop is null");
   auto Err = flushQueueImpl(Interop);
   if (Err) {
-    REPORT("Failure to flush interop object " DPxMOD " queue: %s\n",
-           DPxPTR(Interop), toString(std::move(Err)).c_str());
+    REPORT() << "Failure to flush interop object " << Interop
+             << " queue: " << toString(std::move(Err));
     return OFFLOAD_FAIL;
   }
   return OFFLOAD_SUCCESS;
@@ -2182,8 +2180,8 @@ int32_t GenericPluginTy::sync_barrier(omp_interop_val_t 
*Interop) {
   assert(Interop && "Interop is null");
   auto Err = syncBarrierImpl(Interop);
   if (Err) {
-    REPORT("Failure to synchronize interop object " DPxMOD ": %s\n",
-           DPxPTR(Interop), toString(std::move(Err)).c_str());
+    REPORT() << "Failure to synchronize interop object " << Interop << ": "
+             << toString(std::move(Err));
     return OFFLOAD_FAIL;
   }
   return OFFLOAD_SUCCESS;
@@ -2195,8 +2193,8 @@ int32_t GenericPluginTy::async_barrier(omp_interop_val_t 
*Interop) {
   assert(Interop && "Interop is null");
   auto Err = asyncBarrierImpl(Interop);
   if (Err) {
-    REPORT("Failure to queue barrier in interop object " DPxMOD ": %s\n",
-           DPxPTR(Interop), toString(std::move(Err)).c_str());
+    REPORT() << "Failure to queue barrier in interop object " << Interop << ": 
"
+             << toString(std::move(Err));
     return OFFLOAD_FAIL;
   }
   return OFFLOAD_SUCCESS;
@@ -2206,8 +2204,8 @@ int32_t GenericPluginTy::data_fence(int32_t DeviceId,
                                     __tgt_async_info *AsyncInfo) {
   auto Err = getDevice(DeviceId).dataFence(AsyncInfo);
   if (Err) {
-    REPORT("failure to place data fence on device %d: %s\n", DeviceId,
-           toString(std::move(Err)).data());
+    REPORT() << "Failure to place data fence on device " << DeviceId << ": "
+             << toString(std::move(Err));
     return OFFLOAD_FAIL;
   }
 
diff --git a/offload/plugins-nextgen/host/dynamic_ffi/ffi.cpp 
b/offload/plugins-nextgen/host/dynamic_ffi/ffi.cpp
index c586ad1c1969b..fe559c8c85e7c 100644
--- a/offload/plugins-nextgen/host/dynamic_ffi/ffi.cpp
+++ b/offload/plugins-nextgen/host/dynamic_ffi/ffi.cpp
@@ -18,6 +18,8 @@
 #include "DLWrap.h"
 #include "ffi.h"
 
+using namespace llvm::omp::target::debug;
+
 DLWRAP_INITIALIZE()
 
 DLWRAP(ffi_call, 4);
@@ -41,7 +43,7 @@ uint32_t ffi_init() {
       llvm::sys::DynamicLibrary::getPermanentLibrary(FFI_PATH, &ErrMsg));
 
   if (!DynlibHandle->isValid()) {
-    DP("Unable to load library '%s': %s!\n", FFI_PATH, ErrMsg.c_str());
+    ODBG(ODT_Init) << "Unable to load library '" << FFI_PATH << "': " << 
ErrMsg;
     return DYNAMIC_FFI_FAIL;
   }
 
@@ -50,10 +52,11 @@ uint32_t ffi_init() {
 
     void *P = DynlibHandle->getAddressOfSymbol(Sym);
     if (P == nullptr) {
-      DP("Unable to find '%s' in '%s'!\n", Sym, FFI_PATH);
+      ODBG(ODT_Init) << "Unable to find '" << Sym << "' in '" << FFI_PATH;
       return DYNAMIC_FFI_FAIL;
     }
-    DP("Implementing %s with dlsym(%s) -> %p\n", Sym, Sym, P);
+    ODBG(ODT_Init) << "Implementing " << Sym << " with dlsym(" << Sym << ") -> 
"
+                   << P;
 
     *dlwrap::pointer(I) = P;
   }
@@ -62,7 +65,8 @@ uint32_t ffi_init() {
   {                                                                            
\
     void *SymbolPtr = DynlibHandle->getAddressOfSymbol(#SYMBOL);               
\
     if (!SymbolPtr) {                                                          
\
-      DP("Unable to find '%s' in '%s'!\n", #SYMBOL, FFI_PATH);                 
\
+      ODBG(ODT_Init) << "Unable to find '" << #SYMBOL << "' in '" << FFI_PATH  
\
+                     << "'!";                                                  
\
       return DYNAMIC_FFI_FAIL;                                                 
\
     }                                                                          
\
     SYMBOL = *reinterpret_cast<decltype(SYMBOL) *>(SymbolPtr);                 
\

_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to