Results 1 to 3 of 3

Thread: for loops in kernel

Hybrid View

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    22

    for loops in kernel

    Hello,

    According to the book "OpenCL in action":

    "Comparisons are time-consumingon the best of processors, but they’re especially slow on dedicated number-crunchers like graphic processor units (GPUs). GPUs excel at performing the same operations over and over again, but they’re not good at making decisions. If a GPU has to check a condition and branch, it may take hundreds of cycles before it can get back to crunching numbers at full speed."

    But in this great book there are few samples where the kernel contains 'for' loops:
    matrix transposition: page 261
    matrix multiplication: page 264
    DFT: page 314

    My question is: Is it possible to avoid 'for' and 'while' loops in kernel functions ?

    And another one: Let's say I have only 5 work groups. It means that I need 5 cores.
    Am I right ?

    Thanks,
    Zvika

  2. #2
    Senior Member
    Join Date
    Dec 2011
    Posts
    170
    The book puts this poorly.

    GPUs are quick at "making decisions". The issue with branching is that if you have *divergent* branching within a work group, it will cause a performance penalty because both sides of the branch are taken by every work item.

    "For" loops that are fixed counts do not fall into the category. However, any control flow that is dependent on the global_id or data you read could cause divergent branching.

    It is something to be aware of but doesn't have to be avoided at all costs.

  3. #3
    Junior Member
    Join Date
    Oct 2013
    Posts
    22
    Quote Originally Posted by Dithermaster View Post
    The book puts this poorly.

    GPUs are quick at "making decisions". The issue with branching is that if you have *divergent* branching within a work group, it will cause a performance penalty because both sides of the branch are taken by every work item.

    "For" loops that are fixed counts do not fall into the category. However, any control flow that is dependent on the global_id or data you read could cause divergent branching.

    It is something to be aware of but doesn't have to be avoided at all costs.
    Dear Dithermaster,

    Thank you for your help !

    Regards,
    Zvika

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •