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-2013, Advanced Micro Devices, Inc., all rights reserved.
14 // Third party copyrights are property of their respective owners.
15 //
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
18 //
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
21 //
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
25 //
26 // * The name of the copyright holders may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
28 //
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the OpenCV Foundation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
39 //
40 //M*/
41
42 #ifndef __OPENCV_TS_OCL_PERF_HPP__
43 #define __OPENCV_TS_OCL_PERF_HPP__
44
45 #include "ocl_test.hpp"
46 #include "ts_perf.hpp"
47
48 namespace cvtest {
49 namespace ocl {
50
51 using namespace perf;
52
53 using std::tr1::get;
54 using std::tr1::tuple;
55
56 #define OCL_PERF_STRATEGY PERF_STRATEGY_SIMPLE
57
58 #define OCL_PERF_TEST(fixture, name) SIMPLE_PERF_TEST(fixture, name)
59 #define OCL_PERF_TEST_P(fixture, name, params) SIMPLE_PERF_TEST_P(fixture, name, params)
60
61 #define SIMPLE_PERF_TEST(fixture, name) \
62 class OCL##_##fixture##_##name : \
63 public ::perf::TestBase \
64 { \
65 public: \
66 OCL##_##fixture##_##name() { } \
67 protected: \
68 virtual void PerfTestBody(); \
69 }; \
70 TEST_F(OCL##_##fixture##_##name, name) { declare.strategy(OCL_PERF_STRATEGY); RunPerfTestBody(); } \
71 void OCL##_##fixture##_##name::PerfTestBody()
72
73 #define SIMPLE_PERF_TEST_P(fixture, name, params) \
74 class OCL##_##fixture##_##name : \
75 public fixture \
76 { \
77 public: \
78 OCL##_##fixture##_##name() { } \
79 protected: \
80 virtual void PerfTestBody(); \
81 }; \
82 TEST_P(OCL##_##fixture##_##name, name) { declare.strategy(OCL_PERF_STRATEGY); RunPerfTestBody(); } \
83 INSTANTIATE_TEST_CASE_P(/*none*/, OCL##_##fixture##_##name, params); \
84 void OCL##_##fixture##_##name::PerfTestBody()
85
86 #define OCL_SIZE_1 szVGA
87 #define OCL_SIZE_2 sz720p
88 #define OCL_SIZE_3 sz1080p
89 #define OCL_SIZE_4 sz2160p
90
91 #define OCL_TEST_SIZES ::testing::Values(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3, OCL_SIZE_4)
92 #define OCL_TEST_TYPES ::testing::Values(CV_8UC1, CV_32FC1, CV_8UC4, CV_32FC4)
93 #define OCL_TEST_TYPES_14 OCL_TEST_TYPES
94 #define OCL_TEST_TYPES_134 ::testing::Values(CV_8UC1, CV_32FC1, CV_8UC3, CV_32FC3, CV_8UC4, CV_32FC4)
95
96 #define OCL_PERF_ENUM ::testing::Values
97
98 // TODO Replace finish call to dstUMat.wait()
99 #define OCL_TEST_CYCLE() \
100 for (cvtest::ocl::perf::safeFinish(); startTimer(), next(); cvtest::ocl::perf::safeFinish(), stopTimer())
101
102 #define OCL_TEST_CYCLE_N(n) \
103 for(declare.iterations(n), cvtest::ocl::perf::safeFinish(); startTimer(), next(); cvtest::ocl::perf::safeFinish(), stopTimer())
104
105 #define OCL_TEST_CYCLE_MULTIRUN(runsNum) \
106 for (declare.runs(runsNum), cvtest::ocl::perf::safeFinish(); startTimer(), next(); cvtest::ocl::perf::safeFinish(), stopTimer()) \
107 for (int r = 0; r < runsNum; cvtest::ocl::perf::safeFinish(), ++r)
108
109
110 namespace perf {
111
112 // Check for current device limitation
113 CV_EXPORTS void checkDeviceMaxMemoryAllocSize(const Size& size, int type, int factor = 1);
114
115 // Initialize Mat with random numbers. Range is depends on the data type.
116 // TODO Parameter type is actually OutputArray
117 CV_EXPORTS void randu(InputOutputArray dst);
118
safeFinish()119 inline void safeFinish()
120 {
121 if (cv::ocl::useOpenCL())
122 cv::ocl::finish();
123 }
124
125 } // namespace perf
126 using namespace perf;
127
128 } // namespace cvtest::ocl
129 } // namespace cvtest
130
131 #endif // __OPENCV_TS_OCL_PERF_HPP__
132