From: Frederik Harwath <frederik@codesourcery.com>
To: <gcc-patches@gcc.gnu.org>
Cc: <thomas@codesourcery.com>
Subject: [PATCH 22/40] openacc: Remove unused partitioning in "kernels" regions
Date: Wed, 15 Dec 2021 16:54:29 +0100 [thread overview]
Message-ID: <20211215155447.19379-23-frederik@codesourcery.com> (raw)
In-Reply-To: <20211215155447.19379-1-frederik@codesourcery.com>
With the old "kernels" handling, unparallelized regions would
get executed with 1x1x1 partitioning even if the user provided
explicit num_gangs, num_workers clauses etc.
This commit restores this behavior by removing unused partitioning
after assigning the parallelism dimensions to loops.
gcc/ChangeLog:
* omp-offload.c (oacc_remove_unused_partitioning): New function
for removing partitioning that is not used by any loop.
(oacc_validate_dims): Call oacc_remove_unused_partitioning and
enable warnings about unused partitioning.
libgomp/ChangeLog:
* testsuite/libgomp.oacc-c-c++-common/acc_prof-kernels-1.c: Adjust
expectations.
---
gcc/omp-offload.c | 51 +++++++++++++++++--
.../acc_prof-kernels-1.c | 18 ++++---
2 files changed, 58 insertions(+), 11 deletions(-)
diff --git a/gcc/omp-offload.c b/gcc/omp-offload.c
index 2743e90f79a3..392ca56b1f4f 100644
--- a/gcc/omp-offload.c
+++ b/gcc/omp-offload.c
@@ -1097,6 +1097,39 @@ oacc_parse_default_dims (const char *dims)
targetm.goacc.validate_dims (NULL_TREE, oacc_min_dims, -2, 0);
}
+/* Remove parallelism dimensions below LEVEL which are not set in USED
+ from DIMS and emit a warning pointing to the location of FN. */
+
+static void
+oacc_remove_unused_partitioning (tree fn, int *dims, int level, unsigned used)
+{
+
+ bool host_compiler = true;
+#ifdef ACCEL_COMPILER
+ host_compiler = false;
+#endif
+
+ static char const *const axes[] =
+ /* Must be kept in sync with GOMP_DIM enumeration. */
+ { "gang", "worker", "vector" };
+
+ char removed_partitions[20] = "\0";
+ for (int ix = level >= 0 ? level : 0; ix != GOMP_DIM_MAX; ix++)
+ if (!(used & GOMP_DIM_MASK (ix)) && dims[ix] >= 0)
+ {
+ if (host_compiler)
+ {
+ strcat (removed_partitions, axes[ix]);
+ strcat (removed_partitions, " ");
+ }
+ dims[ix] = -1;
+ }
+ if (removed_partitions[0] != '\0')
+ warning_at (DECL_SOURCE_LOCATION (fn), OPT_Wopenacc_parallelism,
+ "removed %spartitioning from %<kernels%> region",
+ removed_partitions);
+}
+
/* Validate and update the dimensions for offloaded FN. ATTRS is the
raw attribute. DIMS is an array of dimensions, which is filled in.
LEVEL is the partitioning level of a routine, or -1 for an offload
@@ -1117,6 +1150,7 @@ oacc_validate_dims (tree fn, tree attrs, int *dims, int level, unsigned used)
for (ix = 0; ix != GOMP_DIM_MAX; ix++)
{
purpose[ix] = TREE_PURPOSE (pos);
+
tree val = TREE_VALUE (pos);
dims[ix] = val ? TREE_INT_CST_LOW (val) : -1;
pos = TREE_CHAIN (pos);
@@ -1126,14 +1160,15 @@ oacc_validate_dims (tree fn, tree attrs, int *dims, int level, unsigned used)
#ifdef ACCEL_COMPILER
check = false;
#endif
+
+ static char const *const axes[] =
+ /* Must be kept in sync with GOMP_DIM enumeration. */
+ { "gang", "worker", "vector" };
+
if (check
&& warn_openacc_parallelism
- && !lookup_attribute ("oacc kernels", DECL_ATTRIBUTES (fn))
- && !lookup_attribute ("oacc parallel_kernels_graphite", DECL_ATTRIBUTES (fn)))
+ && !lookup_attribute ("oacc kernels", DECL_ATTRIBUTES (fn)))
{
- static char const *const axes[] =
- /* Must be kept in sync with GOMP_DIM enumeration. */
- { "gang", "worker", "vector" };
for (ix = level >= 0 ? level : 0; ix != GOMP_DIM_MAX; ix++)
if (dims[ix] < 0)
; /* Defaulting axis. */
@@ -1144,14 +1179,20 @@ oacc_validate_dims (tree fn, tree attrs, int *dims, int level, unsigned used)
"region contains %s partitioned code but"
" is not %s partitioned", axes[ix], axes[ix]);
else if (!(used & GOMP_DIM_MASK (ix)) && dims[ix] != 1)
+ {
/* The dimension is explicitly partitioned to non-unity, but
no use is made within the region. */
warning_at (DECL_SOURCE_LOCATION (fn), OPT_Wopenacc_parallelism,
"region is %s partitioned but"
" does not contain %s partitioned code",
axes[ix], axes[ix]);
+ }
}
+ if (lookup_attribute ("oacc parallel_kernels_graphite",
+ DECL_ATTRIBUTES (fn)))
+ oacc_remove_unused_partitioning (fn, dims, level, used);
+
bool changed = targetm.goacc.validate_dims (fn, dims, level, used);
/* Default anything left to 1 or a partitioned default. */
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_prof-kernels-1.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_prof-kernels-1.c
index ad33f72e2fb6..65c83dce01c9 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_prof-kernels-1.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/acc_prof-kernels-1.c
@@ -7,6 +7,8 @@
#include <acc_prof.h>
+/* { dg-skip-if "'kernels' not analyzed by Graphite at -O0" { *-*-* } { "-O0" } { "" } } */
+/* { dg-additional-options "-Wopenacc-parallelism" } */
/* Use explicit 'copyin' clauses, to work around "'firstprivate'
optimizations", which will cause the value at the point of call to be used
@@ -95,12 +97,8 @@ static void cb_enqueue_launch_start (acc_prof_info *prof_info, acc_event_info *e
assert (event_info->launch_event.num_workers >= 1);
else
{
-#ifdef __OPTIMIZE__
- assert (event_info->launch_event.num_workers == num_workers);
-#else
- /* See 'num_gangs' above. */
- assert (event_info->launch_event.num_workers == 1);
-#endif
+ /* Unused partitioning levels get removed from "kernels" region. */
+ assert (event_info->launch_event.num_workers == real_num_workers);
}
if (vector_length < 1)
assert (event_info->launch_event.vector_length >= 1);
@@ -183,6 +181,7 @@ int main()
STATE_OP (state, = 0);
num_gangs = 30;
num_workers = 3;
+ real_num_workers = 1;
vector_length = 5;
{
#define N 100
@@ -192,6 +191,8 @@ int main()
/* { dg-prune-output "using vector_length \\(32\\), ignoring 5" } */
{
for (int i = 0; i < N; ++i)
+ /* { dg-warning "region is worker partitioned but does not contain worker partitioned code" "" { target *-*-* } .-1 } */
+ /* { dg-warning "removed worker partitioning from 'kernels' region" "" { target *-*-* } .-2 } */
x[i] = i * i;
}
if (acc_device_type == acc_device_host)
@@ -208,6 +209,9 @@ int main()
STATE_OP (state, = 0);
num_gangs = 22;
num_workers = 5;
+ /* No worker loop and hence, in a kernels region, worker partitioning
+ should be removed. */
+ real_num_workers = 1;
vector_length = 7;
{
#define N 100
@@ -217,6 +221,8 @@ int main()
/* { dg-prune-output "using vector_length \\(32\\), ignoring runtime setting" } */
{
for (int i = 0; i < N; ++i)
+ /* { dg-warning "region is worker partitioned but does not contain worker partitioned code" "" { target *-*-* } .-1 } */
+ /* { dg-warning "removed worker partitioning from 'kernels' region" "" { target *-*-* } .-2 } */
x[i] = i * i;
}
if (acc_device_type == acc_device_host)
--
2.33.0
-----------------
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
next prev parent reply other threads:[~2021-12-15 15:56 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-15 15:54 [PATCH 00/40] OpenACC "kernels" Improvements Frederik Harwath
2021-12-15 15:54 ` [PATCH 01/40] Kernels loops annotation: C and C++ Frederik Harwath
2021-12-15 15:54 ` [PATCH 02/40] Add -fno-openacc-kernels-annotate-loops option to more testcases Frederik Harwath
2021-12-15 15:54 ` [PATCH 03/40] Kernels loops annotation: Fortran Frederik Harwath
2021-12-15 15:54 ` [PATCH 04/40] Additional Fortran testsuite fixes for kernels loops annotation pass Frederik Harwath
2021-12-15 15:54 ` [PATCH 05/40] Fix bug in processing of array dimensions in data clauses Frederik Harwath
2021-12-15 15:54 ` [PATCH 06/40] Add a "combined" flag for "acc kernels loop" etc directives Frederik Harwath
2021-12-15 15:54 ` [PATCH 07/40] Annotate inner loops in "acc kernels loop" directives (C/C++) Frederik Harwath
2021-12-15 15:54 ` [PATCH 08/40] Annotate inner loops in "acc kernels loop" directives (Fortran) Frederik Harwath
2021-12-15 15:54 ` [PATCH 09/40] Permit calls to builtins and intrinsics in kernels loops Frederik Harwath
2021-12-15 15:54 ` [PATCH 10/40] Fix patterns in Fortran tests for kernels loop annotation Frederik Harwath
2021-12-15 15:54 ` [PATCH 11/40] Clean up loop variable extraction in OpenACC " Frederik Harwath
2021-12-15 15:54 ` [PATCH 12/40] Relax some restrictions on the loop bound in " Frederik Harwath
2021-12-15 15:54 ` [PATCH 13/40] Fortran: Delinearize array accesses Frederik Harwath
2021-12-15 15:54 ` [PATCH 14/40] openacc: Move pass_oacc_device_lower after pass_graphite Frederik Harwath
2021-12-15 15:54 ` [PATCH 15/40] graphite: Extend SCoP detection dump output Frederik Harwath
2022-05-16 12:49 ` Tobias Burnus
2022-05-17 8:21 ` Richard Biener
2022-05-18 12:19 ` Harwath, Frederik
2022-05-18 12:21 ` Richard Biener
2021-12-15 15:54 ` [PATCH 16/40] graphite: Rename isl_id_for_ssa_name Frederik Harwath
2022-05-16 12:49 ` Tobias Burnus
2022-05-17 8:22 ` Richard Biener
2021-12-15 15:54 ` [PATCH 17/40] graphite: Fix minor mistakes in comments Frederik Harwath
2022-05-16 12:49 ` Tobias Burnus
2022-05-17 8:22 ` Richard Biener
2021-12-15 15:54 ` [PATCH 18/40] Move compute_alias_check_pairs to tree-data-ref.c Frederik Harwath
2021-12-15 15:54 ` [PATCH 19/40] graphite: Add runtime alias checking Frederik Harwath
2021-12-15 15:54 ` [PATCH 20/40] openacc: Use Graphite for dependence analysis in "kernels" regions Frederik Harwath
2021-12-15 15:54 ` [PATCH 21/40] openacc: Add "can_be_parallel" flag info to "graph" dumps Frederik Harwath
2021-12-15 15:54 ` Frederik Harwath [this message]
2021-12-15 15:54 ` [PATCH 23/40] Add function for printing a single OMP_CLAUSE Frederik Harwath
2021-12-15 15:54 ` [PATCH 24/40] openacc: Add data optimization pass Frederik Harwath
2021-12-15 15:54 ` [PATCH 25/40] openacc: Add runtime alias checking for OpenACC kernels Frederik Harwath
2021-12-15 15:54 ` [PATCH 26/40] openacc: Warn about "independent" "kernels" loops with data-dependences Frederik Harwath
2021-12-15 15:54 ` [PATCH 27/40] openacc: Handle internal function calls in pass_lim Frederik Harwath
2021-12-15 15:54 ` [PATCH 28/40] openacc: Disable pass_pre on outlined functions analyzed by Graphite Frederik Harwath
2021-12-15 15:54 ` [PATCH 29/40] graphite: Tune parameters for OpenACC use Frederik Harwath
2021-12-15 15:54 ` [PATCH 30/40] graphite: Adjust scop loop-nest choice Frederik Harwath
2021-12-15 15:54 ` [PATCH 31/40] graphite: Accept loops without data references Frederik Harwath
2021-12-15 15:54 ` [PATCH 32/40] Reference reduction localization Frederik Harwath
2021-12-15 15:54 ` [PATCH 33/40] Fix tree check failure with " Frederik Harwath
2021-12-15 15:54 ` [PATCH 34/40] Use more appropriate var in localize_reductions call Frederik Harwath
2021-12-15 15:54 ` [PATCH 35/40] Handle references in OpenACC "private" clauses Frederik Harwath
2021-12-15 15:54 ` [PATCH 36/40] openacc: Enable reduction variable localization for "kernels" Frederik Harwath
2021-12-15 15:54 ` [PATCH 37/40] Fix for is_gimple_reg vars to 'data kernels' Frederik Harwath
2021-12-15 15:54 ` [PATCH 38/40] openacc: fix privatization of by-reference arrays Frederik Harwath
2021-12-15 15:54 ` [PATCH 39/40] openacc: Check type for references in reduction lowering Frederik Harwath
2021-12-16 12:00 ` [PATCH 40/40] openacc: Adjust testsuite to new "kernels" handling Frederik Harwath
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=20211215155447.19379-23-frederik@codesourcery.com \
--to=frederik@codesourcery.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=thomas@codesourcery.com \
/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).