From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1534) id 7BF953857831; Sat, 16 Oct 2021 15:51:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7BF953857831 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Tobias Burnus To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/omp/gcc-11] openmp: Handle OpenMP 5.1 simplified OMP_PLACES syntax X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/devel/omp/gcc-11 X-Git-Oldrev: 7b6f0eea7f0e35ce738871a6539ea7f28a0db676 X-Git-Newrev: 4429405a68d0063191efaacc4d14fce5088d60f3 Message-Id: <20211016155126.7BF953857831@sourceware.org> Date: Sat, 16 Oct 2021 15:51:26 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 16 Oct 2021 15:51:26 -0000 https://gcc.gnu.org/g:4429405a68d0063191efaacc4d14fce5088d60f3 commit 4429405a68d0063191efaacc4d14fce5088d60f3 Author: Jakub Jelinek Date: Fri Oct 15 23:38:43 2021 +0200 openmp: Handle OpenMP 5.1 simplified OMP_PLACES syntax In addition to adding ll_caches and numa_domain abstract names to OMP_PLACES syntax, OpenMP 5.1 also added one syntax simplification: https://github.com/OpenMP/spec/issues/2080 https://github.com/OpenMP/spec/pull/2081 in particular that in the grammar place non-terminal is now not only { res-list } but also res (i.e. a non-negative integer), which stands as a shortcut for { res } So, one can specify OMP_PLACES=0,4,8,12 with the meaning OMP_PLACES={0},{4},{8},{12} or OMP_PLACES=0:4 instead of OMP_PLACES={0}:4 or OMP_PLACES={0},{1},{2},{3} etc. This patch implements that. 2021-10-15 Jakub Jelinek * env.c (parse_one_place): Handle non-negative-number the same as { non-negative-number }. Reject even !number:1 and !number:1:stride or !place:1 or !place:1:stride instead of just length other than 1. * libgomp.texi (OpenMP 5.1): Document OMP_PLACES syntax extensions and OMP_NUM_TEAMS/OMP_TEAMS_THREAD_LIMIT and omp_{set_num,get_max}_teams/omp_{s,g}et_teams_thread_limit features as implemented. * testsuite/libgomp.c/affinity-1.c: Add a test for the 5.1 place simplified syntax. (cherry picked from commit 4a0fed0c0c7241562eaa5f1a4c916b689429ad86) Diff: --- libgomp/ChangeLog.omp | 16 +++++++++++++++ libgomp/env.c | 35 ++++++++++++++++++++++++-------- libgomp/libgomp.texi | 6 +++--- libgomp/testsuite/libgomp.c/affinity-1.c | 6 ++++-- 4 files changed, 49 insertions(+), 14 deletions(-) diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp index 937eeb3e2cf..c149bc9a88b 100644 --- a/libgomp/ChangeLog.omp +++ b/libgomp/ChangeLog.omp @@ -1,3 +1,19 @@ +2021-10-15 Tobias Burnus + + Backported from master: + 2021-10-15 Jakub Jelinek + + * env.c (parse_one_place): Handle non-negative-number the same + as { non-negative-number }. Reject even !number:1 and + !number:1:stride or !place:1 or !place:1:stride instead of just + length other than 1. + * libgomp.texi (OpenMP 5.1): Document OMP_PLACES syntax extensions + and OMP_NUM_TEAMS/OMP_TEAMS_THREAD_LIMIT and + omp_{set_num,get_max}_teams/omp_{s,g}et_teams_thread_limit features + as implemented. + * testsuite/libgomp.c/affinity-1.c: Add a test for the 5.1 place + simplified syntax. + 2021-10-15 Tobias Burnus Backported from master: diff --git a/libgomp/env.c b/libgomp/env.c index b0acacb5783..df10ff656b6 100644 --- a/libgomp/env.c +++ b/libgomp/env.c @@ -546,6 +546,7 @@ parse_one_place (char **envp, bool *negatep, unsigned long *lenp, long stride = 1; int pass; bool any_negate = false; + bool has_braces = true; *negatep = false; while (isspace ((unsigned char) *env)) ++env; @@ -557,12 +558,28 @@ parse_one_place (char **envp, bool *negatep, unsigned long *lenp, ++env; } if (*env != '{') - return false; - ++env; - while (isspace ((unsigned char) *env)) - ++env; + { + char *end; + unsigned long this_num; + + errno = 0; + this_num = strtoul (env, &end, 10); + if (errno || end == env) + return false; + env = end - 1; + has_braces = false; + if (gomp_places_list + && !gomp_affinity_add_cpus (p, this_num, 1, 1, false)) + return false; + } + else + { + ++env; + while (isspace ((unsigned char) *env)) + ++env; + } start = env; - for (pass = 0; pass < (any_negate ? 2 : 1); pass++) + for (pass = 0; pass < (any_negate ? 2 : has_braces); pass++) { env = start; do @@ -590,6 +607,8 @@ parse_one_place (char **envp, bool *negatep, unsigned long *lenp, if (*env == ':') { ++env; + if (this_negate) + return false; while (isspace ((unsigned char) *env)) ++env; errno = 0; @@ -612,8 +631,6 @@ parse_one_place (char **envp, bool *negatep, unsigned long *lenp, ++env; } } - if (this_negate && this_len != 1) - return false; if (gomp_places_list && pass == this_negate) { if (this_negate) @@ -640,6 +657,8 @@ parse_one_place (char **envp, bool *negatep, unsigned long *lenp, if (*env == ':') { char *end; + if (*negatep) + return false; ++env; while (isspace ((unsigned char) *env)) ++env; @@ -663,8 +682,6 @@ parse_one_place (char **envp, bool *negatep, unsigned long *lenp, ++env; } } - if (*negatep && len != 1) - return false; *envp = env; *lenp = len; *stridep = stride; diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi index 0cc988f23a8..38f9f4ade73 100644 --- a/libgomp/libgomp.texi +++ b/libgomp/libgomp.texi @@ -309,7 +309,7 @@ The OpenMP 4.5 specification is fully supported. @item @code{present} argument to @code{defaultmap} clause @tab N @tab @item @code{omp_set_num_teams}, @code{omp_set_teams_thread_limit}, @code{omp_get_max_teams}, @code{omp_get_teams_thread_limit} runtime - routines @tab N @tab + routines @tab Y @tab @item @code{omp_target_is_accessible} runtime routine @tab N @tab @item @code{omp_target_memcpy_async} and @code{omp_target_memcpy_rect_async} runtime routines @tab N @tab @@ -328,9 +328,9 @@ The OpenMP 4.5 specification is fully supported. @code{ompt_callback_target_emi_t}, @code{ompt_callback_target_map_emi_t} and @code{ompt_callback_target_submit_emi_t} @tab N @tab @item @code{ompt_callback_error_t} type @tab N @tab -@item @code{OMP_PLACES} syntax was extension @tab N @tab +@item @code{OMP_PLACES} syntax extensions @tab Y @tab @item @code{OMP_NUM_TEAMS} and @code{OMP_TEAMS_THREAD_LIMIT} environment - variables @tab N @tab + variables @tab Y @tab @end multitable @unnumberedsubsec Other new OpenMP 5.1 features diff --git a/libgomp/testsuite/libgomp.c/affinity-1.c b/libgomp/testsuite/libgomp.c/affinity-1.c index 574a9f7b69a..1039e3b9c96 100644 --- a/libgomp/testsuite/libgomp.c/affinity-1.c +++ b/libgomp/testsuite/libgomp.c/affinity-1.c @@ -48,7 +48,7 @@ struct place }; struct places { - char name[40]; + char name[50]; int count; struct place places[8]; } places_array[] = { @@ -62,7 +62,9 @@ struct places { { 1, 1 }, { 2, 1 }, { 3, 1 }, { 4, 1 }, { 5, 1 }, { 6, 1 }, { 7, 1 } } }, { "{0,1},{3,2,4},{6,5,!6},{6},{7:2:-1,!6}", 5, - { { 0, 2 }, { 2, 3 }, { 5, 1 }, { 6, 1 }, { 7, 1 } } } + { { 0, 2 }, { 2, 3 }, { 5, 1 }, { 6, 1 }, { 7, 1 } } }, + { "1,2,{2,3,!2},3,3,!3,!{5:3:-1,!4,!5},{4},5,!4,!5", 3, + { { 1, 1 }, { 2, 1 }, { 3, 1 } } } }; unsigned long contig_cpucount;