Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
alalek committed Oct 8, 2021
2 parents e0cfaee + 17bd9a1 commit cca4c47
Show file tree
Hide file tree
Showing 12 changed files with 192 additions and 158 deletions.
2 changes: 2 additions & 0 deletions cmake/OpenCVDetectCXXCompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ elseif(MSVC)
set(OpenCV_RUNTIME vc15)
elseif(MSVC_VERSION MATCHES "^192[0-9]$")
set(OpenCV_RUNTIME vc16)
elseif(MSVC_VERSION MATCHES "^193[0-9]$")
set(OpenCV_RUNTIME vc17)
else()
message(WARNING "OpenCV does not recognize MSVC_VERSION \"${MSVC_VERSION}\". Cannot set OpenCV_RUNTIME")
endif()
Expand Down
14 changes: 14 additions & 0 deletions cmake/templates/OpenCVConfig.root-WIN32.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,20 @@ elseif(MSVC)
set(OpenCV_RUNTIME vc14) # selecting previous compatible runtime version
endif()
endif()
elseif(MSVC_VERSION MATCHES "^193[0-9]$")
set(OpenCV_RUNTIME vc17)
check_one_config(has_VS2022)
if(NOT has_VS2022)
set(OpenCV_RUNTIME vc16)
check_one_config(has_VS2019)
if(NOT has_VS2019)
set(OpenCV_RUNTIME vc15) # selecting previous compatible runtime version
check_one_config(has_VS2017)
if(NOT has_VS2017)
set(OpenCV_RUNTIME vc14) # selecting previous compatible runtime version
endif()
endif()
endif()
endif()
elseif(MINGW)
set(OpenCV_RUNTIME mingw)
Expand Down
4 changes: 2 additions & 2 deletions modules/core/src/parallel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
#endif

#if defined __unix__ || defined __APPLE__ || defined __GLIBC__ \
|| defined __HAIKU__ || defined __EMSCRIPTEN__ || defined __FreeBSD__ \
|| defined __OpenBSD__
|| defined __HAIKU__ || defined __EMSCRIPTEN__ \
|| defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
Expand Down
119 changes: 71 additions & 48 deletions modules/core/src/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@

#include <opencv2/core/utils/filesystem.private.hpp>

#ifndef OPENCV_WITH_THREAD_SANITIZER
#if defined(__clang__) && defined(__has_feature)
#if __has_feature(thread_sanitizer)
#define OPENCV_WITH_THREAD_SANITIZER 1
#include <atomic> // assume C++11
#endif
#endif
#endif
#ifndef OPENCV_WITH_THREAD_SANITIZER
#define OPENCV_WITH_THREAD_SANITIZER 0
#endif

namespace cv {

static void _initSystem()
Expand Down Expand Up @@ -1383,80 +1395,78 @@ namespace details {
#endif
#endif

template <class T>
class DisposedSingletonMark
{
private:
static bool mark;
protected:
DisposedSingletonMark() {}
~DisposedSingletonMark()
{
mark = true;
}
public:
static bool isDisposed() { return mark; }
};

// TLS platform abstraction layer
class TlsAbstraction : public DisposedSingletonMark<TlsAbstraction>
class TlsAbstraction
{
public:
TlsAbstraction();
~TlsAbstraction();
void* getData() const
{
if (isDisposed()) // guard: static initialization order fiasco
return NULL;
return getData_();
}
void setData(void *pData)
~TlsAbstraction()
{
if (isDisposed()) // guard: static initialization order fiasco
return;
return setData_(pData);
// TlsAbstraction singleton should not be released
// There is no reliable way to avoid problems caused by static initialization order fiasco
// NB: Do NOT use logging here
fprintf(stderr, "OpenCV FATAL: TlsAbstraction::~TlsAbstraction() call is not expected\n");
fflush(stderr);
}

void* getData() const;
void setData(void *pData);

void releaseSystemResources();

private:
void* getData_() const;
void setData_(void *pData);

#ifdef _WIN32
#ifndef WINRT
DWORD tlsKey;
bool disposed;
#endif
#else // _WIN32
pthread_key_t tlsKey;
#if OPENCV_WITH_THREAD_SANITIZER
std::atomic<bool> disposed;
#else
bool disposed;
#endif
#endif
};

template<> bool DisposedSingletonMark<TlsAbstraction>::mark = false;

static TlsAbstraction& getTlsAbstraction_()
class TlsAbstractionReleaseGuard
{
static TlsAbstraction g_tls; // disposed in atexit() handlers (required for unregistering our callbacks)
return g_tls;
}
TlsAbstraction& tls_;
public:
TlsAbstractionReleaseGuard(TlsAbstraction& tls) : tls_(tls)
{
/* nothing */
}
~TlsAbstractionReleaseGuard()
{
tls_.releaseSystemResources();
}
};

// TODO use reference
static TlsAbstraction* getTlsAbstraction()
{
static TlsAbstraction* instance = &getTlsAbstraction_();
return DisposedSingletonMark<TlsAbstraction>::isDisposed() ? NULL : instance;
static TlsAbstraction *g_tls = new TlsAbstraction(); // memory leak is intended here to avoid disposing of TLS container
static TlsAbstractionReleaseGuard g_tlsReleaseGuard(*g_tls);
return g_tls;
}


#ifdef _WIN32
#ifdef WINRT
static __declspec( thread ) void* tlsData = NULL; // using C++11 thread attribute for local thread data
TlsAbstraction::TlsAbstraction() {}
TlsAbstraction::~TlsAbstraction()
void TlsAbstraction::releaseSystemResources()
{
cv::__termination = true; // DllMain is missing in static builds
}
void* TlsAbstraction::getData_() const
void* TlsAbstraction::getData() const
{
return tlsData;
}
void TlsAbstraction::setData_(void *pData)
void TlsAbstraction::setData(void *pData)
{
tlsData = pData;
}
Expand All @@ -1465,6 +1475,7 @@ void TlsAbstraction::setData_(void *pData)
static void NTAPI opencv_fls_destructor(void* pData);
#endif // CV_USE_FLS
TlsAbstraction::TlsAbstraction()
: disposed(false)
{
#ifndef CV_USE_FLS
tlsKey = TlsAlloc();
Expand All @@ -1473,26 +1484,31 @@ TlsAbstraction::TlsAbstraction()
#endif // CV_USE_FLS
CV_Assert(tlsKey != TLS_OUT_OF_INDEXES);
}
TlsAbstraction::~TlsAbstraction()
void TlsAbstraction::releaseSystemResources()
{
cv::__termination = true; // DllMain is missing in static builds
disposed = true;
#ifndef CV_USE_FLS
TlsFree(tlsKey);
#else // CV_USE_FLS
FlsFree(tlsKey);
#endif // CV_USE_FLS
tlsKey = TLS_OUT_OF_INDEXES;
}
void* TlsAbstraction::getData_() const
void* TlsAbstraction::getData() const
{
if (disposed)
return NULL;
#ifndef CV_USE_FLS
return TlsGetValue(tlsKey);
#else // CV_USE_FLS
return FlsGetValue(tlsKey);
#endif // CV_USE_FLS
}
void TlsAbstraction::setData_(void *pData)
void TlsAbstraction::setData(void *pData)
{
if (disposed)
return; // no-op
#ifndef CV_USE_FLS
CV_Assert(TlsSetValue(tlsKey, pData) == TRUE);
#else // CV_USE_FLS
Expand All @@ -1503,25 +1519,31 @@ void TlsAbstraction::setData_(void *pData)
#else // _WIN32
static void opencv_tls_destructor(void* pData);
TlsAbstraction::TlsAbstraction()
: disposed(false)
{
CV_Assert(pthread_key_create(&tlsKey, opencv_tls_destructor) == 0);
}
TlsAbstraction::~TlsAbstraction()
void TlsAbstraction::releaseSystemResources()
{
cv::__termination = true; // DllMain is missing in static builds
disposed = true;
if (pthread_key_delete(tlsKey) != 0)
{
// Don't use logging here
fprintf(stderr, "OpenCV ERROR: TlsAbstraction::~TlsAbstraction(): pthread_key_delete() call failed\n");
fflush(stderr);
}
}
void* TlsAbstraction::getData_() const
void* TlsAbstraction::getData() const
{
if (disposed)
return NULL;
return pthread_getspecific(tlsKey);
}
void TlsAbstraction::setData_(void *pData)
void TlsAbstraction::setData(void *pData)
{
if (disposed)
return; // no-op
CV_Assert(pthread_setspecific(tlsKey, pData) == 0);
}
#endif
Expand Down Expand Up @@ -1549,6 +1571,7 @@ class TlsStorage
TlsStorage() :
tlsSlotsSize(0)
{
(void)getTlsAbstraction(); // ensure singeton initialization (for correct order of atexit calls)
tlsSlots.reserve(32);
threads.reserve(32);
g_isTlsStorageInitialized = true;
Expand Down Expand Up @@ -1786,11 +1809,11 @@ static void WINAPI opencv_fls_destructor(void* pData)
#endif // CV_USE_FLS
#endif // _WIN32

static TlsAbstraction* const g_force_initialization_of_TlsAbstraction
static TlsStorage* const g_force_initialization_of_TlsStorage
#if defined __GNUC__
__attribute__((unused))
#endif
= getTlsAbstraction();
= &getTlsStorage();


#else // OPENCV_DISABLE_THREAD_SUPPORT
Expand Down
20 changes: 20 additions & 0 deletions modules/dnn/src/layers/convolution_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "../ie_ngraph.hpp"
#include "../op_vkcom.hpp"

#include <opencv2/core/utils/configuration.private.hpp>
#include <opencv2/core/utils/logger.hpp>

#include "opencv2/core/hal/hal.hpp"
Expand Down Expand Up @@ -1736,7 +1737,26 @@ class ConvolutionLayerImpl CV_FINAL : public BaseConvolutionLayerImpl
config.pad = pad;
config.stride = stride;
config.dilation = dilation;
if (inputs[0].dims != 4 && inputs[0].dims != umat_blobs[0].dims)
{
static bool bypassCheck = utils::getConfigurationParameterBool("OPENCV_OCL4DNN_CONVOLUTION_IGNORE_INPUT_DIMS_4_CHECK", false);
if (!bypassCheck)
{
CV_LOG_ERROR(NULL, "DNN/OpenCL: Unsupported configuration: inputs[0].dims=" << inputs[0].dims << " umat_blobs[0].dims=" << umat_blobs[0].dims
<< ". Consider reporting complete reproducer to https://github.com/opencv/opencv/issues/20833."
<< " You can skip this check temporary through OPENCV_OCL4DNN_CONVOLUTION_IGNORE_INPUT_DIMS_4_CHECK=1"
);
return false;
}
}
config.group = inputs[0].size[1] / umat_blobs[0].size[1];
if (config.group < 1) // config.group == 0 causes div by zero in ocl4dnn code
{
CV_LOG_WARNING(NULL, "DNN/OpenCL: Unsupported config.group=" << config.group
<< ". Consider reporting complete reproducer to https://github.com/opencv/opencv/issues/20833"
);
return false;
}
config.bias_term = umat_blobs.size() == 2;
config.use_half = use_half;

Expand Down
2 changes: 0 additions & 2 deletions modules/dnn/src/ocl4dnn/include/ocl4dnn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,6 @@ class OCL4DNNConvSpatial
bool createDWConvKernel(int32_t blockWidth,
int32_t blockHeight,
int32_t blockDepth);
void CreateSubBuffer(const UMat& buffer, UMat& sub_buffer,
int32_t offset, int32_t size, bool write_only);
bool convolve(const UMat &bottom, UMat &top,
const UMat &weight, const UMat &bias,
int32_t numImages,
Expand Down
Loading

0 comments on commit cca4c47

Please sign in to comment.