exit from program directly from kernel

Hi all,
I want to exit from my program directly from kernel.
As we use exit in C.
I want to exit from kernel only!

Suppose,
global void kernel()
{…
if(…)
//exit from the whole program
//exit() is not working inside kernel
}

You can’t terminate your host process from device code.

If you want to halt a kernel execution, you can use:

assert(0);

however this corrupts the CUDA context.

As txbob says, you cannot terminate the host process from within the kernel. To exit from a kernel you could simply

return;

in every thread. If all threads need to do that in response to a special event detected by just one threads or a few threads, you may need to atomically increment a flag that all threads check periodically.

Thanks @txbob.
Thank you @njuffa(I already have that idea!).

Thanks @txbob.
Thank you @njuffa(I already have that idea!).