32 #include "_ccl_abstract_wrapper.h"
98 NULL, (ccl_wrapper_release_cl_object) clReleaseEvent, NULL);
117 g_return_if_fail(evt != NULL);
140 g_return_val_if_fail(evt != NULL, NULL);
164 g_return_val_if_fail(evt != NULL, NULL);
167 const char* final_name;
170 if (evt->name != NULL) {
173 final_name = evt->name;
180 CCLErr* err_internal = NULL;
185 if (err_internal != NULL) {
186 g_warning(
"Unable to determine final event name due to" \
187 "the following error: %s", err_internal->message);
188 g_error_free(err_internal);
193 case CL_COMMAND_NDRANGE_KERNEL:
194 final_name =
"NDRANGE_KERNEL";
196 case CL_COMMAND_NATIVE_KERNEL:
197 final_name =
"NATIVE_KERNEL";
199 case CL_COMMAND_READ_BUFFER:
200 final_name =
"READ_BUFFER";
202 case CL_COMMAND_WRITE_BUFFER:
203 final_name =
"WRITE_BUFFER";
205 case CL_COMMAND_COPY_BUFFER:
206 final_name =
"COPY_BUFFER";
208 case CL_COMMAND_READ_IMAGE:
209 final_name =
"READ_IMAGE";
211 case CL_COMMAND_WRITE_IMAGE:
212 final_name =
"WRITE_IMAGE";
214 case CL_COMMAND_COPY_IMAGE:
215 final_name =
"COPY_IMAGE";
217 case CL_COMMAND_COPY_BUFFER_TO_IMAGE:
218 final_name =
"COPY_BUFFER_TO_IMAGE";
220 case CL_COMMAND_COPY_IMAGE_TO_BUFFER:
221 final_name =
"COPY_IMAGE_TO_BUFFER";
223 case CL_COMMAND_MAP_BUFFER:
224 final_name =
"MAP_BUFFER";
226 case CL_COMMAND_MAP_IMAGE:
227 final_name =
"MAP_IMAGE";
229 case CL_COMMAND_UNMAP_MEM_OBJECT:
230 final_name =
"UNMAP_MEM_OBJECT";
232 case CL_COMMAND_MARKER:
233 final_name =
"MARKER";
235 case CL_COMMAND_ACQUIRE_GL_OBJECTS:
236 final_name =
"ACQUIRE_GL_OBJECTS";
238 case CL_COMMAND_RELEASE_GL_OBJECTS:
239 final_name =
"RELEASE_GL_OBJECTS";
241 case CL_COMMAND_READ_BUFFER_RECT:
242 final_name =
"READ_BUFFER_RECT";
244 case CL_COMMAND_WRITE_BUFFER_RECT:
245 final_name =
"WRITE_BUFFER_RECT";
247 case CL_COMMAND_COPY_BUFFER_RECT:
248 final_name =
"COPY_BUFFER_RECT";
250 case CL_COMMAND_USER:
255 case CL_COMMAND_BARRIER:
256 final_name =
"BARRIER";
258 case CL_COMMAND_MIGRATE_MEM_OBJECTS:
259 final_name =
"MIGRATE_MEM_OBJECTS";
261 case CL_COMMAND_FILL_BUFFER:
262 final_name =
"FILL_BUFFER";
264 case CL_COMMAND_FILL_IMAGE:
265 final_name =
"FILL_IMAGE";
267 case CL_COMMAND_SVM_FREE:
268 final_name =
"SVM_FREE";
270 case CL_COMMAND_SVM_MEMCPY:
271 final_name =
"SVM_MEMCPY";
273 case CL_COMMAND_SVM_MEMFILL:
274 final_name =
"SVM_MEMFILL";
276 case CL_COMMAND_SVM_MAP:
277 final_name =
"SVM_MAP";
279 case CL_COMMAND_SVM_UNMAP:
280 final_name =
"SVM_UNMAP";
282 case CL_COMMAND_GL_FENCE_SYNC_OBJECT_KHR:
283 final_name =
"GL_FENCE_SYNC_OBJECT_KHR";
285 case CL_COMMAND_ACQUIRE_D3D10_OBJECTS_KHR:
286 final_name =
"ACQUIRE_D3D10_OBJECTS_KHR";
288 case CL_COMMAND_RELEASE_D3D10_OBJECTS_KHR:
289 final_name =
"RELEASE_D3D10_OBJECTS_KHR";
291 case CL_COMMAND_ACQUIRE_DX9_MEDIA_SURFACES_KHR:
292 final_name =
"ACQUIRE_DX9_MEDIA_SURFACES_KHR";
294 case CL_COMMAND_RELEASE_DX9_MEDIA_SURFACES_KHR:
295 final_name =
"RELEASE_DX9_MEDIA_SURFACES_KHR";
297 case CL_COMMAND_ACQUIRE_D3D11_OBJECTS_KHR:
298 final_name =
"ACQUIRE_D3D11_OBJECTS_KHR";
300 case CL_COMMAND_RELEASE_D3D11_OBJECTS_KHR:
301 final_name =
"RELEASE_D3D11_OBJECTS_KHR";
303 case CL_COMMAND_ACQUIRE_EGL_OBJECTS_KHR:
304 final_name =
"ACQUIRE_EGL_OBJECTS_KHR";
306 case CL_COMMAND_RELEASE_EGL_OBJECTS_KHR:
307 final_name =
"RELEASE_EGL_OBJECTS_KHR";
309 case CL_COMMAND_EGL_FENCE_SYNC_OBJECT_KHR:
310 final_name =
"EGL_FENCE_SYNC_OBJECT_KHR";
313 final_name =
"UNKNOWN";
314 g_warning(
"Unknown event command type: 0x%x", ct);
340 g_return_val_if_fail(err == NULL || *err == NULL, 0);
343 g_return_val_if_fail(evt != NULL, 0);
357 ct = *((cl_command_type*) info->
value);
387 g_return_val_if_fail(evt != NULL, 0);
389 g_return_val_if_fail(err == NULL || *err == NULL, 0);
394 #ifdef CL_VERSION_1_1
400 CCLErr* err_internal = NULL;
403 evt, CL_EVENT_CONTEXT, cl_context, &err_internal);
417 g_assert(err == NULL || *err == NULL);
423 g_assert(err == NULL || *err != NULL);
462 void *user_data,
CCLErr** err) {
465 g_return_val_if_fail(evt != NULL, CL_FALSE);
467 g_return_val_if_fail(err == NULL || *err == NULL, CL_FALSE);
476 CCLErr* err_internal = NULL;
478 #ifndef CL_VERSION_1_1
491 "%s: Event callbacks require cf4ocl to be deployed with "
492 "support for OpenCL version 1.1 or newer.",
504 "%s: set event callback requires OpenCL version 1.1 or newer.",
509 command_exec_callback_type, pfn_notify, user_data);
511 CL_SUCCESS != ocl_status, ocl_status, error_handler,
512 "%s: unable to set event callback (OpenCL error %d: %s).",
513 CCL_STRD, ocl_status,
ccl_err(ocl_status));
518 g_assert(err == NULL || *err == NULL);
519 ret_status = CL_TRUE;
525 g_assert(err == NULL || *err != NULL);
527 ret_status = CL_FALSE;
555 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
558 g_return_val_if_fail(ctx != NULL, NULL);
569 CCLErr* err_internal = NULL;
571 #ifndef CL_VERSION_1_1
582 "%s: User events require cf4ocl to be deployed with "
583 "support for OpenCL version 1.1 or newer.",
595 "%s: User events require OpenCL version 1.1 or newer.",
601 CL_SUCCESS != ocl_status, ocl_status, error_handler,
602 "%s: error creating user event (OpenCL error %d: %s).",
603 CCL_STRD, ocl_status,
ccl_err(ocl_status));
611 g_assert(err == NULL || *err == NULL);
616 g_assert(err == NULL || *err != NULL);
645 g_return_val_if_fail(err == NULL || *err == NULL, CL_FALSE);
648 g_return_val_if_fail(evt != NULL, CL_FALSE);
657 CCLErr* err_internal = NULL;
659 #ifndef CL_VERSION_1_1
670 "%s: User events require cf4ocl to be deployed with "
671 "support for OpenCL version 1.1 or newer.",
683 "%s: User events require OpenCL version 1.1 or newer.",
687 ocl_status = clSetUserEventStatus(
690 CL_SUCCESS != ocl_status, ocl_status, error_handler,
691 "%s: error setting user event status (OpenCL error %d: %s).",
692 CCL_STRD, ocl_status,
ccl_err(ocl_status));
697 g_assert(err == NULL || *err == NULL);
698 ret_status = CL_TRUE;
703 g_assert(err == NULL || *err != NULL);
704 ret_status = CL_FALSE;
726 g_return_val_if_fail(evt_wait_lst != NULL, NULL);
735 if (*evt_wait_lst == NULL)
736 *evt_wait_lst = g_ptr_array_new();
739 va_start(al, evt_wait_lst);
742 while ((evt = va_arg(al,
CCLEvent*)) != NULL) {
753 g_return_val_if_fail((*evt_wait_lst)->len > 0, NULL);
772 g_return_val_if_fail(evt_wait_lst != NULL, NULL);
775 g_return_val_if_fail(evts != NULL, NULL);
778 g_return_val_if_fail(evts[0] != NULL, NULL);
781 if (*evt_wait_lst == NULL)
782 *evt_wait_lst = g_ptr_array_new();
785 for (guint i = 0; evts[i] != NULL; ++i) {
809 if ((evt_wait_lst != NULL) && (*evt_wait_lst != NULL)) {
810 g_ptr_array_free(*evt_wait_lst, TRUE);
811 *evt_wait_lst = NULL;
832 g_return_val_if_fail(err == NULL || *err == NULL, CL_FALSE);
840 ocl_status = clWaitForEvents(
841 ccl_event_wait_list_get_num_events(evt_wait_lst),
842 ccl_event_wait_list_get_clevents(evt_wait_lst));
844 CL_SUCCESS != ocl_status, ocl_status, error_handler,
845 "%s: error while waiting for events (OpenCL error %d: %s).",
846 CCL_STRD, ocl_status,
ccl_err(ocl_status));
852 g_assert(err == NULL || *err == NULL);
853 ret_status = CL_TRUE;
858 g_assert(err == NULL || *err != NULL);
859 ret_status = CL_FALSE;
void ccl_event_set_name(CCLEvent *evt, const char *name)
Set event name for profiling purposes.
const char * ccl_event_get_final_name(CCLEvent *evt)
Get the final event name for profiling purposes.
#define CCL_OCL_ERROR
Resolves to error category identifying string, in this case an error in the OpenCL library...
cl_bool ccl_event_set_callback(CCLEvent *evt, cl_int command_exec_callback_type, ccl_event_callback pfn_notify, void *user_data, CCLErr **err)
Wrapper for OpenCL clSetEventCallback() function.
CCLEvent * ccl_user_event_new(CCLContext *ctx, CCLErr **err)
Create a new user event.
#define ccl_if_err_create_goto(err, quark, error_condition, error_code, label, msg,...)
If error is detected (error_code != no_error_code), create an error object (CCLErr) and go to the spe...
#define ccl_context_unwrap(ctx)
Get the OpenCL context object.
GPtrArray * CCLEventWaitList
A list of event objects on which enqueued commands can wait.
Useful definitions used internally by cf4ocl.
#define ccl_event_get_info(evt, param_name, err)
Get a CCLWrapperInfo event information object.
void ccl_event_destroy(CCLEvent *evt)
Decrements the reference count of the event wrapper object.
Definition of a wrapper class and its methods for OpenCL event objects.
The context wrapper class.
#define ccl_if_err_propagate_goto(err_dest, err_src, label)
Same as ccl_if_err_goto(), but rethrows error in a source CCLErr object to a new destination CCLErr o...
const char * ccl_err(int code)
Convert OpenCL error code to a readable string.
cl_uint ccl_event_get_opencl_version(CCLEvent *evt, CCLErr **err)
Get the OpenCL version of the platform associated with this event object.
CCLContext * ccl_context_new_wrap(cl_context context)
Get the context wrapper for the given OpenCL context.
cl_uint ccl_context_get_opencl_version(CCLContext *ctx, CCLErr **err)
Get the OpenCL version of the platform associated with this context.
struct ccl_event CCLEvent
Event wrapper class.
#define CCL_ERROR
Resolves to error category identifying string, in this case an error in cf4ocl.
cl_command_type ccl_event_get_command_type(CCLEvent *evt, CCLErr **err)
Get the command type which fired the given event.
Base class for all OpenCL wrappers.
#define ccl_event_get_info_scalar(evt, param_name, param_type, err)
Macro which returns a scalar event information value.
cl_bool ccl_user_event_set_status(CCLEvent *evt, cl_int execution_status, CCLErr **err)
Sets the execution status of a user event object.
#define ccl_context_unref(ctx)
Alias to ccl_context_destroy().
#define CCL_UNUSED(x)
Macro to avoid warning in unused variables.
const char * ccl_event_get_name(CCLEvent *evt)
Get the event name for profiling purposes.
CCLEventWaitList * ccl_event_wait_list_add(CCLEventWaitList *evt_wait_lst,...)
Add event wrapper objects to an event wait list (variable argument list version). ...
#define ccl_event_unwrap(evt)
Get the OpenCL event object.
void * value
Object information.
CCLEventWaitList * ccl_event_wait_list_add_v(CCLEventWaitList *evt_wait_lst, CCLEvent **evts)
Add event wrapper objects to an event wait list (array version).
Class which represents information about a wrapped OpenCL object.
GError CCLErr
Error handling class.
Definition of a wrapper class and its methods for OpenCL queue objects.
CCLEvent * ccl_event_new_wrap(cl_event event)
Get the event wrapper for the given OpenCL event.
cl_bool ccl_event_wait(CCLEventWaitList *evt_wait_lst, CCLErr **err)
Waits on the host thread for commands identified by events in the wait list to complete.
The operation is not supported by the version of the selected OpenCL platform.
void ccl_event_wait_list_clear(CCLEventWaitList *evt_wait_lst)
Clears an event wait list.
void(* ccl_event_callback)(cl_event event, cl_int event_command_exec_status, void *user_data)
Prototype for user event callback functions.