Path: blob/master/modules/core/perf/opencl/perf_arithm.cpp
16358 views
/*M///////////////////////////////////////////////////////////////////////////////////////1//2// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.3//4// By downloading, copying, installing or using the software you agree to this license.5// If you do not agree to this license, do not download, install,6// copy or use the software.7//8//9// License Agreement10// For Open Source Computer Vision Library11//12// Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved.13// Third party copyrights are property of their respective owners.14//15// Redistribution and use in source and binary forms, with or without modification,16// are permitted provided that the following conditions are met:17//18// * Redistribution's of source code must retain the above copyright notice,19// this list of conditions and the following disclaimer.20//21// * Redistribution's in binary form must reproduce the above copyright notice,22// this list of conditions and the following disclaimer in the documentation23// and/or other materials provided with the distribution.24//25// * The name of the copyright holders may not be used to endorse or promote products26// derived from this software without specific prior written permission.27//28// This software is provided by the copyright holders and contributors "as is" and29// any express or implied warranties, including, but not limited to, the implied30// warranties of merchantability and fitness for a particular purpose are disclaimed.31// In no event shall the OpenCV Foundation or contributors be liable for any direct,32// indirect, incidental, special, exemplary, or consequential damages33// (including, but not limited to, procurement of substitute goods or services;34// loss of use, data, or profits; or business interruption) however caused35// and on any theory of liability, whether in contract, strict liability,36// or tort (including negligence or otherwise) arising in any way out of37// the use of this software, even if advised of the possibility of such damage.38//39//M*/4041#include "../perf_precomp.hpp"42#include "opencv2/ts/ocl_perf.hpp"4344#ifdef HAVE_OPENCL4546namespace opencv_test {47namespace ocl {4849///////////// Lut ////////////////////////5051typedef Size_MatType LUTFixture;5253OCL_PERF_TEST_P(LUTFixture, LUT,54::testing::Combine(OCL_TEST_SIZES,55OCL_TEST_TYPES))56{57const Size_MatType_t params = GetParam();58const Size srcSize = get<0>(params);59const int type = get<1>(params), cn = CV_MAT_CN(type);6061checkDeviceMaxMemoryAllocSize(srcSize, type);6263UMat src(srcSize, CV_8UC(cn)), lut(1, 256, type);64int dstType = CV_MAKETYPE(lut.depth(), src.channels());65UMat dst(srcSize, dstType);6667declare.in(src, lut, WARMUP_RNG).out(dst);6869OCL_TEST_CYCLE() cv::LUT(src, lut, dst);7071SANITY_CHECK(dst);72}7374///////////// Exp ////////////////////////7576typedef Size_MatType ExpFixture;7778OCL_PERF_TEST_P(ExpFixture, Exp, ::testing::Combine(79OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))80{81const Size_MatType_t params = GetParam();82const Size srcSize = get<0>(params);83const int type = get<1>(params);8485checkDeviceMaxMemoryAllocSize(srcSize, type);8687UMat src(srcSize, type), dst(srcSize, type);88declare.in(src).out(dst);89randu(src, 5, 16);9091OCL_TEST_CYCLE() cv::exp(src, dst);9293if (CV_MAT_DEPTH(type) >= CV_32F)94SANITY_CHECK(dst, 1e-5, ERROR_RELATIVE);95else96SANITY_CHECK(dst, 1);97}9899///////////// Log ////////////////////////100101typedef Size_MatType LogFixture;102103OCL_PERF_TEST_P(LogFixture, Log, ::testing::Combine(104OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))105{106const Size_MatType_t params = GetParam();107const Size srcSize = get<0>(params);108const int type = get<1>(params);109110checkDeviceMaxMemoryAllocSize(srcSize, type);111112UMat src(srcSize, type), dst(srcSize, type);113randu(src, 1, 10000);114declare.in(src).out(dst);115116OCL_TEST_CYCLE() cv::log(src, dst);117118if (CV_MAT_DEPTH(type) >= CV_32F)119SANITY_CHECK(dst, 2e-4, ERROR_RELATIVE);120else121SANITY_CHECK(dst, 1);122}123124///////////// Add ////////////////////////125126typedef Size_MatType AddFixture;127128OCL_PERF_TEST_P(AddFixture, Add,129::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))130{131const Size srcSize = GET_PARAM(0);132const int type = GET_PARAM(1);133134checkDeviceMaxMemoryAllocSize(srcSize, type);135136UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);137declare.in(src1, src2, WARMUP_RNG).out(dst);138139OCL_TEST_CYCLE() cv::add(src1, src2, dst);140141SANITY_CHECK(dst);142}143144///////////// Subtract ////////////////////////145146typedef Size_MatType SubtractFixture;147148OCL_PERF_TEST_P(SubtractFixture, Subtract,149::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))150{151const Size_MatType_t params = GetParam();152const Size srcSize = get<0>(params);153const int type = get<1>(params);154155checkDeviceMaxMemoryAllocSize(srcSize, type);156157UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);158declare.in(src1, src2, WARMUP_RNG).out(dst);159160OCL_TEST_CYCLE() cv::subtract(src1, src2, dst);161162SANITY_CHECK(dst);163}164165///////////// Mul ////////////////////////166167typedef Size_MatType MulFixture;168169OCL_PERF_TEST_P(MulFixture, Multiply, ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))170{171const Size_MatType_t params = GetParam();172const Size srcSize = get<0>(params);173const int type = get<1>(params);174175checkDeviceMaxMemoryAllocSize(srcSize, type);176177UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);178declare.in(src1, src2, WARMUP_RNG).out(dst);179180OCL_TEST_CYCLE() cv::multiply(src1, src2, dst);181182SANITY_CHECK(dst);183}184185///////////// Div ////////////////////////186187typedef Size_MatType DivFixture;188189OCL_PERF_TEST_P(DivFixture, Divide,190::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))191{192const Size_MatType_t params = GetParam();193const Size srcSize = get<0>(params);194const int type = get<1>(params);195196checkDeviceMaxMemoryAllocSize(srcSize, type);197198UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);199declare.in(src1, src2, WARMUP_RNG).out(dst);200201// remove zeros from src2202{203Mat m2 = src2.getMat(ACCESS_RW);204Mat zero_mask = m2 == 0;205Mat fix;206zero_mask.convertTo(fix, type); // 0 or 255207cv::add(m2, fix, m2);208}209210OCL_TEST_CYCLE() cv::divide(src1, src2, dst);211212if (CV_MAT_DEPTH(type) >= CV_32F)213SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);214else215SANITY_CHECK(dst, 1);216}217218///////////// Absdiff ////////////////////////219220typedef Size_MatType AbsDiffFixture;221222OCL_PERF_TEST_P(AbsDiffFixture, Absdiff,223::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))224{225const Size_MatType_t params = GetParam();226const Size srcSize = get<0>(params);227const int type = get<1>(params);228229checkDeviceMaxMemoryAllocSize(srcSize, type);230231UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);232declare.in(src1, src2, WARMUP_RNG).in(dst);233234OCL_TEST_CYCLE() cv::absdiff(src1, src2, dst);235236SANITY_CHECK(dst);237}238239///////////// CartToPolar ////////////////////////240241typedef Size_MatType CartToPolarFixture;242243OCL_PERF_TEST_P(CartToPolarFixture, CartToPolar, ::testing::Combine(244OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))245{246const Size_MatType_t params = GetParam();247const Size srcSize = get<0>(params);248const int type = get<1>(params);249250checkDeviceMaxMemoryAllocSize(srcSize, type);251252UMat src1(srcSize, type), src2(srcSize, type),253dst1(srcSize, type), dst2(srcSize, type);254declare.in(src1, src2, WARMUP_RNG).out(dst1, dst2);255256OCL_TEST_CYCLE() cv::cartToPolar(src1, src2, dst1, dst2);257258SANITY_CHECK(dst1, 8e-3);259SANITY_CHECK(dst2, 8e-3);260}261262///////////// PolarToCart ////////////////////////263264typedef Size_MatType PolarToCartFixture;265266OCL_PERF_TEST_P(PolarToCartFixture, PolarToCart, ::testing::Combine(267OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))268{269const Size_MatType_t params = GetParam();270const Size srcSize = get<0>(params);271const int type = get<1>(params);272273checkDeviceMaxMemoryAllocSize(srcSize, type);274275UMat src1(srcSize, type), src2(srcSize, type),276dst1(srcSize, type), dst2(srcSize, type);277declare.in(src1, src2, WARMUP_RNG).out(dst1, dst2);278279OCL_TEST_CYCLE() cv::polarToCart(src1, src2, dst1, dst2);280281SANITY_CHECK(dst1, 5e-5);282SANITY_CHECK(dst2, 5e-5);283}284285///////////// Magnitude ////////////////////////286287typedef Size_MatType MagnitudeFixture;288289OCL_PERF_TEST_P(MagnitudeFixture, Magnitude, ::testing::Combine(290OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))291{292const Size_MatType_t params = GetParam();293const Size srcSize = get<0>(params);294const int type = get<1>(params);295296checkDeviceMaxMemoryAllocSize(srcSize, type);297298UMat src1(srcSize, type), src2(srcSize, type),299dst(srcSize, type);300declare.in(src1, src2, WARMUP_RNG).out(dst);301302OCL_TEST_CYCLE() cv::magnitude(src1, src2, dst);303304SANITY_CHECK(dst, 1e-6);305}306307///////////// Transpose ////////////////////////308309typedef Size_MatType TransposeFixture;310311OCL_PERF_TEST_P(TransposeFixture, Transpose, ::testing::Combine(312OCL_TEST_SIZES, OCL_TEST_TYPES_134))313{314const Size_MatType_t params = GetParam();315const Size srcSize = get<0>(params);316const int type = get<1>(params);317318checkDeviceMaxMemoryAllocSize(srcSize, type);319320UMat src(srcSize, type), dst(srcSize, type);321declare.in(src, WARMUP_RNG).out(dst);322323OCL_TEST_CYCLE() cv::transpose(src, dst);324325SANITY_CHECK(dst);326}327328OCL_PERF_TEST_P(TransposeFixture, TransposeInplace, ::testing::Combine(329OCL_PERF_ENUM(Size(640, 640), Size(1280, 1280), Size(2160, 2160)), OCL_TEST_TYPES_134))330{331const Size_MatType_t params = GetParam();332const Size srcSize = get<0>(params);333const int type = get<1>(params);334335checkDeviceMaxMemoryAllocSize(srcSize, type);336337UMat src(srcSize, type);338declare.in(src, WARMUP_RNG).out(src, WARMUP_NONE);339340OCL_TEST_CYCLE() cv::transpose(src, src);341342SANITY_CHECK_NOTHING();343}344345///////////// Flip ////////////////////////346347enum348{349FLIP_BOTH = 0, FLIP_ROWS, FLIP_COLS350};351352CV_ENUM(FlipType, FLIP_BOTH, FLIP_ROWS, FLIP_COLS)353354typedef tuple<Size, MatType, FlipType> FlipParams;355typedef TestBaseWithParam<FlipParams> FlipFixture;356357OCL_PERF_TEST_P(FlipFixture, Flip,358::testing::Combine(OCL_TEST_SIZES,359OCL_TEST_TYPES, FlipType::all()))360{361const FlipParams params = GetParam();362const Size srcSize = get<0>(params);363const int type = get<1>(params);364const int flipType = get<2>(params);365366checkDeviceMaxMemoryAllocSize(srcSize, type);367368UMat src(srcSize, type), dst(srcSize, type);369declare.in(src, WARMUP_RNG).out(dst);370371OCL_TEST_CYCLE() cv::flip(src, dst, flipType - 1);372373SANITY_CHECK(dst);374}375376///////////// minMaxLoc ////////////////////////377378typedef Size_MatType MinMaxLocFixture;379380OCL_PERF_TEST_P(MinMaxLocFixture, MinMaxLoc,381::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))382{383const Size_MatType_t params = GetParam();384const Size srcSize = get<0>(params);385const int type = get<1>(params);386bool onecn = CV_MAT_CN(type) == 1;387388checkDeviceMaxMemoryAllocSize(srcSize, type);389390UMat src(srcSize, type);;391declare.in(src, WARMUP_RNG);392393double min_val = 0.0, max_val = 0.0;394Point min_loc, max_loc;395396OCL_TEST_CYCLE() cv::minMaxLoc(src, &min_val, &max_val, onecn ? &min_loc : NULL,397onecn ? &max_loc : NULL);398399ASSERT_GE(max_val, min_val);400SANITY_CHECK(min_val);401SANITY_CHECK(max_val);402403int min_loc_x = min_loc.x, min_loc_y = min_loc.y, max_loc_x = max_loc.x,404max_loc_y = max_loc.y;405SANITY_CHECK(min_loc_x);406SANITY_CHECK(min_loc_y);407SANITY_CHECK(max_loc_x);408SANITY_CHECK(max_loc_y);409}410411///////////// Sum ////////////////////////412413typedef Size_MatType SumFixture;414415OCL_PERF_TEST_P(SumFixture, Sum,416::testing::Combine(OCL_TEST_SIZES,417OCL_TEST_TYPES_134))418{419const Size_MatType_t params = GetParam();420const Size srcSize = get<0>(params);421const int type = get<1>(params), depth = CV_MAT_DEPTH(type);422423checkDeviceMaxMemoryAllocSize(srcSize, type);424425UMat src(srcSize, type);426Scalar result;427randu(src, 0, 60);428declare.in(src);429430OCL_TEST_CYCLE() result = cv::sum(src);431432if (depth >= CV_32F)433SANITY_CHECK(result, 1e-6, ERROR_RELATIVE);434else435SANITY_CHECK(result);436}437438///////////// countNonZero ////////////////////////439440typedef Size_MatType CountNonZeroFixture;441442OCL_PERF_TEST_P(CountNonZeroFixture, CountNonZero,443::testing::Combine(OCL_TEST_SIZES,444OCL_PERF_ENUM(CV_8UC1, CV_32FC1)))445{446const Size_MatType_t params = GetParam();447const Size srcSize = get<0>(params);448const int type = get<1>(params);449450checkDeviceMaxMemoryAllocSize(srcSize, type);451452UMat src(srcSize, type);453int result = 0;454randu(src, 0, 10);455declare.in(src);456457OCL_TEST_CYCLE() result = cv::countNonZero(src);458459SANITY_CHECK(result);460}461462///////////// Phase ////////////////////////463464typedef Size_MatType PhaseFixture;465466OCL_PERF_TEST_P(PhaseFixture, Phase, ::testing::Combine(467OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))468{469const Size_MatType_t params = GetParam();470const Size srcSize = get<0>(params);471const int type = get<1>(params);472473checkDeviceMaxMemoryAllocSize(srcSize, type);474475UMat src1(srcSize, type), src2(srcSize, type),476dst(srcSize, type);477declare.in(src1, src2, WARMUP_RNG).out(dst);478479OCL_TEST_CYCLE() cv::phase(src1, src2, dst, 1);480481SANITY_CHECK(dst, 1e-2);482}483484///////////// bitwise_and ////////////////////////485486typedef Size_MatType BitwiseAndFixture;487488OCL_PERF_TEST_P(BitwiseAndFixture, Bitwise_and,489::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))490{491const Size_MatType_t params = GetParam();492const Size srcSize = get<0>(params);493const int type = get<1>(params);494495checkDeviceMaxMemoryAllocSize(srcSize, type);496497UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);498declare.in(src1, src2, WARMUP_RNG).out(dst);499500OCL_TEST_CYCLE() cv::bitwise_and(src1, src2, dst);501502SANITY_CHECK(dst);503}504505///////////// bitwise_xor ////////////////////////506507typedef Size_MatType BitwiseXorFixture;508509OCL_PERF_TEST_P(BitwiseXorFixture, Bitwise_xor,510::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))511{512const Size_MatType_t params = GetParam();513const Size srcSize = get<0>(params);514const int type = get<1>(params);515516checkDeviceMaxMemoryAllocSize(srcSize, type);517518UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);519declare.in(src1, src2, WARMUP_RNG).out(dst);520521OCL_TEST_CYCLE() cv::bitwise_xor(src1, src2, dst);522523SANITY_CHECK(dst);524}525526///////////// bitwise_or ////////////////////////527528typedef Size_MatType BitwiseOrFixture;529530OCL_PERF_TEST_P(BitwiseOrFixture, Bitwise_or,531::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))532{533const Size_MatType_t params = GetParam();534const Size srcSize = get<0>(params);535const int type = get<1>(params);536537checkDeviceMaxMemoryAllocSize(srcSize, type);538539UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);540declare.in(src1, src2, WARMUP_RNG).out(dst);541542OCL_TEST_CYCLE() cv::bitwise_or(src1, src2, dst);543544SANITY_CHECK(dst);545}546547///////////// bitwise_not ////////////////////////548549typedef Size_MatType BitwiseNotFixture;550551OCL_PERF_TEST_P(BitwiseNotFixture, Bitwise_not,552::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))553{554const Size_MatType_t params = GetParam();555const Size srcSize = get<0>(params);556const int type = get<1>(params);557558checkDeviceMaxMemoryAllocSize(srcSize, type);559560UMat src(srcSize, type), dst(srcSize, type);561declare.in(src, WARMUP_RNG).out(dst);562563OCL_TEST_CYCLE() cv::bitwise_not(src, dst);564565SANITY_CHECK(dst);566}567568///////////// compare ////////////////////////569570CV_ENUM(CmpCode, CMP_LT, CMP_LE, CMP_EQ, CMP_NE, CMP_GE, CMP_GT)571572typedef tuple<Size, MatType, CmpCode> CompareParams;573typedef TestBaseWithParam<CompareParams> CompareFixture;574575OCL_PERF_TEST_P(CompareFixture, Compare,576::testing::Combine(OCL_TEST_SIZES,577OCL_TEST_TYPES_134, CmpCode::all()))578{579const CompareParams params = GetParam();580const Size srcSize = get<0>(params);581const int type = get<1>(params);582const int cmpCode = get<2>(params);583584checkDeviceMaxMemoryAllocSize(srcSize, type);585586UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, CV_8UC(CV_MAT_CN(type)));587declare.in(src1, src2, WARMUP_RNG).out(dst);588589OCL_TEST_CYCLE() cv::compare(src1, src2, dst, cmpCode);590591SANITY_CHECK(dst);592}593594OCL_PERF_TEST_P(CompareFixture, CompareScalar,595::testing::Combine(OCL_TEST_SIZES,596OCL_PERF_ENUM((MatType)CV_32FC1), // TODO: OCL_TEST_TYPES_134597CmpCode::all()))598{599const CompareParams params = GetParam();600const Size srcSize = get<0>(params);601const int type = get<1>(params);602const int cmpCode = get<2>(params);603604checkDeviceMaxMemoryAllocSize(srcSize, type);605606UMat src1(srcSize, type), dst(srcSize, CV_8UC(CV_MAT_CN(type)));607declare.in(src1, WARMUP_RNG).out(dst);608609OCL_TEST_CYCLE() cv::compare(src1, 32, dst, cmpCode);610611SANITY_CHECK(dst);612}613614///////////// pow ////////////////////////615616typedef Size_MatType PowFixture;617618OCL_PERF_TEST_P(PowFixture, Pow, ::testing::Combine(619OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))620{621const Size_MatType_t params = GetParam();622const Size srcSize = get<0>(params);623const int type = get<1>(params);624625checkDeviceMaxMemoryAllocSize(srcSize, type);626627UMat src(srcSize, type), dst(srcSize, type);628randu(src, 0, 100);629declare.in(src).out(dst);630631OCL_TEST_CYCLE() cv::pow(src, 2.17, dst);632633SANITY_CHECK(dst, 1.5e-6, ERROR_RELATIVE);634}635636///////////// AddWeighted////////////////////////637638typedef Size_MatType AddWeightedFixture;639640OCL_PERF_TEST_P(AddWeightedFixture, AddWeighted,641::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))642{643const Size_MatType_t params = GetParam();644const Size srcSize = get<0>(params);645const int type = get<1>(params), depth = CV_MAT_DEPTH(type);646647checkDeviceMaxMemoryAllocSize(srcSize, type);648649UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);650declare.in(src1, src2, WARMUP_RNG).out(dst);651double alpha = 2.0, beta = 1.0, gama = 3.0;652653OCL_TEST_CYCLE() cv::addWeighted(src1, alpha, src2, beta, gama, dst);654655if (depth >= CV_32F)656SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);657else658SANITY_CHECK(dst);659}660661///////////// Sqrt ///////////////////////662663typedef Size_MatType SqrtFixture;664665OCL_PERF_TEST_P(SqrtFixture, Sqrt, ::testing::Combine(666OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))667{668const Size_MatType_t params = GetParam();669const Size srcSize = get<0>(params);670const int type = get<1>(params);671672checkDeviceMaxMemoryAllocSize(srcSize, type);673674UMat src(srcSize, type), dst(srcSize, type);675randu(src, 0, 1000);676declare.in(src).out(dst);677678OCL_TEST_CYCLE() cv::sqrt(src, dst);679680if (CV_MAT_DEPTH(type) >= CV_32F)681SANITY_CHECK(dst, 1e-5, ERROR_RELATIVE);682else683SANITY_CHECK(dst, 1);684}685686///////////// SetIdentity ////////////////////////687688typedef Size_MatType SetIdentityFixture;689690OCL_PERF_TEST_P(SetIdentityFixture, SetIdentity,691::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES))692{693const Size_MatType_t params = GetParam();694const Size srcSize = get<0>(params);695const int type = get<1>(params);696697checkDeviceMaxMemoryAllocSize(srcSize, type);698699UMat dst(srcSize, type);700declare.out(dst);701702OCL_TEST_CYCLE() cv::setIdentity(dst, cv::Scalar::all(181));703704SANITY_CHECK(dst);705}706707///////////// MeanStdDev ////////////////////////708709typedef Size_MatType MeanStdDevFixture;710711OCL_PERF_TEST_P(MeanStdDevFixture, MeanStdDev,712::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),713OCL_TEST_TYPES_134))714{715const Size_MatType_t params = GetParam();716const Size srcSize = get<0>(params);717const int type = get<1>(params);718const double eps = 2e-5;719720checkDeviceMaxMemoryAllocSize(srcSize, type);721722UMat src(srcSize, type);723Scalar mean, stddev;724declare.in(src, WARMUP_RNG);725726OCL_TEST_CYCLE() cv::meanStdDev(src, mean, stddev);727728double mean0 = mean[0], mean1 = mean[1], mean2 = mean[2], mean3 = mean[3];729double stddev0 = stddev[0], stddev1 = stddev[1], stddev2 = stddev[2], stddev3 = stddev[3];730731SANITY_CHECK(mean0, eps, ERROR_RELATIVE);732SANITY_CHECK(mean1, eps, ERROR_RELATIVE);733SANITY_CHECK(mean2, eps, ERROR_RELATIVE);734SANITY_CHECK(mean3, eps, ERROR_RELATIVE);735SANITY_CHECK(stddev0, eps, ERROR_RELATIVE);736SANITY_CHECK(stddev1, eps, ERROR_RELATIVE);737SANITY_CHECK(stddev2, eps, ERROR_RELATIVE);738SANITY_CHECK(stddev3, eps, ERROR_RELATIVE);739}740741OCL_PERF_TEST_P(MeanStdDevFixture, MeanStdDevWithMask,742::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),743OCL_TEST_TYPES_134))744{745const Size_MatType_t params = GetParam();746const Size srcSize = get<0>(params);747const int type = get<1>(params);748const double eps = 2e-5;749750checkDeviceMaxMemoryAllocSize(srcSize, type);751752UMat src(srcSize, type), mask(srcSize, CV_8UC1);753Scalar mean, stddev;754declare.in(src, mask, WARMUP_RNG);755756OCL_TEST_CYCLE() cv::meanStdDev(src, mean, stddev, mask);757758double mean0 = mean[0], mean1 = mean[1], mean2 = mean[2], mean3 = mean[3];759double stddev0 = stddev[0], stddev1 = stddev[1], stddev2 = stddev[2], stddev3 = stddev[3];760761SANITY_CHECK(mean0, eps, ERROR_RELATIVE);762SANITY_CHECK(mean1, eps, ERROR_RELATIVE);763SANITY_CHECK(mean2, eps, ERROR_RELATIVE);764SANITY_CHECK(mean3, eps, ERROR_RELATIVE);765SANITY_CHECK(stddev0, eps, ERROR_RELATIVE);766SANITY_CHECK(stddev1, eps, ERROR_RELATIVE);767SANITY_CHECK(stddev2, eps, ERROR_RELATIVE);768SANITY_CHECK(stddev3, eps, ERROR_RELATIVE);769}770771///////////// Norm ////////////////////////772773CV_ENUM(NormType, NORM_INF, NORM_L1, NORM_L2)774775typedef tuple<Size, MatType, NormType> NormParams;776typedef TestBaseWithParam<NormParams> NormFixture;777778OCL_PERF_TEST_P(NormFixture, Norm1Arg,779::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),780OCL_TEST_TYPES_134, NormType::all()))781{782const NormParams params = GetParam();783const Size srcSize = get<0>(params);784const int type = get<1>(params);785const int normType = get<2>(params);786787checkDeviceMaxMemoryAllocSize(srcSize, type);788789UMat src1(srcSize, type);790double res;791declare.in(src1, WARMUP_RNG);792793OCL_TEST_CYCLE() res = cv::norm(src1, normType);794795SANITY_CHECK(res, 1e-5, ERROR_RELATIVE);796}797798OCL_PERF_TEST_P(NormFixture, Norm,799::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),800OCL_TEST_TYPES_134, NormType::all()))801{802const NormParams params = GetParam();803const Size srcSize = get<0>(params);804const int type = get<1>(params);805const int normType = get<2>(params);806807checkDeviceMaxMemoryAllocSize(srcSize, type);808809UMat src1(srcSize, type), src2(srcSize, type);810double res;811declare.in(src1, src2, WARMUP_RNG);812813OCL_TEST_CYCLE() res = cv::norm(src1, src2, normType);814815SANITY_CHECK(res, 1e-5, ERROR_RELATIVE);816}817818OCL_PERF_TEST_P(NormFixture, NormRel,819::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),820OCL_TEST_TYPES_134, NormType::all()))821{822const NormParams params = GetParam();823const Size srcSize = get<0>(params);824const int type = get<1>(params);825const int normType = get<2>(params);826827checkDeviceMaxMemoryAllocSize(srcSize, type);828829UMat src1(srcSize, type), src2(srcSize, type);830double res;831declare.in(src1, src2, WARMUP_RNG);832833OCL_TEST_CYCLE() res = cv::norm(src1, src2, normType | cv::NORM_RELATIVE);834835SANITY_CHECK(res, 1e-5, ERROR_RELATIVE);836}837838///////////// UMat::dot ////////////////////////839840typedef Size_MatType UMatDotFixture;841842OCL_PERF_TEST_P(UMatDotFixture, UMatDot,843::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),844OCL_TEST_TYPES_134))845{846const Size_MatType_t params = GetParam();847const Size srcSize = get<0>(params);848const int type = get<1>(params);849double r = 0.0;850851checkDeviceMaxMemoryAllocSize(srcSize, type);852853UMat src1(srcSize, type), src2(srcSize, type);854declare.in(src1, src2, WARMUP_RNG);855856OCL_TEST_CYCLE() r = src1.dot(src2);857858SANITY_CHECK(r, 1e-5, ERROR_RELATIVE);859}860861///////////// Repeat ////////////////////////862863typedef Size_MatType RepeatFixture;864865OCL_PERF_TEST_P(RepeatFixture, Repeat,866::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3), OCL_TEST_TYPES))867{868const Size_MatType_t params = GetParam();869const Size srcSize = get<0>(params);870const int type = get<1>(params), nx = 2, ny = 2;871872checkDeviceMaxMemoryAllocSize(srcSize, type);873874UMat src(srcSize, type), dst(Size(srcSize.width * nx, srcSize.height * ny), type);875declare.in(src, WARMUP_RNG).out(dst);876877OCL_TEST_CYCLE() cv::repeat(src, nx, ny, dst);878879SANITY_CHECK(dst);880}881882///////////// Min ////////////////////////883884typedef Size_MatType MinFixture;885886OCL_PERF_TEST_P(MinFixture, Min,887::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES))888{889const Size_MatType_t params = GetParam();890const Size srcSize = get<0>(params);891const int type = get<1>(params);892893checkDeviceMaxMemoryAllocSize(srcSize, type);894895UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);896declare.in(src1, src2, WARMUP_RNG).out(dst);897898OCL_TEST_CYCLE() cv::min(src1, src2, dst);899900SANITY_CHECK(dst);901}902903///////////// Max ////////////////////////904905typedef Size_MatType MaxFixture;906907OCL_PERF_TEST_P(MaxFixture, Max,908::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES))909{910const Size_MatType_t params = GetParam();911const Size srcSize = get<0>(params);912const int type = get<1>(params);913914checkDeviceMaxMemoryAllocSize(srcSize, type);915916UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);917declare.in(src1, src2, WARMUP_RNG).out(dst);918919OCL_TEST_CYCLE() cv::max(src1, src2, dst);920921SANITY_CHECK(dst);922}923924///////////// InRange ////////////////////////925926typedef Size_MatType InRangeFixture;927928OCL_PERF_TEST_P(InRangeFixture, InRange,929::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES))930{931const Size_MatType_t params = GetParam();932const Size srcSize = get<0>(params);933const int type = get<1>(params);934935checkDeviceMaxMemoryAllocSize(srcSize, type);936937UMat src(srcSize, type), lb(srcSize, type), ub(srcSize, type), dst(srcSize, CV_8UC1);938declare.in(src, lb, ub, WARMUP_RNG).out(dst);939940OCL_TEST_CYCLE() cv::inRange(src, lb, ub, dst);941942SANITY_CHECK(dst);943}944945///////////// Normalize ////////////////////////946947CV_ENUM(NormalizeModes, CV_MINMAX, CV_L2, CV_L1, CV_C)948949typedef tuple<Size, MatType, NormalizeModes> NormalizeParams;950typedef TestBaseWithParam<NormalizeParams> NormalizeFixture;951952OCL_PERF_TEST_P(NormalizeFixture, Normalize,953::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134,954NormalizeModes::all()))955{956const NormalizeParams params = GetParam();957const Size srcSize = get<0>(params);958const int type = get<1>(params), mode = get<2>(params);959960checkDeviceMaxMemoryAllocSize(srcSize, type);961962UMat src(srcSize, type), dst(srcSize, type);963declare.in(src, WARMUP_RNG).out(dst);964965OCL_TEST_CYCLE() cv::normalize(src, dst, 10, 110, mode);966967SANITY_CHECK(dst, 5e-2);968}969970OCL_PERF_TEST_P(NormalizeFixture, NormalizeWithMask,971::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC1, CV_32FC1),972NormalizeModes::all()))973{974const NormalizeParams params = GetParam();975const Size srcSize = get<0>(params);976const int type = get<1>(params), mode = get<2>(params);977978checkDeviceMaxMemoryAllocSize(srcSize, type);979980UMat src(srcSize, type), mask(srcSize, CV_8UC1), dst(srcSize, type);981declare.in(src, mask, WARMUP_RNG).out(dst);982983OCL_TEST_CYCLE() cv::normalize(src, dst, 10, 110, mode, -1, mask);984985SANITY_CHECK(dst, 5e-2);986}987988///////////// ConvertScaleAbs ////////////////////////989990typedef Size_MatType ConvertScaleAbsFixture;991992OCL_PERF_TEST_P(ConvertScaleAbsFixture, ConvertScaleAbs,993::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES))994{995const Size_MatType_t params = GetParam();996const Size srcSize = get<0>(params);997const int type = get<1>(params), cn = CV_MAT_CN(type);998999checkDeviceMaxMemoryAllocSize(srcSize, type);10001001UMat src(srcSize, type), dst(srcSize, CV_8UC(cn));1002declare.in(src, WARMUP_RNG).out(dst);10031004OCL_TEST_CYCLE() cv::convertScaleAbs(src, dst, 0.5, 2);10051006SANITY_CHECK(dst, 1); // CV_8U1007}10081009///////////// PatchNaNs ////////////////////////10101011typedef Size_MatType PatchNaNsFixture;10121013OCL_PERF_TEST_P(PatchNaNsFixture, PatchNaNs,1014::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4)))1015{1016const Size_MatType_t params = GetParam();1017Size srcSize = get<0>(params);1018const int type = get<1>(params), cn = CV_MAT_CN(type);10191020checkDeviceMaxMemoryAllocSize(srcSize, type);10211022UMat src(srcSize, type);1023declare.in(src, WARMUP_RNG).out(src);10241025// generating NaNs1026{1027Mat src_ = src.getMat(ACCESS_RW);1028srcSize.width *= cn;1029for (int y = 0; y < srcSize.height; ++y)1030{1031float * const ptr = src_.ptr<float>(y);1032for (int x = 0; x < srcSize.width; ++x)1033ptr[x] = (x + y) % 2 == 0 ? std::numeric_limits<float>::quiet_NaN() : ptr[x];1034}1035}10361037OCL_TEST_CYCLE() cv::patchNaNs(src, 17.7);10381039SANITY_CHECK(src);1040}104110421043///////////// ScaleAdd ////////////////////////10441045typedef Size_MatType ScaleAddFixture;10461047OCL_PERF_TEST_P(ScaleAddFixture, ScaleAdd,1048::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES))1049{1050const Size_MatType_t params = GetParam();1051const Size srcSize = get<0>(params);1052const int type = get<1>(params);10531054checkDeviceMaxMemoryAllocSize(srcSize, type);10551056UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);1057declare.in(src1, src2, WARMUP_RNG).out(dst);10581059OCL_TEST_CYCLE() cv::scaleAdd(src1, 0.6, src2, dst);10601061SANITY_CHECK(dst, 1e-6);1062}10631064///////////// Transform ////////////////////////10651066typedef Size_MatType TransformFixture;10671068OCL_PERF_TEST_P(TransformFixture, Transform,1069::testing::Combine(OCL_TEST_SIZES,1070::testing::Values(CV_8UC3, CV_8SC3, CV_16UC3, CV_16SC3, CV_32SC3, CV_32FC3, CV_64FC3)))1071{1072const Size_MatType_t params = GetParam();1073const Size srcSize = get<0>(params);1074const int type = get<1>(params);10751076checkDeviceMaxMemoryAllocSize(srcSize, type);10771078const float transform[] = { 0.5f, 0.f, 0.86602540378f, 128,10790.f, 1.f, 0.f, -64,10800.86602540378f, 0.f, 0.5f, 32,};1081Mat mtx(Size(4, 3), CV_32FC1, (void*)transform);10821083UMat src(srcSize, type), dst(srcSize, type);1084randu(src, 0, 30);1085declare.in(src).out(dst);10861087OCL_TEST_CYCLE() cv::transform(src, dst, mtx);10881089SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);1090}10911092///////////// PSNR ////////////////////////10931094typedef Size_MatType PSNRFixture;10951096OCL_PERF_TEST_P(PSNRFixture, PSNR,1097::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC1, CV_8UC4)))1098{1099const Size_MatType_t params = GetParam();1100const Size srcSize = get<0>(params);1101const int type = get<1>(params);11021103checkDeviceMaxMemoryAllocSize(srcSize, type);11041105double psnr = 0;1106UMat src1(srcSize, type), src2(srcSize, type);1107declare.in(src1, src2, WARMUP_RNG);11081109OCL_TEST_CYCLE() psnr = cv::PSNR(src1, src2);11101111SANITY_CHECK(psnr, 1e-4, ERROR_RELATIVE);1112}11131114///////////// Reduce ////////////////////////11151116CV_ENUM(ReduceMinMaxOp, CV_REDUCE_MIN, CV_REDUCE_MAX)11171118typedef tuple<Size, std::pair<MatType, MatType>, int, ReduceMinMaxOp> ReduceMinMaxParams;1119typedef TestBaseWithParam<ReduceMinMaxParams> ReduceMinMaxFixture;11201121OCL_PERF_TEST_P(ReduceMinMaxFixture, Reduce,1122::testing::Combine(OCL_TEST_SIZES,1123OCL_PERF_ENUM(std::make_pair<MatType, MatType>(CV_8UC1, CV_8UC1),1124std::make_pair<MatType, MatType>(CV_32FC4, CV_32FC4)),1125OCL_PERF_ENUM(0, 1),1126ReduceMinMaxOp::all()))1127{1128const ReduceMinMaxParams params = GetParam();1129const std::pair<MatType, MatType> types = get<1>(params);1130const int stype = types.first, dtype = types.second,1131dim = get<2>(params), op = get<3>(params);1132const Size srcSize = get<0>(params),1133dstSize(dim == 0 ? srcSize.width : 1, dim == 0 ? 1 : srcSize.height);1134const double eps = CV_MAT_DEPTH(dtype) <= CV_32S ? 1 : 1e-5;11351136checkDeviceMaxMemoryAllocSize(srcSize, stype);1137checkDeviceMaxMemoryAllocSize(srcSize, dtype);11381139UMat src(srcSize, stype), dst(dstSize, dtype);1140declare.in(src, WARMUP_RNG).out(dst);11411142OCL_TEST_CYCLE() cv::reduce(src, dst, dim, op, dtype);11431144SANITY_CHECK(dst, eps);1145}11461147CV_ENUM(ReduceAccOp, CV_REDUCE_SUM, CV_REDUCE_AVG)11481149typedef tuple<Size, std::pair<MatType, MatType>, int, ReduceAccOp> ReduceAccParams;1150typedef TestBaseWithParam<ReduceAccParams> ReduceAccFixture;11511152OCL_PERF_TEST_P(ReduceAccFixture, Reduce,1153::testing::Combine(OCL_TEST_SIZES,1154OCL_PERF_ENUM(std::make_pair<MatType, MatType>(CV_8UC4, CV_32SC4),1155std::make_pair<MatType, MatType>(CV_32FC1, CV_32FC1)),1156OCL_PERF_ENUM(0, 1),1157ReduceAccOp::all()))1158{1159const ReduceAccParams params = GetParam();1160const std::pair<MatType, MatType> types = get<1>(params);1161const int stype = types.first, dtype = types.second,1162dim = get<2>(params), op = get<3>(params);1163const Size srcSize = get<0>(params),1164dstSize(dim == 0 ? srcSize.width : 1, dim == 0 ? 1 : srcSize.height);1165const double eps = CV_MAT_DEPTH(dtype) <= CV_32S ? 1 : 3e-4;11661167checkDeviceMaxMemoryAllocSize(srcSize, stype);1168checkDeviceMaxMemoryAllocSize(srcSize, dtype);11691170UMat src(srcSize, stype), dst(dstSize, dtype);1171declare.in(src, WARMUP_RNG).out(dst);11721173OCL_TEST_CYCLE() cv::reduce(src, dst, dim, op, dtype);11741175SANITY_CHECK(dst, eps);1176}11771178} } // namespace opencv_test::ocl11791180#endif // HAVE_OPENCL118111821183