https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118478

--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> ---
> I don't believe we should do two copy constructors for target,
> one on the host and one on the device.

My understanding is that the (first)privatization happens twice.
I am not saying that the implementation should actually do it twice.
Indeed, I think it would be a missed-optimization doing it twice.

The OpenMP 6.0 specification has for "firstprivate":

"For each variable of class type:

* If the firstprivate clause is *not* on a *target* construct then
  a copy constructor is invoked to perform the initialization; and
* If the firstprivate clause is on a *target* construct then how
  many copy constructors, if any, are invoked is unspecified."

[For Fortran, some similar wording is planned, cf. OpenMP spec
Issue 4371.]


Thus, if 'firstprivate' is not on target, we have to use the
C++ copy constructor and Fortran defined assignments.

For 'firstprivate' on target, the simplest is probably to
keep using the current code, i.e. not invoking any copy
constructor/defined assignment - albeit at least for
'omp requires self_maps' (and, possibly, unified_shared_memory)
we could invoke it on the host - as the memory is device accessible,
albeit possibly slower (topic of shared memory controller vs. remote
access or memory-page migration).

Reply via email to