Publishing R3
[platform/upstream/dldt.git] / inference-engine / thirdparty / mkl-dnn / tests / benchdnn / conv / bench_conv.cpp
1 /*******************************************************************************
2 * Copyright 2017-2018 Intel Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *******************************************************************************/
16
17 #include <stdlib.h>
18 #include <string.h>
19 #include <stdio.h>
20 #include <float.h>
21 #include <math.h>
22
23 #include "mkldnn.h"
24
25 #include "mkldnn_common.hpp"
26 #include "mkldnn_memory.hpp"
27
28 #include "conv/conv.hpp"
29
30 namespace conv {
31
32 /* global driver parameters */
33 const dt_conf_t *cfg = conf_f32;
34 const char *pattern = NULL;
35 dir_t dir = FWD_B;
36 int mb = 0;
37 alg_t alg = DIRECT;
38 merge_t merge = NONE;
39 attr_t attr;
40 const char *skip_impl = "";
41 bool allow_unimpl = false;
42 const char *perf_template = "perf,%n,%d,%GO,%GF,%-t,%-Gp,%0t,%0Gp";
43
44 void reset_parameters() {
45     cfg = conf_f32;
46     pattern = NULL;
47     dir = FWD_B;
48     mb = 0;
49     alg = DIRECT;
50     merge = NONE;
51     attr = attr_t();
52     skip_impl = "";
53     allow_unimpl = false;
54 }
55
56 void check_correctness(const desc_t *c) {
57     const prb_t p(*c, dir, cfg, alg, merge, attr, mb);
58     char pstr[max_prb_len];
59     prb2str(&p, pstr);
60
61     if (pattern && !match_regex(pstr, pattern))
62         return;
63     print(1, "run: %s\n", pstr);
64
65     res_t res{};
66     const int status = conv::doit(&p, &res);
67     (void)status;
68
69     bool want_perf_report = false;
70
71     parse_result(res, want_perf_report, allow_unimpl, status, pstr);
72
73     if (want_perf_report && bench_mode & PERF)
74         perf_report(&p, &res, pstr);
75
76     benchdnn_stat.tests++;
77 }
78
79 int bench(int argc, char **argv, bool main_bench) {
80     for (int arg = 0; arg < argc; ++arg) {
81         if (!strncmp("--batch=", argv[arg], 8))
82             SAFE(batch(argv[arg] + 8, bench), CRIT);
83         else if (!strncmp("--cfg=", argv[arg], 6))
84             cfg = str2cfg(argv[arg] + 6);
85         else if (!strncmp("--match=", argv[arg], 8))
86             pattern = argv[arg] + 8;
87         else if (!strncmp("--mb=", argv[arg], 5))
88             mb = atoi(argv[arg] + 5);
89         else if (!strncmp("--dir=", argv[arg], 6))
90             dir = str2dir(argv[arg] + 6);
91         else if (!strncmp("--alg=", argv[arg], 6))
92             alg = str2alg(argv[arg] + 6);
93         else if (!strncmp("--merge=", argv[arg], 8))
94             merge = str2merge(argv[arg] + 8);
95         else if (!strncmp("--attr=", argv[arg], 7))
96             SAFE(str2attr(&attr, argv[arg] + 7), CRIT);
97         else if (!strncmp("--skip-impl=", argv[arg], 12))
98             skip_impl = argv[arg] + 12;
99         else if (!strncmp("--allow-unimpl=", argv[arg], 15))
100             allow_unimpl = str2bool(argv[arg] + 15);
101         else if (!strncmp("--perf-template=", argv[arg], 16))
102             perf_template = argv[arg] + 16;
103         else if (!strcmp("--reset", argv[arg]))
104             reset_parameters();
105         else if (!strncmp("--mode=", argv[0], 7))
106             bench_mode = str2bench_mode(argv[0] + 7);
107         else if (!strncmp("-v", argv[arg], 2))
108             verbose = atoi(argv[arg] + 2);
109         else if (!strncmp("--verbose=", argv[arg], 10))
110             verbose = atoi(argv[arg] + 10);
111         else {
112             desc_t c;
113             bool is_deconv = 0;
114             if (str2desc(&c, argv[arg], is_deconv) == FAIL) {
115                 fprintf(stderr, "driver: unknown option: `%s`, exiting...\n",
116                         argv[arg]);
117                 exit(2);
118             }
119             check_correctness(&c);
120         }
121     }
122
123     return OK;
124 }
125
126 }