Skip to content

Commit b575b70

Browse files
committed
[Flang][OpenMP] Derived type member map fortran offload runtime tests
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
1 parent 4ea850b commit b575b70

20 files changed

+848
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
! Offloading test checking interaction of an
2+
! explicit derived type mapping when mapped
3+
! to target and assinging one derived type
4+
! to another
5+
! REQUIRES: flang, amdgcn-amd-amdhsa
6+
! UNSUPPORTED: nvptx64-nvidia-cuda
7+
! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
8+
! UNSUPPORTED: aarch64-unknown-linux-gnu
9+
! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
10+
! UNSUPPORTED: x86_64-pc-linux-gnu
11+
! UNSUPPORTED: x86_64-pc-linux-gnu-LTO
12+
13+
! RUN: %libomptarget-compile-fortran-run-and-check-generic
14+
program main
15+
type :: scalar
16+
integer(4) :: ix = 0
17+
real(4) :: rx = 0.0
18+
complex(4) :: zx = (0,0)
19+
end type scalar
20+
21+
type(scalar) :: in
22+
type(scalar) :: out
23+
in%ix = 10
24+
in%rx = 2.0
25+
in%zx = (2, 10)
26+
27+
!$omp target map(from:out) map(to:in)
28+
out = in
29+
!$omp end target
30+
31+
print*, in%ix
32+
print*, in%rx
33+
write (*,*) in%zx
34+
35+
print*, out%ix
36+
print*, out%rx
37+
write (*,*) out%zx
38+
end program main
39+
40+
!CHECK: 10
41+
!CHECK: 2.
42+
!CHECK: (2.,10.)
43+
!CHECK: 10
44+
!CHECK: 2.
45+
!CHECK: (2.,10.)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
! Offloading test checking interaction of an
2+
! explicit derived type mapping when mapped to
3+
! target and assigning to individual members
4+
! REQUIRES: flang, amdgcn-amd-amdhsa
5+
! UNSUPPORTED: nvptx64-nvidia-cuda
6+
! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
7+
! UNSUPPORTED: aarch64-unknown-linux-gnu
8+
! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
9+
! UNSUPPORTED: x86_64-pc-linux-gnu
10+
! UNSUPPORTED: x86_64-pc-linux-gnu-LTO
11+
12+
! RUN: %libomptarget-compile-fortran-run-and-check-generic
13+
program main
14+
type :: scalar
15+
integer(4) :: ix = 0
16+
real(4) :: rx = 0.0
17+
complex(4) :: zx = (0,0)
18+
integer(4) :: array(5)
19+
end type scalar
20+
21+
type(scalar) :: out
22+
type(scalar) :: in
23+
24+
in%ix = 10
25+
in%rx = 2.0
26+
in%zx = (2, 10)
27+
28+
do i = 1, 5
29+
in%array(i) = i
30+
end do
31+
32+
!$omp target map(from:out) map(to:in)
33+
out%ix = in%ix
34+
out%rx = in%rx
35+
out%zx = in%zx
36+
37+
do i = 1, 5
38+
out%array(i) = in%array(i)
39+
end do
40+
!$omp end target
41+
42+
print*, in%ix
43+
print*, in%rx
44+
print*, in%array
45+
write (*,*) in%zx
46+
47+
print*, out%ix
48+
print*, out%rx
49+
print*, out%array
50+
write (*,*) out%zx
51+
end program main
52+
53+
!CHECK: 10
54+
!CHECK: 2.
55+
!CHECK: 1 2 3 4 5
56+
!CHECK: (2.,10.)
57+
!CHECK: 10
58+
!CHECK: 2.
59+
!CHECK: 1 2 3 4 5
60+
!CHECK: (2.,10.)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
! Offloading test checking interaction of an
2+
! implicit derived type mapping when mapped
3+
! to target and assinging one derived type
4+
! to another
5+
! REQUIRES: flang, amdgcn-amd-amdhsa
6+
! UNSUPPORTED: nvptx64-nvidia-cuda
7+
! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
8+
! UNSUPPORTED: aarch64-unknown-linux-gnu
9+
! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
10+
! UNSUPPORTED: x86_64-pc-linux-gnu
11+
! UNSUPPORTED: x86_64-pc-linux-gnu-LTO
12+
13+
! RUN: %libomptarget-compile-fortran-run-and-check-generic
14+
program main
15+
type :: scalar
16+
integer(4) :: ix = 0
17+
real(4) :: rx = 0.0
18+
complex(4) :: zx = (0,0)
19+
end type scalar
20+
21+
type(scalar) :: in
22+
type(scalar) :: out
23+
in%ix = 10
24+
in%rx = 2.0
25+
in%zx = (2, 10)
26+
27+
!$omp target map(from:out)
28+
out = in
29+
!$omp end target
30+
31+
print*, in%ix
32+
print*, in%rx
33+
write (*,*) in%zx
34+
35+
print*, out%ix
36+
print*, out%rx
37+
write (*,*) out%zx
38+
end program main
39+
40+
!CHECK: 10
41+
!CHECK: 2.
42+
!CHECK: (2.,10.)
43+
!CHECK: 10
44+
!CHECK: 2.
45+
!CHECK: (2.,10.)
46+
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
! Offloading test checking interaction of an
2+
! explicit derived type mapping when mapped
3+
! to target and assinging one derived type
4+
! to another
5+
! REQUIRES: flang, amdgcn-amd-amdhsa
6+
! UNSUPPORTED: nvptx64-nvidia-cuda
7+
! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
8+
! UNSUPPORTED: aarch64-unknown-linux-gnu
9+
! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
10+
! UNSUPPORTED: x86_64-pc-linux-gnu
11+
! UNSUPPORTED: x86_64-pc-linux-gnu-LTO
12+
13+
! RUN: %libomptarget-compile-fortran-run-and-check-generic
14+
program main
15+
type :: scalar
16+
integer(4) :: ix = 0
17+
real(4) :: rx = 0.0
18+
complex(4) :: zx = (0,0)
19+
integer(4) :: array(5)
20+
end type scalar
21+
22+
type(scalar) :: out
23+
type(scalar) :: in
24+
25+
in%ix = 10
26+
in%rx = 2.0
27+
in%zx = (2, 10)
28+
29+
do i = 1, 5
30+
in%array(i) = i
31+
end do
32+
33+
!$omp target
34+
out%ix = in%ix
35+
out%rx = in%rx
36+
out%zx = in%zx
37+
38+
do i = 1, 5
39+
out%array(i) = in%array(i)
40+
end do
41+
!$omp end target
42+
43+
print*, in%ix
44+
print*, in%rx
45+
print*, in%array
46+
write (*,*) in%zx
47+
48+
print*, out%ix
49+
print*, out%rx
50+
print*, out%array
51+
write (*,*) out%zx
52+
end program main
53+
54+
!CHECK: 10
55+
!CHECK: 2.
56+
!CHECK: 1 2 3 4 5
57+
!CHECK: (2.,10.)
58+
!CHECK: 10
59+
!CHECK: 2.
60+
!CHECK: 1 2 3 4 5
61+
!CHECK: (2.,10.)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
! Offloading test checking interaction of an
2+
! explicit derived type member mapping of
3+
! an array with bounds when mapped to
4+
! target using a combination of update,
5+
! enter and exit directives.
6+
! REQUIRES: flang, amdgcn-amd-amdhsa
7+
! UNSUPPORTED: nvptx64-nvidia-cuda
8+
! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
9+
! UNSUPPORTED: aarch64-unknown-linux-gnu
10+
! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
11+
! UNSUPPORTED: x86_64-pc-linux-gnu
12+
! UNSUPPORTED: x86_64-pc-linux-gnu-LTO
13+
14+
! RUN: %libomptarget-compile-fortran-run-and-check-generic
15+
program main
16+
type :: scalar_array
17+
integer(4) :: array(10)
18+
end type scalar_array
19+
20+
type(scalar_array) :: scalar_arr
21+
22+
do I = 1, 10
23+
scalar_arr%array(I) = I + I
24+
end do
25+
26+
!$omp target enter data map(to: scalar_arr%array(3:6))
27+
28+
! overwrite our target data with an update.
29+
do I = 1, 10
30+
scalar_arr%array(I) = 10
31+
end do
32+
33+
!$omp target update to(scalar_arr%array(3:6))
34+
35+
! The compiler/runtime is less friendly about read/write out of
36+
! bounds when using enter and exit, we have to specifically loop
37+
! over the correct range
38+
!$omp target
39+
do i=3,6
40+
scalar_arr%array(i) = scalar_arr%array(i) + i
41+
end do
42+
!$omp end target
43+
44+
!$omp target exit data map(from: scalar_arr%array(3:6))
45+
46+
print*, scalar_arr%array
47+
end program
48+
49+
!CHECK: 10 10 13 14 15 16 10 10 10 10
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
! Offloading test checking interaction of an
2+
! explicit derived type member mapping of
3+
! an array with bounds when mapped to
4+
! target using a combination of enter and
5+
! exit directives.
6+
! REQUIRES: flang, amdgcn-amd-amdhsa
7+
! UNSUPPORTED: nvptx64-nvidia-cuda
8+
! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
9+
! UNSUPPORTED: aarch64-unknown-linux-gnu
10+
! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
11+
! UNSUPPORTED: x86_64-pc-linux-gnu
12+
! UNSUPPORTED: x86_64-pc-linux-gnu-LTO
13+
14+
! RUN: %libomptarget-compile-fortran-run-and-check-generic
15+
program main
16+
type :: scalar_array
17+
integer(4) :: array(10)
18+
end type scalar_array
19+
20+
type(scalar_array) :: scalar_arr
21+
22+
do I = 1, 10
23+
scalar_arr%array(I) = I + I
24+
end do
25+
26+
!$omp target enter data map(to: scalar_arr%array(3:6))
27+
28+
! Shouldn't overwrite data already locked in
29+
! on target via enter, which will then be
30+
! overwritten by our exit
31+
do I = 1, 10
32+
scalar_arr%array(I) = 10
33+
end do
34+
35+
! The compiler/runtime is less friendly about read/write out of
36+
! bounds when using enter and exit, we have to specifically loop
37+
! over the correct range
38+
!$omp target
39+
do i=3,6
40+
scalar_arr%array(i) = scalar_arr%array(i) + i
41+
end do
42+
!$omp end target
43+
44+
!$omp target exit data map(from: scalar_arr%array(3:6))
45+
46+
print*, scalar_arr%array
47+
end program
48+
49+
!CHECK: 10 10 9 12 15 18 10 10 10 10
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
! Offloading test checking interaction of an
2+
! explicit derived type member mapping of
3+
! an array when mapped to target
4+
! REQUIRES: flang, amdgcn-amd-amdhsa
5+
! UNSUPPORTED: nvptx64-nvidia-cuda
6+
! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
7+
! UNSUPPORTED: aarch64-unknown-linux-gnu
8+
! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
9+
! UNSUPPORTED: x86_64-pc-linux-gnu
10+
! UNSUPPORTED: x86_64-pc-linux-gnu-LTO
11+
12+
! RUN: %libomptarget-compile-fortran-run-and-check-generic
13+
program main
14+
type :: scalar_array
15+
real(4) :: break_0
16+
real(4) :: array_x(10)
17+
real(4) :: break_1
18+
real(4) :: array_y(10)
19+
real(4) :: break_3
20+
end type scalar_array
21+
22+
type(scalar_array) :: scalar_arr
23+
24+
!$omp target map(tofrom:scalar_arr%array_y)
25+
do i = 1, 10
26+
scalar_arr%array_y(i) = i
27+
end do
28+
!$omp end target
29+
30+
print *, scalar_arr%array_y
31+
end program main
32+
33+
!CHECK: 1. 2. 3. 4. 5. 6. 7. 8. 9. 10.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
! Offloading test checking interaction of an
2+
! explicit derived type member mapping of
3+
! two arrays with explicit bounds when
4+
! mapped to target
5+
! REQUIRES: flang, amdgcn-amd-amdhsa
6+
! UNSUPPORTED: nvptx64-nvidia-cuda
7+
! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
8+
! UNSUPPORTED: aarch64-unknown-linux-gnu
9+
! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
10+
! UNSUPPORTED: x86_64-pc-linux-gnu
11+
! UNSUPPORTED: x86_64-pc-linux-gnu-LTO
12+
13+
! RUN: %libomptarget-compile-fortran-run-and-check-generic
14+
program main
15+
type :: scalar_array
16+
real(4) :: break_0
17+
integer(4) :: array_x(3,3,3)
18+
real(4) :: break_1
19+
integer(4) :: array_y(3,3,3)
20+
real(4) :: break_3
21+
end type scalar_array
22+
23+
type(scalar_array) :: scalar_arr
24+
25+
do i = 1, 3
26+
do j = 1, 3
27+
do k = 1, 3
28+
scalar_arr%array_x(i, j, k) = 42
29+
scalar_arr%array_y(i, j, k) = 0 ! Will get overwritten by garbage values in target
30+
end do
31+
end do
32+
end do
33+
34+
!$omp target map(tofrom:scalar_arr%array_x(1:3, 1:3, 2:2), scalar_arr%array_y(1:3, 1:3, 1:3))
35+
do j = 1, 3
36+
do k = 1, 3
37+
scalar_arr%array_y(k, j, 2) = scalar_arr%array_x(k, j, 2)
38+
end do
39+
end do
40+
!$omp end target
41+
42+
print *, scalar_arr%array_y
43+
end program main
44+
45+
!CHECK: 0 0 0 0 0 0 0 0 0 42 42 42 42 42 42 42 42 42 0 0 0 0 0 0 0 0

0 commit comments

Comments
 (0)