Skip to content

Commit

Permalink
[Flang][OpenMP] Derived type member map fortran offload runtime tests
Browse files Browse the repository at this point in the history
This is a large series of runtime tests that help to add coverage for the specific cases intended to be supported by the PR stack
that extends derived type map support in Flang+OpenMP. Primarily this will add functionality coverage, there's cases where
things may work, but not optimally (or at least similarly to the status quo in Clang), addiitonal IR tests are added in the
relevant segments of the related PRs to test for breakages like that.

Pull Request: llvm#82850
  • Loading branch information
agozillon committed Apr 24, 2024
1 parent b9f2c16 commit 7e2d35b
Show file tree
Hide file tree
Showing 30 changed files with 1,306 additions and 5 deletions.
45 changes: 45 additions & 0 deletions offload/test/offloading/fortran/target-map-derived-type-full-1.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
! Offloading test checking interaction of an
! explicit derived type mapping when mapped
! to target and assinging one derived type
! to another
! REQUIRES: flang, amdgcn-amd-amdhsa
! UNSUPPORTED: nvptx64-nvidia-cuda
! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
! UNSUPPORTED: aarch64-unknown-linux-gnu
! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
! UNSUPPORTED: x86_64-pc-linux-gnu
! UNSUPPORTED: x86_64-pc-linux-gnu-LTO

! RUN: %libomptarget-compile-fortran-run-and-check-generic
program main
type :: scalar
integer(4) :: ix = 0
real(4) :: rx = 0.0
complex(4) :: zx = (0,0)
end type scalar

type(scalar) :: in
type(scalar) :: out
in%ix = 10
in%rx = 2.0
in%zx = (2, 10)

!$omp target map(from:out) map(to:in)
out = in
!$omp end target

print*, in%ix
print*, in%rx
write (*,*) in%zx

print*, out%ix
print*, out%rx
write (*,*) out%zx
end program main

!CHECK: 10
!CHECK: 2.
!CHECK: (2.,10.)
!CHECK: 10
!CHECK: 2.
!CHECK: (2.,10.)
60 changes: 60 additions & 0 deletions offload/test/offloading/fortran/target-map-derived-type-full-2.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
! Offloading test checking interaction of an
! explicit derived type mapping when mapped to
! target and assigning to individual members
! REQUIRES: flang, amdgcn-amd-amdhsa
! UNSUPPORTED: nvptx64-nvidia-cuda
! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
! UNSUPPORTED: aarch64-unknown-linux-gnu
! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
! UNSUPPORTED: x86_64-pc-linux-gnu
! UNSUPPORTED: x86_64-pc-linux-gnu-LTO

! RUN: %libomptarget-compile-fortran-run-and-check-generic
program main
type :: scalar
integer(4) :: ix = 0
real(4) :: rx = 0.0
complex(4) :: zx = (0,0)
integer(4) :: array(5)
end type scalar

type(scalar) :: out
type(scalar) :: in

in%ix = 10
in%rx = 2.0
in%zx = (2, 10)

do i = 1, 5
in%array(i) = i
end do

!$omp target map(from:out) map(to:in)
out%ix = in%ix
out%rx = in%rx
out%zx = in%zx

do i = 1, 5
out%array(i) = in%array(i)
end do
!$omp end target

print*, in%ix
print*, in%rx
print*, in%array
write (*,*) in%zx

print*, out%ix
print*, out%rx
print*, out%array
write (*,*) out%zx
end program main

!CHECK: 10
!CHECK: 2.
!CHECK: 1 2 3 4 5
!CHECK: (2.,10.)
!CHECK: 10
!CHECK: 2.
!CHECK: 1 2 3 4 5
!CHECK: (2.,10.)
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
! Offloading test checking interaction of an
! implicit derived type mapping when mapped
! to target and assinging one derived type
! to another
! REQUIRES: flang, amdgcn-amd-amdhsa
! UNSUPPORTED: nvptx64-nvidia-cuda
! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
! UNSUPPORTED: aarch64-unknown-linux-gnu
! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
! UNSUPPORTED: x86_64-pc-linux-gnu
! UNSUPPORTED: x86_64-pc-linux-gnu-LTO

! RUN: %libomptarget-compile-fortran-run-and-check-generic
program main
type :: scalar
integer(4) :: ix = 0
real(4) :: rx = 0.0
complex(4) :: zx = (0,0)
end type scalar

type(scalar) :: in
type(scalar) :: out
in%ix = 10
in%rx = 2.0
in%zx = (2, 10)

!$omp target map(from:out)
out = in
!$omp end target

print*, in%ix
print*, in%rx
write (*,*) in%zx

print*, out%ix
print*, out%rx
write (*,*) out%zx
end program main

!CHECK: 10
!CHECK: 2.
!CHECK: (2.,10.)
!CHECK: 10
!CHECK: 2.
!CHECK: (2.,10.)

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
! Offloading test checking interaction of an
! explicit derived type mapping when mapped
! to target and assinging one derived type
! to another
! REQUIRES: flang, amdgcn-amd-amdhsa
! UNSUPPORTED: nvptx64-nvidia-cuda
! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
! UNSUPPORTED: aarch64-unknown-linux-gnu
! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
! UNSUPPORTED: x86_64-pc-linux-gnu
! UNSUPPORTED: x86_64-pc-linux-gnu-LTO

! RUN: %libomptarget-compile-fortran-run-and-check-generic
program main
type :: scalar
integer(4) :: ix = 0
real(4) :: rx = 0.0
complex(4) :: zx = (0,0)
integer(4) :: array(5)
end type scalar

type(scalar) :: out
type(scalar) :: in

in%ix = 10
in%rx = 2.0
in%zx = (2, 10)

do i = 1, 5
in%array(i) = i
end do

!$omp target
out%ix = in%ix
out%rx = in%rx
out%zx = in%zx

do i = 1, 5
out%array(i) = in%array(i)
end do
!$omp end target

print*, in%ix
print*, in%rx
print*, in%array
write (*,*) in%zx

print*, out%ix
print*, out%rx
print*, out%array
write (*,*) out%zx
end program main

!CHECK: 10
!CHECK: 2.
!CHECK: 1 2 3 4 5
!CHECK: (2.,10.)
!CHECK: 10
!CHECK: 2.
!CHECK: 1 2 3 4 5
!CHECK: (2.,10.)
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
! Offloading test checking interaction of an
! explicit member map from two large nested
! derived types
! REQUIRES: flang, amdgcn-amd-amdhsa
! UNSUPPORTED: nvptx64-nvidia-cuda
! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
! UNSUPPORTED: aarch64-unknown-linux-gnu
! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
! UNSUPPORTED: x86_64-pc-linux-gnu
! UNSUPPORTED: x86_64-pc-linux-gnu-LTO

! RUN: %libomptarget-compile-fortran-run-and-check-generic
program main
type :: bottom_layer1
real(4) :: i4
real(4) :: j4
real(4) :: k4
end type bottom_layer1

type :: bottom_layer2
integer(4) :: i3
integer(4) :: j3
integer(4) :: k3
end type bottom_layer2

type :: middle_layer
real(4) :: array_i2(10)
real(4) :: i2
real(4) :: array_j2(10)
type(bottom_layer1) :: nest
type(bottom_layer2) :: nest2
end type middle_layer

type :: top_layer
real(4) :: i
integer(4) :: array_i(10)
real(4) :: j
integer, allocatable :: array_j(:)
integer(4) :: k
type(middle_layer) :: nested
end type top_layer

type(top_layer) :: top_dtype
type(top_layer) :: top_dtype2

top_dtype2%nested%nest%i4 = 10
top_dtype2%nested%nest%j4 = 12
top_dtype2%nested%nest%k4 = 54

top_dtype2%nested%nest2%i3 = 20
top_dtype2%nested%nest2%j3 = 40
top_dtype2%nested%nest2%k3 = 60

top_dtype2%nested%i2 = 200

do i = 1, 10
top_dtype2%array_i(i) = i
end do

!$omp target map(from: top_dtype%nested%nest%j4, top_dtype%nested%nest%i4, top_dtype%nested%nest%k4) &
!$omp map(from: top_dtype%array_i, top_dtype%nested%nest2%i3, top_dtype%nested%i2) &
!$omp map(from: top_dtype%nested%nest2%k3, top_dtype%nested%nest2%j3) &
!$omp map(to: top_dtype2%nested%nest%j4, top_dtype2%nested%nest%i4, top_dtype2%nested%nest%k4) &
!$omp map(to: top_dtype2%array_i, top_dtype2%nested%nest2%i3, top_dtype2%nested%i2) &
!$omp map(to: top_dtype2%nested%nest2%k3, top_dtype2%nested%nest2%j3)
top_dtype%nested%nest%i4 = top_dtype2%nested%nest%i4
top_dtype%nested%nest%j4 = top_dtype2%nested%nest%j4
top_dtype%nested%nest%k4 = top_dtype2%nested%nest%k4

top_dtype%nested%nest2%i3 = top_dtype2%nested%nest2%i3
top_dtype%nested%nest2%j3 = top_dtype2%nested%nest2%j3
top_dtype%nested%nest2%k3 = top_dtype2%nested%nest2%k3

top_dtype%nested%i2 = top_dtype2%nested%i2

do i = 1, 10
top_dtype%array_i(i) = top_dtype2%array_i(i)
end do
!$omp end target

print *, top_dtype%nested%nest%i4
print *, top_dtype%nested%nest%j4
print *, top_dtype%nested%nest%k4

print *, top_dtype%nested%nest2%i3
print *, top_dtype%nested%nest2%j3
print *, top_dtype%nested%nest2%k3

print *, top_dtype%nested%i2

print *, top_dtype%array_i
end program main

!CHECK: 10.
!CHECK: 12.
!CHECK: 54.
!CHECK: 20
!CHECK: 40
!CHECK: 60
!CHECK: 200.
!CHECK: 1 2 3 4 5 6 7 8 9 10
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
! Offloading test checking interaction of two
! explicit arrau member maps with bounds from
! two nested derived types
! REQUIRES: flang, amdgcn-amd-amdhsa
! UNSUPPORTED: nvptx64-nvidia-cuda
! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
! UNSUPPORTED: aarch64-unknown-linux-gnu
! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
! UNSUPPORTED: x86_64-pc-linux-gnu
! UNSUPPORTED: x86_64-pc-linux-gnu-LTO

! RUN: %libomptarget-compile-fortran-run-and-check-generic
program main
type :: bottom_layer
real(8) :: i2
real(4) :: array_i2(10)
real(4) :: array_j2(10)
end type bottom_layer

type :: top_layer
real(4) :: i
integer(4) :: array_i(10)
real(4) :: j
type(bottom_layer) :: nested
integer, allocatable :: array_j(:)
integer(4) :: k
end type top_layer

type(top_layer) :: top_dtype
type(top_layer) :: top_dtype2

!$omp target map(tofrom: top_dtype%nested%array_i2(4:8), top_dtype2%nested%array_j2(4:8))
do i = 4, 8
top_dtype%nested%array_i2(i) = i * 2
end do

do i = 4, 8
top_dtype2%nested%array_j2(i) = i * 2
end do
!$omp end target

print *, top_dtype%nested%array_i2
print *, top_dtype2%nested%array_j2
end program main

!CHECK: 0. 0. 0. 8. 10. 12. 14. 16. 0. 0.
!CHECK: 0. 0. 0. 8. 10. 12. 14. 16. 0. 0.
Loading

0 comments on commit 7e2d35b

Please sign in to comment.