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