Hello everyone,
I am a newbie to Cuda and I have a project to work on. The project is to find the k nearest neighbours of all objects, but thrust is too slow in sorting the neighbours, I dunno why. I might have something wrong with the code. Could you please help me? I meant by too slow is my CPU is faster in sorting than using thrust. I have Geforce GT 740.
here’s launch: I’m launching the kernel to find the kNN of object j
for (int j = 0; j < numberOfObjects; j++){
kNNQueryInGPU << <blocksPerGrid, threadsPerBlock >> >(x_d, y_d, list1_d, list2_d, j);
cudaMemcpy(&list1, list1_d, sizeof(int) * numberOfObjects, cudaMemcpyDeviceToHost);
cudaMemcpy(&list2, list2_d, sizeof(int) * numberOfObjects, cudaMemcpyDeviceToHost);
thrust::sort_by_key(list1, list1 + numberOfObjects, list2);
getKNNeighbour(list1, j);
}
here’s the kernel
__global__ void kNNQueryInGPU(int *x, int *y, int *list1, int* list2, int index){
int tid = threadIdx.x + blockDim.x * blockIdx.x;
if (tid < numberOfObjects){
list1[tid] = sqrt(pow((double)(x[index] - x[tid]), 2) + pow((double)(y[index] - y[tid]), 2));
list2[tid] = threadIdx.x + blockDim.x * blockIdx.x;
}//ends while-loop
}