From patchwork Tue Jun 16 22:39:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Brown X-Patchwork-Id: 1310766 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49mjny6V0nz9sSc for ; Wed, 17 Jun 2020 08:40:22 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0B5E5388F077; Tue, 16 Jun 2020 22:40:10 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id 36221383E82C; Tue, 16 Jun 2020 22:40:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 36221383E82C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Julian_Brown@mentor.com IronPort-SDR: 0K1auYXV4EseN8Q6PJ4iKHFSwJ7WLAr/4mXLp2xxng1K0CFE6z3eIn+b0aZri3+5n5T22DAX00 B3nhwkHCd1F5IjB0RpVqpvHnR/3mwyZKAGkADAqxIqAuBpOqL36sXKHQ2AuE86qE7R5ExKa+28 ZXQqP7JiiQMPI5nLD++zPQ07siVROC4P1vgcPB0m2kZKGjJYT35qMRd70klDREqOXbjFbQNVdp nneYKM1FUtKytRKDBzn0DTCImgEOYyKFpcqT8OXBaUlPAZ0UjFF0jdCAD84iXu8yCOrtZKH8Nx XZM= X-IronPort-AV: E=Sophos;i="5.73,520,1583222400"; d="scan'208";a="49874503" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 16 Jun 2020 14:40:06 -0800 IronPort-SDR: AZo0T8b9HJ2aUHXnp4fprZZfMttmvkXwh0rVmcxXiorw9IBZ+Xot6Bky05/Rpqn+fGLg5Cp269 Th1tHql828rP4Cuyz9nTfToXBoovnk5gFwuVfUMJcoraMCWWGlIKFV9rUqX1tkjOcmUSCRlfUe Q8RgV8oAClrK4Nyt0EMrZm4Q+6ZBpbvMTiyVY1/APxbjAtQq1A54boLrEUEKXIINpUkAl+WQFS pKhyiatmh9RMgDMHD+xbdlvCbismFxyYQrkHn2YASYwefyI0StHtHyaisd298BrAiJycHlwzp8 V7M= From: Julian Brown To: Subject: [PATCH 8/9] [OpenACC] Fix standalone attach for Fortran assumed-shape array pointers Date: Tue, 16 Jun 2020 15:39:44 -0700 Message-ID: <0193ff08d4a4a2b6ca86c7a891b8ff35203fa440.1592343757.git.julian@codesourcery.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-02.mgc.mentorg.com (139.181.222.2) To SVR-IES-MBX-03.mgc.mentorg.com (139.181.222.3) X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jakub Jelinek , Tobias Burnus , "Moore, Catherine" , Thomas Schwinge , fortran@gcc.gnu.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" As mentioned in the blurb for the previous patch, an "attach" operation for a Fortran pointer with an array descriptor must copy that array descriptor to the target. This patch arranges for that to be so. OK? Julian ChangeLog gcc/fortran/ * trans-openmp.c (gfc_trans_omp_clauses): Copy array descriptor to target for attach clauses when appropriate. libgomp/ * testsuite/libgomp.oacc-fortran/attach-descriptor-1.f90: New test. --- gcc/fortran/trans-openmp.c | 40 ++++++++++++++- .../attach-descriptor-1.f90 | 51 +++++++++++++++++++ 2 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 libgomp/testsuite/libgomp.oacc-fortran/attach-descriptor-1.f90 diff --git a/gcc/fortran/trans-openmp.c b/gcc/fortran/trans-openmp.c index 02c40fdc660..909a86795e0 100644 --- a/gcc/fortran/trans-openmp.c +++ b/gcc/fortran/trans-openmp.c @@ -2573,8 +2573,44 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses, } } if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl)) - && n->u.map_op != OMP_MAP_ATTACH - && n->u.map_op != OMP_MAP_DETACH) + && (n->u.map_op == OMP_MAP_ATTACH + || n->u.map_op == OMP_MAP_DETACH)) + { + tree type = TREE_TYPE (decl); + tree data = gfc_conv_descriptor_data_get (decl); + if (present) + data = gfc_build_cond_assign_expr (block, present, + data, + null_pointer_node); + tree ptr + = fold_convert (build_pointer_type (char_type_node), + data); + ptr = build_fold_indirect_ref (ptr); + /* Standalone attach clauses used with arrays with + descriptors must copy the descriptor to the target, + else they won't have anything to perform the + attachment onto (see OpenACC 2.6, "2.6.3. Data + Structures with Pointers"). */ + OMP_CLAUSE_DECL (node) = ptr; + node2 = build_omp_clause (input_location, OMP_CLAUSE_MAP); + OMP_CLAUSE_SET_MAP_KIND (node2, GOMP_MAP_TO_PSET); + OMP_CLAUSE_DECL (node2) = decl; + OMP_CLAUSE_SIZE (node2) = TYPE_SIZE_UNIT (type); + node3 = build_omp_clause (input_location, OMP_CLAUSE_MAP); + if (n->u.map_op == OMP_MAP_ATTACH) + { + OMP_CLAUSE_SET_MAP_KIND (node3, GOMP_MAP_ATTACH); + n->u.map_op = OMP_MAP_ALLOC; + } + else /* OMP_MAP_DETACH. */ + { + OMP_CLAUSE_SET_MAP_KIND (node3, GOMP_MAP_DETACH); + n->u.map_op = OMP_MAP_RELEASE; + } + OMP_CLAUSE_DECL (node3) = data; + OMP_CLAUSE_SIZE (node3) = size_int (0); + } + else if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl))) { tree type = TREE_TYPE (decl); tree ptr = gfc_conv_descriptor_data_get (decl); diff --git a/libgomp/testsuite/libgomp.oacc-fortran/attach-descriptor-1.f90 b/libgomp/testsuite/libgomp.oacc-fortran/attach-descriptor-1.f90 new file mode 100644 index 00000000000..2dd1a6fa5b6 --- /dev/null +++ b/libgomp/testsuite/libgomp.oacc-fortran/attach-descriptor-1.f90 @@ -0,0 +1,51 @@ +program att + use openacc + implicit none + type t + integer :: arr1(10) + integer, allocatable :: arr2(:) + end type t + integer :: i + type(t) :: myvar + integer, target :: tarr(10) + integer, pointer :: myptr(:) + + allocate(myvar%arr2(10)) + + do i=1,10 + myvar%arr1(i) = 0 + myvar%arr2(i) = 0 + tarr(i) = 0 + end do + + call acc_copyin(myvar) + call acc_copyin(myvar%arr2) + call acc_copyin(tarr) + + myptr => tarr + + !$acc enter data attach(myvar%arr2, myptr) + + ! FIXME: This warning is emitted on the wrong line number. + ! { dg-warning "using vector_length \\(32\\), ignoring 1" "" { target openacc_nvidia_accel_selected } 36 } + !$acc serial present(myvar%arr2) + do i=1,10 + myvar%arr1(i) = i + myvar%arr2(i) = i + end do + myptr(3) = 99 + !$acc end serial + + !$acc exit data detach(myvar%arr2, myptr) + + call acc_copyout(myvar%arr2) + call acc_copyout(myvar) + call acc_copyout(tarr) + + do i=1,10 + if (myvar%arr1(i) .ne. i) stop 1 + if (myvar%arr2(i) .ne. i) stop 2 + end do + if (tarr(3) .ne. 99) stop 3 + +end program att