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@multicorewareinc.com
19 // Jin Ma, jin@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 opencv_test {
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
OCL_PERF_TEST_P(MixChannelsFixture,MixChannels,::testing::Combine (Values (OCL_SIZE_1,OCL_SIZE_2,OCL_SIZE_3),OCL_PERF_ENUM (CV_8U,CV_32F)))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 tuple<cv::Size, MatDepth> Size_MatDepth_t;
160 typedef TestBaseWithParam<Size_MatDepth_t> Size_MatDepth;
161
162 typedef Size_MatDepth InsertChannelFixture;
163
OCL_PERF_TEST_P(InsertChannelFixture,InsertChannel,::testing::Combine (Values (OCL_SIZE_1,OCL_SIZE_2,OCL_SIZE_3),OCL_PERF_ENUM (CV_8U,CV_32F)))164 OCL_PERF_TEST_P(InsertChannelFixture, InsertChannel,
165 ::testing::Combine(Values(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),
166 OCL_PERF_ENUM(CV_8U, CV_32F)))
167 {
168 const Size_MatDepth_t params = GetParam();
169 const Size srcSize = get<0>(params);
170 const int depth = get<1>(params), type = CV_MAKE_TYPE(depth, 3);
171
172 checkDeviceMaxMemoryAllocSize(srcSize, type);
173
174 UMat src(srcSize, depth), dst(srcSize, type, Scalar::all(17));
175 declare.in(src, WARMUP_RNG).out(dst);
176
177 OCL_TEST_CYCLE() cv::insertChannel(src, dst, 1);
178
179 SANITY_CHECK(dst);
180 }
181
182 ///////////// ExtractChannel ////////////////////////
183
184 typedef Size_MatDepth ExtractChannelFixture;
185
OCL_PERF_TEST_P(ExtractChannelFixture,ExtractChannel,::testing::Combine (Values (OCL_SIZE_1,OCL_SIZE_2,OCL_SIZE_3),OCL_PERF_ENUM (CV_8U,CV_32F)))186 OCL_PERF_TEST_P(ExtractChannelFixture, ExtractChannel,
187 ::testing::Combine(Values(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),
188 OCL_PERF_ENUM(CV_8U, CV_32F)))
189 {
190 const Size_MatDepth_t params = GetParam();
191 const Size srcSize = get<0>(params);
192 const int depth = get<1>(params), type = CV_MAKE_TYPE(depth, 3);
193
194 checkDeviceMaxMemoryAllocSize(srcSize, type);
195
196 UMat src(srcSize, type), dst(srcSize, depth);
197 declare.in(src, WARMUP_RNG).out(dst);
198
199 OCL_TEST_CYCLE() cv::extractChannel(src, dst, 1);
200
201 SANITY_CHECK(dst);
202 }
203
204 } } // namespace opencv_test::ocl
205
206 #endif // HAVE_OPENCL
207