* [Patch] OpenMP/Fortran: Fix loop-iter var privatization with !$OMP LOOP [PR108512] @ 2023-01-24 15:24 Tobias Burnus 2023-01-31 11:20 ` Jakub Jelinek 0 siblings, 1 reply; 4+ messages in thread From: Tobias Burnus @ 2023-01-24 15:24 UTC (permalink / raw) To: Jakub Jelinek, gcc-patches; +Cc: fortran [-- Attachment #1: Type: text/plain, Size: 992 bytes --] I stumbled over a new FAIL (regression) in sollve_vv today, which was due to an odd corner case (see commit log for a description). The mentioned in-scan error is tested for in gomp/loop-2.f90 ("'inscan' REDUCTION clause on construct other than DO, SIMD, DO SIMD, PARALLEL DO, PARALLEL DO SIMD"). I hope that this patch covers all cases and no other surprises exist... OK for mainline? * * * The ICE is new in GCC 13 due to the duplicate diagnostic (cf. PR); the original issue existed before but seemingly did not affect the code, at least the sollve_vv testcase passed before. Still, it could be backported to GCC 12. (Fortran '!$omp loop' support was added with r12-1206.) Thoughts? Tobias ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955 [-- Attachment #2: fix-omp-parallel-loop.diff --] [-- Type: text/x-patch, Size: 5528 bytes --] OpenMP/Fortran: Fix loop-iter var privatization with !$OMP LOOP [PR108512] For 'parallel', loop-iteration variables are marked are marked as 'private', unless they either appear in an omp do/simd loop or an data-sharing clause already exists for those on 'parallel'. 'omp loop' wasn't handled, leading to (potentially) multiple data-sharing clauses in gfc_resolve_do_iterator as omp_current_ctx pointed to the 'parallel' directive, ignoring the in-betwen 'loop' directive. The latter lead to a bogus diagnostic - or rather an ICE as the source location var contained only '\0'. gcc/fortran/ChangeLog: PR fortran/108512 * openmp.cc (gfc_resolve_omp_do_blocks): Don't check 'inscan' restrictions for loop as rejected elsewhere. (gfc_resolve_do_iterator): Set a source location for added 'private'-clause arguments. * resolve.cc (gfc_resolve_code): Call gfc_resolve_omp_do_blocks also for EXEC_OMP_LOOP. gcc/testsuite/ChangeLog: PR fortran/108512 * gfortran.dg/gomp/loop-5.f90: New test. gcc/fortran/openmp.cc | 5 +- gcc/fortran/resolve.cc | 1 + gcc/testsuite/gfortran.dg/gomp/loop-5.f90 | 84 +++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 1 deletion(-) diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc index cc1eab90b8c..7673a52249f 100644 --- a/gcc/fortran/openmp.cc +++ b/gcc/fortran/openmp.cc @@ -9056,7 +9056,9 @@ gfc_resolve_omp_do_blocks (gfc_code *code, gfc_namespace *ns) } if (i < omp_current_do_collapse || omp_current_do_collapse <= 0) omp_current_do_collapse = 1; - if (code->ext.omp_clauses->lists[OMP_LIST_REDUCTION_INSCAN]) + if (code->op == EXEC_OMP_LOOP) + ; /* Already rejected in resolve_omp_clauses. */ + else if (code->ext.omp_clauses->lists[OMP_LIST_REDUCTION_INSCAN]) { locus *loc = &code->ext.omp_clauses->lists[OMP_LIST_REDUCTION_INSCAN]->where; @@ -9224,6 +9226,7 @@ gfc_resolve_do_iterator (gfc_code *code, gfc_symbol *sym, bool add_clause) p = gfc_get_omp_namelist (); p->sym = sym; + p->where = omp_current_ctx->code->loc; p->next = omp_clauses->lists[OMP_LIST_PRIVATE]; omp_clauses->lists[OMP_LIST_PRIVATE] = p; } diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index 94213cd3cd4..bd2a749776d 100644 --- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -11950,6 +11950,7 @@ gfc_resolve_code (gfc_code *code, gfc_namespace *ns) case EXEC_OMP_DISTRIBUTE_SIMD: case EXEC_OMP_DO: case EXEC_OMP_DO_SIMD: + case EXEC_OMP_LOOP: case EXEC_OMP_SIMD: case EXEC_OMP_TARGET_SIMD: gfc_resolve_omp_do_blocks (code, ns); diff --git a/gcc/testsuite/gfortran.dg/gomp/loop-5.f90 b/gcc/testsuite/gfortran.dg/gomp/loop-5.f90 new file mode 100644 index 00000000000..1948e782653 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/loop-5.f90 @@ -0,0 +1,84 @@ +! { dg-additional-options "-fdump-tree-original" } +! +! PR fortran/108512 + +! The problem was that the context wasn't reset for the 'LOOP' +! such that the clauses of the loops weren't seen when adding +! PRIVATE clauses. +! +! In the following, only the loop variable of the non-OpenMP loop +! in 'subroutine four' should get a front-end addded PRIVATE clause + +implicit none +integer :: x, a(10), b(10), n + n = 10 + a = -42 + b = [(2*x, x=1,10)] + +! { dg-final { scan-tree-dump-times "#pragma omp target map\\(tofrom:a\\) map\\(tofrom:b\\) map\\(tofrom:x\\)\[\r\n\]" 1 "original" } } +! { dg-final { scan-tree-dump-times "#pragma omp parallel\[\r\n\]" 2 "original" } } +! ^- shows up twice; checked only here. +! { dg-final { scan-tree-dump-times "#pragma omp loop lastprivate\\(x\\)\[\r\n\]" 1 "original" } } + + !$omp target parallel map(tofrom: a, b, x) + !$omp loop lastprivate(x) + DO x = 1, n + a(x) = a(x) + b(x) + END DO + !$omp end loop + !$omp end target parallel + if (x /= 11) error stop + if (any (a /= [(2*x - 42, x=1,10)])) error stop + call two() + call three() + call four() +end + +subroutine two + implicit none + integer :: ii, mm, arr(10) + mm = 10 + arr = 0 + +! { dg-final { scan-tree-dump-times "#pragma omp target map\\(tofrom:arr\\) map\\(tofrom:ii\\)\[\r\n\]" 1 "original" } } +! { dg-final { scan-tree-dump-times "#pragma omp parallel shared\\(ii\\)\[\r\n\]" 1 "original" } } +! { dg-final { scan-tree-dump-times "#pragma omp loop lastprivate\\(ii\\)\[\r\n\]" 1 "original" } } + + !$omp target parallel loop map(tofrom: arr) lastprivate(ii) + DO ii = 1, mm + arr(ii) = arr(ii) + ii + END DO +end + +subroutine three + implicit none + integer :: kk, zz, var(10) + zz = 10 + var = 0 + +! { dg-final { scan-tree-dump-times "#pragma omp target map\\(tofrom:var\\)\[\r\n\]" 1 "original" } } +! "#pragma omp parallel\[\r\n\]" - shows up twice, dump checked above +! { dg-final { scan-tree-dump-times "#pragma omp loop\[\r\n\]" 1 "original" } } + + !$omp target parallel loop map(tofrom: var) + DO kk = 1, zz + var(kk) = var(kk) + kk + END DO +end + +subroutine four + implicit none + integer :: jj, qq, dist(10) + qq = 10 + dist = 0 + +! { dg-final { scan-tree-dump-times "#pragma omp target map\\(tofrom:dist\\)\[\r\n\]" 1 "original" } } +! { dg-final { scan-tree-dump-times "#pragma omp parallel private\\(jj\\)\[\r\n\]" 1 "original" } } + + !$omp target parallel map(tofrom: dist) + ! *no* '!$omp do/loop/simd' + DO jj = 1, qq + dist(qq) = dist(qq) + qq + END DO + !$omp end target parallel +end ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Patch] OpenMP/Fortran: Fix loop-iter var privatization with !$OMP LOOP [PR108512] 2023-01-24 15:24 [Patch] OpenMP/Fortran: Fix loop-iter var privatization with !$OMP LOOP [PR108512] Tobias Burnus @ 2023-01-31 11:20 ` Jakub Jelinek 2023-02-10 11:52 ` [Patch][v2] " Tobias Burnus 0 siblings, 1 reply; 4+ messages in thread From: Jakub Jelinek @ 2023-01-31 11:20 UTC (permalink / raw) To: Tobias Burnus; +Cc: gcc-patches, fortran On Tue, Jan 24, 2023 at 04:24:07PM +0100, Tobias Burnus wrote: > gcc/fortran/ChangeLog: > > PR fortran/108512 > * openmp.cc (gfc_resolve_omp_do_blocks): Don't check 'inscan' > restrictions for loop as rejected elsewhere. > (gfc_resolve_do_iterator): Set a source location for added > 'private'-clause arguments. > * resolve.cc (gfc_resolve_code): Call gfc_resolve_omp_do_blocks > also for EXEC_OMP_LOOP. > > gcc/testsuite/ChangeLog: > > PR fortran/108512 > * gfortran.dg/gomp/loop-5.f90: New test. > > gcc/fortran/openmp.cc | 5 +- > gcc/fortran/resolve.cc | 1 + > gcc/testsuite/gfortran.dg/gomp/loop-5.f90 | 84 +++++++++++++++++++++++++++++++ > 3 files changed, 89 insertions(+), 1 deletion(-) > > diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc > index cc1eab90b8c..7673a52249f 100644 > --- a/gcc/fortran/openmp.cc > +++ b/gcc/fortran/openmp.cc > @@ -9056,7 +9056,9 @@ gfc_resolve_omp_do_blocks (gfc_code *code, gfc_namespace *ns) > } > if (i < omp_current_do_collapse || omp_current_do_collapse <= 0) > omp_current_do_collapse = 1; > - if (code->ext.omp_clauses->lists[OMP_LIST_REDUCTION_INSCAN]) > + if (code->op == EXEC_OMP_LOOP) > + ; /* Already rejected in resolve_omp_clauses. */ I don't understand why is this needed. Sure, the vast majority of constructs don't allow reduction(inscan, ...), do we need to list them all? Is EXEC_OMP_LOOP somehow reusing that list for something else? What about EXEC_OMP_*_LOOP? If not, how does that differ say from EXEC_OMP_DISTRIBUTE or EXEC_OMP_TASKLOOP and many others? If it is rejected earlier, then perhaps we should free/clear the list after we diagnose it if it causes harm later. > + else if (code->ext.omp_clauses->lists[OMP_LIST_REDUCTION_INSCAN]) > { > locus *loc > = &code->ext.omp_clauses->lists[OMP_LIST_REDUCTION_INSCAN]->where; > @@ -9224,6 +9226,7 @@ gfc_resolve_do_iterator (gfc_code *code, gfc_symbol *sym, bool add_clause) > > p = gfc_get_omp_namelist (); > p->sym = sym; > + p->where = omp_current_ctx->code->loc; > p->next = omp_clauses->lists[OMP_LIST_PRIVATE]; > omp_clauses->lists[OMP_LIST_PRIVATE] = p; > } Ok. > diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc > index 94213cd3cd4..bd2a749776d 100644 > --- a/gcc/fortran/resolve.cc > +++ b/gcc/fortran/resolve.cc > @@ -11950,6 +11950,7 @@ gfc_resolve_code (gfc_code *code, gfc_namespace *ns) > case EXEC_OMP_DISTRIBUTE_SIMD: > case EXEC_OMP_DO: > case EXEC_OMP_DO_SIMD: > + case EXEC_OMP_LOOP: > case EXEC_OMP_SIMD: > case EXEC_OMP_TARGET_SIMD: > gfc_resolve_omp_do_blocks (code, ns); I'm afraid this is needed but insufficient. I think case EXEC_OMP_MASKED_TASKLOOP: case EXEC_OMP_MASKED_TASKLOOP_SIMD: case EXEC_OMP_MASTER_TASKLOOP: case EXEC_OMP_MASTER_TASKLOOP_SIMD: case EXEC_OMP_PARALLEL_LOOP: case EXEC_OMP_TARGET_PARALLEL_LOOP: case EXEC_OMP_TARGET_TEAMS_LOOP: case EXEC_OMP_TARGET_SIMD: case EXEC_OMP_TEAMS_LOOP: should be in the list above (of course alphabetically sorted in between the others) gfc_resolve_omp_parallel_blocks (code, ns); (the non-parallel-workshare one). Went through the c-family/c-omp.cc list in comment above splitting function and checked all appropriate constructs there... > diff --git a/gcc/testsuite/gfortran.dg/gomp/loop-5.f90 b/gcc/testsuite/gfortran.dg/gomp/loop-5.f90 > new file mode 100644 > index 00000000000..1948e782653 > --- /dev/null > +++ b/gcc/testsuite/gfortran.dg/gomp/loop-5.f90 > @@ -0,0 +1,84 @@ > +! { dg-additional-options "-fdump-tree-original" } > +! > +! PR fortran/108512 > + > +! The problem was that the context wasn't reset for the 'LOOP' > +! such that the clauses of the loops weren't seen when adding > +! PRIVATE clauses. > +! > +! In the following, only the loop variable of the non-OpenMP loop > +! in 'subroutine four' should get a front-end addded PRIVATE clause > + > +implicit none > +integer :: x, a(10), b(10), n > + n = 10 > + a = -42 > + b = [(2*x, x=1,10)] > + > +! { dg-final { scan-tree-dump-times "#pragma omp target map\\(tofrom:a\\) map\\(tofrom:b\\) map\\(tofrom:x\\)\[\r\n\]" 1 "original" } } > +! { dg-final { scan-tree-dump-times "#pragma omp parallel\[\r\n\]" 2 "original" } } > +! ^- shows up twice; checked only here. > +! { dg-final { scan-tree-dump-times "#pragma omp loop lastprivate\\(x\\)\[\r\n\]" 1 "original" } } > + > + !$omp target parallel map(tofrom: a, b, x) > + !$omp loop lastprivate(x) > + DO x = 1, n > + a(x) = a(x) + b(x) > + END DO > + !$omp end loop > + !$omp end target parallel > + if (x /= 11) error stop > + if (any (a /= [(2*x - 42, x=1,10)])) error stop > + call two() > + call three() > + call four() > +end > + > +subroutine two > + implicit none > + integer :: ii, mm, arr(10) > + mm = 10 > + arr = 0 > + > +! { dg-final { scan-tree-dump-times "#pragma omp target map\\(tofrom:arr\\) map\\(tofrom:ii\\)\[\r\n\]" 1 "original" } } > +! { dg-final { scan-tree-dump-times "#pragma omp parallel shared\\(ii\\)\[\r\n\]" 1 "original" } } > +! { dg-final { scan-tree-dump-times "#pragma omp loop lastprivate\\(ii\\)\[\r\n\]" 1 "original" } } > + > + !$omp target parallel loop map(tofrom: arr) lastprivate(ii) > + DO ii = 1, mm > + arr(ii) = arr(ii) + ii > + END DO > +end > + > +subroutine three > + implicit none > + integer :: kk, zz, var(10) > + zz = 10 > + var = 0 > + > +! { dg-final { scan-tree-dump-times "#pragma omp target map\\(tofrom:var\\)\[\r\n\]" 1 "original" } } > +! "#pragma omp parallel\[\r\n\]" - shows up twice, dump checked above > +! { dg-final { scan-tree-dump-times "#pragma omp loop\[\r\n\]" 1 "original" } } > + > + !$omp target parallel loop map(tofrom: var) > + DO kk = 1, zz > + var(kk) = var(kk) + kk > + END DO > +end > + > +subroutine four > + implicit none > + integer :: jj, qq, dist(10) > + qq = 10 > + dist = 0 > + > +! { dg-final { scan-tree-dump-times "#pragma omp target map\\(tofrom:dist\\)\[\r\n\]" 1 "original" } } > +! { dg-final { scan-tree-dump-times "#pragma omp parallel private\\(jj\\)\[\r\n\]" 1 "original" } } > + > + !$omp target parallel map(tofrom: dist) > + ! *no* '!$omp do/loop/simd' > + DO jj = 1, qq > + dist(qq) = dist(qq) + qq > + END DO > + !$omp end target parallel > +end Jakub ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Patch][v2] OpenMP/Fortran: Fix loop-iter var privatization with !$OMP LOOP [PR108512] 2023-01-31 11:20 ` Jakub Jelinek @ 2023-02-10 11:52 ` Tobias Burnus 2023-02-15 10:07 ` Jakub Jelinek 0 siblings, 1 reply; 4+ messages in thread From: Tobias Burnus @ 2023-02-10 11:52 UTC (permalink / raw) To: Jakub Jelinek; +Cc: gcc-patches, fortran [-- Attachment #1: Type: text/plain, Size: 2885 bytes --] Updated version attached. On 31.01.23 12:20, Jakub Jelinek via Gcc-patches wrote: > On Tue, Jan 24, 2023 at 04:24:07PM +0100, Tobias Burnus wrote: >> + if (code->op == EXEC_OMP_LOOP) >> + ; /* Already rejected in resolve_omp_clauses. */ > I don't understand why is this needed. Sure, the vast majority of > constructs don't allow reduction(inscan, ...), do we need to list them all? I think using the same != condition as in resolve_omp_clauses would be better. The messages inside this procedure come earlier than the ones in resolve_omp_clauses. Thus, they cannot be silenced there. However, while I did try this, preventing some odd error messages, I have now removed it again. – It is never quite clear when it is better to have multiple error messages and when suppressing some is better. * * * For more on 'inscan' and combined constructs (mainly with target, an OpenMP 5.1 feature), see the newly filed https://gcc.gnu.org/PR108749 >> diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc >> index 94213cd3cd4..bd2a749776d 100644 >> --- a/gcc/fortran/resolve.cc >> +++ b/gcc/fortran/resolve.cc >> @@ -11950,6 +11950,7 @@ gfc_resolve_code (gfc_code *code, gfc_namespace *ns) >> case EXEC_OMP_DISTRIBUTE_SIMD: >> case EXEC_OMP_DO: >> case EXEC_OMP_DO_SIMD: >> + case EXEC_OMP_LOOP: >> case EXEC_OMP_SIMD: >> case EXEC_OMP_TARGET_SIMD: >> gfc_resolve_omp_do_blocks (code, ns); > I'm afraid this is needed but insufficient. > I think > case EXEC_OMP_MASKED_TASKLOOP: > case EXEC_OMP_MASKED_TASKLOOP_SIMD: > case EXEC_OMP_MASTER_TASKLOOP: > case EXEC_OMP_MASTER_TASKLOOP_SIMD: > case EXEC_OMP_PARALLEL_LOOP: > case EXEC_OMP_TARGET_PARALLEL_LOOP: > case EXEC_OMP_TARGET_TEAMS_LOOP: > case EXEC_OMP_TARGET_SIMD: > case EXEC_OMP_TEAMS_LOOP: > should be in the list above (of course alphabetically sorted in between the > others) > gfc_resolve_omp_parallel_blocks (code, ns); I think 'TARGET_SIMD' shouldn't be resolved though parallel blocks but can call directly call gfc_resolve_omp_do_blocks (as currently/previously implemented). The masked version were already handled inside gfc_resolve_omp_parallel_blocks but missing in gfc_resolve_code, while the 'loop' ones had to be added to both. (I did not extend the testcase, but I updated two to add additional dg-error to the same line.) Thanks for the comments. Any further suggestions? Tobias ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955 [-- Attachment #2: fix-omp-parallel-loop-v2.diff --] [-- Type: text/x-patch, Size: 11733 bytes --] OpenMP/Fortran: Fix loop-iter var privatization with !$OMP LOOP [PR108512] For 'parallel', loop-iteration variables are marked are marked as 'private', unless they either appear in an omp do/simd loop or an data-sharing clause already exists for those on 'parallel'. 'omp loop' wasn't handled, leading to (potentially) multiple data-sharing clauses in gfc_resolve_do_iterator as omp_current_ctx pointed to the 'parallel' directive, ignoring the in-betwen 'loop' directive. The latter lead to a bogus diagnostic - or rather an ICE as the source location var contained only '\0'. Additionally, several 'case EXEC_OMP...LOOP' have been added to call the right resolution function and likewise for '{masked,master} taskloop'. gcc/fortran/ChangeLog: PR fortran/108512 * openmp.cc (gfc_resolve_omp_parallel_blocks): Handle combined 'loop' directives. (gfc_resolve_do_iterator): Set a source location for added 'private'-clause arguments. * resolve.cc (gfc_resolve_code): Call gfc_resolve_omp_do_blocks also for EXEC_OMP_LOOP and gfc_resolve_omp_parallel_blocks for combined directives with loop + '{masked,master} taskloop (simd)'. gcc/testsuite/ChangeLog: PR fortran/108512 * gfortran.dg/gomp/loop-5.f90: New test. * gfortran.dg/gomp/loop-2.f90: Update dg-error. * gfortran.dg/gomp/taskloop-2.f90: Update dg-error. gcc/fortran/openmp.cc | 13 +++-- gcc/fortran/resolve.cc | 9 +++ gcc/testsuite/gfortran.dg/gomp/loop-2.f90 | 5 ++ gcc/testsuite/gfortran.dg/gomp/loop-5.f90 | 84 +++++++++++++++++++++++++++ gcc/testsuite/gfortran.dg/gomp/taskloop-2.f90 | 2 + 5 files changed, 109 insertions(+), 4 deletions(-) diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc index 1897e1dbc71..abca146d78e 100644 --- a/gcc/fortran/openmp.cc +++ b/gcc/fortran/openmp.cc @@ -9125,28 +9125,32 @@ gfc_resolve_omp_parallel_blocks (gfc_code *code, gfc_namespace *ns) { case EXEC_OMP_DISTRIBUTE_PARALLEL_DO: case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD: + case EXEC_OMP_MASKED_TASKLOOP: + case EXEC_OMP_MASKED_TASKLOOP_SIMD: + case EXEC_OMP_MASTER_TASKLOOP: + case EXEC_OMP_MASTER_TASKLOOP_SIMD: case EXEC_OMP_PARALLEL_DO: case EXEC_OMP_PARALLEL_DO_SIMD: + case EXEC_OMP_PARALLEL_LOOP: case EXEC_OMP_PARALLEL_MASKED_TASKLOOP: case EXEC_OMP_PARALLEL_MASKED_TASKLOOP_SIMD: case EXEC_OMP_PARALLEL_MASTER_TASKLOOP: case EXEC_OMP_PARALLEL_MASTER_TASKLOOP_SIMD: - case EXEC_OMP_MASKED_TASKLOOP: - case EXEC_OMP_MASKED_TASKLOOP_SIMD: - case EXEC_OMP_MASTER_TASKLOOP: - case EXEC_OMP_MASTER_TASKLOOP_SIMD: case EXEC_OMP_TARGET_PARALLEL_DO: case EXEC_OMP_TARGET_PARALLEL_DO_SIMD: + case EXEC_OMP_TARGET_PARALLEL_LOOP: case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE: case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO: case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD: + case EXEC_OMP_TARGET_TEAMS_LOOP: case EXEC_OMP_TASKLOOP: case EXEC_OMP_TASKLOOP_SIMD: case EXEC_OMP_TEAMS_DISTRIBUTE: case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO: case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD: + case EXEC_OMP_TEAMS_LOOP: gfc_resolve_omp_do_blocks (code, ns); break; default: @@ -9225,6 +9229,7 @@ gfc_resolve_do_iterator (gfc_code *code, gfc_symbol *sym, bool add_clause) p = gfc_get_omp_namelist (); p->sym = sym; + p->where = omp_current_ctx->code->loc; p->next = omp_clauses->lists[OMP_LIST_PRIVATE]; omp_clauses->lists[OMP_LIST_PRIVATE] = p; } diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index 549916c2b53..96c34065691 100644 --- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -11923,9 +11923,14 @@ gfc_resolve_code (gfc_code *code, gfc_namespace *ns) break; case EXEC_OMP_DISTRIBUTE_PARALLEL_DO: case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD: + case EXEC_OMP_MASKED_TASKLOOP: + case EXEC_OMP_MASKED_TASKLOOP_SIMD: + case EXEC_OMP_MASTER_TASKLOOP: + case EXEC_OMP_MASTER_TASKLOOP_SIMD: case EXEC_OMP_PARALLEL: case EXEC_OMP_PARALLEL_DO: case EXEC_OMP_PARALLEL_DO_SIMD: + case EXEC_OMP_PARALLEL_LOOP: case EXEC_OMP_PARALLEL_MASKED: case EXEC_OMP_PARALLEL_MASKED_TASKLOOP: case EXEC_OMP_PARALLEL_MASKED_TASKLOOP_SIMD: @@ -11936,11 +11941,13 @@ gfc_resolve_code (gfc_code *code, gfc_namespace *ns) case EXEC_OMP_TARGET_PARALLEL: case EXEC_OMP_TARGET_PARALLEL_DO: case EXEC_OMP_TARGET_PARALLEL_DO_SIMD: + case EXEC_OMP_TARGET_PARALLEL_LOOP: case EXEC_OMP_TARGET_TEAMS: case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE: case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO: case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD: + case EXEC_OMP_TARGET_TEAMS_LOOP: case EXEC_OMP_TASK: case EXEC_OMP_TASKLOOP: case EXEC_OMP_TASKLOOP_SIMD: @@ -11949,6 +11956,7 @@ gfc_resolve_code (gfc_code *code, gfc_namespace *ns) case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO: case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD: + case EXEC_OMP_TEAMS_LOOP: omp_workshare_save = omp_workshare_flag; omp_workshare_flag = 0; gfc_resolve_omp_parallel_blocks (code, ns); @@ -11957,6 +11965,7 @@ gfc_resolve_code (gfc_code *code, gfc_namespace *ns) case EXEC_OMP_DISTRIBUTE_SIMD: case EXEC_OMP_DO: case EXEC_OMP_DO_SIMD: + case EXEC_OMP_LOOP: case EXEC_OMP_SIMD: case EXEC_OMP_TARGET_SIMD: gfc_resolve_omp_do_blocks (code, ns); diff --git a/gcc/testsuite/gfortran.dg/gomp/loop-2.f90 b/gcc/testsuite/gfortran.dg/gomp/loop-2.f90 index 4962683f2b0..2d83e3a7507 100644 --- a/gcc/testsuite/gfortran.dg/gomp/loop-2.f90 +++ b/gcc/testsuite/gfortran.dg/gomp/loop-2.f90 @@ -18,18 +18,23 @@ do i = 1, 64 end do !$omp loop reduction(inscan, +: r) ! { dg-error "'inscan' REDUCTION clause on construct other than DO, SIMD, DO SIMD, PARALLEL DO, PARALLEL DO SIMD" } + ! { dg-error "With INSCAN at .1., expected loop body with ..OMP SCAN between two structured-block-sequences" "" { target *-*-* } .-1 } do i = 1, 64 end do !$omp teams loop reduction(inscan, +: r) ! { dg-error "'inscan' REDUCTION clause on construct other than DO, SIMD, DO SIMD, PARALLEL DO, PARALLEL DO SIMD" } + ! { dg-error "With INSCAN at .1., expected loop body with ..OMP SCAN between two structured-block-sequences" "" { target *-*-* } .-1 } do i = 1, 64 end do !$omp parallel loop reduction(inscan, +: r) ! { dg-error "'inscan' REDUCTION clause on construct other than DO, SIMD, DO SIMD, PARALLEL DO, PARALLEL DO SIMD" } + ! { dg-error "With INSCAN at .1., expected loop body with ..OMP SCAN between two structured-block-sequences" "" { target *-*-* } .-1 } do i = 1, 64 end do !$omp target teams loop reduction(inscan, +: r) ! { dg-error "'inscan' REDUCTION clause on construct other than DO, SIMD, DO SIMD, PARALLEL DO, PARALLEL DO SIMD" } + ! { dg-error "With INSCAN at .1., expected loop body with ..OMP SCAN between two structured-block-sequences" "" { target *-*-* } .-1 } do i = 1, 64 end do !$omp target parallel loop reduction(inscan, +: r) ! { dg-error "'inscan' REDUCTION clause on construct other than DO, SIMD, DO SIMD, PARALLEL DO, PARALLEL DO SIMD" } + ! { dg-error "With INSCAN at .1., expected loop body with ..OMP SCAN between two structured-block-sequences" "" { target *-*-* } .-1 } do i = 1, 64 end do diff --git a/gcc/testsuite/gfortran.dg/gomp/loop-5.f90 b/gcc/testsuite/gfortran.dg/gomp/loop-5.f90 new file mode 100644 index 00000000000..1948e782653 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/loop-5.f90 @@ -0,0 +1,84 @@ +! { dg-additional-options "-fdump-tree-original" } +! +! PR fortran/108512 + +! The problem was that the context wasn't reset for the 'LOOP' +! such that the clauses of the loops weren't seen when adding +! PRIVATE clauses. +! +! In the following, only the loop variable of the non-OpenMP loop +! in 'subroutine four' should get a front-end addded PRIVATE clause + +implicit none +integer :: x, a(10), b(10), n + n = 10 + a = -42 + b = [(2*x, x=1,10)] + +! { dg-final { scan-tree-dump-times "#pragma omp target map\\(tofrom:a\\) map\\(tofrom:b\\) map\\(tofrom:x\\)\[\r\n\]" 1 "original" } } +! { dg-final { scan-tree-dump-times "#pragma omp parallel\[\r\n\]" 2 "original" } } +! ^- shows up twice; checked only here. +! { dg-final { scan-tree-dump-times "#pragma omp loop lastprivate\\(x\\)\[\r\n\]" 1 "original" } } + + !$omp target parallel map(tofrom: a, b, x) + !$omp loop lastprivate(x) + DO x = 1, n + a(x) = a(x) + b(x) + END DO + !$omp end loop + !$omp end target parallel + if (x /= 11) error stop + if (any (a /= [(2*x - 42, x=1,10)])) error stop + call two() + call three() + call four() +end + +subroutine two + implicit none + integer :: ii, mm, arr(10) + mm = 10 + arr = 0 + +! { dg-final { scan-tree-dump-times "#pragma omp target map\\(tofrom:arr\\) map\\(tofrom:ii\\)\[\r\n\]" 1 "original" } } +! { dg-final { scan-tree-dump-times "#pragma omp parallel shared\\(ii\\)\[\r\n\]" 1 "original" } } +! { dg-final { scan-tree-dump-times "#pragma omp loop lastprivate\\(ii\\)\[\r\n\]" 1 "original" } } + + !$omp target parallel loop map(tofrom: arr) lastprivate(ii) + DO ii = 1, mm + arr(ii) = arr(ii) + ii + END DO +end + +subroutine three + implicit none + integer :: kk, zz, var(10) + zz = 10 + var = 0 + +! { dg-final { scan-tree-dump-times "#pragma omp target map\\(tofrom:var\\)\[\r\n\]" 1 "original" } } +! "#pragma omp parallel\[\r\n\]" - shows up twice, dump checked above +! { dg-final { scan-tree-dump-times "#pragma omp loop\[\r\n\]" 1 "original" } } + + !$omp target parallel loop map(tofrom: var) + DO kk = 1, zz + var(kk) = var(kk) + kk + END DO +end + +subroutine four + implicit none + integer :: jj, qq, dist(10) + qq = 10 + dist = 0 + +! { dg-final { scan-tree-dump-times "#pragma omp target map\\(tofrom:dist\\)\[\r\n\]" 1 "original" } } +! { dg-final { scan-tree-dump-times "#pragma omp parallel private\\(jj\\)\[\r\n\]" 1 "original" } } + + !$omp target parallel map(tofrom: dist) + ! *no* '!$omp do/loop/simd' + DO jj = 1, qq + dist(qq) = dist(qq) + qq + END DO + !$omp end target parallel +end diff --git a/gcc/testsuite/gfortran.dg/gomp/taskloop-2.f90 b/gcc/testsuite/gfortran.dg/gomp/taskloop-2.f90 index 21427623584..41b4d6d2191 100644 --- a/gcc/testsuite/gfortran.dg/gomp/taskloop-2.f90 +++ b/gcc/testsuite/gfortran.dg/gomp/taskloop-2.f90 @@ -27,9 +27,11 @@ end do do i = 1, 64 ! { dg-error "OMP SCAN between two structured-block-sequences" "" { target *-*-* } .-1 } end do !$omp master taskloop reduction(inscan, +: r) ! { dg-error "'inscan' REDUCTION clause on construct other than DO, SIMD, DO SIMD, PARALLEL DO, PARALLEL DO SIMD" } + ! { dg-error "With INSCAN at .1., expected loop body with ..OMP SCAN between two structured-block-sequences" "" { target *-*-* } .-1 } do i = 1, 64 end do !$omp master taskloop simd reduction(inscan, +: r) ! { dg-error "'inscan' REDUCTION clause on construct other than DO, SIMD, DO SIMD, PARALLEL DO, PARALLEL DO SIMD" } + ! { dg-error "With INSCAN at .1., expected loop body with ..OMP SCAN between two structured-block-sequences" "" { target *-*-* } .-1 } do i = 1, 64 end do !$omp parallel master taskloop reduction(inscan, +: r) ! { dg-error "'inscan' REDUCTION clause on construct other than DO, SIMD, DO SIMD, PARALLEL DO, PARALLEL DO SIMD" } ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Patch][v2] OpenMP/Fortran: Fix loop-iter var privatization with !$OMP LOOP [PR108512] 2023-02-10 11:52 ` [Patch][v2] " Tobias Burnus @ 2023-02-15 10:07 ` Jakub Jelinek 0 siblings, 0 replies; 4+ messages in thread From: Jakub Jelinek @ 2023-02-15 10:07 UTC (permalink / raw) To: Tobias Burnus; +Cc: gcc-patches, fortran On Fri, Feb 10, 2023 at 12:52:47PM +0100, Tobias Burnus wrote: > > I'm afraid this is needed but insufficient. > > I think > > case EXEC_OMP_MASKED_TASKLOOP: > > case EXEC_OMP_MASKED_TASKLOOP_SIMD: > > case EXEC_OMP_MASTER_TASKLOOP: > > case EXEC_OMP_MASTER_TASKLOOP_SIMD: > > case EXEC_OMP_PARALLEL_LOOP: > > case EXEC_OMP_TARGET_PARALLEL_LOOP: > > case EXEC_OMP_TARGET_TEAMS_LOOP: > > case EXEC_OMP_TARGET_SIMD: > > case EXEC_OMP_TEAMS_LOOP: > > should be in the list above (of course alphabetically sorted in between the > > others) > > gfc_resolve_omp_parallel_blocks (code, ns); > > I think 'TARGET_SIMD' shouldn't be resolved though parallel blocks but You're right, we use gfc_resolve_omp_parallel_blocks for parallel, teams, task but not for target alone. > can call directly call gfc_resolve_omp_do_blocks (as > currently/previously implemented). The masked version were already > handled inside gfc_resolve_omp_parallel_blocks but missing in > gfc_resolve_code, while the 'loop' ones had to be added to both. > > (I did not extend the testcase, but I updated two to add additional > dg-error to the same line.) > gcc/fortran/ChangeLog: > > PR fortran/108512 > * openmp.cc (gfc_resolve_omp_parallel_blocks): Handle combined 'loop' > directives. > (gfc_resolve_do_iterator): Set a source location for added > 'private'-clause arguments. > * resolve.cc (gfc_resolve_code): Call gfc_resolve_omp_do_blocks > also for EXEC_OMP_LOOP and gfc_resolve_omp_parallel_blocks for > combined directives with loop + '{masked,master} taskloop (simd)'. > > gcc/testsuite/ChangeLog: > > PR fortran/108512 > * gfortran.dg/gomp/loop-5.f90: New test. > * gfortran.dg/gomp/loop-2.f90: Update dg-error. > * gfortran.dg/gomp/taskloop-2.f90: Update dg-error. LGTM, thanks. Jakub ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-02-15 10:07 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2023-01-24 15:24 [Patch] OpenMP/Fortran: Fix loop-iter var privatization with !$OMP LOOP [PR108512] Tobias Burnus 2023-01-31 11:20 ` Jakub Jelinek 2023-02-10 11:52 ` [Patch][v2] " Tobias Burnus 2023-02-15 10:07 ` Jakub Jelinek
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).