Debian Codegraph @

libgomp/testsuite/libgomp.fortran/examples-4/declare_target-1.f90

raw
1 ! { dg-do run }
2 ! { dg-additional-sources ../on_device_arch.c }
3 ! { dg-additional-options -Wno-complain-wrong-lang }
4
5 module e_53_1_mod
6 integer :: THRESHOLD = 20
7 contains
8 integer recursive function fib (n) result (f)
9 !$omp declare target
10 integer :: n
11 if (n <= 0) then
12 f = 0
13 else if (n == 1) then
14 f = 1
15 else
16 f = fib (n - 1) + fib (n - 2)
17 end if
18 end function
19
20 integer function fib_wrapper (n)
21 integer :: x
22 !$omp target map(to: n) map(from: x) if(n > THRESHOLD)
23 x = fib (n)
24 !$omp end target
25 fib_wrapper = x
26 end function
27 end module
28
29 program e_53_1
30 use e_53_1_mod, only : fib, fib_wrapper
31 integer :: REC_DEPTH = 25
32
33 interface
34 integer function on_device_arch_nvptx() bind(C)
35 end function on_device_arch_nvptx
36 end interface
37
38 if (on_device_arch_nvptx () /= 0) then
39 ! Reduced from 25 to 23, otherwise execution runs out of thread stack on
40 ! Nvidia Titan V.
41 ! Reduced from 23 to 22, otherwise execution runs out of thread stack on
42 ! Nvidia T400 (2GB variant), when run with GOMP_NVPTX_JIT=-O0.
43 ! Reduced from 22 to 20, otherwise execution runs out of thread stack on
44 ! Nvidia RTX A2000 (6GB variant), when run with GOMP_NVPTX_JIT=-O0.
45 REC_DEPTH = 20
46 end if
47
48 if (fib (15) /= fib_wrapper (15)) stop 1
49 if (fib (REC_DEPTH) /= fib_wrapper (REC_DEPTH)) stop 2
50 end program