With CUDA, I’m trying to allocate arrays in a structure, because I want to use this structure in my kernels. So here is a short code (stored in a file called struct.cuf) that describe my problem. I’m compiling with the PGI 16.10 version, and I’m using the following options : -O3 -Mcuda=cc5x struct.cuf -o struct_out
module structure type mytype integer :: alpha,beta,gamma real,dimension(:),pointer :: a end type mytype type mytypeDevice integer :: alpha,beta,gamma real,dimension(:),pointer,device :: a end type mytypeDevice end module structure program main use cudafor use structure type(mytype) :: T(3) type(mytypeDevice) :: T_Device(3) ! For the host do i=1,3 allocate(T(i)%a(10)) end do T(1)%a=1; T(2)%a=2; T(3)%a=3 ! For the device do i=1,3 allocate(T_Device(i)%a(10)) end do do i=1,3 T_Device(i)%a=T(i)%a end do end program main
This code works, but I can’t use the structure T_Device in my kernels, because it needs the
device attribute in the kernel variables declaration. I get this error :
PGF90-S-0528-Argument number 1 to mykernel: device attribute mismatch
So is there an efficient way to use structures in the device ? I would like to use the a arrays declared in mytype in the device, to use them in my kernels.