Call kernel from kernel

Is it possible to call some function(device kernel) from kernel which is already running?
For example:
__global kernel1
for (i=1;i<10;i++)
call kernel2 (i)

.
.
.
.
.
.
device kernel2 (i)
something doing…

So I call from host kernel 1 which iterates through ‘for’ and calls kernel2…

Can I do that?
Thx!

Of course you can do that. Keep in mind that all device function calls are inlined and there is no stack, thus no recursion is possible.

What you mean that I can’t use stack? Can’t you texture memory? Explain me wider please. :)

He’s referring to a function call stack:
http://en.wikipedia.org/wiki/Call_stack

On a normal CPU, this is how function calls are implemented. It makes binaries much smaller, and allows for recursion.

For the GPU, the compiler instead inlines every function call. This means that a copy of the function body is inserted in every location where you call the function. You don’t have to do anything special, but you should be aware of it. Inline functions cannot be called recursively.

Ok…Just no recursion! Thanks!