             __syncthreads();
 
             histogramMultipleAdd8(HCoarse,histCoarse, 2*r+1);
-//            __syncthreads();
             int cols_m_1=cols-1;
 
              for(int j=r;j<cols-r;j++){

                Hscan[tx]=H[tx];
            }
            __syncthreads();
            if (1 <= tx && tx < 8 )
                Hscan[tx]+=Hscan[tx-1];
            __syncthreads();
            if (2 <= tx && tx < 8 )
                Hscan[tx]+=Hscan[tx-2];
            __syncthreads();
            if (4 <= tx && tx < 8 )
                Hscan[tx]+=Hscan[tx-4];
            __syncthreads();

            if(tx<7){
                if(Hscan[tx+1] > medPos && Hscan[tx] < medPos){
                    *retval=tx+1;
                    *countAtMed=Hscan[tx];
                }
                else if(Hscan[tx]==medPos){
                  if(Hscan[tx+1]>medPos){
                     *retval=tx+1;
                     *countAtMed=Hscan[tx];
                  }
                }
            }
        }

        __device__ void histogramMedianPar32LookupOnly(int* H,int* Hscan, const int medPos,int* retval, int* countAtMed){


namespace cv { namespace cuda { namespace device
{
        __device__ void histogramAddAndSub8(int* H, const int * hist_colAdd,const int * hist_colSub){
            int tx = threadIdx.x;
            if (tx<8){
