xref: /llvm-project/offload/test/offloading/fortran/target-use-dev-ptr.f90 (revision d84d0caf28902843e0aae7ac435daed9aa04e3e2)
1! Basic test of use_device_ptr, checking if the appropriate
2! addresses are maintained across target boundaries
3! REQUIRES: clang, flang, amdgcn-amd-amdhsa
4
5! RUN: %clang -c -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa \
6! RUN:   %S/../../Inputs/target-use-dev-ptr.c -o target-use-dev-ptr_c.o
7! RUN: %libomptarget-compile-fortran-generic target-use-dev-ptr_c.o
8! RUN: %t | %fcheck-generic
9
10program use_device_test
11   use iso_c_binding
12   interface
13      type(c_ptr) function get_ptr() BIND(C)
14         USE, intrinsic :: iso_c_binding
15         implicit none
16      end function get_ptr
17
18      integer(c_int) function check_result(host, dev) BIND(C)
19         USE, intrinsic :: iso_c_binding
20         implicit none
21         type(c_ptr), intent(in) :: host, dev
22      end function check_result
23   end interface
24
25   type(c_ptr) :: device_ptr, x
26
27   x = get_ptr()
28   device_ptr = x
29
30   !$omp target data map(tofrom: x) use_device_ptr(x)
31   device_ptr = x
32   !$omp end target data
33
34   print *, check_result(x, device_ptr)
35end program use_device_test
36
37! CHECK: SUCCESS
38