From ab8f578f9d1e2a51e0a3590c10c7f92e9c82eb20 Mon Sep 17 00:00:00 2001 From: Alexey Spizhevoy Date: Tue, 25 Jan 2011 15:11:01 +0000 Subject: [PATCH] added error handling into GPU perf. tests --- samples/gpu/performance/performance.cpp | 37 +++++++++++++++++++------ samples/gpu/performance/performance.h | 11 ++++++++ samples/gpu/performance/tests.cpp | 2 +- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/samples/gpu/performance/performance.cpp b/samples/gpu/performance/performance.cpp index caa3fd1695..68d5811829 100644 --- a/samples/gpu/performance/performance.cpp +++ b/samples/gpu/performance/performance.cpp @@ -12,7 +12,7 @@ void TestSystem::run() (*it)->run(); cout << setiosflags(ios_base::left); - cout << " " << setw(10) << "CPU, ms" << setw(10) << "GPU, ms" + cout << TAB << setw(10) << "CPU, ms" << setw(10) << "GPU, ms" << setw(10) << "SPEEDUP" << "DESCRIPTION\n"; cout << resetiosflags(ios_base::left); @@ -21,8 +21,23 @@ void TestSystem::run() for (; it != tests_.end(); ++it) { cout << endl << (*it)->name() << ":\n"; - (*it)->run(); - flush_subtest_data(); + try + { + (*it)->run(); + flush_subtest_data(); + } + catch (const cv::Exception& e) + { + cout << TAB << "error"; + switch (e.code) + { + case CV_StsNoMem: cout << ": out of memory"; break; + } + if (!description_.str().empty()) + cout << " [" << description_.str() << "]"; + cout << endl; + reset_subtest_data(); + } } cout << setiosflags(ios_base::fixed | ios_base::left); @@ -39,13 +54,11 @@ void TestSystem::flush_subtest_data() int cpu_time = static_cast(cpu_elapsed_ / getTickFrequency() * 1000.0); int gpu_time = static_cast(gpu_elapsed_ / getTickFrequency() * 1000.0); - cpu_elapsed_ = 0; - gpu_elapsed_ = 0; double speedup = static_cast(cpu_time) / std::max(1, gpu_time); speedup_total_ += speedup; - cout << " " << setiosflags(ios_base::fixed | ios_base::left); + cout << TAB << setiosflags(ios_base::fixed | ios_base::left); stringstream stream; stream << cpu_time; @@ -60,12 +73,11 @@ void TestSystem::flush_subtest_data() cout << setw(10) << stream.str(); cout << description_.str(); - description_.str(""); cout << resetiosflags(ios_base::fixed | ios_base::left) << endl; - can_flush_ = false; num_subtests_called_++; + reset_subtest_data(); } @@ -77,8 +89,17 @@ void gen(Mat& mat, int rows, int cols, int type, Scalar low, Scalar high) } +int CV_CDECL cvErrorCallback(int /*status*/, const char* /*func_name*/, + const char* /*err_msg*/, const char* /*file_name*/, + int /*line*/, void* /*userdata*/) +{ + return 0; +} + + int main() { + redirectError(cvErrorCallback); TestSystem::instance()->run(); return 0; } \ No newline at end of file diff --git a/samples/gpu/performance/performance.h b/samples/gpu/performance/performance.h index a1feeb3ca0..7b833b057e 100644 --- a/samples/gpu/performance/performance.h +++ b/samples/gpu/performance/performance.h @@ -7,6 +7,8 @@ #include #include +#define TAB " " + class Runnable { public: @@ -31,6 +33,7 @@ public: } void addInit(Runnable* init) { inits_.push_back(init); } + void addTest(Runnable* test) { tests_.push_back(test); } void run(); @@ -66,6 +69,14 @@ private: void flush_subtest_data(); + void reset_subtest_data() + { + cpu_elapsed_ = 0; + gpu_elapsed_ = 0; + description_.str(""); + can_flush_ = false; + } + std::vector inits_; std::vector tests_; diff --git a/samples/gpu/performance/tests.cpp b/samples/gpu/performance/tests.cpp index eac8c98515..f0729b9c4e 100644 --- a/samples/gpu/performance/tests.cpp +++ b/samples/gpu/performance/tests.cpp @@ -107,7 +107,7 @@ TEST(dft) Mat src, dst; gpu::GpuMat d_src, d_dst; - for (int size = 1000; size <= 4000; size *= 2) + for (int size = 1000; size <= 8000; size *= 2) { SUBTEST << "size " << size << ", 32FC2, complex-to-complex";