30 #include "_ccl_abstract_dev_container_wrapper.h"
63 static void ccl_context_release_fields(
CCLContext* ctx) {
66 g_return_if_fail(ctx != NULL);
88 #define ccl_context_properties_default_free(properties, ctx_props) \
89 if (properties == NULL) \
90 g_slice_free1(3 * sizeof(cl_context_properties), ctx_props)
109 static cl_context_properties* ccl_context_properties_default(
110 const cl_context_properties* properties,
111 cl_device_id device,
CCLErr** err) {
114 g_return_val_if_fail(device != NULL, NULL);
116 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
119 cl_context_properties* ctx_props = NULL;
122 cl_platform_id platform;
128 if (properties == NULL) {
133 ctx_props = g_slice_alloc(3 *
sizeof(cl_context_properties));
136 ocl_status = clGetDeviceInfo(device, CL_DEVICE_PLATFORM,
137 sizeof(cl_platform_id), &platform, NULL);
139 CL_SUCCESS != ocl_status, ocl_status, error_handler,
140 "%s: unable to get platform from device (OpenCL error %d: %s).",
141 CCL_STRD, ocl_status,
ccl_err(ocl_status));
144 ctx_props[0] = CL_CONTEXT_PLATFORM;
145 ctx_props[1] = (cl_context_properties) platform;
151 ctx_props = (cl_context_properties*) properties;
155 g_assert(err == NULL || *err == NULL);
160 g_assert(err == NULL || *err != NULL);
251 g_return_val_if_fail(filters != NULL, NULL);
253 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
256 CCLErr* err_internal = NULL;
259 GPtrArray* devices = NULL;
271 "%s: no device found for selected filters.",
276 (
CCLDevice**) devices->pdata, pfn_notify, user_data,
281 g_assert(err == NULL || *err == NULL);
287 g_assert(err == NULL || *err != NULL);
292 if (devices != NULL) g_ptr_array_free(devices, TRUE);
320 const cl_context_properties* properties, cl_uint num_devices,
322 void* user_data,
CCLErr** err) {
325 g_return_val_if_fail(num_devices > 0, NULL);
327 g_return_val_if_fail(devices != NULL, NULL);
329 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
332 cl_device_id* cl_devices = NULL;
334 cl_context_properties* ctx_props = NULL;
338 cl_context context = NULL;
342 CCLErr* err_internal = NULL;
346 (cl_device_id*) g_slice_alloc(
sizeof(cl_device_id) * num_devices);
349 for (guint i = 0; i < num_devices; i++)
353 ctx_props = ccl_context_properties_default(
354 properties, cl_devices[0], &err_internal);
357 context = clCreateContext(
358 (
const cl_context_properties*) ctx_props, num_devices,
359 (
const cl_device_id*) cl_devices, pfn_notify, user_data,
362 CL_SUCCESS != ocl_status, ocl_status, error_handler,
363 "%s: unable to create cl_context (OpenCL error %d: %s).",
364 CCL_STRD, ocl_status,
ccl_err(ocl_status));
370 g_assert(err == NULL || *err == NULL);
375 g_assert(err == NULL || *err != NULL);
384 ccl_context_properties_default_free(properties, ctx_props);
385 g_slice_free1(
sizeof(cl_device_id) * num_devices, cl_devices);
412 void* filter,
void* data,
CCLErr** err) {
415 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
418 CCLErr* err_internal = NULL;
427 if (filter != NULL) {
441 error_handler,
"%s: Unknown filter type.", CCL_STRD);
454 g_assert(err == NULL || *err == NULL);
460 g_assert(err == NULL || *err != NULL);
481 (ccl_wrapper_release_fields) ccl_context_release_fields,
482 (ccl_wrapper_release_cl_object) clReleaseContext, NULL);
509 g_return_val_if_fail(ctx != NULL, 0);
511 g_return_val_if_fail(err == NULL || *err == NULL, 0);
540 g_return_val_if_fail(ctx != NULL, NULL);
542 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
546 CCLErr* err_internal = NULL;
549 if (ctx->platf != NULL) {
563 g_assert(err == NULL || *err == NULL);
569 g_assert(err == NULL || *err != NULL);
598 CCLContext* ctx, cl_mem_flags flags, cl_mem_object_type image_type,
599 cl_uint* num_image_formats,
CCLErr** err) {
602 g_return_val_if_fail(ctx != NULL, NULL);
604 g_return_val_if_fail(num_image_formats != NULL, NULL);
606 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
614 const cl_image_format* image_formats = NULL;
621 flags, image_type, 0, NULL, num_image_formats);
623 CL_SUCCESS != ocl_status, ocl_status, error_handler,
624 "%s: get number of supported image formats (OpenCL error %d: %s).",
625 CCL_STRD, ocl_status,
ccl_err(ocl_status));
628 "%s: number of returned supported image formats is 0.",
632 info = ccl_wrapper_info_new(
633 (*num_image_formats) *
sizeof(cl_image_format));
637 flags, image_type, *num_image_formats,
638 (cl_image_format*) info->
value, NULL);
640 CL_SUCCESS != ocl_status, ocl_status, error_handler,
641 "%s: get supported image formats (OpenCL error %d: %s).",
642 CCL_STRD, ocl_status,
ccl_err(ocl_status));
645 ccl_wrapper_add_info((
CCLWrapper*) ctx, CL_IMAGE_FORMAT, info);
648 g_assert(err == NULL || *err == NULL);
649 image_formats = (
const cl_image_format*) info->
value;
654 g_assert(err == NULL || *err != NULL);
655 *num_image_formats = 0;
660 return image_formats;
681 ccl_context_get_cldevices, index, err);
699 ccl_context_get_cldevices, err);
723 ccl_context_get_cldevices, err);
void ccl_context_destroy(CCLContext *ctx)
Decrements the reference count of the context wrapper object.
CCLDevice *const * ccl_context_get_all_devices(CCLContext *ctx, CCLErr **err)
Get all device wrappers in context.
#define CCL_OCL_ERROR
Resolves to error category identifying string, in this case an error in the OpenCL library...
CCLDevSelDevices ccl_devsel_dep_platform(CCLDevSelDevices devices, void *data, CCLErr **err)
Dependent filter function which only accepts devices of the same platform (the platform to which the ...
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 ...
#define ccl_if_err_create_goto(err, quark, error_condition, error_code, label, msg,...)
If error is detected (error_code != no_error_code), create an error object (CCLErr) and go to the spe...
#define ccl_context_unwrap(ctx)
Get the OpenCL context object.
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.
Useful definitions used internally by cf4ocl.
Definition of a wrapper class and its methods for OpenCL context objects.
The context wrapper class.
#define ccl_if_err_propagate_goto(err_dest, err_src, label)
Same as ccl_if_err_goto(), but rethrows error in a source CCLErr object to a new destination CCLErr o...
CCLDevice * ccl_context_get_device(CCLContext *ctx, cl_uint index, CCLErr **err)
Get CCLDevice wrapper at given index.
const char * ccl_err(int code)
Convert OpenCL error code to a readable string.
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.
cl_bool(* ccl_devsel_indep)(CCLDevice *device, void *data, CCLErr **err)
Independent filter function: Abstract function for filtering one OpenCL device at a time...
Base class for wrappers which contain devices, i.e., CCLPlatform, CCLProgram and CCLContext.
#define CCL_ERROR
Resolves to error category identifying string, in this case an error in cf4ocl.
The requested OpenCL device was not found.
#define ccl_platform_unref(platform)
Alias to ccl_platform_destroy().
Independent filter, filters one device at a time.
Base class for all OpenCL wrappers.
CCLDevSelDevices ccl_devsel_select(CCLDevSelFilters *filters, CCLErr **err)
Select one or more OpenCL devices based on the provided filters.
void ccl_devsel_add_dep_filter(CCLDevSelFilters *filters, ccl_devsel_dep filter, void *data)
Add a dependent filter to the filter set.
CCLPlatform * ccl_platform_new_from_device(CCLDevice *dev, CCLErr **err)
Get the platform wrapper for the given device wrapper.
#define ccl_device_unwrap(dev)
Get the OpenCL device_id object.
void ccl_devsel_add_indep_filter(CCLDevSelFilters *filters, ccl_devsel_indep filter, void *data)
Add an independent filter to the filter set.
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 ...
Invalid function arguments.
#define ccl_context_new_from_filters(filters, err)
Create a new context wrapper object selecting devices using the given set of filters.
CCLDevSelDevices(* ccl_devsel_dep)(CCLDevSelDevices devices, void *data, CCLErr **err)
Dependent filter function: Abstract function for filtering several OpenCL devices depending on the av...
GPtrArray * CCLDevSelFilters
A set of independent and dependent device filters.
Dependent filter, filters devices depending on the currently available device choices.
void * value
Object information.
enum ccl_devsel_filter_type CCLDevSelFilterType
Filter type.
Class which represents information about a wrapped OpenCL object.
GError CCLErr
Error handling class.
cl_uint ccl_context_get_num_devices(CCLContext *ctx, CCLErr **err)
Return number of devices in context.
#define ccl_context_get_info(ctx, param_name, err)
Get a CCLWrapperInfo context information object.
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.
cl_uint ccl_platform_get_opencl_version(CCLPlatform *platf, CCLErr **err)
Get the OpenCL version of this platform.