0

Suppose we have declared as this as a kernel parameter:

__local float *sharedData  

And let us say the work group size is 512. Then how many such copies of sharedData will be allocated ? 512 ? or there will be only one copy, and will be broadcasted to all the threads?

What about the other variables in the kernel. My understanding is all the variables in the kernel body will be duplicated 'n' no. of time , where 'n' is the no. of threads in the work group.

2
  • Local variables exist once per workgroup. Default (private) variables exist once per work item.
    – DarkZeros
    Aug 20, 2014 at 8:56
  • @DarkZeros so you mean there would be a single value in shared memory , and will be read by all the threads, (by broadcast?) ? Aug 20, 2014 at 9:23

1 Answer 1

1

Yes, the local array is visible (you say broadcast) to all work items in the workgroup. There will be one copy per workgroup regardless of the workgroup size.

If your workgroup is 512 workitems and you want one float per work item, then sharedData will have 512 elements, and it's up to you to specify this size via clSetKernelArg.

As DarkZeros says, private variables are specific to each workitem. Each of the 512 workitems has its own copy.

(Note: I think what you're calling a thread is what we call a workitem.)

3
  • @user3891236 A thread is something independent, that runs on its own. While a Workitem is a OpenCL specific term, and reffers to the small pieces inside a work group. They are not threads, since they are not independent, all of them run the same code with different data.
    – DarkZeros
    Aug 21, 2014 at 9:09
  • @DarkZeros Thanks for the info. Can you point me to some reference in support of your argument (especially that workitems are not independent)? Aug 21, 2014 at 9:28
  • I think "thread" comes from CUDA's nomanclature and is not an OpenCL. See this reference: cs.nyu.edu/~lerner/spring12/Preso07-OpenCL.pdf Also see slide 26 of this presentation: wiki.aalto.fi/download/attachments/40025977/… for a table of CUDA concepts mapped to OpenCL.
    – Tim
    Aug 21, 2014 at 17:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.