Hello,
I am having some difficulties in understanding the “reflected” clause. I have something like:
!$acc data region copy(a,b,c)
call foo(a,b,c)
...
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
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.
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:
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
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?
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.
Thank you very much for the detailed reply