From patchwork Wed Jun 29 19:54:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 55542 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0F22C383EC6B for ; Wed, 29 Jun 2022 19:55:24 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa4.mentor.iphmx.com (esa4.mentor.iphmx.com [68.232.137.252]) by sourceware.org (Postfix) with ESMTPS id 1FA53383F971 for ; Wed, 29 Jun 2022 19:55:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1FA53383F971 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.92,231,1650960000"; d="diff'?scan'208";a="78052514" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 29 Jun 2022 11:55:02 -0800 IronPort-SDR: Iv1oj7xWhOAuC2WvAnlmE+94mCeJGMoMRdrqUEGPtCEgIVHAyrqX80l4hKiGQlei2tJvw2K7BE tJ3wTtVHBrFPvxF1rFluQt1rOF+4/FbIYJwsiRIdzbqnd5q/pMzifJgBggYUjERYZEqf8B5aC7 YfloEoZIXsYL5cb5I7e069PwUnfaprcR/CanAcLbhmN7WgASJHCY7Vkv61Sjm8CIBJm5U2Rj/N gJC3Uuntp2gnhIIV3YoalAj7YA//4NAxLuvUqLih8vu4pAzWU+vZSKZJOqTX9XuLDYNYL5bqT3 Trc= Message-ID: Date: Wed, 29 Jun 2022 21:54:56 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Content-Language: en-US To: Jakub Jelinek , gcc-patches From: Tobias Burnus Subject: [Patch] OpenMP: Prepare omp-* for ancestor:1 handling X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-05.mgc.mentorg.com (139.181.222.5) To svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, 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: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Currently, this is a rather useless patch - even though it helps to reduce the number of local patches I have. Due to the printed sorry, adding a testcase with -fdump-tree-* is also not possible, yet. For reverse offload, the plan is to call GOMP_target_ext inside the on the device, passing 'device(omp_initial_device)' alias device(GOMP_DEVICE_HOST_FALLBACK) to the target device's libgomp. The pointer to the generated target-region function is then passed as argument. However, that only works if that function is not nullified ... The reason that nullifying was added is: https://gcc.gnu.org/PR100573 https://gcc.gnu.org/r12-1066-g95d67762171f83277a5700b270c0d1e2756f83f4 https://gcc.gnu.org/pipermail/gcc-patches/2021-May/571285.html Note: Instead of just checking for GOMP_DEVICE_HOST_FALLBACK, more effort could be done, e.g. by setting some attribute on the generated function and then check for check for it. Example: 'omp target device_ancestor' + using lookup_attribute). That's what's done in the second variant. OK for mainline (which variant)? Or do you prefer to wait for a more complete patch? Tobias PS: Reverse offload - still to do: - 'requires' patch - Generate two variants of the target-region function: an empty version on the device (just to have a pointer address in the offload_func table) and the full version (on the host only) Those together are sufficient for a omp_get_num_device() == 0 version (implied by 'required reverse_offload' not being fulfilled by any device). For a more useful implementation, more work inside libgomp is required. ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955 OpenMP: Prepare omp-* for ancestor:1 handling gcc/ChangeLog: * omp-expand.cc (expand_omp_target): Set device to GOMP_DEVICE_HOST_FALLBACK for ancestor. * omp-low.cc (scan_omp_target): Add 'omp target device_ancestor' attribute to generated target-region function for ancestor:1. * omp-offload.cc (pass_omp_target_link::execute): Don't nullify function pointer for ancestor:1. gcc/omp-expand.cc | 6 +++++- gcc/omp-low.cc | 6 ++++++ gcc/omp-offload.cc | 9 +++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/gcc/omp-expand.cc b/gcc/omp-expand.cc index 1023c56fc3d..dc0a963e9e3 100644 --- a/gcc/omp-expand.cc +++ b/gcc/omp-expand.cc @@ -10005,7 +10005,11 @@ expand_omp_target (struct omp_region *region) need_device_adjustment = true; device_loc = OMP_CLAUSE_LOCATION (c); if (OMP_CLAUSE_DEVICE_ANCESTOR (c)) - sorry_at (device_loc, "% not yet supported"); + { + device = build_int_cst (integer_type_node, + GOMP_DEVICE_HOST_FALLBACK); + sorry_at (device_loc, "% not yet supported"); + } } else { diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc index b9d5529f212..140ef229cc0 100644 --- a/gcc/omp-low.cc +++ b/gcc/omp-low.cc @@ -3094,6 +3094,12 @@ scan_omp_target (gomp_target *stmt, omp_context *outer_ctx) if (offloaded) { create_omp_child_function (ctx, false); + tree c = omp_find_clause (gimple_omp_target_clauses (ctx->stmt), + OMP_CLAUSE_DEVICE); + if (c && OMP_CLAUSE_DEVICE_ANCESTOR (c)) + DECL_ATTRIBUTES (ctx->cb.dst_fn) + = tree_cons (get_identifier ("omp target device_ancestor"), + NULL_TREE, DECL_ATTRIBUTES (ctx->cb.dst_fn)); gimple_omp_target_set_child_fn (stmt, ctx->cb.dst_fn); } diff --git a/gcc/omp-offload.cc b/gcc/omp-offload.cc index 3a89119371c..a6c108aef30 100644 --- a/gcc/omp-offload.cc +++ b/gcc/omp-offload.cc @@ -2803,6 +2803,15 @@ pass_omp_target_link::execute (function *fun) { if (gimple_call_builtin_p (gsi_stmt (gsi), BUILT_IN_GOMP_TARGET)) { + tree dev = gimple_call_arg (gsi_stmt (gsi), 0); + tree fn = gimple_call_arg (gsi_stmt (gsi), 1); + if (POINTER_TYPE_P (TREE_TYPE (fn))) + fn = TREE_OPERAND (fn, 0); + if (TREE_CODE (dev) == INTEGER_CST + && wi::to_wide (dev) == GOMP_DEVICE_HOST_FALLBACK + && lookup_attribute ("omp target device_ancestor", + DECL_ATTRIBUTES (fn)) != NULL_TREE) + continue; /* ancestor:1 */ /* Nullify the second argument of __builtin_GOMP_target_ext. */ gimple_call_set_arg (gsi_stmt (gsi), 1, null_pointer_node); update_stmt (gsi_stmt (gsi));