mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 08:13:04 +04:00
Merge branch 4.x
This commit is contained in:
@@ -283,24 +283,40 @@ inline IppCmpOp arithm_ipp_convert_cmp(int cmpop)
|
||||
inline int arithm_ipp_cmp8u(const uchar* src1, size_t step1, const uchar* src2, size_t step2,
|
||||
uchar* dst, size_t step, int width, int height, int cmpop)
|
||||
{
|
||||
// perf regression with AVX512: https://github.com/opencv/opencv/issues/28251
|
||||
if (ippCPUID_AVX512F&cv::ipp::getIppFeatures())
|
||||
return 0;
|
||||
|
||||
ARITHM_IPP_CMP(ippiCompare_8u_C1R, src1, (int)step1, src2, (int)step2, dst, (int)step, ippiSize(width, height));
|
||||
}
|
||||
|
||||
inline int arithm_ipp_cmp16u(const ushort* src1, size_t step1, const ushort* src2, size_t step2,
|
||||
uchar* dst, size_t step, int width, int height, int cmpop)
|
||||
{
|
||||
// perf regression with AVX512: https://github.com/opencv/opencv/issues/28251
|
||||
if (ippCPUID_AVX512F&cv::ipp::getIppFeatures())
|
||||
return 0;
|
||||
|
||||
ARITHM_IPP_CMP(ippiCompare_16u_C1R, src1, (int)step1, src2, (int)step2, dst, (int)step, ippiSize(width, height));
|
||||
}
|
||||
|
||||
inline int arithm_ipp_cmp16s(const short* src1, size_t step1, const short* src2, size_t step2,
|
||||
uchar* dst, size_t step, int width, int height, int cmpop)
|
||||
{
|
||||
// perf regression with AVX512: https://github.com/opencv/opencv/issues/28251
|
||||
if (ippCPUID_AVX512F&cv::ipp::getIppFeatures())
|
||||
return 0;
|
||||
|
||||
ARITHM_IPP_CMP(ippiCompare_16s_C1R, src1, (int)step1, src2, (int)step2, dst, (int)step, ippiSize(width, height));
|
||||
}
|
||||
|
||||
inline int arithm_ipp_cmp32f(const float* src1, size_t step1, const float* src2, size_t step2,
|
||||
uchar* dst, size_t step, int width, int height, int cmpop)
|
||||
{
|
||||
// perf regression with AVX512: https://github.com/opencv/opencv/issues/28251
|
||||
if (ippCPUID_AVX512F&cv::ipp::getIppFeatures())
|
||||
return 0;
|
||||
|
||||
ARITHM_IPP_CMP(ippiCompare_32f_C1R, src1, (int)step1, src2, (int)step2, dst, (int)step, ippiSize(width, height));
|
||||
}
|
||||
|
||||
|
||||
@@ -69,10 +69,17 @@
|
||||
#include <sanitizer/msan_interface.h>
|
||||
#define CV_ANNOTATE_MEMORY_IS_INITIALIZED(address, size) \
|
||||
__msan_unpoison(address, size)
|
||||
#define CV_ANNOTATE_NO_SANITIZE_MEMORY __attribute__((no_sanitize("memory")))
|
||||
#endif
|
||||
#endif
|
||||
#ifndef CV_ANNOTATE_MEMORY_IS_INITIALIZED
|
||||
#define CV_ANNOTATE_MEMORY_IS_INITIALIZED(address, size) do { } while(0)
|
||||
#define CV_ANNOTATE_NO_SANITIZE_MEMORY
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__) && defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
|
||||
//lapack stores matrices in column-major order so transposing is needed everywhere
|
||||
@@ -108,8 +115,9 @@ set_value(fptype *dst, size_t dst_ld, fptype value, size_t m, size_t n)
|
||||
dst[i*dst_ld + j] = value;
|
||||
}
|
||||
|
||||
// MSAN can't see that the fortran LAPACK functions initialize `info`
|
||||
template <typename fptype> static inline int
|
||||
lapack_LU(fptype* a, size_t a_step, int m, fptype* b, size_t b_step, int n, int* info)
|
||||
CV_ANNOTATE_NO_SANITIZE_MEMORY lapack_LU(fptype* a, size_t a_step, int m, fptype* b, size_t b_step, int n, int* info)
|
||||
{
|
||||
#if defined (ACCELERATE_NEW_LAPACK) && defined (ACCELERATE_LAPACK_ILP64)
|
||||
cv::AutoBuffer<long> piv_buff(m);
|
||||
@@ -710,4 +718,8 @@ int lapack_gemm64fc(const double *src1, size_t src1_step, const double *src2, si
|
||||
return lapack_gemm_c(src1, src1_step, src2, src2_step, alpha, src3, src3_step, beta, dst, dst_step, m, n, k, flags);
|
||||
}
|
||||
|
||||
#endif //HAVE_LAPACK
|
||||
#if defined(__APPLE__) && defined(__clang__)
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
#endif //HAVE_LAPACK
|
||||
@@ -46,6 +46,8 @@
|
||||
#include <atomic>
|
||||
#include <limits>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include "mathfuncs.hpp"
|
||||
|
||||
namespace cv
|
||||
@@ -1423,12 +1425,21 @@ int cv::solveCubic( InputArray _coeffs, OutputArray _roots )
|
||||
a3 = coeffs.at<double>(i+3);
|
||||
}
|
||||
|
||||
if( a0 == 0 )
|
||||
// Fix for Issue #27748: Normalize coefficients to avoid overflow/underflow
|
||||
// and correctly detect negligible cubic terms.
|
||||
double max_coeff = std::max({std::abs(a0), std::abs(a1), std::abs(a2), std::abs(a3)});
|
||||
|
||||
// If max_coeff is effectively zero, the equation is 0=0
|
||||
if (max_coeff < std::numeric_limits<double>::epsilon())
|
||||
return -1;
|
||||
|
||||
// Check if the cubic term is negligible relative to the largest coefficient
|
||||
if( std::abs(a0) < std::numeric_limits<double>::epsilon() * max_coeff )
|
||||
{
|
||||
if( a1 == 0 )
|
||||
if( std::abs(a1) < std::numeric_limits<double>::epsilon() * max_coeff )
|
||||
{
|
||||
if( a2 == 0 ) // constant
|
||||
n = a3 == 0 ? -1 : 0;
|
||||
if( std::abs(a2) < std::numeric_limits<double>::epsilon() * max_coeff )
|
||||
n = std::abs(a3) < std::numeric_limits<double>::epsilon() * max_coeff ? -1 : 0;
|
||||
else
|
||||
{
|
||||
// linear equation
|
||||
@@ -1445,7 +1456,7 @@ int cv::solveCubic( InputArray _coeffs, OutputArray _roots )
|
||||
d = std::sqrt(d);
|
||||
double q1 = (-a2 + d) * 0.5;
|
||||
double q2 = (a2 + d) * -0.5;
|
||||
if( fabs(q1) > fabs(q2) )
|
||||
if( std::abs(q1) > std::abs(q2) )
|
||||
{
|
||||
x0 = q1 / a1;
|
||||
x1 = a3 / q1;
|
||||
@@ -1462,6 +1473,13 @@ int cv::solveCubic( InputArray _coeffs, OutputArray _roots )
|
||||
else
|
||||
{
|
||||
// cubic equation
|
||||
// Normalize coefficients in-place to prevent overflow/instability
|
||||
double scale = 1.0 / max_coeff;
|
||||
a0 *= scale;
|
||||
a1 *= scale;
|
||||
a2 *= scale;
|
||||
a3 *= scale;
|
||||
|
||||
a0 = 1./a0;
|
||||
a1 *= a0;
|
||||
a2 *= a0;
|
||||
@@ -1470,6 +1488,7 @@ int cv::solveCubic( InputArray _coeffs, OutputArray _roots )
|
||||
double Q = (a1 * a1 - 3 * a2) * (1./9);
|
||||
double R = (a1 * (2 * a1 * a1 - 9 * a2) + 27 * a3) * (1./54);
|
||||
double Qcubed = Q * Q * Q;
|
||||
|
||||
/*
|
||||
Here we expand expression `Qcubed - R * R` for `d` variable
|
||||
to reduce common terms `a1^6 / 729` and `-a1^4 * a2 / 81`
|
||||
|
||||
@@ -93,7 +93,7 @@ static void* AppleCLGetProcAddress(const char* name)
|
||||
handle = dlopen(path.c_str(), RTLD_LAZY | RTLD_GLOBAL);
|
||||
if (handle == NULL)
|
||||
{
|
||||
if (path != NULL && path != defaultPath)
|
||||
if (!path.empty() && path != defaultPath)
|
||||
fprintf(stderr, ERROR_MSG_CANT_LOAD);
|
||||
}
|
||||
else if (dlsym(handle, OPENCL_FUNC_TO_CHECK_1_1) == NULL)
|
||||
|
||||
@@ -465,10 +465,6 @@ namespace {
|
||||
static inline int _initMaxThreads()
|
||||
{
|
||||
int maxThreads = omp_get_max_threads();
|
||||
if (!utils::getConfigurationParameterBool("OPENCV_FOR_OPENMP_DYNAMIC_DISABLE", false))
|
||||
{
|
||||
omp_set_dynamic(1);
|
||||
}
|
||||
return maxThreads;
|
||||
}
|
||||
static int numThreadsMax = _initMaxThreads();
|
||||
|
||||
@@ -179,6 +179,7 @@ const uint64_t AT_HWCAP = NT_GNU_HWCAP;
|
||||
#define _WIN32_WINNT 0x0400 // http://msdn.microsoft.com/en-us/library/ms686857(VS.85).aspx
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#include <combaseapi.h>
|
||||
#if (_WIN32_WINNT >= 0x0602)
|
||||
#include <synchapi.h>
|
||||
#endif
|
||||
@@ -478,6 +479,7 @@ struct HWFeatures
|
||||
g_hwFeatureNames[CPU_NEON_DOTPROD] = "NEON_DOTPROD";
|
||||
g_hwFeatureNames[CPU_NEON_FP16] = "NEON_FP16";
|
||||
g_hwFeatureNames[CPU_NEON_BF16] = "NEON_BF16";
|
||||
g_hwFeatureNames[CPU_SVE] = "SVE";
|
||||
|
||||
g_hwFeatureNames[CPU_VSX] = "VSX";
|
||||
g_hwFeatureNames[CPU_VSX3] = "VSX3";
|
||||
@@ -641,6 +643,7 @@ struct HWFeatures
|
||||
{
|
||||
have[CV_CPU_NEON_DOTPROD] = (auxv.a_un.a_val & (1 << 20)) != 0; // HWCAP_ASIMDDP
|
||||
have[CV_CPU_NEON_FP16] = (auxv.a_un.a_val & (1 << 10)) != 0; // HWCAP_ASIMDHP
|
||||
have[CV_CPU_SVE] = (auxv.a_un.a_val & (1 << 22)) != 0; // HWCAP_SVE
|
||||
}
|
||||
#if defined(AT_HWCAP2)
|
||||
else if (auxv.a_type == AT_HWCAP2)
|
||||
|
||||
Reference in New Issue
Block a user