public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed][OG12] libgomp: no need to attach USM pointers
@ 2023-02-23 12:16 Andrew Stubbs
  0 siblings, 0 replies; only message in thread
From: Andrew Stubbs @ 2023-02-23 12:16 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 307 bytes --]

This patch fixes a bug in which libgomp doesn't know what to do with 
attached pointers in fortran derived types when using Unified Shared 
Memory instead of explicit mappings.

I've committed it to the devel/omp/gcc-12 branch (OG12) and will fold it 
into the next rebase/repost of the USM patches.

Andrew

[-- Attachment #2: 230223-fix-usm-attach.patch --]
[-- Type: text/plain, Size: 1720 bytes --]

libgomp: no need to attach USM pointers

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.

diff --git a/libgomp/target.c b/libgomp/target.c
index 24109f28ddc..fcc5b9dabca 100644
--- a/libgomp/target.c
+++ b/libgomp/target.c
@@ -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
index 00000000000..ff15f4ba1f5
--- /dev/null
+++ b/libgomp/testsuite/libgomp.fortran/usm-3.f90
@@ -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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-23 12:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-23 12:16 [committed][OG12] libgomp: no need to attach USM pointers Andrew Stubbs

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).