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_kernel_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_KERNEL_WRAPPER_H_
31 #define _CCL_KERNEL_WRAPPER_H_
32 
33 #include <glib.h>
34 #include "ccl_oclversions.h"
35 #include "ccl_abstract_wrapper.h"
36 #include "ccl_kernel_arg.h"
37 #include "ccl_event_wrapper.h"
38 #include "ccl_queue_wrapper.h"
39 #include "ccl_memobj_wrapper.h"
40 
114 /* Get the kernel wrapper for the given OpenCL kernel. */
115 CCL_EXPORT
116 CCLKernel* ccl_kernel_new_wrap(cl_kernel kernel);
117 
118 /* Create a new kernel wrapper object. */
119 CCL_EXPORT
121  CCLProgram* prg, const char* kernel_name, CCLErr** err);
122 
123 /* Decrements the reference count of the kernel wrapper object.
124  * If it reaches 0, the kernel wrapper object is destroyed. */
125 CCL_EXPORT
126 void ccl_kernel_destroy(CCLKernel* krnl);
127 
128 /* Set one kernel argument. */
129 CCL_EXPORT
130 void ccl_kernel_set_arg(CCLKernel* krnl, cl_uint arg_index, void* arg);
131 
132 /* Set all kernel arguments. This function accepts a variable list of
133  * arguments which must end with `NULL`. */
134 CCL_EXPORT
135 void ccl_kernel_set_args(CCLKernel* krnl, ...) G_GNUC_NULL_TERMINATED;
136 
137 /* Set all kernel arguments. This function accepts a `NULL`-terminated
138  * array of kernel arguments. */
139 CCL_EXPORT
140 void ccl_kernel_set_args_v(CCLKernel* krnl, void** args);
141 
142 /* Enqueues a kernel for execution on a device. */
143 CCL_EXPORT
145  cl_uint work_dim, const size_t* global_work_offset,
146  const size_t* global_work_size, const size_t* local_work_size,
147  CCLEventWaitList* evt_wait_lst, CCLErr** err);
148 
149 /* Set kernel arguments and enqueue it for execution. */
150 CCL_EXPORT
152  CCLQueue* cq, cl_uint work_dim, const size_t* global_work_offset,
153  const size_t* global_work_size, const size_t* local_work_size,
154  CCLEventWaitList* evt_wait_lst, CCLErr** err, ...)
155  G_GNUC_NULL_TERMINATED;
156 
157 /* Set kernel arguments and enqueue it for execution. */
158 CCL_EXPORT
160  CCLQueue* cq, cl_uint work_dim, const size_t* global_work_offset,
161  const size_t* global_work_size, const size_t* local_work_size,
162  CCLEventWaitList* evt_wait_lst, void** args, CCLErr** err);
163 
164 /* Enqueues a command to execute a native C/C++ function not compiled
165  * using the OpenCL compiler. */
166 CCL_EXPORT
168  void (CL_CALLBACK * user_func)(void*), void* args, size_t cb_args,
169  cl_uint num_mos, CCLMemObj* const* mo_list,
170  const void** args_mem_loc, CCLEventWaitList* evt_wait_lst,
171  CCLErr** err);
172 
173 /* Get the OpenCL version of the platform associated with this
174  * kernel. */
175 CCL_EXPORT
176 cl_uint ccl_kernel_get_opencl_version(CCLKernel* krnl, CCLErr** err);
177 
178 /* Suggest appropriate global and local worksizes for the given real
179  * work size, based on device and kernel characteristics. */
180 CCL_EXPORT
182  cl_uint dims, const size_t* real_worksize, size_t* gws, size_t* lws,
183  CCLErr** err);
184 
196 #define ccl_kernel_get_info(krnl, param_name, err) \
197  ccl_wrapper_get_info((CCLWrapper*) (krnl), NULL, (param_name), 0, \
198  CCL_INFO_KERNEL, CL_FALSE, (err))
199 
216 #define ccl_kernel_get_info_scalar(krnl, param_name, param_type, err) \
217  *((param_type*) ccl_wrapper_get_info_value((CCLWrapper*) (krnl), \
218  NULL, (param_name), sizeof(param_type), \
219  CCL_INFO_KERNEL, CL_FALSE, (err)))
220 
237 #define ccl_kernel_get_info_array(krnl, param_name, param_type, err) \
238  (param_type) ccl_wrapper_get_info_value((CCLWrapper*) (krnl), \
239  NULL, (param_name), sizeof(param_type), \
240  CCL_INFO_KERNEL, CL_FALSE, (err))
241 
254 #define ccl_kernel_get_workgroup_info(krnl, dev, param_name, err) \
255  ccl_wrapper_get_info((CCLWrapper*) (krnl), (CCLWrapper*) (dev), \
256  (param_name), 0, CCL_INFO_KERNEL_WORKGROUP, CL_FALSE, (err))
257 
276 #define ccl_kernel_get_workgroup_info_scalar(krnl, dev, param_name, \
277  param_type, err) \
278  *((param_type*) ccl_wrapper_get_info_value((CCLWrapper*) (krnl), \
279  (CCLWrapper*) (dev), (param_name), sizeof(param_type), \
280  CCL_INFO_KERNEL_WORKGROUP, CL_FALSE, (err)))
281 
300 #define ccl_kernel_get_workgroup_info_array(krnl, dev, param_name, \
301  param_type, err) \
302  (param_type) ccl_wrapper_get_info_value((CCLWrapper*) (krnl), \
303  (CCLWrapper*) (dev), (param_name), sizeof(param_type), \
304  CCL_INFO_KERNEL_WORKGROUP, CL_FALSE, (err))
305 
306 /* Get a ::CCLWrapperInfo kernel argument information object. */
307 CCL_EXPORT
309  cl_kernel_arg_info param_name, CCLErr** err);
310 
329 #define ccl_kernel_get_arg_info_scalar(krnl, idx, param_name, \
330  param_type, err) \
331  (param_type) \
332  ((ccl_kernel_get_arg_info((krnl), (idx), (param_name), (err)) != NULL) \
333  ? **((param_type**) ccl_kernel_get_arg_info( \
334  (krnl), (idx), (param_name), (err))) \
335  : 0)
336 
355 #define ccl_kernel_get_arg_info_array(krnl, idx, param_name, \
356  param_type, err) \
357  (ccl_kernel_get_arg_info((krnl), (idx), (param_name), (err)) != NULL) \
358  ? *((param_type*) ccl_kernel_get_arg_info( \
359  (krnl), (idx), (param_name), (err))) \
360  : NULL
361 
367 #define ccl_kernel_ref(krnl) \
368  ccl_wrapper_ref((CCLWrapper*) (krnl))
369 
376 #define ccl_kernel_unref(krnl) ccl_kernel_destroy(krnl)
377 
384 #define ccl_kernel_unwrap(krnl) \
385  ((cl_kernel) ccl_wrapper_unwrap((CCLWrapper*) (krnl)))
386 
387 
390 #endif
391 
void ccl_kernel_destroy(CCLKernel *krnl)
Decrements the reference count of the kernel wrapper object.
CCLEvent * ccl_kernel_set_args_and_enqueue_ndrange_v(CCLKernel *krnl, CCLQueue *cq, cl_uint work_dim, const size_t *global_work_offset, const size_t *global_work_size, const size_t *local_work_size, CCLEventWaitList *evt_wait_lst, void **args, CCLErr **err)
Set kernel arguments and enqueue it for execution on a device.
GPtrArray * CCLEventWaitList
A list of event objects on which enqueued commands can wait.
Definition of a wrapper class and its methods for OpenCL event objects.
CCLWrapperInfo * ccl_kernel_get_arg_info(CCLKernel *krnl, cl_uint idx, cl_kernel_arg_info param_name, CCLErr **err)
Get a CCLWrapperInfo kernel argument information object.
cl_uint ccl_kernel_get_opencl_version(CCLKernel *krnl, CCLErr **err)
Get the OpenCL version of the platform associated with this kernel.
Base class for memory object wrappers, i.e., CCLBuffer and CCLImage.
Command queue wrapper class.
void ccl_kernel_set_args(CCLKernel *krnl,...)
Set all kernel arguments.
cl_bool ccl_kernel_suggest_worksizes(CCLKernel *krnl, CCLDevice *dev, cl_uint dims, const size_t *real_worksize, size_t *gws, size_t *lws, CCLErr **err)
Suggest appropriate local (and optionally global) work sizes for the given real work size...
Event wrapper class.
Definition of a wrapper type and related functions for a OpenCL kernel arguments. ...
Definition of an abstract wrapper class and its methods for OpenCL objects.
CCLEvent * ccl_kernel_enqueue_native(CCLQueue *cq, void(*user_func)(void *), void *args, size_t cb_args, cl_uint num_mos, CCLMemObj *const *mo_list, const void **args_mem_loc, CCLEventWaitList *evt_wait_lst, CCLErr **err)
Enqueues a command to execute a native C/C++ function not compiled using the OpenCL compiler...
CCLKernel * ccl_kernel_new_wrap(cl_kernel kernel)
Get the kernel wrapper for the given OpenCL kernel.
Header for normalizing OpenCL versions within cf4ocl.
Program wrapper class.
CCLEvent * ccl_kernel_enqueue_ndrange(CCLKernel *krnl, CCLQueue *cq, cl_uint work_dim, const size_t *global_work_offset, const size_t *global_work_size, const size_t *local_work_size, CCLEventWaitList *evt_wait_lst, CCLErr **err)
Enqueues a kernel for execution on a device.
Kernel wrapper class.
Class which represents information about a wrapped OpenCL object.
void ccl_kernel_set_arg(CCLKernel *krnl, cl_uint arg_index, void *arg)
Set one kernel argument.
GError CCLErr
Error handling class.
Definition: ccl_common.h:291
void ccl_kernel_set_args_v(CCLKernel *krnl, void **args)
Set all kernel arguments.
Definition of a wrapper class and its methods for OpenCL memory objects.
Device wrapper class.
Definition of a wrapper class and its methods for OpenCL queue objects.
CCLKernel * ccl_kernel_new(CCLProgram *prg, const char *kernel_name, CCLErr **err)
Create a new kernel wrapper object.
CCLEvent * ccl_kernel_set_args_and_enqueue_ndrange(CCLKernel *krnl, CCLQueue *cq, cl_uint work_dim, const size_t *global_work_offset, const size_t *global_work_size, const size_t *local_work_size, CCLEventWaitList *evt_wait_lst, CCLErr **err,...)
Set kernel arguments and enqueue it for execution on a device.