AnsweredAssumed Answered

Call-by-reference and const OpenCL Objects

Question asked by settle on Jul 13, 2012
Latest reply on Jul 15, 2012 by settle

This may be more of a C++ question than OpenCL, but I can't seem to make sense of some parts in the OpenCL C++ Wrapper API included in the AMD APP SDK (include/CL/cl.hpp).

 

Would someone mind explaining why vectors of OpenCL objects such as "Event" are sometimes passed by reference with "&" and othertimes "*"?

Case 1:

cl_int cl::CommandQueue::enqueueWaitForEvents(

const VECTOR_CLASS<Event>& events)

Case 2:

cl_int cl::CommandQueue::enqueueNDRangeKernel(

const Kernel& kernel,

const NDRange& offset,

const NDRange& global,

const NDRange& local,

const VECTOR_CLASS<Event> * events = NULL,

Event * event = NULL)

My initial hypothesis was because Case 2 sets a default value of NULL, but then I found other cases with "Device" that seem to refute that.

Case 3:

cl::Context::Context(VECTOR_CLASS<Device>& devices,

cl_context_properties * properties = NULL,

void (CL_CALLBACK * pfn_notify)(

const char * errorinfo,

const void * private_info_size,

::size_t cb,

void * user_data) = NULL,

void * user_data = NULL,

cl_int * err = NULL)

Case 4:

cl_int cl::Platform::getDevices(cl_device_type type,

VECTOR_CLASS<Device> * devices)

 

 

 

Secondly, why does the OpenCL C++ Wrapper API use "const" and pass-by-reference when passing memory objects

cl_int cl::CommandQueue::enqueueCopyBuffer(

const Buffer & src,

const Buffer & dst,

::size_t src_offset,

::size_t dst_offset,

::size_t size,

const VECTOR_CLASS<Event> * events = NULL,

Event * event = NULL)

but the the OpenCL C API uses neither

cl_int clEnqueueCopyBuffer (cl_command_queue command_queue,

cl_mem src_buffer,

cl_mem dst_buffer,

size_t src_offset,

size_t dst_offset,

size_t size,

cl_uint num_events_in_wait_list,

const cl_event *event_wait_list,

cl_event *event)

 

Frankly, it's hard/impossible to make sense of most OpenCL C data types and C++ Objects because the information is hidden away in opaque pointers (e.g., typedef struct _cl_mem * cl_mem;) or opaque classes (e.g., detail::Wrapper<cl_mem>).

Outcomes