OpenACC與CUDA Fortran交互(2)

在帖子《OpenACC與CUDA Fortran交互(1)》中,舉了一個在openacc中嵌套cuda fortran的例子。現在舉一個cuda fortran中嵌套openacc的例子。上代碼:

  1. ! cuf_main.cuf
  2. program main
  3.   integer, parameter :: N = 2**20
  4.   ! Allocate X and Y only on the device
  5.   real, device, dimension(N) :: X, Y
  6.   integer :: i
  7.   real :: tmp

  8.   ! CUDA Fortran will automatically convert these to run on the device
  9.   X(:) = 1.0
  10.   Y(:) = 0.0

  11.   !$acc kernels deviceptr(x,y)
  12.   y(:) = y(:) + 2.0*x(:)
  13.   !$acc end kernels

  14.   ! Copy the first element back from Y for correctness checking
  15.   tmp = y(1)
  16.   print *, tmp
  17. end program

編譯:
  1. pgf90  -o cuda_fortran_openacc cuf_main.cuf -acc -Mcuda=cc3.5 -Minfo
發佈了40 篇原創文章 · 獲贊 7 · 訪問量 9萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章