2011-01-24 18:33:01 +08:00
|
|
|
#include <iomanip>
|
2011-01-26 19:37:54 +08:00
|
|
|
#include <stdexcept>
|
2011-03-03 21:46:44 +08:00
|
|
|
#include <string>
|
2011-01-24 18:33:01 +08:00
|
|
|
#include "performance.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace cv;
|
|
|
|
|
|
|
|
void TestSystem::run()
|
|
|
|
{
|
2011-10-03 22:05:52 +08:00
|
|
|
if (is_list_mode_)
|
|
|
|
{
|
|
|
|
for (vector<Runnable*>::iterator it = tests_.begin(); it != tests_.end(); ++it)
|
|
|
|
cout << (*it)->name() << endl;
|
2012-01-11 16:58:39 +08:00
|
|
|
|
2011-10-03 22:05:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run test initializers
|
|
|
|
for (vector<Runnable*>::iterator it = inits_.begin(); it != inits_.end(); ++it)
|
2011-01-26 15:49:56 +08:00
|
|
|
{
|
2011-02-17 23:25:50 +08:00
|
|
|
if ((*it)->name().find(test_filter_, 0) != string::npos)
|
|
|
|
(*it)->run();
|
2011-01-26 15:49:56 +08:00
|
|
|
}
|
2011-01-25 22:43:54 +08:00
|
|
|
|
2011-01-26 16:12:06 +08:00
|
|
|
printHeading();
|
2011-01-24 18:33:01 +08:00
|
|
|
|
2011-01-25 22:43:54 +08:00
|
|
|
// Run tests
|
2011-10-03 22:05:52 +08:00
|
|
|
for (vector<Runnable*>::iterator it = tests_.begin(); it != tests_.end(); ++it)
|
2011-01-24 18:33:01 +08:00
|
|
|
{
|
2011-01-25 23:11:01 +08:00
|
|
|
try
|
|
|
|
{
|
2011-02-17 23:25:50 +08:00
|
|
|
if ((*it)->name().find(test_filter_, 0) != string::npos)
|
|
|
|
{
|
|
|
|
cout << endl << (*it)->name() << ":\n";
|
|
|
|
(*it)->run();
|
|
|
|
finishCurrentSubtest();
|
|
|
|
}
|
2011-01-25 23:11:01 +08:00
|
|
|
}
|
2011-01-26 19:37:54 +08:00
|
|
|
catch (const Exception&)
|
2011-01-25 23:11:01 +08:00
|
|
|
{
|
2011-01-26 19:37:54 +08:00
|
|
|
// Message is printed via callback
|
2011-02-17 23:25:50 +08:00
|
|
|
resetCurrentSubtest();
|
2011-01-26 19:37:54 +08:00
|
|
|
}
|
|
|
|
catch (const runtime_error& e)
|
|
|
|
{
|
|
|
|
printError(e.what());
|
2011-02-17 23:25:50 +08:00
|
|
|
resetCurrentSubtest();
|
2011-01-25 23:11:01 +08:00
|
|
|
}
|
2011-01-24 18:33:01 +08:00
|
|
|
}
|
|
|
|
|
2011-01-26 16:12:06 +08:00
|
|
|
printSummary();
|
2011-01-24 18:33:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-17 23:25:50 +08:00
|
|
|
void TestSystem::finishCurrentSubtest()
|
2011-01-24 18:33:01 +08:00
|
|
|
{
|
2011-02-17 23:25:50 +08:00
|
|
|
if (cur_subtest_is_empty_)
|
|
|
|
// There is no need to print subtest statistics
|
2011-01-24 18:33:01 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
int cpu_time = static_cast<int>(cpu_elapsed_ / getTickFrequency() * 1000.0);
|
|
|
|
int gpu_time = static_cast<int>(gpu_elapsed_ / getTickFrequency() * 1000.0);
|
|
|
|
|
2011-02-17 23:25:50 +08:00
|
|
|
double speedup = static_cast<double>(cpu_elapsed_) /
|
|
|
|
std::max((int64)1, gpu_elapsed_);
|
2011-01-25 17:54:17 +08:00
|
|
|
speedup_total_ += speedup;
|
|
|
|
|
2011-02-17 23:25:50 +08:00
|
|
|
printMetrics(cpu_time, gpu_time, speedup);
|
2011-01-26 16:12:06 +08:00
|
|
|
|
|
|
|
num_subtests_called_++;
|
2011-02-17 23:25:50 +08:00
|
|
|
resetCurrentSubtest();
|
2011-01-26 16:12:06 +08:00
|
|
|
}
|
2011-01-24 18:33:01 +08:00
|
|
|
|
2011-01-26 16:12:06 +08:00
|
|
|
|
|
|
|
void TestSystem::printHeading()
|
|
|
|
{
|
|
|
|
cout << setiosflags(ios_base::left);
|
|
|
|
cout << TAB << setw(10) << "CPU, ms" << setw(10) << "GPU, ms"
|
2011-01-26 19:37:54 +08:00
|
|
|
<< setw(14) << "SPEEDUP"
|
2011-01-26 16:12:06 +08:00
|
|
|
<< "DESCRIPTION\n";
|
|
|
|
cout << resetiosflags(ios_base::left);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TestSystem::printSummary()
|
|
|
|
{
|
|
|
|
cout << setiosflags(ios_base::fixed);
|
|
|
|
cout << "\naverage GPU speedup: x"
|
2011-01-26 23:28:42 +08:00
|
|
|
<< setprecision(3) << speedup_total_ / std::max(1, num_subtests_called_)
|
2011-01-26 16:12:06 +08:00
|
|
|
<< endl;
|
|
|
|
cout << resetiosflags(ios_base::fixed);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-17 23:25:50 +08:00
|
|
|
void TestSystem::printMetrics(double cpu_time, double gpu_time, double speedup)
|
2011-01-26 16:12:06 +08:00
|
|
|
{
|
|
|
|
cout << TAB << setiosflags(ios_base::left);
|
2011-01-24 18:33:01 +08:00
|
|
|
stringstream stream;
|
2011-01-26 15:49:56 +08:00
|
|
|
|
2011-01-24 18:33:01 +08:00
|
|
|
stream << cpu_time;
|
|
|
|
cout << setw(10) << stream.str();
|
|
|
|
|
|
|
|
stream.str("");
|
|
|
|
stream << gpu_time;
|
|
|
|
cout << setw(10) << stream.str();
|
|
|
|
|
|
|
|
stream.str("");
|
|
|
|
stream << "x" << setprecision(3) << speedup;
|
2011-01-26 19:37:54 +08:00
|
|
|
cout << setw(14) << stream.str();
|
2011-01-24 18:33:01 +08:00
|
|
|
|
2011-02-17 23:25:50 +08:00
|
|
|
cout << cur_subtest_description_.str();
|
2011-01-26 15:49:56 +08:00
|
|
|
cout << resetiosflags(ios_base::left) << endl;
|
2011-01-24 18:33:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-26 19:37:54 +08:00
|
|
|
void TestSystem::printError(const std::string& msg)
|
|
|
|
{
|
2011-02-17 23:25:50 +08:00
|
|
|
cout << TAB << "[error: " << msg << "] " << cur_subtest_description_.str() << endl;
|
2011-01-26 19:37:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-25 22:43:54 +08:00
|
|
|
void gen(Mat& mat, int rows, int cols, int type, Scalar low, Scalar high)
|
|
|
|
{
|
|
|
|
mat.create(rows, cols, type);
|
|
|
|
RNG rng(0);
|
|
|
|
rng.fill(mat, RNG::UNIFORM, low, high);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-26 19:37:54 +08:00
|
|
|
string abspath(const string& relpath)
|
|
|
|
{
|
2011-01-28 15:45:01 +08:00
|
|
|
return TestSystem::instance().workingDir() + relpath;
|
2011-01-26 19:37:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-25 23:11:01 +08:00
|
|
|
int CV_CDECL cvErrorCallback(int /*status*/, const char* /*func_name*/,
|
2011-01-26 19:37:54 +08:00
|
|
|
const char* err_msg, const char* /*file_name*/,
|
2011-01-25 23:11:01 +08:00
|
|
|
int /*line*/, void* /*userdata*/)
|
|
|
|
{
|
2011-01-28 15:45:01 +08:00
|
|
|
TestSystem::instance().printError(err_msg);
|
2011-01-25 23:11:01 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-11 16:58:39 +08:00
|
|
|
int main(int argc, const char* argv[])
|
2011-01-24 18:33:01 +08:00
|
|
|
{
|
2012-01-11 16:58:39 +08:00
|
|
|
redirectError(cvErrorCallback);
|
|
|
|
|
|
|
|
const char* keys =
|
|
|
|
"{ h | help | false | print help message }"
|
|
|
|
"{ f | filter | | filter for test }"
|
|
|
|
"{ w | workdir | | set working directory }"
|
|
|
|
"{ l | list | false | show all tests }";
|
|
|
|
|
|
|
|
CommandLineParser cmd(argc, argv, keys);
|
|
|
|
|
|
|
|
if (cmd.get<bool>("help"))
|
2011-03-03 21:46:44 +08:00
|
|
|
{
|
2012-01-11 16:58:39 +08:00
|
|
|
cout << "Avaible options:" << endl;
|
|
|
|
cmd.printParams();
|
|
|
|
return 0;
|
2011-03-03 21:46:44 +08:00
|
|
|
}
|
2011-01-26 19:37:54 +08:00
|
|
|
|
2012-01-11 16:58:39 +08:00
|
|
|
string filter = cmd.get<string>("filter");
|
|
|
|
string workdir = cmd.get<string>("workdir");
|
|
|
|
bool list = cmd.get<bool>("list");
|
|
|
|
|
|
|
|
if (!filter.empty())
|
|
|
|
TestSystem::instance().setTestFilter(filter);
|
|
|
|
|
|
|
|
if (!workdir.empty())
|
|
|
|
{
|
|
|
|
if (workdir[workdir.size() - 1] != '/' && workdir[workdir.size() - 1] != '\\')
|
|
|
|
workdir += '/';
|
|
|
|
|
|
|
|
TestSystem::instance().setWorkingDir(workdir);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (list)
|
|
|
|
TestSystem::instance().setListMode(true);
|
|
|
|
|
2011-01-28 15:45:01 +08:00
|
|
|
TestSystem::instance().run();
|
2011-01-26 19:37:54 +08:00
|
|
|
|
2011-01-24 18:33:01 +08:00
|
|
|
return 0;
|
2011-02-17 23:25:50 +08:00
|
|
|
}
|