[Openmp-commits] [openmp] Fix mapping of struct to device (PR #70821)

via Openmp-commits openmp-commits at lists.llvm.org
Tue Oct 31 09:23:47 PDT 2023


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff e107c9468b9c734fba016166fccc82a7e2b6527b 3ca102766d977bf5ecadd0f3101fbf1382105eb3 -- openmp/libomptarget/test/offloading/struct_mapping_with_pointers.cpp openmp/libomptarget/src/omptarget.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/openmp/libomptarget/src/omptarget.cpp b/openmp/libomptarget/src/omptarget.cpp
index 9f7ae3107888..5b009f2d5ad9 100644
--- a/openmp/libomptarget/src/omptarget.cpp
+++ b/openmp/libomptarget/src/omptarget.cpp
@@ -586,7 +586,7 @@ int targetDataBegin(ident_t *Loc, DeviceTy &Device, int32_t ArgNum,
   for (int32_t I = 0; I < ArgNum; ++I) {
     if (NewArgTypes[I] < 0)
       continue;
-    for (int32_t J = I+1; J < ArgNum; ++J) {
+    for (int32_t J = I + 1; J < ArgNum; ++J) {
       if (Args[I] == ArgsBase[I] && Args[I] == Args[J] &&
           ArgsBase[I] == ArgsBase[J] && ArgSizes[I] == ArgSizes[J] &&
           NewArgTypes[J] >= 0) {
@@ -854,14 +854,13 @@ postProcessingTargetDataEnd(DeviceTy *Device,
     // remaining shadow pointer entries for this struct.
     const bool HasFrom = ArgType & OMP_TGT_MAPTYPE_FROM;
     if (HasFrom) {
-      Entry->foreachShadowPointerInfo(
-          [&](const ShadowPtrInfoTy &ShadowPtr) {
-            *ShadowPtr.HstPtrAddr = ShadowPtr.HstPtrVal;
-            DP("Restoring original host pointer value " DPxMOD " for host "
-               "pointer " DPxMOD "\n",
-               DPxPTR(ShadowPtr.HstPtrVal), DPxPTR(ShadowPtr.HstPtrAddr));
-            return OFFLOAD_SUCCESS;
-          });
+      Entry->foreachShadowPointerInfo([&](const ShadowPtrInfoTy &ShadowPtr) {
+        *ShadowPtr.HstPtrAddr = ShadowPtr.HstPtrVal;
+        DP("Restoring original host pointer value " DPxMOD " for host "
+           "pointer " DPxMOD "\n",
+           DPxPTR(ShadowPtr.HstPtrVal), DPxPTR(ShadowPtr.HstPtrAddr));
+        return OFFLOAD_SUCCESS;
+      });
     }
 
     // Give up the lock as we either don't need it anymore (e.g., done with
diff --git a/openmp/libomptarget/test/offloading/struct_mapping_with_pointers.cpp b/openmp/libomptarget/test/offloading/struct_mapping_with_pointers.cpp
index dc009c1478bb..4c9d5c7a23e8 100644
--- a/openmp/libomptarget/test/offloading/struct_mapping_with_pointers.cpp
+++ b/openmp/libomptarget/test/offloading/struct_mapping_with_pointers.cpp
@@ -15,12 +15,10 @@ struct Descriptor {
   int val_arr;
 };
 
-
-
 int main() {
   Descriptor dat = Descriptor();
-  dat.datum = (int *)malloc(sizeof(int)*10);
-  dat.more_datum = (int *)malloc(sizeof(int)*20);
+  dat.datum = (int *)malloc(sizeof(int) * 10);
+  dat.more_datum = (int *)malloc(sizeof(int) * 20);
   dat.xi = 3;
   dat.arr[0][0] = 1;
 
@@ -66,7 +64,8 @@ int main() {
   // CHECK: Libomptarget --> Moving 80 bytes (hst:[[MORE_DATUM_HST_PTR_BEGIN]]) -> (tgt:[[MORE_DATUM_DEVICE_PTR_BEGIN]])
   // clang-format on
 
-  #pragma omp target enter data map(to: dat.datum[:10]) map(to:dat.more_datum[:20]) map(to: dat)
+#pragma omp target enter data map(to : dat.datum[ : 10])                       \
+    map(to : dat.more_datum[ : 20]) map(to : dat)
 
   /// Checks induced by having a target region:
   // clang-format off
@@ -74,8 +73,8 @@ int main() {
   // CHECK: Libomptarget --> Mapping exists (implicit) with HstPtrBegin=[[DAT_HST_PTR_BASE]], TgtPtrBegin=[[DAT_DEVICE_PTR_BASE]], Size=288, DynRefCount=2 (incremented), HoldRefCount=0, Name=unknown
   // CHECK: Libomptarget --> Obtained target argument [[DAT_DEVICE_PTR_BASE]] from host pointer [[DAT_HST_PTR_BASE]]
   // clang-format on
- 
-  #pragma omp target
+
+#pragma omp target
   {
     dat.xi = 4;
     dat.datum[7]++;
@@ -91,7 +90,7 @@ int main() {
   // CHECK: Libomptarget --> Mapping exists with HstPtrBegin=[[DAT_HST_PTR_BASE]], TgtPtrBegin=[[DAT_DEVICE_PTR_BASE]], Size=288, DynRefCount=1 (decremented), HoldRefCount=0
   // clang-format on
 
-  #pragma omp target exit data map(from: dat)
+#pragma omp target exit data map(from : dat)
 
   /// Target data end checks:
   // clang-format off
@@ -113,5 +112,3 @@ int main() {
 
   return 0;
 }
-
-

``````````

</details>


https://github.com/llvm/llvm-project/pull/70821


More information about the Openmp-commits mailing list