public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Alexander Monakov <amonakov@ispras.ru>
To: gcc-patches@gcc.gnu.org
Cc: Jakub Jelinek <jakub@redhat.com>,	Dmitry Melnik <dm@ispras.ru>
Subject: [gomp4 06/14] omp-low: copy omp_data_o to shared memory on NVPTX
Date: Tue, 20 Oct 2015 18:34:00 -0000	[thread overview]
Message-ID: <1445366076-16082-7-git-send-email-amonakov@ispras.ru> (raw)
In-Reply-To: <1445366076-16082-1-git-send-email-amonakov@ispras.ru>

(This patch serves as a straw man proposal to have something concrete for
discussion and further patches)

On PTX, stack memory is private to each thread.  When master thread constructs
'omp_data_o' on its own stack and passes it to other threads via
GOMP_parallel by reference, other threads cannot use the resulting pointer.
We need to arrange structures passed between threads be in global, or better,
in PTX __shared__ memory (private to each CUDA thread block).

We cannot easily adjust expansion of 'omp parallel' because it is done before
LTO streamout.  I've opted to adjust calls to GOMP_parallel in
pass_late_lower_omp instead.

As I see, there are two possible approaches.  Either arrange the structure be
in shared memory from the compiler, or have GOMP_parallel perform the copies.
The latter requires passing sizeof(omp_data_o) to GOMP_parallel, and also to
GOMP_OFFLOAD_run (to reserve shared memory), so doing it from the compiler
seems simpler.

Using static storage may preclude nested parallelism.  Not sure we want to
support it for offloading anyway (but there needs to be a clear decision).

Using separate variables is wasteful: they should go into a union to reduce
shared memory consumption.

	* omp-low.c (expand_parallel_call): Mark function for
        pass_late_lower_omp transforms.
        (pass_late_lower_omp::execute): Copy omp_data_o to/from
        'shared' memory on NVPTX.
---
 gcc/omp-low.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 46 insertions(+), 7 deletions(-)

diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index 6481163..5b75bf6 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -5384,7 +5384,10 @@ expand_parallel_call (struct omp_region *region, basic_block bb,
   if (t == NULL)
     t1 = null_pointer_node;
   else
-    t1 = build_fold_addr_expr (t);
+    {
+      t1 = build_fold_addr_expr (t);
+      cfun->curr_properties &= ~PROP_gimple_lompifn;
+    }
   t2 = build_fold_addr_expr (gimple_omp_parallel_child_fn (entry_stmt));
 
   vec_alloc (args, 4 + vec_safe_length (ws_args));
@@ -14703,15 +14706,51 @@ pass_late_lower_omp::execute (function *fun)
     for (i = gsi_start_bb (bb); !gsi_end_p (i); gsi_next (&i))
       {
 	gimple stmt = gsi_stmt (i);
-	if (!(is_gimple_call (stmt)
-	      && gimple_call_internal_p (stmt)
-	      && gimple_call_internal_fn (stmt) == IFN_GOACC_DATA_END_WITH_ARG))
+
+	if (!is_gimple_call (stmt))
 	  continue;
 
-	tree fn = builtin_decl_explicit (BUILT_IN_GOACC_DATA_END);
-	gimple g = gimple_build_call (fn, 0);
+#ifdef ADDR_SPACE_SHARED
+	/* Transform "GOMP_parallel (fn, &omp_data_o, ...)" call to
+
+	   static __shared__ typeof(omp_data_o) omp_data_shared;
+	   omp_data_shared = omp_data_o;
+	   GOMP_parallel(fn, &omp_data_shared, ...);
+	   omp_data_o = omp_data_shared; */
+	if (gimple_call_builtin_p (stmt, BUILT_IN_GOMP_PARALLEL))
+	  {
+	    tree omp_data_ptr = gimple_call_arg (stmt, 1);
+	    if (TREE_CODE (omp_data_ptr) == ADDR_EXPR)
+	      {
+		tree omp_data = TREE_OPERAND (omp_data_ptr, 0);
+		tree type = TREE_TYPE (omp_data);
+		int quals = ENCODE_QUAL_ADDR_SPACE (ADDR_SPACE_SHARED);
+		type = build_qualified_type (type, quals);
+		tree decl = create_tmp_var (type, "omp_data_shared");
+		TREE_STATIC (decl) = 1;
+		TREE_ADDRESSABLE (decl) = 1;
+		varpool_node::finalize_decl (decl);
+
+		gimple g = gimple_build_assign (decl, omp_data);
+		gsi_insert_before (&i, g, GSI_SAME_STMT);
+
+		g = gimple_build_assign (omp_data, decl);
+		gsi_insert_after (&i, g, GSI_NEW_STMT);
+
+		gimple_call_set_arg (stmt, 1, build_fold_addr_expr (decl));
+	      }
+	    continue;
+	  }
+#endif
+
+	if (gimple_call_internal_p (stmt)
+	    && gimple_call_internal_fn (stmt) == IFN_GOACC_DATA_END_WITH_ARG)
+	  {
+	    tree fn = builtin_decl_explicit (BUILT_IN_GOACC_DATA_END);
+	    gimple g = gimple_build_call (fn, 0);
 
-	gsi_replace (&i, g, false);
+	    gsi_replace (&i, g, false);
+	  }
       }
 
   return TODO_update_ssa;

  reply	other threads:[~2015-10-20 18:34 UTC|newest]

Thread overview: 99+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-20 18:34 [gomp4 00/14] NVPTX: further porting Alexander Monakov
2015-10-20 18:34 ` Alexander Monakov [this message]
2015-10-21  0:07   ` [gomp4 06/14] omp-low: copy omp_data_o to shared memory on NVPTX Bernd Schmidt
2015-10-21  6:49     ` Alexander Monakov
2015-10-21  8:48   ` Jakub Jelinek
2015-10-21  9:09     ` Alexander Monakov
2015-10-21  9:24       ` Jakub Jelinek
2015-10-21 10:42       ` Bernd Schmidt
2015-10-21 14:06         ` Alexander Monakov
2015-11-03 14:25   ` Alexander Monakov
2015-11-06 14:00     ` Bernd Schmidt
2015-11-06 14:06       ` Jakub Jelinek
2015-11-10 10:39     ` Jakub Jelinek
2015-11-26  9:51       ` Jakub Jelinek
2015-10-20 18:34 ` [gomp4 12/14] libgomp: fixup error.c on nvptx Alexander Monakov
2015-10-21 10:03   ` Jakub Jelinek
2015-10-20 18:34 ` [gomp4 14/14] libgomp: use more generic implementations " Alexander Monakov
2015-10-21 10:17   ` Jakub Jelinek
2015-10-20 18:34 ` [gomp4 07/14] libgomp nvptx plugin: launch target functions via gomp_nvptx_main Alexander Monakov
2015-10-20 21:12   ` Bernd Schmidt
2015-10-20 21:19     ` Alexander Monakov
2015-10-20 21:27       ` Bernd Schmidt
2015-10-21  9:07         ` Jakub Jelinek
2015-10-20 18:34 ` [gomp4 08/14] libgomp nvptx: populate proc.c Alexander Monakov
2015-10-21  9:15   ` Jakub Jelinek
2015-10-20 18:34 ` [gomp4 04/14] nvptx: fix output of _Bool global variables Alexander Monakov
2015-10-20 20:51   ` Bernd Schmidt
2015-10-20 21:04     ` Alexander Monakov
2015-10-28 16:56       ` Alexander Monakov
2015-10-28 17:01         ` Bernd Schmidt
2015-10-28 17:38           ` Alexander Monakov
2015-10-28 17:39             ` Bernd Schmidt
2015-10-28 17:51               ` Alexander Monakov
2015-10-28 18:06                 ` Bernd Schmidt
2015-10-28 18:07                   ` Alexander Monakov
2015-10-28 18:33                     ` Bernd Schmidt
2015-10-28 19:37                       ` Alexander Monakov
2015-10-29 11:13                         ` Bernd Schmidt
2015-10-30 13:27                           ` Alexander Monakov
2015-10-30 13:38                             ` Bernd Schmidt
2015-10-20 18:34 ` [gomp4 01/14] nvptx: emit kernels for 'omp target entrypoint' only for OpenACC Alexander Monakov
2015-10-20 23:48   ` Bernd Schmidt
2015-10-21  5:40     ` Alexander Monakov
2015-10-21  8:11   ` Jakub Jelinek
2015-10-21  8:36     ` Alexander Monakov
2015-10-20 18:34 ` [gomp4 11/14] libgomp: avoid variable-length stack allocation in team.c Alexander Monakov
2015-10-20 20:48   ` Bernd Schmidt
2015-10-20 21:41     ` Alexander Monakov
2015-10-20 21:46       ` Bernd Schmidt
2015-10-21  9:59   ` Jakub Jelinek
2015-10-20 18:34 ` [gomp4 05/14] omp-low: set 'omp target entrypoint' only on entypoints Alexander Monakov
2015-10-20 23:57   ` Bernd Schmidt
2015-10-21  8:20   ` Jakub Jelinek
2015-10-30 16:58     ` Alexander Monakov
2015-11-06 14:05       ` Bernd Schmidt
2015-11-06 14:08         ` Jakub Jelinek
2015-11-06 14:12           ` Bernd Schmidt
2015-11-06 17:16         ` Alexander Monakov
2015-10-20 18:34 ` [gomp4 03/14] nvptx: expand support for address spaces Alexander Monakov
2015-10-20 20:56   ` Bernd Schmidt
2015-10-20 21:06     ` Alexander Monakov
2015-10-20 21:13       ` Bernd Schmidt
2015-10-20 21:41         ` Cesar Philippidis
2015-10-20 21:51           ` Bernd Schmidt
2015-10-20 18:52 ` [gomp4 13/14] libgomp: provide minimal GOMP_teams Alexander Monakov
2015-10-21 10:12   ` Jakub Jelinek
2015-10-20 18:52 ` [gomp4 10/14] libgomp: arrange a team of pre-started threads via gomp_nvptx_main Alexander Monakov
2015-10-21  9:49   ` Jakub Jelinek
2015-10-21 14:41     ` Alexander Monakov
2015-10-21 15:02       ` Jakub Jelinek
2015-10-20 18:53 ` [gomp4 09/14] libgomp: provide barriers on NVPTX Alexander Monakov
2015-10-20 20:56   ` Bernd Schmidt
2015-10-20 22:00     ` Alexander Monakov
2015-10-21  2:23       ` Bernd Schmidt
2015-10-21  9:39   ` Jakub Jelinek
2015-10-20 19:01 ` [gomp4 02/14] nvptx: emit pointers to OpenMP target region entry points Alexander Monakov
2015-10-21  7:55 ` [gomp4 00/14] NVPTX: further porting Martin Jambor
2015-10-21  8:56 ` Jakub Jelinek
2015-10-21  9:17   ` Alexander Monakov
2015-10-21  9:29     ` Jakub Jelinek
2015-10-28 17:22       ` Alexander Monakov
2015-10-29  8:54         ` Jakub Jelinek
2015-10-29 11:38           ` Alexander Monakov
2015-10-21 12:06 ` Bernd Schmidt
2015-10-21 15:48   ` Alexander Monakov
2015-10-21 16:10     ` Bernd Schmidt
2015-10-22  9:55     ` Jakub Jelinek
2015-10-22 16:42       ` Alexander Monakov
2015-10-22 17:16         ` Julian Brown
2015-10-22 18:19           ` Alexander Monakov
2015-10-22 17:17         ` Bernd Schmidt
2015-10-22 18:10           ` Alexander Monakov
2015-10-22 18:27             ` Bernd Schmidt
2015-10-22 19:28               ` Alexander Monakov
2015-10-23  8:23           ` Jakub Jelinek
2015-10-23  8:25           ` Jakub Jelinek
2015-10-23 10:24           ` Jakub Jelinek
2015-10-23 10:48             ` Bernd Schmidt
2015-10-23 17:36             ` Alexander Monakov

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=1445366076-16082-7-git-send-email-amonakov@ispras.ru \
    --to=amonakov@ispras.ru \
    --cc=dm@ispras.ru \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.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).