32 #include "_ccl_memobj_wrapper.h"
91 (ccl_wrapper_release_fields) ccl_memobj_release_fields,
92 (ccl_wrapper_release_cl_object) clReleaseMemObject, NULL);
114 size_t size,
void* host_ptr,
CCLErr** err) {
117 g_return_val_if_fail(ctx != NULL, NULL);
119 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
127 host_ptr, &ocl_status);
129 CL_SUCCESS != ocl_status, ocl_status, error_handler,
130 "%s: unable to create buffer (OpenCL error %d: %s).",
131 CCL_STRD, ocl_status,
ccl_err(ocl_status));
137 g_assert(err == NULL || *err == NULL);
142 g_assert(err == NULL || *err != NULL);
176 cl_bool blocking_read,
size_t offset,
size_t size,
void *ptr,
180 g_return_val_if_fail(cq != NULL, NULL);
182 g_return_val_if_fail(buf != NULL, NULL);
184 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
187 cl_event
event = NULL;
192 ccl_event_wait_list_get_num_events(evt_wait_lst),
193 ccl_event_wait_list_get_clevents(evt_wait_lst), &event);
195 CL_SUCCESS != ocl_status, ocl_status, error_handler,
196 "%s: unable to read buffer (OpenCL error %d: %s).",
197 CCL_STRD, ocl_status,
ccl_err(ocl_status));
202 evt = ccl_queue_produce_event(cq, event);
208 g_assert(err == NULL || *err == NULL);
213 g_assert(err == NULL || *err != NULL);
251 cl_bool blocking_write,
size_t offset,
size_t size,
void *ptr,
255 g_return_val_if_fail(cq != NULL, NULL);
257 g_return_val_if_fail(buf != NULL, NULL);
259 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
262 cl_event
event = NULL;
267 ccl_event_wait_list_get_num_events(evt_wait_lst),
268 ccl_event_wait_list_get_clevents(evt_wait_lst), &event);
270 CL_SUCCESS != ocl_status, ocl_status, error_handler,
271 "%s: unable to write buffer (OpenCL error %d: %s).",
272 CCL_STRD, ocl_status,
ccl_err(ocl_status));
277 evt = ccl_queue_produce_event(cq, event);
283 g_assert(err == NULL || *err == NULL);
288 g_assert(err == NULL || *err != NULL);
329 cl_bool blocking_map, cl_map_flags map_flags,
size_t offset,
334 g_return_val_if_fail(cq != NULL, NULL);
336 g_return_val_if_fail(buf != NULL, NULL);
338 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
341 cl_event
event = NULL;
348 ccl_event_wait_list_get_num_events(evt_wait_lst),
349 ccl_event_wait_list_get_clevents(evt_wait_lst),
350 &event, &ocl_status);
352 CL_SUCCESS != ocl_status, ocl_status, error_handler,
353 "%s: unable to map buffer (OpenCL error %d: %s).",
354 CCL_STRD, ocl_status,
ccl_err(ocl_status));
359 evt_inner = ccl_queue_produce_event(cq, event);
367 g_assert(err == NULL || *err == NULL);
372 g_assert(err == NULL || *err != NULL);
414 g_return_val_if_fail(cq != NULL, NULL);
416 g_return_val_if_fail(src_buf != NULL, NULL);
418 g_return_val_if_fail(dst_buf != NULL, NULL);
420 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
423 cl_event
event = NULL;
428 src_offset, dst_offset, size,
429 ccl_event_wait_list_get_num_events(evt_wait_lst),
430 ccl_event_wait_list_get_clevents(evt_wait_lst), &event);
432 CL_SUCCESS != ocl_status, ocl_status, error_handler,
433 "%s: unable to write buffer (OpenCL error %d: %s).",
434 CCL_STRD, ocl_status,
ccl_err(ocl_status));
439 evt = ccl_queue_produce_event(cq, event);
445 g_assert(err == NULL || *err == NULL);
450 g_assert(err == NULL || *err != NULL);
494 const size_t *dst_origin,
const size_t *region,
498 g_return_val_if_fail(cq != NULL, NULL);
500 g_return_val_if_fail(src_buf != NULL, NULL);
502 g_return_val_if_fail(dst_img != NULL, NULL);
504 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
509 cl_event
event = NULL;
516 src_offset, dst_origin, region,
517 ccl_event_wait_list_get_num_events(evt_wait_lst),
518 ccl_event_wait_list_get_clevents(evt_wait_lst), &event);
520 CL_SUCCESS != ocl_status, ocl_status, error_handler,
521 "%s: unable to copy buffer to image (OpenCL error %d: %s).",
522 CCL_STRD, ocl_status,
ccl_err(ocl_status));
527 evt = ccl_queue_produce_event(cq, event);
533 g_assert(err == NULL || *err == NULL);
538 g_assert(err == NULL || *err != NULL);
570 cl_mem_flags flags,
size_t origin,
size_t size,
CCLErr** err) {
573 g_return_val_if_fail(buf != NULL, NULL);
575 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
586 CCLErr* err_internal = NULL;
588 #ifndef CL_VERSION_1_1
602 "%s: Sub-buffers require cf4ocl to be deployed with support "
603 "for OpenCL version 1.1 or newer.",
609 const cl_buffer_region br = { .origin = origin, .size = size};
619 "%s: sub-buffers require OpenCL version 1.1 or newer.",
624 CL_BUFFER_CREATE_TYPE_REGION, (
const void*) &br, &ocl_status);
626 CL_SUCCESS != ocl_status, ocl_status, error_handler,
627 "%s: unable create sub-buffer (OpenCL error %d: %s).",
628 CCL_STRD, ocl_status,
ccl_err(ocl_status));
636 g_assert(err == NULL || *err == NULL);
641 g_assert(err == NULL || *err != NULL);
691 cl_bool blocking_read,
const size_t* buffer_origin,
692 const size_t* host_origin,
const size_t* region,
693 size_t buffer_row_pitch,
size_t buffer_slice_pitch,
694 size_t host_row_pitch,
size_t host_slice_pitch,
void *ptr,
698 g_return_val_if_fail(cq != NULL, NULL);
700 g_return_val_if_fail(buf != NULL, NULL);
702 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
707 cl_event
event = NULL;
713 CCLErr* err_internal = NULL;
715 #ifndef CL_VERSION_1_1
737 "%s: Rectangular buffer read requires cf4ocl to be deployed with "
738 "support for OpenCL version 1.1 or newer.",
751 "%s: rect. buffer reads require OpenCL version 1.1 or newer.",
757 host_origin, region, buffer_row_pitch, buffer_slice_pitch,
758 host_row_pitch, host_slice_pitch, ptr,
759 ccl_event_wait_list_get_num_events(evt_wait_lst),
760 ccl_event_wait_list_get_clevents(evt_wait_lst), &event);
762 CL_SUCCESS != ocl_status, ocl_status, error_handler,
763 "%s: unable to enqueue a rectangular buffer read (OpenCL error %d: %s).",
764 CCL_STRD, ocl_status,
ccl_err(ocl_status));
769 evt = ccl_queue_produce_event(cq, event);
777 g_assert(err == NULL || *err == NULL);
782 g_assert(err == NULL || *err != NULL);
834 cl_bool blocking_write,
const size_t* buffer_origin,
835 const size_t* host_origin,
const size_t* region,
836 size_t buffer_row_pitch,
size_t buffer_slice_pitch,
837 size_t host_row_pitch,
size_t host_slice_pitch,
void *ptr,
841 g_return_val_if_fail(cq != NULL, NULL);
843 g_return_val_if_fail(buf != NULL, NULL);
845 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
850 cl_event
event = NULL;
856 CCLErr* err_internal = NULL;
858 #ifndef CL_VERSION_1_1
880 "%s: Rectangular buffer write requires cf4ocl to be deployed with "
881 "support for OpenCL version 1.1 or newer.",
894 "%s: rect. buffer writes require OpenCL version 1.1 or newer.",
900 host_origin, region, buffer_row_pitch, buffer_slice_pitch,
901 host_row_pitch, host_slice_pitch, ptr,
902 ccl_event_wait_list_get_num_events(evt_wait_lst),
903 ccl_event_wait_list_get_clevents(evt_wait_lst), &event);
905 CL_SUCCESS != ocl_status, ocl_status, error_handler,
906 "%s: unable to enqueue a rectangular buffer write (OpenCL error %d: %s).",
907 CCL_STRD, ocl_status,
ccl_err(ocl_status));
912 evt = ccl_queue_produce_event(cq, event);
920 g_assert(err == NULL || *err == NULL);
925 g_assert(err == NULL || *err != NULL);
974 const size_t *dst_origin,
const size_t *region,
975 size_t src_row_pitch,
size_t src_slice_pitch,
size_t dst_row_pitch,
980 g_return_val_if_fail(cq != NULL, NULL);
982 g_return_val_if_fail(src_buf != NULL, NULL);
984 g_return_val_if_fail(dst_buf != NULL, NULL);
986 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
991 cl_event
event = NULL;
997 CCLErr* err_internal = NULL;
999 #ifndef CL_VERSION_1_1
1019 "%s: Rectangular buffer copy requires cf4ocl to be deployed with "
1020 "support for OpenCL version 1.1 or newer.",
1033 "%s: rect. buffer copy requires OpenCL version 1.1 or newer.",
1039 src_origin, dst_origin, region, src_row_pitch, src_slice_pitch,
1040 dst_row_pitch, dst_slice_pitch,
1041 ccl_event_wait_list_get_num_events(evt_wait_lst),
1042 ccl_event_wait_list_get_clevents(evt_wait_lst), &event);
1044 CL_SUCCESS != ocl_status, ocl_status, error_handler,
1045 "%s: unable to enqueue a rectangular buffer copy (OpenCL error %d: %s).",
1046 CCL_STRD, ocl_status,
ccl_err(ocl_status));
1051 evt = ccl_queue_produce_event(cq, event);
1059 g_assert(err == NULL || *err == NULL);
1064 g_assert(err == NULL || *err != NULL);
1101 const void *pattern,
size_t pattern_size,
size_t offset,
1105 g_return_val_if_fail(cq != NULL, NULL);
1107 g_return_val_if_fail(buf != NULL, NULL);
1109 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
1114 cl_event
event = NULL;
1120 CCLErr* err_internal = NULL;
1122 #ifndef CL_VERSION_1_2
1139 "%s: Buffer fill requires cf4ocl to be deployed with "
1140 "support for OpenCL version 1.1 or newer.",
1153 "%s: Buffer fill requires OpenCL version 1.2 or newer.",
1159 ccl_event_wait_list_get_num_events(evt_wait_lst),
1160 ccl_event_wait_list_get_clevents(evt_wait_lst), &event);
1162 CL_SUCCESS != ocl_status, ocl_status, error_handler,
1163 "%s: unable to enqueue a fill buffer command (OpenCL error %d: %s).",
1164 CCL_STRD, ocl_status,
ccl_err(ocl_status));
1169 evt = ccl_queue_produce_event(cq, event);
1177 g_assert(err == NULL || *err == NULL);
1182 g_assert(err == NULL || *err != NULL);
#define CCL_OCL_ERROR
Resolves to error category identifying string, in this case an error in the OpenCL library...
CCLEvent * ccl_buffer_enqueue_copy_to_image(CCLBuffer *src_buf, CCLImage *dst_img, CCLQueue *cq, size_t src_offset, const size_t *dst_origin, const size_t *region, CCLEventWaitList *evt_wait_lst, CCLErr **err)
Copy a buffer object to an image 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...
CCLEvent * ccl_buffer_enqueue_write_rect(CCLBuffer *buf, CCLQueue *cq, cl_bool blocking_write, const size_t *buffer_origin, const size_t *host_origin, const size_t *region, size_t buffer_row_pitch, size_t buffer_slice_pitch, size_t host_row_pitch, size_t host_slice_pitch, void *ptr, CCLEventWaitList *evt_wait_lst, CCLErr **err)
Write a 2D or 3D rectangular region to a buffer object from host memory.
#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_memobj_unwrap(mo)
Get the OpenCL cl_mem object.
CCLEvent * ccl_buffer_enqueue_read_rect(CCLBuffer *buf, CCLQueue *cq, cl_bool blocking_read, const size_t *buffer_origin, const size_t *host_origin, const size_t *region, size_t buffer_row_pitch, size_t buffer_slice_pitch, size_t host_row_pitch, size_t host_slice_pitch, void *ptr, CCLEventWaitList *evt_wait_lst, CCLErr **err)
Read from a 2D or 3D rectangular region from a buffer object to host memory.
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...
Base class for memory object wrappers, i.e., CCLBuffer and CCLImage.
Definition of a wrapper class and its methods for OpenCL image objects.
Command queue wrapper class.
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.
CCLEvent * ccl_buffer_enqueue_write(CCLBuffer *buf, CCLQueue *cq, cl_bool blocking_write, size_t offset, size_t size, void *ptr, CCLEventWaitList *evt_wait_lst, CCLErr **err)
Write to a buffer object from host memory.
#define CCL_ERROR
Resolves to error category identifying string, in this case an error in cf4ocl.
CCLBuffer * ccl_buffer_new_from_region(CCLBuffer *buf, cl_mem_flags flags, size_t origin, size_t size, CCLErr **err)
Creates a sub-buffer that represents a specific region in the given buffer.
CCLEvent * ccl_buffer_enqueue_read(CCLBuffer *buf, CCLQueue *cq, cl_bool blocking_read, size_t offset, size_t size, void *ptr, CCLEventWaitList *evt_wait_lst, CCLErr **err)
Read from a buffer object to host memory.
CCLBuffer * ccl_buffer_new_wrap(cl_mem mem_object)
Get the buffer wrapper for the given OpenCL buffer.
Base class for all OpenCL wrappers.
#define CCL_UNUSED(x)
Macro to avoid warning in unused variables.
cl_uint ccl_memobj_get_opencl_version(CCLMemObj *mo, CCLErr **err)
Get the OpenCL version of the platform associated with this memory object.
CCLEvent * ccl_buffer_enqueue_fill(CCLBuffer *buf, CCLQueue *cq, const void *pattern, size_t pattern_size, size_t offset, size_t size, CCLEventWaitList *evt_wait_lst, CCLErr **err)
Fill a buffer object with a pattern of a given pattern size.
CCLEvent * ccl_buffer_enqueue_copy_rect(CCLBuffer *src_buf, CCLBuffer *dst_buf, CCLQueue *cq, const size_t *src_origin, const size_t *dst_origin, const size_t *region, size_t src_row_pitch, size_t src_slice_pitch, size_t dst_row_pitch, size_t dst_slice_pitch, CCLEventWaitList *evt_wait_lst, CCLErr **err)
Copy a 2D or 3D rectangular region from a buffer object to another buffer object. ...
void ccl_buffer_destroy(CCLBuffer *buf)
Decrements the reference count of the wrapper object.
void * ccl_buffer_enqueue_map(CCLBuffer *buf, CCLQueue *cq, cl_bool blocking_map, cl_map_flags map_flags, size_t offset, size_t size, CCLEventWaitList *evt_wait_lst, CCLEvent **evt, CCLErr **err)
Map a region of a buffer into the host address space and return a pointer to this mapped region...
CCLEvent * ccl_buffer_enqueue_copy(CCLBuffer *src_buf, CCLBuffer *dst_buf, CCLQueue *cq, size_t src_offset, size_t dst_offset, size_t size, CCLEventWaitList *evt_wait_lst, CCLErr **err)
Copy from one buffer object to another.
GError CCLErr
Error handling class.
#define ccl_queue_unwrap(cq)
Get the OpenCL command queue object.
Definition of a wrapper class and its methods for OpenCL buffer objects.
CCLBuffer * ccl_buffer_new(CCLContext *ctx, cl_mem_flags flags, size_t size, void *host_ptr, CCLErr **err)
Create a CCLBuffer wrapper object.
The operation is not supported by the version of the selected OpenCL platform.