Asynchronous Events

It will be very helpful to be able to be notified asynchronously when specific OpenCL events have completed.

Note that [b]clWaitForEvents/b 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 [i]clWaitForEvents/i 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 [i]clWaitForEvents/i - 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:

cl_int clNotifyEventCompletion(const cl_event event, void (*ev_notify)(cl_event, void *user_data), void *user_data);

That would be ideal - short of that, the least required to support complex and multi-threaded parallel applications would be to:

  1. Require [i]clWaitForEvents/i to be thread-safe (without blocking other threads from using OpenCL functions simultaneously);
  2. Introduce an interruptible variant of [i]clWaitForEvents/i, 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 [i]clWaitForEvents/i and its variants, but is activated by the host-program to cause [i]clWaitForEvents/i to be aborted.

Thank you.