[Openmp-commits] [PATCH] D123891: [libomptarget] Make omp_target_is_present checks storage instead of zero length array.

Ye Luo via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Fri Apr 15 20:22:38 PDT 2022


ye-luo created this revision.
Herald added a project: All.
ye-luo requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: openmp-commits, sstefan1.
Herald added a project: OpenMP.

Consider checking whether a pointer has been mapped can be achieved via omp_get_mapped_ptr.
omp_target_is_present is more needed to check whether the storage being pointed is mapped.
This restore the old behavior of omp_target_is_present before D123093 <https://reviews.llvm.org/D123093>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123891

Files:
  openmp/libomptarget/src/api.cpp
  openmp/libomptarget/test/mapping/target_implicit_partial_map.c


Index: openmp/libomptarget/test/mapping/target_implicit_partial_map.c
===================================================================
--- openmp/libomptarget/test/mapping/target_implicit_partial_map.c
+++ openmp/libomptarget/test/mapping/target_implicit_partial_map.c
@@ -13,6 +13,14 @@
 
 #pragma omp target data map(alloc: arr[50:2]) // partially mapped
   {
+    // CHECK: must present: 1
+    fprintf(stderr, "must present: %d\n",
+            omp_target_is_present(&arr[50], omp_get_default_device()));
+
+    // CHECK: should not present: 0
+    fprintf(stderr, "should not present: %d\n",
+            omp_target_is_present(&arr[0], omp_get_default_device()));
+
 #pragma omp target // would implicitly map with full size but already present
     {
       arr[50] = 5;
Index: openmp/libomptarget/src/api.cpp
===================================================================
--- openmp/libomptarget/src/api.cpp
+++ openmp/libomptarget/src/api.cpp
@@ -108,8 +108,12 @@
   DeviceTy &Device = *PM->Devices[device_num];
   bool IsLast; // not used
   bool IsHostPtr;
+  // omp_target_is_present tests whether a host pointer refers to storage that
+  // is mapped to a given device. However, due to the lack of the storage size,
+  // only check 1 byte. Cannot set size 0 which checks whether the pointer (zero
+  // lengh array) is mapped instead of the referred storage.
   TargetPointerResultTy TPR =
-      Device.getTgtPtrBegin(const_cast<void *>(ptr), 0, IsLast,
+      Device.getTgtPtrBegin(const_cast<void *>(ptr), 1, IsLast,
                             /*UpdateRefCount=*/false,
                             /*UseHoldRefCount=*/false, IsHostPtr);
   int rc = (TPR.TargetPointer != NULL);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123891.423210.patch
Type: text/x-patch
Size: 1705 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20220416/7351122c/attachment-0001.bin>


More information about the Openmp-commits mailing list