Interrupt How to interrupt kernel execution

I am looking for a way to interrupt parallel processing on the GPU either from CPU or in GPU kernel by a thread. if someone can help me to find how can i finish kernel from a thread if the thread decide to finish the kernel execution. so please help me your opinions on how to terminate the kernel from a thread or another ways to terminate it?

Other than killing the process, I don’t think that there is an asynchronous method of killing a running kernel. The best you can do is have the kernel periodically check a flag and abort if it is not set.

Thanks for your reply, you mean the following pseudo code:

[codebox]bool flag=false;//in the global memory

//in each thread let say in each iteration of each thread

if(flag)

return

//when a thread wants to terminate the kernel

flag=true;

[/codebox]

in this case i think flag is a bottleneck and may resulted to race conditions and breakdown the performance and also for changing the flag to true it may resulted to some inconsistency?

Please help me by your comments and thanks in advance! External Media

Yes, I am not aware of another method to abort a kernel.

Well, all methods for asynchronous abort will result in inconsistency and race conditions by virtue of being asynchronous. Something equivalent to pthread_cancel would cause the same problems.

In terms of performance using a flag, you have to balance performance overheads of checking the flag with latency between when the flag is received and when the next thread aborts.

In general I try to avoid using an approach like this. Is there any particular reason why you need to abort kernels like this?