20 #include "_ccl_memobj_wrapper.h"
43 void ccl_memobj_release_fields(
CCLMemObj* mo) {
46 g_return_if_fail(mo != NULL);
82 g_return_val_if_fail(mo != NULL, 0);
84 g_return_val_if_fail(err == NULL || *err == NULL, 0);
88 CCLErr* err_internal = NULL;
93 mo, CL_MEM_CONTEXT, cl_context, &err_internal);
107 g_assert(err == NULL || *err == NULL);
113 g_assert(err == NULL || *err != NULL);
146 g_return_val_if_fail(cq != NULL, NULL);
148 g_return_val_if_fail(mo != NULL, NULL);
150 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
162 ccl_event_wait_list_get_num_events(evt_wait_lst),
163 ccl_event_wait_list_get_clevents(evt_wait_lst), &event);
165 CL_SUCCESS != ocl_status, ocl_status, error_handler,
166 "%s: unable to unmap memory object (OpenCL error %d: %s).",
167 CCL_STRD, ocl_status,
ccl_err(ocl_status));
172 evt = ccl_queue_produce_event(cq, event);
178 g_assert(err == NULL || *err == NULL);
184 g_assert(err == NULL || *err != NULL);
215 void *user_data,
CCLErr** err) {
218 g_return_val_if_fail(mo != NULL, CL_FALSE);
220 g_return_val_if_fail(err == NULL || *err == NULL, CL_FALSE);
229 CCLErr* err_internal = NULL;
231 #ifndef CL_VERSION_1_1
243 "%s: Setting destructor callbacks requires cf4ocl to be "
244 "deployed with support for OpenCL version 1.1 or newer.",
256 "%s: memory object destructor callbacks require OpenCL " \
257 "version 1.1 or newer.",
262 pfn_notify, user_data);
264 CL_SUCCESS != ocl_status, ocl_status, error_handler,
265 "%s: unable to set memory object destructor callback "
266 "(OpenCL error %d: %s).",
267 CCL_STRD, ocl_status,
ccl_err(ocl_status));
272 g_assert(err == NULL || *err == NULL);
273 ret_status = CL_TRUE;
279 g_assert(err == NULL || *err != NULL);
281 ret_status = CL_FALSE;
311 CCLQueue* cq, cl_mem_migration_flags flags,
315 g_return_val_if_fail(cq != NULL, NULL);
317 g_return_val_if_fail(mos != NULL, NULL);
319 g_return_val_if_fail(num_mos > 0, NULL);
321 g_return_val_if_fail(err == NULL || *err == NULL, NULL);
332 CCLErr* err_internal = NULL;
334 cl_mem* mem_objects = NULL;
336 #ifndef CL_VERSION_1_2
349 "%s: Memory object migration requires cf4ocl to be "
350 "deployed with support for OpenCL version 1.2 or newer.",
362 "%s: memory object migration requires OpenCL version 1.2 or " \
367 mem_objects = (cl_mem*) g_slice_alloc(
sizeof(cl_mem) * num_mos);
370 for (cl_uint i = 0; i < num_mos; ++i) {
376 num_mos, (
const cl_mem*) mem_objects, flags,
377 ccl_event_wait_list_get_num_events(evt_wait_lst),
378 ccl_event_wait_list_get_clevents(evt_wait_lst), &event);
380 CL_SUCCESS != ocl_status, ocl_status, error_handler,
381 "%s: unable to migrate memory objects (OpenCL error %d: %s).",
382 CCL_STRD, ocl_status,
ccl_err(ocl_status));
387 evt = ccl_queue_produce_event(cq, event);
395 g_assert(err == NULL || *err == NULL);
401 g_assert(err == NULL || *err != NULL);
409 if (mem_objects) g_slice_free1(
sizeof(cl_mem) * num_mos, mem_objects);
void(* ccl_memobj_destructor_callback)(cl_mem memobj, void *user_data)
Prototype for memory object destructor callback functions.
#define CCL_OCL_ERROR
Resolves to error category identifying string, in this case an error in the OpenCL library...
#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...
GPtrArray * CCLEventWaitList
A list of event objects on which enqueued commands can wait.
Useful definitions used internally by cf4ocl.
#define ccl_memobj_unwrap(mo)
Get the OpenCL cl_mem object.
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...
Base class for memory object wrappers, i.e., CCLBuffer and CCLImage.
Command queue wrapper class.
const char * ccl_err(int code)
Convert OpenCL error code to a readable string.
void ccl_event_wait_list_clear(CCLEventWaitList *evt_wait_lst)
Clears an event wait list.
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.
#define CCL_ERROR
Resolves to error category identifying string, in this case an error in cf4ocl.
#define ccl_context_unref(ctx)
Alias to ccl_context_destroy().
#define CCL_UNUSED(x)
Macro to avoid warning in unused variables.
cl_uint ccl_memobj_get_opencl_version(CCLMemObj *mo, CCLErr **err)
Get the OpenCL version of the platform associated with this memory object.
Definition of a wrapper class and its methods for OpenCL memory objects.
cl_bool ccl_memobj_set_destructor_callback(CCLMemObj *mo, ccl_memobj_destructor_callback pfn_notify, void *user_data, CCLErr **err)
Wrapper for OpenCL clSetMemObjectDestructorCallback() function.
GError CCLErr
Error handling class.
#define ccl_memobj_get_info_scalar(mo, param_name, param_type, err)
Macro which returns a scalar memory object information value.
#define ccl_queue_unwrap(cq)
Get the OpenCL command queue object.
The operation is not supported by the version of the selected OpenCL platform.
CCLEvent * ccl_memobj_enqueue_migrate(CCLMemObj **mos, cl_uint num_mos, CCLQueue *cq, cl_mem_migration_flags flags, CCLEventWaitList *evt_wait_lst, CCLErr **err)
Enqueues a command to indicate which device a set of memory objects should be associated with...
CCLEvent * ccl_memobj_enqueue_unmap(CCLMemObj *mo, CCLQueue *cq, void *mapped_ptr, CCLEventWaitList *evt_wait_lst, CCLErr **err)
Enqueues a command to unmap a previously mapped region of a memory object.