cf4ocl (C Framework for OpenCL)  v2.1.0
Object-oriented framework for developing and benchmarking OpenCL projects in C/C++
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ccl_image_wrapper.c
Go to the documentation of this file.
1 /*
2  * This file is part of cf4ocl (C Framework for OpenCL).
3  *
4  * cf4ocl is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as
6  * published by the Free Software Foundation, either version 3 of the
7  * License, or (at your option) any later version.
8  *
9  * cf4ocl is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with cf4ocl. If not, see
16  * <http://www.gnu.org/licenses/>.
17  * */
18 
30 #include "ccl_image_wrapper.h"
31 #include "ccl_buffer_wrapper.h"
32 #include "_ccl_memobj_wrapper.h"
33 #include "_ccl_defs.h"
34 
40 struct ccl_image {
41 
46  CCLMemObj mo;
47 
48 };
49 
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) {
80 
81  /* OpenCL image object. */
82  cl_mem image = NULL;
83  /* OpenCL function status. */
84  cl_int ocl_status;
85 
86  CCL_BEGIN_IGNORE_DEPRECATIONS
87 
88  /* Check what type of image to create. */
89  if (img_dsc->image_type == CL_MEM_OBJECT_IMAGE2D) {
90 
91  /* Create a 2D image. */
92  image = clCreateImage2D(ccl_context_unwrap(ctx), flags,
93  image_format, img_dsc->image_width, img_dsc->image_height,
94  img_dsc->image_row_pitch, host_ptr, &ocl_status);
95 
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));
101 
102  } else if (img_dsc->image_type == CL_MEM_OBJECT_IMAGE3D) {
103 
104  /* Create a 3D image. */
105  image = clCreateImage3D(ccl_context_unwrap(ctx), flags,
106  image_format, img_dsc->image_width, img_dsc->image_height,
107  img_dsc->image_depth, img_dsc->image_row_pitch,
108  img_dsc->image_slice_pitch, host_ptr, &ocl_status);
109 
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));
115 
116  } else {
117 
118  /* Unknown or unsupported image type. */
119  ccl_if_err_create_goto(*err, CCL_ERROR, CL_TRUE,
120  CCL_ERROR_UNSUPPORTED_OCL, error_handler,
121  "%s: unknown or unsuported image type (%x)", CCL_STRD,
122  img_dsc->image_type);
123 
124  }
125 
126  CCL_END_IGNORE_DEPRECATIONS
127 
128  /* If we got here, everything is OK. */
129  g_assert(err == NULL || *err == NULL);
130  goto finish;
131 
132 error_handler:
133 
134  /* If we got here there was an error, verify that it is so. */
135  g_assert(err == NULL || *err != NULL);
136 
137 finish:
138 
139  /* Return OpenCL image object. */
140  return image;
141 
142 }
143 
160 CCL_EXPORT
161 CCLImage* ccl_image_new_wrap(cl_mem mem_object) {
162 
163  return (CCLImage*) ccl_wrapper_new(
164  CCL_IMAGE, (void*) mem_object, sizeof(CCLImage));
165 
166 }
167 
176 CCL_EXPORT
178 
179  ccl_wrapper_unref((CCLWrapper*) img, sizeof(CCLImage),
180  (ccl_wrapper_release_fields) ccl_memobj_release_fields,
181  (ccl_wrapper_release_cl_object) clReleaseMemObject, NULL);
182 
183 }
184 
225 CCL_EXPORT
226 CCLImage* ccl_image_new_v(CCLContext* ctx, cl_mem_flags flags,
227  const cl_image_format* image_format, const CCLImageDesc* img_dsc,
228  void* host_ptr, CCLErr** err) {
229 
230  /* Make sure ctx is not NULL. */
231  g_return_val_if_fail(ctx != NULL, NULL);
232  /* Make sure img_dsc is not NULL. */
233  g_return_val_if_fail(img_dsc != NULL, NULL);
234  /* Make sure err is NULL or it is not set. */
235  g_return_val_if_fail(err == NULL || *err == NULL, NULL);
236 
237  /* Image wrapper object. */
238  CCLImage* img = NULL;
239  /* OpenCL image object. */
240  cl_mem image;
241  /* Internal error handling object. */
242  CCLErr* err_internal = NULL;
243 
244 #ifdef CL_VERSION_1_2
245 
246  /* OpenCL function status. */
247  cl_int ocl_status;
248  /* OpenCL platform version. */
249  double ocl_ver;
250 
251  /* Get OpenCL platform version. */
252  ocl_ver = ccl_context_get_opencl_version(ctx, &err_internal);
253  ccl_if_err_propagate_goto(err, err_internal, error_handler);
254 
255  /* Create image depending on OpenCL platform version.*/
256  if (ocl_ver >= 120) {
257  /* OpenCL is >= 1.2, use "new" API. */
258 
259  /* OpenCL image descriptor. Initialize it with data from
260  * img_dsc (CCLImageDesc), unwrapping the wrapped buffer, if
261  * any. */
262  cl_mem memory_object = (img_dsc->memobj != NULL)
263  ? ccl_memobj_unwrap(img_dsc->memobj) : NULL;
264  const cl_image_desc image_desc = {
265  .image_type = img_dsc->image_type,
266  .image_width = img_dsc->image_width,
267  .image_height = img_dsc->image_height,
268  .image_depth = img_dsc->image_depth,
269  .image_array_size = img_dsc->image_array_size,
270  .image_row_pitch = img_dsc->image_row_pitch,
271  .image_slice_pitch = img_dsc->image_slice_pitch,
272  .num_mip_levels = img_dsc->num_mip_levels,
273  .num_samples = img_dsc->num_samples,
274 #ifdef CL_VERSION_2_0
275  .mem_object = memory_object
276 #else
277  .buffer = memory_object
278 #endif
279  };
280 
281  /* Create image. */
282  image = clCreateImage(ccl_context_unwrap(ctx), flags,
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));
289 
290  } else {
291  /* OpenCL is < 1.2, use "old" API. */
292 
293  image = ccl_image_new_deprecated(ctx, flags, image_format,
294  img_dsc, host_ptr, &err_internal);
295  ccl_if_err_propagate_goto(err, err_internal, error_handler);
296 
297  }
298 
299 #else
300 
301  /* Create image. */
302  image = ccl_image_new_deprecated(ctx, flags, image_format,
303  img_dsc, host_ptr, &err_internal);
304  ccl_if_err_propagate_goto(err, err_internal, error_handler);
305 
306 #endif
307 
308  /* Wrap image. */
309  img = ccl_image_new_wrap(image);
310 
311  /* If we got here, everything is OK. */
312  g_assert(err == NULL || *err == NULL);
313  goto finish;
314 
315 error_handler:
316 
317  /* If we got here there was an error, verify that it is so. */
318  g_assert(err == NULL || *err != NULL);
319 
320 finish:
321 
322  /* Return image wrapper. */
323  return img;
324 
325 }
326 
390 CCL_EXPORT
391 CCLImage* ccl_image_new(CCLContext* ctx, cl_mem_flags flags,
392  const cl_image_format* image_format, void* host_ptr, CCLErr** err,
393  ...) {
394 
395  /* Make sure ctx is not NULL. */
396  g_return_val_if_fail(ctx != NULL, NULL);
397  /* Make sure err is NULL or it is not set. */
398  g_return_val_if_fail(err == NULL || *err == NULL, NULL);
399 
400  /* The va_list, which represents the variable argument list. */
401  va_list args_va;
402  /* A key. */
403  const char* key;
404  /* The image description object, initialized to zeros. */
406 
407  /* Initialize the va_list. */
408  va_start(args_va, err);
409 
410  /* Check if any arguments are given, and if so, populate
411  * image_dsc. */
412  while ((key = va_arg(args_va, const char*)) != NULL) {
413 
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) {
417  image_dsc.image_width = va_arg(args_va, size_t);
418  } else if (g_strcmp0(key, "image_height") == 0) {
419  image_dsc.image_height = va_arg(args_va, size_t);
420  } else if (g_strcmp0(key, "image_depth") == 0) {
421  image_dsc.image_depth = va_arg(args_va, size_t);
422  } else if (g_strcmp0(key, "image_array_size") == 0) {
423  image_dsc.image_array_size = va_arg(args_va, size_t);
424  } else if (g_strcmp0(key, "image_row_pitch") == 0) {
425  image_dsc.image_row_pitch = va_arg(args_va, size_t);
426  } else if (g_strcmp0(key, "image_slice_pitch") == 0) {
427  image_dsc.image_slice_pitch = va_arg(args_va, size_t);
428  } else if (g_strcmp0(key, "num_mip_levels") == 0) {
429  image_dsc.num_mip_levels = va_arg(args_va, cl_uint);
430  } else if (g_strcmp0(key, "num_samples") == 0) {
431  image_dsc.num_samples = va_arg(args_va, cl_uint);
432  } else if (g_strcmp0(key, "memobj") == 0) {
433  image_dsc.memobj = va_arg(args_va, CCLMemObj*);
434  } else {
435  g_set_error(err, CCL_ERROR, CCL_ERROR_ARGS,
436  "%s: unknown key '%s'", CCL_STRD, key);
437  va_end(args_va);
438  return NULL;
439  }
440  }
441 
442  /* Close the va_list. */
443  va_end(args_va);
444 
445  /* Create the image using the vector version of this function. */
446  return ccl_image_new_v(ctx, flags, image_format,
447  (const CCLImageDesc*) &image_dsc, host_ptr, err);
448 
449 }
450 
484 CCL_EXPORT
486  cl_bool blocking_read, const size_t* origin, const size_t* region,
487  size_t row_pitch, size_t slice_pitch, void *ptr,
488  CCLEventWaitList* evt_wait_lst, CCLErr** err) {
489 
490  /* Make sure cq is not NULL. */
491  g_return_val_if_fail(cq != NULL, NULL);
492  /* Make sure img is not NULL. */
493  g_return_val_if_fail(img != NULL, NULL);
494  /* Make sure err is NULL or it is not set. */
495  g_return_val_if_fail(err == NULL || *err == NULL, NULL);
496 
497  /* OpenCL function status. */
498  cl_int ocl_status;
499  /* OpenCL event object. */
500  cl_event event = NULL;
501  /* Event wrapper object. */
502  CCLEvent* evt = NULL;
503 
504  /* Read image from device into host. */
505  ocl_status = clEnqueueReadImage(ccl_queue_unwrap(cq),
506  ccl_memobj_unwrap(img), blocking_read, origin, region,
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));
514 
515  /* Wrap event and associate it with the respective command queue.
516  * The event object will be released automatically when the command
517  * queue is released. */
518  evt = ccl_queue_produce_event(cq, event);
519 
520  /* Clear event wait list. */
521  ccl_event_wait_list_clear(evt_wait_lst);
522 
523  /* If we got here, everything is OK. */
524  g_assert(err == NULL || *err == NULL);
525  goto finish;
526 
527 error_handler:
528  /* If we got here there was an error, verify that it is so. */
529  g_assert(err == NULL || *err != NULL);
530 
531  /* An error occurred, return NULL to signal it. */
532  evt = NULL;
533 
534 finish:
535 
536  /* Return event. */
537  return evt;
538 
539 }
540 
574 CCL_EXPORT
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,
578  CCLEventWaitList* evt_wait_lst, CCLErr** err) {
579 
580  /* Make sure cq is not NULL. */
581  g_return_val_if_fail(cq != NULL, NULL);
582  /* Make sure img is not NULL. */
583  g_return_val_if_fail(img != NULL, NULL);
584  /* Make sure err is NULL or it is not set. */
585  g_return_val_if_fail(err == NULL || *err == NULL, NULL);
586 
587  /* OpenCL function status. */
588  cl_int ocl_status;
589  /* OpenCL event object. */
590  cl_event event = NULL;
591  /* Event wrapper object. */
592  CCLEvent* evt = NULL;
593 
594  /* Write image to device from host. */
595  ocl_status = clEnqueueWriteImage(ccl_queue_unwrap(cq),
596  ccl_memobj_unwrap(img), blocking_write, origin, region,
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));
604 
605  /* Wrap event and associate it with the respective command queue.
606  * The event object will be released automatically when the command
607  * queue is released. */
608  evt = ccl_queue_produce_event(cq, event);
609 
610  /* Clear event wait list. */
611  ccl_event_wait_list_clear(evt_wait_lst);
612 
613  /* If we got here, everything is OK. */
614  g_assert(err == NULL || *err == NULL);
615  goto finish;
616 
617 error_handler:
618  /* If we got here there was an error, verify that it is so. */
619  g_assert(err == NULL || *err != NULL);
620 
621  /* An error occurred, return NULL to signal it. */
622  evt = NULL;
623 
624 finish:
625 
626  /* Return event. */
627  return evt;
628 
629 }
630 
661 CCL_EXPORT
663  CCLQueue* cq, const size_t* src_origin, const size_t* dst_origin,
664  const size_t* region, CCLEventWaitList* evt_wait_lst,
665  CCLErr** err) {
666 
667  /* Make sure cq is not NULL. */
668  g_return_val_if_fail(cq != NULL, NULL);
669  /* Make sure src_img is not NULL. */
670  g_return_val_if_fail(src_img != NULL, NULL);
671  /* Make sure dst_img is not NULL. */
672  g_return_val_if_fail(dst_img != NULL, NULL);
673  /* Make sure err is NULL or it is not set. */
674  g_return_val_if_fail(err == NULL || *err == NULL, NULL);
675 
676  /* OpenCL function status. */
677  cl_int ocl_status;
678  /* OpenCL event object. */
679  cl_event event = NULL;
680  /* Event wrapper object. */
681  CCLEvent* evt = NULL;
682 
683  /* Copy image. */
684  ocl_status = clEnqueueCopyImage(ccl_queue_unwrap(cq),
685  ccl_memobj_unwrap(src_img), ccl_memobj_unwrap(dst_img),
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));
693 
694  /* Wrap event and associate it with the respective command queue.
695  * The event object will be released automatically when the command
696  * queue is released. */
697  evt = ccl_queue_produce_event(cq, event);
698 
699  /* Clear event wait list. */
700  ccl_event_wait_list_clear(evt_wait_lst);
701 
702  /* If we got here, everything is OK. */
703  g_assert(err == NULL || *err == NULL);
704  goto finish;
705 
706 error_handler:
707  /* If we got here there was an error, verify that it is so. */
708  g_assert(err == NULL || *err != NULL);
709 
710  /* An error occurred, return NULL to signal it. */
711  evt = NULL;
712 
713 finish:
714 
715  /* Return event. */
716  return evt;
717 
718 }
719 
749 CCL_EXPORT
751  CCLBuffer* dst_buf, CCLQueue* cq, const size_t *src_origin,
752  const size_t *region, size_t dst_offset,
753  CCLEventWaitList* evt_wait_lst, CCLErr** err) {
754 
755  /* Make sure cq is not NULL. */
756  g_return_val_if_fail(cq != NULL, NULL);
757  /* Make sure src_img is not NULL. */
758  g_return_val_if_fail(src_img != NULL, NULL);
759  /* Make sure dst_buf is not NULL. */
760  g_return_val_if_fail(dst_buf != NULL, NULL);
761  /* Make sure err is NULL or it is not set. */
762  g_return_val_if_fail(err == NULL || *err == NULL, NULL);
763 
764  /* OpenCL function status. */
765  cl_int ocl_status;
766  /* OpenCL event object. */
767  cl_event event = NULL;
768  /* Event wrapper object. */
769  CCLEvent* evt = NULL;
770 
771  /* Copy image to buffer. */
772  ocl_status = clEnqueueCopyImageToBuffer(ccl_queue_unwrap(cq),
773  ccl_memobj_unwrap(src_img), ccl_memobj_unwrap(dst_buf),
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));
781 
782  /* Wrap event and associate it with the respective command queue.
783  * The event object will be released automatically when the command
784  * queue is released. */
785  evt = ccl_queue_produce_event(cq, event);
786 
787  /* Clear event wait list. */
788  ccl_event_wait_list_clear(evt_wait_lst);
789 
790  /* If we got here, everything is OK. */
791  g_assert(err == NULL || *err == NULL);
792  goto finish;
793 
794 error_handler:
795  /* If we got here there was an error, verify that it is so. */
796  g_assert(err == NULL || *err != NULL);
797 
798  /* An error occurred, return NULL to signal it. */
799  evt = NULL;
800 
801 finish:
802 
803  /* Return event. */
804  return evt;
805 
806 }
807 
847 CCL_EXPORT
849  cl_bool blocking_map, cl_map_flags map_flags, const size_t* origin,
850  const size_t* region, size_t *image_row_pitch,
851  size_t *image_slice_pitch, CCLEventWaitList* evt_wait_lst,
852  CCLEvent** evt, CCLErr** err) {
853 
854  /* Make sure cq is not NULL. */
855  g_return_val_if_fail(cq != NULL, NULL);
856  /* Make sure img is not NULL. */
857  g_return_val_if_fail(img != NULL, NULL);
858  /* Make sure err is NULL or it is not set. */
859  g_return_val_if_fail(err == NULL || *err == NULL, NULL);
860 
861  cl_int ocl_status;
862  cl_event event = NULL;
863  CCLEvent* evt_inner = NULL;
864  void* ptr = NULL;
865 
866  /* Perform image map. */
867  ptr = clEnqueueMapImage(ccl_queue_unwrap(cq),
868  ccl_memobj_unwrap(img), blocking_map, map_flags,
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));
877 
878  /* Wrap event and associate it with the respective command queue.
879  * The event object will be released automatically when the command
880  * queue is released. */
881  evt_inner = ccl_queue_produce_event(cq, event);
882  if (evt != NULL)
883  *evt = evt_inner;
884 
885  /* Clear event wait list. */
886  ccl_event_wait_list_clear(evt_wait_lst);
887 
888  /* If we got here, everything is OK. */
889  g_assert(err == NULL || *err == NULL);
890  goto finish;
891 
892 error_handler:
893  /* If we got here there was an error, verify that it is so. */
894  g_assert(err == NULL || *err != NULL);
895 
896  /* An error occurred, return NULL to signal it. */
897  ptr = NULL;
898 
899 finish:
900 
901  /* Return host pointer. */
902  return ptr;
903 
904 }
905 
933 CCL_EXPORT
935  const void *fill_color, const size_t *origin, const size_t *region,
936  CCLEventWaitList* evt_wait_lst, CCLErr** err) {
937 
938  /* Make sure cq is not NULL. */
939  g_return_val_if_fail(cq != NULL, NULL);
940  /* Make sure img is not NULL. */
941  g_return_val_if_fail(img != NULL, NULL);
942  /* Make sure err is NULL or it is not set. */
943  g_return_val_if_fail(err == NULL || *err == NULL, NULL);
944 
945  /* OpenCL function status. */
946  cl_int ocl_status;
947  /* OpenCL event object. */
948  cl_event event = NULL;
949  /* Event wrapper object. */
950  CCLEvent* evt = NULL;
951  /* OpenCL version of the underlying platform. */
952  double ocl_ver;
953  /* Internal error handling object. */
954  CCLErr* err_internal = NULL;
955 
956 #ifndef CL_VERSION_1_2
957 
958  CCL_UNUSED(fill_color);
959  CCL_UNUSED(origin);
960  CCL_UNUSED(region);
961  CCL_UNUSED(evt_wait_lst);
962  CCL_UNUSED(ocl_status);
963  CCL_UNUSED(event);
964  CCL_UNUSED(ocl_ver);
965  CCL_UNUSED(err_internal);
966 
967  /* If cf4ocl was not compiled with support for OpenCL >= 1.2, always throw
968  * error. */
969  ccl_if_err_create_goto(*err, CCL_ERROR, TRUE,
970  CCL_ERROR_UNSUPPORTED_OCL, error_handler,
971  "%s: Image fill requires cf4ocl to be deployed with "
972  "support for OpenCL version 1.2 or newer.",
973  CCL_STRD);
974 
975 #else
976 
977  /* Check that context platform is >= OpenCL 1.2 */
979  (CCLMemObj*) img, &err_internal);
980  ccl_if_err_propagate_goto(err, err_internal, error_handler);
981 
982  /* If OpenCL version is not >= 1.2, throw error. */
983  ccl_if_err_create_goto(*err, CCL_ERROR, ocl_ver < 120,
984  CCL_ERROR_UNSUPPORTED_OCL, error_handler,
985  "%s: Image fill requires OpenCL version 1.2 or newer.",
986  CCL_STRD);
987 
988  /* Fill image. */
989  ocl_status = clEnqueueFillImage(ccl_queue_unwrap(cq),
990  ccl_memobj_unwrap(img), fill_color, origin, region,
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));
997 
998  /* Wrap event and associate it with the respective command queue.
999  * The event object will be released automatically when the command
1000  * queue is released. */
1001  evt = ccl_queue_produce_event(cq, event);
1002 
1003  /* Clear event wait list. */
1004  ccl_event_wait_list_clear(evt_wait_lst);
1005 
1006 #endif
1007 
1008  /* If we got here, everything is OK. */
1009  g_assert(err == NULL || *err == NULL);
1010  goto finish;
1011 
1012 error_handler:
1013  /* If we got here there was an error, verify that it is so. */
1014  g_assert(err == NULL || *err != NULL);
1015 
1016  /* An error occurred, return NULL to signal it. */
1017  evt = NULL;
1018 
1019 finish:
1020 
1021  /* Return event. */
1022  return evt;
1023 
1024 }
1025 
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...
Definition: ccl_common.h:324
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.
Image wrapper class.
#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...
Definition: _ccl_defs.h:91
#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.
Buffer wrapper class.
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...
Definition: _ccl_defs.h:120
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.
Definition: ccl_errors.c:118
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.
Image object.
Definition: ccl_common.h:102
#define CCL_ERROR
Resolves to error category identifying string, in this case an error in cf4ocl.
Definition: ccl_common.h:320
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.
Event wrapper class.
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.
Definition: ccl_common.h:86
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.
Definition: ccl_common.h:302
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.
Definition: ccl_common.h:291
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.
Definition: ccl_common.h:311
cl_uint num_samples
Unused up to OpenCL 2.0.
CCLMemObj * memobj
A memory object wrapper.