5 Replies Latest reply on Oct 19, 2010 10:19 AM by himanshu.gautam

    Compiler can't count down :-/

    redditisgreat
      Reverse "for loops" count one short with evergreen GPU code.

      After hours of debugging I found the reason my sorting algorithm didn't work.

       

      With a given input of A[] = 1, 2, ..., N the following Kernel code gives us for n=16

       

       

      sum_total1 = 136;   // correct sum with faulty loop
      sum_total2 = 135;   // incorrect sum with correct loop

       

      The error persists for larger N, but not for N=8 for example.

      All tested on Juniper.

      __private uint sum_total1 = 0ul; __private uint sum_total2 = 0ul; for( int i=N-1; i>=-1; --i ){ sum_total1 += A[ i ]; } for( int i=N-1; i>= 0; --i ){ sum_total2 += A[ i ]; }