how to limit the time of a kernel

How to limit the time that a kernel can have? For example, I want a kernel to run no more than 1 second. Whenever 1 second is up, the kernel should exit. How to write the kernel to enforce the stop?

Thank you,

You could use the %clock register to count the number of core cycles for which your threads have been running. Search the forum to see how it could be used or for inline ptx code.

EDIT: my phrasing is a bit wrong… The %clock register automatically increments itself every core clock. Doesn’t matter whether your thread is running or is using the %clock or not.

Be aware that [font=“Courier New”]%clock[/font] and [font=“Courier New”]%clock64[/font] only seem to be guaranteed to be consistent within a block. You’ll have to do some experimentation to see whether you can use it for global timing.

While we are talking about PTX inline assembly, [font=“Courier New”]trap[/font] seems to be a useful instruction once you’ve detected the kernel is taking too long. That way you can abort even if some threads fail to notice the abort attempt.