| 1 |
! { dg-do run } |
| 2 |
! { dg-additional-options "-foffload-options=nvptx-none=-misa=sm_35" { target { offload_target_nvptx } } } |
| 3 |
! { dg-additional-sources reverse-offload-1-aux.f90 } |
| 4 |
|
| 5 |
! Check that reverse offload works in particular: |
| 6 |
! - no code is generated on the device side (i.e. no |
| 7 |
! implicit declare target of called functions and no |
| 8 |
! code gen for the target-region body) |
| 9 |
! -> would otherwise fail due to 'add_3' symbol |
| 10 |
! - Plus the usual (compiles, runs, produces correct result) |
| 11 |
|
| 12 |
! Note: Running also the non-reverse-offload target regions |
| 13 |
! on the host (host fallback) is valid and will pass. |
| 14 |
|
| 15 |
module m |
| 16 |
interface |
| 17 |
integer function add_3 (x) |
| 18 |
implicit none |
| 19 |
integer, value :: x |
| 20 |
end function |
| 21 |
end interface |
| 22 |
integer :: global_var = 5 |
| 23 |
end module m |
| 24 |
|
| 25 |
module m2 |
| 26 |
use m |
| 27 |
!$omp requires reverse_offload |
| 28 |
implicit none (type, external) |
| 29 |
contains |
| 30 |
subroutine check_offload (x, y) |
| 31 |
integer :: x, y |
| 32 |
x = add_3(x) |
| 33 |
y = add_3(y) |
| 34 |
end subroutine check_offload |
| 35 |
subroutine m2_tg_fn(x, y) |
| 36 |
integer :: x, y |
| 37 |
!$omp declare target |
| 38 |
if (x /= 2 .or. y /= 3) stop 1 |
| 39 |
x = x + 2 |
| 40 |
y = y + 7 |
| 41 |
!$omp target device(ancestor : 1) map(tofrom: x) |
| 42 |
call check_offload(x, y) |
| 43 |
!$omp end target |
| 44 |
if (x /= 2+2+3 .or. y /= 3 + 7) stop 2 |
| 45 |
end subroutine |
| 46 |
end module m2 |
| 47 |
|
| 48 |
program main |
| 49 |
use m |
| 50 |
!$omp requires reverse_offload |
| 51 |
implicit none (type, external) |
| 52 |
|
| 53 |
integer :: prog_var = 99 |
| 54 |
|
| 55 |
!$omp target |
| 56 |
block |
| 57 |
use m2 |
| 58 |
integer :: x, y |
| 59 |
x = 2; y = 3 |
| 60 |
call m2_tg_fn (x, y) |
| 61 |
end block |
| 62 |
|
| 63 |
!$omp target |
| 64 |
block |
| 65 |
use m2 |
| 66 |
integer :: x, y |
| 67 |
x = -2; y = -1 |
| 68 |
!$omp target device ( ancestor:1 ) firstprivate(y) map(tofrom:x) |
| 69 |
if (x /= -2 .or. y /= -1) stop 3 |
| 70 |
call my_func (x, y) |
| 71 |
if (x /= 2*(3-2) .or. y /= 3*(3-1)) stop 5 |
| 72 |
!$omp end target |
| 73 |
if (x /= 2*(3-2) .or. y /= -1) stop 6 |
| 74 |
end block |
| 75 |
|
| 76 |
if (prog_var /= 41 .or. global_var /= 242) stop 7 |
| 77 |
|
| 78 |
contains |
| 79 |
|
| 80 |
subroutine my_func(x, y) |
| 81 |
integer :: x, y |
| 82 |
if (prog_var /= 99) stop 8 |
| 83 |
if (global_var /= 5) stop 9 |
| 84 |
prog_var = 41 |
| 85 |
global_var = 242 |
| 86 |
x = 2*add_3(x) |
| 87 |
y = 3*add_3(y) |
| 88 |
end subroutine my_func |
| 89 |
end |