Merge pull request #3823 from lupustr3:pvlasov/implementation_detector_update

pull/3848/head
Vadim Pisarevsky 10 years ago
commit 9997e6d337
  1. 2
      modules/core/include/opencv2/core/utility.hpp
  2. 30
      modules/core/src/precomp.hpp
  3. 45
      modules/core/src/system.cpp

@ -61,7 +61,7 @@ CV_EXPORTS void addImpl(int flag, const char* func = 0); // add implementation a
// Each implementation entry correspond to function name entry, so you can find which implementation was executed in which fucntion
CV_EXPORTS int getImpl(std::vector<int> &impl, std::vector<String> &funName);
CV_EXPORTS bool useCollection(); // return implementation colelction state
CV_EXPORTS bool useCollection(); // return implementation collection state
CV_EXPORTS void setUseCollection(bool flag); // set implementation collection state
#define CV_IMPL_PLAIN 0x01 // native CPU OpenCV implementation

@ -232,15 +232,30 @@ inline bool checkScalar(InputArray sc, int atype, int sckind, int akind)
void convertAndUnrollScalar( const Mat& sc, int buftype, uchar* scbuf, size_t blocksize );
#ifdef CV_COLLECT_IMPL_DATA
struct ImplCollector
{
ImplCollector()
{
useCollection = false;
implFlags = 0;
}
bool useCollection; // enable/disable impl data collection
int implFlags;
std::vector<int> implCode;
std::vector<String> implFun;
cv::Mutex mutex;
};
#endif
struct CoreTLSData
{
CoreTLSData() : device(0), useOpenCL(-1), useIPP(-1), useCollection(false)
CoreTLSData() : device(0), useOpenCL(-1), useIPP(-1)
{
#ifdef HAVE_TEGRA_OPTIMIZATION
useTegra = -1;
#endif
#ifdef CV_COLLECT_IMPL_DATA
implFlags = 0;
#endif
}
@ -251,13 +266,6 @@ struct CoreTLSData
int useIPP; // 1 - use, 0 - do not use, -1 - auto/not initialized
#ifdef HAVE_TEGRA_OPTIMIZATION
int useTegra; // 1 - use, 0 - do not use, -1 - auto/not initialized
#endif
bool useCollection; // enable/disable impl data collection
#ifdef CV_COLLECT_IMPL_DATA
int implFlags;
std::vector<int> implCode;
std::vector<String> implFun;
#endif
};

@ -1163,47 +1163,56 @@ TLSData<CoreTLSData>& getCoreTlsData()
#ifdef CV_COLLECT_IMPL_DATA
ImplCollector& getImplData()
{
static ImplCollector *value = new ImplCollector();
return *value;
}
void setImpl(int flags)
{
CoreTLSData* data = getCoreTlsData().get();
data->implFlags = flags;
data->implCode.clear();
data->implFun.clear();
cv::AutoLock lock(getImplData().mutex);
getImplData().implFlags = flags;
getImplData().implCode.clear();
getImplData().implFun.clear();
}
void addImpl(int flag, const char* func)
{
CoreTLSData* data = getCoreTlsData().get();
data->implFlags |= flag;
cv::AutoLock lock(getImplData().mutex);
getImplData().implFlags |= flag;
if(func) // use lazy collection if name was not specified
{
size_t index = data->implCode.size();
if(!index || (data->implCode[index-1] != flag || data->implFun[index-1].compare(func))) // avoid duplicates
size_t index = getImplData().implCode.size();
if(!index || (getImplData().implCode[index-1] != flag || getImplData().implFun[index-1].compare(func))) // avoid duplicates
{
data->implCode.push_back(flag);
data->implFun.push_back(func);
getImplData().implCode.push_back(flag);
getImplData().implFun.push_back(func);
}
}
}
int getImpl(std::vector<int> &impl, std::vector<String> &funName)
{
CoreTLSData* data = getCoreTlsData().get();
impl = data->implCode;
funName = data->implFun;
return data->implFlags; // return actual flags for lazy collection
cv::AutoLock lock(getImplData().mutex);
impl = getImplData().implCode;
funName = getImplData().implFun;
return getImplData().implFlags; // return actual flags for lazy collection
}
bool useCollection()
{
CoreTLSData* data = getCoreTlsData().get();
return data->useCollection;
return getImplData().useCollection;
}
void setUseCollection(bool flag)
{
CoreTLSData* data = getCoreTlsData().get();
data->useCollection = flag;
cv::AutoLock lock(getImplData().mutex);
getImplData().useCollection = flag;
}
#endif

Loading…
Cancel
Save