Results 1 to 2 of 2

Thread: Limit of kernel args

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    3

    Limit of kernel args

    Hi,

    I'm developing an OpenCL kernel that takes several OpenGL buffer objects as arguments. I was reading the clSetKernelArg documentation and I have a doubt with the thread-safe definition.
    I understand as no thread-safe a function that can not be invoked by more than one thread at the same time. Is that right? But is correct if I have only one thread that is changing the kernel args and queueing the same kernel a lot of times?

    My kernel takes two arguments and my program does something like that:
    Code :
    for (int i = 0; i < 100; i++) {
    clEnqueueAcquireGLObjects(..)
    clSetKernelArg(myKernel, 0, sizeof(float) * bufferSize, openGLBuffers[i]);
    clSetKernelArg(myKernel, 1, sizeof(float) * bufferSize, openGLBuffers[i++]);
    clEnqueueNDRangeKernel(myCommandQ, myKernel, ....);
    clEnqueueReleaseGLObjects(..)
    }

    Thanks for any help!

  2. #2
    Senior Member
    Join Date
    Aug 2011
    Posts
    271

    Re: Limit of kernel args

    setArg isn't thread safe because it alters the state of a local kernel object which describes the kernel invocation. As soon as you enqueue it though, this state is copied to the execution queue and so can be changed at will.

    The lack of thread safety just means you can't do something like:

    thread1: k.setarg(0, x)
    thread2: k.setarg(0, y)
    thread1: enqueue k
    thread2: enqueue k

    Which is clearly and obviously not going to work.

    whereas:
    thread1: k.setarg(0, x)
    thread1: enqueue k
    thread2: k.setarg(0, y)
    thread2: enqueue k

    Is obviously fine.

    But if you're not using threads, then questions 'thread safety' are simply meaningless.

    Quote Originally Posted by Carlos.Reig
    Hi,

    I'm developing an OpenCL kernel that takes several OpenGL buffer objects as arguments. I was reading the clSetKernelArg documentation and I have a doubt with the thread-safe definition.
    I understand as no thread-safe a function that can not be invoked by more than one thread at the same time. Is that right? But is correct if I have only one thread that is changing the kernel args and queueing the same kernel a lot of times?

    My kernel takes two arguments and my program does something like that:
    Code :
    for (int i = 0; i < 100; i++) {
    clEnqueueAcquireGLObjects(..)
    clSetKernelArg(myKernel, 0, sizeof(float) * bufferSize, openGLBuffers[i]);
    clSetKernelArg(myKernel, 1, sizeof(float) * bufferSize, openGLBuffers[i++]);
    clEnqueueNDRangeKernel(myCommandQ, myKernel, ....);
    clEnqueueReleaseGLObjects(..)
    }

    Thanks for any help!

Similar Threads

  1. Replies: 12
    Last Post: 02-08-2013, 09:36 AM
  2. clBuildProgram crashes with varying kernel args
    By poonaatsoc in forum OpenCL
    Replies: 2
    Last Post: 12-24-2009, 05:56 AM

Posting Permissions

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