Why can't I assign values to a list?

I wrote code like this:

	float* ComparisonList;
	cudaMalloc((void**)&ComparisonList, sizeof(float)* Times * row * IndexNum);	

        ''' 

	ConstantFalseAlarmRate << <GridForConstantFalseAlarmRate, ThreadsPerBlock >> > (NormallizeData, ComparisonList, StartIndex, EndIndex, ExerciseUnit, ProtectUnit, alpha, row, col, Times);

       '''

__global__ void ConstantFalseAlarmRate(float* InputData, float* OutputData, int StartIndex, int EndIndex, int ExerciseUnit, int ProtectUnit, float alpha, int row, int col, int Times)
{
	int i = threadIdx.x + blockDim.x * blockIdx.x;
	int j = threadIdx.y + blockDim.y * blockIdx.y;
	int k = threadIdx.z + blockDim.z * blockDim.z;

	if (i < 110 && j < row && k < Times)
	{
		OutputData[k * row * 110 + j * 110 + i] = 0.1;
	}
}

I am sure that the input is correct, and the blocksize and gridsize is (64,8,2), (2,16,50), row = 128, Times =100, IndexNum = 110.
It turns out that i could only assign some value to “ComparisonList”, that is , just a few of elements in “ComparisonList” are 0.1, others are “0”.
It’s weird, because i didn’t assign “0” to “ComparisonList”. That means at least values in “ComparisonList” should be “NAN”, but they are “0”.
I don’t know why would this happen. Can you give me some advice to deal with this bug?

well, i found that i made a stupid mistake. I used wrong index of k : “int k = threadIdx.z + blockDim.z * blockDim.z”. It should be “int k = threadIdx.z + blockDim.z * blockIdx.z;”

Thanks for sharing the solution.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.