From: Thomas Schwinge <thomas@codesourcery.com>
To: Tobias Burnus <tobias@codesourcery.com>, <gcc-patches@gcc.gnu.org>
Cc: <fortran@gcc.gnu.org>, Jakub Jelinek <jakub@redhat.com>
Subject: Re: [Patch] OpenMP: Fix use_device_{addr, ptr} with in-data-sharing arg
Date: Tue, 10 May 2022 14:56:47 +0200 [thread overview]
Message-ID: <875ymdsfzk.fsf@euler.schwinge.homeip.net> (raw)
In-Reply-To: <b4b56c8e-4c35-132c-1a75-0fe18ee07d71@codesourcery.com>
[-- Attachment #1: Type: text/plain, Size: 7851 bytes --]
Hi!
On 2022-04-20T15:19:38+0200, Tobias Burnus <tobias@codesourcery.com> wrote:
> For
> omp parallel shared(array_desc_var)
> the shared-variable is passed to the generated function as
> argument - and replaced by a DECL_VALUE_EXPR inside the parallel region.
>
> If inside the parallel region, a
>
> omp target data has_device_addr(array_descr_var)
>
> is used, the latter generates a
> omp_arr->array_descr_var = &array_descr_var.data;
> ...
> tmp_desc = array_descr_var
> tmp_desc.data = omp_o->array_descr_var
>
> that is: 'tmp_desc' gets assigned the original descriptor
> and only the data components is updated.
>
>
> However, if that's inside the parallel region, not 'array_descr_var'
> has to be used – but the value expression ('omp_i->array_descr_var').
>
> Fixed by searching the variable used in use_device_{addr,ptr} in the
> outer OpenMP context – and then checking for a DECL_VALUE_EXPR.
I wonder if corresponding OpenACC clause needs similar consideration --
or maybe is covered with this 'OMP_CLAUSE_USE_DEVICE_PTR',
'OMP_CLAUSE_USE_DEVICE_ADDR' handling here (haven't looked yet).
> --- /dev/null
> +++ b/libgomp/testsuite/libgomp.fortran/use_device_addr-5.f90
> @@ -0,0 +1,143 @@
> +program main
> + use omp_lib
> + implicit none
> + integer, allocatable :: aaa(:,:,:)
> + integer :: i
> +
> + allocate (aaa(-4:10,-3:8,2))
> + aaa(:,:,:) = reshape ([(i, i = 1, size(aaa))], shape(aaa))
> +
> + do i = 0, omp_get_num_devices()
> + !$omp target data map(to: aaa)
> + call test_addr (aaa, i)
> + call test_ptr (aaa, i)
> + !$omp end target data
> + end do
Pushed to master branch commit 798152475559a6be8049692932cc747c6499e7f5
"Fix up 'libgomp.fortran/use_device_addr-5.f90' multi-device testing",
see attached.
Grüße
Thomas
> + deallocate (aaa)
> +
> +contains
> +
> + subroutine test_addr (aaaa, dev)
> + use iso_c_binding
> + integer, target, allocatable :: aaaa(:,:,:), bbbb(:,:,:)
> + integer, value :: dev
> + integer :: i
> + type(c_ptr) :: ptr
> + logical :: is_shared
> +
> + is_shared = .false.
> + !$omp target device(dev) map(to: is_shared)
> + is_shared = .true.
> + !$omp end target
> +
> + allocate (bbbb(-4:10,-3:8,2))
> + bbbb(:,:,:) = reshape ([(-i, i = 1, size(bbbb))], shape(bbbb))
> + !$omp target enter data map(to: bbbb) device(dev)
> + if (any (lbound (aaaa) /= [-4, -3, 1])) error stop 1
> + if (any (shape (aaaa) /= [15, 12, 2])) error stop 2
> + if (any (lbound (bbbb) /= [-4, -3, 1])) error stop 3
> + if (any (shape (bbbb) /= [15, 12, 2])) error stop 4
> + if (any (aaaa /= -bbbb)) error stop 5
> + if (any (aaaa /= reshape ([(i, i = 1, size(aaaa))], shape(aaaa)))) &
> + error stop 6
> +
> + !$omp parallel do shared(bbbb, aaaa)
> + do i = 1,1
> + if (any (lbound (aaaa) /= [-4, -3, 1])) error stop 5
> + if (any (shape (aaaa) /= [15, 12, 2])) error stop 6
> + if (any (lbound (bbbb) /= [-4, -3, 1])) error stop 7
> + if (any (shape (bbbb) /= [15, 12, 2])) error stop 8
> + if (any (aaaa /= -bbbb)) error stop 5
> + if (any (aaaa /= reshape ([(i, i = 1, size(aaaa))], shape(aaaa)))) &
> + error stop 6
> + ptr = c_loc (aaaa)
> + !$omp target data use_device_addr(bbbb, aaaa) device(dev)
> + if (any (lbound (aaaa) /= [-4, -3, 1])) error stop 9
> + if (any (shape (aaaa) /= [15, 12, 2])) error stop 10
> + if (any (lbound (bbbb) /= [-4, -3, 1])) error stop 11
> + if (any (shape (bbbb) /= [15, 12, 2])) error stop 12
> + if (is_shared) then
> + if (any (aaaa /= -bbbb)) error stop 5
> + if (any (aaaa /= reshape ([(i, i = 1, size(aaaa))], shape(aaaa)))) &
> + error stop 6
> + end if
> + if (is_shared .neqv. c_associated (ptr, c_loc (aaaa))) error stop
> +
> + !$omp target has_device_addr(bbbb, aaaa) device(dev)
> + if (any (lbound (aaaa) /= [-4, -3, 1])) error stop 9
> + if (any (shape (aaaa) /= [15, 12, 2])) error stop 10
> + if (any (lbound (bbbb) /= [-4, -3, 1])) error stop 11
> + if (any (shape (bbbb) /= [15, 12, 2])) error stop 12
> + if (any (aaaa /= -bbbb)) error stop 5
> + if (any (aaaa /= reshape ([(i, i = 1, size(aaaa))], shape(aaaa)))) &
> + error stop 6
> + !$omp end target
> + !$omp end target data
> + end do
> + !$omp target exit data map(delete: bbbb) device(dev)
> + deallocate (bbbb)
> + end subroutine test_addr
> +
> + subroutine test_ptr (aaaa, dev)
> + use iso_c_binding
> + integer, target, allocatable :: aaaa(:,:,:), bbbb(:,:,:)
> + integer, value :: dev
> + integer :: i
> + type(c_ptr) :: ptr
> + logical :: is_shared
> +
> + is_shared = .false.
> + !$omp target device(dev) map(to: is_shared)
> + is_shared = .true.
> + !$omp end target
> +
> + allocate (bbbb(-4:10,-3:8,2))
> + bbbb(:,:,:) = reshape ([(-i, i = 1, size(bbbb))], shape(bbbb))
> + !$omp target enter data map(to: bbbb) device(dev)
> + if (any (lbound (aaaa) /= [-4, -3, 1])) error stop 1
> + if (any (shape (aaaa) /= [15, 12, 2])) error stop 2
> + if (any (lbound (bbbb) /= [-4, -3, 1])) error stop 3
> + if (any (shape (bbbb) /= [15, 12, 2])) error stop 4
> + if (any (aaaa /= -bbbb)) error stop 5
> + if (any (aaaa /= reshape ([(i, i = 1, size(aaaa))], shape(aaaa)))) &
> + error stop 6
> +
> + !$omp parallel do shared(bbbb, aaaa)
> + do i = 1,1
> + if (any (lbound (aaaa) /= [-4, -3, 1])) error stop 5
> + if (any (shape (aaaa) /= [15, 12, 2])) error stop 6
> + if (any (lbound (bbbb) /= [-4, -3, 1])) error stop 7
> + if (any (shape (bbbb) /= [15, 12, 2])) error stop 8
> + if (any (aaaa /= -bbbb)) error stop 5
> + if (any (aaaa /= reshape ([(i, i = 1, size(aaaa))], shape(aaaa)))) &
> + error stop 6
> + ptr = c_loc (aaaa)
> + !$omp target data use_device_ptr(bbbb, aaaa) device(dev)
> + if (any (lbound (aaaa) /= [-4, -3, 1])) error stop 9
> + if (any (shape (aaaa) /= [15, 12, 2])) error stop 10
> + if (any (lbound (bbbb) /= [-4, -3, 1])) error stop 11
> + if (any (shape (bbbb) /= [15, 12, 2])) error stop 12
> + if (is_shared) then
> + if (any (aaaa /= -bbbb)) error stop 5
> + if (any (aaaa /= reshape ([(i, i = 1, size(aaaa))], shape(aaaa)))) &
> + error stop 6
> + end if
> + if (is_shared .neqv. c_associated (ptr, c_loc (aaaa))) error stop
> +
> + ! Uses has_device_addr due to PR fortran/105318
> + !!$omp target is_device_ptr(bbbb, aaaa) device(dev)
> + !$omp target has_device_addr(bbbb, aaaa) device(dev)
> + if (any (lbound (aaaa) /= [-4, -3, 1])) error stop 9
> + if (any (shape (aaaa) /= [15, 12, 2])) error stop 10
> + if (any (lbound (bbbb) /= [-4, -3, 1])) error stop 11
> + if (any (shape (bbbb) /= [15, 12, 2])) error stop 12
> + if (any (aaaa /= -bbbb)) error stop 5
> + if (any (aaaa /= reshape ([(i, i = 1, size(aaaa))], shape(aaaa)))) &
> + error stop 6
> + !$omp end target
> + !$omp end target data
> + end do
> + !$omp target exit data map(delete: bbbb) device(dev)
> + deallocate (bbbb)
> + end subroutine test_ptr
> +end program main
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-up-libgomp.fortran-use_device_addr-5.f90-multi-d.patch --]
[-- Type: text/x-diff, Size: 1333 bytes --]
From 798152475559a6be8049692932cc747c6499e7f5 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Tue, 10 May 2022 14:43:56 +0200
Subject: [PATCH] Fix up 'libgomp.fortran/use_device_addr-5.f90' multi-device
testing
Fix-up for recent commit r13-116-g3f8c389fe90bf565a6221a46bb7fb745dd4c1510
"OpenMP: Fix use_device_{addr,ptr} with in-data-sharing arg", where we
currently get:
libgomp: use_device_ptr pointer wasn't mapped
FAIL: libgomp.fortran/use_device_addr-5.f90 -O execution test
libgomp/
* testsuite/libgomp.fortran/use_device_addr-5.f90: Fix up
multi-device testing.
---
libgomp/testsuite/libgomp.fortran/use_device_addr-5.f90 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libgomp/testsuite/libgomp.fortran/use_device_addr-5.f90 b/libgomp/testsuite/libgomp.fortran/use_device_addr-5.f90
index 1def70a1bc0..3124d60fe9b 100644
--- a/libgomp/testsuite/libgomp.fortran/use_device_addr-5.f90
+++ b/libgomp/testsuite/libgomp.fortran/use_device_addr-5.f90
@@ -8,7 +8,7 @@ program main
aaa(:,:,:) = reshape ([(i, i = 1, size(aaa))], shape(aaa))
do i = 0, omp_get_num_devices()
- !$omp target data map(to: aaa)
+ !$omp target data map(to: aaa) device(i)
call test_addr (aaa, i)
call test_ptr (aaa, i)
!$omp end target data
--
2.35.1
prev parent reply other threads:[~2022-05-10 12:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-20 13:19 [Patch] OpenMP: Fix use_device_{addr,ptr} " Tobias Burnus
2022-05-04 12:03 ` Jakub Jelinek
2022-05-04 16:38 ` Tobias Burnus
2022-05-10 12:56 ` Thomas Schwinge [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=875ymdsfzk.fsf@euler.schwinge.homeip.net \
--to=thomas@codesourcery.com \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=tobias@codesourcery.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).