From ae4be413c3a6dda6eacad198a7cedb033640a3bd Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Fri, 17 Jan 2014 01:05:59 +0400 Subject: [PATCH] added perf tests for cv::reduce --- modules/core/perf/opencl/perf_arithm.cpp | 64 ++++++++++++++++++++++++++++++++ modules/core/src/matrix.cpp | 1 + modules/core/test/ocl/test_arithm.cpp | 2 +- 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/modules/core/perf/opencl/perf_arithm.cpp b/modules/core/perf/opencl/perf_arithm.cpp index 4eae489..dc5cc07 100644 --- a/modules/core/perf/opencl/perf_arithm.cpp +++ b/modules/core/perf/opencl/perf_arithm.cpp @@ -912,6 +912,70 @@ OCL_PERF_TEST_P(PSNRFixture, PSNR, SANITY_CHECK(psnr, 1e-4, ERROR_RELATIVE); } +///////////// Reduce //////////////////////// + +CV_ENUM(ReduceMinMaxOp, CV_REDUCE_MIN, CV_REDUCE_MAX) + +typedef tuple, int, ReduceMinMaxOp> ReduceMinMaxParams; +typedef TestBaseWithParam ReduceMinMaxFixture; + +OCL_PERF_TEST_P(ReduceMinMaxFixture, Reduce, + ::testing::Combine(OCL_TEST_SIZES, + OCL_PERF_ENUM(std::make_pair(CV_8UC1, CV_8UC1), + std::make_pair(CV_32FC4, CV_32FC4)), + OCL_PERF_ENUM(0, 1), + ReduceMinMaxOp::all())) +{ + const ReduceMinMaxParams params = GetParam(); + const std::pair types = get<1>(params); + const int stype = types.first, dtype = types.second, + dim = get<2>(params), op = get<3>(params); + const Size srcSize = get<0>(params), + dstSize(dim == 0 ? srcSize.width : 1, dim == 0 ? 1 : srcSize.height); + const double eps = CV_MAT_DEPTH(dtype) <= CV_32S ? 1 : 1e-5; + + checkDeviceMaxMemoryAllocSize(srcSize, stype); + checkDeviceMaxMemoryAllocSize(srcSize, dtype); + + UMat src(srcSize, stype), dst(dstSize, dtype); + declare.in(src, WARMUP_RNG).out(dst); + + OCL_TEST_CYCLE() cv::reduce(src, dst, dim, op, dtype); + + SANITY_CHECK(dst, eps); +} + +CV_ENUM(ReduceAccOp, CV_REDUCE_SUM, CV_REDUCE_AVG) + +typedef tuple, int, ReduceAccOp> ReduceAccParams; +typedef TestBaseWithParam ReduceAccFixture; + +OCL_PERF_TEST_P(ReduceAccFixture, Reduce, + ::testing::Combine(OCL_TEST_SIZES, + OCL_PERF_ENUM(std::make_pair(CV_8UC4, CV_32SC4), + std::make_pair(CV_32FC1, CV_32FC1)), + OCL_PERF_ENUM(0, 1), + ReduceAccOp::all())) +{ + const ReduceAccParams params = GetParam(); + const std::pair types = get<1>(params); + const int stype = types.first, dtype = types.second, + dim = get<2>(params), op = get<3>(params); + const Size srcSize = get<0>(params), + dstSize(dim == 0 ? srcSize.width : 1, dim == 0 ? 1 : srcSize.height); + const double eps = CV_MAT_DEPTH(dtype) <= CV_32S ? 1 : 3e-4; + + checkDeviceMaxMemoryAllocSize(srcSize, stype); + checkDeviceMaxMemoryAllocSize(srcSize, dtype); + + UMat src(srcSize, stype), dst(dstSize, dtype); + declare.in(src, WARMUP_RNG).out(dst); + + OCL_TEST_CYCLE() cv::reduce(src, dst, dim, op, dtype); + + SANITY_CHECK(dst, eps); +} + } } // namespace cvtest::ocl #endif // HAVE_OPENCL diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index f513919..53db7e3 100644 --- a/modules/core/src/matrix.cpp +++ b/modules/core/src/matrix.cpp @@ -3036,6 +3036,7 @@ void cv::reduce(InputArray _src, OutputArray _dst, int dim, int op, int dtype) int stype = _src.type(), sdepth = CV_MAT_DEPTH(stype), cn = CV_MAT_CN(stype); if( dtype < 0 ) dtype = _dst.fixedType() ? _dst.type() : stype; + dtype = CV_MAKETYPE(dtype >= 0 ? dtype : stype, cn); int ddepth = CV_MAT_DEPTH(dtype); CV_Assert( cn == CV_MAT_CN(dtype) ); diff --git a/modules/core/test/ocl/test_arithm.cpp b/modules/core/test/ocl/test_arithm.cpp index 87442bb..2932fc8 100644 --- a/modules/core/test/ocl/test_arithm.cpp +++ b/modules/core/test/ocl/test_arithm.cpp @@ -1615,7 +1615,7 @@ OCL_TEST_P(ReduceSum, Mat) OCL_OFF(cv::reduce(src_roi, dst_roi, dim, CV_REDUCE_SUM, dtype)); OCL_ON(cv::reduce(usrc_roi, udst_roi, dim, CV_REDUCE_SUM, dtype)); - double eps = ddepth <= CV_32S ? 1 : 5e-5; + double eps = ddepth <= CV_32S ? 1 : 1e-4; OCL_EXPECT_MATS_NEAR(dst, eps) } } -- 2.7.4