Problem with setting buffers as kernel parameters

I have a kernel defined like this:

kernel void trivial_kmean(global float* points, global float* centroids, global int* closestCentroid , const int clusters, const int pts, const int dimensions) {...}

Kernel and buffer creation is successful but when I’m trying to set memory objects as kernel parameters CL_INVALID_MEM_OBJECT occurs.
Buffers definition:

cl_mem centroids, points, closestCentroids;
points = clCreateBuffer(context, CL_MEM_READ_ONLY , sizeof(float) * dimensions * pts, NULL, &bufferCreationError);
centroids = clCreateBuffer(context, CL_MEM_READ_ONLY , sizeof(float) * dimensions * clusters, NULL, &bufferCreationError);
closestCentroids = clCreateBuffer(context, CL_MEM_WRITE_ONLY, sizeof(int) * pts,	NULL, &bufferCreationError);

Parameter setting:

setArgumentError = clSetKernelArg(k, 0, sizeof(cl_mem), &points);
setArgumentError = clSetKernelArg(k, 1, sizeof(cl_mem), &centroids);
setArgumentError = clSetKernelArg(k, 2, sizeof(cl_mem), &closestCentroids);

I can not find the cause of this error
Please help me!

I don’t see any obvious errors yet.

Do you write to the read only buffers (or map/unmap them) prior to using them as kernel arguments? Perhaps the runtime is detecting this and giving the error (since it might use deferred allocation and since you don’t write they aren’t allocated, which is an error when it tried to use them as as parameter).

If you make them CL_MEM_READ_WRITE, does it work?

I tried to write to buffers, this does not cause errors, but still I can not use them.
Changing buffer flags does not changing anything. Setting parameters fails with the same error.

Hm, that is a puzzle, and I’m still not seeing what could cause the problem. I suggest starting with a simple OpenCL sample code example that uses buffers, and after verifying that it works, slowly changing it to be more like your code until you find the change that breaks it. You’ll either find the issue or you’ll end up with working code.