Path: blob/master/modules/core/perf/opencl/perf_channels.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-2012, Multicoreware, Inc., all rights reserved.13// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.14// Third party copyrights are property of their respective owners.15//16// @Authors17// Fangfang Bai, [email protected]18// Jin Ma, [email protected]19//20// Redistribution and use in source and binary forms, with or without modification,21// are permitted provided that the following conditions are met:22//23// * Redistribution's of source code must retain the above copyright notice,24// this list of conditions and the following disclaimer.25//26// * Redistribution's in binary form must reproduce the above copyright notice,27// this list of conditions and the following disclaimer in the documentation28// and/or other materials provided with the distribution.29//30// * The name of the copyright holders may not be used to endorse or promote products31// derived from this software without specific prior written permission.32//33// This software is provided by the copyright holders and contributors as is and34// any express or implied warranties, including, but not limited to, the implied35// warranties of merchantability and fitness for a particular purpose are disclaimed.36// In no event shall the Intel Corporation or contributors be liable for any direct,37// indirect, incidental, special, exemplary, or consequential damages38// (including, but not limited to, procurement of substitute goods or services;39// loss of use, data, or profits; or business interruption) however caused40// and on any theory of liability, whether in contract, strict liability,41// or tort (including negligence or otherwise) arising in any way out of42// the use of this software, even if advised of the possibility of such damage.43//44//M*/4546#include "../perf_precomp.hpp"47#include "opencv2/ts/ocl_perf.hpp"4849#ifdef HAVE_OPENCL5051namespace opencv_test {52namespace ocl {5354///////////// Merge////////////////////////5556typedef tuple<Size, MatDepth, int> MergeParams;57typedef TestBaseWithParam<MergeParams> MergeFixture;5859OCL_PERF_TEST_P(MergeFixture, Merge,60::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8U, CV_32F), Values(2, 3)))61{62const MergeParams params = GetParam();63const Size srcSize = get<0>(params);64const int depth = get<1>(params), cn = get<2>(params), dtype = CV_MAKE_TYPE(depth, cn);6566checkDeviceMaxMemoryAllocSize(srcSize, dtype);6768UMat dst(srcSize, dtype);69vector<UMat> src(cn);70for (vector<UMat>::iterator i = src.begin(), end = src.end(); i != end; ++i)71{72i->create(srcSize, CV_MAKE_TYPE(depth, 1));73declare.in(*i, WARMUP_RNG);74}75declare.out(dst);7677OCL_TEST_CYCLE() cv::merge(src, dst);7879SANITY_CHECK(dst);80}8182///////////// Split ////////////////////////8384typedef MergeParams SplitParams;85typedef TestBaseWithParam<SplitParams> SplitFixture;8687OCL_PERF_TEST_P(SplitFixture, Split,88::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8U, CV_32F), Values(2, 3)))89{90const SplitParams params = GetParam();91const Size srcSize = get<0>(params);92const int depth = get<1>(params), cn = get<2>(params), type = CV_MAKE_TYPE(depth, cn);9394ASSERT_TRUE(cn == 3 || cn == 2);9596checkDeviceMaxMemoryAllocSize(srcSize, type);9798UMat src(srcSize, type);99std::vector<UMat> dst(cn, UMat(srcSize, CV_MAKE_TYPE(depth, 1)));100101declare.in(src, WARMUP_RNG);102for (int i = 0; i < cn; ++i)103declare.in(dst[i]);104105OCL_TEST_CYCLE() cv::split(src, dst);106107ASSERT_EQ(cn, (int)dst.size());108109if (cn == 2)110{111UMat & dst0 = dst[0], & dst1 = dst[1];112SANITY_CHECK(dst0);113SANITY_CHECK(dst1);114}115else116{117UMat & dst0 = dst[0], & dst1 = dst[1], & dst2 = dst[2];118SANITY_CHECK(dst0);119SANITY_CHECK(dst1);120SANITY_CHECK(dst2);121}122}123124///////////// MixChannels ////////////////////////125126typedef tuple<Size, MatDepth> MixChannelsParams;127typedef TestBaseWithParam<MixChannelsParams> MixChannelsFixture;128129OCL_PERF_TEST_P(MixChannelsFixture, MixChannels,130::testing::Combine(Values(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),131OCL_PERF_ENUM(CV_8U, CV_32F)))132{133const MixChannelsParams params = GetParam();134const Size srcSize = get<0>(params);135const int depth = get<1>(params), type = CV_MAKE_TYPE(depth, 2), n = 2;136137checkDeviceMaxMemoryAllocSize(srcSize, type);138139std::vector<UMat> src(n), dst(n);140for (int i = 0; i < n; ++i)141{142src[i] = UMat(srcSize, type);143dst[i] = UMat(srcSize, type);144declare.in(src[i], WARMUP_RNG).out(dst[i]);145}146147int fromTo[] = { 1,2, 2,0, 0,3, 3,1 };148149OCL_TEST_CYCLE() cv::mixChannels(src, dst, fromTo, 4);150151UMat & dst0 = dst[0], & dst1 = dst[1];152SANITY_CHECK(dst0);153SANITY_CHECK(dst1);154}155156///////////// InsertChannel ////////////////////////157158typedef tuple<cv::Size, MatDepth> Size_MatDepth_t;159typedef TestBaseWithParam<Size_MatDepth_t> Size_MatDepth;160161typedef Size_MatDepth InsertChannelFixture;162163OCL_PERF_TEST_P(InsertChannelFixture, InsertChannel,164::testing::Combine(Values(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),165OCL_PERF_ENUM(CV_8U, CV_32F)))166{167const Size_MatDepth_t params = GetParam();168const Size srcSize = get<0>(params);169const int depth = get<1>(params), type = CV_MAKE_TYPE(depth, 3);170171checkDeviceMaxMemoryAllocSize(srcSize, type);172173UMat src(srcSize, depth), dst(srcSize, type, Scalar::all(17));174declare.in(src, WARMUP_RNG).out(dst);175176OCL_TEST_CYCLE() cv::insertChannel(src, dst, 1);177178SANITY_CHECK(dst);179}180181///////////// ExtractChannel ////////////////////////182183typedef Size_MatDepth ExtractChannelFixture;184185OCL_PERF_TEST_P(ExtractChannelFixture, ExtractChannel,186::testing::Combine(Values(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),187OCL_PERF_ENUM(CV_8U, CV_32F)))188{189const Size_MatDepth_t params = GetParam();190const Size srcSize = get<0>(params);191const int depth = get<1>(params), type = CV_MAKE_TYPE(depth, 3);192193checkDeviceMaxMemoryAllocSize(srcSize, type);194195UMat src(srcSize, type), dst(srcSize, depth);196declare.in(src, WARMUP_RNG).out(dst);197198OCL_TEST_CYCLE() cv::extractChannel(src, dst, 1);199200SANITY_CHECK(dst);201}202203} } // namespace opencv_test::ocl204205#endif // HAVE_OPENCL206207208