Anybody have idea about how to find the frequency of each char in a string?
For example: In aabbcd, I need to figure out frequency of characters: a: 2, b: 2, c: 1, d: 1
My implementation is as below, but it doesn’t work, and there are multiple threads waiting for writing distribution[index], it is not so efficient.
Does anybody have better idea? Thanks a lot
void countblock(unsigned char *d_buf, unsigned int length, unsigned *output )
unsigned tid = threadIdx.x +
blockIdx.x * blockDim.x +
blockIdx.y * blockDim.x * gridDim.x;
unsigned char index = d_buf[tid]; atomicAdd(&distribution[index], 1); __syncthreads(); if(tid < 257) output[tid] = distribution[tid]; __syncthreads();