Index: openmp/libomptarget/src/device.cpp =================================================================== --- openmp/libomptarget/src/device.cpp +++ openmp/libomptarget/src/device.cpp @@ -229,6 +229,14 @@ DP("Return HstPtrBegin " DPxMOD " Size=%" PRId64 " for unified shared " "memory\n", DPxPTR((uintptr_t)HstPtrBegin), Size); + + if (!PM->RTLs.NoMaps) + // even under unified_shared_memory need to check for correctness of + // use of map clauses. device pointer is same as host ptr in this case + HostDataToTargetMap.emplace( + (uintptr_t)HstPtrBase, (uintptr_t)HstPtrBegin, + (uintptr_t)HstPtrBegin + Size, (uintptr_t)HstPtrBegin, HstPtrName); + IsHostPtr = true; TargetPointer = HstPtrBegin; } @@ -367,9 +375,6 @@ int DeviceTy::deallocTgtPtr(void *HstPtrBegin, int64_t Size, bool HasCloseModifier) { - if (PM->RTLs.RequiresFlags & OMP_REQ_UNIFIED_SHARED_MEMORY && - !HasCloseModifier) - return OFFLOAD_SUCCESS; // Check if the pointer is contained in any sub-nodes. int rc; DataMapMtx.lock(); @@ -379,14 +384,17 @@ if (HT.decRefCount() == 0) { DP("Deleting tgt data " DPxMOD " of size %" PRId64 "\n", DPxPTR(HT.TgtPtrBegin), Size); - deleteData((void *)HT.TgtPtrBegin); + if (!(PM->RTLs.RequiresFlags & OMP_REQ_UNIFIED_SHARED_MEMORY && + !HasCloseModifier)) + deleteData((void *)HT.TgtPtrBegin); INFO(OMP_INFOTYPE_MAPPING_CHANGED, DeviceID, "Removing map entry with HstPtrBegin=" DPxMOD ", TgtPtrBegin=" DPxMOD ", Size=%" PRId64 ", Name=%s\n", DPxPTR(HT.HstPtrBegin), DPxPTR(HT.TgtPtrBegin), Size, (HT.HstPtrName) ? getNameFromMapping(HT.HstPtrName).c_str() : "unknown"); - HostDataToTargetMap.erase(lr.Entry); + if (!PM->RTLs.NoMaps) + HostDataToTargetMap.erase(lr.Entry); } rc = OFFLOAD_SUCCESS; } else { Index: openmp/libomptarget/src/rtl.h =================================================================== --- openmp/libomptarget/src/rtl.h +++ openmp/libomptarget/src/rtl.h @@ -116,6 +116,8 @@ int64_t RequiresFlags = OMP_REQ_UNDEFINED; + bool NoMaps; + explicit RTLsTy() = default; // Register the clauses of the requires directive. Index: openmp/libomptarget/src/rtl.cpp =================================================================== --- openmp/libomptarget/src/rtl.cpp +++ openmp/libomptarget/src/rtl.cpp @@ -77,6 +77,12 @@ return; } + // In UNIFIED_SHARED_MEMORY mode, users can disable + // map checks by setting OPENMP_DISABLE_MAPS + if (const char *NoMapsStr = getenv("OPENMP_DISABLE_MAPS")) + if (NoMapsStr) + NoMaps = std::stoi(NoMapsStr); + DP("Loading RTLs...\n"); // Attempt to open all the plugins and, if they exist, check if the interface Index: openmp/libomptarget/test/unified_shared_memory/check_maps.c =================================================================== --- /dev/null +++ openmp/libomptarget/test/unified_shared_memory/check_maps.c @@ -0,0 +1,44 @@ +// RUN: %libomptarget-compile-generic +// RUN: %libomptarget-run-fail-generic 2>&1 \ +// RUN: | %fcheck-generic + +// CHECK: Libomptarget message: explicit extension not allowed: host address specified is 0x{{.*}}, but device allocation maps to host at 0x{{.*}} +// CHECK: Libomptarget error: Call to getOrAllocTgtPtr returned null pointer (device failure or illegal mapping). +// CHECK: Libomptarget fatal error 1: failure of target construct while offloading is mandatory + +// REQUIRES: unified_shared_memory + +#include +#include + +// --------------------------------------------------------------------------- +// Various definitions copied from OpenMP RTL + +extern void __tgt_register_requires(int64_t); + +// End of definitions copied from OpenMP RTL. +// --------------------------------------------------------------------------- + +#pragma omp requires unified_shared_memory + +#define N 1024 + +int main(int argc, char *argv[]) { + int data[N]; + + // Manual registration of requires flags for Clang versions + // that do not support requires. + __tgt_register_requires(8); + + +#pragma omp target enter data map(to:data[0:N/2]) + +// extending a map under unified_shared_memory mode is prohibited +#pragma omp target enter data map(to:data[0:N]) + +#pragma omp target + { + } + + return 0; +}