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