public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Tom de Vries <Tom_deVries@mentor.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: "gcc-patches@gnu.org" <gcc-patches@gnu.org>,
	Richard Biener	<rguenther@suse.de>
Subject: Re: [PING^3][PATCH, 12/16] Handle acc loop directive
Date: Mon, 22 Feb 2016 10:55:00 -0000	[thread overview]
Message-ID: <56CAE8F6.9000302@mentor.com> (raw)
In-Reply-To: <56BDBDC3.6010708@mentor.com>

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

On 12/02/16 12:10, Tom de Vries wrote:
> On 26/01/16 13:49, Jakub Jelinek wrote:
>> On Tue, Jan 26, 2016 at 01:38:39PM +0100, Tom de Vries wrote:
>>> Ping^3. ( https://gcc.gnu.org/ml/gcc-patches/2015-11/msg01089.html )
>>
>> First of all, I wonder if it wouldn't be far easier to handle these
>> during
>> gimplification rather than during omp expansion or during parsing.
>> Inside
>> kernels, do you need to honor any clauses on the acc loop, like
>> privatization etc., or can you just ignore it altogether (after
>> parsing them
>> to ensure they are valid)?
>
> The oacc loop clauses are: gang, worker, vector, seq, auto, tile,
> device_type, independent, private, reduction.
>
> AFAIU, there're all safe to ignore. That has largely been the approach
> in the gomp-4_0-branch, and sofar I haven't seen any failures due to
> ignoring a loop clause in a kernels region.
>
> But we do want to be able to honor loop clauses in a kernels region at
> some point. F.i., supporting the independent clause would allow more
> test-cases to be parallelized.
>
> At some point we had an implementation of the independent clause in the
> gomp-4_0-branch, but that had to be reverted (
> https://gcc.gnu.org/ml/gcc-patches/2015-11/msg00696.html ).
>
> Anyway, the implementation of the propagation of the independent
> property was to keep the loop directive with the independent clause
> until omp-expand (where we have cfg), and set a new field
> marked_independent in the corresponding struct loop.
>
> If we want to do the expansion of the loop directive to a normal loop at
> gimplication, I see two issues:
> - in general, we don't only check for correctness during parsing,
>    there's also checking being done during scan_omp, which happens in
>    pass_lower_omp, after gimplification.
> - how do we mark the new loop as being independent?
>
>> Handling this in expand_omp_for_generic is not really nice, because it
>> will
>> make already very complicated function even more complex.
>
> An alternative would be to copy expand_omp_for_generic, apply the patch,
> and partially evaluate for the single call introduced in the patch.
>
> Do you prefer this approach?

Jakub,

Following up on your suggestion to implement this during gimplification, 
I wrote attached patch.

I'll put it through some openacc testing and add testcases. Is this 
approach acceptable for stage4?

Thanks,
- Tom

[-- Attachment #2: 0001-Ignore-acc-loop-directive-in-kernels-region.patch --]
[-- Type: text/x-patch, Size: 3514 bytes --]

Ignore acc loop directive in kernels region

---
 gcc/gimplify.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 85 insertions(+)

diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 7be6bd7..cec0627 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -8364,6 +8364,82 @@ find_combined_omp_for (tree *tp, int *walk_subtrees, void *)
   return NULL_TREE;
 }
 
+/* Gimplify the loops with index I and higher in omp_for FOR_STMT as a
+   sequential loop, and append the resulting gimple statements to PRE_P.  */
+
+static void
+gimplify_omp_for_seq (tree for_stmt, gimple_seq *pre_p, unsigned int i)
+{
+  gcc_assert (OMP_FOR_ORIG_DECLS (for_stmt) == NULL_TREE);
+  unsigned int len = TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt));
+  gcc_assert (i < len);
+
+  /* Gimplify OMP_FOR[i] as:
+
+     if (i == 0)
+       OMP_FOR_PRE_BODY;
+     OMP_FOR_INIT[i];
+     goto <loop_entry_label>;
+     <fall_thru_label>:
+     if (i == len - 1)
+       OMP_FOR_BODY;
+     else
+       OMP_FOR[i+1];
+    OMP_FOR_INCR[i];
+    <loop_entry_label>:
+    if (OMP_FOR_COND[i])
+      goto <fall_thru_label>;
+    else
+      goto <loop_exit_label>;
+    <loop_exit_label>:
+  */
+
+  tree loop_entry_label = create_artificial_label (UNKNOWN_LOCATION);
+  tree fall_thru_label = create_artificial_label (UNKNOWN_LOCATION);
+  tree loop_exit_label = create_artificial_label (UNKNOWN_LOCATION);
+
+  /* if (i = 0) OMP_FOR_PRE_BODY. */
+  if (i == 0)
+    gimplify_and_add (OMP_FOR_PRE_BODY (for_stmt), pre_p);
+
+  /* OMP_FOR_INIT[i].  */
+  tree init = TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), i);
+  gimplify_stmt (&init, pre_p);
+
+  /* goto <loop_entry_label>.  */
+  gimplify_seq_add_stmt (pre_p, gimple_build_goto (loop_entry_label));
+
+  /* <fall_thru_label>.  */
+  gimplify_seq_add_stmt (pre_p, gimple_build_label (fall_thru_label));
+
+  /* if (i == len - 1) OMP_FOR_BODY
+     else OMP_FOR[i+1].  */
+  if (i == len - 1)
+    gimplify_and_return_first (OMP_FOR_BODY (for_stmt), pre_p);
+  else
+    gimplify_omp_for_seq (for_stmt, pre_p, i + 1);
+
+  /* OMP_FOR_INCR[i].  */
+  tree incr = TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i);
+  gimplify_stmt (&incr, pre_p);
+
+  /* <loop_entry_label>.  */
+  gimplify_seq_add_stmt (pre_p, gimple_build_label (loop_entry_label));
+
+  /* if (OMP_FOR_COND[i]) goto <fall_thru_label>
+     else goto <loop_exit_label>.  */
+  tree cond = TREE_VEC_ELT (OMP_FOR_COND (for_stmt), i);
+  tree var = TREE_OPERAND (cond, 0);
+  tree final_val = TREE_OPERAND (cond, 1);
+  gimplify_expr (&final_val, pre_p, NULL, is_gimple_val, fb_rvalue);
+  gimple *gimple_cond = gimple_build_cond (TREE_CODE (cond), var, final_val,
+					   fall_thru_label, loop_exit_label);
+  gimplify_seq_add_stmt (pre_p, gimple_cond);
+
+  /* <loop_exit_label>.  */
+  gimplify_seq_add_stmt (pre_p, gimple_build_label (loop_exit_label));
+}
+
 /* Gimplify the gross structure of an OMP_FOR statement.  */
 
 static enum gimplify_status
@@ -8403,6 +8479,15 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p)
       gcc_unreachable ();
     }
 
+  if (ort == ORT_ACC
+      && gimplify_omp_ctxp != NULL
+      && gimplify_omp_ctxp->region_type == ORT_ACC_KERNELS)
+    {
+      /* For now, ignore loop directive in kernels region.  */
+      gimplify_omp_for_seq (for_stmt, pre_p, 0);
+      return GS_ALL_DONE;
+    }
+
   /* Set OMP_CLAUSE_LINEAR_NO_COPYIN flag on explicit linear
      clause for the IV.  */
   if (ort == ORT_SIMD && TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)) == 1)

  reply	other threads:[~2016-02-22 10:55 UTC|newest]

Thread overview: 133+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-09 15:35 [PATCH series, 16] Use parloops to parallelize oacc kernels regions Tom de Vries
2015-11-09 15:44 ` [PATCH, 1/16] Insert new exit block only when needed in transform_to_exit_first_loop_alt Tom de Vries
2015-11-11 10:50   ` Richard Biener
2015-11-09 15:45 ` [PATCH, 2/16] Make create_parallel_loop return void Tom de Vries
2015-11-11 10:50   ` Richard Biener
2015-11-09 15:51 ` [PATCH, 3/16] Ignore reduction clause on kernels directive Tom de Vries
2015-11-24 12:25   ` [PING][PATCH, " Tom de Vries
2016-01-18 14:24     ` [PING^2][PATCH, " Tom de Vries
2016-01-18 14:26       ` Jakub Jelinek
2015-11-09 16:10 ` [PATCH, 4/16] Implement -foffload-alias Tom de Vries
2015-11-11 10:53   ` Richard Biener
2015-11-11 11:01     ` Jakub Jelinek
2015-11-12 16:04       ` Tom de Vries
2015-11-13  8:46         ` Richard Biener
2015-11-13 11:03           ` Tom de Vries
2015-11-13 11:30             ` Richard Biener
2015-11-13 11:39               ` Jakub Jelinek
2015-11-21 12:24                 ` Tom de Vries
2015-11-23 11:46                   ` Richard Biener
2015-11-27 11:44                     ` Tom de Vries
2015-11-27 12:14                       ` Tom de Vries
2015-12-02  9:59                         ` Jakub Jelinek
2016-03-14 13:16                           ` Tom de Vries
2016-03-14 23:18                             ` Tom de Vries
2015-12-02  9:46                       ` Jakub Jelinek
2015-12-02 13:11                         ` Tom de Vries
2015-12-11 12:45                 ` Tom de Vries
2015-12-11 13:00                   ` Richard Biener
2015-12-13 16:38                     ` Tom de Vries
2015-12-14 13:26                       ` Richard Biener
2015-12-14 15:44                         ` Tom de Vries
2015-12-16 13:16                           ` Richard Biener
2015-12-16 14:43                             ` Tom de Vries
2015-12-17 12:03                               ` [gomp4] " Thomas Schwinge
2015-12-03 11:53       ` Tom de Vries
2015-11-09 16:31 ` [PATCH, 5/16] Add in_oacc_kernels_region in struct loop Tom de Vries
2015-11-11 10:57   ` Richard Biener
2015-11-16 11:39     ` Tom de Vries
2015-11-16 11:39     ` Tom de Vries
2015-11-16 12:41       ` Richard Biener
2015-11-09 17:39 ` [PATCH, 6/16] Add pass_oacc_kernels Tom de Vries
2015-11-11 10:59   ` Richard Biener
2015-11-19 13:51     ` Tom de Vries
2015-11-24 12:17       ` Tom de Vries
2015-11-25 10:42         ` Richard Biener
2016-02-05 12:06   ` Use plain -fopenacc to enable OpenACC kernels processing (was: [PATCH, 6/16] Add pass_oacc_kernels) Thomas Schwinge
2016-02-10 14:40     ` Use plain -fopenacc to enable OpenACC kernels processing Thomas Schwinge
2016-02-15 16:54       ` Tom de Vries
2016-02-23 15:19         ` Thomas Schwinge
2015-11-09 18:14 ` [PATCH, 7/16] Add pass_dominator_oacc_kernels Tom de Vries
2015-11-11 11:05   ` Richard Biener
2015-11-16 12:04     ` Tom de Vries
2015-11-09 18:34 ` [PATCH, 8/16] Add pass_ch_oacc_kernels Tom de Vries
2015-11-11 20:29   ` Tom de Vries
2015-11-30 12:12     ` [gomp4] Use pass_ch instead of pass_ch_oacc_kernels (was: [PATCH, 8/16] Add pass_ch_oacc_kernels) Thomas Schwinge
2015-11-09 19:53 ` [PATCH, 9/16] Add pass_parallelize_loops_oacc_kernels Tom de Vries
2015-11-16 11:59   ` Tom de Vries
2015-11-24 12:27     ` Tom de Vries
2015-12-13 16:58       ` [PIING][PATCH, " Tom de Vries
2015-12-14 15:23         ` Richard Biener
2016-01-16 22:41           ` [Committed] Move pass_expand_omp_ssa out of pass_parallelize_loops Tom de Vries
2016-01-18 12:59           ` [Committed] Allow pass_parallelize_loops to be run outside the loop pipeline Tom de Vries
2016-01-18 13:07           ` [committed] Add oacc_kernels_p argument to pass_parallelize_loops Tom de Vries
2016-01-18 13:30             ` [committed] Add pass_parallelize_loops to pass_oacc_kernels Tom de Vries
2016-01-20  8:54             ` [committed] Add oacc_kernels_p argument to pass_parallelize_loops Thomas Schwinge
2016-01-20 10:31               ` Tom de Vries
2015-11-09 19:59 ` [PATCH, 10/16] Add pass_oacc_kernels pass group in passes.def Tom de Vries
2015-11-11 11:03   ` Richard Biener
2015-11-16 11:55     ` Tom de Vries
2015-11-16 12:45       ` Richard Biener
2015-11-16 23:21         ` Tom de Vries
2015-11-17 10:05           ` Richard Biener
2015-11-17 14:54             ` Tom de Vries
2015-11-17 15:18               ` Richard Biener
2015-11-17 15:39                 ` Tom de Vries
2015-11-17 22:21                   ` [PATCH, PR68373 ] Call scev_const_prop in pass_parallelize_loops::execute Tom de Vries
2015-11-19  9:36                     ` Tom de Vries
2015-11-20 10:15                       ` Richard Biener
2015-11-18  8:30                   ` [PATCH, 10/16] Add pass_oacc_kernels pass group in passes.def Richard Biener
2015-11-18 16:22                     ` Bernhard Reutner-Fischer
2015-11-20 12:53                       ` [committed, trivial] Fix typo and trailing whitespace in dump-file strings in parloops Tom de Vries
2015-11-19  0:35               ` [PATCH, 10/16] Add pass_oacc_kernels pass group in passes.def Tom de Vries
2015-11-20 10:28                 ` Richard Biener
2015-11-21  8:42                   ` Tom de Vries
2015-11-23 11:31                     ` Richard Biener
2015-11-23 15:53                       ` Tom de Vries
2015-11-23 16:38                         ` Richard Biener
2015-11-19 10:31         ` Tom de Vries
2015-11-20 10:37           ` Richard Biener
2015-11-20 13:27             ` Tom de Vries
2015-11-20 13:29               ` Richard Biener
2015-11-20 16:34                 ` Tom de Vries
2015-11-23 10:11                   ` Richard Biener
2015-11-24 12:22                     ` Tom de Vries
2015-11-24 13:19                       ` Richard Biener
2015-11-24 14:33                         ` Tom de Vries
2015-11-24 14:36                           ` Richard Biener
2015-11-24 15:05                             ` Tom de Vries
2015-11-25 10:43                               ` Richard Biener
2015-11-25 10:44                       ` Richard Biener
2015-11-30 17:48                         ` [gomp4] " Thomas Schwinge
2015-11-22 23:37             ` [PATCH] Don't reapply loops flags if unnecessary in loop_optimizer_init Tom de Vries
2015-11-23 10:33               ` Richard Biener
2015-11-23 11:27                 ` Tom de Vries
2015-11-09 20:02 ` [PATCH, 11/16] Update testcases after adding kernels pass group Tom de Vries
2015-11-11 11:03   ` Richard Biener
2015-11-12 14:32     ` Tom de Vries
2015-11-12 14:43       ` Richard Biener
2015-11-12 15:42         ` David Malcolm
2015-11-13  9:44           ` Richard Biener
2015-11-09 20:06 ` [PATCH, 12/16] Handle acc loop directive Tom de Vries
2015-11-24 12:30   ` [PING][PATCH, " Tom de Vries
2016-01-18 14:27     ` [PING^2][PATCH, " Tom de Vries
2016-01-26 12:38       ` [PING^3][PATCH, " Tom de Vries
2016-01-26 12:50         ` Jakub Jelinek
2016-02-12 11:11           ` Tom de Vries
2016-02-22 10:55             ` Tom de Vries [this message]
2016-02-22 10:58               ` Jakub Jelinek
2016-02-29  3:27                 ` Tom de Vries
2016-03-07  8:22                   ` [PING][PATCH, " Tom de Vries
2016-03-14  6:21                     ` [PING^2][PATCH, " Tom de Vries
2015-11-09 20:08 ` [PATCH, 13/16] Add c-c++-common/goacc/kernels-*.c Tom de Vries
2016-01-18 13:33   ` [committed] Add oacc kernels tests in goacc Tom de Vries
2015-11-09 20:09 ` [PATCH, 14/16] Add gfortran.dg/goacc/kernels-*.f95 Tom de Vries
2015-11-09 20:11 ` [PATCH, 15/16] Add libgomp.oacc-c-c++-common/kernels-*.c Tom de Vries
2016-01-18 13:39   ` [comitted] Add oacc kernels test in libgomp Tom de Vries
2016-03-09  9:18   ` [PATCH, 15/16] Add libgomp.oacc-c-c++-common/kernels-*.c Tom de Vries
2016-03-18 12:46     ` Scan for parallelization of the oacc kernels test-cases in gfortran.dg/goacc (was: [PATCH, 15/16] Add libgomp.oacc-c-c++-common/kernels-*.c) Thomas Schwinge
2016-04-05  9:13       ` Scan for parallelization of the oacc kernels test-cases in gfortran.dg/goacc Tom de Vries
2016-04-07 15:26         ` Thomas Schwinge
2015-11-09 20:12 ` [PATCH, 16/16] Add libgomp.oacc-fortran/kernels-*.f95 Tom de Vries
2016-03-09  9:19   ` Tom de Vries
2016-03-16 13:12     ` Thomas Schwinge

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56CAE8F6.9000302@mentor.com \
    --to=tom_devries@mentor.com \
    --cc=gcc-patches@gnu.org \
    --cc=jakub@redhat.com \
    --cc=rguenther@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).