# Beginner question: understanding NDRange

Show 40 post(s) from this thread on one page
Page 1 of 2 12 Last
• 03-09-2010, 02:35 PM
Rui
Beginner question: understanding NDRange
Hello,

I'm learning OpenCL and I'm having some difficult understanding the NDRange concept. All I have to understand is that it is related to the positions of work-items, etc right? Where can I find some simple examples about 1, 2 and 3 dimension problems?

• 03-09-2010, 03:44 PM
dominik
Re: Beginner question: understanding NDRange
A very basic example for a 1-dimensional problem is vector addition. Work-item X is responsible for adding the elements at position X of the input vectors.
An example for a 2-dimensional problem is matrix multiplication. Work-item (x,y) computes the result of element (x,y) in the output matrix.
I can't think of a nice 3D problem right now, but I hope that you get the idea...
• 03-09-2010, 09:24 PM
Rui
Re: Beginner question: understanding NDRange
I see, and from what I've read a 3 dimensional problem could refer to a volume for example.
Apart from that, what I could conclude from the examples I saw was, and please correct me if I'm wrong: imagining a 1024x1024 image where we want to apply some filter to each pixel.

* The operation to apply would be defined within a kernel, which would be executed 1024*1024 times
* Those 1024*1024 kernel instances (work-items) could be grouped in 128x128 work-groups (number defined by the user, according to some criteria).
* NDRange means 'simply' the dimensional index space from where all those kernel instances could be identified
• 03-10-2010, 12:54 AM
dominik
Re: Beginner question: understanding NDRange
That's right. NDRange describes the space of work-items, which can be 1-, 2- or 3-dimensional. Each work-item then executes the kernel code (usually on different data depending on its position in the work-item space).
As you said, in your example you would create 1024x1024 work-items that each apply the filter to one pixel in your image, namely work-item (x,y) applies the filter to pixel (x,y).
• 03-10-2010, 07:29 AM
Rui
Re: Beginner question: understanding NDRange
One last thing, in the OpenCL specification it's written that "Work-groups are assigned a unique work-group ID with the
same dimensionality as the index space used for the work-items". I'm not quite understanding what does an "id with the same dimensionality as the index space" means.

Thanks a lot!
• 03-10-2010, 08:36 AM
Rui
Re: Beginner question: understanding NDRange
Another one came up, you said a 2D problem could be for example a matrix multiplication, but I read also that buffer objects in OpenCL are one-dimensional, and for 2D or 3D you have image objects. Does that mean in fact that a problem like matrix multiplication ("apparently" 2D) would have to be mapped to a 1 dimensional problem?
• 03-10-2010, 08:37 AM
dominik
Re: Beginner question: understanding NDRange
It means that if your work-item space is n-dimensional, your work-group space is also n-dimensional.
To come back to your example: if you have 1024x1024 work-items (in 2 dimensions), then your workgroups are also arranged in two dimensions, i.e. they are identified by two IDs. For example you can have 64x64 workgroups of size 16x16.
• 03-10-2010, 08:40 AM
dominik
Re: Beginner question: understanding NDRange
Quote:

Originally Posted by Rui
Another one came up, you said a 2D problem could be for example a matrix multiplication, but I read also that buffer objects in OpenCL are one-dimensional, and for 2D or 3D you have image objects. Does that mean in fact that a problem like matrix multiplication ("apparently" 2D) would have to be mapped to a 1 dimensional problem?

You would have to map the matrix (2-dimensional) to a buffer (1-dimensional), but it's still possible (and sensible) to use a 2-dimensional space of work-items. You just have to make sure you get the indexing right when accessing the matrices.
• 03-10-2010, 09:03 AM
wilson
Re: Beginner question: understanding NDRange
So, if i call this opencl function size_t get_local_id (uint dimindx) , this would return an unidimensional id of a work-item from a workgroup in the dimindx Dimension. Right?

And the if i want a a bi-dimension coordinates i would have to use the equation, at page 20 from specs,
(gx , gy) = (wx * Sx + sx , wy * Sy + sy)

right?

Thanks
• 03-10-2010, 10:32 AM
dbs2
Re: Beginner question: understanding NDRange