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;
This commit is contained in:
Pavel Vlasov 2015-09-25 18:00:53 +03:00
parent 34e4e66bf1
commit e837d69f8f
11 changed files with 318 additions and 42 deletions

View File

@ -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. */

View File

@ -645,6 +645,7 @@ namespace cudev
namespace ipp namespace ipp
{ {
CV_EXPORTS int getIppFeatures();
CV_EXPORTS void setIppStatus(int status, const char * const funcname = NULL, const char * const filename = NULL, CV_EXPORTS void setIppStatus(int status, const char * const funcname = NULL, const char * const filename = NULL,
int line = 0); int line = 0);
CV_EXPORTS int getIppStatus(); CV_EXPORTS int getIppStatus();

View File

@ -256,6 +256,42 @@ static inline IppDataType ippiGetDataType(int depth)
#define HAVE_ICV 0 #define HAVE_ICV 0
#endif #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_COND (cv::ipp::useIPP())
#define CV_IPP_CHECK() if(CV_IPP_CHECK_COND) #define CV_IPP_CHECK() if(CV_IPP_CHECK_COND)

View File

@ -42,6 +42,7 @@
//M*/ //M*/
#include "precomp.hpp" #include "precomp.hpp"
#include <iostream>
namespace cv { namespace cv {
@ -377,21 +378,6 @@ bool checkHardwareSupport(int feature)
volatile bool useOptimizedFlag = true; 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_SSE2 = featuresEnabled.have[CV_CPU_SSE2];
volatile bool USE_SSE4_2 = featuresEnabled.have[CV_CPU_SSE4_2]; volatile bool USE_SSE4_2 = featuresEnabled.have[CV_CPU_SSE4_2];
@ -1305,26 +1291,88 @@ void setUseCollection(bool flag)
namespace ipp namespace ipp
{ {
static int ippStatus = 0; // 0 - all is ok, -1 - IPP functions failed struct IPPInitSingelton
static const char * funcname = NULL, * filename = NULL; {
static int linen = 0; 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) void setIppStatus(int status, const char * const _funcname, const char * const _filename, int _line)
{ {
ippStatus = status; getIPPSingelton().ippStatus = status;
funcname = _funcname; getIPPSingelton().funcname = _funcname;
filename = _filename; getIPPSingelton().filename = _filename;
linen = _line; getIPPSingelton().linen = _line;
} }
int getIppStatus() int getIppStatus()
{ {
return ippStatus; return getIPPSingelton().ippStatus;
} }
String getIppErrorLocation() 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() bool useIPP()
@ -1333,11 +1381,7 @@ bool useIPP()
CoreTLSData* data = getCoreTlsData().get(); CoreTLSData* data = getCoreTlsData().get();
if(data->useIPP < 0) if(data->useIPP < 0)
{ {
const char* pIppEnv = getenv("OPENCV_IPP"); data->useIPP = getIPPSingelton().useIPP;
if(pIppEnv && (cv::String(pIppEnv) == "disabled"))
data->useIPP = false;
else
data->useIPP = true;
} }
return (data->useIPP > 0); return (data->useIPP > 0);
#else #else

View File

@ -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. */

View File

@ -100,7 +100,6 @@
#define MAX_IPP8u 255 #define MAX_IPP8u 255
#define MAX_IPP16u 65535 #define MAX_IPP16u 65535
#define MAX_IPP32f 1.0 #define MAX_IPP32f 1.0
static IppStatus sts = ippInit();
#endif #endif
namespace cv namespace cv

View File

@ -43,10 +43,6 @@
#include "precomp.hpp" #include "precomp.hpp"
#include "opencl_kernels_imgproc.hpp" #include "opencl_kernels_imgproc.hpp"
#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7)
static IppStatus sts = ippInit();
#endif
/****************************************************************************************\ /****************************************************************************************\
Sobel & Scharr Derivative Filters Sobel & Scharr Derivative Filters
\****************************************************************************************/ \****************************************************************************************/

View File

@ -50,10 +50,6 @@
#include "precomp.hpp" #include "precomp.hpp"
#include "opencl_kernels_imgproc.hpp" #include "opencl_kernels_imgproc.hpp"
#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7)
static IppStatus sts = ippInit();
#endif
namespace cv namespace cv
{ {
#if IPP_VERSION_X100 >= 710 #if IPP_VERSION_X100 >= 710

View File

@ -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. */

View File

@ -44,10 +44,6 @@
#include "precomp.hpp" #include "precomp.hpp"
#include "opencl_kernels_imgproc.hpp" #include "opencl_kernels_imgproc.hpp"
#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7)
static IppStatus sts = ippInit();
#endif
namespace cv namespace cv
{ {

View File

@ -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. */