Debian Codegraph @

libgomp/testsuite/libgomp.oacc-fortran/routine-nohost-1.f90

raw
1 ! Test 'nohost' clause via 'acc_on_device'.
2
3 ! { dg-do run }
4
5 ! With optimizations disabled, we currently don't expect that 'acc_on_device' "evaluates at compile time to a constant".
6 ! { dg-skip-if "TODO PR82391" { *-*-* } { "-O0" } }
7
8 ! { dg-additional-options "-fdump-tree-oaccloops" }
9
10 ! { dg-additional-options "-fno-inline" } for stable results regarding OpenACC 'routine'.
11
12 program main
13 use openacc
14 implicit none
15 integer, parameter :: n = 10
16 integer :: a(n), i
17 integer, external :: fact_nohost
18 !$acc routine (fact_nohost)
19 integer, external :: fact
20
21 !$acc parallel loop
22 do i = 1, n
23 if (acc_on_device(acc_device_not_host)) then
24 a(i) = fact_nohost(i)
25 else
26 a(i) = 0
27 end if
28 end do
29 !$acc end parallel loop
30
31 do i = 1, n
32 if (acc_get_device_type() .eq. acc_device_host) then
33 if (a(i) .ne. 0) stop 10 + i
34 else
35 if (a(i) .ne. fact(i)) stop 20 + i
36 end if
37 end do
38 end program main
39
40 recursive function fact(x) result(res)
41 implicit none
42 !$acc routine (fact)
43 integer, intent(in) :: x
44 integer :: res
45
46 if (x < 1) then
47 res = 1
48 else
49 res = x * fact(x - 1)
50 end if
51 end function fact
52
53 function fact_nohost(x) result(res)
54 use openacc
55 implicit none
56 !$acc routine (fact_nohost) nohost
57 integer, intent(in) :: x
58 integer :: res
59 integer, external :: fact
60
61 res = fact(x)
62 end function fact_nohost
63 ! { dg-final { scan-tree-dump-times {(?n)^OpenACC routine 'fact_nohost' has 'nohost' clause\.$} 1 oaccloops { target { ! offloading_enabled } } } }
64 ! { dg-final { scan-tree-dump-times {(?n)^OpenACC routine 'fact_nohost_' has 'nohost' clause\.$} 1 oaccloops { target offloading_enabled } } }
65 !TODO See PR101551 for 'offloading_enabled' differences.