public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/omp/gcc-11] Apply gangprivate attribute to innermost decl
@ 2021-05-13 16:11 Kwok Yeung
0 siblings, 0 replies; only message in thread
From: Kwok Yeung @ 2021-05-13 16:11 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:2805d1555d3fa354246f426b1dee019cae34d804
commit 2805d1555d3fa354246f426b1dee019cae34d804
Author: Julian Brown <julian@codesourcery.com>
Date: Tue May 28 08:42:10 2019 -0700
Apply gangprivate attribute to innermost decl
...and fix parallelism-level calculation when applying the attribute.
gcc/
* omp-low.c (mark_oacc_gangprivate): Add CTX parameter. Use to look up
correct decl to add attribute to.
(lower_omp_for): Move "oacc gangprivate" processing from here...
(process_oacc_gangprivate_1): ...to here. New function.
(lower_omp_target): Update call to mark_oacc_gangprivate.
(execute_lower_omp): Call process_oacc_gangprivate_1 for each OMP
context.
libgomp/
* testsuite/libgomp.oacc-fortran/gangprivate-attrib-2.f90: New test.
Diff:
---
gcc/ChangeLog.omp | 10 +++
gcc/omp-low.c | 75 +++++++++++++---------
libgomp/ChangeLog.omp | 4 ++
.../libgomp.oacc-fortran/gangprivate-attrib-2.f90 | 23 +++++++
4 files changed, 83 insertions(+), 29 deletions(-)
diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index f98933fd60f..7cb656d090b 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,13 @@
+2019-05-28 Julian Brown <julian@codesourcery.com>
+
+ * omp-low.c (mark_oacc_gangprivate): Add CTX parameter. Use to look up
+ correct decl to add attribute to.
+ (lower_omp_for): Move "oacc gangprivate" processing from here...
+ (process_oacc_gangprivate_1): ...to here. New function.
+ (lower_omp_target): Update call to mark_oacc_gangprivate.
+ (execute_lower_omp): Call process_oacc_gangprivate_1 for each OMP
+ context.
+
2019-05-20 Julian Brown <julian@codesourcery.com>
* gimplify.c (gimplify_adjust_omp_clauses_1): Support implied no_alloc
diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index 923f89de3b1..c3fe175448a 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -10169,25 +10169,36 @@ oacc_record_vars_in_bind (omp_context *ctx, tree bindvars)
semantics are correct. */
static void
-mark_oacc_gangprivate (vec<tree> *decls)
+mark_oacc_gangprivate (vec<tree> *decls, omp_context *ctx)
{
int i;
tree decl;
FOR_EACH_VEC_ELT (*decls, i, decl)
- if (!lookup_attribute ("oacc gangprivate", DECL_ATTRIBUTES (decl)))
- {
- if (dump_file && (dump_flags & TDF_DETAILS))
- {
- fprintf (dump_file,
- "Setting 'oacc gangprivate' attribute for decl:");
- print_generic_decl (dump_file, decl, TDF_SLIM);
- fputc ('\n', dump_file);
- }
- DECL_ATTRIBUTES (decl)
- = tree_cons (get_identifier ("oacc gangprivate"),
- NULL, DECL_ATTRIBUTES (decl));
- }
+ {
+ for (omp_context *thisctx = ctx; thisctx; thisctx = thisctx->outer)
+ {
+ tree inner_decl = maybe_lookup_decl (decl, thisctx);
+ if (inner_decl)
+ {
+ decl = inner_decl;
+ break;
+ }
+ }
+ if (!lookup_attribute ("oacc gangprivate", DECL_ATTRIBUTES (decl)))
+ {
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ {
+ fprintf (dump_file,
+ "Setting 'oacc gangprivate' attribute for decl:");
+ print_generic_decl (dump_file, decl, TDF_SLIM);
+ fputc ('\n', dump_file);
+ }
+ DECL_ATTRIBUTES (decl)
+ = tree_cons (get_identifier ("oacc gangprivate"),
+ NULL, DECL_ATTRIBUTES (decl));
+ }
+ }
}
/* Gimplify a GIMPLE_OMP_CRITICAL statement. This is a relatively simple
@@ -11444,20 +11455,7 @@ lower_omp_for (gimple_stmt_iterator *gsi_p, omp_context *ctx)
/* Add OpenACC partitioning and reduction markers just before the loop. */
if (oacc_head)
- {
- gimple_seq_add_seq (&body, oacc_head);
-
- unsigned level_total = 0;
- omp_context *thisctx;
-
- for (thisctx = ctx; thisctx; thisctx = thisctx->outer)
- level_total += thisctx->oacc_partitioning_levels;
-
- /* If the current context and parent contexts are distributed over a
- total of one parallelism level, we have gang partitioning. */
- if (level_total == 1)
- mark_oacc_gangprivate (ctx->oacc_addressable_var_decls);
- }
+ gimple_seq_add_seq (&body, oacc_head);
lower_omp_for_lastprivate (&fd, &body, &dlist, &clist, ctx);
@@ -12646,7 +12644,7 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx)
if (offloaded)
{
- mark_oacc_gangprivate (ctx->oacc_addressable_var_decls);
+ mark_oacc_gangprivate (ctx->oacc_addressable_var_decls, ctx);
/* Declare all the variables created by mapping and the variables
declared in the scope of the target body. */
@@ -13723,6 +13721,24 @@ lower_omp_teams (gimple_stmt_iterator *gsi_p, omp_context *ctx)
TREE_USED (block) = 1;
}
+static int
+process_oacc_gangprivate_1 (splay_tree_node node, void *data)
+{
+ omp_context *ctx = (omp_context *) node->value;
+ unsigned level_total = 0;
+ omp_context *thisctx;
+
+ for (thisctx = ctx; thisctx; thisctx = thisctx->outer)
+ level_total += thisctx->oacc_partitioning_levels;
+
+ /* If the current context and parent contexts are distributed over a
+ total of one parallelism level, we have gang partitioning. */
+ if (level_total == 1)
+ mark_oacc_gangprivate (ctx->oacc_addressable_var_decls, ctx);
+
+ return 0;
+}
+
/* Callback for lower_omp_1. Return non-NULL if *tp needs to be
regimplified. If DATA is non-NULL, lower_omp_1 is outside
of OMP context, but with task_shared_vars set. */
@@ -14116,6 +14132,7 @@ execute_lower_omp (void)
if (all_contexts)
{
+ splay_tree_foreach (all_contexts, process_oacc_gangprivate_1, NULL);
splay_tree_delete (all_contexts);
all_contexts = NULL;
}
diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 76847f7ab36..46703b60a28 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,7 @@
+2019-05-28 Julian Brown <julian@codesourcery.com>
+
+ * testsuite/libgomp.oacc-fortran/gangprivate-attrib-2.f90: New test.
+
2019-05-16 Julian Brown <julian@codesourcery.com>
* testsuite/libgomp.oacc-c-c++-common/kernels-for-index-reuse-1.c: New
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/gangprivate-attrib-2.f90 b/libgomp/testsuite/libgomp.oacc-fortran/gangprivate-attrib-2.f90
new file mode 100644
index 00000000000..d147229d91e
--- /dev/null
+++ b/libgomp/testsuite/libgomp.oacc-fortran/gangprivate-attrib-2.f90
@@ -0,0 +1,23 @@
+! Test for lack of "oacc gangprivate" attribute on worker-private variables
+
+! { dg-do run }
+! { dg-additional-options "-fdump-tree-omplower-details" }
+! { dg-final { scan-tree-dump-times "Setting 'oacc gangprivate' attribute for decl" 0 "omplower" } } */
+
+program main
+ integer :: w, arr(0:31)
+
+ !$acc parallel num_gangs(32) num_workers(32) copyout(arr)
+ !$acc loop gang worker private(w)
+ do j = 0, 31
+ w = 0
+ !$acc loop seq
+ do i = 0, 31
+ w = w + 1
+ end do
+ arr(j) = w
+ end do
+ !$acc end parallel
+
+ if (any (arr .ne. 32)) stop 1
+end program main
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-05-13 16:11 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-13 16:11 [gcc/devel/omp/gcc-11] Apply gangprivate attribute to innermost decl Kwok Yeung
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).