public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Ilya Verbin <iverbin@gmail.com>, Richard Henderson <rth@redhat.com>
Cc: "Michael V. Zolotukhin" <michael.v.zolotukhin@gmail.com>,
	       Kirill Yukhin <kirill.yukhin@gmail.com>,
	       GCC Development <gcc@gcc.gnu.org>,
	triegel@redhat.com,
	       Sergey Ostanevich <sergos.gnu@gmail.com>
Subject: Re: [RFC] Offloading Support in libgomp
Date: Fri, 14 Feb 2014 15:43:00 -0000	[thread overview]
Message-ID: <20140214154304.GG20378@tucnak.redhat.com> (raw)
In-Reply-To: <CADG=Z0Hz-fCggx9+8z1MokXQ4Z5AO0+3c5DKiqfL5d7vTaw4pw@mail.gmail.com>

On Fri, Feb 14, 2014 at 07:24:16PM +0400, Ilya Verbin wrote:
> 2014-01-31 22:03 GMT+04:00 Jakub Jelinek <jakub@redhat.com>:
> > Implicit map(tofrom: a) on #pragma omp target is what the standard
> > requires, so I don't see a bug on the compiler side.
> >         Jakub
> 
> There is an exception in the standard (page 177, lines 17-21):
> 
> > If a corresponding list item of the original list item is in the enclosing device data
> > environment, the new device data environment uses the corresponding list item from the
> > enclosing device data environment. No additional storage is allocated in the new device
> > data environment and neither initialization nor assignment is performed, regardless of
> > the map-type that is specified.
> 
> So, the pointer 'a' should inherit map-type ALLOC from the enclosing
> device data environment.

The standard itself is very unclear.  I'll cite my omp-lang mail from
September:

> Ok, I'm for now implementing this refcounted model.                                                                                              
> One still unclear thing is what is supposed to happen if multiple host threads                                                                   
> enter a target data construct mapping at least one same object with different                                                                    
> map kind.                                                                                                                                        
> Say thread A enters #pragma omp target data map(tofrom:p[:64]), then                                                                             
> thread B enters #pragma omp target data map(alloc:p[:64]) while thread A is                                                                      
> still running the body of it's target data (so, the mapping just increments                                                                      
> refcount of the p[:64] array section), then thread A leaves the target data                                                                      
> construct, decrements p[:64] refcount, but as it is non-zero, doesn't                                                                            
> deallocate it, and finally thread B enters end of its target data construct and                                                                  
> unmaps p[:64].  The question is, when (if ever) is the array section supposed                                                                    
> to be copied back to host?  Shall it be done at the end of thread's A target                                                                     
> data section, or at the end of thread's B target data section (i.e. propagate                                                                    
> the flag, has at least one of the mapping's requested copy from the device to                                                                    
> host at the end of it's lifetime), or not copied at all?                                                                                         
> What if thread B doesn't request the whole array section, but only a portion                                                                     
> thereof map(alloc:p[:32]) ?  Would it copy the whole p[:64] array section                                                                        
> back, or just a portion of it?  Though, admittedly, this latter case of a subset                                                                 
> might be harder to construct valid non-racy testcase for, one needs to make                                                                      
> sure one of the target data constructs is always entered before the other;                                                                       
> though perhaps with #pragma omp atomic and spinning it might be doable.                                                                          

and will just paraphrase the Sep 9th answer I got for that, because not sure I'm allowed
to repost it.  The answer was that on entry the standard is pretty clear what
happens, the first encountering thread/data construct allocates and optionally copies
based on the flags, all others when it is already mapped do nothing.  On exit, the
standard is silent and none of the solutions are right, the committee will discuss
it further.

So, for now the implementation choice was to or in the copy from device bit.

Now, you could argue this case is different, because it is not different threads,
but the same thread, just nested construct on the same thread.  But how to
reliably differentiate that?  Even if you stored some thread identification
into the tree along with each mapping (what thread mapped this in), what if some
other thread also does the same (outer #pragma omp target data, inner
#pragma omp target, where the outer one does just array section mapping and
inner tofrom mapping on the pointer), then we'd still copy back.

So, perhaps we should just stop for now oring the copyfrom in and just use
the copyfrom from the very first mapping only, and wait for what the committee
actually agrees on.

Richard, your thoughts on this?

	Jakub

  reply	other threads:[~2014-02-14 15:43 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
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 [this message]
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=20140214154304.GG20378@tucnak.redhat.com \
    --to=jakub@redhat.com \
    --cc=gcc@gcc.gnu.org \
    --cc=iverbin@gmail.com \
    --cc=kirill.yukhin@gmail.com \
    --cc=michael.v.zolotukhin@gmail.com \
    --cc=rth@redhat.com \
    --cc=sergos.gnu@gmail.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).