public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [gomp4, committed] Ignore reduction clauses in kernels region
@ 2015-09-29 10:19 Tom de Vries
  2015-09-29 11:23 ` Tom de Vries
  0 siblings, 1 reply; 2+ messages in thread
From: Tom de Vries @ 2015-09-29 10:19 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 156 bytes --]

Hi,

this patch filters out reduction clauses in an oacc kernels region. This 
fixes an ICE in the test-case.

Committed to gomp-4_0-branch.

Thanks,
- Tom

[-- Attachment #2: 0001-Ignore-reduction-clauses-in-kernels-region.patch --]
[-- Type: text/x-patch, Size: 3223 bytes --]

Ignore reduction clauses in kernels region

2015-09-29  Tom de Vries  <tom@codesourcery.com>

	* omp-low.c (ctx_in_oacc_kernels_region): New function.
	(scan_omp_for): Filter out reduction clauses in kernels region.

	* c-c++-common/goacc/kernels-acc-loop-reduction.c: New test.
---
 gcc/omp-low.c                                      | 18 +++++++++++++++-
 .../goacc/kernels-acc-loop-reduction.c             | 25 ++++++++++++++++++++++
 2 files changed, 42 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/c-c++-common/goacc/kernels-acc-loop-reduction.c

diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index a5904eb..597035f 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -2579,6 +2579,20 @@ oacc_loop_or_target_p (gimple *stmt)
 	      && gimple_omp_for_kind (stmt) == GF_OMP_FOR_KIND_OACC_LOOP));
 }
 
+bool
+ctx_in_oacc_kernels_region (omp_context *ctx)
+{
+  for (;ctx != NULL; ctx = ctx->outer)
+    {
+      gimple *stmt = ctx->stmt;
+      if (gimple_code (stmt) == GIMPLE_OMP_TARGET
+	  && gimple_omp_target_kind (stmt) == GF_OMP_TARGET_KIND_OACC_KERNELS)
+	return true;
+    }
+
+  return false;
+}
+
 /* Scan a GIMPLE_OMP_FOR.  */
 
 static void
@@ -2592,6 +2606,7 @@ scan_omp_for (gomp_for *stmt, omp_context *outer_ctx)
   bool auto_clause = false;
   bool seq_clause = false;
   int gwv_routine = 0;
+  bool in_oacc_kernels_region = ctx_in_oacc_kernels_region (outer_ctx);
 
   if (outer_ctx)
     outer_type = gimple_code (outer_ctx->stmt);
@@ -2665,7 +2680,8 @@ scan_omp_for (gomp_for *stmt, omp_context *outer_ctx)
 
       /* Filter out any OpenACC clauses which aren't associated with
 	 gangs, workers or vectors.  Such reductions are no-ops.  */
-      if (extract_oacc_loop_mask (ctx) == 0)
+      if (extract_oacc_loop_mask (ctx) == 0
+	  || in_oacc_kernels_region)
 	{
 	  /* First filter out the clauses at the beginning of the chain.  */
 	  while (clauses && OMP_CLAUSE_CODE (clauses) == OMP_CLAUSE_REDUCTION)
diff --git a/gcc/testsuite/c-c++-common/goacc/kernels-acc-loop-reduction.c b/gcc/testsuite/c-c++-common/goacc/kernels-acc-loop-reduction.c
new file mode 100644
index 0000000..f3aa4e7
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/goacc/kernels-acc-loop-reduction.c
@@ -0,0 +1,25 @@
+/* { dg-additional-options "-O2" } */
+/* { dg-additional-options "-ftree-parallelize-loops=32" } */
+/* { dg-additional-options "-fdump-tree-parloops_oacc_kernels-all" } */
+/* { dg-additional-options "-fdump-tree-optimized" } */
+
+unsigned int
+foo (int n, unsigned int *a)
+{
+  unsigned int sum = 0;
+
+#pragma acc kernels loop gang reduction(+:sum)
+  for (int i = 0; i < n; i++)
+    sum += a[i];
+
+  return sum;
+}
+
+/* Check that only one loop is analyzed, and that it can be parallelized.  */
+/* { dg-final { scan-tree-dump-times "SUCCESS: may be parallelized" 1 "parloops_oacc_kernels" } } */
+/* { dg-final { scan-tree-dump-not "FAILED:" "parloops_oacc_kernels" } } */
+
+/* Check that the loop has been split off into a function.  */
+/* { dg-final { scan-tree-dump-times "(?n);; Function .*foo.*\\._omp_fn\\.0" 1 "optimized" } } */
+
+/* { dg-final { scan-tree-dump-times "(?n)pragma omp target oacc_parallel.*num_gangs\\(32\\)" 1 "parloops_oacc_kernels" } } */
-- 
1.9.1


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

* Re: [gomp4, committed] Ignore reduction clauses in kernels region
  2015-09-29 10:19 [gomp4, committed] Ignore reduction clauses in kernels region Tom de Vries
@ 2015-09-29 11:23 ` Tom de Vries
  0 siblings, 0 replies; 2+ messages in thread
From: Tom de Vries @ 2015-09-29 11:23 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 349 bytes --]

On 29/09/15 11:49, Tom de Vries wrote:
> Hi,
>
> this patch filters out reduction clauses in an oacc kernels region. This
> fixes an ICE in the test-case.
>
> Committed to gomp-4_0-branch.

I've committed this follow-up patch that marks the function 
ctx_in_oacc_kernels_region static, and adds the missing function header 
comment.

Thanks,
- Tom


[-- Attachment #2: 0001-Make-ctx_in_oacc_kernels_region-static.patch --]
[-- Type: text/x-patch, Size: 693 bytes --]

Make ctx_in_oacc_kernels_region static

2015-09-29  Tom de Vries  <tom@codesourcery.com>

	* omp-low.c (ctx_in_oacc_kernels_region): Make static.  Add missing
	function header comment.
---
 gcc/omp-low.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index 75044a5..64f6168 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -2579,7 +2579,9 @@ oacc_loop_or_target_p (gimple *stmt)
 	      && gimple_omp_for_kind (stmt) == GF_OMP_FOR_KIND_OACC_LOOP));
 }
 
-bool
+/* Return true if ctx is part of an oacc kernels region.  */
+
+static bool
 ctx_in_oacc_kernels_region (omp_context *ctx)
 {
   for (;ctx != NULL; ctx = ctx->outer)
-- 
1.9.1


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

end of thread, other threads:[~2015-09-29 10:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-29 10:19 [gomp4, committed] Ignore reduction clauses in kernels region Tom de Vries
2015-09-29 11:23 ` Tom de Vries

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).