[llvm] [Offload] Fix debug printing for functions implemented in headers (PR #112046)
Nick Sarnie via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 11 14:06:33 PDT 2024
https://github.com/sarnex updated https://github.com/llvm/llvm-project/pull/112046
>From 5abf8f5f26842202601176b3fefd388cb585e127 Mon Sep 17 00:00:00 2001
From: "Sarnie, Nick" <nick.sarnie at intel.com>
Date: Fri, 11 Oct 2024 12:50:35 -0700
Subject: [PATCH 1/2] [Offload] Fix debug printing for functions implemented in
headers
Signed-off-by: Sarnie, Nick <nick.sarnie at intel.com>
---
offload/include/Shared/Debug.h | 5 +++++
.../plugins-nextgen/common/include/MemoryManager.h | 11 ++++++-----
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/offload/include/Shared/Debug.h b/offload/include/Shared/Debug.h
index 7c3db8dbf119f6..f14087f5424092 100644
--- a/offload/include/Shared/Debug.h
+++ b/offload/include/Shared/Debug.h
@@ -33,6 +33,9 @@
// // 16 digits for 64bit
// (uintptr_t) ptr);
//
+// Any function that uses DEBUG_PREFIX and is implemented in a header that is
+// called by multiple plugins must be annotated with OMPTARGET_INLINE.
+//
//===----------------------------------------------------------------------===//
#ifndef OMPTARGET_SHARED_DEBUG_H
@@ -171,12 +174,14 @@ inline uint32_t getDebugLevel() {
FAILURE_MESSAGE(__VA_ARGS__); \
} \
} while (false)
+#define OMPTARGET_INLINE __attribute__((always_inline))
#else
#define DEBUGP(prefix, ...) \
{}
#define DP(...) \
{}
#define REPORT(...) FAILURE_MESSAGE(__VA_ARGS__);
+#define OMPTARGET_INLINE
#endif // OMPTARGET_DEBUG
/// Emit a message giving the user extra information about the runtime if
diff --git a/offload/plugins-nextgen/common/include/MemoryManager.h b/offload/plugins-nextgen/common/include/MemoryManager.h
index fe1989930b76ef..01d8fa664a9d29 100644
--- a/offload/plugins-nextgen/common/include/MemoryManager.h
+++ b/offload/plugins-nextgen/common/include/MemoryManager.h
@@ -70,7 +70,7 @@ class MemoryManagerTy {
}
/// Find a suitable bucket
- static int findBucket(size_t Size) {
+ OMPTARGET_INLINE static int findBucket(size_t Size) {
const size_t F = floorToPowerOfTwo(Size);
DP("findBucket: Size %zu is floored to %zu.\n", Size, F);
@@ -175,7 +175,8 @@ class MemoryManagerTy {
/// allocate directly on the device. If a \p nullptr is returned, it might
/// be because the device is OOM. In that case, it will free all unused
/// memory and then try again.
- void *allocateOrFreeAndAllocateOnDevice(size_t Size, void *HstPtr) {
+ OMPTARGET_INLINE void *allocateOrFreeAndAllocateOnDevice(size_t Size,
+ void *HstPtr) {
void *TgtPtr = allocateOnDevice(Size, HstPtr);
// We cannot get memory from the device. It might be due to OOM. Let's
// free all memory in FreeLists and try again.
@@ -213,7 +214,7 @@ class MemoryManagerTy {
/// Allocate memory of size \p Size from target device. \p HstPtr is used to
/// assist the allocation.
- void *allocate(size_t Size, void *HstPtr) {
+ OMPTARGET_INLINE void *allocate(size_t Size, void *HstPtr) {
// If the size is zero, we will not bother the target device. Just return
// nullptr directly.
if (Size == 0)
@@ -282,7 +283,7 @@ class MemoryManagerTy {
}
/// Deallocate memory pointed by \p TgtPtr
- int free(void *TgtPtr) {
+ OMPTARGET_INLINE int free(void *TgtPtr) {
DP("MemoryManagerTy::free: target memory " DPxMOD ".\n", DPxPTR(TgtPtr));
NodeTy *P = nullptr;
@@ -323,7 +324,7 @@ class MemoryManagerTy {
/// threshold and the second element represents whether user disables memory
/// manager explicitly by setting the var to 0. If user doesn't specify
/// anything, returns <0, true>.
- static std::pair<size_t, bool> getSizeThresholdFromEnv() {
+ OMPTARGET_INLINE static std::pair<size_t, bool> getSizeThresholdFromEnv() {
static UInt32Envar MemoryManagerThreshold(
"LIBOMPTARGET_MEMORY_MANAGER_THRESHOLD", 0);
>From 0a44b066f5dbcf0e02421fffbcc2f9d63ec79a22 Mon Sep 17 00:00:00 2001
From: "Sarnie, Nick" <nick.sarnie at intel.com>
Date: Fri, 11 Oct 2024 14:06:15 -0700
Subject: [PATCH 2/2] format
Signed-off-by: Sarnie, Nick <nick.sarnie at intel.com>
---
offload/plugins-nextgen/common/include/MemoryManager.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/offload/plugins-nextgen/common/include/MemoryManager.h b/offload/plugins-nextgen/common/include/MemoryManager.h
index 01d8fa664a9d29..4814e447d99600 100644
--- a/offload/plugins-nextgen/common/include/MemoryManager.h
+++ b/offload/plugins-nextgen/common/include/MemoryManager.h
@@ -176,7 +176,7 @@ class MemoryManagerTy {
/// be because the device is OOM. In that case, it will free all unused
/// memory and then try again.
OMPTARGET_INLINE void *allocateOrFreeAndAllocateOnDevice(size_t Size,
- void *HstPtr) {
+ void *HstPtr) {
void *TgtPtr = allocateOnDevice(Size, HstPtr);
// We cannot get memory from the device. It might be due to OOM. Let's
// free all memory in FreeLists and try again.
More information about the llvm-commits
mailing list