public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: "Michael V. Zolotukhin" <michael.v.zolotukhin@gmail.com>
Cc: Kirill Yukhin <kirill.yukhin@gmail.com>,
	       Richard Henderson <rth@redhat.com>,
	gcc@gcc.gnu.org,        triegel@redhat.com
Subject: Re: [RFC] Offloading Support in libgomp
Date: Tue, 27 Aug 2013 16:22:00 -0000	[thread overview]
Message-ID: <20130827113956.GH21876@tucnak.zalov.cz> (raw)
In-Reply-To: <20130827112609.GA4093@msticlxl57.ims.intel.com>

On Tue, Aug 27, 2013 at 03:26:09PM +0400, Michael V. Zolotukhin wrote:
> > Anyway, the GOMP_target_data implementation and part of GOMP_target would
> > be something along the lines of following pseudocode:
> > 
> > device_data = lookup_device_id (device_id);
> > ...
> Thanks, I've seen that similarly.  But the problem with passing
> arguments to the target is still open.  I'll try to explain, what is the
> problem.
> 
> Remember what we did for 'pragma parallel':
>   struct .omp_data_s.0 .omp_data_o.2;
>   .omp_data_o.2.s = 0.0;
>   .omp_data_o.2.b = &b;
>   .omp_data_o.2.c = &c;
>   .omp_data_o.2.y = y_7(D);
>   .omp_data_o.2.j = j_9(D);
>   __builtin_GOMP_parallel (bar._omp_fn.0, &.omp_data_o.2, 0, 0);
>   s_12 = .omp_data_o.2.s;
>   y_13 = .omp_data_o.2.y;
>   j_14 = .omp_data_o.2.j;
> 
> I.e. compiler prepares a structure with all arguments and pass it to the
> runtime.  Runtime passes this structure as-is to callee (i.e. to
> bar._omp_fn.0).
> 
> In bar._omp_fn.0 the compiler just emits code that extracts
> corresponding fields from the given struct and thus initialize all
> needed local vars:
>   bar._omp_fn.0 (struct .omp_data_s.0 * .omp_data_i)
>   {
>     int _12;
>     int _13;
>     ...
>     _12 = .omp_data_i_11(D)->y;
>     _13 = .omp_data_i_11(D)->j;
>     ...
>   }
> 
> That scheme would work perfectly for implementing host fallback, but as
> I see it, can't be applied as is for target offloading.  The reason is
> the following:
> *) Compiler doesn't know runtime info, i.e. it doesn't know target
> addresses so it can't fill the structure for passing to target version
> of the routine.
> *) Runtime doesn't know the structure layout - runtime should firstly
> translate addresses and only then pass it to the callee, but it don't
> know which addresses to translate, because it doesn't know which
> variables are used by the callee.
> 
> Currently, I see two possible solutions for this:
> 1) add to the structure with arguments fields, describing size of each
> field.  Then GOMP_target parses this struct and replace every found
> address with the corresponding target address, and only then call
> target_call.
> 2) Lift mapping/allocation stuff from runtime to compile time, i.e.
> allow the compiler to generate calls like this:
>   .omp_data_o.2.s = 0.0;
>   .omp_data_o.2.b = &b;
>   .omp_data_o.2.c = &c;
>   .omp_data_o.2.y = y_7(D);
>   .omp_data_o.2.j = j_9(D);
>   .omp_data_o.target.2.s = GOMP_translate_target_address (0.0);
>   .omp_data_o.target.2.b = GOMP_translate_target_address (&b);
>   .omp_data_o.target.2.c = GOMP_translate_target_address (&c);
>   .omp_data_o.target.2.y = GOMP_translate_target_address (y_7(D));
>   .omp_data_o.target.2.j = GOMP_translate_target_address (j_9(D));
>   GOMP_target (bar._omp_fn.0, &.omp_data_o.2, &.omp_data_o.target.2, 0, 0, );
> Thus runtime would have two versions of structure with arguments and
> will be able to pass it as-is to target callee.  But probably we'll need
> a version of that struct for each target and that would look very ugly.
> 
> What do you think on that?  Maybe I'm missing or overcomplicating
> something, but for now I can't get how all this stuff could work
> together without answers to these questions.

What I meant was just that if you call GOMP_target with
num_descs N, then the structure will look like:
struct .omp_target_data
{
  sometype0 *var0;
  sometype1 *var1;
  ...
  sometypeNminus1 *varNminus1;
};
so pretty much the runtime will call the target routine with address of
an array of N pointers, and the compiler generated target routine will
just use a struct to access it to make it more debuggable.  As there won't
be any paddings in the structure, I'd hope the structure layout will be
exactly the same as the array.

	Jakub

  reply	other threads:[~2013-08-27 11:40 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-22 22:37 Michael V. Zolotukhin
2013-08-23  0:22 ` Jakub Jelinek
2013-08-23 12:16   ` Michael V. Zolotukhin
2013-08-23 12:37     ` Jakub Jelinek
2013-08-24  6:17       ` Michael V. Zolotukhin
2013-08-25 16:24         ` Jakub Jelinek
2013-08-27  0:36           ` Michael V. Zolotukhin
2013-08-27  0:38             ` Jakub Jelinek
2013-08-27  6:16               ` Michael V. Zolotukhin
2013-08-27  8:06                 ` Jakub Jelinek
2013-08-27 15:47                   ` Michael V. Zolotukhin
2013-08-27 16:22                     ` Jakub Jelinek [this message]
2013-08-27 19:54                       ` Michael V. Zolotukhin
2013-08-28 11:21                         ` Jakub Jelinek
2013-08-29 10:44                           ` Michael V. Zolotukhin
2013-09-10 15:02                           ` Michael V. Zolotukhin
2013-09-10 15:15                             ` Jakub Jelinek
2013-09-10 15:31                               ` Michael V. Zolotukhin
2013-09-10 15:36                                 ` Jakub Jelinek
2013-09-10 15:38                                   ` Michael V. Zolotukhin
2013-09-13 11:30                                     ` Michael V. Zolotukhin
2013-09-13 12:36                                       ` Jakub Jelinek
2013-09-13 13:11                                         ` Michael V. Zolotukhin
2013-09-13 13:16                                           ` Jakub Jelinek
2013-09-13 15:09                                             ` Ilya Tocar
2013-09-13 15:34                                         ` Jakub Jelinek
2014-07-17  7:52                                       ` Thomas Schwinge
2014-07-17 12:30                                         ` Ilya Verbin
2014-07-17 12:37                                           ` Jakub Jelinek
2014-07-17 12:58                                             ` Thomas Schwinge
2014-07-17 13:09                                               ` Thomas Schwinge
2014-07-17 13:35                                                 ` Jakub Jelinek
2014-07-17 14:37                                                   ` Thomas Schwinge
2013-09-13  9:35                         ` Michael Zolotukhin
2013-09-13 10:52                           ` Kirill Yukhin
2013-09-13 11:04                           ` Nathan Sidwell
2013-09-13 11:21                             ` Michael V. Zolotukhin
2013-09-16  9:35                           ` Jakub Jelinek
2013-09-17 12:05                             ` Michael V. Zolotukhin
2013-09-17 12:30                               ` Jakub Jelinek
2013-10-28 10:43                                 ` Ilya Verbin
2013-10-29  8:04                                   ` Jakub Jelinek
2014-01-31 18:03                                     ` Ilya Verbin
2014-01-31 19:43                                       ` Jakub Jelinek
2014-02-14 15:24                                         ` Ilya Verbin
2014-02-14 15:43                                           ` Jakub Jelinek
2014-02-14 18:54                                             ` Richard Henderson
2014-02-17 15:59                                             ` Ilya Verbin
2014-02-17 16:03                                               ` Jakub Jelinek
2013-08-28 12:56             ` Richard Biener
2013-08-28 15:26               ` Jakub Jelinek
2013-08-28 17:03                 ` Richard Biener
2013-08-28 17:15                   ` Jakub Jelinek
2013-08-29 21:09                     ` Richard Biener
2013-08-28 18:54                   ` Torvald Riegel
2013-08-28 18:43                 ` Torvald Riegel

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=20130827113956.GH21876@tucnak.zalov.cz \
    --to=jakub@redhat.com \
    --cc=gcc@gcc.gnu.org \
    --cc=kirill.yukhin@gmail.com \
    --cc=michael.v.zolotukhin@gmail.com \
    --cc=rth@redhat.com \
    --cc=triegel@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).