PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Webinar

Calling functions within device code

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
crip_crop



Joined: 28 Jul 2010
Posts: 68

PostPosted: Thu Nov 18, 2010 5:35 am    Post subject: Calling functions within device code Reply with quote

I'm a little bit confused about how to call a subroutine from a subroutine already on the GPU. I'm porting quite a large bit of code using CUDA Fortran. As with most large codes, there are lots of subroutine calls within the subroutine I am porting.

In the PGI programming guide it seems to contradict itself... it says
Quote:
A subroutine or function with the device attribute must appear within a Fortran
module, and may only be called from device subprograms in the same module.


but also

Quote:
A kernel subroutine may not be contained in another subroutine or
function, and may not contain any other subprogram.


So, I'm a little confused as to what I need to do with my subroutines... do they need inlining or can I just stick them all in one module?

If anyone could clarify this for me it would be much appreciated.

Crip_crop
Back to top
View user's profile
mkcolg



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

PostPosted: Thu Nov 18, 2010 3:11 pm    Post subject: Reply with quote

Hi Crip_crop,

The second quote means that a kernel can not be contained within another subroutine, but it can be contained within a module. The first quote means that when device code calls another device routine, the two routines must be be in the same module. Hence, your module would look something like this:

Code:
module mymod

contains

attributes(device) function func1(a,b)

! some code

end function func1

attributes(global) subroutine sub1()

! some code
i = func1(x,y)
! more code
end subroutine sub1

end module mymod



Hope this helps,
Mat
Back to top
View user's profile
crip_crop



Joined: 28 Jul 2010
Posts: 68

PostPosted: Fri Nov 19, 2010 7:11 am    Post subject: Reply with quote

That's really useful, thanks. Wowzer this is going to be one meaty module.
Back to top
View user's profile
crip_crop



Joined: 28 Jul 2010
Posts: 68

PostPosted: Tue Sep 27, 2011 9:16 am    Post subject: Reply with quote

Does anyone happen to know the reason why all device subroutines are required to be in the same module?

I'm doing a presentation about my experiences using CUDA Fortran and I'd like to give an explanation for this.

Cheers,
Crip_crop
Back to top
View user's profile
mkcolg



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

PostPosted: Tue Sep 27, 2011 1:11 pm    Post subject: Reply with quote

Hi Crip_crop,

Quote:
Does anyone happen to know the reason why all device subroutines are required to be in the same module?
To ensure they can be inlined.

In CUDA C and Fortran, calling subroutines from device code is not supported. While you can organize your code into separate routines, at compile time these routines must be inlined by the compiler.

Hope this helps,
Mat
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling 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