PDA

View Full Version : Can event callbacks be preempted by other event callbacks?



mindsporter
06-24-2011, 03:03 AM
Hi,

I could not find anything in the OpenCL 1.1 standard that talks about preemption of event callback functions by other event callback functions. Could someone enlighten me on this? What happens if multiple OpenCL events register the same callback function to trigger on event completion, and all of the events complete? Are there any guarantees that only a single instance of the callback will be in progress at any given time? If not, is there a way to get a shared callback to run like a critical section? Would spinlocks suffice or are there again no guarantees about progression of state through blocking lock requests?

Many thanks.

Albert.

david.garcia
07-06-2011, 05:08 AM
What happens if multiple OpenCL events register the same callback function to trigger on event completion, and all of the events complete? Are there any guarantees that only a single instance of the callback will be in progress at any given time? If not, is there a way to get a shared callback to run like a critical section?

What will happen is implementation-dependent. In some implementations, multiple different threads may execute the callback simultaneously. There is no guarantee that the callbacks will be executed serially. It's the application's responsibility to ensure that the callback is thread-safe.

If you require the callbacks to be serialized, I recommend using a critical section inside the callback function.

cathy29
07-14-2011, 09:15 PM
I've been looking for an answer for this specific problem & now at last I have the possible answer. You're an angel! Thanks!

david.garcia
07-15-2011, 05:14 AM
For future cases, I recommend reading the OpenCL 1.1 specification available from http://www.khronos.org/registry/cl/specs/opencl-1.1.pdf or at least the man pages available from http://www.khronos.org/registry/cl/sdk/ ... man/xhtml/ (http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/)

If you look at the description of function clSetEventCallback() either in the spec or the man pages it says that "This callback function may be called asynchronously by the OpenCL implementation. It is the application's responsibility to ensure that the callback function is thread-safe."