CUDA Fortran:How to define variables in a kernel subroutine.

Please see the following codes first:

module simpleOps_m
contains
attributes(global) subroutine inc(a, b)
implicit none
integer :: a(:)
integer, value :: b
integer :: i
integer :: c(256)

i = threadIdx%x
c(i)=a(i)
a(i) = a(i)+b + c(i)
end subroutine inc
end module simpleOps_m

In the line “integer :: c(256)”, should I use “integer :: c(256)” or "integer, device :: c(256)“?

Hi Happyfish,

When a variable is declared in a device subroutine, the “device” attribute is implied. Though, you can add it if you want, so either works.

  • Mat