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_arg.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_kernel_arg.h"
31 #include "_ccl_abstract_wrapper.h"
32 
41 #define ccl_arg_is_local(arg) \
42  (arg->info == (void*) &arg_local_marker)
43 
49 static char arg_local_marker;
50 
57 static const CCLArg arg_skip = { CCL_NONE, NULL, NULL, 0 };
58 
59 /* Use this constant to skip kernel arguments in ::ccl_kernel_set_args()
60  * and ::ccl_kernel_set_args_v() functions. */
61 CCL_EXPORT
62 const CCLArg* ccl_arg_skip = &arg_skip;
63 
75 CCL_EXPORT
76 CCLArg* ccl_arg_new(void* value, size_t size) {
77 
78  /* Make sure size is > 0. */
79  g_return_val_if_fail(size > 0, NULL);
80 
81  CCLArg* arg = g_slice_new(CCLArg);
82 
83  arg->cl_object = g_memdup((const void*) value, (guint) size);
84  arg->info = (void*) &arg_local_marker;
85  arg->ref_count = (gint) size;
86 
87  return arg;
88 
89 }
90 
99 CCL_EXPORT
100 void ccl_arg_destroy(CCLArg* arg) {
101 
102  /* Make sure arg is not NULL. */
103  g_return_if_fail(arg != NULL);
104 
105  if ccl_arg_is_local(arg) {
106  g_free(arg->cl_object);
107  g_slice_free(CCLArg, arg);
108  }
109 }
110 
120 CCL_EXPORT
121 size_t ccl_arg_size(CCLArg* arg) {
122 
123  /* Make sure arg is not NULL. */
124  g_return_val_if_fail(arg != NULL, 0);
125 
126  return ccl_arg_is_local(arg)
127  ? (size_t) arg->ref_count
128  : sizeof(void*);
129 }
130 
140 CCL_EXPORT
141 void* ccl_arg_value(CCLArg* arg) {
142 
143  /* Make sure arg is not NULL. */
144  g_return_val_if_fail(arg != NULL, NULL);
145 
146  return ccl_arg_is_local(arg)
147  ? arg->cl_object
148  : &arg->cl_object;
149 }
CCLArg * ccl_arg_new(void *value, size_t size)
Create a new kernel argument.
const CCLArg * ccl_arg_skip
Use this constant to skip kernel arguments in the ccl_kernel_set_args(), ccl_kernel_set_args_v(), ccl_kernel_set_args_and_enqueue_ndrange() and ccl_kernel_set_args_and_enqueue_ndrange_v() functions.
Base class for all OpenCL wrappers.
No object, enumeration termination marker.
Definition: ccl_common.h:114
Definition of a wrapper type and related functions for a OpenCL kernel arguments. ...