[PATCH, libgomp, OpenMP 5.0] Implement omp_get_device_num

Jakub Jelinek jakub@redhat.com
Fri Jul 23 10:39:13 GMT 2021


On Fri, Jul 23, 2021 at 06:21:41PM +0800, Chung-Lin Tang wrote:
> --- a/libgomp/icv-device.c
> +++ b/libgomp/icv-device.c
> @@ -61,8 +61,17 @@ omp_is_initial_device (void)
>    return 1;
>  }
>  
> +int
> +omp_get_device_num (void)
> +{
> +  /* By specification, this is equivalent to omp_get_initial_device
> +     on the host.  */
> +  return omp_get_initial_device ();
> +}
> +

I think this won't work properly with the intel micoffload, where the host
libgomp is used in the offloaded code.
For omp_is_initial_device, the plugin solves it by:
liboffloadmic/plugin/offload_target_main.cpp
overriding it:
/* Override the corresponding functions from libgomp.  */
extern "C" int
omp_is_initial_device (void) __GOMP_NOTHROW
{
  return 0;
}
   
extern "C" int32_t
omp_is_initial_device_ (void)
{
  return omp_is_initial_device ();
}
but guess it will need slightly more work because we need to copy the value
to the offloading device too.
It can be done incrementally though.

> --- a/libgomp/libgomp-plugin.h
> +++ b/libgomp/libgomp-plugin.h
> @@ -102,6 +102,12 @@ struct addr_pair
>    uintptr_t end;
>  };
>  
> +/* This symbol is to name a target side variable that holds the designated
> +   'device number' of the target device. The symbol needs to be available to
> +   libgomp code and the  offload plugin (which in the latter case must be
> +   stringified).  */
> +#define GOMP_DEVICE_NUM_VAR __gomp_device_num

For a single var it is acceptable (though, please avoid the double space
before offload plugin in the comment), but once we have more than one
variable, I think we should simply have a struct which will contain all the
parameters that need to be copied from the host to the offloading device at
image load time (and have eventually another struct that holds parameters
that we'll need to copy to the device on each kernel launch, I bet some ICVs
will be one category, other ICVs another one).

> diff --git a/libgomp/libgomp.map b/libgomp/libgomp.map
> index 8ea27b5565f..ffcb98ae99e 100644
> --- a/libgomp/libgomp.map
> +++ b/libgomp/libgomp.map
> @@ -197,6 +197,8 @@ OMP_5.0.1 {
>  	omp_get_supported_active_levels_;
>  	omp_fulfill_event;
>  	omp_fulfill_event_;
> +	omp_get_device_num;
> +	omp_get_device_num_;
>  } OMP_5.0;

This is wrong.  We've already released GCC 11.1 with the OMP_5.0.1
symbol version, so we must not add any further symbols into that symbol
version.  OpenMP 5.0 routines added in GCC 12 should be OMP_5.0.2 symbol
version.

	Jakub



More information about the Gcc-patches mailing list