best equivalent of mirror in OpenACC

Hello,
I read there is no mirror equivalent in OpenACC. I am wondering about the best way to “translate” it in OpenACC. Starting from a trivial example:

module storage
   integer, parameter :: N=1000
   real, dimension(:,:), allocatable :: A,B,C
!$acc mirror(A,B,C) 
end module storage

subroutine matadd_sub()  
   use storage; implicit none
   integer :: i,j
!$acc region 
   do i=1,N  
      do j=1,N  
         C(i,j) = A(i,j) + B(i,j)
      enddo
   enddo     
!$acc end region 
end subroutine matadd_sub

program matadd  
   use storage  ; implicit none 
   allocate(A(N,N),B(N,N),C(N,N))
   A = 1.  ; B = 2.  ; C = 0. 
!$acc update device(A,B) 
   call matadd_sub() 
!$acc update host(C) 
   print*,"C: ",C(6,3)
end program matadd

I think a possibility is:

module storage
   integer, parameter :: N=1000
   real, dimension(:,:), allocatable :: A,B,C
end module storage 

subroutine matadd_sub()
   use storage; implicit none
   integer :: i,j
!$acc kernels loop present(A,B,C)
   do i=1,N  
      do j=1,N
         C(i,j) = A(i,j) + B(i,j)
      enddo       
   enddo   
!$acc end kernels 
end subroutine matadd_sub

program matadd
   use storage  ; implicit none
   allocate(A(N,N),B(N,N),C(N,N))
   A = 1.  ; B = 2.  ; C = 0. 
!$acc data region copyin(A,B) copyout(C)
   call matadd_sub() 
!$acc end data region
   print*,"C: ",C(6,3)
end program matadd

It seems to work with PGI 12.3. But I would prefer much something like

module storage
   integer, parameter :: N=1000
   real, dimension(:,:), allocatable :: A,B,C
!$acc declare device_resident(A,B,C) ! I do not know the clause
end module storage

subroutine matadd_sub()  
   use storage; implicit none
   integer :: i,j
!$acc kernels 
   do i=1,N  
      do j=1,N  
         C(i,j) = A(i,j) + B(i,j)
      enddo
   enddo     
!$acc end kernels 
end subroutine matadd_sub

program matadd  
   use storage  ; implicit none 
   allocate(A(N,N),B(N,N),C(N,N))
   A = 1.  ; B = 2.  ; C = 0. 
!$acc update device(A,B) 
   call matadd_sub() 
!$acc update host(C) 
   print*,"C: ",C(6,3)
end program matadd

This second version seems to be incorrect. Is it possibile to do modify it to make it working?

thanks in advance,
Francesco

Hi Francesco,

!$acc declare device_resident(A,B,C) ! I do not know the clause

You got it correct. “device_resident” is the closest OpenACC equivalent to mirror. However, it’s not supported in the 12.3 OpenACC beta. “device_resident” should be available by the full release in June.

  • Mat