Fix gcc.c-torture/execute/ieee/cdivchkf.c on hpux
[official-gcc.git] / libgomp / testsuite / libgomp.oacc-fortran / host_data-2.f90
blobfe1ae8ab50a557cc23b7040a4e06b569122deb87
1 ! Test host_data interoperability with CUDA blas. This test was
2 ! derived from libgomp.oacc-c-c++-common/host_data-1.c.
4 ! { dg-do run { target openacc_nvidia_accel_selected } }
5 ! { dg-additional-options "-lcublas -Wall -Wextra" }
6 ! { dg-require-effective-target openacc_cublas }
8 program test
9 implicit none
11 integer, parameter :: N = 10
12 integer :: i
13 real*4 :: x_ref(N), y_ref(N), x(N), y(N), a
15 interface
16 subroutine cublassaxpy(N, alpha, x, incx, y, incy) bind(c, name="cublasSaxpy")
17 use iso_c_binding
18 integer(kind=c_int), value :: N
19 real(kind=c_float), value :: alpha
20 type(*), dimension(*) :: x
21 integer(kind=c_int), value :: incx
22 type(*), dimension(*) :: y
23 integer(kind=c_int), value :: incy
24 end subroutine cublassaxpy
25 end interface
27 a = 2.0
29 do i = 1, N
30 x(i) = 4.0 * i
31 y(i) = 3.0
32 x_ref(i) = x(i)
33 y_ref(i) = y(i)
34 end do
36 call saxpy (N, a, x_ref, y_ref)
38 !$acc data copyin (x) copy (y)
39 !$acc host_data use_device (x, y)
40 call cublassaxpy(N, a, x, 1, y, 1)
41 !$acc end host_data
42 !$acc end data
44 call validate_results (N, y, y_ref)
46 !$acc data create (x) copyout (y)
47 !$acc parallel loop
48 do i = 1, N
49 y(i) = 3.0
50 end do
51 !$acc end parallel loop
53 !$acc host_data use_device (x, y)
54 call cublassaxpy(N, a, x, 1, y, 1)
55 !$acc end host_data
56 !$acc end data
58 call validate_results (N, y, y_ref)
60 y(:) = 3.0
62 !$acc data copyin (x) copyin (a) copy (y)
63 !$acc parallel present (x) pcopy (y) present (a)
64 call saxpy (N, a, x, y)
65 !$acc end parallel
66 !$acc end data
68 call validate_results (N, y, y_ref)
70 y(:) = 3.0
72 !$acc enter data copyin (x, a, y)
73 !$acc parallel present (x) pcopy (y) present (a)
74 call saxpy (N, a, x, y)
75 !$acc end parallel
76 !$acc exit data delete (x, a) copyout (y)
78 call validate_results (N, y, y_ref)
79 end program test
81 subroutine saxpy (nn, aa, xx, yy)
82 integer :: nn
83 real*4 :: aa, xx(nn), yy(nn)
84 integer i
85 !$acc routine
87 do i = 1, nn
88 yy(i) = yy(i) + aa * xx(i)
89 end do
90 end subroutine saxpy
92 subroutine validate_results (n, a, b)
93 integer :: n
94 real*4 :: a(n), b(n)
96 do i = 1, N
97 if (abs(a(i) - b(i)) > 0.0001) stop 1
98 end do
99 end subroutine validate_results