Advertisement
rasoran

Untitled

Oct 21st, 2014
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 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[tid] = 0;
  9.     buf[dim+tid] = 0;
  10.     buf[pout*dim+tid] = in[idx];
  11.     barrier(CLK_LOCAL_MEM_FENCE);
  12.     for (int offset = 1; offset < dim; offset *= 2) {
  13.       pout = 1 - pout; // swap double buffer indices
  14.       pin = 1 - pout;
  15.       if (tid >= offset) {
  16.         buf[pout*dim+tid] += buf[pin*dim+tid - offset];
  17.       } else {
  18.         buf[pout*dim+tid] = buf[pin*dim+tid];
  19.       }
  20.       barrier(CLK_LOCAL_MEM_FENCE);
  21.     }
  22.     out[idx] = buf[pout*dim+tid]; // write output
  23.     barrier(CLK_LOCAL_MEM_FENCE);
  24.     if (tid == n-1) {
  25.       bout[gid] = buf[pout*dim+tid]; // write output
  26.     }
  27.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement