From patchwork Thu Jul 2 16:15:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Stubbs X-Patchwork-Id: 1321663 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yNVW5jDdz9sR4 for ; Fri, 3 Jul 2020 02:15:30 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A5429386F81C; Thu, 2 Jul 2020 16:15:28 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa1.mentor.iphmx.com (esa1.mentor.iphmx.com [68.232.129.153]) by sourceware.org (Postfix) with ESMTPS id 7719F386F803 for ; Thu, 2 Jul 2020 16:15:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7719F386F803 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Andrew_Stubbs@mentor.com IronPort-SDR: nGDrCfEyP+MXzRTF0HLj/2wzjE9aTzTqJKtvsp+iduNtXwVnyorgDV/5RD8pAkJjA9FmGVNFE3 6PdKqiAH/RgYitpJp2peP8unf30mteRQjmUvXmDEXHaNM55YCI5uih5nHntRlRV3wMmyM8wmFJ BJJVnZ+sUmHHbC+msbVPuTzPU5VQlDIa0pdAPOSeyho+2exi5V9PoQdhmbZQSTgVx/+2W7x38n mmBdAryLTuo8UaD1gl00BV2jK+50LEVWd1RXoTIpcIrOYz0ggnpus2JemXLtxGi6TTeYSMYhNH 870= X-IronPort-AV: E=Sophos;i="5.75,304,1589270400"; d="scan'208";a="52683988" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 02 Jul 2020 08:15:25 -0800 IronPort-SDR: RiOVqYZIIqP6XaOrIPyVzgqBMj7f3YfhYtBh8qah2bcb9FostavmvVl1+Bp8k2ueg+edfHFlBp wm431bO3MXZfTXSXPqSMv71DpjTs6dWK6j4tZi90DlvbcGtOMmW6nHY92WrWWMJf82Q2eY5wiN bYwO+TSNPcVnUAPwsun57c4g+fdTHZ3cpLXOz0+G9tAbPWz7yHBqp8gXB4/nlJ6R3EQk0EDD6R /rZVlIS+iURNrv+R0TmVJdQDnMP+01+kSs/XYfvSMJayXZh6UIauvd+QBQI/BmsAzGepahdD9m LpA= From: Andrew Stubbs Subject: [PATCH] OpenMP: Disable GPU threads when only teams are used To: "gcc-patches@gcc.gnu.org" Message-ID: <7c4bb857-a078-0c43-d853-6729cfa07221@codesourcery.com> Date: Thu, 2 Jul 2020 17:15:20 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 Content-Language: en-GB X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-08.mgc.mentorg.com (139.181.222.8) To SVR-IES-MBX-03.mgc.mentorg.com (139.181.222.3) X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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@gcc.gnu.org Sender: "Gcc-patches" This patch, originally by Kwok, auto-adjusts the default OpenMP target arguments to set num_threads(1) when there are no parallel regions. There may still be multiple teams in this case. The result is that libgomp will not attempt to launch GPU threads that will never get used. OK to commit? Andrew OpenMP: Disable GPU threads when only teams are used gcc/ * omp-expand.c (contains_threads): New. (get_target_arguments): Add region argument. Set number of threads to one if region does not contain threads. (expand_omp_target): Add extra argument in call to get_target_arguments. Co-Authored-By: Andrew Stubbs diff --git a/gcc/omp-expand.c b/gcc/omp-expand.c index 0f07e51f7e8..6afe18d5ee0 100644 --- a/gcc/omp-expand.c +++ b/gcc/omp-expand.c @@ -8461,10 +8461,22 @@ push_target_argument_according_to_value (gimple_stmt_iterator *gsi, int device, } } +static bool +contains_threads (struct omp_region *region) +{ + if (!region) + return false; + + return region->type == GIMPLE_OMP_PARALLEL + || contains_threads (region->inner) + || contains_threads (region->next); +} + /* Create an array of arguments that is then passed to GOMP_target. */ static tree -get_target_arguments (gimple_stmt_iterator *gsi, gomp_target *tgt_stmt) +get_target_arguments (gimple_stmt_iterator *gsi, gomp_target *tgt_stmt, + struct omp_region *region) { auto_vec args; tree clauses = gimple_omp_target_clauses (tgt_stmt); @@ -8481,6 +8493,11 @@ get_target_arguments (gimple_stmt_iterator *gsi, gomp_target *tgt_stmt) t = OMP_CLAUSE_THREAD_LIMIT_EXPR (c); else t = integer_minus_one_node; + + if (tree_int_cst_equal (t, integer_zero_node) + && !contains_threads (region->inner)) + t = integer_one_node; + push_target_argument_according_to_value (gsi, GOMP_TARGET_ARG_DEVICE_ALL, GOMP_TARGET_ARG_THREAD_LIMIT, t, &args); @@ -8994,7 +9011,7 @@ expand_omp_target (struct omp_region *region) depend = build_int_cst (ptr_type_node, 0); args.quick_push (depend); if (start_ix == BUILT_IN_GOMP_TARGET) - args.quick_push (get_target_arguments (&gsi, entry_stmt)); + args.quick_push (get_target_arguments (&gsi, entry_stmt, region)); break; case BUILT_IN_GOACC_PARALLEL: if (lookup_attribute ("oacc serial", DECL_ATTRIBUTES (child_fn)) != NULL)