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_buffer_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_BUFFER_WRAPPER_H_
31 #define _CCL_BUFFER_WRAPPER_H_
32 
33 #include "ccl_memobj_wrapper.h"
34 
92 /* Get the buffer wrapper for the given OpenCL buffer. */
93 CCL_EXPORT
94 CCLBuffer* ccl_buffer_new_wrap(cl_mem mem_object);
95 
96 /* Create a ::CCLBuffer wrapper object. */
97 CCL_EXPORT
98 CCLBuffer* ccl_buffer_new(CCLContext* ctx, cl_mem_flags flags,
99  size_t size, void *host_ptr, CCLErr** err);
100 
101 /* Decrements the reference count of the wrapper object. If it
102  * reaches 0, the wrapper object is destroyed. */
103 CCL_EXPORT
104 void ccl_buffer_destroy(CCLBuffer* buf);
105 
106 /* Read from a buffer object to host memory. */
107 CCL_EXPORT
109  cl_bool blocking_read, size_t offset, size_t size, void *ptr,
110  CCLEventWaitList* evt_wait_lst, CCLErr** err);
111 
112 /* Write to a buffer object from host memory. */
113 CCL_EXPORT
115  cl_bool blocking_write, size_t offset, size_t size, void *ptr,
116  CCLEventWaitList* evt_wait_lst, CCLErr** err);
117 
118 /* Map a region of the buffer object given by buffer into the host
119  * address space and returns a pointer to this mapped region. */
120 CCL_EXPORT
122  cl_bool blocking_map, cl_map_flags map_flags, size_t offset,
123  size_t size, CCLEventWaitList* evt_wait_lst, CCLEvent** evt,
124  CCLErr** err);
125 
126 /* Copy from one buffer object to another. */
127 CCL_EXPORT
129  CCLBuffer* dst_buf, CCLQueue* cq, size_t src_offset,
130  size_t dst_offset, size_t size, CCLEventWaitList* evt_wait_lst,
131  CCLErr** err);
132 
133 /* Copy a buffer object to an image object. This function wraps the
134  * clEnqueueCopyBufferToImage() OpenCL function. */
135 CCL_EXPORT
137  CCLImage* dst_img, CCLQueue* cq, size_t src_offset,
138  const size_t *dst_origin, const size_t *region,
139  CCLEventWaitList* evt_wait_lst, CCLErr** err);
140 
141 /* Creates a sub-buffer that represents a specific region in the given
142  * buffer. */
143 CCL_EXPORT
145  cl_mem_flags flags, size_t origin, size_t size, CCLErr** err);
146 
147 /* Read from a 2D or 3D rectangular region from a buffer object to host
148  * memory. */
149 CCL_EXPORT
151  cl_bool blocking_read, const size_t* buffer_origin,
152  const size_t* host_origin, const size_t* region,
153  size_t buffer_row_pitch, size_t buffer_slice_pitch,
154  size_t host_row_pitch, size_t host_slice_pitch, void *ptr,
155  CCLEventWaitList* evt_wait_lst, CCLErr** err);
156 
157 /* Write a 2D or 3D rectangular region to a buffer object from host
158  * memory. */
159 CCL_EXPORT
161  cl_bool blocking_write, const size_t* buffer_origin,
162  const size_t* host_origin, const size_t* region,
163  size_t buffer_row_pitch, size_t buffer_slice_pitch,
164  size_t host_row_pitch, size_t host_slice_pitch, void *ptr,
165  CCLEventWaitList* evt_wait_lst, CCLErr** err);
166 
167 /* Copy a 2D or 3D rectangular region from a buffer object to another
168  * buffer object. */
169 CCL_EXPORT
171  CCLBuffer* dst_buf, CCLQueue* cq, const size_t *src_origin,
172  const size_t *dst_origin, const size_t *region,
173  size_t src_row_pitch, size_t src_slice_pitch, size_t dst_row_pitch,
174  size_t dst_slice_pitch, CCLEventWaitList* evt_wait_lst,
175  CCLErr** err);
176 
177 /* Fill a buffer object with a pattern of a given pattern size. */
178 CCL_EXPORT
180  const void *pattern, size_t pattern_size, size_t offset,
181  size_t size, CCLEventWaitList* evt_wait_lst, CCLErr** err);
182 
199 #define ccl_buffer_enqueue_unmap(buf, cq, ptr, ewl, err) \
200  ccl_memobj_enqueue_unmap((CCLMemObj*) buf, cq, ptr, ewl, err)
201 
207 #define ccl_buffer_ref(buf) \
208  ccl_wrapper_ref((CCLWrapper*) buf)
209 
215 #define ccl_buffer_unref(buf) ccl_buffer_destroy(buf)
216 
223 #define ccl_buffer_unwrap(buf) \
224  ((cl_mem) ccl_wrapper_unwrap((CCLWrapper*) buf))
225 
228 #endif
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.
Image wrapper class.
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.
GPtrArray * CCLEventWaitList
A list of event objects on which enqueued commands can wait.
Buffer wrapper class.
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.
Command queue wrapper class.
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.
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.
Event wrapper class.
CCLBuffer * ccl_buffer_new_wrap(cl_mem mem_object)
Get the buffer wrapper for the given OpenCL buffer.
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.
Definition of a wrapper class and its methods for OpenCL memory objects.
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.
Definition: ccl_common.h:291
CCLBuffer * ccl_buffer_new(CCLContext *ctx, cl_mem_flags flags, size_t size, void *host_ptr, CCLErr **err)
Create a CCLBuffer wrapper object.