30 #include "_ccl_abstract_wrapper.h"
68 GHashTableIter evt_iter;
81 static void ccl_queue_release_fields(
CCLQueue* cq) {
84 g_return_if_fail(cq != NULL);
94 if (cq->evts != NULL) {
95 g_hash_table_destroy(cq->evts);
156 const cl_queue_properties* prop_full,
CCLErr** err) {
159 g_return_val_if_fail(ctx != NULL, NULL);
161 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
166 cl_command_queue queue = NULL;
170 CCLErr* err_internal = NULL;
172 cl_command_queue_properties properties = 0;
174 cl_bool prop_other = CL_FALSE;
178 if (prop_full != NULL) {
181 for (cl_uint i = 0; prop_full[i] != 0; i = i + 2) {
184 if (prop_full[i] == CL_QUEUE_PROPERTIES) {
188 properties = prop_full[i + 1];
193 prop_other = CL_TRUE;
201 ~(CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE |
202 CL_QUEUE_PROFILING_ENABLE)) != 0) {
206 prop_other = CL_TRUE;
218 #ifdef CL_VERSION_2_0
228 if (platf_ver >= 200) {
232 queue = clCreateCommandQueueWithProperties(
234 prop_full, &ocl_status);
245 g_warning(
"OpenCL >= 2.0 queue properties are not supported by "
246 "the selected OpenCL platform and will be ignored.");
247 properties = properties &
248 (CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE |
249 CL_QUEUE_PROFILING_ENABLE);
253 CCL_BEGIN_IGNORE_DEPRECATIONS
256 CCL_END_IGNORE_DEPRECATIONS
265 g_warning(
"OpenCL >= 2.0 queue properties are not supported by "
266 "the selected OpenCL platform and will be ignored.");
267 properties = properties &
268 (CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE |
269 CL_QUEUE_PROFILING_ENABLE);
280 CL_SUCCESS != ocl_status, ocl_status, error_handler,
281 "%s: unable to create queue (OpenCL error %d: %s).",
282 CCL_STRD, ocl_status,
ccl_err(ocl_status));
295 g_assert(err == NULL || *err == NULL);
300 g_assert(err == NULL || *err != NULL);
334 cl_command_queue_properties properties,
CCLErr** err) {
336 const cl_queue_properties prop_full[] =
337 { CL_QUEUE_PROPERTIES, properties, 0 };
356 (ccl_wrapper_release_fields) ccl_queue_release_fields,
357 (ccl_wrapper_release_cl_object) clReleaseCommandQueue, NULL);
377 g_return_val_if_fail(cq != NULL, NULL);
379 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
384 CCLErr* err_internal = NULL;
387 if (cq->ctx != NULL) {
400 g_assert(err == NULL || *err == NULL);
405 g_assert(err == NULL || *err != NULL);
430 g_return_val_if_fail(cq != NULL, NULL);
432 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
438 CCLErr* err_internal = NULL;
441 if (cq->dev != NULL) {
454 g_assert(err == NULL || *err == NULL);
459 g_assert(err == NULL || *err != NULL);
487 g_return_val_if_fail(cq != NULL, NULL);
489 g_return_val_if_fail(event != NULL, NULL);
495 if (cq->evts == NULL) {
496 cq->evts = g_hash_table_new_full(g_direct_hash, g_direct_equal,
502 g_hash_table_add(cq->evts, (gpointer) evt);
523 void ccl_queue_iter_event_init(
CCLQueue* cq) {
526 g_return_if_fail(cq != NULL);
529 g_hash_table_iter_init(&cq->evt_iter, cq->evts);
556 g_return_val_if_fail(cq != NULL, NULL);
559 gboolean exists = g_hash_table_iter_next(&cq->evt_iter, &evt, NULL);
560 return exists ? (
CCLEvent*) evt : NULL;
580 g_return_val_if_fail(err == NULL || *err == NULL, CL_INT_MAX);
582 g_return_val_if_fail(cq != NULL, CL_INVALID_COMMAND_QUEUE);
589 if (ocl_status != CL_SUCCESS)
591 "%s: unable to flush queue (OpenCL error %d: %s).",
592 CCL_STRD, ocl_status,
ccl_err(ocl_status));
595 return ocl_status == CL_SUCCESS ? CL_TRUE : CL_FALSE;
615 g_return_val_if_fail(err == NULL || *err == NULL, CL_INT_MAX);
617 g_return_val_if_fail(cq != NULL, CL_INVALID_COMMAND_QUEUE);
624 if (ocl_status != CL_SUCCESS)
626 "%s: unable to finish queue (OpenCL error %d: %s).",
627 CCL_STRD, ocl_status,
ccl_err(ocl_status));
630 return ocl_status == CL_SUCCESS ? CL_TRUE : CL_FALSE;
655 g_return_if_fail(cq != NULL);
658 if (cq->evts != NULL) {
659 g_hash_table_remove_all(cq->evts);
688 static cl_event ccl_enqueue_barrier_deprecated(
CCLQueue* cq,
694 cl_event
event = NULL;
696 CCL_BEGIN_IGNORE_DEPRECATIONS
700 if ((evt_wait_lst == NULL) ||
701 (ccl_event_wait_list_get_num_events(evt_wait_lst) == 0)) {
706 CL_SUCCESS != ocl_status, ocl_status, error_handler,
707 "%s: error in clEnqueueBarrier() (OpenCL error %d: %s).",
708 CCL_STRD, ocl_status,
ccl_err(ocl_status));
714 ccl_event_wait_list_get_num_events(evt_wait_lst),
715 ccl_event_wait_list_get_clevents(evt_wait_lst));
717 CL_SUCCESS != ocl_status, ocl_status, error_handler,
718 "%s: error in clEnqueueWaitForEvents() (OpenCL error %d: %s).",
719 CCL_STRD, ocl_status,
ccl_err(ocl_status));
726 CL_SUCCESS != ocl_status, ocl_status, error_handler,
727 "%s: error in clEnqueueMarker() (OpenCL error %d: %s).",
728 CCL_STRD, ocl_status,
ccl_err(ocl_status));
730 CCL_END_IGNORE_DEPRECATIONS
733 g_assert(err == NULL || *err == NULL);
738 g_assert(err == NULL || *err != NULL);
775 g_return_val_if_fail(cq != NULL, NULL);
777 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
784 CCLErr* err_internal = NULL;
786 #ifdef CL_VERSION_1_2
806 if (platf_ver >= 120) {
810 ccl_event_wait_list_get_num_events(evt_wait_lst),
811 ccl_event_wait_list_get_clevents(evt_wait_lst), &event);
813 CL_SUCCESS != ocl_status, ocl_status, error_handler,
814 "%s: error in clEnqueueBarrierWithWaitList() "
815 "(OpenCL error %d: %s).",
816 CCL_STRD, ocl_status,
ccl_err(ocl_status));
821 event = ccl_enqueue_barrier_deprecated(
822 cq, evt_wait_lst, &err_internal);
830 event = ccl_enqueue_barrier_deprecated(
831 cq, evt_wait_lst, &err_internal);
839 evt = ccl_queue_produce_event(cq, event);
845 g_assert(err == NULL || *err == NULL);
851 g_assert(err == NULL || *err != NULL);
883 static cl_event ccl_enqueue_marker_deprecated(
CCLQueue* cq,
889 cl_event
event = NULL;
893 if (evt_wait_lst != NULL) {
894 g_warning(
"The OpenCL version of the selected platform " \
895 "doesn't support markers on specific events. The marker " \
896 "will only fire an event when all previous events have " \
900 CCL_BEGIN_IGNORE_DEPRECATIONS
905 CL_SUCCESS != ocl_status, ocl_status, error_handler,
906 "%s: error in clEnqueueMarker() (OpenCL error %d: %s).",
907 CCL_STRD, ocl_status,
ccl_err(ocl_status));
909 CCL_END_IGNORE_DEPRECATIONS
912 g_assert(err == NULL || *err == NULL);
917 g_assert(err == NULL || *err != NULL);
955 g_return_val_if_fail(cq != NULL, NULL);
957 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
964 CCLErr* err_internal = NULL;
966 #ifdef CL_VERSION_1_2
986 if (platf_ver >= 120) {
990 ccl_event_wait_list_get_num_events(evt_wait_lst),
991 ccl_event_wait_list_get_clevents(evt_wait_lst), &event);
993 CL_SUCCESS != ocl_status, ocl_status, error_handler,
994 "%s: error in clEnqueueMarkerWithWaitList() (OpenCL error %d: %s).",
995 CCL_STRD, ocl_status,
ccl_err(ocl_status));
1000 event = ccl_enqueue_marker_deprecated(
1001 cq, evt_wait_lst, &err_internal);
1009 event = ccl_enqueue_marker_deprecated(
1010 cq, evt_wait_lst, &err_internal);
1018 evt = ccl_queue_produce_event(cq, event);
1024 g_assert(err == NULL || *err == NULL);
1030 g_assert(err == NULL || *err != NULL);
CCLEvent * ccl_enqueue_barrier(CCLQueue *cq, CCLEventWaitList *evt_wait_lst, CCLErr **err)
Enqueues a barrier command on the given command queue.
#define CCL_OCL_ERROR
Resolves to error category identifying string, in this case an error in the OpenCL library...
#define ccl_context_ref(ctx)
Increase the reference count of the context wrapper object.
CCLQueue * ccl_queue_new(CCLContext *ctx, CCLDevice *dev, cl_command_queue_properties properties, CCLErr **err)
Create a new command queue wrapper object.
#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.
void ccl_event_destroy(CCLEvent *evt)
Decrements the reference count of the event wrapper object.
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...
CCLEvent * ccl_enqueue_marker(CCLQueue *cq, CCLEventWaitList *evt_wait_lst, CCLErr **err)
Enqueues a marker command on the given command queue.
Command queue wrapper class.
CCLDevice * ccl_context_get_device(CCLContext *ctx, cl_uint index, CCLErr **err)
Get CCLDevice wrapper at given index.
const char * ccl_err(int code)
Convert OpenCL error code to a readable string.
void ccl_event_wait_list_clear(CCLEventWaitList *evt_wait_lst)
Clears an event wait list.
#define ccl_queue_get_info(cq, param_name, err)
Get a CCLWrapperInfo command queue information 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.
cl_bool ccl_queue_flush(CCLQueue *cq, CCLErr **err)
Issues all previously queued commands in a command queue to the associated device.
CCLQueue * ccl_queue_new_wrap(cl_command_queue command_queue)
Get the command queue wrapper for the given OpenCL command queue.
void ccl_queue_gc(CCLQueue *cq)
Release all events associated with the command queue.
cl_bool ccl_queue_finish(CCLQueue *cq, CCLErr **err)
Blocks until all previously queued OpenCL commands in a command-queue are issued to the associated de...
#define ccl_device_ref(dev)
Increase the reference count of the device wrapper object.
Base class for all OpenCL wrappers.
CCLDevice * ccl_queue_get_device(CCLQueue *cq, CCLErr **err)
Get the device associated with the given command queue wrapper object.
#define ccl_device_unwrap(dev)
Get the OpenCL device_id object.
#define ccl_context_unref(ctx)
Alias to ccl_context_destroy().
CCLQueue * ccl_queue_new_full(CCLContext *ctx, CCLDevice *dev, const cl_queue_properties *prop_full, CCLErr **err)
Create a new command queue wrapper object.
#define ccl_device_unref(dev)
Alias to ccl_device_destroy().
void * value
Object information.
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.
CCLContext * ccl_queue_get_context(CCLQueue *cq, CCLErr **err)
Get the context associated with the given command queue wrapper object.
void ccl_queue_destroy(CCLQueue *cq)
Decrements the reference count of the command queue wrapper object.
#define ccl_queue_unwrap(cq)
Get the OpenCL command queue object.
CCLDevice * ccl_device_new_wrap(cl_device_id device)
Get the device wrapper for the given OpenCL device.