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) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
16 //
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
19 //
20 // * Redistribution's of source code must retain the above copyright notice,
21 // this list of conditions and the following disclaimer.
22 //
23 // * Redistribution's in binary form must reproduce the above copyright notice,
24 // this list of conditions and the following disclaimer in the documentation
25 // and/or other materials provided with the distribution.
26 //
27 // * The name of the copyright holders may not be used to endorse or promote products
28 // derived from this software without specific prior written permission.
29 //
30 // This software is provided by the copyright holders and contributors "as is" and
31 // any express or implied warranties, including, but not limited to, the implied
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
34 // indirect, incidental, special, exemplary, or consequential damages
35 // (including, but not limited to, procurement of substitute goods or services;
36 // loss of use, data, or profits; or business interruption) however caused
37 // and on any theory of liability, whether in contract, strict liability,
38 // or tort (including negligence or otherwise) arising in any way out of
39 // the use of this software, even if advised of the possibility of such damage.
40 //
41 //M*/
42
43 #include "perf_precomp.hpp"
44
45 using namespace std;
46 using namespace testing;
47 using namespace perf;
48
49 //////////////////////////////////////////////////////////////////////
50 // GEMM
51
52 #ifdef HAVE_CUBLAS
53
54 CV_FLAGS(GemmFlags, 0, cv::GEMM_1_T, cv::GEMM_2_T, cv::GEMM_3_T)
55 #define ALL_GEMM_FLAGS Values(GemmFlags(0), GemmFlags(cv::GEMM_1_T), GemmFlags(cv::GEMM_2_T), GemmFlags(cv::GEMM_3_T), \
56 GemmFlags(cv::GEMM_1_T | cv::GEMM_2_T), GemmFlags(cv::GEMM_1_T | cv::GEMM_3_T), GemmFlags(cv::GEMM_1_T | cv::GEMM_2_T | cv::GEMM_3_T))
57
58 DEF_PARAM_TEST(Sz_Type_Flags, cv::Size, MatType, GemmFlags);
59
60 PERF_TEST_P(Sz_Type_Flags, GEMM,
61 Combine(Values(cv::Size(512, 512), cv::Size(1024, 1024)),
62 Values(CV_32FC1, CV_32FC2, CV_64FC1),
63 ALL_GEMM_FLAGS))
64 {
65 const cv::Size size = GET_PARAM(0);
66 const int type = GET_PARAM(1);
67 const int flags = GET_PARAM(2);
68
69 cv::Mat src1(size, type);
70 declare.in(src1, WARMUP_RNG);
71
72 cv::Mat src2(size, type);
73 declare.in(src2, WARMUP_RNG);
74
75 cv::Mat src3(size, type);
76 declare.in(src3, WARMUP_RNG);
77
78 if (PERF_RUN_CUDA())
79 {
80 declare.time(5.0);
81
82 const cv::cuda::GpuMat d_src1(src1);
83 const cv::cuda::GpuMat d_src2(src2);
84 const cv::cuda::GpuMat d_src3(src3);
85 cv::cuda::GpuMat dst;
86
87 TEST_CYCLE() cv::cuda::gemm(d_src1, d_src2, 1.0, d_src3, 1.0, dst, flags);
88
89 CUDA_SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
90 }
91 else
92 {
93 declare.time(50.0);
94
95 cv::Mat dst;
96
97 TEST_CYCLE() cv::gemm(src1, src2, 1.0, src3, 1.0, dst, flags);
98
99 CPU_SANITY_CHECK(dst);
100 }
101 }
102
103 #endif
104
105 //////////////////////////////////////////////////////////////////////
106 // MulSpectrums
107
108 CV_FLAGS(DftFlags, 0, cv::DFT_INVERSE, cv::DFT_SCALE, cv::DFT_ROWS, cv::DFT_COMPLEX_OUTPUT, cv::DFT_REAL_OUTPUT)
109
110 DEF_PARAM_TEST(Sz_Flags, cv::Size, DftFlags);
111
112 PERF_TEST_P(Sz_Flags, MulSpectrums,
113 Combine(CUDA_TYPICAL_MAT_SIZES,
114 Values(0, DftFlags(cv::DFT_ROWS))))
115 {
116 const cv::Size size = GET_PARAM(0);
117 const int flag = GET_PARAM(1);
118
119 cv::Mat a(size, CV_32FC2);
120 cv::Mat b(size, CV_32FC2);
121 declare.in(a, b, WARMUP_RNG);
122
123 if (PERF_RUN_CUDA())
124 {
125 const cv::cuda::GpuMat d_a(a);
126 const cv::cuda::GpuMat d_b(b);
127 cv::cuda::GpuMat dst;
128
129 TEST_CYCLE() cv::cuda::mulSpectrums(d_a, d_b, dst, flag);
130
131 CUDA_SANITY_CHECK(dst);
132 }
133 else
134 {
135 cv::Mat dst;
136
137 TEST_CYCLE() cv::mulSpectrums(a, b, dst, flag);
138
139 CPU_SANITY_CHECK(dst);
140 }
141 }
142
143 //////////////////////////////////////////////////////////////////////
144 // MulAndScaleSpectrums
145
PERF_TEST_P(Sz,MulAndScaleSpectrums,CUDA_TYPICAL_MAT_SIZES)146 PERF_TEST_P(Sz, MulAndScaleSpectrums,
147 CUDA_TYPICAL_MAT_SIZES)
148 {
149 const cv::Size size = GetParam();
150
151 const float scale = 1.f / size.area();
152
153 cv::Mat src1(size, CV_32FC2);
154 cv::Mat src2(size, CV_32FC2);
155 declare.in(src1,src2, WARMUP_RNG);
156
157 if (PERF_RUN_CUDA())
158 {
159 const cv::cuda::GpuMat d_src1(src1);
160 const cv::cuda::GpuMat d_src2(src2);
161 cv::cuda::GpuMat dst;
162
163 TEST_CYCLE() cv::cuda::mulAndScaleSpectrums(d_src1, d_src2, dst, cv::DFT_ROWS, scale, false);
164
165 CUDA_SANITY_CHECK(dst);
166 }
167 else
168 {
169 FAIL_NO_CPU();
170 }
171 }
172
173 //////////////////////////////////////////////////////////////////////
174 // Dft
175
176 PERF_TEST_P(Sz_Flags, Dft,
177 Combine(CUDA_TYPICAL_MAT_SIZES,
178 Values(0, DftFlags(cv::DFT_ROWS), DftFlags(cv::DFT_INVERSE))))
179 {
180 declare.time(10.0);
181
182 const cv::Size size = GET_PARAM(0);
183 const int flag = GET_PARAM(1);
184
185 cv::Mat src(size, CV_32FC2);
186 declare.in(src, WARMUP_RNG);
187
188 if (PERF_RUN_CUDA())
189 {
190 const cv::cuda::GpuMat d_src(src);
191 cv::cuda::GpuMat dst;
192
193 TEST_CYCLE() cv::cuda::dft(d_src, dst, size, flag);
194
195 CUDA_SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
196 }
197 else
198 {
199 cv::Mat dst;
200
201 TEST_CYCLE() cv::dft(src, dst, flag);
202
203 CPU_SANITY_CHECK(dst);
204 }
205 }
206
207 //////////////////////////////////////////////////////////////////////
208 // Convolve
209
210 DEF_PARAM_TEST(Sz_KernelSz_Ccorr, cv::Size, int, bool);
211
212 PERF_TEST_P(Sz_KernelSz_Ccorr, Convolve,
213 Combine(CUDA_TYPICAL_MAT_SIZES,
214 Values(17, 27, 32, 64),
215 Bool()))
216 {
217 declare.time(10.0);
218
219 const cv::Size size = GET_PARAM(0);
220 const int templ_size = GET_PARAM(1);
221 const bool ccorr = GET_PARAM(2);
222
223 const cv::Mat image(size, CV_32FC1);
224 const cv::Mat templ(templ_size, templ_size, CV_32FC1);
225 declare.in(image, templ, WARMUP_RNG);
226
227 if (PERF_RUN_CUDA())
228 {
229 cv::cuda::GpuMat d_image = cv::cuda::createContinuous(size, CV_32FC1);
230 d_image.upload(image);
231
232 cv::cuda::GpuMat d_templ = cv::cuda::createContinuous(templ_size, templ_size, CV_32FC1);
233 d_templ.upload(templ);
234
235 cv::Ptr<cv::cuda::Convolution> convolution = cv::cuda::createConvolution();
236
237 cv::cuda::GpuMat dst;
238
239 TEST_CYCLE() convolution->convolve(d_image, d_templ, dst, ccorr);
240
241 CUDA_SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
242 }
243 else
244 {
245 if (ccorr)
246 FAIL_NO_CPU();
247
248 cv::Mat dst;
249
250 TEST_CYCLE() cv::filter2D(image, dst, image.depth(), templ);
251
252 CPU_SANITY_CHECK(dst);
253 }
254 }
255