 
             unsigned int* minSSDImage = cminSSDImage + X + Y * cminSSD_step;
             unsigned char* disparImage = disp.data + X + Y * disp.step;
-         /*   if (X < cwidth)
-            {
-                unsigned int *minSSDImage_end = minSSDImage + min(ROWSperTHREAD, cheight - Y) * minssd_step;
-                for(uint *ptr = minSSDImage; ptr != minSSDImage_end; ptr += minssd_step )
-                    *ptr = 0xFFFFFFFF;
-            }*/
+            //if (X < cwidth)
+            //{
+            //    unsigned int *minSSDImage_end = minSSDImage + min(ROWSperTHREAD, cheight - Y) * minssd_step;
+            //    for(uint *ptr = minSSDImage; ptr != minSSDImage_end; ptr += minssd_step )
+            //        *ptr = 0xFFFFFFFF;
+            //}
             int end_row = ::min(ROWSperTHREAD, cheight - Y - RADIUS);
             int y_tex;
             int x_tex = X - RADIUS;


                    __syncthreads(); //before MinSSD function

                    if (X < cwidth - RADIUS && row < cheight - RADIUS - Y)
                    {
                        int idx = row * cminSSD_step;
                        uint2 minSSD = MinSSD<RADIUS>(col_ssd_cache + threadIdx.x, col_ssd);
                        if (minSSD.x < minSSDImage[idx])
                        {
                            disparImage[disp.step * row] = (unsigned char)(d + minSSD.y);
                            minSSDImage[idx] = minSSD.x;
                        }
                    }
                } // for row loop
            } // for d loop
        }



                __syncthreads(); //before MinSSD function

                if (Y < cheight - RADIUS)
                {
                    uint2 minSSD = MinSSD<RADIUS>(col_ssd_cache + threadIdx.x, col_ssd, X);

                    // For threads that do not satisfy the if condition below("X < cwidth - RADIUS"), previously
                    // computed "minSSD" value, which is the result of "MinSSD" function call, is not used at all.
                    //
                    // However, since the "MinSSD" function has "__syncthreads" call in its body, those threads
                    // must also call "MinSSD" to avoid deadlock. (#13850)
                    //
                    // From CUDA 9, using "__syncwarp" with proper mask value instead of using "__syncthreads"
                    // could be an option, but the shared memory access pattern does not allow this option,
                    // resulting in race condition. (Checked via "cuda-memcheck --tool racecheck")

                    if (X < cwidth - RADIUS)
                    {
                        if (minSSD.x < minSSDImage[0])
                        {
                            disparImage[0] = (unsigned char)(d + minSSD.y);
                            minSSDImage[0] = minSSD.x;
                        }
                    }
                }

