From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa4.mentor.iphmx.com (esa4.mentor.iphmx.com [68.232.137.252]) by sourceware.org (Postfix) with ESMTPS id 15B2D3856DD3; Tue, 10 May 2022 12:56:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 15B2D3856DD3 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.91,214,1647331200"; d="scan'208,223";a="75687227" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 10 May 2022 04:56:57 -0800 IronPort-SDR: zChfQYv9SHlferkScJgmWfs9vjjOoaZd+ORFV/PubXDhVmv3WNZCtIPdHmAGSB+DtKVoA6xC1W oII9wIVN0lCh910sdlDbzeNmU9D5lK4AAeIyt/HaHkIhR43GSyw9kxukmiy8HoDU0ylecXKBdK AP94B5bFucd+sYCArq679TVKW6a6VPogOh3Yd1b38vG/1mIyn7ii339WA2yR+teHqbl255rLIT eXvVuBvqLnZj1VNbsoQ9W+0SVF8HteDshWA00LkC34pdMtryhchVrlUH6x7aYum/+GxjwkykDz UDE= From: Thomas Schwinge To: Tobias Burnus , CC: , Jakub Jelinek Subject: Re: [Patch] OpenMP: Fix use_device_{addr, ptr} with in-data-sharing arg In-Reply-To: References: User-Agent: Notmuch/0.29.3+94~g74c3f1b (https://notmuchmail.org) Emacs/27.1 (x86_64-pc-linux-gnu) Date: Tue, 10 May 2022 14:56:47 +0200 Message-ID: <875ymdsfzk.fsf@euler.schwinge.homeip.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: fortran@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Fortran mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 May 2022 12:57:00 -0000 --=-=-= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Hi! On 2022-04-20T15:19:38+0200, Tobias Burnus 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 =3D &array_descr_var.data; > ... > tmp_desc =3D array_descr_var > tmp_desc.data =3D 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 =E2=80=93 but the value expression ('omp_i->array_descr_va= r'). > > Fixed by searching the variable used in use_device_{addr,ptr} in the > outer OpenMP context =E2=80=93 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(:,:,:) =3D reshape ([(i, i =3D 1, size(aaa))], shape(aaa)) > + > + do i =3D 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=C3=BC=C3=9Fe 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 =3D .false. > + !$omp target device(dev) map(to: is_shared) > + is_shared =3D .true. > + !$omp end target > + > + allocate (bbbb(-4:10,-3:8,2)) > + bbbb(:,:,:) =3D reshape ([(-i, i =3D 1, size(bbbb))], shape(bbbb)) > + !$omp target enter data map(to: bbbb) device(dev) > + if (any (lbound (aaaa) /=3D [-4, -3, 1])) error stop 1 > + if (any (shape (aaaa) /=3D [15, 12, 2])) error stop 2 > + if (any (lbound (bbbb) /=3D [-4, -3, 1])) error stop 3 > + if (any (shape (bbbb) /=3D [15, 12, 2])) error stop 4 > + if (any (aaaa /=3D -bbbb)) error stop 5 > + if (any (aaaa /=3D reshape ([(i, i =3D 1, size(aaaa))], shape(aaaa))= )) & > + error stop 6 > + > + !$omp parallel do shared(bbbb, aaaa) > + do i =3D 1,1 > + if (any (lbound (aaaa) /=3D [-4, -3, 1])) error stop 5 > + if (any (shape (aaaa) /=3D [15, 12, 2])) error stop 6 > + if (any (lbound (bbbb) /=3D [-4, -3, 1])) error stop 7 > + if (any (shape (bbbb) /=3D [15, 12, 2])) error stop 8 > + if (any (aaaa /=3D -bbbb)) error stop 5 > + if (any (aaaa /=3D reshape ([(i, i =3D 1, size(aaaa))], shape(aaaa= )))) & > + error stop 6 > + ptr =3D c_loc (aaaa) > + !$omp target data use_device_addr(bbbb, aaaa) device(dev) > + if (any (lbound (aaaa) /=3D [-4, -3, 1])) error stop 9 > + if (any (shape (aaaa) /=3D [15, 12, 2])) error stop 10 > + if (any (lbound (bbbb) /=3D [-4, -3, 1])) error stop 11 > + if (any (shape (bbbb) /=3D [15, 12, 2])) error stop 12 > + if (is_shared) then > + if (any (aaaa /=3D -bbbb)) error stop 5 > + if (any (aaaa /=3D reshape ([(i, i =3D 1, size(aaaa))], shape(= aaaa)))) & > + error stop 6 > + end if > + if (is_shared .neqv. c_associated (ptr, c_loc (aaaa))) error sto= p > + > + !$omp target has_device_addr(bbbb, aaaa) device(dev) > + if (any (lbound (aaaa) /=3D [-4, -3, 1])) error stop 9 > + if (any (shape (aaaa) /=3D [15, 12, 2])) error stop 10 > + if (any (lbound (bbbb) /=3D [-4, -3, 1])) error stop 11 > + if (any (shape (bbbb) /=3D [15, 12, 2])) error stop 12 > + if (any (aaaa /=3D -bbbb)) error stop 5 > + if (any (aaaa /=3D reshape ([(i, i =3D 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 =3D .false. > + !$omp target device(dev) map(to: is_shared) > + is_shared =3D .true. > + !$omp end target > + > + allocate (bbbb(-4:10,-3:8,2)) > + bbbb(:,:,:) =3D reshape ([(-i, i =3D 1, size(bbbb))], shape(bbbb)) > + !$omp target enter data map(to: bbbb) device(dev) > + if (any (lbound (aaaa) /=3D [-4, -3, 1])) error stop 1 > + if (any (shape (aaaa) /=3D [15, 12, 2])) error stop 2 > + if (any (lbound (bbbb) /=3D [-4, -3, 1])) error stop 3 > + if (any (shape (bbbb) /=3D [15, 12, 2])) error stop 4 > + if (any (aaaa /=3D -bbbb)) error stop 5 > + if (any (aaaa /=3D reshape ([(i, i =3D 1, size(aaaa))], shape(aaaa))= )) & > + error stop 6 > + > + !$omp parallel do shared(bbbb, aaaa) > + do i =3D 1,1 > + if (any (lbound (aaaa) /=3D [-4, -3, 1])) error stop 5 > + if (any (shape (aaaa) /=3D [15, 12, 2])) error stop 6 > + if (any (lbound (bbbb) /=3D [-4, -3, 1])) error stop 7 > + if (any (shape (bbbb) /=3D [15, 12, 2])) error stop 8 > + if (any (aaaa /=3D -bbbb)) error stop 5 > + if (any (aaaa /=3D reshape ([(i, i =3D 1, size(aaaa))], shape(aaaa= )))) & > + error stop 6 > + ptr =3D c_loc (aaaa) > + !$omp target data use_device_ptr(bbbb, aaaa) device(dev) > + if (any (lbound (aaaa) /=3D [-4, -3, 1])) error stop 9 > + if (any (shape (aaaa) /=3D [15, 12, 2])) error stop 10 > + if (any (lbound (bbbb) /=3D [-4, -3, 1])) error stop 11 > + if (any (shape (bbbb) /=3D [15, 12, 2])) error stop 12 > + if (is_shared) then > + if (any (aaaa /=3D -bbbb)) error stop 5 > + if (any (aaaa /=3D reshape ([(i, i =3D 1, size(aaaa))], shape(= aaaa)))) & > + error stop 6 > + end if > + if (is_shared .neqv. c_associated (ptr, c_loc (aaaa))) error sto= p > + > + ! 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) /=3D [-4, -3, 1])) error stop 9 > + if (any (shape (aaaa) /=3D [15, 12, 2])) error stop 10 > + if (any (lbound (bbbb) /=3D [-4, -3, 1])) error stop 11 > + if (any (shape (bbbb) /=3D [15, 12, 2])) error stop 12 > + if (any (aaaa /=3D -bbbb)) error stop 5 > + if (any (aaaa /=3D reshape ([(i, i =3D 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=C3=9Fe 201= , 80634 M=C3=BCnchen; Gesellschaft mit beschr=C3=A4nkter Haftung; Gesch=C3= =A4ftsf=C3=BChrer: Thomas Heurung, Frank Th=C3=BCrauf; Sitz der Gesellschaf= t: M=C3=BCnchen; Registergericht M=C3=BCnchen, HRB 106955 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename="0001-Fix-up-libgomp.fortran-use_device_addr-5.f90-multi-d.patch" >From 798152475559a6be8049692932cc747c6499e7f5 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge 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 --=-=-=--