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

            Bug ID: 127214
           Summary: [OpenMP] 'declare target' - LINK and ENTER variables
                    mishandled with MAP clauses
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: openmp, wrong-code
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
  Target Milestone: ---

Created attachment 65499
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=65499&action=edit
Testcase: Compile with "gcc -fopenmp" (and one of the -D... options); failing
is the default case

This is with DECLARE TARGET and an ENTER and a LINK global variable.

* Without OpenMP:  7 / 17

* With OpenMP - and -foffload=disable or offloading to a device:
    7 / 9  (WRONG!) - compiled as is
    7 / 17 (OK) - with -DFULL_VAR=1
    7 / 17 (OK) - with -DIMPLICIT=1

With self_maps with GCC 16: Same result for -foffload=disabled.
But for self_maps and offloading, the result is:
    3 / 9  (WRONG!) - compiled as is
    3 / 17 (!)      - with -DIMPLICIT=1
    7 / 17 (OK)     - with -DFULL_VAR=1

The issue with the '3' is that host and device have their own variable.
The target mapping code in omp-low.cc does not know about 'self_maps'
and adds a map clause because of the 'always' modifier for the global variable.

It seems as if with implicit mapping, the variable is used directly while with
'map(always,…)' the passed argument is used.

Using the global variable (and not one passed as argument) should always work
for enter/link/local variables in target structured blocks - at least for
global variables, for static variables in function scope, see PR 127213.

BTW: For self_maps, the link and the enter variable should have the same
address as the host variable, i.e. return host memory. For 'local', it is
always the local variables.
And on devices w/o self_maps, 'abc' is the global variable and 'cde' is a
global variable but as the data is not on the device, the explicit/implicit
'map' clause will create temporary data and attach it to the global link
variable.

Reply via email to