PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Webinar

Understanding the reflected clause

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Accelerator Programming
View previous topic :: View next topic  
Author Message
_sayan_



Joined: 07 Apr 2012
Posts: 29

PostPosted: Thu Jun 07, 2012 6:58 am    Post subject: Understanding the reflected clause Reply with quote

Hello,

I am having some difficulties in understanding the "reflected" clause. I have something like:

Code:

!$acc data region copy(a,b,c)
call foo(a,b,c)
...



Code:

sub foo(a,b,c)
real, intent(in) :: a(min:max), b(min:max), c(min:max)
!$acc region
do i=1,N
do j=1,N
!compute using a,b,c
d(i,j) = a(j)*b(j)*c(j) !d is mirrored here
endo
endo
....


In the above case, if I don't 'reflect' a, b and c, what happens in the acc region? I was thinking there would not be any extra data transfers since in the enclosing data region, I have already copied a,b and c to the gpu.

Thank you.
Sayan
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6215
Location: The Portland Group Inc.

PostPosted: Thu Jun 07, 2012 11:50 am    Post subject: Reply with quote

Quote:
In the above case, if I don't 'reflect' a, b and c, what happens in the acc region?
A second copy of a, b, and c will be copied to the GPU.

Quote:
I was thinking there would not be any extra data transfers since in the enclosing data region, I have already copied a,b and c to the gpu.
The compiler has no visibility to know that foo was called from an data region. Hence, you need to use the reflected directive to tell the compiler to add the code required to perform a run time check to find the device copies of the variables.

So you need to add:
Code:

sub foo(a,b,c)
real, intent(in) :: a(min:max), b(min:max), c(min:max)
!$acc reflected (a,b,c)
!$acc region
do i=1,N
do j=1,N
!compute using a,b,c
d(i,j) = a(j)*b(j)*c(j) !d is mirrored here
endo
endo

Note that foo must have an interface, either explicit or implicit, in order to use reflected. Given d is mirrored, I assume foo is declared in a module and hence does have an implicit interface.

Hope this helps,
Mat
Back to top
View user's profile
_sayan_



Joined: 07 Apr 2012
Posts: 29

PostPosted: Thu Jun 07, 2012 2:33 pm    Post subject: Reply with quote

Thank you very much, I assume that since 'd' doesn't appear as an argument, the compiler would know that it is in the device space. An off track question - I think when d is deallocated at the host space, the subsequent device copy will also be deallocated, and not when the data region ends (as opposed to the arrays which appear in data region subclauses like copy(...),copyin(...) for eg.). Am I right?
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6215
Location: The Portland Group Inc.

PostPosted: Thu Jun 07, 2012 3:00 pm    Post subject: Reply with quote

Quote:
I assume that since 'd' doesn't appear as an argument, the compiler would know that it is in the device space. I think when d is deallocated at the host space, the subsequent device copy will also be deallocated, and not when the data region ends (as opposed to the arrays which appear in data region subclauses like copy(...),copyin(...) for eg.). Am I right?
A mirror directive mirrors the allocation status of the host variable. When the host variable is allocated, a device copy is also allocated. When the host variable is deallocated, then the device variable is deallocated. The mirror directive also creates an implicit data region having the same lifetime as the host variable. Also, data regions can be nested and are independent so your explicit data region has no impact on d.

One major difference is that mirror does not perform any data movement. Hence, you must use the update directive to explicitly copy data between the host and device.

- Mat
Back to top
View user's profile
_sayan_



Joined: 07 Apr 2012
Posts: 29

PostPosted: Fri Jun 08, 2012 7:18 am    Post subject: Reply with quote

Thank you very much for the detailed reply
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Accelerator Programming All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group