The Khronos Group - a non-profit industry consortium to develop, publish and promote open standard, royalty-free media authoring and acceleration standards for desktop and handheld devices, combined with conformance qualification programs for platform and device interoperability.

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: when to use get_global id and get_local id in opencl?

Originally Posted by jai

it means that values are automatically assigned to cores of gpu ? It means kernel automatically runs on next core whose value is --> previous core's id + 1?

Yes you got it.

I think this picture is better than the last one i posted and will show how it works:
One workitem is done on one processor. Every workitem get's a unique id(get_global_id()). The items inside a workgroup are executed in parallel. And this is done for all items.

Re: when to use get_global id and get_local id in opencl?

if we have ,say n+1 input elements and global work size is n means number of cores in gpu is n then how it will execute means n element will execute and after that in 2nd cycle
last element will be processed by any freed core....am i right? or something else will happen?

Re: when to use get_global id and get_local id in opencl?

i have not heard about 0D ,heard only about 1D,2Dand 3D
pls clarify..........
if id number starting from 5 means id =5 then array which we have declared fill the value from 5 th element not from 0th element?
and i am not making any work group?

Re: when to use get_global id and get_local id in opencl?

get_local_id and get_group_size are only needed if you are using shared local memory. For many algorithms that do not, you can ignore them and use get_global_id.

In order to process large global work sizes, they are divided up into work groups that you can think of as being run sequentially. Each work group has a size. The local id is the index within the group, the group number is the count, the group size is the size.

Kernels are 1D, 2D, or 3D. Use get_global_id(0) to get the first dimension (C counts starting at 0; there is no 0D). Use get_global_id(1) for the second dimension when doing 2D kernels, and get_global_id(2) for the third dimension when doing 3D kernels.

Re: when to use get_global id and get_local id in opencl?

I don't understand what you mean by "wasted".

If you set your global work size to, say, 10, then (in parallel) 10 GPU threads will run, each getting a different result when they call get_global_id. Specifically, one will get 0, one will get 1, etc., up to 9. In your example kernel, this will calculate C=A+B for 10 array elements in parallel.

When you re-code from single-threaded CPU code, you often replace your inner loop (or the two inner loops in the 2D case) with a kernel executed over some global work size. The loop (or loops) go away and the OpenCL runtime take care of executing your kernel across the global work size. Think of get_global_id as "what is my loop index" from a sequential version of your algorithm.

Re: when to use get_global id and get_local id in opencl?

i am saying that idx =5
means a[5] is the 5 th storage location in array then 6th then7th then 8th then9th then what will happen because i have 10 elements but in array it is storing from 1[5]? because my array will start from a[0] to a[9] in kernel code.and is it also same for the B[idx]..
thanks

Re: when to use get_global id and get_local id in opencl?

Please study the basics of global IDs from an OpenCL tutorial or book.

You can say that idx = 5 as much as you want, but it's not. It's 0 to the global size minus one, runs across that many threads (work items). If your array is 10 elements and you set the global size to 10, idx will be 0, 1, 2, ..., 8, 9 across 10 work items and each element of your array will be processed.

If you *want* to start at 5 you can by using the offset parameter (starting in OpenCL 1.1) but that doesn't seem to be what you're looking for here.