1
votes

I am currently learning how to use OpenCL but I am having an issue with trying to enqueue a kernel to my queue.

The kernel is supposed to receive a float and 2 Buffer of type unsigned char and unsigned int -

__kernel void task2(float value,
                    __global unsigned char *chars,
                    __global unsigned int *ints) 

My program looks like the following -

bufferA = cl::Buffer(context, CL_MEM_WRITE_ONLY, sizeof(cl_uchar) * alphabets.size());
bufferB = cl::Buffer(context, CL_MEM_READ_WRITE, sizeof(cl_uint) * numbers.size());

kernel = cl::Kernel(prog, "kernelTest");
kernel.setArg(0, 2.55);
kernel.setArg(1, bufferA);
kernel.setArg(2, bufferB);

queue.enqueueTask(kernel);

where alphabets and numbers are vectors. The program is built successfully but excluded since I think it'd be irrelevant to this question.

When reaching the enqueueTask portion in the program, I receive an error -

Error in: clSetKernelArg
Error code: -51 (CL_INVALID_ARG_SIZE)

Unless I am completely wrong about this, the kernel takes in 3 arguments and I am passing in three arguments of float, unsigned char Buffer and unsigned Int buffer respectively. Am I doing something wrong?

1

1 Answers

2
votes

You don't say which of your 3 setArg() calls is failing, but I suspect the problem might be that the literal 2.55 is of type double while your kernel expects a float. You could try 2.55f, or if that doesn't work, use a temporary variable of type float instead of a literal.

Note that clSetKernelArg() (the backend for cl::Kernel::setArg()) does not validate the size of buffer objects. So CL_INVALID_ARG_SIZE only relates to size mismatch of scalar arguments, and for global pointer kernel arguments, clSetKernelArg() validates that the argument passed is in fact a valid cl_mem handle (and specified arg_size is sizeof(cl_mem)).