9 Replies Latest reply on Jun 10, 2015 6:19 AM by boxerab

    OpenCL optimization: removing conditional assignments

    boxerab
      Here is a quote from the AMD OpenCL optimization guide:

       

      ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

      Optimizing Kernels for Southern Island GPUs

      Remove Conditional Assignments

      A conditional of the form “if-then-else” generates branching. Use the select() function to replace these structures with conditional assignments that do not cause branching. For example:

      if(x==1) r=0.5;
      if(x==2) r=1.0;

      becomes

      r = select(r, 0.5, x==1);
      r = select(r, 1.0, x==2);

      Note that if the body of the if statement contains an I/O, the if statement cannot be eliminated.

       

      //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

       

      I am confused about the last statement:

       

      If the body of the if statement contains an I/O, the if statement cannot be eliminated.

       

      Can someone please explain?