]> gcc.gnu.org Git - gcc.git/commitdiff
openacc: Warn about "independent" "kernels" loops with data-dependences
authorFrederik Harwath <frederik@codesourcery.com>
Tue, 16 Nov 2021 15:20:15 +0000 (16:20 +0100)
committerKwok Cheung Yeung <kcy@codesourcery.com>
Tue, 21 Jun 2022 13:11:52 +0000 (14:11 +0100)
This commit concerns loops in OpenACC "kernels" region that have been marked
up with an explicit "independent" clause by the user, but for which Graphite
found data dependences.  A discussion on the private internal OpenACC mailing
list suggested that warning the user about the dependences woud be a more
acceptable solution than reverting the user's decision. This behavior is
implemented by the present commit.

gcc/ChangeLog:

        * common.opt: Add flag Wopenacc-false-independent.
        * omp-offload.cc (oacc_loop_warn_if_false_independent): New function.
        (oacc_loop_fixed_partitions): Call from here.

gcc/ChangeLog.omp
gcc/common.opt
gcc/omp-offload.cc

index e79905aa713f645e33d913c09e3877e9aa48af94..46da06d022f53943d1cf76264352f5366cae8057 100644 (file)
@@ -1,3 +1,9 @@
+2021-11-16  Andrew Stubbs  <ams@codesourcery.com>
+
+       * common.opt: Add flag Wopenacc-false-independent.
+       * omp-offload.cc (oacc_loop_warn_if_false_independent): New function.
+       (oacc_loop_fixed_partitions): Call from here.
+
 2021-11-16  Andrew Stubbs  <ams@codesourcery.com>
 
        * graphite-isl-ast-to-gimple.cc: Include internal-fn.h.
index 8511e0251749e1448a5c5b8518c157112da3dd10..ea2837c857dbc39a8ec931d995f5875c714359ec 100644 (file)
@@ -873,6 +873,11 @@ Wtsan
 Common Var(warn_tsan) Init(1) Warning
 Warn about unsupported features in ThreadSanitizer.
 
+Wopenacc-false-independent
+Common Var(warn_openacc_false_independent) Init(1) Warning
+Warn in case a loop in an OpenACC \"kernels\" region has an \"independent\"
+clause but analysis shows that it has loop-carried dependences.
+
 Xassembler
 Driver Separate
 
index 25d2038bbd764a06e98ef6396c0391dac439b1cc..b3f534c579d9853705f5e18a13d5d75859b1c6e0 100644 (file)
@@ -2054,6 +2054,51 @@ oacc_loop_transform_auto_into_independent (oacc_loop *loop)
   return true;
 }
 
+/* Emit a warning if LOOP has an "independent" clause but Graphite's
+   analysis shows that it has data dependences. Note that we respect
+   the user's explicit decision to parallelize the loop but we
+   nevertheless warn that this decision could be wrong. */
+
+static void
+oacc_loop_warn_if_false_independent (oacc_loop *loop)
+{
+  if (!optimize)
+    return;
+
+  if (loop->routine)
+    return;
+
+  /* TODO Warn about "auto" & "independent" in "parallel" regions? */
+  if (!oacc_parallel_kernels_graphite_fun_p ())
+    return;
+
+  if (!(loop->flags & OLF_INDEPENDENT))
+    return;
+
+  bool analyzed = false;
+  bool can_be_parallel = oacc_loop_can_be_parallel_p (loop, analyzed);
+  loop_p cfg_loop = oacc_loop_get_cfg_loop (loop);
+
+  if (cfg_loop && cfg_loop->inner && !analyzed)
+    {
+      if (dump_enabled_p ())
+       {
+         const dump_user_location_t loc
+           = dump_user_location_t::from_location_t (loop->loc);
+         dump_printf_loc (MSG_MISSED_OPTIMIZATION, loc,
+                          "'independent' loop in 'kernels' region has not been "
+                          "analyzed (cf. 'graphite' "
+                          "dumps for more information).\n");
+       }
+      return;
+    }
+
+  if (!can_be_parallel)
+    warning_at (loop->loc, 0,
+                "loop has \"independent\" clause but data dependences were "
+                "found.");
+}
+
 /* Walk the OpenACC loop hierarchy checking and assigning the
    programmer-specified partitionings.  OUTER_MASK is the partitioning
    this loop is contained within.  Return mask of partitioning
@@ -2105,6 +2150,10 @@ oacc_loop_fixed_partitions (oacc_loop *loop, unsigned outer_mask)
            }
        }
 
+      /* TODO Is this flag needed? Perhaps use -Wopenacc-parallelism? */
+      if (warn_openacc_false_independent)
+        oacc_loop_warn_if_false_independent (loop);
+
       if (maybe_auto && (loop->flags & OLF_INDEPENDENT))
        {
          loop->flags |= OLF_AUTO;
This page took 0.071744 seconds and 5 git commands to generate.