Skip to content

Commit

Permalink
fix ACC deviceptr attribute usage in a separate Fortran subroutine ca…
Browse files Browse the repository at this point in the history
…ll with dummy call -> Fortran standard for ACC
  • Loading branch information
sbrdar authored and wdeconinck committed Dec 9, 2024
1 parent e8d275d commit 2deffad
Showing 1 changed file with 48 additions and 27 deletions.
75 changes: 48 additions & 27 deletions src/tests/field/fctest_field_wrap_gpu.F90
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,51 @@ module fcta_Field_wrap_device_fixture

! -----------------------------------------------------------------------------

subroutine kernel_1(view, N)
real(c_double) :: view(:,:,:)
integer, intent(in) :: N
!$acc data present(view)
!$acc parallel loop
do j=1,N
view(1,1,j) = real(j, c_double)
view(2,1,j) = -3_c_double
enddo
!$acc end data
end subroutine kernel_1


subroutine kernel_2(view, Ni, Nj, Nl)
real(c_double) :: view(:,:,:)
integer, intent(in) :: Ni, Nj, Nl
!$acc data deviceptr(view)
!$acc parallel loop
do i = 1, Ni
do j = 1, Nj
do l = 1, Nl
view(i,j,l) = -view(i,j,l)
enddo
enddo
enddo
!$acc end data
end subroutine kernel_2


subroutine kernel_3(view, Ni, Nj, Nk)
logical :: view(:,:,:)
integer, intent(in) :: Ni, Nj, Nk
!$acc data present(view)
!$acc parallel loop
do i=1,Ni
do j=1,Nj
do k=1,Nk
view(i,j,k) = (mod(k,3) == 0 )
enddo
enddo
enddo
!$acc end data
end subroutine kernel_3


TEST( test_field_wrapdata )
implicit none

Expand All @@ -60,13 +105,7 @@ module fcta_Field_wrap_device_fixture
call field%allocate_device()
call field%update_device()

!$acc data present(fview)
!$acc parallel loop
do j=1,N
fview(1,1,j) = real(j, c_double)
fview(2,1,j) = -3_c_double
enddo
!$acc end data
call kernel_1(fview, N)

j = N/2
FCTEST_CHECK_EQUAL( existing_data(1,1,j), -2._c_double )
Expand Down Expand Up @@ -112,16 +151,7 @@ module fcta_Field_wrap_device_fixture
call field%update_device()
call field%device_data(fview)

!$acc data deviceptr(fview)
!$acc parallel loop
do i = 1, Ni
do j = 1, Nj
do l = 1, Nl
fview(i,j,l) = -fview(i,j,l)
enddo
enddo
enddo
!$acc end data
call kernel_2(fview, Ni, Nj, Nl)

call field%update_host()
call field%deallocate_device()
Expand Down Expand Up @@ -171,16 +201,7 @@ module fcta_Field_wrap_device_fixture
call field%allocate_device()
call field%update_device()

!$acc data present(fview)
!$acc parallel loop
do i=1,Ni
do j=1,Nj
do k=1,Nk
fview(i,j,k) = (mod(k,3) == 0 )
enddo
enddo
enddo
!$acc end data
call kernel_3(fview, Ni, Nj, Nk)

FCTEST_CHECK_EQUAL( fview(1,1,1), .false. )
FCTEST_CHECK_EQUAL( fview(1,1,2), .true. )
Expand Down

0 comments on commit 2deffad

Please sign in to comment.