From: Kwok Cheung Yeung <kcy@codesourcery.com>
To: <gcc-patches@gcc.gnu.org>, Jakub Jelinek <jakub@redhat.com>
Cc: Thomas Schwinge <thomas@codesourcery.com>,
Julian Brown <julian@codesourcery.com>
Subject: [PATCH 09/10, OpenACC] Avoid introducing 'create' mapping clauses for loop index variables in kernels regions
Date: Wed, 17 Jul 2019 21:32:00 -0000 [thread overview]
Message-ID: <846179c6-abad-fbdb-b44a-a05b7b1eb9be@codesourcery.com> (raw)
In-Reply-To: <5e191259-d5d5-34ce-7fd5-fc8d2e6d982e@codesourcery.com>
This patch avoids adding CREATE mapping clauses for loop index variables. It
also sets TREE_ADDRESSABLE on newly mapped declarations, which fixes an ICE that
sometimes appears due to an assert firing in omp-low.c.
2019-07-16 Julian Brown <julian@codesourcery.com>
gcc/
* omp-oacc-kernels.c (find_omp_for_index_vars_1,
find_omp_for_index_vars): New functions.
(maybe_build_inner_data_region): Add IDX_VARS argument. Don't add
CREATE mapping clauses for loop index variables. Set TREE_ADDRESSABLE
flag on newly-mapped declarations as a side effect.
(decompose_kernels_region_body): Call find_omp_for_index_vars. Don't
create PRESENT clause for loop index variables. Pass index variable
set to maybe_build_inner_data_region.
---
gcc/omp-oacc-kernels.c | 58 ++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 51 insertions(+), 7 deletions(-)
diff --git a/gcc/omp-oacc-kernels.c b/gcc/omp-oacc-kernels.c
index d65e6c6..2091385 100644
--- a/gcc/omp-oacc-kernels.c
+++ b/gcc/omp-oacc-kernels.c
@@ -766,6 +766,43 @@ flatten_binds (gbind *bind, bool include_toplevel_vars = false)
return vars;
}
+/* Recursively search BODY_SEQUENCE for 'for' loops, and record their loop
+ indices in IDX_VARS. */
+
+static void
+find_omp_for_index_vars_1 (gimple_seq body_sequence, hash_set<tree> *idx_vars)
+{
+ gimple_stmt_iterator gsi;
+
+ for (gsi = gsi_start (body_sequence); !gsi_end_p (gsi); gsi_next (&gsi))
+ {
+ gimple *stmt = gsi_stmt (gsi);
+ gimple *for_stmt = top_level_omp_for_in_stmt (stmt);
+
+ if (for_stmt)
+ {
+ tree idx = gimple_omp_for_index (for_stmt, 0);
+ idx_vars->add (idx);
+ find_omp_for_index_vars_1 (gimple_omp_body (for_stmt), idx_vars);
+ }
+ else if (gimple_code (stmt) == GIMPLE_BIND)
+ find_omp_for_index_vars_1 (gimple_bind_body (as_a <gbind *> (stmt)),
+ idx_vars);
+ }
+}
+
+/* Find all loop index variables in a bind. */
+
+static hash_set<tree>
+find_omp_for_index_vars (gbind *bind)
+{
+ hash_set<tree> idx_vars;
+
+ find_omp_for_index_vars_1 (gimple_bind_body (bind), &idx_vars);
+
+ return idx_vars;
+}
+
/* Helper function for places where we construct data regions. Wraps the BODY
inside a try-finally construct at LOC that calls __builtin_GOACC_data_end
in its cleanup block. Returns this try statement. */
@@ -784,13 +821,15 @@ make_data_region_try_statement (location_t loc, gimple *body)
/* If INNER_BIND_VARS holds variables, build an OpenACC data region with
location LOC containing BODY and having "create(var)" clauses for each
- variable. If INNER_CLEANUP is present, add a try-finally statement with
- this cleanup code in the finally block. Return the new data region, or
- the original BODY if no data region was needed. */
+ variable (such variables are also made addressable as a side effect). If
+ INNER_CLEANUP is present, add a try-finally statement with this cleanup
+ code in the finally block. Return the new data region, or the original
+ BODY if no data region was needed. */
static gimple *
maybe_build_inner_data_region (location_t loc, gimple *body,
- tree inner_bind_vars, gimple *inner_cleanup)
+ tree inner_bind_vars, gimple *inner_cleanup,
+ hash_set<tree> *idx_vars)
{
/* Build data "create(var)" clauses for these local variables.
Below we will add these to a data region enclosing the entire body
@@ -817,7 +856,7 @@ maybe_build_inner_data_region (location_t loc, gimple *body,
else
inner_bind_vars = next;
}
- else
+ else if (!idx_vars->contains (v))
{
/* Otherwise, build the map clause. */
tree new_clause = build_omp_clause (loc, OMP_CLAUSE_MAP);
@@ -825,6 +864,7 @@ maybe_build_inner_data_region (location_t loc, gimple *body,
OMP_CLAUSE_DECL (new_clause) = v;
OMP_CLAUSE_SIZE (new_clause) = DECL_SIZE_UNIT (v);
OMP_CLAUSE_CHAIN (new_clause) = inner_data_clauses;
+ TREE_ADDRESSABLE (v) = 1;
inner_data_clauses = new_clause;
prev_mapped_var = v;
@@ -1156,6 +1196,8 @@ decompose_kernels_region_body (gimple *kernels_region,
tree kernels_clauses)
tree inner_bind_vars = flatten_binds (kernels_bind);
gimple_seq body_sequence = gimple_bind_body (kernels_bind);
+ hash_set<tree> idx_vars = find_omp_for_index_vars (kernels_bind);
+
/* All these inner variables will get allocated on the device (below, by
calling maybe_build_inner_data_region). Here we create "present"
clauses for them and add these clauses to the list of clauses to be
@@ -1163,7 +1205,9 @@ decompose_kernels_region_body (gimple *kernels_region,
tree kernels_clauses)
tree present_clauses = kernels_clauses;
for (tree var = inner_bind_vars; var; var = TREE_CHAIN (var))
{
- if (!DECL_ARTIFICIAL (var) && TREE_CODE (var) != CONST_DECL)
+ if (!DECL_ARTIFICIAL (var)
+ && TREE_CODE (var) != CONST_DECL
+ && !idx_vars.contains (var))
{
tree present_clause = build_omp_clause (loc, OMP_CLAUSE_MAP);
OMP_CLAUSE_SET_MAP_KIND (present_clause, GOMP_MAP_FORCE_PRESENT);
@@ -1342,7 +1386,7 @@ decompose_kernels_region_body (gimple *kernels_region,
tree kernels_clauses)
/* If we found variables declared in nested scopes, build a data region to
map them to the device. */
body = maybe_build_inner_data_region (loc, body, inner_bind_vars,
- inner_cleanup);
+ inner_cleanup, &idx_vars);
return body;
}
--
2.8.1
next prev parent reply other threads:[~2019-07-17 21:30 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-01 0:00 [og8] OpenACC 'kernels' construct changes: splitting of the construct into several regions Thomas Schwinge
2019-02-01 19:48 ` Thomas Schwinge
2019-07-17 21:03 ` [PATCH 00/10, OpenACC] Rework handling of OpenACC kernels regions Kwok Cheung Yeung
2019-07-17 21:04 ` [PATCH 01/10, OpenACC] Use "-fopenacc-kernels=parloops" to document "parloops" test cases Kwok Cheung Yeung
2019-07-17 21:05 ` [PATCH 02/10, OpenACC] Add OpenACC target kinds for decomposed kernels regions Kwok Cheung Yeung
2019-07-18 9:28 ` Jakub Jelinek
2019-08-05 22:31 ` Kwok Cheung Yeung
2019-07-17 21:06 ` [PATCH 03/10, OpenACC] Separate OpenACC kernels regions in data and parallel parts Kwok Cheung Yeung
2019-07-17 21:11 ` [PATCH 04/10, OpenACC] Turn OpenACC kernels regions into a sequence of, parallel regions Kwok Cheung Yeung
2019-07-18 10:09 ` Jakub Jelinek
2019-08-05 21:58 ` Kwok Cheung Yeung
2020-11-13 22:33 ` In 'gcc/omp-oacc-kernels-decompose.cc', use langhook instead of accessing language-specific decl information (was: [PATCH 04/10, OpenACC] Turn OpenACC kernels regions into a sequence of, parallel regions) Thomas Schwinge
2019-07-17 21:12 ` [PATCH 05/10, OpenACC] Handle conditional execution of loops in OpenACC, kernels regions Kwok Cheung Yeung
2019-07-17 21:13 ` [PATCH 06/10, OpenACC] Adjust parallelism of loops in gang-single parts of OpenACC " Kwok Cheung Yeung
2019-08-05 22:17 ` Kwok Cheung Yeung
2019-07-17 21:24 ` [PATCH 07/10, OpenACC] Launch kernels asynchronously in " Kwok Cheung Yeung
2019-07-17 21:30 ` [PATCH 08/10, OpenACC] New OpenACC kernels region decompose algorithm Kwok Cheung Yeung
2019-07-17 21:32 ` Kwok Cheung Yeung [this message]
2019-07-17 21:37 ` [PATCH 10/10, OpenACC] Make new OpenACC kernels conversion the default; adjust and add tests Kwok Cheung Yeung
2019-07-18 9:24 ` [PATCH 00/10, OpenACC] Rework handling of OpenACC kernels regions Jakub Jelinek
2020-11-13 22:22 ` Decompose OpenACC 'kernels' constructs into parts, a sequence of compute constructs (was: [og8] OpenACC 'kernels' construct changes: splitting of the construct into several regions) Thomas Schwinge
2020-11-15 9:14 ` Tobias Burnus
2021-04-19 8:29 ` Decompose OpenACC 'kernels' constructs into parts, a sequence of compute constructs Thomas Schwinge
2021-04-19 12:38 ` Thomas Schwinge
2020-11-27 13:50 ` Thomas Schwinge
2022-01-13 9:44 ` Enhance OpenACC 'kernels' decomposition testing (was: Decompose OpenACC 'kernels' constructs into parts, a sequence of compute constructs) Thomas Schwinge
2022-01-19 22:29 ` Catch 'GIMPLE_DEBUG' misbehavior in OpenACC 'kernels' decomposition [PR100400, PR103836, PR104061] " Thomas Schwinge
2022-01-19 23:00 ` Jakub Jelinek
2022-01-20 8:26 ` Catch 'GIMPLE_DEBUG' misbehavior in OpenACC 'kernels' decomposition [PR100400, PR103836, PR104061] Thomas Schwinge
2022-01-20 9:58 ` Jakub Jelinek
2022-03-12 12:38 ` Add 'c-c++-common/goacc/kernels-decompose-pr104086-1.c' [PR104086] Thomas Schwinge
2022-03-12 12:42 ` OpenACC 'kernels' decomposition: Mark variables used in 'present' clauses as addressable [PR100280, PR104086] Thomas Schwinge
2022-03-17 8:04 ` Enhance further testcases to verify Openacc 'kernels' decomposition 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=846179c6-abad-fbdb-b44a-a05b7b1eb9be@codesourcery.com \
--to=kcy@codesourcery.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=julian@codesourcery.com \
--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).