Monday, 15 June 2015

c++ - find indexes of specific values in array (openCL) -



c++ - find indexes of specific values in array (openCL) -

i have array of length 22500 filled 1's , 0's: {0,0,0,1,1,0,1,0,0,0,1,0} execution of next iteration, need know how many 1's in array (very easy 2 step reduction) , more importantly @ positions are. positions should in format {3,4,6,10} considering illustration array above. there smart way in opencl? copying array host programme , running on cpu take long. enqueuing single kernel take long well.

what able run 256 workers (one work group) , whenever worker encounters '1' add together index indexes array.

here draft of kernel use:

__kernel void findindexesofrowstocecalc(__global int * rowstorecalc, __global int * lengthofarray,__global int * indexes,__global int * sum){ int lid = get_local_id(0); __local int ctr = 0; __local int sums[256]; int mysum = 0; (int = lid; < *lengthofarray; += get_local_size(0)){ barrier(clk_local_mem_fence); if (*(rowstorecalc + i) == 1){ *(indexes + ctr) = i; ctr = ctr + 1; mysum = mysum + 1; } } sums[lid] = mysum; barrier(clk_local_mem_fence); int pmax = get_local_size(0)>>1; while (pmax>0){ if (lid < pmax){ sums[lid] = sums[lid] + sums[lid + pmax]; } pmax = pmax >> 1; } barrier(clk_local_mem_fence); if (lid == 0){ *sum = sums[0]; } }

my concern if 2 workers encounter '1' simulatenously, effort write same position in indexes array or local ctr variable incremented before happens? there way solve this?

thank much in advance!

c++ arrays opencl

No comments:

Post a Comment