From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1461) id 4BFD53858C5E; Thu, 23 Feb 2023 12:11:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4BFD53858C5E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677154319; bh=kPFWUQ9wLfBnPGhik9Ck1z+OdKdSdSOCj9Ki4tOpqzo=; h=From:To:Subject:Date:From; b=yUvKAycO1rCmNFgYFDylNYsn3j+FOSVsrochq2mVdSi0AcufwGMsz6XbjE27wL0dO /IbH7dAX/ofybz5/gFsM4C/hUEy1vK9DXJCQvp1jq4T3pKH7nWjMm5Uf/Ti0EF52dG ojwd899WKhlNPgUCT7Yfk1tI4SCKHxzXn9InfJKE= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Andrew Stubbs To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/omp/gcc-12] libgomp: no need to attach USM pointers X-Act-Checkin: gcc X-Git-Author: Andrew Stubbs X-Git-Refname: refs/heads/devel/omp/gcc-12 X-Git-Oldrev: 55a18d4744258e3909568e425f9f473c49f9d13f X-Git-Newrev: 3ad47717bf7163ed1628c829e06166a74c1e9cd3 Message-Id: <20230223121159.4BFD53858C5E@sourceware.org> Date: Thu, 23 Feb 2023 12:11:59 +0000 (GMT) List-Id: https://gcc.gnu.org/g:3ad47717bf7163ed1628c829e06166a74c1e9cd3 commit 3ad47717bf7163ed1628c829e06166a74c1e9cd3 Author: Andrew Stubbs Date: Mon Feb 20 12:23:14 2023 +0000 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: --- libgomp/ChangeLog.omp | 5 +++++ libgomp/target.c | 5 +++++ libgomp/testsuite/libgomp.fortran/usm-3.f90 | 33 +++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp index 98f046c292a..51c15697e72 100644 --- a/libgomp/ChangeLog.omp +++ b/libgomp/ChangeLog.omp @@ -1,3 +1,8 @@ +2023-02-23 Andrew Stubbs + + * target.c (gomp_attach_pointer): Check for USM. + * testsuite/libgomp.fortran/usm-3.f90: New test. + 2023-02-22 Tobias Burnus * testsuite/libgomp.fortran/target-enter-data-3.f90: Uncomment 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