From patchwork Thu Jan 14 23:02:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cesar Philippidis X-Patchwork-Id: 567774 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id DDE711409A0 for ; Fri, 15 Jan 2016 10:02:47 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=FyuapqiG; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=E9EmlXKjmEnw/nSz7 Op6nvs8mWQPUp+AUptZQP5SZRYb9o5E7B5wBNRQ25Q312+VoCwsHjSZUVIPisZJU zLBa8N+8ZfXz/ZU/sq4pRs5G4fXydhJqIXR/7HRaszrNNSH5HpYCsbEoSXHv32z1 99Emkgq3n2kL88y/egobEA7f7k= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=gRrOu4SntBg5byvaAUDJ0gi hGVg=; b=FyuapqiGv880K8XPSu49gCWeqgQ3GVk6azk6RzNzdMrb57ifR/XF5se i2PE3Jkv0MCYTWPh15KIRglY16moHLzNqBuwnRNdZ7pEd7W/ORBmNCwBAcAETNXh V0KF8ZhDvJN/N3Tbvz+1ucCuDZmU4WbRrKjEElCf4ib7GotvcFkk= Received: (qmail 119918 invoked by alias); 14 Jan 2016 23:02:37 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 119893 invoked by uid 89); 14 Jan 2016 23:02:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=reminded, Hx-languages-length:4286 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 14 Jan 2016 23:02:34 +0000 Received: from svr-orw-fem-02x.mgc.mentorg.com ([147.34.96.206] helo=SVR-ORW-FEM-02.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1aJquS-00026Q-Oj from Cesar_Philippidis@mentor.com ; Thu, 14 Jan 2016 15:02:28 -0800 Received: from [IPv6:::1] (147.34.91.1) by svr-orw-fem-02.mgc.mentorg.com (147.34.96.168) with Microsoft SMTP Server id 14.3.224.2; Thu, 14 Jan 2016 15:02:28 -0800 Subject: Re: [openacc] implicit non-scalars data mapping in kernels To: Nathan Sidwell , Jakub Jelinek , Marek Polacek References: <5696CFC1.9060004@codesourcery.com> <20160113223508.GM25528@redhat.com> <20160113224426.GW3017@tucnak.redhat.com> <5697AE40.3010205@acm.org> CC: "gcc-patches@gcc.gnu.org" From: Cesar Philippidis Message-ID: <56982904.60507@codesourcery.com> Date: Thu, 14 Jan 2016 15:02:28 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 MIME-Version: 1.0 In-Reply-To: <5697AE40.3010205@acm.org> On 01/14/2016 06:18 AM, Nathan Sidwell wrote: > On 01/13/16 17:44, Jakub Jelinek wrote: >> On Wed, Jan 13, 2016 at 11:35:08PM +0100, Marek Polacek wrote: >>> On Wed, Jan 13, 2016 at 02:29:21PM -0800, Cesar Philippidis wrote: >>>> --- a/gcc/gimplify.c >>>> +++ b/gcc/gimplify.c >>>> @@ -5994,6 +5994,11 @@ oacc_default_clause (struct gimplify_omp_ctx >>>> *ctx, tree decl, unsigned flags) >>>> { >>>> const char *rkind; >>>> bool on_device = false; >>>> + tree type = TREE_TYPE (decl); >>>> + >>>> + if (TREE_CODE (type) == REFERENCE_TYPE >>>> + || POINTER_TYPE_P (type)) >>> >>> I think this should be just POINTER_TYPE_P--this macro checks for >>> REFERENCE_TYPE as well. >> >> Unless the spec says that for all pointers you should consider what it >> points to, this really looks weird to me. > > I think the spec is silent. I remember looking at this before and > thinking looking through pointers was strange. IMHO it should behave in > a manner as similar as possible to OpenMP (which I presume is precise > about whether one should look through arbitrary pointer types). > > Is this a case of the Fortran FE OpenACC bits not annotating some > artificial object correctly? I don't think it's specific to fortran. You can have reference types in c++ too. Actually, Jakub's comment reminded me to create a test case for c++, and it turns out that the c++ FE does not like any reference types in openacc data clauses at all. At this point, I'm reasonably confident that this issue is independent from the c++ issue. Is this patch ok for trunk? C++ support is still a work in progress, and I'll address that in a follow up patch. Cesar 2016-01-14 Cesar Philippidis gcc/ * gimplify.c (oacc_default_clause): Decode reference and pointer types for both kernels and parallel regions. libgomp/ * testsuite/libgomp.oacc-fortran/kernels-data.f90: New test. diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 17144d1..eda2e9c 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -5994,6 +5994,10 @@ oacc_default_clause (struct gimplify_omp_ctx *ctx, tree decl, unsigned flags) { const char *rkind; bool on_device = false; + tree type = TREE_TYPE (decl); + + if (lang_hooks.decls.omp_privatize_by_reference (decl)) + type = TREE_TYPE (type); if ((ctx->region_type & (ORT_ACC_PARALLEL | ORT_ACC_KERNELS)) != 0 && is_global_var (decl) @@ -6012,7 +6016,7 @@ oacc_default_clause (struct gimplify_omp_ctx *ctx, tree decl, unsigned flags) /* Scalars are default 'copy' under kernels, non-scalars are default 'present_or_copy'. */ flags |= GOVD_MAP; - if (!AGGREGATE_TYPE_P (TREE_TYPE (decl))) + if (!AGGREGATE_TYPE_P (type)) flags |= GOVD_MAP_FORCE; rkind = "kernels"; @@ -6020,12 +6024,6 @@ oacc_default_clause (struct gimplify_omp_ctx *ctx, tree decl, unsigned flags) case ORT_ACC_PARALLEL: { - tree type = TREE_TYPE (decl); - - if (TREE_CODE (type) == REFERENCE_TYPE - || POINTER_TYPE_P (type)) - type = TREE_TYPE (type); - if (on_device || AGGREGATE_TYPE_P (type)) /* Aggregates default to 'present_or_copy'. */ flags |= GOVD_MAP; diff --git a/libgomp/testsuite/libgomp.oacc-fortran/non-scalar-data.f90 b/libgomp/testsuite/libgomp.oacc-fortran/non-scalar-data.f90 new file mode 100644 index 0000000..4afb562 --- /dev/null +++ b/libgomp/testsuite/libgomp.oacc-fortran/non-scalar-data.f90 @@ -0,0 +1,50 @@ +! Ensure that a non-scalar dummy arguments which are implicitly used inside +! offloaded regions are properly mapped using present_or_copy. + +! { dg-do run } + +program main + implicit none + + integer, parameter :: n = 100 + integer :: array(n), i + + !$acc data copy(array) + call kernels(array, n) + + !$acc update host(array) + + do i = 1, n + if (array(i) .ne. i) call abort + end do + + call parallel(array, n) + !$acc end data + + do i = 1, n + if (array(i) .ne. i+i) call abort + end do +end program main + +subroutine kernels (array, n) + integer, dimension (n) :: array + integer :: n, i + + !$acc kernels + do i = 1, n + array(i) = i + end do + !$acc end kernels +end subroutine kernels + + +subroutine parallel (array, n) + integer, dimension (n) :: array + integer :: n, i + + !$acc parallel + do i = 1, n + array(i) = i+i + end do + !$acc end parallel +end subroutine parallel