llvm-project/offload/test/offloading/fortran/declare-target-automap.f90
Akash Banerjee 5a5e8ba0c3
[MLIR][OpenMP] Add a new AutomapToTargetData conversion pass in FIR (#151989)
Add a new `AutomapToTargetData` pass. This gathers the declare target
enter variables which have the `AUTOMAP` modifier. And adds
`omp.declare_target_enter/exit` mapping directives for `fir.allocmem`
and `fir.freemem` oeprations on the `AUTOMAP` enabled variables.

Automap Ref: OpenMP 6.0 section 7.9.7.
2025-08-11 13:18:38 +01:00

37 lines
1.2 KiB
Fortran

!Offloading test for AUTOMAP modifier in declare target enter
! REQUIRES: flang, amdgpu
program automap_program
use iso_c_binding, only: c_loc
use omp_lib, only: omp_get_default_device, omp_target_is_present
integer, parameter :: N = 10
integer :: i
integer, allocatable, target :: automap_array(:)
!$omp declare target enter(automap:automap_array)
! false since the storage is not present even though the descriptor is present
write (*, *) omp_target_is_present(c_loc(automap_array), omp_get_default_device())
! CHECK: 0
allocate (automap_array(N))
! true since the storage should be allocated and reference count incremented by the allocate
write (*, *) omp_target_is_present(c_loc(automap_array), omp_get_default_device())
! CHECK: 1
! since storage is present this should not be a runtime error
!$omp target teams loop
do i = 1, N
automap_array(i) = i
end do
!$omp target update from(automap_array)
write (*, *) automap_array
! CHECK: 1 2 3 4 5 6 7 8 9 10
deallocate (automap_array)
! automap_array should have it's storage unmapped on device here
write (*, *) omp_target_is_present(c_loc(automap_array), omp_get_default_device())
! CHECK: 0
end program