OpenCL: clSetKernelArg returns CL_INVALID_ARG_SIZE
<p>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.</p>

<pre><code>//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 &lt;&lt; "iterations: " &lt;&lt; iterations &lt;&lt; std::endl
//cout confirms I'm getting this correctly

//Set kernel arguments
bool argOK = (CL_SUCCESS == clSetKernelArg(kernel, 0, sizeof(cl_mem), (void*)&amp;inputBuffer));
argOK = argOK &amp;&amp; (CL_SUCCESS == clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *)&amp;outputBuffer));
argOK = argOK &amp;&amp; (CL_SUCCESS == clSetKernelArg(kernel, 2, sizeof(cl_uint), &amp;iterations));
argOK = argOK &amp;&amp; (CL_SUCCESS == clSetKernelArg(kernel, 3, sizeof(inputBuffer), NULL));
argOK = argOK &amp;&amp; (CL_SUCCESS == clSetKernelArg(kernel, 4, sizeof(inputBuffer), NULL));
//Check for failure
if(!argOK) {
    std::cerr &lt;&lt; "Error: clSetKernelArg failed\n";
    return SDK_FAILURE;
}
</code></pre>

<p>When I run the program, it prints:</p>

<pre><code>Error:  clSetKernelArg failed
</code></pre>

<p>I did some digging/debugging, and eventually found that this line:</p>

<pre><code>argOK = argOK &amp;&amp; (CL_SUCCESS == clSetKernelArg(kernel, 2, sizeof(cl_uint), &amp;iterations));
</code></pre>

<p>was the culprit.  Changing it to: </p>

<pre><code>argOK = argOK &amp;&amp; (CL_INVALID_ARG_SIZE == clSetKernelArg(kernel, 2, sizeof(cl_uint), &amp;iterations));
</code></pre>

<p>Lets the program continue successfully.  <strong>Therefore, the clSetKernelArg(kernel, 2, ...) statement is returning CL_INVALID_ARG_SIZE.</strong>  It's weird though, since it looks like I'm passing in the correct size for the iterations variable.</p>

<p>Here's my kernel for reference:</p>

<pre><code>__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.  

}
</code></pre>

<p>TL;DR:  <strong>Why is the setKernelArg call returning CL_INVALID_ARG_SIZE?</strong></p>