From 8f35b572ff0b20eecb291f68d8bd2395a6a80281 Mon Sep 17 00:00:00 2001 From: Alexey Spizhevoy Date: Fri, 28 Jan 2011 07:45:01 +0000 Subject: [PATCH] added performance tests for log, exp, add, magnitude --- samples/gpu/performance/performance.cpp | 8 +-- samples/gpu/performance/performance.h | 26 ++++---- samples/gpu/performance/tests.cpp | 108 ++++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+), 18 deletions(-) diff --git a/samples/gpu/performance/performance.cpp b/samples/gpu/performance/performance.cpp index b45dd54..ebf9889 100644 --- a/samples/gpu/performance/performance.cpp +++ b/samples/gpu/performance/performance.cpp @@ -123,7 +123,7 @@ void gen(Mat& mat, int rows, int cols, int type, Scalar low, Scalar high) string abspath(const string& relpath) { - return TestSystem::instance()->workingDir() + relpath; + return TestSystem::instance().workingDir() + relpath; } @@ -131,7 +131,7 @@ int CV_CDECL cvErrorCallback(int /*status*/, const char* /*func_name*/, const char* err_msg, const char* /*file_name*/, int /*line*/, void* /*userdata*/) { - TestSystem::instance()->printError(err_msg); + TestSystem::instance().printError(err_msg); return 0; } @@ -144,11 +144,11 @@ int main(int argc, char** argv) } else { - TestSystem::instance()->setWorkingDir(argv[1]); + TestSystem::instance().setWorkingDir(argv[1]); } redirectError(cvErrorCallback); - TestSystem::instance()->run(); + 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 373fe0f..1bfcff8 100644 --- a/samples/gpu/performance/performance.h +++ b/samples/gpu/performance/performance.h @@ -26,10 +26,10 @@ private: class TestSystem { public: - static TestSystem* instance() + static TestSystem& instance() { static TestSystem me; - return &me; + return me; } void addInit(Runnable* init) { inits_.push_back(init); } @@ -106,10 +106,9 @@ private: #define INIT(name) \ - struct name##_init: Runnable \ - { \ + struct name##_init: Runnable { \ name##_init(): Runnable(#name) { \ - TestSystem::instance()->addInit(this); \ + TestSystem::instance().addInit(this); \ } \ void run(); \ } name##_init_instance; \ @@ -117,21 +116,20 @@ private: #define TEST(name) \ - struct name##_test: Runnable \ - { \ + struct name##_test: Runnable { \ name##_test(): Runnable(#name) { \ - TestSystem::instance()->addTest(this); \ + TestSystem::instance().addTest(this); \ } \ void run(); \ } name##_test_instance; \ void name##_test::run() -#define SUBTEST TestSystem::instance()->subtest() -#define DESCRIPTION TestSystem::instance()->subtest() -#define CPU_ON TestSystem::instance()->cpuOn() -#define GPU_ON TestSystem::instance()->gpuOn() -#define CPU_OFF TestSystem::instance()->cpuOff() -#define GPU_OFF TestSystem::instance()->gpuOff() +#define SUBTEST TestSystem::instance().subtest() +#define DESCRIPTION TestSystem::instance().subtest() +#define CPU_ON TestSystem::instance().cpuOn() +#define GPU_ON TestSystem::instance().gpuOn() +#define CPU_OFF TestSystem::instance().cpuOff() +#define GPU_OFF TestSystem::instance().gpuOff() void gen(cv::Mat& mat, int rows, int cols, int type, cv::Scalar low, cv::Scalar high); diff --git a/samples/gpu/performance/tests.cpp b/samples/gpu/performance/tests.cpp index b47e8b4..ebece94 100644 --- a/samples/gpu/performance/tests.cpp +++ b/samples/gpu/performance/tests.cpp @@ -332,4 +332,112 @@ TEST(BruteForceMatcher) GPU_ON; d_matcher.radiusMatch(d_query, d_train, d_matches, max_distance); GPU_OFF; +} + + +TEST(magnitude) +{ + Mat x, y, mag; + gpu::GpuMat d_x, d_y, d_mag; + + for (int size = 2000; size <= 4000; size += 1000) + { + SUBTEST << "size " << size; + + gen(x, size, size, CV_32F, 0, 1); + gen(y, size, size, CV_32F, 0, 1); + mag.create(size, size, CV_32F); + + CPU_ON; + magnitude(x, y, mag); + CPU_OFF; + + d_x = x; + d_y = y; + d_mag.create(size, size, CV_32F); + + GPU_ON; + gpu::magnitude(d_x, d_y, d_mag); + GPU_OFF; + } +} + + +TEST(add) +{ + Mat src1, src2, dst; + gpu::GpuMat d_src1, d_src2, d_dst; + + for (int size = 2000; size <= 4000; size += 1000) + { + SUBTEST << "size " << size << ", 32F"; + + gen(src1, size, size, CV_32F, 0, 1); + gen(src2, size, size, CV_32F, 0, 1); + dst.create(size, size, CV_32F); + + CPU_ON; + add(src1, src2, dst); + CPU_OFF; + + d_src1 = src1; + d_src2 = src2; + d_dst.create(size, size, CV_32F); + + GPU_ON; + gpu::add(d_src1, d_src2, d_dst); + GPU_OFF; + } +} + + +TEST(log) +{ + Mat src, dst; + gpu::GpuMat d_src, d_dst; + + for (int size = 2000; size <= 4000; size += 1000) + { + SUBTEST << "size " << size << ", 32F"; + + gen(src, size, size, CV_32F, 1, 10); + dst.create(size, size, CV_32F); + + CPU_ON; + log(src, dst); + CPU_OFF; + + d_src = src; + d_dst.create(size, size, CV_32F); + + GPU_ON; + gpu::log(d_src, d_dst); + GPU_OFF; + } +} + + +TEST(exp) +{ + Mat src, dst; + gpu::GpuMat d_src, d_dst; + + for (int size = 2000; size <= 4000; size += 1000) + { + SUBTEST << "size " << size << ", 32F"; + + gen(src, size, size, CV_32F, 0, 1); + dst.create(size, size, CV_32F); + + CPU_ON; + exp(src, dst); + CPU_OFF; + + d_src = src; + d_dst.create(size, size, CV_32F); + + GPU_ON; + gpu::exp(d_src, d_dst); + GPU_OFF; + } } \ No newline at end of file -- 2.7.4