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:


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!

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.