9 Replies Latest reply on Jul 29, 2010 1:29 PM by ryta1203

    Flow control

    niravshah00

      Hello All,

      Sorry for the wierd post

      In the documentation it says " even if one thread in a wavefront diverges all the rest of the thread in the wavefront execute the path. "

      Can some body explain this with a simple if and else example.

      Also what does it mean by" branching is done by combining all necessary path as wavefront "

        • Flow control
          nou

          it means if you have for example

          if(cond){
          //some code
          }
          else{
          //another code
          }

          then if cond isn't consistent across wavefront then both branch  is executed in each thread. if is condition consistent across all thread in wavefront then it execute only one branch.

            • Flow control
              niravshah00

              Why would all the threads in the wavefront execute both the branches

              i mean why would the threads in the wavefront have to execute the else part even if the "if (cond)" is true for them .

              Or does it mean that some threads in the wavefront would execute path 1 and some would execute path 2.

              Also what does it mean when it says "all the necessary brances are combined as wavefront" .Can this be explained in detail.

                • Flow control
                  jeff_golds

                   

                  Originally posted by: niravshah00 Why would all the threads in the wavefront execute both the branches

                   

                  i mean why would the threads in the wavefront have to execute the else part even if the "if (cond)" is true for them .



                  Because that's how the vector HW works.  Say you have 63 threads that take the first branch and 1 thread that takes the second.  What really happens is that both branches are taken and the execute mask is set accordingly (i.e. 1 thread is masked out on the first branch and only 1 thread is masked in on the second branch).

                  Jeff

              • Flow control
                MicahVillmow
                This is how our hardware and predication works. There is no flow control units for each individual thread, so the whole wavefront has to execute the branch if any thread in the wavefront executes the branch. If the condition is false, then the results are not written to memory, but the execution still occurs.
                  • Flow control
                    niravshah00

                    What does it mean when it is said that Flow control,such as branaching is done by combining all necessary paths as wavefront.

                    What do you mean by necessary path and how are the wavefronts formed unless you test the conditions

                    AND is it safe to say that all threads in a wavefront are synchronized at the branch and then the branch is executed??

                      • Flow control
                        jeff_golds

                         

                        Originally posted by: niravshah00 What does it mean when it is said that Flow control,such as branaching is done by combining all necessary paths as wavefront.

                         

                        What do you mean by necessary path and how are the wavefronts formed unless you test the conditions

                         

                        AND is it safe to say that all threads in a wavefront are synchronized at the branch and then the branch is executed??

                         

                        A wavefront is always in sync with itself.  All the threads in the wavefront execute simultaneously.  When a branch is reached, the HW looks at all the predication masks for the threads in the wavefront and decides which branch to take.  If all the masks are the same, then the HW will only execute the relevant branch.  If the masks differ, then the HW must take multiple branches.  As mentioned above, all threads in the wavefront execute simultaneously, so all threads take all needed branches.  Execution masks prevent the HW from actually using results from branches that the thread wouldn't have taken on its own.

                        Jeff

                          • Flow control
                            niravshah00

                            So the mask size is the same as the size of wavefront and conceptually there is a bit for each thread in mask for each branch.

                            So there is a mask for a wavefront for each branch .

                            If so when is the mask created?definetly not at compile time.

                            1 means store the results and 0 means just execute the branch but dont store results.

                            This would be the last question

                              • Flow control
                                jeff_golds

                                 

                                Originally posted by: niravshah00 So the mask size is the same as the size of wavefront and conceptually there is a bit for each thread in mask for each branch.

                                 

                                So there is a mask for a wavefront for each branch .

                                 

                                If so when is the mask created?definetly not at compile time.

                                 

                                1 means store the results and 0 means just execute the branch but dont store results.



                                The HW generates the mask based on the results of the predication instructions in the kernel.  You can see this if you look at the ISA code of a kernel containing branches.

                                Jeff

                        • Flow control
                          ryta1203

                          Luckily, if-else... branches are easily gotten rid of, and the majority of the times for the better.