     // CHECK_CUDA_ERROR();
 
     // printf("scales %i\n",scales);
-    cudaThreadSynchronize();
 
     // printf("total size of preallocated images in GPU memory: %f\n",(float)allBytes/(1024.0f*1024.0f));
 

            rcDepthMap_dmp.getBuffer(), rcDepthMap_dmp.getPitch(),
            width, height, wsh, gammaC, gammaP, epipShift,
            (float)(i - (ntcsteps - 1) / 2), i, moveByTcOrRc, xFrom, imWidth, imHeight);
        cudaThreadSynchronize();
    };

    refine_setLastThreeSimsMap_kernel<<<grid, block>>>(

            depthMap_dmp.getBuffer(), depthMap_dmp.getPitch(),
            depthMap_dmp.getBuffer(), depthMap_dmp.getPitch(),
            width, height, 0, 0, fpPlaneDepth);
        refine_dilateFPPlaneDepthMapXpYp_kernel<<<grid, block>>>(
            depthMap_dmp.getBuffer(), depthMap_dmp.getPitch(),
            depthMap_dmp.getBuffer(), depthMap_dmp.getPitch(),
            width, height, -1, 0, fpPlaneDepth);
        refine_dilateFPPlaneDepthMapXpYp_kernel<<<grid, block>>>(
            depthMap_dmp.getBuffer(), depthMap_dmp.getPitch(),
            depthMap_dmp.getBuffer(), depthMap_dmp.getPitch(),
            width, height, +1, 0, fpPlaneDepth);
        refine_dilateFPPlaneDepthMapXpYp_kernel<<<grid, block>>>(
            depthMap_dmp.getBuffer(), depthMap_dmp.getPitch(),
            depthMap_dmp.getBuffer(), depthMap_dmp.getPitch(),
            width, height, 0, -1, fpPlaneDepth);
        refine_dilateFPPlaneDepthMapXpYp_kernel<<<grid, block>>>(
            depthMap_dmp.getBuffer(), depthMap_dmp.getPitch(),
            depthMap_dmp.getBuffer(), depthMap_dmp.getPitch(),
            width, height, 0, +1, fpPlaneDepth);
    };

    refine_convertFPPlaneDepthMapToDepthMap_kernel<<<grid, block>>>(
        depthMap_dmp.getBuffer(), depthMap_dmp.getPitch(),
        depthMap_dmp.getBuffer(), depthMap_dmp.getPitch(),
        width, height);
}

void ps_refineDepthMapInternal(CudaDeviceMemoryPitched<float, 2>& osimMap_dmp,
