In some examples for CUDA Fortran, I sometimes see device arrays declared assumed-size, e.g.:
! Kernel definition
attributes(global) subroutine ksaxpy( n, a, x, y )
real, dimension(*) :: x,y
real, value :: a
integer, value :: n, i
i = (blockidx%x-1) * blockdim%x + threadidx%x
if( i <= n ) y(i) = a * x(i) + y(i)
end subroutine
I’ve seen this in a few other places as well, and I guess I’ve never thought of doing this and wondered why it was done. Is it just that since x and y are (assumedly) device arrays allocated in the host code, that all Fortran needs to know is it’s 1-D? From looking at the code, I’d have done ‘real, dimension(n) :: x, y’ since n is passed by value. (Though, I can see that logically, the compiler doesn’t need n there to do its job. And, well, I was taught assumed-size is something you should never use…until it’s the only way to do something. Which seems to happen more than you think.)
And, if x were 2D, say x(n,n), would you need to do ‘real, dimension(n,*)’ like the good old days of Fortran 77?
Matt