1 /*M/////////////////////////////////////////////////////////////////////////////////////// 2 // 3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 // 5 // By downloading, copying, installing or using the software you agree to this license. 6 // If you do not agree to this license, do not download, install, 7 // copy or use the software. 8 // 9 // 10 // License Agreement 11 // For Open Source Computer Vision Library 12 // 13 // Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved. 14 // Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved. 15 // Third party copyrights are property of their respective owners. 16 // 17 // @Authors 18 // Fangfang Bai, fangfang (at) multicorewareinc.com 19 // Jin Ma, jin (at) multicorewareinc.com 20 // 21 // Redistribution and use in source and binary forms, with or without modification, 22 // are permitted provided that the following conditions are met: 23 // 24 // * Redistribution's of source code must retain the above copyright notice, 25 // this list of conditions and the following disclaimer. 26 // 27 // * Redistribution's in binary form must reproduce the above copyright notice, 28 // this list of conditions and the following disclaimer in the documentation 29 // and/or other materials provided with the distribution. 30 // 31 // * The name of the copyright holders may not be used to endorse or promote products 32 // derived from this software without specific prior written permission. 33 // 34 // This software is provided by the copyright holders and contributors as is and 35 // any express or implied warranties, including, but not limited to, the implied 36 // warranties of merchantability and fitness for a particular purpose are disclaimed. 37 // In no event shall the Intel Corporation or contributors be liable for any direct, 38 // indirect, incidental, special, exemplary, or consequential damages 39 // (including, but not limited to, procurement of substitute goods or services; 40 // loss of use, data, or profits; or business interruption) however caused 41 // and on any theory of liability, whether in contract, strict liability, 42 // or tort (including negligence or otherwise) arising in any way out of 43 // the use of this software, even if advised of the possibility of such damage. 44 // 45 //M*/ 46 47 #include "../perf_precomp.hpp" 48 #include "opencv2/ts/ocl_perf.hpp" 49 50 #ifdef HAVE_OPENCL 51 52 namespace cvtest { 53 namespace ocl { 54 55 ///////////// Merge//////////////////////// 56 57 typedef tuple<Size, MatDepth, int> MergeParams; 58 typedef TestBaseWithParam<MergeParams> MergeFixture; 59 60 OCL_PERF_TEST_P(MergeFixture, Merge, 61 ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8U, CV_32F), Values(2, 3))) 62 { 63 const MergeParams params = GetParam(); 64 const Size srcSize = get<0>(params); 65 const int depth = get<1>(params), cn = get<2>(params), dtype = CV_MAKE_TYPE(depth, cn); 66 67 checkDeviceMaxMemoryAllocSize(srcSize, dtype); 68 69 UMat dst(srcSize, dtype); 70 vector<UMat> src(cn); 71 for (vector<UMat>::iterator i = src.begin(), end = src.end(); i != end; ++i) 72 { 73 i->create(srcSize, CV_MAKE_TYPE(depth, 1)); 74 declare.in(*i, WARMUP_RNG); 75 } 76 declare.out(dst); 77 78 OCL_TEST_CYCLE() cv::merge(src, dst); 79 80 SANITY_CHECK(dst); 81 } 82 83 ///////////// Split //////////////////////// 84 85 typedef MergeParams SplitParams; 86 typedef TestBaseWithParam<SplitParams> SplitFixture; 87 88 OCL_PERF_TEST_P(SplitFixture, Split, 89 ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8U, CV_32F), Values(2, 3))) 90 { 91 const SplitParams params = GetParam(); 92 const Size srcSize = get<0>(params); 93 const int depth = get<1>(params), cn = get<2>(params), type = CV_MAKE_TYPE(depth, cn); 94 95 ASSERT_TRUE(cn == 3 || cn == 2); 96 97 checkDeviceMaxMemoryAllocSize(srcSize, type); 98 99 UMat src(srcSize, type); 100 std::vector<UMat> dst(cn, UMat(srcSize, CV_MAKE_TYPE(depth, 1))); 101 102 declare.in(src, WARMUP_RNG); 103 for (int i = 0; i < cn; ++i) 104 declare.in(dst[i]); 105 106 OCL_TEST_CYCLE() cv::split(src, dst); 107 108 ASSERT_EQ(cn, (int)dst.size()); 109 110 if (cn == 2) 111 { 112 UMat & dst0 = dst[0], & dst1 = dst[1]; 113 SANITY_CHECK(dst0); 114 SANITY_CHECK(dst1); 115 } 116 else 117 { 118 UMat & dst0 = dst[0], & dst1 = dst[1], & dst2 = dst[2]; 119 SANITY_CHECK(dst0); 120 SANITY_CHECK(dst1); 121 SANITY_CHECK(dst2); 122 } 123 } 124 125 ///////////// MixChannels //////////////////////// 126 127 typedef tuple<Size, MatDepth> MixChannelsParams; 128 typedef TestBaseWithParam<MixChannelsParams> MixChannelsFixture; 129 130 OCL_PERF_TEST_P(MixChannelsFixture, MixChannels, 131 ::testing::Combine(Values(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3), 132 OCL_PERF_ENUM(CV_8U, CV_32F))) 133 { 134 const MixChannelsParams params = GetParam(); 135 const Size srcSize = get<0>(params); 136 const int depth = get<1>(params), type = CV_MAKE_TYPE(depth, 2), n = 2; 137 138 checkDeviceMaxMemoryAllocSize(srcSize, type); 139 140 std::vector<UMat> src(n), dst(n); 141 for (int i = 0; i < n; ++i) 142 { 143 src[i] = UMat(srcSize, type); 144 dst[i] = UMat(srcSize, type); 145 declare.in(src[i], WARMUP_RNG).out(dst[i]); 146 } 147 148 int fromTo[] = { 1,2, 2,0, 0,3, 3,1 }; 149 150 OCL_TEST_CYCLE() cv::mixChannels(src, dst, fromTo, 4); 151 152 UMat & dst0 = dst[0], & dst1 = dst[1]; 153 SANITY_CHECK(dst0); 154 SANITY_CHECK(dst1); 155 } 156 157 ///////////// InsertChannel //////////////////////// 158 159 typedef Size_MatDepth InsertChannelFixture; 160 161 OCL_PERF_TEST_P(InsertChannelFixture, InsertChannel, 162 ::testing::Combine(Values(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3), 163 OCL_PERF_ENUM(CV_8U, CV_32F))) 164 { 165 const Size_MatDepth_t params = GetParam(); 166 const Size srcSize = get<0>(params); 167 const int depth = get<1>(params), type = CV_MAKE_TYPE(depth, 3); 168 169 checkDeviceMaxMemoryAllocSize(srcSize, type); 170 171 UMat src(srcSize, depth), dst(srcSize, type, Scalar::all(17)); 172 declare.in(src, WARMUP_RNG).out(dst); 173 174 OCL_TEST_CYCLE() cv::insertChannel(src, dst, 1); 175 176 SANITY_CHECK(dst); 177 } 178 179 ///////////// ExtractChannel //////////////////////// 180 181 typedef Size_MatDepth ExtractChannelFixture; 182 183 OCL_PERF_TEST_P(ExtractChannelFixture, ExtractChannel, 184 ::testing::Combine(Values(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3), 185 OCL_PERF_ENUM(CV_8U, CV_32F))) 186 { 187 const Size_MatDepth_t params = GetParam(); 188 const Size srcSize = get<0>(params); 189 const int depth = get<1>(params), type = CV_MAKE_TYPE(depth, 3); 190 191 checkDeviceMaxMemoryAllocSize(srcSize, type); 192 193 UMat src(srcSize, type), dst(srcSize, depth); 194 declare.in(src, WARMUP_RNG).out(dst); 195 196 OCL_TEST_CYCLE() cv::extractChannel(src, dst, 1); 197 198 SANITY_CHECK(dst); 199 } 200 201 } } // namespace cvtest::ocl 202 203 #endif // HAVE_OPENCL 204