It will be very helpful to be able to be notified asynchronously when specific OpenCL events have completed.
Note that clWaitForEvents() has several deficiencies:
1) One cannot wait for any of several events to complete - only until they all complete.
2) According to appendix A.2 ("Multiple Host Threads") of the OpenCL bible, calls to clWaitForEvents() are probably not thread-safe. This means that we cannot even wait for different events in different threads, and in any case, even if other threads were ready to enqueue new OpenCL operation(s), they must still wait for the thread that is stuck in clWaitForEvents() - there is even no way to abort that waiting-for-events thread. Even interrupting/killing/longjmp that thread is probably not an option as it is likely to leave the OpenCL library in a locked or weird state.
A simple and clean solution is to be able to request a callback when an event completes. For example:
That would be ideal - short of that, the least required to support complex and multi-threaded parallel applications would be to:Code :
cl_int clNotifyEventCompletion(const cl_event event, void (*ev_notify)(cl_event, void *user_data), void *user_data);
1. Require clWaitForEvents() to be thread-safe (without blocking other threads from using OpenCL functions simultaneously);
2. Introduce an interruptible variant of clWaitForEvents(), that returns when a signal was received, even if the event(s) are not yet complete;
3. Introduce an OpenCL call that waits for ANY of several events to complete;
4. Create a new type of event: an "abort-event", which can be used in clWaitForEvents() and its variants, but is activated by the host-program to cause clWaitForEvents() to be aborted.