So, it seems that the problem is this:
If the queue has unexecuted kernels that are waiting on events to complete, then clReleaseCommandQueue
In my opinion, this is a bug: releasing a command queue should remove all unexecuted kernels, even if
they are waiting on events.
As per the clReleaseCommandQueue:
"After the command_queue reference count becomes zero and all commands queued to command_queue have finished (e.g., kernel executions, memory object updates, etc.), the command-queue is deleted.
clReleaseCommandQueue performs an implicit flush to issue any previously queued OpenCL commands in command_queue."
Yes, that explains it. See here opencl - clReleaseCommandQueue hangs when queue contains unexecuted kernels that are waiting on completion events - Stac… for
further discussion. It turns out that calling
clSetUserEventStatus() with negative value causes waiting kernel to abort without executing.