From patchwork Wed Jan 13 22:29:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cesar Philippidis X-Patchwork-Id: 567147 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 44CEE1402EC for ; Thu, 14 Jan 2016 09:29:35 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=LzoyXdRH; 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:from :subject:to:message-id:date:mime-version:content-type; q=dns; s= default; b=QFUiTUBPIjOOHN6hMiGcyaXsCH4/ZY6N5m80C+mQb2sw0LKZCNhox 8P3wHC0VsEdvMIY5lgjO3Q5NGfZjUKjFKVf0LFgaJUmgqt2kxqkOHRbR+yDZ3ZOE fkHKrsdyjJbJvP7pMbK1Mr7mIM0mjTX01kUqp6U7mmfqtMD5Nz+4Zc= 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:from :subject:to:message-id:date:mime-version:content-type; s= default; bh=LImfQaua0VGqyWvtMqxf6/SpWbE=; b=LzoyXdRH0Uu8mt1mvFpR urMglFhXi3axiUnLHay5+qkb7iD7uh8Qx59exg/U8i5xS/zLw2rxyFJGqQ1eojV5 q79vyYPhNa6ybELGwh2TdxLzGXrSEy8uPfb3R/IMAaMCVcDP2vTD6ySwe2bh13yE LnwE95LtubOGIEPLu6h4DfA= Received: (qmail 78570 invoked by alias); 13 Jan 2016 22:29:28 -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 78559 invoked by uid 89); 13 Jan 2016 22:29:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.1 required=5.0 tests=AWL, BAYES_05, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=is_global_var, sk:aggrega, sk:!AGGREG, sk:AGGREGA 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; Wed, 13 Jan 2016 22:29:26 +0000 Received: from svr-orw-fem-03.mgc.mentorg.com ([147.34.97.39]) by relay1.mentorg.com with esmtp id 1aJTur-0004za-V3 from Cesar_Philippidis@mentor.com ; Wed, 13 Jan 2016 14:29:22 -0800 Received: from [IPv6:::1] (147.34.91.1) by svr-orw-fem-03.mgc.mentorg.com (147.34.97.39) with Microsoft SMTP Server id 14.3.224.2; Wed, 13 Jan 2016 14:29:21 -0800 From: Cesar Philippidis Subject: [openacc] implicit non-scalars data mapping in kernels To: "gcc-patches@gcc.gnu.org" , Nathan Sidwell , Jakub Jelinek Message-ID: <5696CFC1.9060004@codesourcery.com> Date: Wed, 13 Jan 2016 14:29:21 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 MIME-Version: 1.0 This patch fixes a bug where the implicit data mapping for "non-scalar" variables in acc kernels regions uses a copy clause instead of a present_or_copy when the variable is a reference type. This situation can arise in fortran, when a dummy array is used inside a kernels region. I noticed that there was already code in place to handle pointer types for parallel data mappings, so in this patch I moved that type extraction earlier so that both kernels and parallel regions can use it. Is this patch ok for trunk? Thanks, Cesar 2016-01-13 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..bc0715b 100644 --- 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)) + type = TREE_TYPE (type); if ((ctx->region_type & (ORT_ACC_PARALLEL | ORT_ACC_KERNELS)) != 0 && is_global_var (decl) @@ -6012,7 +6017,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 +6025,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/kernels-data.f90 b/libgomp/testsuite/libgomp.oacc-fortran/kernels-data.f90 new file mode 100644 index 0000000..bf812b6 --- /dev/null +++ b/libgomp/testsuite/libgomp.oacc-fortran/kernels-data.f90 @@ -0,0 +1,30 @@ +! Ensure that a non-scalar dummy argument which is implicitly used in a +! kernels regions is 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 data(array, n) + !$acc end data + + do i = 1, n + if (array(i) .ne. i) call abort + end do +end program main + +subroutine data (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 data