From: Jakub Jelinek Date: Fri, 15 Oct 2021 14:35:57 +0000 (+0200) Subject: openmp: Handle OpenMP 5.1 simplified OMP_PLACES syntax X-Git-Tag: upstream/12.2.0~4257 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4a0fed0c0c7241562eaa5f1a4c916b689429ad86;p=platform%2Fupstream%2Fgcc.git 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. --- diff --git a/libgomp/env.c b/libgomp/env.c index b0acacb..df10ff6 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 af25e9d..e9fa8ba 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 574a9f7..1039e3b 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;