CUDA Fortran and PUBLIC/PRIVATE

An odd question, but one I thought I’d ask about. Namely, how compatible is CUDA Fortran with PUBLIC and PRIVATE (and, I suppose, PROTECTED)?

I ask because I was recently trying to clean up some CUDA Fortran modules with some data hiding (as we all should do using modules) and ran into issues.

As a test example to show these, I hacked some matmul code that looked like:

module mmul_mod

use cudafor
implicit none

real, allocatable, dimension(:,:), device :: A_dev, B_dev, C_dev
 
contains

   attributes(global) subroutine mmul_kernel(N,M,L)

This worked just fine, obviously. I then tried:

module mmul_mod

use cudafor
implicit none

PRIVATE
PUBLIC :: A_dev, B_dev, C_dev

real, allocatable, dimension(:,:), device :: A_dev, B_dev, C_dev
 
contains

   attributes(global) subroutine mmul_kernel(N,M,L)

Also worked. But, when I try:

module mmul_mod

use cudafor
implicit none

PRIVATE

real, allocatable, dimension(:,:), device, PUBLIC :: A_dev, B_dev, C_dev
 
contains

   attributes(global) subroutine mmul_kernel(N,M,L)

the compiler bombs out with:

pgfortran -Minfo -Mcuda -c mmul_mod.F90
PGF90-S-0134-Illegal attribute - conflict with access (mmul_mod.F90: 8)
  0 inform,   0 warnings,   1 severes, 0 fatal for mmul_mod
make: *** [mmul_mod.o] Error 2

As the real code I’m working often has 20-30 device variables (or more) and many constants, I’m not too keen on adding 20-30 extra lines PUBLIC’ing the device variables in addition to all the REAL, ALLOCATABLE, DEVICE declarations. Is there a way I can PUBLIC these on the same line as they are declared?

Also, I guess I should ask: are attributes(global) subroutines and functions inherently PUBLIC? Notice above I never declared mmul_kernel as PUBLIC, and yet it worked just fine. (And, the corollary: are attributes(device) subroutines and functions inherently PRIVATE?)

Thanks,
Matt

PS: I did try the above module with just PRIVATE and no PUBLIC and it bombs out in the way you’d expect. A_dev et al aren’t declared in the USEing routine, etc.

Quite frankly, we haven’t paid much attention to attributes like public and private in combination with device to this point. I know originally, we added some limiting checks to keep things simple, and that’s likely what you are running into. I’ll add a feature request to allow public and private in combination with both device and constant (I think those two make sense) for PGI 12.0.