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.h
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 #ifndef _CCL_IMAGE_WRAPPER_H_
31 #define _CCL_IMAGE_WRAPPER_H_
32 
33 #include "ccl_memobj_wrapper.h"
34 
120 #define CCL_IMAGE_DESC_BLANK {0, 0, 0, 0, 0, 0, 0, 0, 0, NULL}
121 
127 typedef struct ccl_image_desc {
128 
135  cl_mem_object_type image_type;
136 
141  size_t image_width;
142 
148  size_t image_height;
149 
154  size_t image_depth;
155 
161  size_t image_array_size;
162 
167  size_t image_row_pitch;
168 
175  size_t image_slice_pitch;
176 
181  cl_uint num_mip_levels;
182 
187  cl_uint num_samples;
188 
197  CCLMemObj* memobj;
198 
199 } CCLImageDesc;
200 
201 /* Get the image wrapper for the given OpenCL image. */
202 CCL_EXPORT
203 CCLImage* ccl_image_new_wrap(cl_mem mem_object);
204 
205 /* Decrements the reference count of the wrapper object. If it
206  * reaches 0, the wrapper object is destroyed. */
207 CCL_EXPORT
208 void ccl_image_destroy(CCLImage* img);
209 
210 /* Creates a new image wrapper object. */
211 CCL_EXPORT
212 CCLImage* ccl_image_new_v(CCLContext* ctx, cl_mem_flags flags,
213  const cl_image_format* image_format, const CCLImageDesc* img_dsc,
214  void* host_ptr, CCLErr** err);
215 
216 /* Creates a new image wrapper object using a variable list of key-value
217  * pairs which describe the image. */
218 CCL_EXPORT
219 CCLImage* ccl_image_new(CCLContext* ctx, cl_mem_flags flags,
220  const cl_image_format* image_format, void* host_ptr, CCLErr** err,
221  ...);
222 
223 /* Read from an image or image array object to host memory. */
224 CCL_EXPORT
226  cl_bool blocking_read, const size_t* origin, const size_t* region,
227  size_t row_pitch, size_t slice_pitch, void *ptr,
228  CCLEventWaitList* evt_wait_lst, CCLErr** err);
229 
230 /* Write to an image or image array object from host memory. */
231 CCL_EXPORT
233  cl_bool blocking_read, const size_t* origin, const size_t* region,
234  size_t input_row_pitch, size_t input_slice_pitch, void *ptr,
235  CCLEventWaitList* evt_wait_lst, CCLErr** err);
236 
237 /* Copy image objects. This function wraps the clEnqueueCopyImage()
238  * OpenCL function. */
239 CCL_EXPORT
241  CCLQueue* cq, const size_t* src_origin, const size_t* dst_origin,
242  const size_t* region, CCLEventWaitList* evt_wait_lst, CCLErr** err);
243 
244 /* Copy an image object to a buffer object. */
245 CCL_EXPORT
247  CCLBuffer* dst_buf, CCLQueue* cq, const size_t *src_origin,
248  const size_t *region, size_t dst_offset,
249  CCLEventWaitList* evt_wait_lst, CCLErr** err);
250 
251 /* Map a region of the image into the host address space and return a
252  * pointer to this mapped region. */
253 CCL_EXPORT
254 void* ccl_image_enqueue_map(CCLImage* img, CCLQueue* cq,
255  cl_bool blocking_map, cl_map_flags map_flags, const size_t* origin,
256  const size_t* region, size_t *image_row_pitch,
257  size_t *image_slice_pitch, CCLEventWaitList* evt_wait_lst,
258  CCLEvent** evt, CCLErr** err);
259 
260 /* Fill an image object with a specified color. This function wraps the
261  * clEnqueueFillImage() OpenCL function. */
262 CCL_EXPORT
264  const void *fill_color, const size_t *origin, const size_t *region,
265  CCLEventWaitList* evt_wait_lst, CCLErr** err);
266 
283 #define ccl_image_enqueue_unmap(img, cq, ptr, ewl, err) \
284  ccl_memobj_enqueue_unmap((CCLMemObj*) img, cq, ptr, ewl, err)
285 
297 #define ccl_image_get_info(img, param_name, err) \
298  ccl_wrapper_get_info((CCLWrapper*) img, NULL, param_name, 0, \
299  CCL_INFO_IMAGE, CL_FALSE, err)
300 
317 #define ccl_image_get_info_scalar(img, param_name, param_type, err) \
318  *((param_type*) ccl_wrapper_get_info_value((CCLWrapper*) img, \
319  NULL, param_name, sizeof(param_type), CCL_INFO_IMAGE, CL_FALSE, err))
320 
337 #define ccl_image_get_info_array(img, param_name, param_type, err) \
338  (param_type) ccl_wrapper_get_info_value((CCLWrapper*) img, \
339  NULL, param_name, sizeof(param_type), CCL_INFO_IMAGE, CL_FALSE, err)
340 
346 #define ccl_image_ref(img) \
347  ccl_wrapper_ref((CCLWrapper*) img)
348 
355 #define ccl_image_unref(img) ccl_image_destroy(img)
356 
363 #define ccl_image_unwrap(img) \
364  ((cl_mem) ccl_wrapper_unwrap((CCLWrapper*) img))
365 
368 #endif
369 
370 
371 
372 
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.
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.
GPtrArray * CCLEventWaitList
A list of event objects on which enqueued commands can wait.
Buffer wrapper class.
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.
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.
Command queue wrapper class.
Describes the type and dimensions of the image or image array independently of the OpenCL version...
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.
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...
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...
struct ccl_image_desc CCLImageDesc
Describes the type and dimensions of the image or image array independently of the OpenCL version...
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.
Definition of a wrapper class and its methods for OpenCL memory objects.
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.
cl_uint num_samples
Unused up to OpenCL 2.0.
CCLMemObj * memobj
A memory object wrapper.