Oddity in declaring constant memory in host subprograms

I seem to have found an oddity with constant memory declaration that is…puzzling me. Can someone tell me what I’m doing wrong?

To wit, if I try and compile this:

program test

use cudafor

implicit none

real, constant :: const(40)

write (*,*) 'Test'

end program test

I get:

(1224) > pgfortran -Mcuda test.F90
PGF90-S-0134-Illegal attribute constant not allowed in host subprograms (test.F90: 7)
  0 inform,   0 warnings,   1 severes, 0 fatal for test
(1225) >

But if I do this:

program test

use cudafor

implicit none

real :: const(40)
attributes(constant) :: const

write (*,*) 'Test'

end program test

it compiles just fine:

(1233) > pgfortran -Mcuda test.att.F90 
(1234) >

So, I’m wondering is the first correct in saying that it’s illegal (though the CUDA Fortran Guide seems to say it’s okay), or is the second one wrong in allowing compilation to occur? I don’t know which behavior to trust…if either.

FYI: I’m using PGI 12.5, but it seems to occur just the same with V 11.10.

Thanks,
Matt

Looks like you’ve found a problem mainly with our docs. Looking through our bug history, it appears we tightened the usage of the constant qualifier in version 10.8. One note says:

Compiler should produce an error for CONSTANT data in a host subroutine or function. There is no way for a kernel to use this data, so it’s useless. It can’t even be passed as an argument.

We are limited to the CUDA use of constant data, which I think in CUDA C is just file global, then accessible by symbol name if needed.

The recommended way to use constant data in CUDA Fortran is to put it into a module that can be “used” in both the host and device, or actually contains the global and device subprograms.

I’ll enter a bug into our system to update the docs and to also generate a message for the attributes(constant) statement in host code.

Sorry for burrowing this out, but I’d be super glad for a clarification here: Is importing such memory declared as constant allowed (from other modules)? If yes, supercool, if not - do you have a feature wishlist somewhere? ;-)

Hi Michel,

Yes, you can access device variables, constant or global, declared in external modules.

  • Mat