Hey Everybody , im trying to find the minimum variable in an array using CUDA reduction algorithm , but for some reason
it doesn’t work.
the call for the function :
findMin<<<blocks,THREADS_PER_BLOCK,blocks>>> (foundPoints,foundPointOnDev,MAXX * MAXY);
in this case blocks = 512
the foundPoints is a MAXX * MAXY array defined on the DEVICE,
foundPointOnDev is the variable declared on the DEVICE to hold the smallest number
the function :
__global__ void findMin(float4 *inPoints,float4 *outPoint,int n)
{
extern __shared__ float4 sdata[];
// load shared mem
unsigned int tid = threadIdx.x;
unsigned int i = blockIdx.x*blockDim.x + threadIdx.x;
float4 infinitePoint;
/*infinitePoint.x = 9999; infinitePoint.y = 9999; infinitePoint.z = 9999;*/
infinitePoint.w = 9999;
//load everything to the shared memory
sdata[tid] = (i < n) ? inPoints[i] : infinitePoint;
__syncthreads();
for(unsigned int s=blockDim.x/2; s>0; s>>=1)
{
if (tid < s)
{
if (sdata[tid].w < sdata[tid + s].w)
sdata[tid] = sdata[tid + s];
}
__syncthreads();
}
if (tid == 0) *outPoint = sdata[0];
}
the problem is that im not getting the result i need