Skip to content

Commit c4619c1

Browse files
committed
Add offload tests
1 parent fd8afce commit c4619c1

File tree

3 files changed

+138
-0
lines changed

3 files changed

+138
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
!REQUIRES: flang, amdgpu
2+
3+
!Test derived from the sollve test for has-device-addr.
4+
5+
!RUN: %libomptarget-compile-fortran-run-and-check-generic
6+
7+
module m
8+
use iso_c_binding
9+
10+
contains
11+
integer function target_has_device_addr()
12+
integer :: errors
13+
integer, target :: x
14+
integer, pointer :: first_scalar_device_addr
15+
type(c_ptr) :: cptr_scalar1
16+
17+
integer :: res1, res2
18+
19+
nullify (first_scalar_device_addr)
20+
errors = 0
21+
x = 10
22+
23+
!$omp target enter data map(to: x)
24+
!$omp target data use_device_addr(x)
25+
x = 11
26+
cptr_scalar1 = c_loc(x)
27+
!$omp end target data
28+
29+
call c_f_pointer (cptr_scalar1, first_scalar_device_addr)
30+
31+
!$omp target map(to: x) map(from: res1, res2) &
32+
!$omp & has_device_addr(first_scalar_device_addr)
33+
res1 = first_scalar_device_addr
34+
res2 = x
35+
!$omp end target
36+
target_has_device_addr = errors
37+
print *, "res1", res1, "res2", res2
38+
end function
39+
end module
40+
41+
42+
program p
43+
use m
44+
integer :: errors
45+
46+
errors = target_has_device_addr()
47+
print *, "errors=", errors
48+
end
49+
50+
!CHECK: res1 11 res2 11
51+
!CHECK: errors= 0
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
!REQUIRES: flang, amdgpu
2+
3+
!RUN: %libomptarget-compile-fortran-run-and-check-generic
4+
5+
subroutine f
6+
type :: t1
7+
integer :: x, y, z
8+
end type
9+
10+
integer, parameter :: n = 9
11+
type(t1) :: b(n)
12+
13+
integer :: i
14+
do i = 1, n
15+
b(i)%x = 0
16+
b(i)%y = 0
17+
b(i)%z = 0
18+
enddo
19+
20+
!$omp target data map(tofrom: b(1:3)) use_device_addr(b)
21+
!$omp target has_device_addr(b(2)%x)
22+
b(2)%x = 1
23+
!$omp end target
24+
!$omp end target data
25+
print *, "b1", b
26+
end
27+
28+
subroutine g
29+
type :: t1
30+
integer :: x(3), y(7), z(5)
31+
end type
32+
33+
integer, parameter :: n = 5
34+
type(t1) :: b(n)
35+
36+
integer :: i
37+
do i = 1, n
38+
b(i)%x = 0
39+
b(i)%y = 0
40+
b(i)%z = 0
41+
enddo
42+
43+
!$omp target data map(tofrom: b(1:3)) use_device_addr(b)
44+
!$omp target has_device_addr(b(2)%x)
45+
b(2)%x(3) = 1
46+
!$omp end target
47+
!$omp end target data
48+
print *, "b2", b
49+
end
50+
51+
call f()
52+
call g()
53+
end
54+
55+
!CHECK: b1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
56+
!CHECK: b2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
57+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
!REQUIRES: flang, amdgpu
2+
3+
!RUN: %libomptarget-compile-fortran-run-and-check-generic
4+
5+
function f(x) result(y)
6+
integer :: x(:)
7+
integer :: y, z
8+
x = 0
9+
y = 11
10+
!$omp target data map(tofrom: x) use_device_addr(x)
11+
!$omp target has_device_addr(x) map(tofrom: y)
12+
y = size(x)
13+
!$omp end target
14+
!$omp end target data
15+
end
16+
17+
program main
18+
interface
19+
function f(x) result(y)
20+
integer :: x(:)
21+
integer :: y
22+
end function
23+
end interface
24+
integer :: x(13)
25+
integer :: y
26+
y = f(x)
27+
print *, "y=", y
28+
end
29+
30+
!CHECK: y= 13

0 commit comments

Comments
 (0)