Re: [PATCH] openmp: Add support for omp_get_supported_active_levels

2020-10-20 Thread Tobias Burnus

See patch and thread at
https://gcc.gnu.org/pipermail/gcc-patches/2020-October/556570.html

Tobias

On 10/20/20 3:51 PM, David Edelsohn via Gcc-patches wrote:

This patch broke bootstrap on AIX.

/nasfarm/edelsohn/src/src/libgomp/target.c: In function
'gomp_target_init.part.':
/nasfarm/edelsohn/src/src/libgomp/target.c:3367:45: error: array
subscript [-19877956975980120, 19877956975980120] is outside array
bounds of 'struct gomp_device_descr[0]' [-Werror=array-bounds]
  3367 |   devices_s[num_devices_after_openmp++] = devices[i];
   |   ~~^~~~
/nasfarm/edelsohn/src/src/libgomp/target.c:3353:7: note: referencing
an object of size 0 allocated by 'malloc'
  3353 | = malloc (num_devices * sizeof (struct gomp_device_descr));
   |   ^~~~
/nasfarm/edelsohn/src/src/libgomp/target.c:3363:39: error: array
subscript [-19877956975980120, 19877956975980120] is outside array
bounds of 'struct gomp_device_descr[0]' [-Werror=array-bounds]
  3363 |   devices_s[num_devices_openmp++] = devices[i];
   |   ^~~~
/nasfarm/edelsohn/src/src/libgomp/target.c:3353:7: note: referencing
an object of size 0 allocated by 'malloc'
  3353 | = malloc (num_devices * sizeof (struct gomp_device_descr));
   |   ^~~~

-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter


Re: [PATCH] openmp: Add support for omp_get_supported_active_levels

2020-10-20 Thread David Edelsohn via Gcc-patches
This patch broke bootstrap on AIX.

/nasfarm/edelsohn/src/src/libgomp/target.c: In function
'gomp_target_init.part.':
/nasfarm/edelsohn/src/src/libgomp/target.c:3367:45: error: array
subscript [-19877956975980120, 19877956975980120] is outside array
bounds of 'struct gomp_device_descr[0]' [-Werror=array-bounds]
 3367 |   devices_s[num_devices_after_openmp++] = devices[i];
  |   ~~^~~~
/nasfarm/edelsohn/src/src/libgomp/target.c:3353:7: note: referencing
an object of size 0 allocated by 'malloc'
 3353 | = malloc (num_devices * sizeof (struct gomp_device_descr));
  |   ^~~~
/nasfarm/edelsohn/src/src/libgomp/target.c:3363:39: error: array
subscript [-19877956975980120, 19877956975980120] is outside array
bounds of 'struct gomp_device_descr[0]' [-Werror=array-bounds]
 3363 |   devices_s[num_devices_openmp++] = devices[i];
  |   ^~~~
/nasfarm/edelsohn/src/src/libgomp/target.c:3353:7: note: referencing
an object of size 0 allocated by 'malloc'
 3353 | = malloc (num_devices * sizeof (struct gomp_device_descr));
  |   ^~~~


Re: [PATCH] openmp: Add support for omp_get_supported_active_levels

2020-10-15 Thread Jakub Jelinek via Gcc-patches
On Thu, Oct 15, 2020 at 10:38:56AM +0100, Kwok Cheung Yeung wrote:
> Okay to apply this patch?

Ok, thanks.

> commit 3f6f8808f74598e274bfb8245c08a5428ee1b3fd
> Author: Kwok Cheung Yeung 
> Date:   Thu Oct 15 02:32:09 2020 -0700
> 
> Amend documentation for omp_get_max_active_levels and 
> omp_get_supported_active_levels
> 
> 2020-10-15  Kwok Cheung Yeung  
> 
>   libgomp/
>   * libgomp.texi (omp_get_max_active_levels): Modify description.
>   (omp_get_supported_active_levels): Make descriptions consistent.
> 
> diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
> index 4a5e56f..7c6d5fd 100644
> --- a/libgomp/libgomp.texi
> +++ b/libgomp/libgomp.texi
> @@ -167,7 +167,7 @@ linkage, and do not throw exceptions.
>  * omp_get_default_device::  Get the default device for target regions
>  * omp_get_dynamic:: Dynamic teams setting
>  * omp_get_level::   Number of parallel regions
> -* omp_get_max_active_levels::   Maximum number of active regions
> +* omp_get_max_active_levels::   Current maximum number of active regions
>  * omp_get_max_task_priority::   Maximum task priority value that can be set
>  * omp_get_max_threads:: Maximum number of threads of parallel region
>  * omp_get_nested::  Nested parallel regions
> @@ -177,7 +177,7 @@ linkage, and do not throw exceptions.
>  * omp_get_num_threads:: Size of the active team
>  * omp_get_proc_bind::   Whether theads may be moved between CPUs
>  * omp_get_schedule::Obtain the runtime scheduling method
> -* omp_get_supported_active_levels:: Maximum number of active levels supported
> +* omp_get_supported_active_levels:: Maximum number of active regions 
> supported
>  * omp_get_team_num::Get team number
>  * omp_get_team_size::   Number of threads in a team
>  * omp_get_thread_limit::Maximum number of threads
> @@ -380,7 +380,7 @@ which enclose the calling call.
>  
>  
>  @node omp_get_max_active_levels
> -@section @code{omp_get_max_active_levels} -- Maximum number of active regions
> +@section @code{omp_get_max_active_levels} -- Current maximum number of 
> active regions
>  @table @asis
>  @item @emph{Description}:
>  This function obtains the maximum allowed number of nested, active parallel 
> regions.


Jakub



Re: [PATCH] openmp: Add support for omp_get_supported_active_levels

2020-10-15 Thread Kwok Cheung Yeung

On 14/10/2020 9:20 am, Jakub Jelinek wrote:

On Tue, Oct 13, 2020 at 07:05:10PM +0100, Kwok Cheung Yeung wrote:

+* omp_get_supported_active_levels:: Maxiumum number of active levels supported


Sorry for not catching it during review, but there is a typo above.  Fixed
with patch below, committed to trunk.



Thanks.


+@node omp_get_supported_active_levels
+@section @code{omp_get_supported_active_levels} -- Maximum number of active 
regions supported


I also wonder about the different wording between the above two places,
don't you want the same wording as earlier here?



Yes, they should be the same... I think I was playing around with wording (since 
the description for omp_get_max_active_levels is 'Maximum number of active 
regions' - different by one extra word!), and forgot to make them consistent.


Maybe we should change the description of omp_get_max_active_levels to 'Current 
maximum number of active regions', to make it more obvious that it can be 
changed? 'omp_get_supported_active_levels' can then be 'Maximum number of active 
regions supported'.


Okay to apply this patch?

Kwok
commit 3f6f8808f74598e274bfb8245c08a5428ee1b3fd
Author: Kwok Cheung Yeung 
Date:   Thu Oct 15 02:32:09 2020 -0700

Amend documentation for omp_get_max_active_levels and 
omp_get_supported_active_levels

2020-10-15  Kwok Cheung Yeung  

libgomp/
* libgomp.texi (omp_get_max_active_levels): Modify description.
(omp_get_supported_active_levels): Make descriptions consistent.

diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index 4a5e56f..7c6d5fd 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -167,7 +167,7 @@ linkage, and do not throw exceptions.
 * omp_get_default_device::  Get the default device for target regions
 * omp_get_dynamic:: Dynamic teams setting
 * omp_get_level::   Number of parallel regions
-* omp_get_max_active_levels::   Maximum number of active regions
+* omp_get_max_active_levels::   Current maximum number of active regions
 * omp_get_max_task_priority::   Maximum task priority value that can be set
 * omp_get_max_threads:: Maximum number of threads of parallel region
 * omp_get_nested::  Nested parallel regions
@@ -177,7 +177,7 @@ linkage, and do not throw exceptions.
 * omp_get_num_threads:: Size of the active team
 * omp_get_proc_bind::   Whether theads may be moved between CPUs
 * omp_get_schedule::Obtain the runtime scheduling method
-* omp_get_supported_active_levels:: Maximum number of active levels supported
+* omp_get_supported_active_levels:: Maximum number of active regions supported
 * omp_get_team_num::Get team number
 * omp_get_team_size::   Number of threads in a team
 * omp_get_thread_limit::Maximum number of threads
@@ -380,7 +380,7 @@ which enclose the calling call.
 
 
 @node omp_get_max_active_levels
-@section @code{omp_get_max_active_levels} -- Maximum number of active regions
+@section @code{omp_get_max_active_levels} -- Current maximum number of active 
regions
 @table @asis
 @item @emph{Description}:
 This function obtains the maximum allowed number of nested, active parallel 
regions.


Re: [PATCH] openmp: Add support for omp_get_supported_active_levels

2020-10-14 Thread Jakub Jelinek via Gcc-patches
On Tue, Oct 13, 2020 at 07:05:10PM +0100, Kwok Cheung Yeung wrote:
> +* omp_get_supported_active_levels:: Maxiumum number of active levels 
> supported

Sorry for not catching it during review, but there is a typo above.  Fixed
with patch below, committed to trunk.

> +@node omp_get_supported_active_levels
> +@section @code{omp_get_supported_active_levels} -- Maximum number of active 
> regions supported

I also wonder about the different wording between the above two places,
don't you want the same wording as earlier here?

> +@table @asis
> +@item @emph{Description}:
> +This function returns the maximum number of nested, active parallel regions
> +supported by this implementation.

2020-10-14  Jakub Jelinek  

* libgomp.texi (omp_get_supported_active_levels): Fix a typo.

--- libgomp/libgomp.texi.jj 2020-10-13 22:29:22.215958176 +0200
+++ libgomp/libgomp.texi2020-10-13 22:29:52.816516414 +0200
@@ -177,7 +177,7 @@ linkage, and do not throw exceptions.
 * omp_get_num_threads:: Size of the active team
 * omp_get_proc_bind::   Whether theads may be moved between CPUs
 * omp_get_schedule::Obtain the runtime scheduling method
-* omp_get_supported_active_levels:: Maxiumum number of active levels supported
+* omp_get_supported_active_levels:: Maximum number of active levels supported
 * omp_get_team_num::Get team number
 * omp_get_team_size::   Number of threads in a team
 * omp_get_thread_limit::Maximum number of threads


Jakub



Re: [PATCH] openmp: Add support for omp_get_supported_active_levels

2020-10-13 Thread Kwok Cheung Yeung

Now committed to trunk with the suggested fixes. Thanks for the quick review.

Kwok

On 13/10/2020 7:36 pm, Jakub Jelinek wrote:


I'd suggest to
#define gomp_supported_active_levels INT_MAX
in libgomp.h and leave out the const variable.  Another possibility is an
enumerator, but we don't include limits.h in libgomp.h.

OMP_5.0 symbol version has been shipped already in GCC 9.  So we should
never add any further symbols to it.
Thus it needs to be added to OMP_5.0.1 symbol version instead (which is new
in GCC 11).

Otherwise LGTM.


Re: [PATCH] openmp: Add support for omp_get_supported_active_levels

2020-10-13 Thread Jakub Jelinek via Gcc-patches
On Tue, Oct 13, 2020 at 07:05:10PM +0100, Kwok Cheung Yeung wrote:
> --- a/libgomp/env.c
> +++ b/libgomp/env.c
> @@ -73,7 +73,8 @@ struct gomp_task_icv gomp_global_icv = {
>.target_data = NULL
>  };
>  
> -unsigned long gomp_max_active_levels_var = INT_MAX;
> +const unsigned long gomp_supported_active_levels = INT_MAX;
> +unsigned long gomp_max_active_levels_var = gomp_supported_active_levels;

This is not valid C, and while gcc currently in GNU mode accepts it (I think
with optimization only?), we shouldn't use that.
It is valid C++ though.

I'd suggest to
#define gomp_supported_active_levels INT_MAX
in libgomp.h and leave out the const variable.  Another possibility is an
enumerator, but we don't include limits.h in libgomp.h.

> --- a/libgomp/libgomp.map
> +++ b/libgomp/libgomp.map
> @@ -172,6 +172,8 @@ OMP_5.0 {
>   omp_display_affinity_;
>   omp_get_affinity_format;
>   omp_get_affinity_format_;
> + omp_get_supported_active_levels;
> + omp_get_supported_active_levels_;

OMP_5.0 symbol version has been shipped already in GCC 9.  So we should
never add any further symbols to it.
Thus it needs to be added to OMP_5.0.1 symbol version instead (which is new
in GCC 11).

Otherwise LGTM.

Jakub



[PATCH] openmp: Add support for omp_get_supported_active_levels

2020-10-13 Thread Kwok Cheung Yeung

Hello

This adds support for the omp_get_supported_active_levels OpenMP runtime 
routine, first introduced in the 5.0 standard. This routine returns the maximum 
level of nested active parallel regions supported on a particular implementation 
of OpenMP, and the current maximum number cannot be set higher than this.


The maximum number in libgomp was initialized to INT_MAX (effectively uncapped), 
so I set the corresponding ICV for omp_get_supported_active_levels to INT_MAX 
too. Attempts to set the maximum to higher than this using 
omp_set_max_active_levels or by setting OMP_MAX_ACTIVE_LEVELS will result in the 
max active levels silently being set to the maximum supported (although since 
omp_set_max_active_levels takes an int and the maximum supported is INT_MAX, 
this is effectively impossible at the moment).


Okay for trunk?

Thanks

Kwok
commit aa519103d7eeaeed825fd358e9532bf51f4be0a9
Author: Kwok Cheung Yeung 
Date:   Wed Oct 7 09:34:32 2020 -0700

openmp: Add support for the omp_get_supported_active_levels runtime library 
routine

This patch implements the omp_get_supported_active_levels runtime routine
from the OpenMP 5.0 specification, which returns the maximum number of
active nested parallel regions supported by this implementation.  The
current maximum (set using the omp_set_max_active_levels routine or the
OMP_MAX_ACTIVE_LEVELS environment variable) cannot exceed this number.

2020-10-13  Kwok Cheung Yeung  

libgomp/
* env.c (gomp_supported_active_levels): New global variable.
(gomp_max_active_levels_var): Initialize to
gomp_supported_active_levels.
(initialize_env): Limit gomp_max_active_levels_var to be at most
equal to gomp_supported_active_levels.
* fortran.c (omp_get_supported_active_levels): Add ialias_redirect.
(omp_get_supported_active_levels_): New.
* icv.c (omp_set_max_active_levels): Limit gomp_max_active_levels_var
to at most equal to gomp_supported_active_levels.
(omp_get_supported_active_levels): New.
* libgomp.h (gomp_supported_active_levels): New.
* libgomp.map (OMP_5.0): Add omp_get_supported_active_levels and
omp_get_supported_active_levels_.
* libgomp.texi (omp_get_supported_active_levels): New.
(omp_set_max_active_levels): Update.  Add reference to
omp_get_supported_active_levels.
* omp.h.in (omp_get_supported_active_levels): New.
* omp_lib.f90.in (omp_get_supported_active_levels): New.
* omp_lib.h.in (omp_get_supported_active_levels): New.
* testsuite/libgomp.c/lib-2.c (main): Check omp_get_max_active_levels
against omp_get_supported_active_levels.
* testsuite/libgomp.fortran/lib4.f90 (lib4): Likewise.

diff --git a/libgomp/env.c b/libgomp/env.c
index c0c4730..539d7a9 100644
--- a/libgomp/env.c
+++ b/libgomp/env.c
@@ -73,7 +73,8 @@ struct gomp_task_icv gomp_global_icv = {
   .target_data = NULL
 };
 
-unsigned long gomp_max_active_levels_var = INT_MAX;
+const unsigned long gomp_supported_active_levels = INT_MAX;
+unsigned long gomp_max_active_levels_var = gomp_supported_active_levels;
 bool gomp_cancel_var = false;
 int gomp_max_task_priority_var = 0;
 #ifndef HAVE_SYNC_BUILTINS
@@ -1369,6 +1370,8 @@ initialize_env (void)
   parse_int ("OMP_MAX_TASK_PRIORITY", _max_task_priority_var, true);
   parse_unsigned_long ("OMP_MAX_ACTIVE_LEVELS", _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", _limit_var, false))
 {
diff --git a/libgomp/fortran.c b/libgomp/fortran.c
index 9d838b3..029dec1 100644
--- a/libgomp/fortran.c
+++ b/libgomp/fortran.c
@@ -63,6 +63,7 @@ ialias_redirect (omp_get_schedule)
 ialias_redirect (omp_get_thread_limit)
 ialias_redirect (omp_set_max_active_levels)
 ialias_redirect (omp_get_max_active_levels)
+ialias_redirect (omp_get_supported_active_levels)
 ialias_redirect (omp_get_level)
 ialias_redirect (omp_get_ancestor_thread_num)
 ialias_redirect (omp_get_team_size)
@@ -418,6 +419,12 @@ omp_get_max_active_levels_ (void)
 }
 
 int32_t
+omp_get_supported_active_levels_ (void)
+{
+  return omp_get_supported_active_levels ();
+}
+
+int32_t
 omp_get_level_ (void)
 {
   return omp_get_level ();
diff --git a/libgomp/icv.c b/libgomp/icv.c
index 3c16abb..1bb46ab 100644
--- a/libgomp/icv.c
+++ b/libgomp/icv.c
@@ -116,7 +116,12 @@ void
 omp_set_max_active_levels (int max_levels)
 {
   if (max_levels >= 0)
-gomp_max_active_levels_var = max_levels;
+{
+  if (max_levels <= gomp_supported_active_levels)
+   gomp_max_active_levels_var = max_levels;
+  else
+   gomp_max_active_levels_var = gomp_supported_active_levels;
+}
 }
 
 int
@@ -126,6 +131,12 @@ omp_get_max_active_levels (void)
 }
 
 int