]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libgomp: no need to attach USM pointers
authorAndrew Stubbs <ams@codesourcery.com>
Mon, 20 Feb 2023 12:23:14 +0000 (12:23 +0000)
committerAndrew Stubbs <ams@codesourcery.com>
Thu, 23 Feb 2023 12:00:48 +0000 (12:00 +0000)
Fix a bug in which Fortran pointers inside derived types caused a runtime
error when Unified Shared Memory was active.

libgomp/ChangeLog:

* target.c (gomp_attach_pointer): Check for USM.
* testsuite/libgomp.fortran/usm-3.f90: New test.

libgomp/ChangeLog.omp
libgomp/target.c
libgomp/testsuite/libgomp.fortran/usm-3.f90 [new file with mode: 0644]

index 98f046c292af3143c063802965bd76476657382d..51c15697e72f87c6c3e59304245d8e18de34cf9c 100644 (file)
@@ -1,3 +1,8 @@
+2023-02-23  Andrew Stubbs  <ams@codesourcery.com>
+
+       * target.c (gomp_attach_pointer): Check for USM.
+       * testsuite/libgomp.fortran/usm-3.f90: New test.
+
 2023-02-22  Tobias Burnus  <tobias@codesourcery.com>
 
        * testsuite/libgomp.fortran/target-enter-data-3.f90: Uncomment
index 24109f28ddce32c8069ac9043be69762a131b403..fcc5b9dabcab4b14749b292e0b91a0bc479d95e2 100644 (file)
@@ -836,6 +836,11 @@ gomp_attach_pointer (struct gomp_device_descr *devicep,
          gomp_fatal ("attempt to attach null pointer");
        }
 
+      if (devicep->is_usm_ptr_func
+         && devicep->is_usm_ptr_func ((void*)(target + bias)))
+       /* Nothing to do here.  */
+       return;
+
       s.host_start = target + bias;
       s.host_end = s.host_start + 1;
       tn = splay_tree_lookup (mem_map, &s);
diff --git a/libgomp/testsuite/libgomp.fortran/usm-3.f90 b/libgomp/testsuite/libgomp.fortran/usm-3.f90
new file mode 100644 (file)
index 0000000..ff15f4b
--- /dev/null
@@ -0,0 +1,33 @@
+! { dg-do run }
+! { dg-require-effective-target omp_usm }
+
+! Ensure that derived types containing allocated values work
+! with Unified Shared Memory.
+
+program usm
+!$omp requires unified_shared_memory
+  use iso_fortran_env
+  implicit none
+
+  type :: struct
+    real(real64), allocatable :: v(:)
+  end type struct
+
+  integer :: index
+  type(struct) :: s
+
+  real(real64), allocatable :: expected(:)
+
+  allocate(s%v(100))
+  do index = 1, size(s%v)
+    s%v(index) = index
+  end do
+  allocate(expected, mold=s%v)
+  expected = s%v - 1._real64
+
+  !$omp target
+  s%v = s%v - 1._real64
+  !$omp end target
+
+  if (any(s%v /= expected)) STOP 1
+end program usm