main.cpp 5.5 KB
Newer Older
N
niko 已提交
1 2 3 4 5 6 7 8 9
/*M///////////////////////////////////////////////////////////////////////////////////////
//
//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
//  By downloading, copying, installing or using the software you agree to this license.
//  If you do not agree to this license, do not download, install,
//  copy or use the software.
//
//
Y
yao 已提交
10
//                           License Agreement
N
niko 已提交
11 12
//                For Open Source Computer Vision Library
//
Y
yao 已提交
13 14
// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
N
niko 已提交
15
// Third party copyrights are property of their respective owners.
Y
yao 已提交
16

N
niko 已提交
17 18 19 20 21 22 23 24
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
//   * Redistribution's of source code must retain the above copyright notice,
//     this list of conditions and the following disclaimer.
//
//   * Redistribution's in binary form must reproduce the above copyright notice,
//     this list of conditions and the following disclaimer in the documentation
Y
yao 已提交
25
//     and/or other oclMaterials provided with the distribution.
N
niko 已提交
26
//
Y
yao 已提交
27
//   * The name of the copyright holders may not be used to endorse or promote products
N
niko 已提交
28 29
//     derived from this software without specific prior written permission.
//
Y
yao 已提交
30
// This software is provided by the copyright holders and contributors as is and
N
niko 已提交
31 32 33 34 35 36 37 38 39 40 41 42
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/

43
#include "perf_precomp.hpp"
N
niko 已提交
44

Y
yao 已提交
45
int main(int argc, const char *argv[])
N
niko 已提交
46
{
Y
yao 已提交
47 48 49 50 51 52
    const char *keys =
        "{ h | help    | false | print help message }"
        "{ f | filter  |       | filter for test }"
        "{ w | workdir |       | set working directory }"
        "{ l | list    | false | show all tests }"
        "{ d | device  | 0     | device id }"
Y
yao 已提交
53
        "{ c | cpu_ocl | false | use cpu as ocl device}"
Y
yao 已提交
54 55
        "{ i | iters   | 10    | iteration count }"
        "{ m | warmup  | 1     | gpu warm up iteration count}"
Y
yao 已提交
56 57
        "{ t | xtop    | 1.1   | xfactor top boundary}"
        "{ b | xbottom | 0.9   | xfactor bottom boundary}"
Y
yao 已提交
58
        "{ v | verify  | false | only run gpu once to verify if problems occur}";
N
Niko 已提交
59

Y
yao 已提交
60
    redirectError(cvErrorCallback);
N
Niko 已提交
61 62 63
    CommandLineParser cmd(argc, argv, keys);
    if (cmd.get<bool>("help"))
    {
Y
yao 已提交
64
        cout << "Avaible options:" << endl;
N
Niko 已提交
65
        cmd.printParams();
Y
yao 已提交
66
        return 0;
N
Niko 已提交
67 68
    }

Y
yao 已提交
69 70 71 72 73 74 75 76 77 78 79 80 81
    // get ocl devices
    bool use_cpu = cmd.get<bool>("c");
    vector<ocl::Info> oclinfo;
    int num_devices = 0;
    if(use_cpu)
        num_devices = getDevice(oclinfo, ocl::CVCL_DEVICE_TYPE_CPU);
    else
        num_devices = getDevice(oclinfo);
    if (num_devices < 1)
    {
        cerr << "no device found\n";
        return -1;
    }
N
Niko 已提交
82

Y
yao 已提交
83 84 85 86 87 88 89 90 91 92 93
    // show device info
    int devidx = 0;
    for (size_t i = 0; i < oclinfo.size(); i++)
    {
        for (size_t j = 0; j < oclinfo[i].DeviceName.size(); j++)
        {
            cout << "device " << devidx++ << ": " << oclinfo[i].DeviceName[j] << endl;
        }
    }

    int device = cmd.get<int>("device");
Y
yao 已提交
94
    if (device < 0 || device >= num_devices)
95
    {
Y
yao 已提交
96
        cerr << "Invalid device ID" << endl;
97
        return -1;
Y
yao 已提交
98
    }
N
Niko 已提交
99

Y
yao 已提交
100 101
    // set this to overwrite binary cache every time the test starts
    ocl::setBinaryDiskCache(ocl::CACHE_UPDATE);
102

Y
yao 已提交
103 104 105 106 107
    if (cmd.get<bool>("verify"))
    {
        TestSystem::instance().setNumIters(1);
        TestSystem::instance().setGPUWarmupIters(0);
        TestSystem::instance().setCPUIters(0);
108
    }
N
Niko 已提交
109

Y
yao 已提交
110 111
    devidx = 0;
    for (size_t i = 0; i < oclinfo.size(); i++)
N
Niko 已提交
112
    {
Y
yao 已提交
113 114 115 116 117 118
        for (size_t j = 0; j < oclinfo[i].DeviceName.size(); j++, devidx++)
        {
            if (device == devidx)
            {
                ocl::setDevice(oclinfo[i], (int)j);
                TestSystem::instance().setRecordName(oclinfo[i].DeviceName[j]);
Y
yao 已提交
119
                cout << "use " << devidx << ": " <<oclinfo[i].DeviceName[j] << endl;
Y
yao 已提交
120 121 122 123
                goto END_DEV;
            }
        }
    }
N
Niko 已提交
124

Y
yao 已提交
125
END_DEV:
N
Niko 已提交
126

Y
yao 已提交
127 128 129 130 131 132 133
    string filter = cmd.get<string>("filter");
    string workdir = cmd.get<string>("workdir");
    bool list = cmd.get<bool>("list");
    int iters = cmd.get<int>("iters");
    int wu_iters = cmd.get<int>("warmup");
    double x_top = cmd.get<double>("xtop");
    double x_bottom = cmd.get<double>("xbottom");
N
Niko 已提交
134

Y
yao 已提交
135 136
    TestSystem::instance().setTopThreshold(x_top);
    TestSystem::instance().setBottomThreshold(x_bottom);
N
Niko 已提交
137

Y
yao 已提交
138 139 140 141
    if (!filter.empty())
    {
        TestSystem::instance().setTestFilter(filter);
    }
N
Niko 已提交
142

Y
yao 已提交
143
    if (!workdir.empty())
N
Niko 已提交
144
    {
Y
yao 已提交
145 146 147 148
        if (workdir[workdir.size() - 1] != '/' && workdir[workdir.size() - 1] != '\\')
        {
            workdir += '/';
        }
N
Niko 已提交
149

Y
yao 已提交
150 151
        TestSystem::instance().setWorkingDir(workdir);
    }
N
Niko 已提交
152

Y
yao 已提交
153 154 155
    if (list)
    {
        TestSystem::instance().setListMode(true);
N
Niko 已提交
156 157
    }

Y
yao 已提交
158 159
    TestSystem::instance().setNumIters(iters);
    TestSystem::instance().setGPUWarmupIters(wu_iters);
N
niko 已提交
160

Y
yao 已提交
161
    TestSystem::instance().run();
N
niko 已提交
162 163

    return 0;
R
Roman Donchenko 已提交
164
}