Reputation: 397
I'm a newbie at OpenCL. I'm trying to pass 5 arguments into a kernel: an input buffer, an output buffer, an integer, and 2 local arrays the size of the input buffer.
//Create input/output cl_mem objects
cl_mem inputBuffer = clCreateBuffer(context, CL_MEM_READ_ONLY |
CL_MEM_COPY_HOST_PTR, inputVector.size(), (void *)inputVector.data(), NULL);
cl_mem outputBuffer = clCreateBuffer(context, CL_MEM_WRITE_ONLY,
inputVector.size(), NULL, NULL);
//get iterator from command line
cl_uint iterations = (cl_uint) atoi(argv[3]);
//std::cout << "iterations: " << iterations << std::endl
//cout confirms I'm getting this correctly
//Set kernel arguments
bool argOK = (CL_SUCCESS == clSetKernelArg(kernel, 0, sizeof(cl_mem), (void*)&inputBuffer));
argOK = argOK && (CL_SUCCESS == clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *)&outputBuffer));
argOK = argOK && (CL_SUCCESS == clSetKernelArg(kernel, 2, sizeof(cl_uint), &iterations));
argOK = argOK && (CL_SUCCESS == clSetKernelArg(kernel, 3, sizeof(inputBuffer), NULL));
argOK = argOK && (CL_SUCCESS == clSetKernelArg(kernel, 4, sizeof(inputBuffer), NULL));
//Check for failure
if(!argOK) {
std::cerr << "Error: clSetKernelArg failed\n";
return SDK_FAILURE;
}
When I run the program, it prints:
Error: clSetKernelArg failed
I did some digging/debugging, and eventually found that this line:
argOK = argOK && (CL_SUCCESS == clSetKernelArg(kernel, 2, sizeof(cl_uint), &iterations));
was the culprit. Changing it to:
argOK = argOK && (CL_INVALID_ARG_SIZE == clSetKernelArg(kernel, 2, sizeof(cl_uint), &iterations));
Lets the program continue successfully. Therefore, the clSetKernelArg(kernel, 2, ...) statement is returning CL_INVALID_ARG_SIZE. It's weird though, since it looks like I'm passing in the correct size for the iterations variable.
Here's my kernel for reference:
__kernel void do_the_thing (__global uchar* in, __global uchar* out,
__global uint * numIterations, __local uchar* arr1, __local uchar* arr2)
{
//Do stuff that I haven't written yet.
}
TL;DR: Why is the setKernelArg call returning CL_INVALID_ARG_SIZE?
Upvotes: 2
Views: 5817
Reputation: 1782
The third argument of your kernel (index = 2) is a buffer (__global uint *
) not a cl_uint
scalar.
Change your kernel to:
__kernel void do_the_thing (__global uchar* in, __global uchar* out, uint numIterations, __local uchar* arr1, __local uchar* arr2)
{
//Do stuff that I haven't written yet.
}
Upvotes: 5