declaring argument's variables as the size of local arrays

Hello, I’m really new using Fortran and CUDA Fortran, I have a question about using variables from arguments as the size for declare local arrays, look please this example:


ATTRIBUTES(GLOBLA) SUBROUTINE gpu_kernel(devA, devB, devC, M, N)
!Use variable arguments to define the argument’s array sizes

INTEGER, DEVICE :: devA(M)
INTEGER, VALUE :: M, N
REAL, DEVICE :: devB(N)
DOUBLE PRECISION :: devC(M,N)

END SUBROUTINE gpu_kernel


I got several errors when I try to use the arguments M and N as the size for local variables inside the Kernel, so I can’t do this for example:

INTEGER, DIMENSION(M) :: local_A, local_B
! or
INTEGER, PARAMETER :: size = M
INTEGER :: local_A(size)
! or
INTEGER :: size=M
INTEGER, DIMENSION(size) :: local_A,…

Chang VALUE attribute for DEVICE results in the same errors…

So, can you tell me please how I do to use variables passed as arguments to define the size of local arrays inside a kernel?

Thanks

Hi Maomerino,

So, can you tell me please how I do to use variables passed as arguments to define the size of local arrays inside a kernel?

Unfortunately, there is no method to dynamically allocate memory on the device so allocatable and automatic arrays are not allowed. Only fixed size local arrays are allowed within device kernels.

  • Mat