Static variable in kernel program

Hi,

Does anyone know how to set a static variable in kernel code?

Thank you,

Hi, everyone.

I just set a static variable in the kernel program (using keywork “static”) and make a loop to execute the kernel program multiple times. The static variable was increamented correctly when the kernel program is called.

Thank you,

You’re doing something the standard prohibits. Section 6.5 says:

In other words, program scope variables cannot be mutable.

Section 6.8 says:

This is not supposed to work. The fact that it does may be a carry-over from CUDA.

Do not expect this to work in different or newer implementations.

To my knowledge there’s no approved way to have static-like behavior. And I’m thankful for that, automatic dependency analysis is much easier without it.

Thank you for your reply.

In that case, if I have a loop and wish to run the kernel program multiple times, how can I pass to the kernel program the iteration variable?

Thank you,

Just by argument. It makes for a much more maintainable code by the way.

I got it.

Thank you, :)