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 // 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 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 CV_EXPORTS void setUseCollection(bool flag); // set implementation collection state
#define CV_IMPL_PLAIN 0x01 // native CPU OpenCV implementation #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 ); 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 struct CoreTLSData
{ {
CoreTLSData() : device(0), useOpenCL(-1), useIPP(-1), useCollection(false) CoreTLSData() : device(0), useOpenCL(-1), useIPP(-1)
{ {
#ifdef HAVE_TEGRA_OPTIMIZATION #ifdef HAVE_TEGRA_OPTIMIZATION
useTegra = -1; useTegra = -1;
#endif
#ifdef CV_COLLECT_IMPL_DATA
implFlags = 0;
#endif #endif
} }
@ -251,13 +266,6 @@ struct CoreTLSData
int useIPP; // 1 - use, 0 - do not use, -1 - auto/not initialized int useIPP; // 1 - use, 0 - do not use, -1 - auto/not initialized
#ifdef HAVE_TEGRA_OPTIMIZATION #ifdef HAVE_TEGRA_OPTIMIZATION
int useTegra; // 1 - use, 0 - do not use, -1 - auto/not initialized 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 #endif
}; };

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

Loading…
Cancel
Save