Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Beginner question: understanding NDRange

  1. #1

    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?

    Thanks in advance

  2. #2
    Member
    Join Date
    Nov 2009
    Location
    Scotland
    Posts
    72

    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...

  3. #3

    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

  4. #4
    Member
    Join Date
    Nov 2009
    Location
    Scotland
    Posts
    72

    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).

  5. #5

    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!

  6. #6

    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?

  7. #7
    Member
    Join Date
    Nov 2009
    Location
    Scotland
    Posts
    72

    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.

  8. #8
    Member
    Join Date
    Nov 2009
    Location
    Scotland
    Posts
    72

    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.

  9. #9
    Junior Member
    Join Date
    Mar 2010
    Posts
    5

    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

  10. #10
    Senior Member
    Join Date
    Jul 2009
    Location
    Northern Europe
    Posts
    311

    Re: Beginner question: understanding NDRange

    get_local_id() will return your ID within your current work-group.
    E.g., if your work-group size is 100, and you have 1000 global work-items, work-item 201 will return local_id of 1 (since it's item 1 in work-group 2).

    get_global_id(0) will return the 0th dimension global ID. (x)
    get_global_id(1) will return the 1st dimension global ID. (y)
    etc.

Page 1 of 2 12 LastLast

Similar Threads

  1. A question on NDRange
    By jazpearson in forum OpenCL
    Replies: 0
    Last Post: 01-30-2013, 07:47 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
  •