Hi (again),
Is there any way using !$acc directives to share data already located on the GPU with Fortran subroutines?
When I compile the test code below with v10.6.0 of the pgf90 compiler, the (edited) output reads:
test_data_spans_subs:
32, Generating copyin(u(:))
sub1:
47, Generating copyin(u(1:100))
sub2:
63, Generating copyin(u(1:100))
Line 32 is the data region in the main program. I would like to eliminate the repeat data copying in the subroutines (lines 47 and 63).
I don’t mind promoting u into MODULE my_data (and not passing it) but I couldn’t find how to make that work either.
Thanks for any advice you can offer,
Alistair.
!!$**************************************
MODULE my_data
IMPLICIT NONE
INTEGER, PARAMETER :: N = 100
END MODULE my_data
!!$**************************************
PROGRAM test_data_spans_subs
USE my_data
IMPLICIT NONE
INTEGER :: u(N)
INTEGER :: i,r
DO i = 1,N
u(i) = i
ENDDO
!!$ Attempt 1: inlined
!$acc data region copyin(u)
!$acc region
r = SUM(u)
!$acc end region
PRINT *,"Total 1: ",r
!$acc region
r = SUM(u**2)
!$acc end region
PRINT *,"Total 2: ",r
!$acc end data region
!!$ Attempt 2: subroutines
!$acc data region copyin(u)
CALL sub1(u)
CALL sub2(u)
!$acc end data region
END PROGRAM test_data_spans_subs
!!$**************************************
SUBROUTINE sub1(u)
USE my_data
IMPLICIT NONE
INTEGER, INTENT(in) :: u(N)
INTEGER :: r
!$acc region
r = SUM(u)
!$acc end region
PRINT *,"Total 1: ",r
END SUBROUTINE sub1
!!$**************************************
SUBROUTINE sub2(u)
USE my_data
IMPLICIT NONE
INTEGER, INTENT(in) :: u(N)
INTEGER :: r
!$acc region
r = SUM(u**2)
!$acc end region
PRINT *,"Total 2: ",r
END SUBROUTINE sub2
!!$**************************************