[llvm] [Offload] Fix dataDelete op for TARGET_ALLOC_HOST memory type (PR #91134)
Jhonatan Cléto via llvm-commits
llvm-commits at lists.llvm.org
Tue May 7 15:30:24 PDT 2024
https://github.com/cl3to updated https://github.com/llvm/llvm-project/pull/91134
>From f5bbd9bea5d76d4cfabdbd6fcb5436f168d7440e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jhonatan=20Cl=C3=A9to?= <j256444 at dac.unicamp.br>
Date: Sun, 5 May 2024 12:14:14 -0300
Subject: [PATCH] [Offload] Fix dataDelete op for TARGET_ALLOC_HOST memory type
---
.../common/src/PluginInterface.cpp | 26 ++++++++++++++-----
offload/src/omptarget.cpp | 4 ++-
2 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/offload/plugins-nextgen/common/src/PluginInterface.cpp b/offload/plugins-nextgen/common/src/PluginInterface.cpp
index b5f3c45c835f..8de93ba17a56 100644
--- a/offload/plugins-nextgen/common/src/PluginInterface.cpp
+++ b/offload/plugins-nextgen/common/src/PluginInterface.cpp
@@ -1348,13 +1348,27 @@ Error GenericDeviceTy::dataDelete(void *TgtPtr, TargetAllocTy Kind) {
return Plugin::success();
int Res;
- if (MemoryManager)
- Res = MemoryManager->free(TgtPtr);
- else
+ switch (Kind) {
+ case TARGET_ALLOC_DEFAULT:
+ case TARGET_ALLOC_DEVICE_NON_BLOCKING:
+ case TARGET_ALLOC_DEVICE:
+ if (MemoryManager) {
+ Res = MemoryManager->free(TgtPtr);
+ if (Res)
+ return Plugin::error(
+ "Failure to deallocate device pointer %p via memory manager",
+ TgtPtr);
+ break;
+ }
+ [[fallthrough]];
+ case TARGET_ALLOC_HOST:
+ case TARGET_ALLOC_SHARED:
Res = free(TgtPtr, Kind);
-
- if (Res)
- return Plugin::error("Failure to deallocate device pointer %p", TgtPtr);
+ if (Res)
+ return Plugin::error(
+ "Failure to deallocate device pointer %p via device deallocator",
+ TgtPtr);
+ }
// Unregister deallocated pinned memory buffer if the type is host memory.
if (Kind == TARGET_ALLOC_HOST)
diff --git a/offload/src/omptarget.cpp b/offload/src/omptarget.cpp
index 803e941fe838..4ed7ce6faaf7 100644
--- a/offload/src/omptarget.cpp
+++ b/offload/src/omptarget.cpp
@@ -461,7 +461,9 @@ void targetFreeExplicit(void *DevicePtr, int DeviceNum, int Kind,
if (!DeviceOrErr)
FATAL_MESSAGE(DeviceNum, "%s", toString(DeviceOrErr.takeError()).c_str());
- DeviceOrErr->deleteData(DevicePtr, Kind);
+ if (DeviceOrErr->deleteData(DevicePtr, Kind))
+ FATAL_MESSAGE(DeviceNum, "%s", "Failed to deallocate device ptr");
+
DP("omp_target_free deallocated device ptr\n");
}
More information about the llvm-commits
mailing list