         __shared__ float sdxabs[25];
         __shared__ float sdyabs[25];
 
+        calc_dx_dy(sdx, sdy, featureX, featureY, featureSize, featureDir);
+        __syncthreads();
+
         const int tid = threadIdx.y * blockDim.x + threadIdx.x;
-
-        calc_dx_dy(sdx, sdy, featureX, featureY, featureSize, featureDir, tid);
-        __syncthreads();
 
         sdxabs[tid] = fabs(sdx[tid]); // |dx| array
         sdyabs[tid] = fabs(sdy[tid]); // |dy| array


        if (threadIdx.x < 5 && threadIdx.y < 5)
        {
            tid = threadIdx.y * 5 + threadIdx.x;

            const float dw = c_DW[yIndex * PATCH_SZ + xIndex];


        __shared__ float sdabs1[25];
        __shared__ float sdabs2[25];

        calc_dx_dy(sdx, sdy, featureX, featureY, featureSize, featureDir);
        __syncthreads();

        const int tid = threadIdx.y * blockDim.x + threadIdx.x;

        if (sdy[tid] >= 0)
        {
