To register a user callback function for a specific command execution status, call the function
void (CL_CALLBACK* pfn_notify)(cl_event event, cl_int event_command_status, void *user_data),
|clSetEventCallback is missing before version 1.1.
event is a valid event object.
command_exec_callback_type specifies the command execution status for which the callback is registered. The command execution callback values for which a callback can be registered are:
CL_COMPLETE. There is no guarantee that the callback functions registered for various execution status values for an event will be called in the exact order that the execution status of a command changes. Furthermore, it should be noted that receiving a call back for an event with a status other than
CL_COMPLETE, in no way implies that the memory model or execution model as defined by the OpenCL specification has changed. For example, it is not valid to assume that a corresponding memory transfer has completed unless the event is in a state
pfn_event_notify is the event callback function that can be registered by the application. 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. The parameters to this callback function are:
event is the event object for which the callback function is invoked.
event_command_status is equal to the command_exec_callback_type used while registering the callback. Refer to the Event Object Queries table for the command execution status values. If the callback is called as the result of the command associated with event being abnormally terminated, an appropriate error code for the error that caused the termination will be passed to event_command_status instead.
user_data is a pointer to user supplied data.
user_data will be passed as the user_data argument when pfn_notify is called. user_data can be
The registered callback function will be called when the execution status of command associated with event changes to an execution status equal to or past the status specified by command_exec_status.
Each call to clSetEventCallback registers the specified user callback function on a callback stack associated with event. The order in which the registered user callback functions are called is undefined.
All callbacks registered for an event object must be called before the event object is destroyed. Callbacks should return promptly.
Behavior is undefined when calling expensive system routines, OpenCL APIs to create contexts or command-queues, or blocking OpenCL APIs in an event callback. Rather than calling a blocking OpenCL API in an event callback, applications may call a non-blocking OpenCL API, then register a completion callback for the non-blocking OpenCL API with the remainder of the work.
Because commands in a command-queue are not required to begin execution until the command-queue is flushed, callbacks that enqueue commands on a command-queue should either call clFlush on the queue before returning, or arrange for the command-queue to be flushed later.
CL_SUCCESS if the function is executed
Otherwise, it returns one of the following errors:
CL_INVALID_if event is not a valid event object.
CL_INVALID_if pfn_event_notify is
NULLor if command_exec_callback_type is not
CL_OUT_if there is a failure to allocate resources required by the OpenCL implementation on the device.
CL_OUT_if there is a failure to allocate resources required by the OpenCL implementation on the host.
OF_ HOST_ MEMORY
For more information, see the OpenCL Specification
This page is extracted from the OpenCL Specification. Fixes and changes should be made to the Specification, not directly.