libgomp – fix handling of 'target enter data'
authorTobias Burnus <tobias@codesourcery.com>
Tue, 31 Mar 2020 18:38:38 +0000 (20:38 +0200)
committerTobias Burnus <tobias@codesourcery.com>
Tue, 31 Mar 2020 18:38:38 +0000 (20:38 +0200)
* target.c (GOMP_target_enter_exit_data): Handle PSET/MAP_POINTER.
* testsuite/libgomp.fortran/target-enter-data-1.f90: New.

libgomp/ChangeLog
libgomp/target.c
libgomp/testsuite/libgomp.fortran/target-enter-data-1.f90 [new file with mode: 0644]

index 7f5a1173eb9d46670fa14f8d862957b35977fe71..6c437930b02f2205c71da53c3dd7061e99faaa0e 100644 (file)
@@ -1,3 +1,8 @@
+2020-03-31  Tobias Burnus  <tobias@codesourcery.com>
+
+       * target.c (GOMP_target_enter_exit_data): Handle PSET/MAP_POINTER.
+       * testsuite/libgomp.fortran/target-enter-data-1.f90: New.
+
 2020-03-24  Tobias Burnus  <tobias@codesourcery.com>
 
        PR libgomp/81689
index c99dd5196fab66145335d79b2bd4ebe261a4ca94..36425477dcb091f076d7a2fec11147b43d6d9919 100644 (file)
@@ -2480,7 +2480,9 @@ GOMP_target_enter_exit_data (int device, size_t mapnum, void **hostaddrs,
        }
     }
 
-  size_t i;
+  /* The variables are mapped separately such that they can be released
+     independently.  */
+  size_t i, j;
   if ((flags & GOMP_TARGET_FLAG_EXIT_DATA) == 0)
     for (i = 0; i < mapnum; i++)
       if ((kinds[i] & 0xff) == GOMP_MAP_STRUCT)
@@ -2489,6 +2491,15 @@ GOMP_target_enter_exit_data (int device, size_t mapnum, void **hostaddrs,
                         &kinds[i], true, GOMP_MAP_VARS_ENTER_DATA);
          i += sizes[i];
        }
+      else if ((kinds[i] & 0xff) == GOMP_MAP_TO_PSET)
+       {
+         for (j = i + 1; j < mapnum; j++)
+           if (!GOMP_MAP_POINTER_P (get_kind (true, kinds, j) & 0xff))
+             break;
+         gomp_map_vars (devicep, j-i, &hostaddrs[i], NULL, &sizes[i],
+                        &kinds[i], true, GOMP_MAP_VARS_ENTER_DATA);
+         i += j - i - 1;
+       }
       else
        gomp_map_vars (devicep, 1, &hostaddrs[i], NULL, &sizes[i], &kinds[i],
                       true, GOMP_MAP_VARS_ENTER_DATA);
diff --git a/libgomp/testsuite/libgomp.fortran/target-enter-data-1.f90 b/libgomp/testsuite/libgomp.fortran/target-enter-data-1.f90
new file mode 100644 (file)
index 0000000..91dedeb
--- /dev/null
@@ -0,0 +1,36 @@
+program main
+  implicit none
+  integer, allocatable, dimension(:) :: AA, BB, CC, DD
+  integer :: i, N = 20
+
+  allocate(BB(N))
+  AA = [(i, i=1,N)]
+
+  !$omp target enter data map(alloc: BB)
+  !$omp target enter data map(to: AA)
+
+  !$omp target
+    BB = 3 * AA
+  !$omp end target
+
+  !$omp target exit data map(delete: AA)
+  !$omp target exit data map(from: BB)
+
+  if (any (BB /= [(3*i, i=1,N)])) stop 1
+  if (any (AA /= [(i, i=1,N)])) stop 2
+
+
+  CC = 31 * BB
+  DD = [(-i, i=1,N)]
+
+  !$omp target enter data map(to: CC) map(alloc: DD)
+
+  !$omp target
+    DD = 5 * CC
+  !$omp end target
+
+  !$omp target exit data map(delete: CC) map(from: DD)
+
+  if (any (CC /= [(31*3*i, i=1,N)])) stop 3
+  if (any (DD /= [(31*3*5*i, i=1,N)])) stop 4
+end