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_context_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 
29 #ifndef _CCL_CONTEXT_WRAPPER_H_
30 #define _CCL_CONTEXT_WRAPPER_H_
31 
32 #include "ccl_oclversions.h"
33 #include "ccl_device_selector.h"
34 #include "ccl_common.h"
35 #include "ccl_errors.h"
36 #include "ccl_device_wrapper.h"
37 #include "ccl_platform_wrapper.h"
38 
125 typedef void (CL_CALLBACK* ccl_context_callback)(
126  const char* errinfo, const void* private_info, size_t cb,
127  void* user_data);
128 
129 /* Get the context wrapper for the given OpenCL context. */
130 CCL_EXPORT
131 CCLContext* ccl_context_new_wrap(cl_context context);
132 
142 #define ccl_context_new_from_filters(filters, err) \
143  ccl_context_new_from_filters_full( \
144  NULL, (filters), NULL, NULL, (err))
145 
158 #define ccl_context_new_from_devices(num_devices, devices, err) \
159  ccl_context_new_from_devices_full( \
160  NULL, (num_devices), (devices), NULL, NULL, (err))
161 
172 #define ccl_context_new_cpu(err) \
173  ccl_context_new_from_indep_filter( \
174  ccl_devsel_indep_type_cpu, NULL, (err))
175 
186 #define ccl_context_new_gpu(err) \
187  ccl_context_new_from_indep_filter( \
188  ccl_devsel_indep_type_gpu, NULL, (err))
189 
200 #define ccl_context_new_accel(err) \
201  ccl_context_new_from_indep_filter( \
202  ccl_devsel_indep_type_accel, NULL, (err))
203 
214 #define ccl_context_new_any(err) \
215  ccl_context_new_from_indep_filter(NULL, NULL, (err))
216 
232 #define ccl_context_new_from_indep_filter(filter, data, err) \
233  ccl_context_new_from_filter(CCL_DEVSEL_INDEP, (filter), (data), (err))
234 
251 #define ccl_context_new_from_dep_filter(filter, data, err) \
252  ccl_context_new_from_filter(CCL_DEVSEL_DEP, (filter), (data), (err))
253 
265 #define ccl_context_new_from_device_index(data, err) \
266  ccl_context_new_from_dep_filter(ccl_devsel_dep_index, (data), (err))
267 
277 #define ccl_context_new_from_menu_full(data, err) \
278  ccl_context_new_from_dep_filter(ccl_devsel_dep_menu, (data), (err))
279 
287 #define ccl_context_new_from_menu(err) \
288  ccl_context_new_from_dep_filter(ccl_devsel_dep_menu, NULL, (err))
289 
290 /* Create a new context wrapper object selecting devices using the given set of
291  * filters. */
292 CCL_EXPORT
294  const cl_context_properties* properties, CCLDevSelFilters* filters,
295  ccl_context_callback pfn_notify, void* user_data, CCLErr **err);
296 
297 /* Creates a context wrapper given an array of ::CCLDevice wrappers and the
298  * remaining parameters required by the clCreateContext() function. */
299 CCL_EXPORT
301  const cl_context_properties* properties, cl_uint num_devices,
302  CCLDevice* const* devices, ccl_context_callback pfn_notify,
303  void* user_data, CCLErr** err);
304 
305 /* Creates a context wrapper using one device filter specified in the function
306  * parameters. */
307 CCL_EXPORT
309  void* filter, void* data, CCLErr** err);
310 
311 /* Decrements the reference count of the context wrapper object.
312  * If it reaches 0, the context wrapper object is destroyed. */
313 CCL_EXPORT
315 
316 /* Get the OpenCL version of the platform associated with this context. */
317 CCL_EXPORT
319 
320 /* Get the platform associated with the context devices. */
321 CCL_EXPORT
323 
324 /* Get the list of image formats supported by a given context. */
325 CCL_EXPORT
326 const cl_image_format* ccl_context_get_supported_image_formats(
327  CCLContext* ctx, cl_mem_flags flags, cl_mem_object_type image_type,
328  cl_uint* num_image_formats, CCLErr** err);
329 
330 /* Get ::CCLDevice wrapper at given index. */
331 CCL_EXPORT
333  CCLContext* ctx, cl_uint index, CCLErr** err);
334 
335 /* Return number of devices in context. */
336 CCL_EXPORT
337 cl_uint ccl_context_get_num_devices(CCLContext* ctx, CCLErr** err);
338 
339 /* Get all device wrappers in context. */
340 CCL_EXPORT
342  CCLErr** err);
343 
355 #define ccl_context_get_info(ctx, param_name, err) \
356  ccl_wrapper_get_info((CCLWrapper*) ctx, NULL, param_name, 0, \
357  CCL_INFO_CONTEXT, CL_FALSE, err)
358 
375 #define ccl_context_get_info_scalar(ctx, param_name, param_type, err) \
376  *((param_type*) ccl_wrapper_get_info_value((CCLWrapper*) ctx, \
377  NULL, param_name, sizeof(param_type), \
378  CCL_INFO_CONTEXT, CL_FALSE, err))
379 
396 #define ccl_context_get_info_array(ctx, param_name, param_type, err) \
397  (param_type) ccl_wrapper_get_info_value((CCLWrapper*) ctx, \
398  NULL, param_name, sizeof(param_type), \
399  CCL_INFO_CONTEXT, CL_FALSE, err)
400 
405 #define ccl_context_ref(ctx) \
406  ccl_wrapper_ref((CCLWrapper*) ctx)
407 
414 #define ccl_context_unref(ctx) \
415  ccl_context_destroy(ctx)
416 
423 #define ccl_context_unwrap(ctx) \
424  ((cl_context) ccl_wrapper_unwrap((CCLWrapper*) ctx))
425 
428 #endif
void ccl_context_destroy(CCLContext *ctx)
Decrements the reference count of the context wrapper object.
Classes and functions for filtering and selecting OpenCL contexts and associated devices.
CCLDevice *const * ccl_context_get_all_devices(CCLContext *ctx, CCLErr **err)
Get all device wrappers in context.
CCLPlatform * ccl_context_get_platform(CCLContext *ctx, CCLErr **err)
Get the platform associated with the context devices.
const cl_image_format * ccl_context_get_supported_image_formats(CCLContext *ctx, cl_mem_flags flags, cl_mem_object_type image_type, cl_uint *num_image_formats, CCLErr **err)
Get the list of image formats supported by a given context.
CCLContext * ccl_context_new_from_devices_full(const cl_context_properties *properties, cl_uint num_devices, CCLDevice *const *devices, ccl_context_callback pfn_notify, void *user_data, CCLErr **err)
Creates a context wrapper given an array of CCLDevice wrappers and the remaining parameters required ...
CCLContext * ccl_context_new_from_filter(CCLDevSelFilterType ftype, void *filter, void *data, CCLErr **err)
Creates a context wrapper using one device filter specified in the function parameters.
Definition of a wrapper class and its methods for OpenCL device objects.
The context wrapper class.
CCLDevice * ccl_context_get_device(CCLContext *ctx, cl_uint index, CCLErr **err)
Get CCLDevice wrapper at given index.
CCLContext * ccl_context_new_wrap(cl_context context)
Get the context wrapper for the given OpenCL context.
cl_uint ccl_context_get_opencl_version(CCLContext *ctx, CCLErr **err)
Get the OpenCL version of the platform associated with this context.
void(* ccl_context_callback)(const char *errinfo, const void *private_info, size_t cb, void *user_data)
A callback function used by the OpenCL implementation to report information on errors during context ...
GPtrArray * CCLDevSelFilters
A set of independent and dependent device filters.
Header for normalizing OpenCL versions within cf4ocl.
Convert OpenCL error codes to readable strings (function header).
enum ccl_devsel_filter_type CCLDevSelFilterType
Filter type.
GError CCLErr
Error handling class.
Definition: ccl_common.h:291
Common cf4ocl definitions.
Definition of a wrapper class and its methods for OpenCL platform objects.
cl_uint ccl_context_get_num_devices(CCLContext *ctx, CCLErr **err)
Return number of devices in context.
Device wrapper class.
The platform wrapper class.
CCLContext * ccl_context_new_from_filters_full(const cl_context_properties *properties, CCLDevSelFilters *filters, ccl_context_callback pfn_notify, void *user_data, CCLErr **err)
Create a new context wrapper object selecting devices using the given set of filters.