Draft countdown

Possible duplicate:
Counting the number of numbers in a cuda array

Is there a way to use thrust or cuda to count errors for duplicates in an array?

for example, if I have a device vector {11, 11, 9, 1, 3, 11, 1, 2, 9, 1, 11} I should get 1: 3 2: 1 3: 1 9: 2, 11: 4

if emphasis cannot do this, how can I use this core?

Thanks! I am doing a concentration calculation. that is why i ask this question. suppose in a domain of 100,000 particles that have nx X ny X nz cells, I need to calculate the concentration of each cell (how many particles in each cell)

My core is

__global__ void concentration_kernel(float3* posPtr, uint* device_cons) { __shared__ uint cache[256]; uint x = threadIdx.x + blockIdx.x * blockDim.x; uint y = threadIdx.y + blockIdx.y * blockDim.y; uint offset = x + y * blockDim.x * gridDim.x; float3 posf3 = posPtr[offset];//make_float3(43.5,55,0.66);// uint cellIndex = (uint)(posf3.z+1)*153*110 + (uint)(posf3.y)*153 + (uint)posf3.x; cache[threadIdx.x] = device_cons[cellIndex]; __syncthreads(); uint a = cache[threadIdx.x]; a++; cache[threadIdx.x] = a; __syncthreads(); device_cons[cellIndex] = cache[threadIdx.x]; } 
+1
source share
2 answers

You can sort the vector first using thrust :: sort , and then use the traction :: reduce_by_key . However, after sorting, you also need to create a new vector (called a value) 1 (of the same length as the sorted vector). These values ​​will be added to get counters:

 reduce_by_key is a generalization of reduce to key-value pairs. For each group of consecutive keys in the range [keys_first, keys_last) that are equal, reduce_by_key copies the first element of the group to the keys_output. The corresponding values in the range are reduced using the plus and the result copied to values_output. 
+2
source

You can use a combination of thrust::unique and thrust::binary_search to find duplicates. You cannot do this locally using this approach, but this can only be done using the draft code.

+1
source

All Articles