0

Declaring allocatable arrays and transferring them to GPU global memory using !$acc declare create and !$acc update device fails with Cray Fortran. It runs OK with PGI and NV Fortran. The following is the code

module gpu_module
implicit none
integer, parameter :: n = 1000000
real(kind=8), allocatable, dimension(:) :: a, b
!$acc declare create(a,b)
end module gpu_module
 
program openacc_example
use gpu_module
implicit none
real(kind=8) :: c(n)
integer :: i
 
allocate(a(1:n))
allocate(b(1:n))
! Initialize arrays
a(1:n) = 1.d0
b(1:n) = 2.d0
!$acc update device(a,b)
 
!$acc parallel loop gang vector present(a,b) copyout(c)
do i = 1, n
  c(i) = a(i) + b(i)
end do
print *, c(1), c(n)
 
end program openacc_example

It fails with the following error:

ftn -hacc declare.f90 -o aaa
srun -u ./aaa
ACC:            find_in_present_table failed for 'a(:)' (0x40000018000-0x400007b9200) from declare.f90:19
ACC: libcrayacc/acc_runtime.c:666 CRAY_ACC_ERROR - Variable not found in present table

For fixed size arrays, i.e. real(kind=8), dimension(1:n) :: a, b, the method using !$acc declare create and !$acc update device works fine. I wonder whether I need to do anything additional to fix the problem.

I found a workaround. If !$acc declare create(a,b) is removed and !$acc update device(a,b) is replaced with !$acc enter data copyin(a,b) the problem can be fixed. However, it is critical for me to be able to use !$acc declare create(a,b), since that allows me to declare variables in GPU global memory inside the module and later use that module wherever I needed.

0 Answers0