Advertisement
Guest User

Untitled

a guest
Sep 20th, 2018
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. __kernel void Sum(__global float * A, __global float *output, ulong AOffset, __local float * target ) {
  2.     const size_t globalId = get_global_id(0);
  3.     const size_t localId = get_local_id(0);
  4.     target[localId] = A[globalId+AOffset];
  5.  
  6.     barrier(CLK_LOCAL_MEM_FENCE);
  7.     size_t blockSize = get_local_size(0);
  8.     size_t halfBlockSize = blockSize / 2;
  9.     while (halfBlockSize>0) {
  10.         if (localId<halfBlockSize) {
  11.             target[localId] += target[localId + halfBlockSize];
  12.             if ((halfBlockSize*2)<blockSize) { // uneven block division
  13.                 if (localId==0) { // when localID==0
  14.                     target[localId] += target[localId + (blockSize-1)];
  15.                 }
  16.             }
  17.         }
  18.         barrier(CLK_LOCAL_MEM_FENCE);
  19.         blockSize = halfBlockSize;
  20.         halfBlockSize = blockSize / 2;
  21.     }
  22.     if (localId==0) {
  23.         output[get_group_id(0)] = target[0];
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement