Advertisement
rasoran

Untitled

Oct 20th, 2014
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.74 KB | None | 0 0
  1.   int pout, pin;
  2.   pout = 0;
  3.   pin = 1;
  4.   // Load input into shared memory.
  5.   // This is exclusive scan, so shift right by one
  6.   // and set first element to 0
  7.   if (idx <= n) {
  8.     buf[pout*dim+tid] = (idx > 0) ? in[idx-1] : 0;
  9.     barrier(CLK_LOCAL_MEM_FENCE);
  10.     for (int offset = 1; offset < dim; offset *= 2) {
  11.       pout = 1 - pout; // swap double buffer indices
  12.       pin = 1 - pout;
  13.       if (offset <= pin*dim+tid) {
  14.         if (tid >= offset) {
  15.           buf[pout*dim+tid] += buf[pin*dim+tid - offset];
  16.         } else {
  17.           buf[pout*dim+tid] = buf[pin*dim+tid];
  18.         }
  19.       }
  20.       barrier(CLK_LOCAL_MEM_FENCE);
  21.     }
  22.     if (idx < pout*dim+dim+1) {
  23.       out[idx] = buf[pout*dim+tid+1]; // write output
  24.     }
  25.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement