0
votes

In OpenCL, how can we send addresses of the memory objects or other arguments in the kernel (while setting the kernel argument) and not accept them as pointers during kernel declaration? how can addresses be assigned to non-pointer datatypes like in the following eg:

//setting the kernel args in host code:

errNum = clSetKernelArg(kernel, 0, sizeof(cl_mem), &imageObjects[0]);
errNum |= clSetKernelArg(kernel, 1, sizeof(cl_mem), &imageObjects[1]);
errNum |= clSetKernelArg(kernel, 2, sizeof(cl_sampler), &sampler);
errNum |= clSetKernelArg(kernel, 3, sizeof(cl_int), &width);
errNum |= clSetKernelArg(kernel, 4, sizeof(cl_int), &height);

// kernel declaration:

__kernel void gaussian_filter(__read_only image2d_t srcImg, __write_only image2d_t dstImg, sampler_t sampler, int width, int height)

The code is a part of "ImageFilter" code given in OpenCl Book Sample on Google Code.

I have two doubts:

1) Here imageObjects[0] already contains the address of input image, So why is there a need to pass &imageObjects[0] to the kernel? also if the addresses are passed, why aren't they accepted as pointers

2) addresses of the args height and width are passed, but none of the args are accepted as pointers, moreover if they are accepted as pointers error is given at the compile time. Why such happens.

1
Do you actually have a problem, or are you just asking for clarification on the API's technicalities?Thomas
I have a problem and I don't know whether it's a part of API's technicality. Please solve my doubts even if they are related to the OpenCL API. I know how the arguments are to be passed, but don't know why they are passed in this way...!shunya

1 Answers

2
votes

ImageObjects[0] is a cl_mem object. It's not the address of the input image. What you pass to clSetKernelArg and what the kernel actually gets is different in this case.

The clSetKernelArg syntax using size and address allows passing any type (including OpenCL objects like memory objects, samplers, etc.) using the same API call.