blockIdx.z returns wrong values

I have the feeling, that the builtin variable blockIdx.z
returns wrong values. It shows numbers != 0
rathet than 0. When there is a grid
with Dimension 1,1,1 there can’t be a blockIdx.z
not equal to 0.
In device Emulation it works.

global static void MyKernel(int *values){
const unsigned int tid = (threadIdx.x ) ;
if(tid==0){
values[tid+0] = blockIdx.x;
values[tid+1] = blockIdx.y;
values[tid+2] = blockIdx.z;
}
}

int dvalues;
int returnvalues[3]={97,98,99};
cudaMalloc((void
*)&dvalues, 3* sizeof(int) );
MyKernel<<<1, 16 >>>(dvalues);
CUDA_SAFE_CALL(cudaMemcpy(returnvalues, dvalues, 3*sizeof(int), CudaMemcpyDeviceToHost));

printf(“%d\n”,returnvalues[0]);
printf(“%d\n”,returnvalues[1]);
printf(“%d\n”,returnvalues[2]);

gives me:
0
0
9728

rather than
0
0
0

The grid is two dimensional only. Using blockIdx.z is illegal.

The thread layout can be three dimensional.

Peter

Thank you. That’s right.
A grid is a grid and not a ‘3D Grid’.

there is an error message,
when starting a Kernel with gridDim.z
not equal to 1.
In chapter 2.2.2 of thr programming guide
it is clearly stated, that a grid is 2D.

After reding: in my eyes the declaration
of gridDim as dim3 just gives room for a future extension
of grids to 3D grids.

Hello Peter,

off course I could find out myself,
but may be you know whether
this blockIdx.z can be of any use.

Thank you.

Not currently. I think it is three dimensional for future extensions.

Peter