Results 1 to 4 of 4

Thread: Problem with setting buffers as kernel parameters

Hybrid View

  1. #1
    Newbie
    Join Date
    Nov 2013
    Posts
    2

    Problem with setting buffers as kernel parameters

    I have a kernel defined like this:
    Code :
    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:
    Code :
    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:
    Code :
    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!

  2. #2
    Senior Member
    Join Date
    Dec 2011
    Posts
    168
    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?

  3. #3
    Newbie
    Join Date
    Nov 2013
    Posts
    2
    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.

  4. #4
    Senior Member
    Join Date
    Dec 2011
    Posts
    168
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •