GoodMorning,
I’m going to use Thrust Library to speed my cuda code.
My cuda code evaluate an array of min value and on the host I’m going to find the min of mins.
HOST CODE:
float minSearchCudaFunction() //return min value
{
size_t elementsPerLine = 104;
size_t width = 5;
size_t height = 5;
int N = 100;
dim3 threadBlocks(tx, ty);
dim3 blocksPerGrid((width + threadBlocks.x - 1) / threadBlocks.x, (height + threadBlocks.y - 1) / threadBlocks.y);
thrust::host_vector<float> h_vec(N);
thrust::generate(h_vec.begin(), h_vec.end(), rand);
thrust::device_vector<float> d_vec = h_vec; //cudaMemcpy in background
// transfer data back to host
thrust::copy(d_vec.begin(), d_vec.end(), h_vec.begin());
float* d_ptr = thrust::raw_pointer_cast(&d_vec[0]);
int bxb = blocksPerGrid.x *blocksPerGrid.y;
thrust::device_vector<float> d_minOut(bxb); // vector of min values
float* min_ptr = thrust::raw_pointer_cast(&d_minOut[0]);
minKernel << <blocksPerGrid, threadBlocks >> >(d_ptr, elementsPerLine, height, width, min_ptr, blocksPerGrid.x, N);
thrust::host_vector<float> h_vec_put(N);
thrust::copy(h_vec_put.begin(), h_vec_put.end(), d_minOut.begin());
// find min of mins array
thrust::device_vector<float>::iterator iter = thrust::min(h_vec_put.begin(), h_vec_put.end());
printf("\n\nMin Value => %3.2f \n", *iter);
system("PAUSE");
return 0;
}
The problem of this code is that return ALWAYS 0.
Could you help me?