public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libgomp/94290] New: [gfortran] OpenMP target teams distribute default firstprivate causes failure to map back values from device
@ 2020-03-23 18:47 jhdavis at udel dot edu
  2020-03-27 19:32 ` [Bug libgomp/94290] " jakub at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: jhdavis at udel dot edu @ 2020-03-23 18:47 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94290
           Summary: [gfortran] OpenMP target teams distribute default
                    firstprivate causes failure to map back values from
                    device
           Product: gcc
           Version: 9.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libgomp
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jhdavis at udel dot edu
                CC: jakub at gcc dot gnu.org
  Target Milestone: ---

Created attachment 48099
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48099&action=edit
Target teams distribute default(firstprivate) reproducible

Hello,

This bug report is from the SOLLVE team regarding default(firstprivate) in an
offloading construct.

--- SUMMARY ---
On a target teams distribute clause the default(firstprivate) clause we are
seeing a failure to map back changes made on the device. In the attached
reproducible we test both the 'private' and 'first' aspects of the clause for
both scalars and arrays on the device and then check the results on the host.
Changing the default(firstprivate) in both parts of the test to
firstprivate(privatized, privatized_array) causes the test to work as expected.
The version of the test in our suite is availible here:
https://github.com/SOLLVE/sollve_vv/blob/d031050b40edf3cd261219d649e932b4f4743ff6/tests/4.5/target_teams_distribute/test_target_teams_distribute_default_firstprivate.F90

--- DETAILS ---
gfortran version: 9.2.0

System: x86_64-pc-linux-gnu (Summit)

Config options: 
    ../gcc9.2/configure --enable-offload-targets=nvptx-none
--with-cuda-driver-include=/software/apps/cuda/9.2//include
--with-cuda-driver-lib=/software/apps/cuda/9.2//lib64 --disable-bootstrap
--disable-multilib --enable-languages=c,c++,fortran,lto
--prefix=/software/apps/gcc/9.2

No compiler output. Runtime output:
 test_firstprivate_private gave        1024 expected 0
 test_firstprivate_first gave        1024 expected 0

Command line to trigger bug:
    gfortran -fopenmp -ffree-line-length-none default_firstprivate_bug.F90 -o
default_firstprivate_bug.F90.o
    ./default_firstprivate_bug.F90.o

Best,

Josh Davis

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug libgomp/94290] [gfortran] OpenMP target teams distribute default firstprivate causes failure to map back values from device
  2020-03-23 18:47 [Bug libgomp/94290] New: [gfortran] OpenMP target teams distribute default firstprivate causes failure to map back values from device jhdavis at udel dot edu
@ 2020-03-27 19:32 ` jakub at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-03-27 19:32 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
This is a test bug.  Please see
https://www.openmp.org/spec-html/5.0/openmpse22.html#x116-4340002.14
When you have a combined or composite constructs, clauses that apply to just
one of the constructs generally are applied to the construct which allows them,
while clauses that can be applied to multiple constructs have more complicated
clause distribution rules in that section.
When you have combined
!$omp target teams default(firstprivate) map(from:a)
then the default clause, as it applies to teams only and not target, goes to
teams, and map clauses go to target.
So, it is like
!$omp target map(from:a)
!$omp teams default(firstprivate)
Now, if you reference a in the teams region, there is no data sharing clause on
the teams construct for a, and the default is firstprivate, which means an
implicit firstprivate(a) clause is added to the teams construct.  The target
construct has a map clause, so a on that construct is mapped rather than
privatized, which means that each team will have its own privatized copy of a,
and the uninitialized original mapped a is then copied back.
Either don't use default(firstprivate) on the combined constructs because you
really want sharing for those vars, or you can use
!$omp target teams default(firstprivate) map(from:a) shared(a)
While OpenMP has a restriction that the same list item can't be specified in
mapping and data sharing clauses, my understanding is that this applies after
the clauses are distributed among the constituent constructs, and as target
construct doesn't allow shared clause and teams construct doesn't allow map
clause, each goes to one of them and should do what you want.
Adding shared(a, b, c, d) clause to both combined directives in your testcase
fixes it.  You can even just add shared(d), though in that case the a, b, c
arrays are mapped to the device and then copied from that to each of the teams
private copies.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-03-27 19:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-23 18:47 [Bug libgomp/94290] New: [gfortran] OpenMP target teams distribute default firstprivate causes failure to map back values from device jhdavis at udel dot edu
2020-03-27 19:32 ` [Bug libgomp/94290] " jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).