From 8009b5150edde6b944aadb44725efbe5ff524ea5 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Wed, 7 Sep 2011 13:16:07 +0000 Subject: [PATCH] added performance tests for gpu module --- modules/gpu/CMakeLists.txt | 3 + modules/gpu/include/opencv2/gpu/gpu.hpp | 4 +- modules/gpu/perf/perf_arithm.cpp | 396 +++++++++++++++++ modules/gpu/perf/perf_filters.cpp | 138 ++++++ modules/gpu/perf/perf_imgproc.cpp | 743 ++++++++++++++++++++++++++++++++ modules/gpu/perf/perf_main.cpp | 22 + modules/gpu/perf/perf_matop.cpp | 188 ++++++++ modules/gpu/perf/perf_precomp.cpp | 1 + modules/gpu/perf/perf_precomp.hpp | 17 + modules/gpu/perf/perf_utility.cpp | 192 +++++++++ modules/gpu/perf/perf_utility.hpp | 74 ++++ 11 files changed, 1776 insertions(+), 2 deletions(-) create mode 100644 modules/gpu/perf/perf_arithm.cpp create mode 100644 modules/gpu/perf/perf_filters.cpp create mode 100644 modules/gpu/perf/perf_imgproc.cpp create mode 100644 modules/gpu/perf/perf_main.cpp create mode 100644 modules/gpu/perf/perf_matop.cpp create mode 100644 modules/gpu/perf/perf_precomp.cpp create mode 100644 modules/gpu/perf/perf_precomp.hpp create mode 100644 modules/gpu/perf/perf_utility.cpp create mode 100644 modules/gpu/perf/perf_utility.hpp diff --git a/modules/gpu/CMakeLists.txt b/modules/gpu/CMakeLists.txt index b9f3666..6c1a222 100644 --- a/modules/gpu/CMakeLists.txt +++ b/modules/gpu/CMakeLists.txt @@ -217,3 +217,6 @@ if(BUILD_TESTS AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test) # install(TARGETS ${the_test_target} RUNTIME DESTINATION bin COMPONENT main) #endif() endif() + + +define_opencv_perf_test(${name}) diff --git a/modules/gpu/include/opencv2/gpu/gpu.hpp b/modules/gpu/include/opencv2/gpu/gpu.hpp index a5243a4..250c630 100644 --- a/modules/gpu/include/opencv2/gpu/gpu.hpp +++ b/modules/gpu/include/opencv2/gpu/gpu.hpp @@ -596,8 +596,8 @@ namespace cv ////////////////////////////// Image processing ////////////////////////////// - //! DST[x,y] = SRC[xmap[x,y],ymap[x,y]] with bilinear interpolation. - //! supports CV_32FC1 map type + //! DST[x,y] = SRC[xmap[x,y],ymap[x,y]] + //! supports only CV_32FC1 map type CV_EXPORTS void remap(const GpuMat& src, GpuMat& dst, const GpuMat& xmap, const GpuMat& ymap, int interpolation, int borderMode = BORDER_CONSTANT, const Scalar& borderValue = Scalar(), Stream& stream = Stream::Null()); diff --git a/modules/gpu/perf/perf_arithm.cpp b/modules/gpu/perf/perf_arithm.cpp new file mode 100644 index 0000000..f4c0804 --- /dev/null +++ b/modules/gpu/perf/perf_arithm.cpp @@ -0,0 +1,396 @@ +#include "perf_precomp.hpp" + +PERF_TEST_P(DevInfo_Size_MatType, transpose, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_8UC1, CV_32SC1, CV_64FC1))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type = std::tr1::get<2>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat src_host(size, type); + + declare.in(src_host, WARMUP_RNG); + + GpuMat src(src_host); + GpuMat dst(size.width, size.height, type); + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + transpose(src, dst); + } + + Mat dst_host = dst; + + SANITY_CHECK(dst_host); +} + +PERF_TEST_P(DevInfo_Size_MatType_FlipCode, flip, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_8UC1, CV_8UC4), + testing::Values((int)HORIZONTAL_AXIS, (int)VERTICAL_AXIS, (int)BOTH_AXIS))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type = std::tr1::get<2>(GetParam()); + int flipCode = std::tr1::get<3>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat src_host(size, type); + + declare.in(src_host, WARMUP_RNG); + + GpuMat src(src_host); + GpuMat dst(size, type); + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + flip(src, dst, flipCode); + } + + Mat dst_host = dst; + + SANITY_CHECK(dst_host); +} + +PERF_TEST_P(DevInfo_Size_MatType, LUT, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_8UC1, CV_8UC3))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type = std::tr1::get<2>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat src_host(size, type); + Mat lut(1, 256, CV_8UC1); + + declare.in(src_host, lut, WARMUP_RNG); + + GpuMat src(src_host); + GpuMat dst(size, type); + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + LUT(src, lut, dst); + } + + Mat dst_host = dst; + + SANITY_CHECK(dst_host); +} + +PERF_TEST_P(DevInfo_Size, cartToPolar, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat x_host(size, CV_32FC1); + Mat y_host(size, CV_32FC1); + + declare.in(x_host, y_host, WARMUP_RNG); + + GpuMat x(x_host); + GpuMat y(y_host); + GpuMat magnitude(size, CV_32FC1); + GpuMat angle(size, CV_32FC1); + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + cartToPolar(x, y, magnitude, angle); + } + + Mat magnitude_host = magnitude; + Mat angle_host = angle; + + SANITY_CHECK(magnitude_host); + SANITY_CHECK(angle_host); +} + +PERF_TEST_P(DevInfo_Size, polarToCart, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat magnitude_host(size, CV_32FC1); + Mat angle_host(size, CV_32FC1); + + declare.in(magnitude_host, angle_host, WARMUP_RNG); + + GpuMat magnitude(magnitude_host); + GpuMat angle(angle_host); + GpuMat x(size, CV_32FC1); + GpuMat y(size, CV_32FC1); + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + polarToCart(magnitude, angle, x, y); + } + + Mat x_host = x; + Mat y_host = angle; + + SANITY_CHECK(x_host); + SANITY_CHECK(y_host); +} + +PERF_TEST_P(DevInfo_Size_MatType, addMat, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_8UC1, CV_8UC4, CV_32FC1))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type = std::tr1::get<2>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat a_host(size, type); + Mat b_host(size, type); + + declare.in(a_host, b_host, WARMUP_RNG); + + GpuMat a(a_host); + GpuMat b(b_host); + GpuMat c(size, type); + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + add(a, b, c); + } + + Mat c_host = c; + + SANITY_CHECK(c_host); +} + +PERF_TEST_P(DevInfo_Size_MatType, addScalar, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_32FC1, CV_32FC2))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type = std::tr1::get<2>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat a_host(size, type); + + declare.in(a_host, WARMUP_RNG); + + GpuMat a(a_host); + Scalar b(1,2,3,4); + GpuMat c(size, type); + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + add(a, b, c); + } + + Mat c_host = c; + + SANITY_CHECK(c_host); +} + +PERF_TEST_P(DevInfo_Size, exp, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat a_host(size, CV_32FC1); + + declare.in(a_host, WARMUP_RNG); + + GpuMat a(a_host); + GpuMat b(size, CV_32FC1); + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + exp(a, b); + } + + Mat b_host = b; + + SANITY_CHECK(b_host); +} + +PERF_TEST_P(DevInfo_Size_MatType, pow, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_8UC1, CV_8UC4, CV_16UC1, CV_32FC1))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type = std::tr1::get<2>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat src_host(size, type); + + declare.in(src_host, WARMUP_RNG); + + GpuMat src(src_host); + GpuMat dst(size, type); + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + pow(src, 2.0, dst); + } + + Mat dst_host = dst; + + SANITY_CHECK(dst_host); +} + +PERF_TEST_P(DevInfo_Size_MatType_CmpOp, compare, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_8UC4, CV_32FC1), + testing::Values(CMP_NE, CMP_EQ))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type = std::tr1::get<2>(GetParam()); + int cmpop = std::tr1::get<3>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat src1_host(size, type); + Mat src2_host(size, type); + + declare.in(src1_host, src2_host, WARMUP_RNG); + + GpuMat src1(src1_host); + GpuMat src2(src2_host); + GpuMat dst(size, type); + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + compare(src1, src2, dst, cmpop); + } + + Mat dst_host = dst; + + SANITY_CHECK(dst_host); +} + +PERF_TEST_P(DevInfo_Size_MatType, bitwise_not, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_8UC1, CV_16UC1, CV_32SC1))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type = std::tr1::get<2>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat src_host(size, type); + + declare.in(src_host, WARMUP_RNG); + + GpuMat src(src_host); + GpuMat dst(size, type); + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + bitwise_not(src, dst); + } + + Mat dst_host = dst; + + SANITY_CHECK(dst_host); +} + +PERF_TEST_P(DevInfo_Size_MatType, bitwise_and, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_8UC1, CV_16UC1, CV_32SC1))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type = std::tr1::get<2>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat src1_host(size, type); + Mat src2_host(size, type); + + declare.in(src1_host, src2_host, WARMUP_RNG); + + GpuMat src1(src1_host); + GpuMat src2(src2_host); + GpuMat dst(size, type); + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + bitwise_and(src1, src2, dst); + } + + Mat dst_host = dst; + + SANITY_CHECK(dst_host); +} + +PERF_TEST_P(DevInfo_Size_MatType, min, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_8UC1, CV_16UC1, CV_32SC1))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type = std::tr1::get<2>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat src1_host(size, type); + Mat src2_host(size, type); + + declare.in(src1_host, src2_host, WARMUP_RNG); + + GpuMat src1(src1_host); + GpuMat src2(src2_host); + GpuMat dst(size, type); + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + min(src1, src2, dst); + } + + Mat dst_host = dst; + + SANITY_CHECK(dst_host); +} diff --git a/modules/gpu/perf/perf_filters.cpp b/modules/gpu/perf/perf_filters.cpp new file mode 100644 index 0000000..76177a0 --- /dev/null +++ b/modules/gpu/perf/perf_filters.cpp @@ -0,0 +1,138 @@ +#include "perf_precomp.hpp" + +PERF_TEST_P(DevInfo_Size_MatType_KernelSize, boxFilter, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_8UC1, CV_8UC4), + testing::Values(3, 5, 7))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type = std::tr1::get<2>(GetParam()); + int ksize = std::tr1::get<3>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat src_host(size, type); + + declare.in(src_host, WARMUP_RNG); + + GpuMat src(src_host); + GpuMat dst(size, type); + + Ptr filter = createBoxFilter_GPU(type, type, Size(ksize, ksize)); + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + filter->apply(src, dst); + } + + Mat dst_host = dst; + + SANITY_CHECK(dst_host); +} + +PERF_TEST_P(DevInfo_Size_MatType_MorphOp_KernelSize, morphologyFilter, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_8UC1, CV_8UC4), + testing::Values((int)MORPH_ERODE, (int)MORPH_DILATE), + testing::Values(3, 5, 7))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type = std::tr1::get<2>(GetParam()); + int op = std::tr1::get<3>(GetParam()); + int ksize = std::tr1::get<4>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat src_host(size, type); + + declare.in(src_host, WARMUP_RNG); + + GpuMat src(src_host); + GpuMat dst(size, type); + + Ptr filter = createMorphologyFilter_GPU(op, type, Mat::ones(ksize, ksize, CV_8U)); + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + filter->apply(src, dst); + } + + Mat dst_host = dst; + + SANITY_CHECK(dst_host); +} + +PERF_TEST_P(DevInfo_Size_MatType_KernelSize, linearFilter, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_8UC1, CV_8UC4), + testing::Values(3, 5, 7))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type = std::tr1::get<2>(GetParam()); + int ksize = std::tr1::get<3>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat src_host(size, type); + + declare.in(src_host, WARMUP_RNG); + + GpuMat src(src_host); + GpuMat dst(size, type); + + Ptr filter = createLinearFilter_GPU(type, type, Mat::ones(ksize, ksize, CV_8U)); + + declare.time(1.0).iterations(100); + + SIMPLE_TEST_CYCLE() + { + filter->apply(src, dst); + } + + Mat dst_host = dst; + + SANITY_CHECK(dst_host); +} + +PERF_TEST_P(DevInfo_Size_MatType_KernelSize_BorderMode, separableLinearFilter, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_8UC1, CV_8UC4, CV_16SC1, CV_16SC3, CV_32FC1), + testing::Values(3, 5, 7), + testing::Values((int)BORDER_REFLECT101, (int)BORDER_CONSTANT))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type = std::tr1::get<2>(GetParam()); + int ksize = std::tr1::get<3>(GetParam()); + int borderMode = std::tr1::get<4>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat src_host(size, type); + + declare.in(src_host, WARMUP_RNG); + + GpuMat src(src_host); + GpuMat dst(size, type); + + Mat kernel = getGaussianKernel(ksize, 0.5, CV_32F); + Ptr filter = createSeparableLinearFilter_GPU(type, type, kernel, kernel, Point(-1,-1), borderMode); + + declare.time(1.0).iterations(100); + + SIMPLE_TEST_CYCLE() + { + filter->apply(src, dst, Rect(0, 0, src.cols, src.rows)); + } + + Mat dst_host = dst; + + SANITY_CHECK(dst_host); +} diff --git a/modules/gpu/perf/perf_imgproc.cpp b/modules/gpu/perf/perf_imgproc.cpp new file mode 100644 index 0000000..3a6d165 --- /dev/null +++ b/modules/gpu/perf/perf_imgproc.cpp @@ -0,0 +1,743 @@ +#include "perf_precomp.hpp" + +PERF_TEST_P(DevInfo_Size_MatType_Interpolation_BorderMode, remap, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_8UC1, CV_8UC4, CV_16UC1, CV_32FC1), + testing::Values((int)INTER_NEAREST, (int)INTER_LINEAR, (int)INTER_CUBIC), + testing::Values((int)BORDER_REFLECT101, (int)BORDER_REPLICATE, (int)BORDER_CONSTANT))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type = std::tr1::get<2>(GetParam()); + int interpolation = std::tr1::get<3>(GetParam()); + int borderMode = std::tr1::get<4>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat src_host(size, type); + + declare.in(src_host, WARMUP_RNG); + + GpuMat src(src_host); + GpuMat dst(size, type); + + Mat xmap_host(size, CV_32FC1); + Mat ymap_host(size, CV_32FC1); + randu(xmap_host, -300, size.width + 300); + randu(ymap_host, -300, size.height + 300); + + GpuMat xmap(xmap_host); + GpuMat ymap(ymap_host); + + declare.time(3.0).iterations(100); + + SIMPLE_TEST_CYCLE() + { + remap(src, dst, xmap, ymap, interpolation, borderMode); + } + + Mat dst_host = dst; + + SANITY_CHECK(dst_host); +} + +PERF_TEST_P(DevInfo, meanShiftFiltering, testing::ValuesIn(devices())) +{ + DeviceInfo devInfo = GetParam(); + + setDevice(devInfo.deviceID()); + + Mat img = readImage("meanshift/cones.png"); + ASSERT_FALSE(img.empty()); + + Mat rgba; + cvtColor(img, rgba, CV_BGR2BGRA); + + GpuMat src(rgba); + GpuMat dst(src.size(), CV_8UC4); + + declare.time(5.0).iterations(100); + + SIMPLE_TEST_CYCLE() + { + meanShiftFiltering(src, dst, 50, 50); + } + + Mat dst_host = dst; + + SANITY_CHECK(dst_host); +} + +PERF_TEST_P(DevInfo, meanShiftProc, testing::ValuesIn(devices())) +{ + DeviceInfo devInfo = GetParam(); + + setDevice(devInfo.deviceID()); + + Mat img = readImage("meanshift/cones.png"); + ASSERT_FALSE(img.empty()); + + Mat rgba; + cvtColor(img, rgba, CV_BGR2BGRA); + + GpuMat src(rgba); + GpuMat dstr(src.size(), CV_8UC4); + GpuMat dstsp(src.size(), CV_16SC2); + + declare.time(5.0).iterations(100); + + SIMPLE_TEST_CYCLE() + { + meanShiftProc(src, dstr, dstsp, 50, 50); + } + + Mat dstr_host = dstr; + Mat dstsp_host = dstsp; + + SANITY_CHECK(dstr_host); + SANITY_CHECK(dstsp_host); +} + +PERF_TEST_P(DevInfo, meanShiftSegmentation, testing::ValuesIn(devices())) +{ + DeviceInfo devInfo = GetParam(); + + setDevice(devInfo.deviceID()); + + Mat img = readImage("meanshift/cones.png"); + ASSERT_FALSE(img.empty()); + + Mat rgba; + cvtColor(img, rgba, CV_BGR2BGRA); + + GpuMat src(rgba); + Mat dst(src.size(), CV_8UC4); + + declare.time(5.0).iterations(100); + + SIMPLE_TEST_CYCLE() + { + meanShiftSegmentation(src, dst, 10, 10, 20); + } + + SANITY_CHECK(dst); +} + +PERF_TEST_P(DevInfo_Size_MatType, reprojectImageTo3D, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_8UC1, CV_16SC1))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type = std::tr1::get<2>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat src_host(size, type); + + declare.in(src_host, WARMUP_RNG); + + GpuMat src(src_host); + GpuMat dst(size, CV_32FC4); + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + reprojectImageTo3D(src, dst, Mat::ones(4, 4, CV_32FC1)); + } + + Mat dst_host(dst); + + SANITY_CHECK(dst_host); +} + +PERF_TEST_P(DevInfo_Size_MatType_CvtColorInfo, cvtColor, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_8UC1, CV_16UC1, CV_32FC1), + testing::Values(CvtColorInfo(4, 4, CV_RGBA2BGRA), CvtColorInfo(4, 1, CV_BGRA2GRAY), CvtColorInfo(1, 4, CV_GRAY2BGRA), + CvtColorInfo(4, 4, CV_BGR2XYZ), CvtColorInfo(4, 4, CV_BGR2YCrCb), CvtColorInfo(4, 4, CV_BGR2HSV)))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type = std::tr1::get<2>(GetParam()); + CvtColorInfo info = std::tr1::get<3>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat src_host(size, CV_MAKETYPE(type, info.scn)); + + declare.in(src_host, WARMUP_RNG); + + GpuMat src(src_host); + GpuMat dst(size, CV_MAKETYPE(type, info.dcn)); + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + cvtColor(src, dst, info.code, info.dcn); + } + + Mat dst_host(dst); + + SANITY_CHECK(dst_host); +} + +PERF_TEST_P(DevInfo_Size_MatType, threshold, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_8UC1, CV_16UC1, CV_32FC1))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type = std::tr1::get<2>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat src_host(size, type); + + declare.in(src_host, WARMUP_RNG); + + GpuMat src(src_host); + GpuMat dst(size, type); + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + threshold(src, dst, 100.0, 255.0, THRESH_BINARY); + } + + Mat dst_host(dst); + + SANITY_CHECK(dst_host); +} + +PERF_TEST_P(DevInfo_Size_MatType_Interpolation_SizeCoeff, resize, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_8UC1, CV_8UC4), + testing::Values((int)INTER_NEAREST, (int)INTER_LINEAR), + testing::Values(0.5, 2.0))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type = std::tr1::get<2>(GetParam()); + int interpolation = std::tr1::get<3>(GetParam()); + double f = std::tr1::get<4>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat src_host(size, type); + + declare.in(src_host, WARMUP_RNG); + + GpuMat src(src_host); + GpuMat dst; + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + resize(src, dst, Size(), f, f, interpolation); + } + + Mat dst_host(dst); + + SANITY_CHECK(dst_host); +} + +PERF_TEST_P(DevInfo_Size_MatType_Interpolation, warpAffine, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_8UC1, CV_8UC4, CV_32FC1), + testing::Values((int)INTER_NEAREST, (int)INTER_LINEAR, (int)INTER_CUBIC))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type = std::tr1::get<2>(GetParam()); + int interpolation = std::tr1::get<3>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat src_host(size, type); + + declare.in(src_host, WARMUP_RNG); + + GpuMat src(src_host); + GpuMat dst(size, type); + + static double reflect[2][3] = { {-1, 0, 0}, + { 0, -1, 0}}; + reflect[0][2] = size.width; + reflect[1][2] = size.height; + Mat M(2, 3, CV_64F, (void*)reflect); + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + warpAffine(src, dst, M, size, interpolation); + } + + Mat dst_host(dst); + + SANITY_CHECK(dst_host); +} + +PERF_TEST_P(DevInfo_Size_MatType_Interpolation, warpPerspective, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_8UC1, CV_8UC4, CV_32FC1), + testing::Values((int)INTER_NEAREST, (int)INTER_LINEAR, (int)INTER_CUBIC))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type = std::tr1::get<2>(GetParam()); + int interpolation = std::tr1::get<3>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat src_host(size, type); + + declare.in(src_host, WARMUP_RNG); + + GpuMat src(src_host); + GpuMat dst(size, type); + + static double reflect[3][3] = { {-1, 0, 0}, + { 0, -1, 0}, + { 0, 0, 1}}; + reflect[0][2] = size.width; + reflect[1][2] = size.height; + Mat M(3, 3, CV_64F, (void*)reflect); + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + warpPerspective(src, dst, M, size, interpolation); + } + + Mat dst_host(dst); + + SANITY_CHECK(dst_host); +} + +PERF_TEST_P(DevInfo_Size_MatType_Interpolation, rotate, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_8UC1, CV_8UC4), + testing::Values((int)INTER_NEAREST, (int)INTER_LINEAR, (int)INTER_CUBIC))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type = std::tr1::get<2>(GetParam()); + int interpolation = std::tr1::get<3>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat src_host(size, type); + + declare.in(src_host, WARMUP_RNG); + + GpuMat src(src_host); + GpuMat dst(size, type); + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + rotate(src, dst, size, 30.0, 0, 0, interpolation); + } + + Mat dst_host(dst); + + SANITY_CHECK(dst_host); +} + +PERF_TEST_P(DevInfo_Size_MatType, copyMakeBorder, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_8UC1, CV_8UC4, CV_32SC1))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type = std::tr1::get<2>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat src_host(size, type); + + declare.in(src_host, WARMUP_RNG); + + GpuMat src(src_host); + GpuMat dst; + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + copyMakeBorder(src, dst, 5, 5, 5, 5); + } + + Mat dst_host(dst); + + SANITY_CHECK(dst_host); +} + +PERF_TEST_P(DevInfo_Size, integral, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat src_host(size, CV_8UC1); + + declare.in(src_host, WARMUP_RNG); + + GpuMat src(src_host); + GpuMat dst; + GpuMat buf; + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + integralBuffered(src, dst, buf); + } + + Mat dst_host(dst); + + SANITY_CHECK(dst_host); +} + +PERF_TEST_P(DevInfo_Size, sqrIntegral, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat src_host(size, CV_8UC1); + + declare.in(src_host, WARMUP_RNG); + + GpuMat src(src_host); + GpuMat dst; + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + sqrIntegral(src, dst); + } + + Mat dst_host(dst); + + SANITY_CHECK(dst_host); +} + +PERF_TEST_P(DevInfo_Size, columnSum, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat src_host(size, CV_32FC1); + + declare.in(src_host, WARMUP_RNG); + + GpuMat src(src_host); + GpuMat dst; + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + columnSum(src, dst); + } + + Mat dst_host(dst); + + SANITY_CHECK(dst_host); +} + +PERF_TEST_P(DevInfo_MatType, cornerHarris, testing::Combine(testing::ValuesIn(devices()), + testing::Values(CV_8UC1, CV_32FC1))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + int type = std::tr1::get<1>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat img = readImage("stereobm/aloe-L.png", CV_LOAD_IMAGE_GRAYSCALE); + ASSERT_FALSE(img.empty()); + + img.convertTo(img, type, type == CV_32F ? 1.0 / 255.0 : 1.0); + + GpuMat src(img); + GpuMat dst; + GpuMat Dx; + GpuMat Dy; + + int blockSize = 3; + int ksize = 7; + double k = 0.5; + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + cornerHarris(src, dst, Dx, Dy, blockSize, ksize, k); + } + + Mat dst_host(dst); + Mat Dx_host(Dx); + Mat Dy_host(Dy); + + SANITY_CHECK(dst_host); + SANITY_CHECK(Dx_host); + SANITY_CHECK(Dy_host); +} + +PERF_TEST_P(DevInfo_MatType, cornerMinEigenVal, testing::Combine(testing::ValuesIn(devices()), + testing::Values(CV_8UC1, CV_32FC1))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + int type = std::tr1::get<1>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat img = readImage("stereobm/aloe-L.png", CV_LOAD_IMAGE_GRAYSCALE); + ASSERT_FALSE(img.empty()); + + img.convertTo(img, type, type == CV_32F ? 1.0 / 255.0 : 1.0); + + GpuMat src(img); + GpuMat dst; + GpuMat Dx; + GpuMat Dy; + + int blockSize = 3; + int ksize = 7; + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + cornerMinEigenVal(src, dst, Dx, Dy, blockSize, ksize); + } + + Mat dst_host(dst); + Mat Dx_host(Dx); + Mat Dy_host(Dy); + + SANITY_CHECK(dst_host); + SANITY_CHECK(Dx_host); + SANITY_CHECK(Dy_host); +} + +PERF_TEST_P(DevInfo_Size_MatType, mulSpectrums, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_8UC1, CV_32FC1))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type = std::tr1::get<2>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat a_host(size, CV_32FC2); + Mat b_host(size, CV_32FC2); + + declare.in(a_host, b_host, WARMUP_RNG); + + GpuMat a(a_host); + GpuMat b(b_host); + GpuMat dst; + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + mulSpectrums(a, b, dst, 0); + } + + Mat dst_host(dst); + + SANITY_CHECK(dst_host); +} + +PERF_TEST_P(DevInfo_Size, dft, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat src_host(size, CV_32FC2); + + declare.in(src_host, WARMUP_RNG); + + GpuMat src(src_host); + GpuMat dst; + + declare.time(2.0).iterations(100); + + SIMPLE_TEST_CYCLE() + { + dft(src, dst, size); + } + + Mat dst_host(dst); + + SANITY_CHECK(dst_host); +} + +PERF_TEST_P(DevInfo_Size, convolve, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat image_host(size, CV_32FC1); + Mat templ_host(size, CV_32FC1); + + declare.in(image_host, templ_host, WARMUP_RNG); + + GpuMat image(image_host); + GpuMat templ(templ_host); + GpuMat dst; + ConvolveBuf buf; + + declare.time(2.0).iterations(100); + + SIMPLE_TEST_CYCLE() + { + convolve(image, templ, dst, false, buf); + } + + Mat dst_host(dst); + + SANITY_CHECK(dst_host); +} + +PERF_TEST_P(DevInfo_Size_MatType, pyrDown, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_8UC1, CV_8UC4, CV_16SC3, CV_32FC1))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type = std::tr1::get<2>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat src_host(size, type); + + declare.in(src_host, WARMUP_RNG); + + GpuMat src(src_host); + GpuMat dst; + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + pyrDown(src, dst); + } + + Mat dst_host(dst); + + SANITY_CHECK(dst_host); +} + +PERF_TEST_P(DevInfo_Size_MatType, pyrUp, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_8UC1, CV_8UC4, CV_16SC3, CV_32FC1))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type = std::tr1::get<2>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat src_host(size, type); + + declare.in(src_host, WARMUP_RNG); + + GpuMat src(src_host); + GpuMat dst; + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + pyrUp(src, dst); + } + + Mat dst_host(dst); + + SANITY_CHECK(dst_host); +} + +PERF_TEST_P(DevInfo_Size_MatType, blendLinear, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_8UC1, CV_32FC1))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type = std::tr1::get<2>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat img1_host(size, type); + Mat img2_host(size, type); + + declare.in(img1_host, img2_host, WARMUP_RNG); + + GpuMat img1(img1_host); + GpuMat img2(img2_host); + GpuMat weights1(size, CV_32FC1, Scalar::all(0.5)); + GpuMat weights2(size, CV_32FC1, Scalar::all(0.5)); + GpuMat dst; + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + blendLinear(img1, img2, weights1, weights2, dst); + } + + Mat dst_host(dst); + + SANITY_CHECK(dst_host); +} + +PERF_TEST_P(DevInfo, Canny, testing::ValuesIn(devices())) +{ + DeviceInfo devInfo = GetParam(); + + setDevice(devInfo.deviceID()); + + Mat image_host = readImage("perf/aloe.jpg", CV_LOAD_IMAGE_GRAYSCALE); + ASSERT_FALSE(image_host.empty()); + + GpuMat image(image_host); + GpuMat dst; + CannyBuf buf; + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + Canny(image, buf, dst, 50.0, 100.0); + } + + Mat dst_host(dst); + + SANITY_CHECK(dst_host); +} diff --git a/modules/gpu/perf/perf_main.cpp b/modules/gpu/perf/perf_main.cpp new file mode 100644 index 0000000..32d5505 --- /dev/null +++ b/modules/gpu/perf/perf_main.cpp @@ -0,0 +1,22 @@ +#include "perf_precomp.hpp" + +#ifdef HAVE_CUDA + +int main(int argc, char **argv) +{ + testing::InitGoogleTest(&argc, argv); + cvtest::TS::ptr()->init("gpu"); + Regression::Init("gpu"); + TestBase::Init(argc, argv); + return RUN_ALL_TESTS(); +} + +#else + +int main(int argc, char** argv) +{ + printf("OpenCV was built without CUDA support\n"); + return 0; +} + +#endif diff --git a/modules/gpu/perf/perf_matop.cpp b/modules/gpu/perf/perf_matop.cpp new file mode 100644 index 0000000..d1505f5 --- /dev/null +++ b/modules/gpu/perf/perf_matop.cpp @@ -0,0 +1,188 @@ +#include "perf_precomp.hpp" + +PERF_TEST_P(DevInfo_Size_MatType, merge, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_8UC1, CV_16UC1, CV_32FC1))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type = std::tr1::get<2>(GetParam()); + + setDevice(devInfo.deviceID()); + + const int num_channels = 4; + + vector src(num_channels); + for (int i = 0; i < num_channels; ++i) + src[i] = GpuMat(size, type, cv::Scalar::all(i)); + + GpuMat dst(size, CV_MAKETYPE(type, num_channels)); + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + merge(src, dst); + } + + Mat dst_host = dst; + + SANITY_CHECK(dst_host); +} + +PERF_TEST_P(DevInfo_Size_MatType, split, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_8UC1, CV_16UC1, CV_32FC1))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type = std::tr1::get<2>(GetParam()); + + setDevice(devInfo.deviceID()); + + const int num_channels = 4; + + GpuMat src(size, CV_MAKETYPE(type, num_channels), cv::Scalar(1, 2, 3, 4)); + + vector dst(num_channels); + for (int i = 0; i < num_channels; ++i) + dst[i] = GpuMat(size, type); + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + split(src, dst); + } + + vector dst_host(dst.size()); + for (size_t i = 0; i < dst.size(); ++i) + dst[i].download(dst_host[i]); + + SANITY_CHECK(dst_host); +} + +PERF_TEST_P(DevInfo_Size_MatType, setTo, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_8UC1, CV_8UC4, CV_32FC1))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type = std::tr1::get<2>(GetParam()); + + setDevice(devInfo.deviceID()); + + GpuMat src(size, type); + Scalar val(1, 2, 3, 4); + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + src.setTo(val); + } + + Mat src_host = src; + + SANITY_CHECK(src_host); +} + +PERF_TEST_P(DevInfo_Size_MatType, setToMasked, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_8UC1, CV_8UC4, CV_32FC1))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type = std::tr1::get<2>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat src_host(size, type); + + declare.in(src_host, WARMUP_RNG); + + GpuMat src(src_host); + Scalar val(1, 2, 3, 4); + + Mat mask_host(size, CV_8UC1); + randu(mask_host, 0.0, 2.0); + GpuMat mask(mask_host); + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + src.setTo(val, mask); + } + + src_host = src; + + SANITY_CHECK(src_host); +} + +PERF_TEST_P(DevInfo_Size_MatType, copyToMasked, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_8UC1, CV_8UC4, CV_32FC1))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type = std::tr1::get<2>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat src_host(size, type); + + declare.in(src_host, WARMUP_RNG); + + GpuMat src(src_host); + GpuMat dst(size, type); + + Mat mask_host(size, CV_8UC1); + randu(mask_host, 0.0, 2.0); + GpuMat mask(mask_host); + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + src.copyTo(dst, mask); + } + + Mat dst_host = dst; + + SANITY_CHECK(dst_host); +} + +PERF_TEST_P(DevInfo_Size_MatType_MatType, convertTo, testing::Combine(testing::ValuesIn(devices()), + testing::Values(GPU_TYPICAL_MAT_SIZES), + testing::Values(CV_8UC1, CV_16UC1, CV_32FC1), + testing::Values(CV_8UC1, CV_16UC1, CV_32FC1))) +{ + DeviceInfo devInfo = std::tr1::get<0>(GetParam()); + Size size = std::tr1::get<1>(GetParam()); + int type1 = std::tr1::get<2>(GetParam()); + int type2 = std::tr1::get<3>(GetParam()); + + setDevice(devInfo.deviceID()); + + Mat src_host(size, type1); + + declare.in(src_host, WARMUP_RNG); + + GpuMat src(src_host); + GpuMat dst(size, type2); + + double a = 0.5; + double b = 1.0; + + declare.time(0.5).iterations(100); + + SIMPLE_TEST_CYCLE() + { + src.convertTo(dst, type2, a, b); + } + + Mat dst_host = dst; + + SANITY_CHECK(dst_host); +} diff --git a/modules/gpu/perf/perf_precomp.cpp b/modules/gpu/perf/perf_precomp.cpp new file mode 100644 index 0000000..8552ac3 --- /dev/null +++ b/modules/gpu/perf/perf_precomp.cpp @@ -0,0 +1 @@ +#include "perf_precomp.hpp" diff --git a/modules/gpu/perf/perf_precomp.hpp b/modules/gpu/perf/perf_precomp.hpp new file mode 100644 index 0000000..c910ab9 --- /dev/null +++ b/modules/gpu/perf/perf_precomp.hpp @@ -0,0 +1,17 @@ +#ifndef __OPENCV_PERF_PRECOMP_HPP__ +#define __OPENCV_PERF_PRECOMP_HPP__ + +#include +#include +#include "cvconfig.h" +#include "opencv2/ts/ts.hpp" +#include "opencv2/core/core.hpp" +#include "opencv2/highgui/highgui.hpp" +#include "opencv2/gpu/gpu.hpp" +#include "perf_utility.hpp" + +#if GTEST_CREATE_SHARED_LIBRARY +#error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined +#endif + +#endif diff --git a/modules/gpu/perf/perf_utility.cpp b/modules/gpu/perf/perf_utility.cpp new file mode 100644 index 0000000..0b7c118 --- /dev/null +++ b/modules/gpu/perf/perf_utility.cpp @@ -0,0 +1,192 @@ +#include "perf_precomp.hpp" + +using namespace std; +using namespace cv::gpu; + +Mat readImage(const string& fileName, int flags) +{ + return imread(string(cvtest::TS::ptr()->get_data_path()) + fileName, flags); +} + +bool supportFeature(const DeviceInfo& info, FeatureSet feature) +{ + return TargetArchs::builtWith(feature) && info.supports(feature); +} + +const vector& devices() +{ + static vector devs; + static bool first = true; + + if (first) + { + int deviceCount = getCudaEnabledDeviceCount(); + + devs.reserve(deviceCount); + + for (int i = 0; i < deviceCount; ++i) + { + DeviceInfo info(i); + if (info.isCompatible()) + devs.push_back(info); + } + + first = false; + } + + return devs; +} + +vector devices(FeatureSet feature) +{ + const vector& d = devices(); + + vector devs_filtered; + + if (TargetArchs::builtWith(feature)) + { + devs_filtered.reserve(d.size()); + + for (size_t i = 0, size = d.size(); i < size; ++i) + { + const DeviceInfo& info = d[i]; + + if (info.supports(feature)) + devs_filtered.push_back(info); + } + } + + return devs_filtered; +} + +void cv::gpu::PrintTo(const DeviceInfo& info, ostream* os) +{ + *os << info.name(); +} + +void PrintTo(const CvtColorInfo& info, ::std::ostream* os) +{ + static const char* str[] = + { + "BGR2BGRA", + "BGRA2BGR", + "BGR2RGBA", + "RGBA2BGR", + "BGR2RGB", + "BGRA2RGBA", + + "BGR2GRAY", + "RGB2GRAY", + "GRAY2BGR", + "GRAY2BGRA", + "BGRA2GRAY", + "RGBA2GRAY", + + "BGR2BGR565", + "RGB2BGR565", + "BGR5652BGR", + "BGR5652RGB", + "BGRA2BGR565", + "RGBA2BGR565", + "BGR5652BGRA", + "BGR5652RGBA", + + "GRAY2BGR565", + "BGR5652GRAY", + + "BGR2BGR555", + "RGB2BGR555", + "BGR5552BGR", + "BGR5552RGB", + "BGRA2BGR555", + "RGBA2BGR555", + "BGR5552BGRA", + "BGR5552RGBA", + + "GRAY2BGR555", + "BGR5552GRAY", + + "BGR2XYZ", + "RGB2XYZ", + "XYZ2BGR", + "XYZ2RGB", + + "BGR2YCrCb", + "RGB2YCrCb", + "YCrCb2BGR", + "YCrCb2RGB", + + "BGR2HSV", + "RGB2HSV", + + 0, + 0, + + 0, + 0, + + 0, + 0, + 0, + 0, + + 0, + 0, + + "BGR2HLS", + "RGB2HLS", + + "HSV2BGR", + "HSV2RGB", + + 0, + 0, + 0, + 0, + + "HLS2BGR", + "HLS2RGB", + + 0, + 0, + 0, + 0, + + "BGR2HSV_FULL", + "RGB2HSV_FULL", + "BGR2HLS_FULL", + "RGB2HLS_FULL", + + "HSV2BGR_FULL", + "HSV2RGB_FULL", + "HLS2BGR_FULL", + "HLS2RGB_FULL", + + 0, + 0, + 0, + 0, + + 0, + 0, + 0, + 0, + + "BGR2YUV", + "RGB2YUV", + "YUV2BGR", + "YUV2RGB", + + 0, + 0, + 0, + 0, + + 0, + 0, + 0, + 0 + }; + + *os << str[info.code]; +} diff --git a/modules/gpu/perf/perf_utility.hpp b/modules/gpu/perf/perf_utility.hpp new file mode 100644 index 0000000..66063bc --- /dev/null +++ b/modules/gpu/perf/perf_utility.hpp @@ -0,0 +1,74 @@ +#ifndef __OPENCV_PERF_GPU_UTILITY_HPP__ +#define __OPENCV_PERF_GPU_UTILITY_HPP__ + +#include +#include "opencv2/ts/ts.hpp" +#include "opencv2/highgui/highgui.hpp" +#include "opencv2/gpu/gpu.hpp" + +using namespace std; +using namespace cv; +using namespace cv::gpu; +using namespace perf; + +enum {HORIZONTAL_AXIS = 0, VERTICAL_AXIS = 1, BOTH_AXIS = -1}; + +CV_ENUM(MorphOp, MORPH_ERODE, MORPH_DILATE) +CV_ENUM(BorderMode, BORDER_REFLECT101, BORDER_REPLICATE, BORDER_CONSTANT, BORDER_REFLECT, BORDER_WRAP) +CV_ENUM(FlipCode, HORIZONTAL_AXIS, VERTICAL_AXIS, BOTH_AXIS) +CV_ENUM(CmpOp, CMP_EQ, CMP_GT, CMP_GE, CMP_LT, CMP_LE, CMP_NE) +CV_ENUM(Interpolation, INTER_NEAREST, INTER_LINEAR, INTER_CUBIC) +CV_ENUM(MatchMethod, TM_SQDIFF, TM_SQDIFF_NORMED, TM_CCORR, TM_CCORR_NORMED, TM_CCOEFF, TM_CCOEFF_NORMED) + +struct CvtColorInfo +{ + int scn; + int dcn; + int code; + + explicit CvtColorInfo(int scn_=0, int dcn_=0, int code_=0) : scn(scn_), dcn(dcn_), code(code_) {} +}; + +typedef TestBaseWithParam DevInfo; +typedef TestBaseWithParam< std::tr1::tuple > DevInfo_Size; +typedef TestBaseWithParam< std::tr1::tuple > DevInfo_MatType; +typedef TestBaseWithParam< std::tr1::tuple > DevInfo_Size_MatType; +typedef TestBaseWithParam< std::tr1::tuple > DevInfo_Size_MatType_MatType; +typedef TestBaseWithParam< std::tr1::tuple > DevInfo_Size_MatType_KernelSize; +typedef TestBaseWithParam< std::tr1::tuple > DevInfo_Size_MatType_MorphOp_KernelSize; +typedef TestBaseWithParam< std::tr1::tuple > DevInfo_Size_MatType_KernelSize_BorderMode; +typedef TestBaseWithParam< std::tr1::tuple > DevInfo_Size_MatType_FlipCode; +typedef TestBaseWithParam< std::tr1::tuple > DevInfo_Size_MatType_CmpOp; +typedef TestBaseWithParam< std::tr1::tuple > DevInfo_Size_MatType_Interpolation; +typedef TestBaseWithParam< std::tr1::tuple > DevInfo_Size_MatType_Interpolation_SizeCoeff; +typedef TestBaseWithParam< std::tr1::tuple > DevInfo_Size_MatType_Interpolation_BorderMode; +typedef TestBaseWithParam< std::tr1::tuple > DevInfo_Size_MatType_CvtColorInfo; +typedef TestBaseWithParam< std::tr1::tuple > DevInfo_Size_MatType_MatchMethod; + +const cv::Size sz1800x1500 = cv::Size(1800, 1500); +const cv::Size sz4700x3000 = cv::Size(4700, 3000); + +#define GPU_TYPICAL_MAT_SIZES szXGA, szSXGA, sz720p, sz1080p, sz1800x1500, sz4700x3000 + +//! read image from testdata folder. +Mat readImage(const string& fileName, int flags = CV_LOAD_IMAGE_COLOR); + +//! return true if device supports specified feature and gpu module was built with support the feature. +bool supportFeature(const cv::gpu::DeviceInfo& info, cv::gpu::FeatureSet feature); + +//! return all devices compatible with current gpu module build. +const std::vector& devices(); +//! return all devices compatible with current gpu module build which support specified feature. +std::vector devices(cv::gpu::FeatureSet feature); + +namespace cv +{ + namespace gpu + { + void PrintTo(const DeviceInfo& info, ::std::ostream* os); + } +} + +void PrintTo(const CvtColorInfo& info, ::std::ostream* os); + +#endif // __OPENCV_PERF_GPU_UTILITY_HPP__ -- 2.7.4