From patchwork Fri Nov 6 20:13:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kwok Cheung Yeung X-Patchwork-Id: 1395904 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=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4CSWmc6Qbjz9sRR for ; Sat, 7 Nov 2020 07:13:36 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7350C3A5C02B; Fri, 6 Nov 2020 20:13:31 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) by sourceware.org (Postfix) with ESMTPS id B75F53851C35 for ; Fri, 6 Nov 2020 20:13:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B75F53851C35 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Kwok_Yeung@mentor.com IronPort-SDR: vayrT+aFlURkGNNDY2SIDsUHy09eE6ayoRYdwbZufxgDu5etnsqN437DIEyFybc78Dwh5peR+G Al/eL3S95mrvBmC8gGv2r2mqCTlxvA/sc/BcMJFBfniqJWJ8a6NWj51GTolNlhsVqBUhfenfmO /VmXsOXZ1TY4m61QZR+qiF9jGB03xPJeWxWVel/IWi5Rk7dxYDCbHrJ9zJQUntNHNC4CDI24cq 2XGJBxQkstbTrNieULkPAgNXC3K5wEFZMJkQciHMoOGsRpWgiCm+L1BswWO75dCa+KsXeZKAD8 bfo= X-IronPort-AV: E=Sophos;i="5.77,457,1596528000"; d="scan'208";a="54788795" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 06 Nov 2020 12:13:26 -0800 IronPort-SDR: fWF3STpBLk7zaOEcQcA7X3WIrMrghLGhTh4sPVkT2jJXWfBApZjLXnJEAsx2148rgWPZtBBMBh 9lZOz7YIufgzskwn50aD5caY8kbpdf7wjU7cbocTzwTH+v5nsqSXq/Yta7Xb8rrEwDnYX60pJf Zo3Hf1fU6jXEzRScWvGuMT1MykoA9vWKgeUB5tBzFNWHXxMyqHNWPyDmrf8eO/xr7Tghwp7RDo 3SgeMh7Zh5++SJdtzK6t7mHQ9vXmjkSIgb3AQ1WF+5nbNQdl7G7p2i3BoZgU02Dpg7oxJ6lqa0 lQo= From: Kwok Cheung Yeung Subject: [PATCH] openmp: Retire nest-var ICV To: jakub Jelinek , GCC Patches Message-ID: <4ef1a10a-7c14-f8ea-a8e8-d68274486039@codesourcery.com> Date: Fri, 6 Nov 2020 20:13:17 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.4.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-04.mgc.mentorg.com (139.181.222.4) X-Spam-Status: No, score=-12.8 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" Hello In addition to deprecating the omp_(get|set)_nested() functions and OMP_NESTED environment variable, OpenMP 5.0 also removes the nest-var ICV altogether, defining it in terms of the max-active-levels-var ICV instead. This patch removes the ICV, and implements the handling of omp_(get|set)_nested() in terms of max-active-levels-var as defined in the spec. The initial value of max-active-levels-var now depends on the number of items in OMP_NUM_THREADS and OMP_PROC_BIND as defined in section 2.5.2 of the spec. OMP_NESTED now changes the value of max-active-levels-var. If OMP_NESTED is false and OMP_MAX_ACTIVE_LEVELS is > 1, I have opted to use the value specified by OMP_MAX_ACTIVE_LEVELS, as OMP_NESTED is deprecated in OpenMP 5.0 (the spec says this is implementation defined in section 6.9). The default value of max-active-levels-var is implementation defined (section 2.5.2). It was previously set to the maximum supported number, but I think it should be 1 now, since OMP_NESTED defaults to false on OpenMP 4.5, and this replicates that behaviour. This change regresses the testcase libgomp.c/target-5.c because nested-var is per data environment, while max-active-levels-var is per-device. The change in semantics causes the test for the nesting setting to fail, because now any changes to the nesting setting apply to the whole device, and not just to the current data environment. I just deleted this part of the testing as the test looks like it is testing per data environment ICVs. Bootstrapped on x86_64 with no offloading, and libgomp testing carried out with nvptx offloading with no regressions. Okay for trunk? Thanks Kwok commit aad8afea37b33b4d5836b2b64be8f4dab6d74509 Author: Kwok Cheung Yeung Date: Wed Nov 4 15:34:12 2020 -0800 openmp: Retire nest-var ICV for OpenMP 5.0 This removes the nest-var ICV, expressing nesting in terms of the max-active-levels-var ICV instead. 2020-11-06 Kwok Cheung Yeung libgomp/ * env.c (gomp_global_icv): Remove nest_var field. (gomp_max_active_levels_var): Initialize to 1. (parse_boolean): Return true on success. (handle_omp_display_env): Express OMP_NESTED in terms of gomp_max_active_levels_var. (initialize_env): Set gomp_max_active_levels_var from OMP_MAX_ACTIVE_LEVELS, OMP_NESTED, OMP_NUM_THREADS and OMP_PROC_BIND. * icv.c (omp_set_nested): Express in terms of gomp_max_active_levels_var. (omp_get_nested): Likewise. * libgomp.h (struct gomp_task_icv): Remove nest_var field. * parallel.c (gomp_resolve_num_threads): Replace reference to nest_var with gomp_max_active_levels_var. * testsuite/libgomp.c/target-5.c: Remove additional options. (main): Remove references to omp_get_nested and omp_set_nested. diff --git a/libgomp/env.c b/libgomp/env.c index ab22525..75d0fe2 100644 --- a/libgomp/env.c +++ b/libgomp/env.c @@ -68,12 +68,11 @@ struct gomp_task_icv gomp_global_icv = { .run_sched_chunk_size = 1, .default_device_var = 0, .dyn_var = false, - .nest_var = false, .bind_var = omp_proc_bind_false, .target_data = NULL }; -unsigned long gomp_max_active_levels_var = gomp_supported_active_levels; +unsigned long gomp_max_active_levels_var = 1; bool gomp_cancel_var = false; enum gomp_target_offload_t gomp_target_offload_var = GOMP_TARGET_OFFLOAD_DEFAULT; @@ -959,16 +958,17 @@ parse_spincount (const char *name, unsigned long long *pvalue) } /* Parse a boolean value for environment variable NAME and store the - result in VALUE. */ + result in VALUE. Return true if one was present and it was + successfully parsed. */ -static void +static bool parse_boolean (const char *name, bool *value) { const char *env; env = getenv (name); if (env == NULL) - return; + return false; while (isspace ((unsigned char) *env)) ++env; @@ -987,7 +987,11 @@ parse_boolean (const char *name, bool *value) while (isspace ((unsigned char) *env)) ++env; if (*env != '\0') - gomp_error ("Invalid value for environment variable %s", name); + { + gomp_error ("Invalid value for environment variable %s", name); + return false; + } + return true; } /* Parse the OMP_WAIT_POLICY environment variable and return the value. */ @@ -1252,7 +1256,7 @@ handle_omp_display_env (unsigned long stacksize, int wait_policy) fprintf (stderr, " OMP_DYNAMIC = '%s'\n", gomp_global_icv.dyn_var ? "TRUE" : "FALSE"); fprintf (stderr, " OMP_NESTED = '%s'\n", - gomp_global_icv.nest_var ? "TRUE" : "FALSE"); + gomp_max_active_levels_var > 1 ? "TRUE" : "FALSE"); fprintf (stderr, " OMP_NUM_THREADS = '%lu", gomp_global_icv.nthreads_var); for (i = 1; i < gomp_nthreads_var_list_len; i++) @@ -1417,16 +1421,11 @@ initialize_env (void) parse_schedule (); parse_boolean ("OMP_DYNAMIC", &gomp_global_icv.dyn_var); - parse_boolean ("OMP_NESTED", &gomp_global_icv.nest_var); parse_boolean ("OMP_CANCELLATION", &gomp_cancel_var); parse_boolean ("OMP_DISPLAY_AFFINITY", &gomp_display_affinity_var); parse_int ("OMP_DEFAULT_DEVICE", &gomp_global_icv.default_device_var, true); parse_target_offload ("OMP_TARGET_OFFLOAD", &gomp_target_offload_var); parse_int ("OMP_MAX_TASK_PRIORITY", &gomp_max_task_priority_var, true); - parse_unsigned_long ("OMP_MAX_ACTIVE_LEVELS", &gomp_max_active_levels_var, - true); - if (gomp_max_active_levels_var > gomp_supported_active_levels) - gomp_max_active_levels_var = gomp_supported_active_levels; gomp_def_allocator = parse_allocator (); if (parse_unsigned_long ("OMP_THREAD_LIMIT", &thread_limit_var, false)) { @@ -1451,6 +1450,23 @@ initialize_env (void) &gomp_bind_var_list_len) && gomp_global_icv.bind_var == omp_proc_bind_false) ignore = true; + if (parse_unsigned_long ("OMP_MAX_ACTIVE_LEVELS", + &gomp_max_active_levels_var, true)) + { + if (gomp_max_active_levels_var > gomp_supported_active_levels) + gomp_max_active_levels_var = gomp_supported_active_levels; + } + else + { + bool nested = true; + + /* OMP_NESTED is deprecated in OpenMP 5.0. */ + if (parse_boolean ("OMP_NESTED", &nested)) + gomp_max_active_levels_var = nested ? gomp_supported_active_levels + : 1; + else if (gomp_nthreads_var_list_len > 1 || gomp_bind_var_list_len > 1) + gomp_max_active_levels_var = gomp_supported_active_levels; + } /* Make sure OMP_PLACES and GOMP_CPU_AFFINITY env vars are always parsed if present in the environment. If OMP_PROC_BIND was set explicitly to false, don't populate places list though. If places diff --git a/libgomp/icv.c b/libgomp/icv.c index 8df15e3..f54ccb1 100644 --- a/libgomp/icv.c +++ b/libgomp/icv.c @@ -56,15 +56,16 @@ omp_get_dynamic (void) void omp_set_nested (int val) { - struct gomp_task_icv *icv = gomp_icv (true); - icv->nest_var = val; + if (val) + gomp_max_active_levels_var = gomp_supported_active_levels; + else if (gomp_max_active_levels_var > 1) + gomp_max_active_levels_var = 1; } int omp_get_nested (void) { - struct gomp_task_icv *icv = gomp_icv (false); - return icv->nest_var; + return gomp_max_active_levels_var > 1; } #pragma GCC diagnostic pop diff --git a/libgomp/libgomp.h b/libgomp/libgomp.h index da7ac03..05aa1e4 100644 --- a/libgomp/libgomp.h +++ b/libgomp/libgomp.h @@ -428,7 +428,6 @@ struct gomp_task_icv int default_device_var; unsigned int thread_limit_var; bool dyn_var; - bool nest_var; char bind_var; /* Internal ICV. */ struct target_mem_desc *target_data; diff --git a/libgomp/parallel.c b/libgomp/parallel.c index 2fe4f573..9629470 100644 --- a/libgomp/parallel.c +++ b/libgomp/parallel.c @@ -53,7 +53,7 @@ gomp_resolve_num_threads (unsigned specified, unsigned count) /* Accelerators with fixed thread counts require this to return 1 for nested parallel regions. */ #if !defined(__AMDGCN__) && !defined(__nvptx__) - && !icv->nest_var + && gomp_max_active_levels_var <= 1 #endif ) return 1; diff --git a/libgomp/testsuite/libgomp.c/target-5.c b/libgomp/testsuite/libgomp.c/target-5.c index 21a69ea..ec31f89 100644 --- a/libgomp/testsuite/libgomp.c/target-5.c +++ b/libgomp/testsuite/libgomp.c/target-5.c @@ -1,5 +1,3 @@ -/* { dg-additional-options "-Wno-deprecated-declarations" } */ - #include #include @@ -7,17 +5,14 @@ int main () { int d_o = omp_get_dynamic (); - int n_o = omp_get_nested (); omp_sched_t s_o; int c_o; omp_get_schedule (&s_o, &c_o); int m_o = omp_get_max_threads (); omp_set_dynamic (1); - omp_set_nested (1); omp_set_schedule (omp_sched_static, 2); omp_set_num_threads (4); int d = omp_get_dynamic (); - int n = omp_get_nested (); omp_sched_t s; int c; omp_get_schedule (&s, &c); @@ -30,13 +25,11 @@ main () int c_c; omp_get_schedule (&s_c, &c_c); if (d_o != omp_get_dynamic () - || n_o != omp_get_nested () || s_o != s_c || c_o != c_c || m_o != omp_get_max_threads ()) abort (); omp_set_dynamic (0); - omp_set_nested (0); omp_set_schedule (omp_sched_dynamic, 4); omp_set_num_threads (2); if (!omp_is_initial_device ()) @@ -48,7 +41,6 @@ main () int c_c; omp_get_schedule (&s_c, &c_c); if (d != omp_get_dynamic () - || n != omp_get_nested () || s != s_c || c != c_c || m != omp_get_max_threads ()) @@ -60,13 +52,11 @@ main () int c_c; omp_get_schedule (&s_c, &c_c); if (d_o != omp_get_dynamic () - || n_o != omp_get_nested () || s_o != s_c || c_o != c_c || m_o != omp_get_max_threads ()) abort (); omp_set_dynamic (0); - omp_set_nested (0); omp_set_schedule (omp_sched_dynamic, 4); omp_set_num_threads (2); if (!omp_is_initial_device ()) @@ -76,7 +66,6 @@ main () abort (); omp_get_schedule (&s_c, &c_c); if (d != omp_get_dynamic () - || n != omp_get_nested () || s != s_c || c != c_c || m != omp_get_max_threads ())