brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.4 KiB · 61d096e Raw
86 lines · plain
1! Test for map type close, verifying it appropriately places memory2! near/on device when utilised in USM mode.3! REQUIRES: clang, flang, amdgpu4 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.o7! RUN: %libomptarget-compile-fortran-generic target-use-dev-ptr_c.o8! RUN: env HSA_XNACK=1 \9! RUN: %libomptarget-run-generic | %fcheck-generic10 11program use_device_test12    use iso_c_binding13    implicit none14    interface15       type(c_ptr) function get_ptr() BIND(C)16          USE, intrinsic :: iso_c_binding17          implicit none18       end function get_ptr19 20       integer(c_int) function check_equality(host, dev) BIND(C)21          USE, intrinsic :: iso_c_binding22          implicit none23          type(c_ptr), value, intent(in) :: host, dev24       end function check_equality25    end interface26    type(c_ptr) :: host_alloc, device_alloc27    integer, pointer :: a28  !$omp requires unified_shared_memory29 30    allocate(a)31    host_alloc = C_LOC(a)32 33! map + target no close34device_alloc = c_null_ptr35!$omp target data map(tofrom: a, device_alloc)36!$omp target map(tofrom: device_alloc)37    device_alloc = C_LOC(a)38!$omp end target39!$omp end target data40 41! CHECK: a used from unified memory42if (check_equality(host_alloc, device_alloc) == 1) then43    print*, "a used from unified memory"44end if45 46! map + target with close47device_alloc = c_null_ptr48!$omp target data map(close, tofrom: a) map(tofrom: device_alloc)49!$omp target map(tofrom: device_alloc)50    device_alloc = C_LOC(a)51!$omp end target52!$omp end target data53 54! CHECK: a copied to device55if (check_equality(host_alloc, device_alloc) == 0) then56    print *, "a copied to device"57end if58 59! map + use_device_ptr no close60device_alloc = c_null_ptr61!$omp target data map(tofrom: a) use_device_ptr(a)62    device_alloc = C_LOC(a)63!$omp end target data64 65! CHECK: a used from unified memory with use_device_ptr66if (check_equality(host_alloc, device_alloc) == 1) then67    print *, "a used from unified memory with use_device_ptr"68end if69 70! map enter/exit + close71device_alloc = c_null_ptr72!$omp target enter data map(close, to: a)73 74!$omp target map(from: device_alloc)75    device_alloc = C_LOC(a)76!$omp end target77 78!$omp target exit data map(from: a)79 80! CHECK: a has been mapped to the device81if (check_equality(host_alloc, device_alloc) == 0) then82    print *, "a has been mapped to the device"83end if84 85end program use_device_test86