   __shared__ int m;
 
   int block_tid = blockDim.x * threadIdx.y + threadIdx.x;
-  int tid = block_tid + (blockIdx.x*blockDim.x*blockDim.y)+(blockIdx.y*blockDim.x*blockDim.y*gridDim.x);
+  int tid = block_tid + (blockIdx.x*blockDim.x) + (blockIdx.y*blockDim.x*blockDim.y*gridDim.x);
   
   ///pixel index of this thread
   int2 pos;

  sliceIdx.x = threadIdx.x+1;
  sliceIdx.y = threadIdx.y+1;
  int edge;
  int i;

  ///load center
  s_slice[sliceIdx.y][sliceIdx.x] = hys_img[pixIdx];

  s_modified[block_tid] = 1;

  do{

    if ((threadIdx.x + threadIdx.y) == 0) m = 0;

    if (m){
      //store center
      hys_img[pixIdx] = s_slice[sliceIdx.x][sliceIdx.y];
    }

    if((!i) || m){

     ///load top
      if(!threadIdx.y){
        if(!threadIdx.x){
          s_slice[0][0] = ((pos.x>0)||(pos.y>0)) * hys_img[pixIdx-size.x-1];///<TL

  int blocksPerGrid = (size.z + threadsPerBlock -1) >> 8;
  dim3 DimBlock(threadsPerBlock);
  dim3 DimGrid(blocksPerGrid);
  int nBlocks = blocksPerGrid;

  int threadsPerBlockDim = 16;
  int blocksPerGridX = ((size.x) + threadsPerBlockDim -1) >> 4;
  int blocksPerGridY = ((size.y) + threadsPerBlockDim -1) >> 4;
  dim3 TwoDimBlock(16,16,1);
  dim3 TwoDimGrid(blocksPerGridX,blocksPerGridY,1);

