Function calls inlining : clarification
In PTX I can have function calls. But the call graph needs to be finite and computable at compile time : is this correct? And the function calls are inlined when converting from PTX to CUBIN instructions?
In PTX I can have function calls. But the call graph needs to be finite and computable at compile time : is this correct? And the function calls are inlined when converting from PTX to CUBIN instructions?

#1
Posted 04/16/2008 02:36 AM   
The function calls are inlined in the compilation of C to PTX by nvcc, even before the PTX assembly stage.
The function calls are inlined in the compilation of C to PTX by nvcc, even before the PTX assembly stage.

#2
Posted 04/16/2008 02:38 AM   
[quote name='seibert' date='Apr 15 2008, 07:38 PM']The function calls are inlined in the compilation of C to PTX by nvcc, even before the PTX assembly stage.
[right][snapback]362937[/snapback][/right]
[/quote]

What happens if I specify the noinline option or if one writes PTX by hand? PTX does have call instructions as well .func labels?
[quote name='seibert' date='Apr 15 2008, 07:38 PM']The function calls are inlined in the compilation of C to PTX by nvcc, even before the PTX assembly stage.

[snapback]362937[/snapback]






What happens if I specify the noinline option or if one writes PTX by hand? PTX does have call instructions as well .func labels?

#3
Posted 04/16/2008 02:46 AM   
Yup, see the PTX ISA guide. PDF pg. 84 for .func and PDF pg. 70 for call.
Yup, see the PTX ISA guide. PDF pg. 84 for .func and PDF pg. 70 for call.

#4
Posted 04/16/2008 05:02 AM   
[quote name='seibert' date='Apr 15 2008, 10:02 PM']Yup, see the PTX ISA guide.  PDF pg. 84 for .func and PDF pg. 70 for call.
[right][snapback]362985[/snapback][/right]
[/quote]

Thanks for your response. Well I can see that I am not being very clear here.

So let me rephrase the question.

I know that PTX has call instructions as well as .func labels. I also know in PTX I can do "call fname" where fname has to be a label and cannot be recursive. My question is this : Does the call graph in PTX have to be finite? Is there for example a maximum "stack depth" or can I have an arbitrary call graph? Or is there some other restriction? What about cycles in the call graph for example? Ruling out recursion only rules out an immediate cycle.

I also know that cubin is not disclosed but I am curious about what happens when PTX is converted into cubin. Do function calls get inlined?
[quote name='seibert' date='Apr 15 2008, 10:02 PM']Yup, see the PTX ISA guide.  PDF pg. 84 for .func and PDF pg. 70 for call.

[snapback]362985[/snapback]






Thanks for your response. Well I can see that I am not being very clear here.



So let me rephrase the question.



I know that PTX has call instructions as well as .func labels. I also know in PTX I can do "call fname" where fname has to be a label and cannot be recursive. My question is this : Does the call graph in PTX have to be finite? Is there for example a maximum "stack depth" or can I have an arbitrary call graph? Or is there some other restriction? What about cycles in the call graph for example? Ruling out recursion only rules out an immediate cycle.



I also know that cubin is not disclosed but I am curious about what happens when PTX is converted into cubin. Do function calls get inlined?

#5
Posted 04/16/2008 05:45 AM   
[quote name='kaoken' date='Apr 16 2008, 12:45 AM']I know that PTX has call instructions as well as .func labels. I also know in PTX I can do "call fname" where fname has to be a label and cannot be recursive. My question is this : Does the call graph in PTX have to be finite?  Is there for example a maximum "stack depth" or can I have an arbitrary call graph? Or is there some other restriction? What about cycles in the call graph for example? Ruling out recursion only rules out an immediate cycle.

I also know that cubin is not disclosed but I am curious about what happens when PTX is converted into cubin. Do function calls get inlined?
[/quote]

The answer to the first part is yes, there is a maximum call depth, as the call instruction says:
"In the current ptx release, parameters are passed through statically allocated ptx registers; i.e., there is no support for recursive calls."

So the call depth is limited by register availability. As for the second part, I'm not sure if ptxas will perform additional transformations and inline functions that were not already inlined by nvcc. Maybe someone else knows this...
[quote name='kaoken' date='Apr 16 2008, 12:45 AM']I know that PTX has call instructions as well as .func labels. I also know in PTX I can do "call fname" where fname has to be a label and cannot be recursive. My question is this : Does the call graph in PTX have to be finite?  Is there for example a maximum "stack depth" or can I have an arbitrary call graph? Or is there some other restriction? What about cycles in the call graph for example? Ruling out recursion only rules out an immediate cycle.



I also know that cubin is not disclosed but I am curious about what happens when PTX is converted into cubin. Do function calls get inlined?





The answer to the first part is yes, there is a maximum call depth, as the call instruction says:

"In the current ptx release, parameters are passed through statically allocated ptx registers; i.e., there is no support for recursive calls."



So the call depth is limited by register availability. As for the second part, I'm not sure if ptxas will perform additional transformations and inline functions that were not already inlined by nvcc. Maybe someone else knows this...

#6
Posted 04/16/2008 11:17 AM   
There are native call and return instructions, but ptxas and nvcc prefer inlining. Anyhow, you have to write code as if everything is inlined in all cases. There is no way to do recursion.
There are native call and return instructions, but ptxas and nvcc prefer inlining. Anyhow, you have to write code as if everything is inlined in all cases. There is no way to do recursion.

#7
Posted 04/21/2008 08:14 AM   
Scroll To Top