Hi gys,
I am trying to use atomicAdd to add the index of a pixel to a gpu_regionOff. The code is shown below:
__global__ void calcCentroidKernel( int *gpu_labels, int *gpu_nRegions, int *gpu_regionOff, int *gpu_regionSize, int *gpu_centroid, int *i, int pitch)
{
int x = (blockIdx.x*blockDim.x)+threadIdx.x;
int y = (blockIdx.y*blockDim.y)+threadIdx.y;
int index = x+y*pitch;
int j = 0;
//// Implement this critical section with atomics. The followning code wont work... :(
if( gpu_labels[index] == index)
{
atomicAdd( i, 1);
atomicAdd( gpu_regionOff+i, index); /////////// ------------ At this line is the error shown --------------- //////////////
}
// I dont think there is a need to __syncthreads but try it, if it doesnt work out.
// Finding the index where offset is stored.
for( j=0; j < *gpu_nRegions; j++)
{
if( gpu_labels[index] == gpu_regionOff[j])
break;
}
// Storing the value of centroid at 2*j position.
if( gpu_labels[index] != -1)
{
atomicAdd( gpu_centroid+(2*j), x);
atomicAdd( gpu_centroid+(2*j)+1, y);
atomicAdd( gpu_regionSize+j, 1);
}
}
void calcCentroid( int *gpu_labels, unsigned char *gpu_labels_uchar, int threadsX, int threadsY, int imageW, int imageH, int *gpu_nRegions, int *gpu_regionOff, int *gpu_regionSize, int *gpu_centroid)
{
int *i;
cudaMalloc( (void **)&i, sizeof(int));
cudaMemset( i, -1, sizeof(int));
dim3 block( threadsX, threadsY, 1);
dim3 grid( imageW / block.x, imageH / block.y, 1);
calcCentroidKernel<<<grid,block>>>( gpu_labels, gpu_nRegions, gpu_regionOff, gpu_regionSize, gpu_centroid, i, imageW);
}
int *gpu_regionOff, *gpu_regionSize, *gpu_centroid;
cudaMalloc( (void **)&gpu_regionOff, (*nRegions)*sizeof(int));
cudaMalloc( (void **)&gpu_regionSize, (*nRegions)*sizeof(int));
cudaMalloc( (void **)&gpu_centroid, (*nRegions)*2*sizeof(int));
cudaMemset( gpu_regionOff, -1, (*nRegions)*sizeof(int));
cudaMemset( gpu_regionSize, 0, (*nRegions)*sizeof(int));
cudaMemset( gpu_centroid, -1, (*nRegions)*2*sizeof(int));
//////////////////////////////////////////////////// Calculating Centroid ////////////////////////////////////////////////////////
calcCentroid( gpu_labels, gpu_labels_uchar, threadsX, threadsY, imageW, imageH, gpu_nRegions, gpu_regionOff, gpu_regionSize, gpu_centroid);
Once i compile the code the following error is shown: (I have marked the line in the code where error occurs)
error: expression must have integral or enum type
Can anyone point out what is gng wrong? Should i use cudaArray instead of global memory for gpu_regionOff,gpu_regionSize, gpu_centroid ?