From patchwork Tue Jun 13 15:52:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chung-Lin Tang X-Patchwork-Id: 107441 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp647496vqr; Tue, 13 Jun 2023 08:53:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ60J4PH0Pe/a/4s3RUl3wWI9QVjQ0SvuHkC+Qx+LBB91zWGWdkd7BhSHQRvrC4G0VX85+yE X-Received: by 2002:aa7:c2d6:0:b0:518:7a95:811 with SMTP id m22-20020aa7c2d6000000b005187a950811mr941090edp.22.1686671611780; Tue, 13 Jun 2023 08:53:31 -0700 (PDT) Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id b7-20020a056402138700b00514b1f2da27si7191094edv.222.2023.06.13.08.53.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 08:53:31 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=x0gbS+sS; arc=fail (signature failed); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4FFE0385828E for ; Tue, 13 Jun 2023 15:53:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4FFE0385828E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686671608; bh=nfdZZw2ydqUh9x4oUG7em2eeTVGU/nCdSd9gXoM3NYg=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=x0gbS+sSS0YlZooqyRkeP/dA3F7EVjSb7ps3H3zgzrNEr8NNCmYr36QwzdYXAOEov wO+k7GecgR+aAr+sAoJXaCuqZrICxFcIE2W7MX2X1KnhA5ZRNpw3/GH4qVFdbNPhUa rbwprKyl4AnqbPYzN0PX6EvqqIJBHnr5kr1nhSOM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2059.outbound.protection.outlook.com [40.107.255.59]) by sourceware.org (Postfix) with ESMTPS id E1D583858D38 for ; Tue, 13 Jun 2023 15:52:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E1D583858D38 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TvJyOiHfwLKax4BNElhje1EWqweSzdZRN3yW0CMlc5Jkgv5XGykECLapDgB0rATEtznnvUYVCmrk7HMxZsYRv9nDuZtUMyJgiEvyB5tWGsN5c2QMGq0MG9vKyk7tPpNZM65p0IFvoo5fwAtY1ZMf6OYdlTNjj26lU1PpIQysBDo0noPTPoubRZZCr+eZSo42E8DvVNpjvHMnJnh76G+jl+EFusqroBeEIfUhpk2/o5OHbmTFrB76uADzk6xM2MEKQoUZs2WZLwG32nVNxk9axaOnJUf+0tbIF0sT0i1ATt9UNlJhLhxDHl7lfQIb9vZpPS31ZEYiiTASG7nA5ya9tA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=nfdZZw2ydqUh9x4oUG7em2eeTVGU/nCdSd9gXoM3NYg=; b=S2WwzLEGoJwIT0CvHH+B3ZT9hiL/4yg7IBDAPNLFORU00Wq5sy24n2gpGhzajzmiTwkU/weL/XUX1HgUTPKOFfLjbjtnh4vB3f9pAd5SNZTp/41rZWjKYWdmc+QcFf9jdfHTmW34CtdAtOQpSRlc2rWLe+/gzXX0GM5GTdVWsQYgowFbiUVBR66DgHR2HiQxFU9/tiHgkZJoH0hkydf19bXi1N+D4mrQmaIkIjo2Q1sPkVoXgUrE8E3J/ciOSUYPf0HzdLxKkS6fXhyvTs/aeeazTrzhw0Co17ho2ppStcuLK2IrCzgqgEBhlR+FxMjQam9T4YBf5HhAD4Jpr2VL+g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=siemens.com; dmarc=pass action=none header.from=siemens.com; dkim=pass header.d=siemens.com; arc=none Received: from SG2PR06MB5430.apcprd06.prod.outlook.com (2603:1096:4:1ba::14) by SG2PR06MB5081.apcprd06.prod.outlook.com (2603:1096:4:1c8::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.29; Tue, 13 Jun 2023 15:52:30 +0000 Received: from SG2PR06MB5430.apcprd06.prod.outlook.com ([fe80::d15a:aa6e:dd53:4fc5]) by SG2PR06MB5430.apcprd06.prod.outlook.com ([fe80::d15a:aa6e:dd53:4fc5%3]) with mapi id 15.20.6455.030; Tue, 13 Jun 2023 15:52:29 +0000 Message-ID: Date: Tue, 13 Jun 2023 23:52:25 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.11.2 Content-Language: en-US Subject: [PATCH, OpenACC 2.7] Implement self clause for compute constructs To: gcc-patches , Thomas Schwinge , Catherine Moore X-ClientProxiedBy: TYCP286CA0281.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:3c9::14) To SG2PR06MB5430.apcprd06.prod.outlook.com (2603:1096:4:1ba::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SG2PR06MB5430:EE_|SG2PR06MB5081:EE_ X-MS-Office365-Filtering-Correlation-Id: 1abad398-c258-47c1-6f9e-08db6c263094 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AHgbqdNRmNpfTUnAO7BPV2n3496D2pKK1VnKE2iJGHqe/wBVEOF+KMeQcxwxu8I2P8cYN6QrvCoOCd4i2sldGR6JaECT0Z/0ahzBGnNVjI3b1tLP+qBt+cuN2L59wg4nsC4KKWMdZxcrLhorDZw/h9egBPWuVCP8CvMapKXehyH5wQO78N676w8H+c5AWorGBBwZIFnANlvhNiPfpXPLQMaTf7Os7vdXza5sxL1xc6S8mugHXFazejiXqJea5WHNM3g0QAkiKCRm71uOdpT6ZMLlpZC6tldgZ2qPtRWipXIp9ZqBMoOHZSvSwc0PSfLlvVshkOHulYG10S9c9vYzSFd5O9OQ2dgMVi1bphc/siB0T585KV80tjNJE32edM0vRq4vYMp6e9Lxe4c1MMkwoL98ZEEVFv9USvjqGk+2eoLAVlN1+0ArS6gAAAl5yEjbla/URW4j5sdn+9KkcBlYqS4fu0lVIONNkaapaiFrST0zuvknycuzLUeOOdLk+Zn1VfzCX0yDl43B3RMEO2/z28QVL6jRfGQz1JSGF/JbKFGX5wTcoWKHkyhQ/Jjku3qaV63m5LdVhLh/AEiTWo4cIxP8pk37rdgNXRODxI4cKOHkHQ+rq9D5EEJPHH84rsFXrYNaukx7LwWdyzHw+BstlA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SG2PR06MB5430.apcprd06.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(4636009)(39860400002)(366004)(346002)(136003)(376002)(396003)(451199021)(66946007)(66476007)(66556008)(478600001)(110136005)(5660300002)(8676002)(8936002)(36756003)(235185007)(6666004)(84970400001)(31686004)(316002)(33964004)(41300700001)(6486002)(38100700002)(82960400001)(186003)(6506007)(86362001)(2906002)(26005)(2616005)(31696002)(6512007)(43740500002)(45980500001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?x4sSQeBf2VS6DB/a4Utzbt8pZB/V?= =?utf-8?q?v3quK7bzujsU92uVuZlpUa8eowC3NcSEwCEIPKk0EO6IhnYfp3YyEa0+s5LoMimJ4?= =?utf-8?q?Kur3DHEMqGlejraI/4VBs4+OKhBdXWrCQRGxhhgZIOUPm+0bwCn9ywwoncIjOcja0?= =?utf-8?q?MbNWYxXKzIo54WHu27HBAOSzCoYkMX/zzGyXD9lBwPKjbZxTXIuAdLgoqWwZZ2POd?= =?utf-8?q?bTPdR30qSTAme3BKK5ul0BxO96rEeqsPwTDCDENJNzBlNvQ90/QpEKiDCLadvdjd7?= =?utf-8?q?39+LLfNHVKkUAtHR50SIK07g++0ldkIruoQ1CwhdJRvbKdEnGCmUydsqjPsOqJuRH?= =?utf-8?q?nOj9h3XQnX1rVx3i7ZgMvkzpqrJcQ5mIEWMStKMomdLjUfN35uls3eKexqIP4G0FT?= =?utf-8?q?ccLsOjfBAfu5Kt7k5gDlFnkktFiFb0fFm2IDJEu4DdnEsQkpYMmCXqQkxxDfCDKlo?= =?utf-8?q?4Q/Y8llAMQzQnInMQeZWrERHR5+UxcpBONrT6n2FCZqsT8zGCX6tVqTgogdgB9Khr?= =?utf-8?q?iLGCReSopitmw6AfpVrJBfm7gbLmTAgmAqSBckdQahwqBZv10BOaSgc4YKs9R3XNZ?= =?utf-8?q?feJneer06YDuoagR6FvIXDIgdCYQzCQRHq9kv1Iyvg3BhCP6A5vp9d8SUd73JoXYC?= =?utf-8?q?6U/7lTrxobk+nRzNdQLrNR/hed/Mrf98iHN6KCP5EQvMROibPqZMZQtfIL/pCjGCb?= =?utf-8?q?RCjJVZJ9czTLqGfZTDXoohLSQi6w4cKkSMtks43H4MasrMG35yJ1A6nTd7z399L74?= =?utf-8?q?iPftdcGc7W0PPcbWy7NzgplF67lVmuM9sBq3iT9fKH5Z0BGSjx/s+9wMxC4KN5s0c?= =?utf-8?q?YSudYa2iGW6l6sdfcJteLoQxhW9E4rDv0FlmzhXByACP29SCK3h3kRuBh5qoLO/Zc?= =?utf-8?q?tpsX18qfmfW8zGCqbTrNCuC8IWRBeQ5o7NO6Y13xrVVbJR9ueNDRwdmkrDWVZn5Bt?= =?utf-8?q?WRoZzYXEYdXRub9lW7Ph8p1pgPD1CgzAzXz8l2KLsDvprCGE6LyPv6P8vx2ZVHqoc?= =?utf-8?q?xlZTU6ZmwThXRDHq2CEmRGYDbCKgWrY+3BTXQ6jkI+2LsWAkvZ0V/yv0dOAlbaUJ+?= =?utf-8?q?5TBPP7RDGq6mRdoeNBSvgER+yhyBVN9wxTn80sB0nKGJBUoE9+BwSadzuX2tv56L8?= =?utf-8?q?XmnthfBmHC4R4zNgvdcuKuah6hAHkuVXJ92uJHz4u+z1/1D4PJChhx1B7VP8Rg27O?= =?utf-8?q?b24y2m9Yx230S457SgLKWh0m5sNXAAmEM66dXMHhNLgZf/DecYMlYdpw7SH3B/Ojh?= =?utf-8?q?pxVQaztBU6cVpUSyg+LQHB3aLEDuNOHM8aJ24vpVO5Hn8plSqwuX6T4RtkWWKVoHp?= =?utf-8?q?tCrysPU06MTdOmYQkcOVbu4dHvfrO43ZnBHW9wAeNFMploeAPIw/Tj7b0T5D8/n70?= =?utf-8?q?Q2Y9YfdQTa7LALYhB6bps5ZAwolzaV81J+A1V1CfkMmrMvJs4XOHTsTcEE1pTAiN9?= =?utf-8?q?/eqDpIkB5SoNMCgN4hW2/u36dem9nxwr1vvwJEW+kf30BkO0MYt7XDwSaH1LCl9gz?= =?utf-8?q?5Y6enmteHf/9Na0ZqGks2zCcxdB0gqFchQ=3D=3D?= X-OriginatorOrg: siemens.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1abad398-c258-47c1-6f9e-08db6c263094 X-MS-Exchange-CrossTenant-AuthSource: SG2PR06MB5430.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2023 15:52:28.8232 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 38ae3bcd-9579-4fd4-adda-b42e1495d55a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 1+R4SHxaUJ//GjAQetNnIfxai9koO32yPWDR0rbltoKea2+o15/La9O6KeCsxwmcUMhip4qCRTESNrUNyBuwqpLTbg9fLdRLf8r7X5yfM2I= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SG2PR06MB5081 X-Spam-Status: No, score=-9.1 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FORGED_SPF_HELO, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: , X-Patchwork-Original-From: Chung-Lin Tang via Gcc-patches From: Chung-Lin Tang Reply-To: cltang@codesourcery.com Cc: Chung-Lin Tang Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768603371606299964?= X-GMAIL-MSGID: =?utf-8?q?1768603371606299964?= Hi Thomas, This patch implements the compiler side for the 'self' clause for compute constructs: parallel, kernels, and serial. As you know, the actual "local device" device type for libgomp is not yet implemented, so the libgomp side is basically just a simple duplicate of what host-fallback is doing, though everything else should be completed by this patch. Tested on powerpc64le-linux/nvptx, x64_64-linux/amdgcn tests pending. Is this okay for trunk? Thanks, Chung-Lin 2023-06-13 Chung-Lin Tang gcc/c/ChangeLog: * c-parser.cc (c_parser_oacc_compute_clause_self): New function. (c_parser_oacc_all_clauses): Add new 'bool compute_p = false' parameter, add parsing of self clause when compute_p is true. (OACC_KERNELS_CLAUSE_MASK): Add PRAGMA_OACC_CLAUSE_SELF. (OACC_PARALLEL_CLAUSE_MASK): Likewise, (OACC_SERIAL_CLAUSE_MASK): Likewise. (c_parser_oacc_compute): Adjust call to c_parser_oacc_all_clauses to set compute_p argument to true. * c-typeck.cc (c_finish_omp_clauses): Add OMP_CLAUSE_SELF case. gcc/cp/ChangeLog: * parser.cc (cp_parser_oacc_compute_clause_self): New function. (cp_parser_oacc_all_clauses): Add new 'bool compute_p = false' parameter, add parsing of self clause when compute_p is true. (OACC_KERNELS_CLAUSE_MASK): Add PRAGMA_OACC_CLAUSE_SELF. (OACC_PARALLEL_CLAUSE_MASK): Likewise, (OACC_SERIAL_CLAUSE_MASK): Likewise. (cp_parser_oacc_compute): Adjust call to c_parser_oacc_all_clauses to set compute_p argument to true. * pt.cc (tsubst_omp_clauses): Add OMP_CLAUSE_SELF case. * c-typeck.cc (c_finish_omp_clauses): Add OMP_CLAUSE_SELF case, merged with OMP_CLAUSE_IF case. gcc/fortran/ChangeLog: * gfortran.h (typedef struct gfc_omp_clauses): Add self_expr field. * openmp.cc (enum omp_mask2): Add OMP_CLAUSE_SELF. (gfc_match_omp_clauses): Add handling for OMP_CLAUSE_SELF. (OACC_PARALLEL_CLAUSES): Add OMP_CLAUSE_SELF. (OACC_KERNELS_CLAUSES): Likewise. (OACC_SERIAL_CLAUSES): Likewise. (resolve_omp_clauses): Add handling for omp_clauses->self_expr. * trans-openmp.cc (gfc_trans_omp_clauses): Add handling of clauses->self_expr and building of OMP_CLAUSE_SELF tree clause. (gfc_split_omp_clauses): Add handling of self_expr field copy. gcc/ChangeLog: * gimplify.cc (gimplify_scan_omp_clauses): Add OMP_CLAUSE_SELF case. (gimplify_adjust_omp_clauses): Likewise. * omp-expand.cc (expand_omp_target): Add OMP_CLAUSE_SELF expansion code, * omp-low.cc (scan_sharing_clauses): Add OMP_CLAUSE_SELF case. * tree-core.h (enum omp_clause_code): Add OMP_CLAUSE_SELF enum. * tree-nested.cc (convert_nonlocal_omp_clauses): Add OMP_CLAUSE_SELF case. (convert_local_omp_clauses): Likewise. * tree-pretty-print.cc (dump_omp_clause): Add OMP_CLAUSE_SELF case. * tree.cc (omp_clause_num_ops): Add OMP_CLAUSE_SELF entry. (omp_clause_code_name): Likewise. * tree.h (OMP_CLAUSE_SELF_EXPR): New macro. gcc/testsuite/ChangeLog: * c-c++-common/goacc/self-clause-1.c: New test. * c-c++-common/goacc/self-clause-2.c: New test. * gfortran.dg/goacc/self.f95: New test. include/ChangeLog: * gomp-constants.h (GOACC_FLAG_LOCAL_DEVICE): New flag bit value. libgomp/ChangeLog: * oacc-parallel.c (GOACC_parallel_keyed): Add code to handle GOACC_FLAG_LOCAL_DEVICE case. * testsuite/libgomp.oacc-c-c++-common/self-1.c: New test. From 449883981c8e1f707b47ff8f8dd70049b9ffda82 Mon Sep 17 00:00:00 2001 From: Chung-Lin Tang Date: Tue, 13 Jun 2023 08:44:31 -0700 Subject: [PATCH] OpenACC 2.7: Implement self clause for compute constructs This patch implements the 'self' clause for compute constructs: parallel, kernels, and serial. This clause conditionally uses the local device (the host mult-core CPU) as the executing device of the compute region. The actual implementation of the "local device" device type inside libgomp (presumably using pthreads) is still not yet completed, so the libgomp side is still implemented the exact same as host-fallback mode. (so as of now, it essentially behaves like the 'if' clause with the condition inverted) gcc/c/ChangeLog: * c-parser.cc (c_parser_oacc_compute_clause_self): New function. (c_parser_oacc_all_clauses): Add new 'bool compute_p = false' parameter, add parsing of self clause when compute_p is true. (OACC_KERNELS_CLAUSE_MASK): Add PRAGMA_OACC_CLAUSE_SELF. (OACC_PARALLEL_CLAUSE_MASK): Likewise, (OACC_SERIAL_CLAUSE_MASK): Likewise. (c_parser_oacc_compute): Adjust call to c_parser_oacc_all_clauses to set compute_p argument to true. * c-typeck.cc (c_finish_omp_clauses): Add OMP_CLAUSE_SELF case. gcc/cp/ChangeLog: * parser.cc (cp_parser_oacc_compute_clause_self): New function. (cp_parser_oacc_all_clauses): Add new 'bool compute_p = false' parameter, add parsing of self clause when compute_p is true. (OACC_KERNELS_CLAUSE_MASK): Add PRAGMA_OACC_CLAUSE_SELF. (OACC_PARALLEL_CLAUSE_MASK): Likewise, (OACC_SERIAL_CLAUSE_MASK): Likewise. (cp_parser_oacc_compute): Adjust call to c_parser_oacc_all_clauses to set compute_p argument to true. * pt.cc (tsubst_omp_clauses): Add OMP_CLAUSE_SELF case. * c-typeck.cc (c_finish_omp_clauses): Add OMP_CLAUSE_SELF case, merged with OMP_CLAUSE_IF case. gcc/fortran/ChangeLog: * gfortran.h (typedef struct gfc_omp_clauses): Add self_expr field. * openmp.cc (enum omp_mask2): Add OMP_CLAUSE_SELF. (gfc_match_omp_clauses): Add handling for OMP_CLAUSE_SELF. (OACC_PARALLEL_CLAUSES): Add OMP_CLAUSE_SELF. (OACC_KERNELS_CLAUSES): Likewise. (OACC_SERIAL_CLAUSES): Likewise. (resolve_omp_clauses): Add handling for omp_clauses->self_expr. * trans-openmp.cc (gfc_trans_omp_clauses): Add handling of clauses->self_expr and building of OMP_CLAUSE_SELF tree clause. (gfc_split_omp_clauses): Add handling of self_expr field copy. gcc/ChangeLog: * gimplify.cc (gimplify_scan_omp_clauses): Add OMP_CLAUSE_SELF case. (gimplify_adjust_omp_clauses): Likewise. * omp-expand.cc (expand_omp_target): Add OMP_CLAUSE_SELF expansion code, * omp-low.cc (scan_sharing_clauses): Add OMP_CLAUSE_SELF case. * tree-core.h (enum omp_clause_code): Add OMP_CLAUSE_SELF enum. * tree-nested.cc (convert_nonlocal_omp_clauses): Add OMP_CLAUSE_SELF case. (convert_local_omp_clauses): Likewise. * tree-pretty-print.cc (dump_omp_clause): Add OMP_CLAUSE_SELF case. * tree.cc (omp_clause_num_ops): Add OMP_CLAUSE_SELF entry. (omp_clause_code_name): Likewise. * tree.h (OMP_CLAUSE_SELF_EXPR): New macro. gcc/testsuite/ChangeLog: * c-c++-common/goacc/self-clause-1.c: New test. * c-c++-common/goacc/self-clause-2.c: New test. * gfortran.dg/goacc/self.f95: New test. include/ChangeLog: * gomp-constants.h (GOACC_FLAG_LOCAL_DEVICE): New flag bit value. libgomp/ChangeLog: * oacc-parallel.c (GOACC_parallel_keyed): Add code to handle GOACC_FLAG_LOCAL_DEVICE case. * testsuite/libgomp.oacc-c-c++-common/self-1.c: New test. --- gcc/c/c-parser.cc | 60 +- gcc/c/c-typeck.cc | 1 + gcc/cp/parser.cc | 64 +- gcc/cp/pt.cc | 1 + gcc/cp/semantics.cc | 5 +- gcc/fortran/gfortran.h | 1 + gcc/fortran/openmp.cc | 39 +- gcc/fortran/trans-openmp.cc | 18 + gcc/gimplify.cc | 2 + gcc/omp-expand.cc | 41 + gcc/omp-low.cc | 2 + .../c-c++-common/goacc/self-clause-1.c | 22 + .../c-c++-common/goacc/self-clause-2.c | 17 + gcc/testsuite/gfortran.dg/goacc/self.f95 | 53 + gcc/tree-core.h | 3 + gcc/tree-nested.cc | 2 + gcc/tree-pretty-print.cc | 7 +- gcc/tree.cc | 2 + gcc/tree.h | 2 + include/gomp-constants.h | 2 + libgomp/oacc-parallel.c | 11 + .../libgomp.oacc-c-c++-common/self-1.c | 962 ++++++++++++++++++ 22 files changed, 1305 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/goacc/self-clause-1.c create mode 100644 gcc/testsuite/c-c++-common/goacc/self-clause-2.c create mode 100644 gcc/testsuite/gfortran.dg/goacc/self.f95 create mode 100644 libgomp/testsuite/libgomp.oacc-c-c++-common/self-1.c diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index e3899bae505..8c8722ccfbe 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -15437,6 +15437,41 @@ c_parser_oacc_clause_wait (c_parser *parser, tree list) return list; } +/* OpenACC 2.7: + self [( expression )] */ + +static tree +c_parser_oacc_compute_clause_self (c_parser *parser, tree list) +{ + tree t; + location_t location = c_parser_peek_token (parser)->location; + if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN) + { + matching_parens parens; + parens.consume_open (parser); + + location_t loc = c_parser_peek_token (parser)->location; + c_expr expr = c_parser_expr_no_commas (parser, NULL); + expr = convert_lvalue_to_rvalue (loc, expr, true, true); + t = c_objc_common_truthvalue_conversion (loc, expr.value); + t = c_fully_fold (t, false, NULL); + parens.skip_until_found_close (parser); + } + else + t = truthvalue_true_node; + + for (tree c = list; c; c = OMP_CLAUSE_CHAIN (c)) + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SELF) + { + error_at (location, "too many % clauses"); + return list; + } + + tree c = build_omp_clause (location, OMP_CLAUSE_SELF); + OMP_CLAUSE_SELF_EXPR (c) = t; + OMP_CLAUSE_CHAIN (c) = list; + return c; +} /* OpenMP 5.0: order ( concurrent ) @@ -17560,7 +17595,8 @@ c_parser_omp_clause_detach (c_parser *parser, tree list) static tree c_parser_oacc_all_clauses (c_parser *parser, omp_clause_mask mask, - const char *where, bool finish_p = true) + const char *where, bool finish_p = true, + bool compute_p = false) { tree clauses = NULL; bool first = true; @@ -17576,7 +17612,18 @@ c_parser_oacc_all_clauses (c_parser *parser, omp_clause_mask mask, c_parser_consume_token (parser); here = c_parser_peek_token (parser)->location; - c_kind = c_parser_omp_clause_name (parser); + + /* For OpenACC compute directives */ + if (compute_p + && c_parser_next_token_is (parser, CPP_NAME) + && !strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value), + "self")) + { + c_kind = PRAGMA_OACC_CLAUSE_SELF; + c_parser_consume_token (parser); + } + else + c_kind = c_parser_omp_clause_name (parser); switch (c_kind) { @@ -17708,6 +17755,10 @@ c_parser_oacc_all_clauses (c_parser *parser, omp_clause_mask mask, false, clauses); c_name = "reduction"; break; + case PRAGMA_OACC_CLAUSE_SELF: + clauses = c_parser_oacc_compute_clause_self (parser, clauses); + c_name = "self"; + break; case PRAGMA_OACC_CLAUSE_SEQ: clauses = c_parser_oacc_simple_clause (here, OMP_CLAUSE_SEQ, clauses); @@ -18544,6 +18595,7 @@ c_parser_oacc_loop (location_t loc, c_parser *parser, char *p_name, | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \ + | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) ) @@ -18564,6 +18616,7 @@ c_parser_oacc_loop (location_t loc, c_parser *parser, char *p_name, | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \ + | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) ) @@ -18582,6 +18635,7 @@ c_parser_oacc_loop (location_t loc, c_parser *parser, char *p_name, | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FIRSTPRIVATE) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \ + | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) ) static tree @@ -18624,7 +18678,7 @@ c_parser_oacc_compute (location_t loc, c_parser *parser, } } - tree clauses = c_parser_oacc_all_clauses (parser, mask, p_name); + tree clauses = c_parser_oacc_all_clauses (parser, mask, p_name, true, true); tree block = c_begin_omp_parallel (); add_stmt (c_parser_omp_structured_block (parser, if_p)); diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index 22e240a3c2a..89bf22df372 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -15821,6 +15821,7 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort) continue; case OMP_CLAUSE_IF: + case OMP_CLAUSE_SELF: case OMP_CLAUSE_NUM_THREADS: case OMP_CLAUSE_NUM_TEAMS: case OMP_CLAUSE_THREAD_LIMIT: diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 20dbe1089ec..efa805fb3b0 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -40956,13 +40956,51 @@ cp_parser_oacc_clause_async (cp_parser *parser, tree list) return list; } +/* OpenACC 2.7: + self [( expression )] */ + +static tree +cp_parser_oacc_compute_clause_self (cp_parser *parser, tree list) +{ + tree t; + location_t location = cp_lexer_peek_token (parser->lexer)->location; + if (cp_lexer_peek_token (parser->lexer)->type == CPP_OPEN_PAREN) + { + matching_parens parens; + parens.consume_open (parser); + t = cp_parser_assignment_expression (parser); + if (t == error_mark_node + || !parens.require_close (parser)) + { + cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true, + /*or_comma=*/false, + /*consume_paren=*/true); + return list; + } + } + else + t = truthvalue_true_node; + + for (tree c = list; c; c = OMP_CLAUSE_CHAIN (c)) + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SELF) + { + error_at (location, "too many % clauses"); + return list; + } + + tree c = build_omp_clause (location, OMP_CLAUSE_SELF); + OMP_CLAUSE_SELF_EXPR (c) = t; + OMP_CLAUSE_CHAIN (c) = list; + return c; +} + /* Parse all OpenACC clauses. The set clauses allowed by the directive is a bitmask in MASK. Return the list of clauses found. */ static tree cp_parser_oacc_all_clauses (cp_parser *parser, omp_clause_mask mask, const char *where, cp_token *pragma_tok, - bool finish_p = true) + bool finish_p = true, bool compute_p = false) { tree clauses = NULL; bool first = true; @@ -40982,7 +41020,19 @@ cp_parser_oacc_all_clauses (cp_parser *parser, omp_clause_mask mask, cp_lexer_consume_token (parser->lexer); here = cp_lexer_peek_token (parser->lexer)->location; - c_kind = cp_parser_omp_clause_name (parser); + + /* For OpenACC compute directives */ + if (compute_p + && cp_lexer_next_token_is (parser->lexer, CPP_NAME) + && !strcmp (IDENTIFIER_POINTER + (cp_lexer_peek_token (parser->lexer)->u.value), + "self")) + { + c_kind = PRAGMA_OACC_CLAUSE_SELF; + cp_lexer_consume_token (parser->lexer); + } + else + c_kind = cp_parser_omp_clause_name (parser); switch (c_kind) { @@ -41116,6 +41166,10 @@ cp_parser_oacc_all_clauses (cp_parser *parser, omp_clause_mask mask, false, clauses); c_name = "reduction"; break; + case PRAGMA_OACC_CLAUSE_SELF: + clauses = cp_parser_oacc_compute_clause_self (parser, clauses); + c_name = "self"; + break; case PRAGMA_OACC_CLAUSE_SEQ: clauses = cp_parser_oacc_simple_clause (here, OMP_CLAUSE_SEQ, clauses); @@ -46227,6 +46281,7 @@ cp_parser_oacc_loop (cp_parser *parser, cp_token *pragma_tok, char *p_name, | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \ + | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) ) @@ -46247,6 +46302,7 @@ cp_parser_oacc_loop (cp_parser *parser, cp_token *pragma_tok, char *p_name, | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \ + | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) ) @@ -46265,6 +46321,7 @@ cp_parser_oacc_loop (cp_parser *parser, cp_token *pragma_tok, char *p_name, | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FIRSTPRIVATE) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \ + | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \ | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) ) static tree @@ -46310,7 +46367,8 @@ cp_parser_oacc_compute (cp_parser *parser, cp_token *pragma_tok, } } - tree clauses = cp_parser_oacc_all_clauses (parser, mask, p_name, pragma_tok); + tree clauses = cp_parser_oacc_all_clauses (parser, mask, p_name, pragma_tok, + true, true); tree block = begin_omp_parallel (); unsigned int save = cp_parser_begin_omp_structured_block (parser); diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 6b20c58ce66..f8d8fc31c53 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -18037,6 +18037,7 @@ tsubst_omp_clauses (tree clauses, enum c_omp_region_type ort, /* FALLTHRU */ case OMP_CLAUSE_TILE: case OMP_CLAUSE_IF: + case OMP_CLAUSE_SELF: case OMP_CLAUSE_NUM_THREADS: case OMP_CLAUSE_SCHEDULE: case OMP_CLAUSE_COLLAPSE: diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index a2e74a5d2c7..ddb9f10b45a 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -7344,13 +7344,14 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) goto handle_field_decl; case OMP_CLAUSE_IF: - t = OMP_CLAUSE_IF_EXPR (c); + case OMP_CLAUSE_SELF: + t = OMP_CLAUSE_OPERAND (c, 0); t = maybe_convert_cond (t); if (t == error_mark_node) remove = true; else if (!processing_template_decl) t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); - OMP_CLAUSE_IF_EXPR (c) = t; + OMP_CLAUSE_OPERAND (c, 0) = t; break; case OMP_CLAUSE_FINAL: diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index a58c60e9828..7a21a6cb008 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -1540,6 +1540,7 @@ typedef struct gfc_omp_clauses { gfc_omp_namelist *lists[OMP_LIST_NUM]; struct gfc_expr *if_expr; + struct gfc_expr *self_expr; struct gfc_expr *final_expr; struct gfc_expr *num_threads; struct gfc_expr *chunk_size; diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc index 9714d5f8f61..038907baa48 100644 --- a/gcc/fortran/openmp.cc +++ b/gcc/fortran/openmp.cc @@ -1091,6 +1091,7 @@ enum omp_mask2 OMP_CLAUSE_ENTER, /* OpenMP 5.2 */ OMP_CLAUSE_DOACROSS, /* OpenMP 5.2 */ OMP_CLAUSE_ASSUMPTIONS, /* OpenMP 5.1. */ + OMP_CLAUSE_SELF, /* OpenACC 2.7 */ /* This must come last. */ OMP_MASK2_LAST }; @@ -3412,6 +3413,27 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, const omp_mask mask, else gfc_current_locus = old_loc; } + if ((mask & OMP_CLAUSE_SELF) + && (m = gfc_match_dupl_check (!c->self_expr, "self")) + != MATCH_NO) + { + gcc_assert (!(mask & OMP_CLAUSE_HOST_SELF)); + if (m == MATCH_ERROR) + goto error; + m = gfc_match (" ( %e )", &c->self_expr); + if (m == MATCH_ERROR) + { + gfc_current_locus = old_loc; + break; + } + else if (m == MATCH_NO) + { + c->self_expr = gfc_get_logical_expr (gfc_default_logical_kind, + NULL, true); + needs_space = true; + } + continue; + } if ((mask & OMP_CLAUSE_HOST_SELF) && gfc_match ("self ( ") == MATCH_YES && gfc_match_omp_map_clause (&c->lists[OMP_LIST_MAP], @@ -3677,19 +3699,22 @@ error: | OMP_CLAUSE_COPY | OMP_CLAUSE_COPYIN | OMP_CLAUSE_COPYOUT \ | OMP_CLAUSE_CREATE | OMP_CLAUSE_NO_CREATE | OMP_CLAUSE_PRESENT \ | OMP_CLAUSE_DEVICEPTR | OMP_CLAUSE_PRIVATE | OMP_CLAUSE_FIRSTPRIVATE \ - | OMP_CLAUSE_DEFAULT | OMP_CLAUSE_WAIT | OMP_CLAUSE_ATTACH) + | OMP_CLAUSE_DEFAULT | OMP_CLAUSE_WAIT | OMP_CLAUSE_ATTACH \ + | OMP_CLAUSE_SELF) #define OACC_KERNELS_CLAUSES \ (omp_mask (OMP_CLAUSE_IF) | OMP_CLAUSE_ASYNC | OMP_CLAUSE_NUM_GANGS \ | OMP_CLAUSE_NUM_WORKERS | OMP_CLAUSE_VECTOR_LENGTH | OMP_CLAUSE_DEVICEPTR \ | OMP_CLAUSE_COPY | OMP_CLAUSE_COPYIN | OMP_CLAUSE_COPYOUT \ | OMP_CLAUSE_CREATE | OMP_CLAUSE_NO_CREATE | OMP_CLAUSE_PRESENT \ - | OMP_CLAUSE_DEFAULT | OMP_CLAUSE_WAIT | OMP_CLAUSE_ATTACH) + | OMP_CLAUSE_DEFAULT | OMP_CLAUSE_WAIT | OMP_CLAUSE_ATTACH \ + | OMP_CLAUSE_SELF) #define OACC_SERIAL_CLAUSES \ (omp_mask (OMP_CLAUSE_IF) | OMP_CLAUSE_ASYNC | OMP_CLAUSE_REDUCTION \ | OMP_CLAUSE_COPY | OMP_CLAUSE_COPYIN | OMP_CLAUSE_COPYOUT \ | OMP_CLAUSE_CREATE | OMP_CLAUSE_NO_CREATE | OMP_CLAUSE_PRESENT \ | OMP_CLAUSE_DEVICEPTR | OMP_CLAUSE_PRIVATE | OMP_CLAUSE_FIRSTPRIVATE \ - | OMP_CLAUSE_DEFAULT | OMP_CLAUSE_WAIT | OMP_CLAUSE_ATTACH) + | OMP_CLAUSE_DEFAULT | OMP_CLAUSE_WAIT | OMP_CLAUSE_ATTACH \ + | OMP_CLAUSE_SELF) #define OACC_DATA_CLAUSES \ (omp_mask (OMP_CLAUSE_IF) | OMP_CLAUSE_DEVICEPTR | OMP_CLAUSE_COPY \ | OMP_CLAUSE_COPYIN | OMP_CLAUSE_COPYOUT | OMP_CLAUSE_CREATE \ @@ -7251,6 +7276,14 @@ resolve_omp_clauses (gfc_code *code, gfc_omp_clauses *omp_clauses, &expr->where); if_without_mod = true; } + if (omp_clauses->self_expr) + { + gfc_expr *expr = omp_clauses->self_expr; + if (!gfc_resolve_expr (expr) + || expr->ts.type != BT_LOGICAL || expr->rank != 0) + gfc_error ("SELF clause at %L requires a scalar LOGICAL expression", + &expr->where); + } for (ifc = 0; ifc < OMP_IF_LAST; ifc++) if (omp_clauses->if_exprs[ifc]) { diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc index 340da85cb99..0f8323901d7 100644 --- a/gcc/fortran/trans-openmp.cc +++ b/gcc/fortran/trans-openmp.cc @@ -3943,6 +3943,22 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses, OMP_CLAUSE_IF_EXPR (c) = if_var; omp_clauses = gfc_trans_add_clause (c, omp_clauses); } + + if (clauses->self_expr) + { + tree self_var; + + gfc_init_se (&se, NULL); + gfc_conv_expr (&se, clauses->self_expr); + gfc_add_block_to_block (block, &se.pre); + self_var = gfc_evaluate_now (se.expr, block); + gfc_add_block_to_block (block, &se.post); + + c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SELF); + OMP_CLAUSE_SELF_EXPR (c) = self_var; + omp_clauses = gfc_trans_add_clause (c, omp_clauses); + } + for (ifc = 0; ifc < OMP_IF_LAST; ifc++) if (clauses->if_exprs[ifc]) { @@ -6595,6 +6611,8 @@ gfc_split_omp_clauses (gfc_code *code, /* And this is copied to all. */ clausesa[GFC_OMP_SPLIT_TARGET].if_expr = code->ext.omp_clauses->if_expr; + clausesa[GFC_OMP_SPLIT_TARGET].self_expr + = code->ext.omp_clauses->self_expr; clausesa[GFC_OMP_SPLIT_TARGET].nowait = code->ext.omp_clauses->nowait; } diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index 6f1e95bfbe7..d309459be1b 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -11867,6 +11867,7 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p, } /* Fall through. */ + case OMP_CLAUSE_SELF: case OMP_CLAUSE_FINAL: OMP_CLAUSE_OPERAND (c, 0) = gimple_boolify (OMP_CLAUSE_OPERAND (c, 0)); @@ -13093,6 +13094,7 @@ gimplify_adjust_omp_clauses (gimple_seq *pre_p, gimple_seq body, tree *list_p, case OMP_CLAUSE_COPYIN: case OMP_CLAUSE_COPYPRIVATE: case OMP_CLAUSE_IF: + case OMP_CLAUSE_SELF: case OMP_CLAUSE_NUM_THREADS: case OMP_CLAUSE_NUM_TEAMS: case OMP_CLAUSE_THREAD_LIMIT: diff --git a/gcc/omp-expand.cc b/gcc/omp-expand.cc index db58b3cb49b..f7b7c67d459 100644 --- a/gcc/omp-expand.cc +++ b/gcc/omp-expand.cc @@ -10331,6 +10331,47 @@ expand_omp_target (struct omp_region *region) } } + if ((c = omp_find_clause (clauses, OMP_CLAUSE_SELF)) != NULL_TREE) + { + gcc_assert (is_gimple_omp_oacc (entry_stmt) && offloaded); + + edge e = split_block_after_labels (new_bb); + basic_block cond_bb = e->src; + new_bb = e->dest; + remove_edge (e); + + basic_block then_bb = create_empty_bb (cond_bb); + basic_block else_bb = create_empty_bb (then_bb); + set_immediate_dominator (CDI_DOMINATORS, then_bb, cond_bb); + set_immediate_dominator (CDI_DOMINATORS, else_bb, cond_bb); + + tree self_cond = gimple_boolify (OMP_CLAUSE_SELF_EXPR (c)); + stmt = gimple_build_cond_empty (self_cond); + gsi = gsi_last_bb (cond_bb); + gsi_insert_after (&gsi, stmt, GSI_CONTINUE_LINKING); + + tree tmp_var = create_tmp_var (TREE_TYPE (goacc_flags)); + stmt = gimple_build_assign (tmp_var, BIT_IOR_EXPR, goacc_flags, + build_int_cst (integer_type_node, + GOACC_FLAG_LOCAL_DEVICE)); + gsi = gsi_start_bb (then_bb); + gsi_insert_after (&gsi, stmt, GSI_CONTINUE_LINKING); + + gsi = gsi_start_bb (else_bb); + stmt = gimple_build_assign (tmp_var, goacc_flags); + gsi_insert_after (&gsi, stmt, GSI_CONTINUE_LINKING); + + make_edge (cond_bb, then_bb, EDGE_TRUE_VALUE); + make_edge (cond_bb, else_bb, EDGE_FALSE_VALUE); + add_bb_to_loop (then_bb, cond_bb->loop_father); + add_bb_to_loop (else_bb, cond_bb->loop_father); + make_edge (then_bb, new_bb, EDGE_FALLTHRU); + make_edge (else_bb, new_bb, EDGE_FALLTHRU); + + goacc_flags = tmp_var; + gsi = gsi_last_nondebug_bb (new_bb); + } + if (need_device_adjustment) { tree uns = fold_convert (unsigned_type_node, device); diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc index 1857b5b960f..d2adf776939 100644 --- a/gcc/omp-low.cc +++ b/gcc/omp-low.cc @@ -1493,6 +1493,7 @@ scan_sharing_clauses (tree clauses, omp_context *ctx) case OMP_CLAUSE_FINAL: case OMP_CLAUSE_IF: + case OMP_CLAUSE_SELF: case OMP_CLAUSE_NUM_THREADS: case OMP_CLAUSE_NUM_TEAMS: case OMP_CLAUSE_THREAD_LIMIT: @@ -1920,6 +1921,7 @@ scan_sharing_clauses (tree clauses, omp_context *ctx) case OMP_CLAUSE_COPYIN: case OMP_CLAUSE_DEFAULT: case OMP_CLAUSE_IF: + case OMP_CLAUSE_SELF: case OMP_CLAUSE_NUM_THREADS: case OMP_CLAUSE_NUM_TEAMS: case OMP_CLAUSE_THREAD_LIMIT: diff --git a/gcc/testsuite/c-c++-common/goacc/self-clause-1.c b/gcc/testsuite/c-c++-common/goacc/self-clause-1.c new file mode 100644 index 00000000000..ed5d072e81f --- /dev/null +++ b/gcc/testsuite/c-c++-common/goacc/self-clause-1.c @@ -0,0 +1,22 @@ +/* { dg-skip-if "not yet" { c++ } } */ + +void +f (int b) +{ + struct { int i; } *p; + +#pragma acc parallel self self(b) /* { dg-error "too many 'self' clauses" } */ + ; +#pragma acc parallel self(*p) /* { dg-error "used struct type value where scalar is required" } */ + ; + +#pragma acc kernels self self(b) /* { dg-error "too many 'self' clauses" } */ + ; +#pragma acc kernels self(*p) /* { dg-error "used struct type value where scalar is required" } */ + ; + +#pragma acc serial self self(b) /* { dg-error "too many 'self' clauses" } */ + ; +#pragma acc serial self(*p) /* { dg-error "used struct type value where scalar is required" } */ + ; +} diff --git a/gcc/testsuite/c-c++-common/goacc/self-clause-2.c b/gcc/testsuite/c-c++-common/goacc/self-clause-2.c new file mode 100644 index 00000000000..d932ac9a4a6 --- /dev/null +++ b/gcc/testsuite/c-c++-common/goacc/self-clause-2.c @@ -0,0 +1,17 @@ +/* { dg-additional-options "-fdump-tree-gimple" } */ + +void +f (short c) +{ +#pragma acc parallel self(c) copy(c) + /* { dg-final { scan-tree-dump-times {(?n)#pragma omp target oacc_parallel map\(tofrom:c \[len: [0-9]+\]\) self\(_[0-9]+\)$} 1 "gimple" } } */ + ++c; + +#pragma acc kernels self(c) copy(c) + /* { dg-final { scan-tree-dump-times {(?n)#pragma omp target oacc_kernels map\(tofrom:c \[len: [0-9]+\]\) self\(_[0-9]+\)$} 1 "gimple" } } */ + ++c; + +#pragma acc serial self(c) copy(c) + /* { dg-final { scan-tree-dump-times {(?n)#pragma omp target oacc_serial map\(tofrom:c \[len: [0-9]+\]\) self\(_[0-9]+\)$} 1 "gimple" } } */ + ++c; +} diff --git a/gcc/testsuite/gfortran.dg/goacc/self.f95 b/gcc/testsuite/gfortran.dg/goacc/self.f95 new file mode 100644 index 00000000000..4817f16be56 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/goacc/self.f95 @@ -0,0 +1,53 @@ +! { dg-do compile } + +program test + implicit none + + logical :: x + integer :: i + + !$acc parallel self () ! { dg-error "Invalid character" } + !$acc parallel self (i) ! { dg-error "scalar LOGICAL expression" } + !$acc end parallel + !$acc parallel self (1) ! { dg-error "scalar LOGICAL expression" } + !$acc end parallel + + !$acc kernels self () ! { dg-error "Invalid character" } + !$acc kernels self (i) ! { dg-error "scalar LOGICAL expression" } + !$acc end kernels + !$acc kernels self (1) ! { dg-error "scalar LOGICAL expression" } + !$acc end kernels + + !$acc serial self () ! { dg-error "Invalid character" } + !$acc serial self (i) ! { dg-error "scalar LOGICAL expression" } + !$acc end serial + !$acc serial self (1) ! { dg-error "scalar LOGICAL expression" } + !$acc end serial + + ! at most one self clause may appear + !$acc parallel self (.false.) self (.false.) { dg-error "Duplicated 'self' clause" } + !$acc kernels self (.false.) self (.false.) { dg-error "Duplicated 'self' clause" } + !$acc serial self (.false.) self (.false.) { dg-error "Duplicated 'self' clause" } + + !$acc parallel self (x) + !$acc end parallel + !$acc parallel self (.true.) + !$acc end parallel + !$acc parallel self (i.gt.1) + !$acc end parallel + + !$acc kernels self (x) + !$acc end kernels + !$acc kernels self (.true.) + !$acc end kernels + !$acc kernels self (i.gt.1) + !$acc end kernels + + !$acc serial self (x) + !$acc end serial + !$acc serial self (.true.) + !$acc end serial + !$acc serial self (i.gt.1) + !$acc end serial + +end program test diff --git a/gcc/tree-core.h b/gcc/tree-core.h index c48a12b378f..3fd5a3dff78 100644 --- a/gcc/tree-core.h +++ b/gcc/tree-core.h @@ -524,6 +524,9 @@ enum omp_clause_code { /* OpenACC clause: nohost. */ OMP_CLAUSE_NOHOST, + + /* OpenACC clause: self. */ + OMP_CLAUSE_SELF, }; #undef DEFTREESTRUCT diff --git a/gcc/tree-nested.cc b/gcc/tree-nested.cc index ae7d1f1f6a8..8dd4c8acf25 100644 --- a/gcc/tree-nested.cc +++ b/gcc/tree-nested.cc @@ -1366,6 +1366,7 @@ convert_nonlocal_omp_clauses (tree *pclauses, struct walk_stmt_info *wi) /* FALLTHRU */ case OMP_CLAUSE_FINAL: case OMP_CLAUSE_IF: + case OMP_CLAUSE_SELF: case OMP_CLAUSE_NUM_THREADS: case OMP_CLAUSE_DEPEND: case OMP_CLAUSE_DOACROSS: @@ -2156,6 +2157,7 @@ convert_local_omp_clauses (tree *pclauses, struct walk_stmt_info *wi) /* FALLTHRU */ case OMP_CLAUSE_FINAL: case OMP_CLAUSE_IF: + case OMP_CLAUSE_SELF: case OMP_CLAUSE_NUM_THREADS: case OMP_CLAUSE_DEPEND: case OMP_CLAUSE_DOACROSS: diff --git a/gcc/tree-pretty-print.cc b/gcc/tree-pretty-print.cc index 25d191b10fd..a743e3cdfd8 100644 --- a/gcc/tree-pretty-print.cc +++ b/gcc/tree-pretty-print.cc @@ -1450,7 +1450,12 @@ dump_omp_clause (pretty_printer *pp, tree clause, int spc, dump_flags_t flags) false); pp_right_paren (pp); break; - + case OMP_CLAUSE_SELF: + pp_string (pp, "self("); + dump_generic_node (pp, OMP_CLAUSE_SELF_EXPR (clause), + spc, flags, false); + pp_right_paren (pp); + break; default: gcc_unreachable (); } diff --git a/gcc/tree.cc b/gcc/tree.cc index 8e144bc090e..18a27d2faf9 100644 --- a/gcc/tree.cc +++ b/gcc/tree.cc @@ -326,6 +326,7 @@ unsigned const char omp_clause_num_ops[] = 0, /* OMP_CLAUSE_IF_PRESENT */ 0, /* OMP_CLAUSE_FINALIZE */ 0, /* OMP_CLAUSE_NOHOST */ + 1, /* OMP_CLAUSE_SELF */ }; const char * const omp_clause_code_name[] = @@ -417,6 +418,7 @@ const char * const omp_clause_code_name[] = "if_present", "finalize", "nohost", + "self", }; /* Unless specific to OpenACC, we tend to internally maintain OpenMP-centric diff --git a/gcc/tree.h b/gcc/tree.h index 1854fe4a7d4..f04457022ac 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -1711,6 +1711,8 @@ class auto_suppress_location_wrappers OMP_CLAUSE_OPERAND (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_HINT), 0) #define OMP_CLAUSE_FILTER_EXPR(NODE) \ OMP_CLAUSE_OPERAND (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_FILTER), 0) +#define OMP_CLAUSE_SELF_EXPR(NODE) \ + OMP_CLAUSE_OPERAND (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_SELF), 0) #define OMP_CLAUSE_GRAINSIZE_EXPR(NODE) \ OMP_CLAUSE_OPERAND (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_GRAINSIZE),0) diff --git a/include/gomp-constants.h b/include/gomp-constants.h index 49b7dd86ff5..8a349ca504f 100644 --- a/include/gomp-constants.h +++ b/include/gomp-constants.h @@ -305,6 +305,8 @@ enum gomp_map_kind /* Force host fallback execution. */ #define GOACC_FLAG_HOST_FALLBACK (1 << 0) +/* Execute on local device (i.e. host multicore CPU). */ +#define GOACC_FLAG_LOCAL_DEVICE (1 << 1) /* For legacy reasons, in the ABI, the GOACC_FLAGs are encoded as an inverted bitmask. */ diff --git a/libgomp/oacc-parallel.c b/libgomp/oacc-parallel.c index 363e6656982..cf37a1bdd7d 100644 --- a/libgomp/oacc-parallel.c +++ b/libgomp/oacc-parallel.c @@ -193,6 +193,17 @@ GOACC_parallel_keyed (int flags_m, void (*fn) (void *), goacc_restore_bind (); goto out_prof; } + else if (flags & GOACC_FLAG_LOCAL_DEVICE) + { + /* TODO: a proper pthreads based "multi-core CPU" local device + implementation. Currently, this is still the same as host-fallback. */ + prof_info.device_type = acc_device_host; + api_info.device_type = prof_info.device_type; + goacc_save_and_set_bind (acc_device_host); + fn (hostaddrs); + goacc_restore_bind (); + goto out_prof; + } else if (acc_device_type (acc_dev->type) == acc_device_host) { fn (hostaddrs); diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/self-1.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/self-1.c new file mode 100644 index 00000000000..752e16e8545 --- /dev/null +++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/self-1.c @@ -0,0 +1,962 @@ +#include +#include +#include + +#define N 32 + +int +main(int argc, char **argv) +{ + float *a, *b, *d_a, *d_b, exp, exp2; + int i; + const int one = 1; + const int zero = 0; + int n; + + a = (float *) malloc (N * sizeof (float)); + b = (float *) malloc (N * sizeof (float)); + d_a = (float *) acc_malloc (N * sizeof (float)); + d_b = (float *) acc_malloc (N * sizeof (float)); + + for (i = 0; i < N; i++) + a[i] = 4.0; + +#pragma acc parallel copyin(a[0:N]) copyout(b[0:N]) self(0) + { + int ii; + + for (ii = 0; ii < N; ii++) + { + if (acc_on_device (acc_device_host)) + b[ii] = a[ii] + 1; + else + b[ii] = a[ii]; + } + } + +#if ACC_MEM_SHARED + exp = 5.0; +#else + exp = 4.0; +#endif + + for (i = 0; i < N; i++) + { + if (b[i] != exp) + abort(); + } + + for (i = 0; i < N; i++) + a[i] = 16.0; + +#pragma acc parallel self(1) + { + int ii; + + for (ii = 0; ii < N; ii++) + { + if (acc_on_device (acc_device_host)) + b[ii] = a[ii] + 1; + else + b[ii] = a[ii]; + } + } + + for (i = 0; i < N; i++) + { + if (b[i] != 17.0) + abort(); + } + + for (i = 0; i < N; i++) + a[i] = 8.0; + +#pragma acc parallel copyin(a[0:N]) copyout(b[0:N]) self(!one) + { + int ii; + + for (ii = 0; ii < N; ii++) + { + if (acc_on_device (acc_device_host)) + b[ii] = a[ii] + 1; + else + b[ii] = a[ii]; + } + } + +#if ACC_MEM_SHARED + exp = 9.0; +#else + exp = 8.0; +#endif + + for (i = 0; i < N; i++) + { + if (b[i] != exp) + abort(); + } + + for (i = 0; i < N; i++) + a[i] = 22.0; + +#pragma acc parallel self(!zero) + { + int ii; + + for (ii = 0; ii < N; ii++) + { + if (acc_on_device (acc_device_host)) + b[ii] = a[ii] + 1; + else + b[ii] = a[ii]; + } + } + + for (i = 0; i < N; i++) + { + if (b[i] != 23.0) + abort(); + } + + for (i = 0; i < N; i++) + a[i] = 16.0; + +#pragma acc parallel copyin(a[0:N]) copyout(b[0:N]) self(false) + { + int ii; + + for (ii = 0; ii < N; ii++) + { + if (acc_on_device (acc_device_host)) + b[ii] = a[ii] + 1; + else + b[ii] = a[ii]; + } + } + +#if ACC_MEM_SHARED + exp = 17.0; +#else + exp = 16.0; +#endif + + for (i = 0; i < N; i++) + { + if (b[i] != exp) + abort(); + } + + for (i = 0; i < N; i++) + a[i] = 76.0; + +#pragma acc parallel self(true) + { + int ii; + + for (ii = 0; ii < N; ii++) + { + if (acc_on_device (acc_device_host)) + b[ii] = a[ii] + 1; + else + b[ii] = a[ii]; + } + } + + for (i = 0; i < N; i++) + { + if (b[i] != 77.0) + abort(); + } + + for (i = 0; i < N; i++) + a[i] = 22.0; + + n = 1; + +#pragma acc parallel copyin(a[0:N]) copyout(b[0:N]) self(!n) + { + int ii; + + for (ii = 0; ii < N; ii++) + { + if (acc_on_device (acc_device_host)) + b[ii] = a[ii] + 1; + else + b[ii] = a[ii]; + } + } + +#if ACC_MEM_SHARED + exp = 23.0; +#else + exp = 22.0; +#endif + + for (i = 0; i < N; i++) + { + if (b[i] != exp) + abort(); + } + + for (i = 0; i < N; i++) + a[i] = 18.0; + + n = 0; + +#pragma acc parallel self(!n) + { + int ii; + + for (ii = 0; ii < N; ii++) + { + if (acc_on_device (acc_device_host)) + b[ii] = a[ii] + 1; + else + b[ii] = a[ii]; + } + } + + for (i = 0; i < N; i++) + { + if (b[i] != 19.0) + abort(); + } + + for (i = 0; i < N; i++) + a[i] = 49.0; + + n = 1; + +#pragma acc parallel copyin(a[0:N]) copyout(b[0:N]) self(!(n + n)) + { + int ii; + + for (ii = 0; ii < N; ii++) + { + if (acc_on_device (acc_device_host)) + b[ii] = a[ii] + 1; + else + b[ii] = a[ii]; + } + } + +#if ACC_MEM_SHARED + exp = 50.0; +#else + exp = 49.0; +#endif + + for (i = 0; i < N; i++) + { + if (b[i] != exp) + abort(); + } + + for (i = 0; i < N; i++) + a[i] = 38.0; + + n = 0; + +#pragma acc parallel self(!(n + n)) + { + int ii; + + for (ii = 0; ii < N; ii++) + { + if (acc_on_device (acc_device_host)) + b[ii] = a[ii] + 1; + else + b[ii] = a[ii]; + } + } + + for (i = 0; i < N; i++) + { + if (b[i] != 39.0) + abort(); + } + + for (i = 0; i < N; i++) + a[i] = 91.0; + +#pragma acc parallel copyin(a[0:N]) copyout(b[0:N]) self(!(-2)) + { + int ii; + + for (ii = 0; ii < N; ii++) + { + if (acc_on_device (acc_device_host)) + b[ii] = a[ii] + 1; + else + b[ii] = a[ii]; + } + } + +#if ACC_MEM_SHARED + exp = 92.0; +#else + exp = 91.0; +#endif + + for (i = 0; i < N; i++) + { + if (b[i] != exp) + abort(); + } + + for (i = 0; i < N; i++) + a[i] = 43.0; + +#pragma acc parallel copyin(a[0:N]) copyout(b[0:N]) self(one != 1) + { + int ii; + + for (ii = 0; ii < N; ii++) + { + if (acc_on_device (acc_device_host)) + b[ii] = a[ii] + 1; + else + b[ii] = a[ii]; + } + } + +#if ACC_MEM_SHARED + exp = 44.0; +#else + exp = 43.0; +#endif + + for (i = 0; i < N; i++) + { + if (b[i] != exp) + abort(); + } + + for (i = 0; i < N; i++) + a[i] = 87.0; + +#pragma acc parallel self(one != 0) + { + int ii; + + for (ii = 0; ii < N; ii++) + { + if (acc_on_device (acc_device_host)) + b[ii] = a[ii] + 1; + else + b[ii] = a[ii]; + } + } + + for (i = 0; i < N; i++) + { + if (b[i] != 88.0) + abort(); + } + + for (i = 0; i < N; i++) + { + a[i] = 3.0; + b[i] = 9.0; + } + +#if ACC_MEM_SHARED + exp = 0.0; + exp2 = 0.0; +#else + acc_map_data (a, d_a, N * sizeof (float)); + acc_map_data (b, d_b, N * sizeof (float)); + exp = 3.0; + exp2 = 9.0; +#endif + +#pragma acc update device(a[0:N], b[0:N]) if(1) + + for (i = 0; i < N; i++) + { + a[i] = 0.0; + b[i] = 0.0; + } + +#pragma acc update host(a[0:N], b[0:N]) if(1) + + for (i = 0; i < N; i++) + { + if (a[i] != exp) + abort(); + + if (b[i] != exp2) + abort(); + } + + for (i = 0; i < N; i++) + { + a[i] = 6.0; + b[i] = 12.0; + } + +#pragma acc update device(a[0:N], b[0:N]) if(0) + + for (i = 0; i < N; i++) + { + a[i] = 0.0; + b[i] = 0.0; + } + +#pragma acc update host(a[0:N], b[0:N]) if(1) + + for (i = 0; i < N; i++) + { + if (a[i] != exp) + abort(); + + if (b[i] != exp2) + abort(); + } + + for (i = 0; i < N; i++) + { + a[i] = 26.0; + b[i] = 21.0; + } + +#pragma acc update device(a[0:N], b[0:N]) if(1) + + for (i = 0; i < N; i++) + { + a[i] = 0.0; + b[i] = 0.0; + } + +#pragma acc update host(a[0:N], b[0:N]) if(0) + + for (i = 0; i < N; i++) + { + if (a[i] != 0.0) + abort(); + + if (b[i] != 0.0) + abort(); + } + +#if !ACC_MEM_SHARED + acc_unmap_data (a); + acc_unmap_data (b); +#endif + + acc_free (d_a); + acc_free (d_b); + + for (i = 0; i < N; i++) + { + a[i] = 4.0; + b[i] = 0.0; + } + +#pragma acc data copyin(a[0:N]) copyout(b[0:N]) if(1) +{ +#pragma acc parallel present(a[0:N]) + { + int ii; + + for (ii = 0; ii < N; ii++) + { + b[ii] = a[ii]; + } + } +} + + for (i = 0; i < N; i++) + { + if (b[i] != 4.0) + abort(); + } + + for (i = 0; i < N; i++) + { + a[i] = 8.0; + b[i] = 1.0; + } + +#pragma acc data copyin(a[0:N]) copyout(b[0:N]) if(0) +{ +#if !ACC_MEM_SHARED + if (acc_is_present (a, N * sizeof (float))) + abort (); +#endif + +#if !ACC_MEM_SHARED + if (acc_is_present (b, N * sizeof (float))) + abort (); +#endif +} + + for (i = 0; i < N; i++) + { + a[i] = 18.0; + b[i] = 21.0; + } + +#pragma acc data copyin(a[0:N]) if(1) +{ +#if !ACC_MEM_SHARED + if (!acc_is_present (a, N * sizeof (float))) + abort (); +#endif + +#pragma acc data copyout(b[0:N]) if(0) + { +#if !ACC_MEM_SHARED + if (acc_is_present (b, N * sizeof (float))) + abort (); +#endif + +#pragma acc data copyout(b[0:N]) if(1) + { +#pragma acc parallel present(a[0:N]) present(b[0:N]) + { + int ii; + + for (ii = 0; ii < N; ii++) + { + b[ii] = a[ii]; + } + } + } + +#if !ACC_MEM_SHARED + if (acc_is_present (b, N * sizeof (float))) + abort (); +#endif + } +} + + for (i = 0; i < N; i++) + { + if (b[i] != 18.0) + abort (); + } + +#pragma acc enter data copyin (b[0:N]) if (0) + +#if !ACC_MEM_SHARED + if (acc_is_present (b, N * sizeof (float))) + abort (); +#endif + +#pragma acc exit data delete (b[0:N]) if (0) + +#pragma acc enter data copyin (b[0:N]) if (1) + +#if !ACC_MEM_SHARED + if (!acc_is_present (b, N * sizeof (float))) + abort (); +#endif + +#pragma acc exit data delete (b[0:N]) if (1) + +#if !ACC_MEM_SHARED + if (acc_is_present (b, N * sizeof (float))) + abort (); +#endif + +#pragma acc enter data copyin (b[0:N]) if (zero) + +#if !ACC_MEM_SHARED + if (acc_is_present (b, N * sizeof (float))) + abort (); +#endif + +#pragma acc exit data delete (b[0:N]) if (zero) + +#pragma acc enter data copyin (b[0:N]) if (one) + +#if !ACC_MEM_SHARED + if (!acc_is_present (b, N * sizeof (float))) + abort (); +#endif + +#pragma acc exit data delete (b[0:N]) if (one) + +#if !ACC_MEM_SHARED + if (acc_is_present (b, N * sizeof (float))) + abort (); +#endif + +#pragma acc enter data copyin (b[0:N]) if (one == 0) + +#if !ACC_MEM_SHARED + if (acc_is_present (b, N * sizeof (float))) + abort (); +#endif + +#pragma acc exit data delete (b[0:N]) if (one == 0) + +#pragma acc enter data copyin (b[0:N]) if (one == 1) + +#if !ACC_MEM_SHARED + if (!acc_is_present (b, N * sizeof (float))) + abort (); +#endif + +#pragma acc exit data delete (b[0:N]) if (one == 1) + +#if !ACC_MEM_SHARED + if (acc_is_present (b, N * sizeof (float))) + abort (); +#endif + + for (i = 0; i < N; i++) + a[i] = 4.0; + +#pragma acc kernels copyin(a[0:N]) copyout(b[0:N]) self(0) + { + int ii; + + for (ii = 0; ii < N; ii++) + { + if (acc_on_device (acc_device_host)) + b[ii] = a[ii] + 1; + else + b[ii] = a[ii]; + } + } + +#if ACC_MEM_SHARED + exp = 5.0; +#else + exp = 4.0; +#endif + + for (i = 0; i < N; i++) + { + if (b[i] != exp) + abort(); + } + + for (i = 0; i < N; i++) + a[i] = 16.0; + +#pragma acc kernels self(1) + { + int ii; + + for (ii = 0; ii < N; ii++) + { + if (acc_on_device (acc_device_host)) + b[ii] = a[ii] + 1; + else + b[ii] = a[ii]; + } + } + + for (i = 0; i < N; i++) + { + if (b[i] != 17.0) + abort(); + } + + for (i = 0; i < N; i++) + a[i] = 8.0; + +#pragma acc kernels copyin(a[0:N]) copyout(b[0:N]) self(!one) + { + int ii; + + for (ii = 0; ii < N; ii++) + { + if (acc_on_device (acc_device_host)) + b[ii] = a[ii] + 1; + else + b[ii] = a[ii]; + } + } + +#if ACC_MEM_SHARED + exp = 9.0; +#else + exp = 8.0; +#endif + + for (i = 0; i < N; i++) + { + if (b[i] != exp) + abort(); + } + + for (i = 0; i < N; i++) + a[i] = 22.0; + +#pragma acc kernels self(!zero) + { + int ii; + + for (ii = 0; ii < N; ii++) + { + if (acc_on_device (acc_device_host)) + b[ii] = a[ii] + 1; + else + b[ii] = a[ii]; + } + } + + for (i = 0; i < N; i++) + { + if (b[i] != 23.0) + abort(); + } + + for (i = 0; i < N; i++) + a[i] = 16.0; + +#pragma acc kernels copyin(a[0:N]) copyout(b[0:N]) self(false) + { + int ii; + + for (ii = 0; ii < N; ii++) + { + if (acc_on_device (acc_device_host)) + b[ii] = a[ii] + 1; + else + b[ii] = a[ii]; + } + } + +#if ACC_MEM_SHARED + exp = 17.0; +#else + exp = 16.0; +#endif + + for (i = 0; i < N; i++) + { + if (b[i] != exp) + abort(); + } + + for (i = 0; i < N; i++) + a[i] = 76.0; + +#pragma acc kernels self(true) + { + int ii; + + for (ii = 0; ii < N; ii++) + { + if (acc_on_device (acc_device_host)) + b[ii] = a[ii] + 1; + else + b[ii] = a[ii]; + } + } + + for (i = 0; i < N; i++) + { + if (b[i] != 77.0) + abort(); + } + + for (i = 0; i < N; i++) + a[i] = 22.0; + + n = 1; + +#pragma acc kernels copyin(a[0:N]) copyout(b[0:N]) self(!n) + { + int ii; + + for (ii = 0; ii < N; ii++) + { + if (acc_on_device (acc_device_host)) + b[ii] = a[ii] + 1; + else + b[ii] = a[ii]; + } + } + +#if ACC_MEM_SHARED + exp = 23.0; +#else + exp = 22.0; +#endif + + for (i = 0; i < N; i++) + { + if (b[i] != exp) + abort(); + } + + for (i = 0; i < N; i++) + a[i] = 18.0; + + n = 0; + +#pragma acc kernels self(!n) + { + int ii; + + for (ii = 0; ii < N; ii++) + { + if (acc_on_device (acc_device_host)) + b[ii] = a[ii] + 1; + else + b[ii] = a[ii]; + } + } + + for (i = 0; i < N; i++) + { + if (b[i] != 19.0) + abort(); + } + + for (i = 0; i < N; i++) + a[i] = 49.0; + + n = 1; + +#pragma acc kernels copyin(a[0:N]) copyout(b[0:N]) self((n + n) == 0) + { + int ii; + + for (ii = 0; ii < N; ii++) + { + if (acc_on_device (acc_device_host)) + b[ii] = a[ii] + 1; + else + b[ii] = a[ii]; + } + } + +#if ACC_MEM_SHARED + exp = 50.0; +#else + exp = 49.0; +#endif + + for (i = 0; i < N; i++) + { + if (b[i] != exp) + abort(); + } + + for (i = 0; i < N; i++) + a[i] = 38.0; + + n = 0; + +#pragma acc kernels self(!(n + n)) + { + int ii; + + for (ii = 0; ii < N; ii++) + { + if (acc_on_device (acc_device_host)) + b[ii] = a[ii] + 1; + else + b[ii] = a[ii]; + } + } + + for (i = 0; i < N; i++) + { + if (b[i] != 39.0) + abort(); + } + + for (i = 0; i < N; i++) + a[i] = 91.0; + +#pragma acc kernels copyin(a[0:N]) copyout(b[0:N]) self(!(-2)) + { + int ii; + + for (ii = 0; ii < N; ii++) + { + if (acc_on_device (acc_device_host)) + b[ii] = a[ii] + 1; + else + b[ii] = a[ii]; + } + } + +#if ACC_MEM_SHARED + exp = 92.0; +#else + exp = 91.0; +#endif + + for (i = 0; i < N; i++) + { + if (b[i] != exp) + abort(); + } + + for (i = 0; i < N; i++) + a[i] = 43.0; + +#pragma acc kernels copyin(a[0:N]) copyout(b[0:N]) self(one != 1) + { + int ii; + + for (ii = 0; ii < N; ii++) + { + if (acc_on_device (acc_device_host)) + b[ii] = a[ii] + 1; + else + b[ii] = a[ii]; + } + } + +#if ACC_MEM_SHARED + exp = 44.0; +#else + exp = 43.0; +#endif + + for (i = 0; i < N; i++) + { + if (b[i] != exp) + abort(); + } + + for (i = 0; i < N; i++) + a[i] = 87.0; + +#pragma acc kernels self(one != 0) + { + int ii; + + for (ii = 0; ii < N; ii++) + { + if (acc_on_device (acc_device_host)) + b[ii] = a[ii] + 1; + else + b[ii] = a[ii]; + } + } + + for (i = 0; i < N; i++) + { + if (b[i] != 88.0) + abort(); + } + + for (i = 0; i < N; i++) + { + a[i] = 3.0; + b[i] = 9.0; + } + +#if ACC_MEM_SHARED + exp = 0.0; + exp2 = 0.0; +#else + acc_map_data (a, d_a, N * sizeof (float)); + acc_map_data (b, d_b, N * sizeof (float)); + exp = 3.0; + exp2 = 9.0; +#endif + + return 0; +}