Initial value for constant variable in cuda fortran

Please test following code by pgfortran V11.4:

program test


    use kernel
    IMPLICIT NONE

    double precision, device :: data1(10)
    double precision :: data2(10)

    call functest<<<1,10>>>(data1)

    data2 = data1

    write(0,*) data2

end program

MODULE kernel

CONTAINS
attributes(global) SUBROUTINE functest(output)

  IMPLICIT NONE
  double precision :: output(:)
  double precision,constant :: s = 2.d0

  output(threadidx%x) = s


END SUBROUTINE functest

END MODULE kernel

Compiled by “pgfortran -Mcuda test.F90”

Results:
0.000000000000000 0.000000000000000 0.000000000000000
0.000000000000000 0.000000000000000 0.000000000000000
0.000000000000000 0.000000000000000 0.000000000000000
0.000000000000000

Analysis:

All initial values of constant variable are set to 0 in .gpu file by the compiler.

Hi tlstar,

It looks this is a bug since single precision and integer constants get properly data initialized, just not double precision. I’ve reported this as TPR#17806.

Thanks,
Mat

And we were late to update you.

thanks,
dave