From e837d69f8fa3b465d7a5185900c84c8ce85f00c0 Mon Sep 17 00:00:00 2001 From: Pavel Vlasov Date: Fri, 25 Sep 2015 18:00:53 +0300 Subject: [PATCH] IPPInitSingelton was added to contain IPP related global variables; OPENCV_IPP env var now allows to select IPP architecture level for IPP9+; IPP initialization logic was unified across modules; --- modules/calib3d/src/main.cpp | 52 +++++++++ modules/core/include/opencv2/core/base.hpp | 1 + modules/core/include/opencv2/core/private.hpp | 36 +++++++ modules/core/src/system.cpp | 102 +++++++++++++----- modules/features2d/src/main.cpp | 52 +++++++++ modules/imgproc/src/color.cpp | 1 - modules/imgproc/src/deriv.cpp | 4 - modules/imgproc/src/imgwarp.cpp | 4 - modules/imgproc/src/main.cpp | 52 +++++++++ modules/imgproc/src/sumpixels.cpp | 4 - modules/objdetect/src/main.cpp | 52 +++++++++ 11 files changed, 318 insertions(+), 42 deletions(-) create mode 100644 modules/calib3d/src/main.cpp create mode 100644 modules/features2d/src/main.cpp create mode 100644 modules/imgproc/src/main.cpp create mode 100644 modules/objdetect/src/main.cpp diff --git a/modules/calib3d/src/main.cpp b/modules/calib3d/src/main.cpp new file mode 100644 index 0000000000..127f86b26b --- /dev/null +++ b/modules/calib3d/src/main.cpp @@ -0,0 +1,52 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +// +// Library initialization file +// + +#include "precomp.hpp" + +IPP_INITIALIZER_AUTO + +/* End of file. */ diff --git a/modules/core/include/opencv2/core/base.hpp b/modules/core/include/opencv2/core/base.hpp index 95142c513b..3ab0982ceb 100644 --- a/modules/core/include/opencv2/core/base.hpp +++ b/modules/core/include/opencv2/core/base.hpp @@ -645,6 +645,7 @@ namespace cudev namespace ipp { +CV_EXPORTS int getIppFeatures(); CV_EXPORTS void setIppStatus(int status, const char * const funcname = NULL, const char * const filename = NULL, int line = 0); CV_EXPORTS int getIppStatus(); diff --git a/modules/core/include/opencv2/core/private.hpp b/modules/core/include/opencv2/core/private.hpp index 28f21d4d80..363c76f0d2 100644 --- a/modules/core/include/opencv2/core/private.hpp +++ b/modules/core/include/opencv2/core/private.hpp @@ -256,6 +256,42 @@ static inline IppDataType ippiGetDataType(int depth) #define HAVE_ICV 0 #endif +#if defined HAVE_IPP +#if IPP_VERSION_X100 >= 900 +#define IPP_INITIALIZER(FEAT) \ +{ \ + if(FEAT) \ + ippSetCpuFeatures(FEAT); \ + else \ + ippInit(); \ +} +#elif IPP_VERSION_X100 >= 800 +#define IPP_INITIALIZER(FEAT) \ +{ \ + ippInit(); \ +} +#else +#define IPP_INITIALIZER(FEAT) \ +{ \ + ippStaticInit(); \ +} +#endif + +#ifdef CVAPI_EXPORTS +#define IPP_INITIALIZER_AUTO \ +struct __IppInitializer__ \ +{ \ + __IppInitializer__() \ + {IPP_INITIALIZER(cv::ipp::getIppFeatures())} \ +}; \ +static struct __IppInitializer__ __ipp_initializer__; +#else +#define IPP_INITIALIZER_AUTO +#endif +#else +#define IPP_INITIALIZER +#define IPP_INITIALIZER_AUTO +#endif #define CV_IPP_CHECK_COND (cv::ipp::useIPP()) #define CV_IPP_CHECK() if(CV_IPP_CHECK_COND) diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index 337414918b..623280b327 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -42,6 +42,7 @@ //M*/ #include "precomp.hpp" +#include namespace cv { @@ -377,21 +378,6 @@ bool checkHardwareSupport(int feature) volatile bool useOptimizedFlag = true; -#ifdef HAVE_IPP -struct IPPInitializer -{ - IPPInitializer(void) - { -#if IPP_VERSION_MAJOR >= 8 - ippInit(); -#else - ippStaticInit(); -#endif - } -}; - -IPPInitializer ippInitializer; -#endif volatile bool USE_SSE2 = featuresEnabled.have[CV_CPU_SSE2]; volatile bool USE_SSE4_2 = featuresEnabled.have[CV_CPU_SSE4_2]; @@ -1305,26 +1291,88 @@ void setUseCollection(bool flag) namespace ipp { -static int ippStatus = 0; // 0 - all is ok, -1 - IPP functions failed -static const char * funcname = NULL, * filename = NULL; -static int linen = 0; +struct IPPInitSingelton +{ +public: + IPPInitSingelton() + { + useIPP = true; + ippStatus = 0; + funcname = NULL; + filename = NULL; + linen = 0; + ippFeatures = 0; + +#ifdef HAVE_IPP + const char* pIppEnv = getenv("OPENCV_IPP"); + cv::String env = pIppEnv; + if(env.size()) + { + if(env == "disabled") + { + std::cerr << "WARNING: IPP was disabled by OPENCV_IPP environment variable" << std::endl; + useIPP = false; + } +#if IPP_VERSION_X100 >= 900 + else if(env == "sse") + ippFeatures = ippCPUID_SSE; + else if(env == "sse2") + ippFeatures = ippCPUID_SSE2; + else if(env == "sse42") + ippFeatures = ippCPUID_SSE42; + else if(env == "avx") + ippFeatures = ippCPUID_AVX; + else if(env == "avx2") + ippFeatures = ippCPUID_AVX2; +#endif + else + std::cerr << "ERROR: Improper value of OPENCV_IPP: " << env.c_str() << std::endl; + } + + IPP_INITIALIZER(ippFeatures) +#endif + } + + bool useIPP; + + int ippStatus; // 0 - all is ok, -1 - IPP functions failed + const char *funcname; + const char *filename; + int linen; + int ippFeatures; +}; + +static IPPInitSingelton& getIPPSingelton() +{ + static IPPInitSingelton sing; + return sing; +} + +int getIppFeatures() +{ +#ifdef HAVE_IPP + return getIPPSingelton().ippFeatures; +#else + return 0; +#endif +} void setIppStatus(int status, const char * const _funcname, const char * const _filename, int _line) { - ippStatus = status; - funcname = _funcname; - filename = _filename; - linen = _line; + getIPPSingelton().ippStatus = status; + getIPPSingelton().funcname = _funcname; + getIPPSingelton().filename = _filename; + getIPPSingelton().linen = _line; } int getIppStatus() { - return ippStatus; + return getIPPSingelton().ippStatus; } String getIppErrorLocation() { - return format("%s:%d %s", filename ? filename : "", linen, funcname ? funcname : ""); + return format("%s:%d %s", getIPPSingelton().filename ? getIPPSingelton().filename : "", getIPPSingelton().linen, getIPPSingelton().funcname ? getIPPSingelton().funcname : ""); } bool useIPP() @@ -1333,11 +1381,7 @@ bool useIPP() CoreTLSData* data = getCoreTlsData().get(); if(data->useIPP < 0) { - const char* pIppEnv = getenv("OPENCV_IPP"); - if(pIppEnv && (cv::String(pIppEnv) == "disabled")) - data->useIPP = false; - else - data->useIPP = true; + data->useIPP = getIPPSingelton().useIPP; } return (data->useIPP > 0); #else diff --git a/modules/features2d/src/main.cpp b/modules/features2d/src/main.cpp new file mode 100644 index 0000000000..127f86b26b --- /dev/null +++ b/modules/features2d/src/main.cpp @@ -0,0 +1,52 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +// +// Library initialization file +// + +#include "precomp.hpp" + +IPP_INITIALIZER_AUTO + +/* End of file. */ diff --git a/modules/imgproc/src/color.cpp b/modules/imgproc/src/color.cpp index df6a59d876..27d602e0d2 100644 --- a/modules/imgproc/src/color.cpp +++ b/modules/imgproc/src/color.cpp @@ -100,7 +100,6 @@ #define MAX_IPP8u 255 #define MAX_IPP16u 65535 #define MAX_IPP32f 1.0 -static IppStatus sts = ippInit(); #endif namespace cv diff --git a/modules/imgproc/src/deriv.cpp b/modules/imgproc/src/deriv.cpp index b2f2bd4975..2fcdabeaaa 100644 --- a/modules/imgproc/src/deriv.cpp +++ b/modules/imgproc/src/deriv.cpp @@ -43,10 +43,6 @@ #include "precomp.hpp" #include "opencl_kernels_imgproc.hpp" -#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7) -static IppStatus sts = ippInit(); -#endif - /****************************************************************************************\ Sobel & Scharr Derivative Filters \****************************************************************************************/ diff --git a/modules/imgproc/src/imgwarp.cpp b/modules/imgproc/src/imgwarp.cpp index 9c16f91a20..e7ee0c677a 100644 --- a/modules/imgproc/src/imgwarp.cpp +++ b/modules/imgproc/src/imgwarp.cpp @@ -50,10 +50,6 @@ #include "precomp.hpp" #include "opencl_kernels_imgproc.hpp" -#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7) -static IppStatus sts = ippInit(); -#endif - namespace cv { #if IPP_VERSION_X100 >= 710 diff --git a/modules/imgproc/src/main.cpp b/modules/imgproc/src/main.cpp new file mode 100644 index 0000000000..127f86b26b --- /dev/null +++ b/modules/imgproc/src/main.cpp @@ -0,0 +1,52 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +// +// Library initialization file +// + +#include "precomp.hpp" + +IPP_INITIALIZER_AUTO + +/* End of file. */ diff --git a/modules/imgproc/src/sumpixels.cpp b/modules/imgproc/src/sumpixels.cpp index a6e86f6c04..8a667d2912 100755 --- a/modules/imgproc/src/sumpixels.cpp +++ b/modules/imgproc/src/sumpixels.cpp @@ -44,10 +44,6 @@ #include "precomp.hpp" #include "opencl_kernels_imgproc.hpp" -#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7) -static IppStatus sts = ippInit(); -#endif - namespace cv { diff --git a/modules/objdetect/src/main.cpp b/modules/objdetect/src/main.cpp new file mode 100644 index 0000000000..127f86b26b --- /dev/null +++ b/modules/objdetect/src/main.cpp @@ -0,0 +1,52 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +// +// Library initialization file +// + +#include "precomp.hpp" + +IPP_INITIALIZER_AUTO + +/* End of file. */ -- GitLab