From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2102) id 36F29385782F; Wed, 17 Nov 2021 08:18:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 36F29385782F Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Frederik Harwath To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/omp/gcc-11] openacc: Warn about "independent" "kernels" loops with data-dependences X-Act-Checkin: gcc X-Git-Author: Frederik Harwath X-Git-Refname: refs/heads/devel/omp/gcc-11 X-Git-Oldrev: eee64041ebd1f801773bbfd4c21b0ab0e4ef8ebe X-Git-Newrev: a4ce3665319fbf3d5c1547e9985e64a9ff98ced8 Message-Id: <20211117081831.36F29385782F@sourceware.org> Date: Wed, 17 Nov 2021 08:18:31 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Nov 2021 08:18:31 -0000 https://gcc.gnu.org/g:a4ce3665319fbf3d5c1547e9985e64a9ff98ced8 commit a4ce3665319fbf3d5c1547e9985e64a9ff98ced8 Author: Frederik Harwath Date: Tue Nov 16 16:20:15 2021 +0100 openacc: Warn about "independent" "kernels" loops with data-dependences 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.c (oacc_loop_warn_if_false_independent): New function. (oacc_loop_fixed_partitions): Call from here. Diff: --- gcc/common.opt | 5 +++++ gcc/omp-offload.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/gcc/common.opt b/gcc/common.opt index aa695e56dc4..4c38ed5cf9a 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -838,6 +838,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 diff --git a/gcc/omp-offload.c b/gcc/omp-offload.c index 94a975a8866..b806e36ef51 100644 --- a/gcc/omp-offload.c +++ b/gcc/omp-offload.c @@ -2043,6 +2043,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 @@ -2094,6 +2139,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;