llvm-project/offload/test/offloading/fortran/target-descriptor-ops.f90
Joseph Huber c49460bae7
[flang-rt] Enable more runtime functions for the GPU target (#183649)
Summary:
This enables primarily `stop.cpp` and `descriptor.cpp`. Requires a
little bit of wrangling to get it to compile. Unlike the CUDA build,
this build uses an in-tree libc++ configured for the GPU. This is
configured without thread support, environment, or filesystem, and it is
not POSIX at all. So, no mutexes, pthreads, or get/setenv.

I tested stop, but i don't know if it's actually legal to exit from
OpenMP offloading.
2026-02-27 12:27:39 -06:00

51 lines
1.1 KiB
Fortran

! REQUIRES: flang, amdgpu
! RUN: %libomptarget-compile-fortran-run-and-check-generic
program main
implicit none
integer :: result
! CHECK: 100
result = 0
!$omp target map(from: result)
block
integer, allocatable :: arr(:)
integer :: i
allocate(arr(4))
do i = 1, 4
arr(i) = i * 10
end do
result = arr(1) + arr(2) + arr(3) + arr(4)
deallocate(arr)
end block
!$omp end target
print *, result
! CHECK: 21
result = 0
!$omp target map(from: result)
block
integer, allocatable :: mat(:,:)
allocate(mat(2, 3))
mat(1,1) = 1; mat(2,1) = 2
mat(1,2) = 3; mat(2,2) = 4
mat(1,3) = 5; mat(2,3) = 6
result = mat(1,1) + mat(2,1) + mat(1,2) + mat(2,2) + mat(1,3) + mat(2,3)
deallocate(mat)
end block
!$omp end target
print *, result
! CHECK: 17
result = 0
!$omp target map(from: result)
block
integer, allocatable :: arr(:)
allocate(arr(8))
result = size(arr) + lbound(arr, 1) + ubound(arr, 1)
deallocate(arr)
end block
!$omp end target
print *, result
end program main