Re: [PATCH] [og10] OpenACC: Turn off worker partitioning if num_workers==1

2021-09-17 Thread Thomas Schwinge
Hi!

On 2020-06-29T13:16:51-0700, Julian Brown  wrote:
> This patch turns off the middle-end worker-partitioning support if the
> number of workers for an outlined offload function is one.  In that case,
> we do not need to perform the broadcasting/neutering code transformation.

ACK, thanks.

> --- a/gcc/omp-offload.c
> +++ b/gcc/omp-offload.c
> @@ -2165,7 +2165,20 @@ public:
>/* opt_pass methods: */
>virtual bool gate (function *)
>{
> -return flag_openacc && targetm.goacc.worker_partitioning;
> +if (!flag_openacc || !targetm.goacc.worker_partitioning)
> +  return false;
> +
> +tree attr = oacc_get_fn_attrib (current_function_decl);
> +
> +if (!attr)
> +  /* Not an offloaded function.  */
> +  return false;

This last check implies that code in
'gcc/omp-oacc-neuter-broadcast.cc:execute_omp_oacc_neuter_broadcast'
ought to be simplified which currently does:

tree attr = oacc_get_fn_attrib (current_function_decl);
if (attr)

..., which now is always-true.

> +
> +int worker_dim
> +  = oacc_get_fn_dim_size (current_function_decl, GOMP_DIM_WORKER);
> +
> +/* No worker partitioning if we know the number of workers is 1.  */
> +return worker_dim != 1;
>};

Pushed to master branch commit 82792cc407d7a7ab99f37e8501d19be2e6164e50
"openacc: Turn off worker partitioning if num_workers==1", see attached.


Grüße
 Thomas


-
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
>From 82792cc407d7a7ab99f37e8501d19be2e6164e50 Mon Sep 17 00:00:00 2001
From: Julian Brown 
Date: Mon, 29 Jun 2020 13:16:51 -0700
Subject: [PATCH] openacc: Turn off worker partitioning if num_workers==1

This patch turns off the middle-end worker-partitioning support if the
number of workers for an outlined offload function is one.  In that case,
we do not need to perform the broadcasting/neutering code transformation.

	gcc/
	* omp-oacc-neuter-broadcast.cc
	(pass_omp_oacc_neuter_broadcast::gate): Disable if num_workers is
	1.
	(execute_omp_oacc_neuter_broadcast): Adjust.

Co-Authored-By: Thomas Schwinge 
---
 gcc/omp-oacc-neuter-broadcast.cc | 47 +---
 1 file changed, 31 insertions(+), 16 deletions(-)

diff --git a/gcc/omp-oacc-neuter-broadcast.cc b/gcc/omp-oacc-neuter-broadcast.cc
index d48627a6940..3fe92248c4e 100644
--- a/gcc/omp-oacc-neuter-broadcast.cc
+++ b/gcc/omp-oacc-neuter-broadcast.cc
@@ -1378,18 +1378,17 @@ execute_omp_oacc_neuter_broadcast ()
 
   /* If this is a routine, calculate MASK as if the outer levels are already
  partitioned.  */
-  tree attr = oacc_get_fn_attrib (current_function_decl);
-  if (attr)
-{
-  tree dims = TREE_VALUE (attr);
-  unsigned ix;
-  for (ix = 0; ix != GOMP_DIM_MAX; ix++, dims = TREE_CHAIN (dims))
-	{
-	  tree allowed = TREE_PURPOSE (dims);
-	  if (allowed && integer_zerop (allowed))
-	mask |= GOMP_DIM_MASK (ix);
-	}
-}
+  {
+tree attr = oacc_get_fn_attrib (current_function_decl);
+tree dims = TREE_VALUE (attr);
+unsigned ix;
+for (ix = 0; ix != GOMP_DIM_MAX; ix++, dims = TREE_CHAIN (dims))
+  {
+	tree allowed = TREE_PURPOSE (dims);
+	if (allowed && integer_zerop (allowed))
+	  mask |= GOMP_DIM_MASK (ix);
+  }
+  }
 
   parallel_g *par = omp_sese_discover_pars (_stmt_map);
   populate_single_mode_bitmaps (par, worker_single, vector_single, mask, 0);
@@ -1506,11 +1505,27 @@ public:
   {}
 
   /* opt_pass methods: */
-  virtual bool gate (function *)
+  virtual bool gate (function *fun)
   {
-return (flag_openacc
-	&& targetm.goacc.create_worker_broadcast_record);
-  };
+if (!flag_openacc)
+  return false;
+
+if (!targetm.goacc.create_worker_broadcast_record)
+  return false;
+
+/* Only relevant for OpenACC offloaded functions.  */
+tree attr = oacc_get_fn_attrib (fun->decl);
+if (!attr)
+  return false;
+
+/* Not relevant for 'num_workers(1)'.  */
+int worker_dim
+  = oacc_get_fn_dim_size (fun->decl, GOMP_DIM_WORKER);
+if (worker_dim == 1)
+  return false;
+
+return true;
+  }
 
   virtual unsigned int execute (function *)
 {
-- 
2.33.0



[PATCH] [og10] OpenACC: Turn off worker partitioning if num_workers==1

2020-06-29 Thread Julian Brown
This patch turns off the middle-end worker-partitioning support if the
number of workers for an outlined offload function is one.  In that case,
we do not need to perform the broadcasting/neutering code transformation.

OK for og10 branch?

Julian

ChangeLog

gcc/
* omp-offload.c (pass_oacc_gimple_workers::gate): Disable worker
partitioning if num_workers is 1.
---
 gcc/omp-offload.c | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/gcc/omp-offload.c b/gcc/omp-offload.c
index bf72782ba4ce..2b730d057781 100644
--- a/gcc/omp-offload.c
+++ b/gcc/omp-offload.c
@@ -2165,7 +2165,20 @@ public:
   /* opt_pass methods: */
   virtual bool gate (function *)
   {
-return flag_openacc && targetm.goacc.worker_partitioning;
+if (!flag_openacc || !targetm.goacc.worker_partitioning)
+  return false;
+
+tree attr = oacc_get_fn_attrib (current_function_decl);
+
+if (!attr)
+  /* Not an offloaded function.  */
+  return false;
+
+int worker_dim
+  = oacc_get_fn_dim_size (current_function_decl, GOMP_DIM_WORKER);
+
+/* No worker partitioning if we know the number of workers is 1.  */
+return worker_dim != 1;
   };
 
   virtual unsigned int execute (function *)
-- 
2.23.0