Merge remote-tracking branch 'origin/2.4' into merge-2.4
[profile/ivi/opencv.git] / modules / ocl / perf / perf_precomp.hpp
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 // 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 #ifdef __GNUC__
44 #  pragma GCC diagnostic ignored "-Wmissing-declarations"
45 #  if defined __clang__ || defined __APPLE__
46 #    pragma GCC diagnostic ignored "-Wmissing-prototypes"
47 #    pragma GCC diagnostic ignored "-Wextra"
48 #  endif
49 #endif
50
51 #ifndef __OPENCV_PERF_PRECOMP_HPP__
52 #define __OPENCV_PERF_PRECOMP_HPP__
53
54 #ifdef __GNUC__
55 #  pragma GCC diagnostic ignored "-Wmissing-declarations"
56 #  if defined __clang__ || defined __APPLE__
57 #    pragma GCC diagnostic ignored "-Wmissing-prototypes"
58 #    pragma GCC diagnostic ignored "-Wextra"
59 #  endif
60 #endif
61
62 #include <iomanip>
63 #include <stdexcept>
64 #include <string>
65 #include <iostream>
66 #include <cstdio>
67 #include <vector>
68 #include <numeric>
69
70 #include "cvconfig.h"
71 #include "opencv2/core.hpp"
72 #include "opencv2/core/utility.hpp"
73 #include "opencv2/imgproc.hpp"
74 #include "opencv2/highgui.hpp"
75 #include "opencv2/calib3d.hpp"
76 #include "opencv2/video.hpp"
77 #include "opencv2/objdetect.hpp"
78 #include "opencv2/features2d.hpp"
79 #include "opencv2/ocl.hpp"
80 #include "opencv2/ts.hpp"
81
82 using namespace std;
83 using namespace cv;
84
85 #define OCL_SIZE_1000 Size(1000, 1000)
86 #define OCL_SIZE_2000 Size(2000, 2000)
87 #define OCL_SIZE_4000 Size(4000, 4000)
88
89 #define OCL_TYPICAL_MAT_SIZES ::testing::Values(OCL_SIZE_1000, OCL_SIZE_2000, OCL_SIZE_4000)
90
91 #define OCL_PERF_ENUM(type, ...) ::testing::Values(type, ## __VA_ARGS__ )
92
93 #define IMPL_OCL "ocl"
94 #define IMPL_GPU "gpu"
95 #define IMPL_PLAIN "plain"
96
97 #define RUN_OCL_IMPL (IMPL_OCL == getSelectedImpl())
98 #define RUN_PLAIN_IMPL (IMPL_PLAIN == getSelectedImpl())
99
100 #ifdef HAVE_OPENCV_GPU
101 # define RUN_GPU_IMPL (IMPL_GPU == getSelectedImpl())
102 #endif
103
104 #ifdef HAVE_OPENCV_GPU
105 #define OCL_PERF_ELSE               \
106         if (RUN_GPU_IMPL)           \
107             CV_TEST_FAIL_NO_IMPL(); \
108         else                        \
109             CV_TEST_FAIL_NO_IMPL();
110 #else
111 #define OCL_PERF_ELSE               \
112             CV_TEST_FAIL_NO_IMPL();
113 #endif
114
115 #define OCL_TEST_CYCLE_N(n) for(declare.iterations(n); startTimer(), next(); cv::ocl::finish(), stopTimer())
116 #define OCL_TEST_CYCLE() for(; startTimer(), next(); cv::ocl::finish(), stopTimer())
117 #define OCL_TEST_CYCLE_MULTIRUN(runsNum) for(declare.runs(runsNum); startTimer(), next(); stopTimer()) for(int r = 0; r < runsNum; cv::ocl::finish(), ++r)
118
119 namespace cvtest {
120 namespace ocl {
121 inline void checkDeviceMaxMemoryAllocSize(const Size& size, int type, int factor = 1)
122 {
123     assert(factor > 0);
124     if (!(IMPL_OCL == perf::TestBase::getSelectedImpl()))
125         return; // OpenCL devices are not used
126     int cn = CV_MAT_CN(type);
127     int cn_ocl = cn == 3 ? 4 : cn;
128     int type_ocl = CV_MAKE_TYPE(CV_MAT_DEPTH(type), cn_ocl);
129     size_t memSize = size.area() * CV_ELEM_SIZE(type_ocl);
130     const cv::ocl::DeviceInfo& devInfo = cv::ocl::Context::getContext()->getDeviceInfo();
131     if (memSize * factor >= devInfo.maxMemAllocSize)
132     {
133         throw perf::TestBase::PerfSkipTestException();
134     }
135 }
136 } // namespace cvtest::ocl
137 } // namespace cvtest
138
139 using namespace cvtest::ocl;
140
141 #endif