From patchwork Thu Aug 30 13:27:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chung-Lin Tang X-Patchwork-Id: 963876 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-484800-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=mentor.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="C0os/rrw"; dkim-atps=neutral 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 421NbB0Qdlz9ryt for ; Thu, 30 Aug 2018 23:27:49 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :reply-to:from:to:subject:message-id:date:mime-version :content-type; q=dns; s=default; b=dTA3Duu4X5A+BAL8FmGXSLzZKZN8z ZyP+UAI4jdULygHt8HdCDa0CQCtefk7ufsyexnvK1NklSnmogZwr/AqugDdhIrpM yb8dcjWIaH67d8SXfzlSnY7Mvnl5/5hn+2Kq064Efg/3TQiZxktjsN8l6uR+jn9/ MmZKUPDqgteTbc= 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 :reply-to:from:to:subject:message-id:date:mime-version :content-type; s=default; bh=C/ujzG7/H6RnV7pRn6tnda4/atA=; b=C0o s/rrw4Y6uOxz9G+7VOyctT4xTNevFCWUdoakMu1wCVUINrl5QuM5Q8Pl1Z7fghG8 WPHvdaFyMfn+QafhFZRpVV8oovsQSUxxitE3UTJvWrEH5WQt3k+j+SgyMNulmenC zf+26X//lkV926TKXI4Id0ZSigXnfcajWq+Ur9dw= Received: (qmail 73177 invoked by alias); 30 Aug 2018 13:27:42 -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 73147 invoked by uid 89); 30 Aug 2018 13:27:41 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS, URIBL_RED autolearn=ham version=3.3.2 spammy=launch, unpack, UD:omp-low.c, ignores 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, 30 Aug 2018 13:27:39 +0000 Received: from svr-orw-mbx-02.mgc.mentorg.com ([147.34.90.202]) by relay1.mentorg.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-SHA384:256) id 1fvMz2-0007ZG-Kg from ChungLin_Tang@mentor.com ; Thu, 30 Aug 2018 06:27:36 -0700 Received: from [0.0.0.0] (147.34.91.1) by svr-orw-mbx-02.mgc.mentorg.com (147.34.90.202) with Microsoft SMTP Server (TLS) id 15.0.1320.4; Thu, 30 Aug 2018 06:27:33 -0700 Reply-To: From: Chung-Lin Tang To: , Jakub Jelinek , Cesar Philippidis Subject: [PATCH, OpenACC] Properly handle wait clause with no arguments Message-ID: <4f14f976-3677-9f94-2ca7-83f5dc8dd7ae@mentor.com> Date: Thu, 30 Aug 2018 21:27:22 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 Hi, this patch properly handles OpenACC 'wait' clauses without arguments, making it an equivalent of "wait all". (current trunk basically discards and ignores such argument-less wait clauses) This adds additional handling in the pack/unpack of the wait argument across the compiler/libgomp interface, but is done in a matter that doesn't affect binary compatibility. This patch was part of the OpenACC async re-work that was done on the gomp4 branch (later merged to OG7/OG8), see [1]. I'm separating this part out and submitting it first because it's logically independent. [1] https://gcc.gnu.org/ml/gcc-patches/2017-06/msg01842.html Re-tested with offloading to ensure no regressions, is this okay for trunk? Thanks, Chung-Lin 2018-08-30 Chung-Lin Tang gcc/c/ * c-parser.c (c_parser_oacc_clause_wait): Add representation of wait clause without argument as 'wait (GOMP_ASYNC_NOVAL)', adjust comments. gcc/cp/ * parser.c (cp_parser_oacc_clause_wait): Add representation of wait clause without argument as 'wait (GOMP_ASYNC_NOVAL)', adjust comments. gcc/fortran/ * trans-openmp.c (gfc_trans_omp_clauses_1): Add representation of wait clause without argument as 'wait (GOMP_ASYNC_NOVAL)'. gcc/ * omp-low.c (expand_omp_target): Add middle-end support for handling OMP_CLAUSE_WAIT clause with a GOMP_ASYNC_NOVAL(-1) as the argument. include/ * gomp-constants.h (GOMP_LAUNCH_OP_MASK): Define. (GOMP_LAUNCH_PACK): Add bitwise-and of GOMP_LAUNCH_OP_MASK. (GOMP_LAUNCH_OP): Likewise. libgomp/ * oacc-parallel.c (GOACC_parallel_keyed): Interpret launch op as signed 16-bit field, adjust num_waits handling. (GOACC_enter_exit_data): Adjust num_waits handling. (GOACC_update): Adjust num_waits handling. Index: gcc/c/c-parser.c =================================================================== --- gcc/c/c-parser.c (revision 263981) +++ gcc/c/c-parser.c (working copy) @@ -12719,7 +12719,7 @@ c_parser_oacc_clause_tile (c_parser *parser, tree } /* OpenACC: - wait ( int-expr-list ) */ + wait [( int-expr-list )] */ static tree c_parser_oacc_clause_wait (c_parser *parser, tree list) @@ -12728,7 +12728,15 @@ c_parser_oacc_clause_wait (c_parser *parser, tree if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN) list = c_parser_oacc_wait_list (parser, clause_loc, list); + else + { + tree c = build_omp_clause (clause_loc, OMP_CLAUSE_WAIT); + OMP_CLAUSE_DECL (c) = build_int_cst (integer_type_node, GOMP_ASYNC_NOVAL); + OMP_CLAUSE_CHAIN (c) = list; + list = c; + } + return list; } Index: gcc/cp/parser.c =================================================================== --- gcc/cp/parser.c (revision 263981) +++ gcc/cp/parser.c (working copy) @@ -32137,7 +32137,7 @@ cp_parser_oacc_wait_list (cp_parser *parser, locat } /* OpenACC: - wait ( int-expr-list ) */ + wait [( int-expr-list )] */ static tree cp_parser_oacc_clause_wait (cp_parser *parser, tree list) @@ -32144,10 +32144,16 @@ cp_parser_oacc_clause_wait (cp_parser *parser, tre { location_t location = cp_lexer_peek_token (parser->lexer)->location; - if (cp_lexer_peek_token (parser->lexer)->type != CPP_OPEN_PAREN) - return list; + if (cp_lexer_peek_token (parser->lexer)->type == CPP_OPEN_PAREN) + list = cp_parser_oacc_wait_list (parser, location, list); + else + { + tree c = build_omp_clause (location, OMP_CLAUSE_WAIT); - list = cp_parser_oacc_wait_list (parser, location, list); + OMP_CLAUSE_DECL (c) = build_int_cst (integer_type_node, GOMP_ASYNC_NOVAL); + OMP_CLAUSE_CHAIN (c) = list; + list = c; + } return list; } Index: gcc/fortran/trans-openmp.c =================================================================== --- gcc/fortran/trans-openmp.c (revision 263981) +++ gcc/fortran/trans-openmp.c (working copy) @@ -2922,6 +2922,13 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp omp_clauses = c; } } + else if (clauses->wait) + { + c = build_omp_clause (where.lb->location, OMP_CLAUSE_WAIT); + OMP_CLAUSE_DECL (c) = build_int_cst (integer_type_node, GOMP_ASYNC_NOVAL); + OMP_CLAUSE_CHAIN (c) = omp_clauses; + omp_clauses = c; + } if (clauses->num_gangs_expr) { tree num_gangs_var Index: gcc/omp-expand.c =================================================================== --- gcc/omp-expand.c (revision 263981) +++ gcc/omp-expand.c (working copy) @@ -7381,16 +7381,32 @@ expand_omp_target (struct omp_region *region) /* ... push a placeholder. */ args.safe_push (integer_zero_node); + bool noval_seen = false; + tree noval = build_int_cst (integer_type_node, GOMP_ASYNC_NOVAL); + for (; c; c = OMP_CLAUSE_CHAIN (c)) if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_WAIT) { + tree wait_expr = OMP_CLAUSE_WAIT_EXPR (c); + + if (TREE_CODE (wait_expr) == INTEGER_CST + && tree_int_cst_compare (wait_expr, noval) == 0) + { + noval_seen = true; + continue; + } + args.safe_push (fold_convert_loc (OMP_CLAUSE_LOCATION (c), - integer_type_node, - OMP_CLAUSE_WAIT_EXPR (c))); + integer_type_node, wait_expr)); num_waits++; } - if (!tagging || num_waits) + if (noval_seen && num_waits == 0) + args[t_wait_idx] = + (tagging + ? oacc_launch_pack (GOMP_LAUNCH_WAIT, NULL_TREE, GOMP_ASYNC_NOVAL) + : noval); + else if (!tagging || num_waits) { tree len; Index: include/gomp-constants.h =================================================================== --- include/gomp-constants.h (revision 263981) +++ include/gomp-constants.h (working copy) @@ -221,13 +221,14 @@ enum gomp_map_kind #define GOMP_LAUNCH_CODE_SHIFT 28 #define GOMP_LAUNCH_DEVICE_SHIFT 16 #define GOMP_LAUNCH_OP_SHIFT 0 +#define GOMP_LAUNCH_OP_MASK 0xffff #define GOMP_LAUNCH_PACK(CODE,DEVICE,OP) \ (((CODE) << GOMP_LAUNCH_CODE_SHIFT) \ | ((DEVICE) << GOMP_LAUNCH_DEVICE_SHIFT) \ - | ((OP) << GOMP_LAUNCH_OP_SHIFT)) + | (((OP) & GOMP_LAUNCH_OP_MASK) << GOMP_LAUNCH_OP_SHIFT)) #define GOMP_LAUNCH_CODE(X) (((X) >> GOMP_LAUNCH_CODE_SHIFT) & 0xf) #define GOMP_LAUNCH_DEVICE(X) (((X) >> GOMP_LAUNCH_DEVICE_SHIFT) & 0xfff) -#define GOMP_LAUNCH_OP(X) (((X) >> GOMP_LAUNCH_OP_SHIFT) & 0xffff) +#define GOMP_LAUNCH_OP(X) (((X) >> GOMP_LAUNCH_OP_SHIFT) & GOMP_LAUNCH_OP_MASK) #define GOMP_LAUNCH_OP_MAX 0xffff /* Bitmask to apply in order to find out the intended device of a target Index: libgomp/oacc-parallel.c =================================================================== --- libgomp/oacc-parallel.c (revision 263981) +++ libgomp/oacc-parallel.c (working copy) @@ -194,10 +194,14 @@ GOACC_parallel_keyed (int device, void (*fn) (void case GOMP_LAUNCH_WAIT: { - unsigned num_waits = GOMP_LAUNCH_OP (tag); + /* Be careful to cast the op field as a signed 16-bit, and + sign-extend to full integer. */ + int num_waits = ((signed short) GOMP_LAUNCH_OP (tag)); - if (num_waits) + if (num_waits > 0) goacc_wait (async, num_waits, &ap); + else if (num_waits == acc_async_noval) + acc_wait_all_async (async); break; } @@ -351,7 +355,7 @@ GOACC_enter_exit_data (int device, size_t mapnum, || host_fallback) return; - if (num_waits) + if (num_waits > 0) { va_list ap; @@ -359,6 +363,8 @@ GOACC_enter_exit_data (int device, size_t mapnum, goacc_wait (async, num_waits, &ap); va_end (ap); } + else if (num_waits == acc_async_noval) + acc_wait_all_async (async); /* Determine whether "finalize" semantics apply to all mappings of this OpenACC directive. */ @@ -542,7 +548,7 @@ GOACC_update (int device, size_t mapnum, || host_fallback) return; - if (num_waits) + if (num_waits > 0) { va_list ap; @@ -550,6 +556,8 @@ GOACC_update (int device, size_t mapnum, goacc_wait (async, num_waits, &ap); va_end (ap); } + else if (num_waits == acc_async_noval) + acc_wait_all_async (async); acc_dev->openacc.async_set_async_func (async);