32 #include "_ccl_memobj_wrapper.h"
77 static cl_mem ccl_image_new_deprecated(
CCLContext* ctx, cl_mem_flags flags,
78 const cl_image_format* image_format,
const CCLImageDesc* img_dsc,
79 void* host_ptr,
CCLErr** err) {
86 CCL_BEGIN_IGNORE_DEPRECATIONS
89 if (img_dsc->
image_type == CL_MEM_OBJECT_IMAGE2D) {
97 CL_SUCCESS != ocl_status, ocl_status, error_handler,
98 "%s: unable to create image with clCreateImage2D() " \
99 "(OpenCL error %d: %s).",
100 CCL_STRD, ocl_status,
ccl_err(ocl_status));
102 }
else if (img_dsc->
image_type == CL_MEM_OBJECT_IMAGE3D) {
111 CL_SUCCESS != ocl_status, ocl_status, error_handler,
112 "%s: unable to create image with clCreateImage3D() " \
113 "(OpenCL error %d: %s).",
114 CCL_STRD, ocl_status,
ccl_err(ocl_status));
121 "%s: unknown or unsuported image type (%x)", CCL_STRD,
126 CCL_END_IGNORE_DEPRECATIONS
129 g_assert(err == NULL || *err == NULL);
135 g_assert(err == NULL || *err != NULL);
180 (ccl_wrapper_release_fields) ccl_memobj_release_fields,
181 (ccl_wrapper_release_cl_object) clReleaseMemObject, NULL);
227 const cl_image_format* image_format,
const CCLImageDesc* img_dsc,
228 void* host_ptr,
CCLErr** err) {
231 g_return_val_if_fail(ctx != NULL, NULL);
233 g_return_val_if_fail(img_dsc != NULL, NULL);
235 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
242 CCLErr* err_internal = NULL;
244 #ifdef CL_VERSION_1_2
256 if (ocl_ver >= 120) {
262 cl_mem memory_object = (img_dsc->
memobj != NULL)
264 const cl_image_desc image_desc = {
274 #ifdef CL_VERSION_2_0
275 .mem_object = memory_object
277 .buffer = memory_object
283 image_format, &image_desc, host_ptr, &ocl_status);
285 CL_SUCCESS != ocl_status, ocl_status, error_handler,
286 "%s: unable to create image with clCreateImage() " \
287 "(OpenCL error %d: %s).",
288 CCL_STRD, ocl_status,
ccl_err(ocl_status));
293 image = ccl_image_new_deprecated(ctx, flags, image_format,
294 img_dsc, host_ptr, &err_internal);
302 image = ccl_image_new_deprecated(ctx, flags, image_format,
303 img_dsc, host_ptr, &err_internal);
312 g_assert(err == NULL || *err == NULL);
318 g_assert(err == NULL || *err != NULL);
392 const cl_image_format* image_format,
void* host_ptr,
CCLErr** err,
396 g_return_val_if_fail(ctx != NULL, NULL);
398 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
408 va_start(args_va, err);
412 while ((key = va_arg(args_va,
const char*)) != NULL) {
414 if (g_strcmp0(key,
"image_type") == 0) {
415 image_dsc.
image_type = va_arg(args_va, cl_mem_object_type);
416 }
else if (g_strcmp0(key,
"image_width") == 0) {
418 }
else if (g_strcmp0(key,
"image_height") == 0) {
420 }
else if (g_strcmp0(key,
"image_depth") == 0) {
422 }
else if (g_strcmp0(key,
"image_array_size") == 0) {
424 }
else if (g_strcmp0(key,
"image_row_pitch") == 0) {
426 }
else if (g_strcmp0(key,
"image_slice_pitch") == 0) {
428 }
else if (g_strcmp0(key,
"num_mip_levels") == 0) {
430 }
else if (g_strcmp0(key,
"num_samples") == 0) {
432 }
else if (g_strcmp0(key,
"memobj") == 0) {
436 "%s: unknown key '%s'", CCL_STRD, key);
486 cl_bool blocking_read,
const size_t* origin,
const size_t* region,
487 size_t row_pitch,
size_t slice_pitch,
void *ptr,
491 g_return_val_if_fail(cq != NULL, NULL);
493 g_return_val_if_fail(img != NULL, NULL);
495 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
500 cl_event
event = NULL;
507 row_pitch, slice_pitch, ptr,
508 ccl_event_wait_list_get_num_events(evt_wait_lst),
509 ccl_event_wait_list_get_clevents(evt_wait_lst), &event);
511 CL_SUCCESS != ocl_status, ocl_status, error_handler,
512 "%s: unable to enqueue an image read (OpenCL error %d: %s).",
513 CCL_STRD, ocl_status,
ccl_err(ocl_status));
518 evt = ccl_queue_produce_event(cq, event);
524 g_assert(err == NULL || *err == NULL);
529 g_assert(err == NULL || *err != NULL);
576 cl_bool blocking_write,
const size_t* origin,
const size_t* region,
577 size_t input_row_pitch,
size_t input_slice_pitch,
void *ptr,
581 g_return_val_if_fail(cq != NULL, NULL);
583 g_return_val_if_fail(img != NULL, NULL);
585 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
590 cl_event
event = NULL;
597 input_row_pitch, input_slice_pitch, ptr,
598 ccl_event_wait_list_get_num_events(evt_wait_lst),
599 ccl_event_wait_list_get_clevents(evt_wait_lst), &event);
601 CL_SUCCESS != ocl_status, ocl_status, error_handler,
602 "%s: unable to enqueue an image write (OpenCL error %d: %s).",
603 CCL_STRD, ocl_status,
ccl_err(ocl_status));
608 evt = ccl_queue_produce_event(cq, event);
614 g_assert(err == NULL || *err == NULL);
619 g_assert(err == NULL || *err != NULL);
663 CCLQueue* cq,
const size_t* src_origin,
const size_t* dst_origin,
668 g_return_val_if_fail(cq != NULL, NULL);
670 g_return_val_if_fail(src_img != NULL, NULL);
672 g_return_val_if_fail(dst_img != NULL, NULL);
674 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
679 cl_event
event = NULL;
686 src_origin, dst_origin, region,
687 ccl_event_wait_list_get_num_events(evt_wait_lst),
688 ccl_event_wait_list_get_clevents(evt_wait_lst), &event);
690 CL_SUCCESS != ocl_status, ocl_status, error_handler,
691 "%s: unable to enqueue an image copy (OpenCL error %d: %s).",
692 CCL_STRD, ocl_status,
ccl_err(ocl_status));
697 evt = ccl_queue_produce_event(cq, event);
703 g_assert(err == NULL || *err == NULL);
708 g_assert(err == NULL || *err != NULL);
752 const size_t *region,
size_t dst_offset,
756 g_return_val_if_fail(cq != NULL, NULL);
758 g_return_val_if_fail(src_img != NULL, NULL);
760 g_return_val_if_fail(dst_buf != NULL, NULL);
762 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
767 cl_event
event = NULL;
774 src_origin, region, dst_offset,
775 ccl_event_wait_list_get_num_events(evt_wait_lst),
776 ccl_event_wait_list_get_clevents(evt_wait_lst), &event);
778 CL_SUCCESS != ocl_status, ocl_status, error_handler,
779 "%s: unable to copy image to buffer (OpenCL error %d: %s).",
780 CCL_STRD, ocl_status,
ccl_err(ocl_status));
785 evt = ccl_queue_produce_event(cq, event);
791 g_assert(err == NULL || *err == NULL);
796 g_assert(err == NULL || *err != NULL);
849 cl_bool blocking_map, cl_map_flags map_flags,
const size_t* origin,
850 const size_t* region,
size_t *image_row_pitch,
855 g_return_val_if_fail(cq != NULL, NULL);
857 g_return_val_if_fail(img != NULL, NULL);
859 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
862 cl_event
event = NULL;
869 origin, region, image_row_pitch, image_slice_pitch,
870 ccl_event_wait_list_get_num_events(evt_wait_lst),
871 ccl_event_wait_list_get_clevents(evt_wait_lst),
872 &event, &ocl_status);
874 CL_SUCCESS != ocl_status, ocl_status, error_handler,
875 "%s: unable to map image (OpenCL error %d: %s).",
876 CCL_STRD, ocl_status,
ccl_err(ocl_status));
881 evt_inner = ccl_queue_produce_event(cq, event);
889 g_assert(err == NULL || *err == NULL);
894 g_assert(err == NULL || *err != NULL);
935 const void *fill_color,
const size_t *origin,
const size_t *region,
939 g_return_val_if_fail(cq != NULL, NULL);
941 g_return_val_if_fail(img != NULL, NULL);
943 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
948 cl_event
event = NULL;
954 CCLErr* err_internal = NULL;
956 #ifndef CL_VERSION_1_2
971 "%s: Image fill requires cf4ocl to be deployed with "
972 "support for OpenCL version 1.2 or newer.",
985 "%s: Image fill requires OpenCL version 1.2 or newer.",
991 ccl_event_wait_list_get_num_events(evt_wait_lst),
992 ccl_event_wait_list_get_clevents(evt_wait_lst), &event);
994 CL_SUCCESS != ocl_status, ocl_status, error_handler,
995 "%s: unable to enqueue a fill image command (OpenCL error %d: %s).",
996 CCL_STRD, ocl_status,
ccl_err(ocl_status));
1001 evt = ccl_queue_produce_event(cq, event);
1009 g_assert(err == NULL || *err == NULL);
1014 g_assert(err == NULL || *err != NULL);
size_t image_height
Height of the image in pixels.
void * ccl_image_enqueue_map(CCLImage *img, CCLQueue *cq, cl_bool blocking_map, cl_map_flags map_flags, const size_t *origin, const size_t *region, size_t *image_row_pitch, size_t *image_slice_pitch, CCLEventWaitList *evt_wait_lst, CCLEvent **evt, CCLErr **err)
Map a region of the image into the host address space and return a pointer to this mapped region...
size_t image_array_size
Number of images in the image array.
size_t image_width
Width of the image in pixels.
#define CCL_OCL_ERROR
Resolves to error category identifying string, in this case an error in the OpenCL library...
CCLImage * ccl_image_new_v(CCLContext *ctx, cl_mem_flags flags, const cl_image_format *image_format, const CCLImageDesc *img_dsc, void *host_ptr, CCLErr **err)
Creates a new image 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.
#define CCL_IMAGE_DESC_BLANK
This macro can be used to set a CCLImageDesc object to all zeros.
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_image_enqueue_copy_to_buffer(CCLImage *src_img, CCLBuffer *dst_buf, CCLQueue *cq, const size_t *src_origin, const size_t *region, size_t dst_offset, CCLEventWaitList *evt_wait_lst, CCLErr **err)
Copy an image object to a buffer 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_image_enqueue_write(CCLImage *img, CCLQueue *cq, cl_bool blocking_write, const size_t *origin, const size_t *region, size_t input_row_pitch, size_t input_slice_pitch, void *ptr, CCLEventWaitList *evt_wait_lst, CCLErr **err)
Write to an image or image array object from host memory.
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.
Describes the type and dimensions of the image or image array independently of the OpenCL version...
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.
cl_uint ccl_context_get_opencl_version(CCLContext *ctx, CCLErr **err)
Get the OpenCL version of the platform associated with this context.
#define CCL_ERROR
Resolves to error category identifying string, in this case an error in cf4ocl.
void ccl_image_destroy(CCLImage *img)
Decrements the reference count of the wrapper object.
CCLEvent * ccl_image_enqueue_read(CCLImage *img, CCLQueue *cq, cl_bool blocking_read, const size_t *origin, const size_t *region, size_t row_pitch, size_t slice_pitch, void *ptr, CCLEventWaitList *evt_wait_lst, CCLErr **err)
Read from an image or image array object to host memory.
size_t image_depth
Depth of the image in pixels.
Base class for all OpenCL wrappers.
size_t image_row_pitch
Scan-line pitch in bytes.
size_t image_slice_pitch
Size in bytes of each 2D slice in the 3D image or the size in bytes of each image in a 1D or 2D image...
#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.
Invalid function arguments.
CCLEvent * ccl_image_enqueue_copy(CCLImage *src_img, CCLImage *dst_img, CCLQueue *cq, const size_t *src_origin, const size_t *dst_origin, const size_t *region, CCLEventWaitList *evt_wait_lst, CCLErr **err)
Copy image objects.
CCLEvent * ccl_image_enqueue_fill(CCLImage *img, CCLQueue *cq, const void *fill_color, const size_t *origin, const size_t *region, CCLEventWaitList *evt_wait_lst, CCLErr **err)
Fill an image object with a specified color.
CCLImage * ccl_image_new(CCLContext *ctx, cl_mem_flags flags, const cl_image_format *image_format, void *host_ptr, CCLErr **err,...)
Creates a new image wrapper object using a variable list of key-value pairs which describe the image...
cl_uint num_mip_levels
Unused up to OpenCL 2.0.
cl_mem_object_type image_type
The type of image, must be supported by the underlying OpenCL version.
GError CCLErr
Error handling class.
CCLImage * ccl_image_new_wrap(cl_mem mem_object)
Get the image wrapper for the given OpenCL image.
#define ccl_queue_unwrap(cq)
Get the OpenCL command queue object.
Definition of a wrapper class and its methods for OpenCL buffer objects.
The operation is not supported by the version of the selected OpenCL platform.
cl_uint num_samples
Unused up to OpenCL 2.0.
CCLMemObj * memobj
A memory object wrapper.