host_data-3.f 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. ! Fixed-mode host_data interaction with CUDA BLAS.
  2. ! { dg-do run { target openacc_nvidia_accel_selected } }
  3. ! { dg-additional-options "-lcublas -Wall -Wextra" }
  4. ! { dg-require-effective-target openacc_cublas }
  5. include "cublas-fixed.h"
  6. integer, parameter :: N = 10
  7. integer :: i
  8. real*4 :: x_ref(N), y_ref(N), x(N), y(N), a
  9. a = 2.0
  10. do i = 1, N
  11. x(i) = 4.0 * i
  12. y(i) = 3.0
  13. x_ref(i) = x(i)
  14. y_ref(i) = y(i)
  15. end do
  16. call saxpy (N, a, x_ref, y_ref)
  17. !$acc data copyin (x) copy (y)
  18. !$acc host_data use_device (x, y)
  19. call cublassaxpy(N, a, x, 1, y, 1)
  20. !$acc end host_data
  21. !$acc end data
  22. call validate_results (N, y, y_ref)
  23. !$acc data create (x) copyout (y)
  24. !$acc parallel loop
  25. do i = 1, N
  26. y(i) = 3.0
  27. end do
  28. !$acc end parallel loop
  29. !$acc host_data use_device (x, y)
  30. call cublassaxpy(N, a, x, 1, y, 1)
  31. !$acc end host_data
  32. !$acc end data
  33. call validate_results (N, y, y_ref)
  34. y(:) = 3.0
  35. !$acc data copyin (x) copyin (a) copy (y)
  36. !$acc parallel present (x) pcopy (y) present (a)
  37. call saxpy (N, a, x, y)
  38. !$acc end parallel
  39. !$acc end data
  40. call validate_results (N, y, y_ref)
  41. y(:) = 3.0
  42. !$acc enter data copyin (x, a, y)
  43. !$acc parallel present (x) pcopy (y) present (a)
  44. call saxpy (N, a, x, y)
  45. !$acc end parallel
  46. !$acc exit data delete (x, a) copyout (y)
  47. call validate_results (N, y, y_ref)
  48. end
  49. subroutine saxpy (nn, aa, xx, yy)
  50. integer :: nn
  51. real*4 :: aa, xx(nn), yy(nn)
  52. integer i
  53. !$acc routine
  54. do i = 1, nn
  55. yy(i) = yy(i) + aa * xx(i)
  56. end do
  57. end subroutine saxpy
  58. subroutine validate_results (n, a, b)
  59. integer :: n
  60. real*4 :: a(n), b(n)
  61. do i = 1, N
  62. if (abs(a(i) - b(i)) > 0.0001) stop 1
  63. end do
  64. end subroutine validate_results