         if ((x < cols * channels ) && (y < rows))
             if (mask[y * step_mask + x / channels] != 0)
             {
-                size_t idx = y * (step / sizeof(T)) + x;
+                size_t idx = y * ( step >> shift_and_sizeof<T>::shift ) + x;
                 mat[idx] = scalar_d[ x % channels ];
             }
     }

    ////////////////////////////////// SetTo //////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////

    template<typename T>
    __global__ void kernel_set_to_without_mask(T * mat, int cols, int rows, int step, int channels)
    {


                SetToFunc_without_mask func = tab[depth];

                if (func == 0)
                    cv::gpu::error("Unsupported convert operation", __FILE__, __LINE__);

                func(mat, channels, stream);
