提交 e837d69f 编写于 作者: P Pavel Vlasov

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;
上级 34e4e66b
/*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. */
......@@ -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();
......
......@@ -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)
......
......@@ -42,6 +42,7 @@
//M*/
#include "precomp.hpp"
#include <iostream>
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
......
/*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. */
......@@ -100,7 +100,6 @@
#define MAX_IPP8u 255
#define MAX_IPP16u 65535
#define MAX_IPP32f 1.0
static IppStatus sts = ippInit();
#endif
namespace cv
......
......@@ -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
\****************************************************************************************/
......
......@@ -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
......
/*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. */
......@@ -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
{
......
/*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. */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册