From a01e81c8f711a9218a5ed9968cc8b26671c5db05 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Tue, 7 Jan 2014 15:08:48 +0400 Subject: [PATCH] added some performance tests --- modules/core/perf/opencl/perf_arithm.cpp | 76 ++++++++++++++++++++++++ modules/core/src/mathfuncs.cpp | 2 +- 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/modules/core/perf/opencl/perf_arithm.cpp b/modules/core/perf/opencl/perf_arithm.cpp index cb06ac4793..5bc2a5aec7 100644 --- a/modules/core/perf/opencl/perf_arithm.cpp +++ b/modules/core/perf/opencl/perf_arithm.cpp @@ -814,6 +814,82 @@ OCL_PERF_TEST_P(NormalizeFixture, Normalize, SANITY_CHECK(dst, 5e-2); } +///////////// ConvertScaleAbs //////////////////////// + +typedef Size_MatType ConvertScaleAbsFixture; + +OCL_PERF_TEST_P(ConvertScaleAbsFixture, ConvertScaleAbs, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES)) +{ + const Size_MatType_t params = GetParam(); + const Size srcSize = get<0>(params); + const int type = get<1>(params), cn = CV_MAT_CN(type); + + checkDeviceMaxMemoryAllocSize(srcSize, type); + + UMat src(srcSize, type), dst(srcSize, CV_8UC(cn)); + declare.in(src, WARMUP_RNG).out(dst); + + OCL_TEST_CYCLE() cv::convertScaleAbs(src, dst, 0.5, 2); + + SANITY_CHECK(dst); +} + +///////////// PatchNaNs //////////////////////// + +typedef Size_MatType PatchNaNsFixture; + +OCL_PERF_TEST_P(PatchNaNsFixture, PatchNaNs, + ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4))) +{ + const Size_MatType_t params = GetParam(); + Size srcSize = get<0>(params); + const int type = get<1>(params), cn = CV_MAT_CN(type); + + checkDeviceMaxMemoryAllocSize(srcSize, type); + + UMat src(srcSize, type); + declare.in(src, WARMUP_RNG).out(src); + + // generating NaNs + { + Mat src_ = src.getMat(ACCESS_RW); + srcSize.width *= cn; + for (int y = 0; y < srcSize.height; ++y) + { + float * const ptr = src_.ptr(y); + for (int x = 0; x < srcSize.width; ++x) + ptr[x] = (x + y) % 2 == 0 ? std::numeric_limits::quiet_NaN() : ptr[x]; + } + } + + OCL_TEST_CYCLE() cv::patchNaNs(src, 17.7); + + SANITY_CHECK(src); +} + + +///////////// ScaleAdd //////////////////////// + +typedef Size_MatType ScaleAddFixture; + +OCL_PERF_TEST_P(ScaleAddFixture, ScaleAdd, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES)) +{ + const Size_MatType_t params = GetParam(); + const Size srcSize = get<0>(params); + const int type = get<1>(params); + + checkDeviceMaxMemoryAllocSize(srcSize, type); + + UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type); + declare.in(src1, src2, WARMUP_RNG).out(dst); + + OCL_TEST_CYCLE() cv::scaleAdd(src1, 0.6, src2, dst); + + SANITY_CHECK(dst, 1e-6); +} + } } // namespace cvtest::ocl #endif // HAVE_OPENCL diff --git a/modules/core/src/mathfuncs.cpp b/modules/core/src/mathfuncs.cpp index 90e0d74a49..15bd93ef53 100644 --- a/modules/core/src/mathfuncs.cpp +++ b/modules/core/src/mathfuncs.cpp @@ -2375,7 +2375,7 @@ static bool ocl_patchNaNs( InputOutputArray _a, float value ) int cn = a.channels(); k.args(ocl::KernelArg::ReadOnlyNoSize(a), - ocl::KernelArg::WriteOnly(a), (float)value); + ocl::KernelArg::WriteOnly(a, cn), (float)value); size_t globalsize[2] = { a.cols * cn, a.rows }; return k.run(2, globalsize, NULL, false);