CLAHE Python bindings
[profile/ivi/opencv.git] / modules / ocl / perf / main.cpp
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 oclMaterials 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 "precomp.hpp"
44
45 int main(int argc, const char *argv[])
46 {
47     vector<ocl::Info> oclinfo;
48     int num_devices = getDevice(oclinfo);
49
50     if (num_devices < 1)
51     {
52         cerr << "no device found\n";
53         return -1;
54     }
55
56     int devidx = 0;
57
58     for (size_t i = 0; i < oclinfo.size(); i++)
59     {
60         for (size_t j = 0; j < oclinfo[i].DeviceName.size(); j++)
61         {
62             printf("device %d: %s\n", devidx++, oclinfo[i].DeviceName[j].c_str());
63         }
64     }
65
66     redirectError(cvErrorCallback);
67
68     const char *keys =
69         "{ h | help    | false | print help message }"
70         "{ f | filter  |       | filter for test }"
71         "{ w | workdir |       | set working directory }"
72         "{ l | list    | false | show all tests }"
73         "{ d | device  | 0     | device id }"
74         "{ i | iters   | 10    | iteration count }"
75         "{ m | warmup  | 1     | gpu warm up iteration count}"
76         "{ t | xtop    | 1.1      | xfactor top boundary}"
77         "{ b | xbottom | 0.9      | xfactor bottom boundary}"
78         "{ v | verify  | false | only run gpu once to verify if problems occur}";
79
80     CommandLineParser cmd(argc, argv, keys);
81
82     if (cmd.get<bool>("help"))
83     {
84         cout << "Avaible options:" << endl;
85         cmd.printParams();
86         return 0;
87     }
88
89     int device = cmd.get<int>("device");
90
91     if (device < 0 || device >= num_devices)
92     {
93         cerr << "Invalid device ID" << endl;
94         return -1;
95     }
96
97     if (cmd.get<bool>("verify"))
98     {
99         TestSystem::instance().setNumIters(1);
100         TestSystem::instance().setGPUWarmupIters(0);
101         TestSystem::instance().setCPUIters(0);
102     }
103
104     devidx = 0;
105
106     for (size_t i = 0; i < oclinfo.size(); i++)
107     {
108         for (size_t j = 0; j < oclinfo[i].DeviceName.size(); j++, devidx++)
109         {
110             if (device == devidx)
111             {
112                 ocl::setDevice(oclinfo[i], (int)j);
113                 TestSystem::instance().setRecordName(oclinfo[i].DeviceName[j]);
114                 printf("\nuse %d: %s\n", devidx, oclinfo[i].DeviceName[j].c_str());
115                 goto END_DEV;
116             }
117         }
118     }
119
120 END_DEV:
121
122     string filter = cmd.get<string>("filter");
123     string workdir = cmd.get<string>("workdir");
124     bool list = cmd.get<bool>("list");
125     int iters = cmd.get<int>("iters");
126     int wu_iters = cmd.get<int>("warmup");
127     double x_top = cmd.get<double>("xtop");
128     double x_bottom = cmd.get<double>("xbottom");
129
130     TestSystem::instance().setTopThreshold(x_top);
131     TestSystem::instance().setBottomThreshold(x_bottom);
132
133     if (!filter.empty())
134     {
135         TestSystem::instance().setTestFilter(filter);
136     }
137
138     if (!workdir.empty())
139     {
140         if (workdir[workdir.size() - 1] != '/' && workdir[workdir.size() - 1] != '\\')
141         {
142             workdir += '/';
143         }
144
145         TestSystem::instance().setWorkingDir(workdir);
146     }
147
148     if (list)
149     {
150         TestSystem::instance().setListMode(true);
151     }
152
153     TestSystem::instance().setNumIters(iters);
154     TestSystem::instance().setGPUWarmupIters(wu_iters);
155
156     TestSystem::instance().run();
157
158     return 0;
159 }