PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

Assumed-size device arrays

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Accelerator Programming
View previous topic :: View next topic  
Author Message
TheMatt



Joined: 06 Jul 2009
Posts: 304
Location: Greenbelt, MD

PostPosted: Thu Jul 26, 2012 5:45 am    Post subject: Assumed-size device arrays Reply with quote

In some examples for CUDA Fortran, I sometimes see device arrays declared assumed-size, e.g.:
Code:
! 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
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 5815
Location: The Portland Group Inc.

PostPosted: Thu Jul 26, 2012 10:35 am    Post subject: Reply with quote

Hi Matt,

The only difference between "dimension(*)" and "dimension(n)" is that the compiler knows the size of the arrays so can perform additional things like array syntax (i.e. x=y) or bounds checking. Both types are passed in as a pointer without a F90 descriptor.

Assumed shape arrays, "dimension(:)", do carry around a F90 descriptor causing some overhead.

Quote:
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?
I believe so.

- Mat
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Accelerator Programming All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group