blob: 540494ca2d698e31d167da712ced9ba0ed418c3b [file]
! Collapsed simd loops whose DO variable is a POINTER or a dummy argument
! store each iteration's value through it, to a target all SIMT lanes would
! share: check that they take the one-lane fallback and compute the right
! result. With a runtime step, the value stored is computed from a separate
! loop counter. The composite loops are only compiled: their DO variable
! is also shared between threads.
! Each POINTER DO variable gets a -Wopenmp warning, because the association
! status of a private copy of a pointer is undefined. The warning does not
! apply here: gfortran does not privatize the pointer, it iterates a
! separate integer counter and assigns each value through the pointer,
! which keeps the association it had before the loop. That assignment is
! the store to a shared target that this test is about.
! { dg-do run }
! { dg-additional-options "-O2 -fdump-tree-omplower-details" }
! { dg-xfail-if "--param=offload-gpu-mode=simt-directed needs the amdgcn SIMT series" { offload_target_amdgcn } }
! { dg-additional-options "--param=offload-gpu-mode=simt-directed" { target offload_target_amdgcn } }
module fallback_1_m
implicit none
integer, parameter :: ni = 4, nj = 300
contains
subroutine pointer_outer (b, c)
!$omp declare target
integer :: b(nj, ni), c(nj, ni)
integer, target :: t
integer, pointer :: p
integer :: j
p => t
!$omp simd collapse(2)
do p = 1, ni ! { dg-warning "has the POINTER attribute" }
do j = 1, nj
b(j, p) = j + 1000 * p
c(j, p) = p
end do
end do
end subroutine
! P points into E, and the store to E(K) may alias it, so P is read again
! after it: under SIMT, that read could see another lane's value.
subroutine pointer_inner (b, c, e, k)
!$omp declare target
integer :: b(nj, ni), c(nj, ni), k
integer, target :: e(2)
integer, pointer :: p
integer :: i
p => e(1)
!$omp simd collapse(2)
do i = 1, ni
do p = 1, nj ! { dg-warning "has the POINTER attribute" }
b(p, i) = p + 1000 * i
e(k) = i
c(p, i) = p
end do
end do
end subroutine
! As pointer_inner, with a runtime step.
subroutine pointer_inner_rstep (b, c, e, k, s)
!$omp declare target
integer :: b(nj, ni), c(nj, ni), k, s
integer, target :: e(2)
integer, pointer :: p
integer :: i
p => e(1)
!$omp simd collapse(2)
do i = 1, ni
do p = 1, nj, s ! { dg-warning "has the POINTER attribute" }
b(p, i) = p + 1000 * i
e(k) = i
c(p, i) = p
end do
end do
end subroutine
subroutine dummy_outer (b, c, d)
!$omp declare target
integer :: b(nj, ni), c(nj, ni), d
integer :: j
!$omp simd collapse(2)
do d = 1, ni
do j = 1, nj
b(j, d) = j + 1000 * d
c(j, d) = d
end do
end do
end subroutine
subroutine dummy_inner (b, c, d)
!$omp declare target
integer :: b(nj, ni), c(nj, ni), d
integer :: i
!$omp simd collapse(2)
do i = 1, ni
do d = 1, nj
b(d, i) = d + 1000 * i
c(d, i) = d
end do
end do
end subroutine
! Not called, see above.
subroutine pointer_composite (b, c)
!$omp declare target
integer :: b(nj, ni), c(nj, ni)
integer, target :: t
integer, pointer :: p
integer :: i
p => t
!$omp parallel do simd collapse(2)
do i = 1, ni
do p = 1, nj ! { dg-warning "has the POINTER attribute" }
b(p, i) = p + 1000 * i
c(p, i) = p
end do
end do
end subroutine
subroutine dummy_composite (b, c, d)
!$omp declare target
integer :: b(nj, ni), c(nj, ni), d
integer :: i
!$omp parallel do simd collapse(2)
do i = 1, ni
do d = 1, nj
b(d, i) = d + 1000 * i
c(d, i) = d
end do
end do
end subroutine
! The inner loop has step S: the elements it skips must still be -1.
subroutine check (b, c, outer, s)
integer :: b(nj, ni), c(nj, ni), s
logical :: outer
integer :: i, j
do i = 1, ni
do j = 1, nj
if (mod (j - 1, s) /= 0) then
if (b(j, i) /= -1 .or. c(j, i) /= -1) stop 4
cycle
end if
if (b(j, i) /= j + 1000 * i) stop 1
if (outer .and. c(j, i) /= i) stop 2
if (.not. outer .and. c(j, i) /= j) stop 3
end do
end do
end subroutine
end module
program fallback_1
use fallback_1_m
implicit none
integer :: b(nj, ni), c(nj, ni), d, e(2), k, s
volatile :: k, s
k = 2
s = 3
b = -1; c = -1
!$omp target map(tofrom: b, c)
call pointer_outer (b, c)
!$omp end target
call check (b, c, .true., 1)
b = -1; c = -1; e = 0
!$omp target map(tofrom: b, c, e) map(to: k)
call pointer_inner (b, c, e, k)
!$omp end target
call check (b, c, .false., 1)
b = -1; c = -1; e = 0
!$omp target map(tofrom: b, c, e) map(to: k, s)
call pointer_inner_rstep (b, c, e, k, s)
!$omp end target
call check (b, c, .false., s)
b = -1; c = -1; d = 0
!$omp target map(tofrom: b, c, d)
call dummy_outer (b, c, d)
!$omp end target
call check (b, c, .true., 1)
b = -1; c = -1; d = 0
!$omp target map(tofrom: b, c, d)
call dummy_inner (b, c, d)
!$omp end target
call check (b, c, .false., 1)
end program
! { dg-final { scan-tree-dump-times "collapsed loop cannot take the SIMT path: iteration variable value stored to memory" 7 "omplower" { target { offload_target_amdgcn || offload_target_nvptx } } } }
! { dg-final { scan-tree-dump-times "collapsed loop cannot take the SIMT path" 7 "omplower" { target { offload_target_amdgcn || offload_target_nvptx } } } }
! { dg-final { scan-tree-dump-not "_simt_" "omplower" { target { offload_target_amdgcn || offload_target_nvptx } } } }