Publishing R3
[platform/upstream/dldt.git] / inference-engine / thirdparty / mkl-dnn / tests / benchdnn / reorder / bench_reorder.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 "mkldnn.h"
18 #include "mkldnn_common.hpp"
19 #include "mkldnn_memory.hpp"
20
21 #include "reorder.hpp"
22 #include "input_reorder.hpp"
23
24 namespace reorder {
25
26 int bench(int argc, char **argv) {
27     const int num_r = sizeof(reorders) / sizeof(reorders[0]);
28     const int num_q = sizeof(q10ns) / sizeof(q10ns[0]);
29     const int num_s = sizeof(default_scales) / sizeof(default_scales[0]);
30
31     for (int q = 0; q < num_q; ++q) {
32         if (q10ns[q].scale == 0) {
33            for (int idx = 0; idx < num_s; ++idx) {
34                q10ns[q].scale = default_scales[idx];
35                for (int r = 0; r < num_r; ++r) {
36                    const prb_t p(&reorders[r], &q10ns[q]);
37                    check(&p);
38                }
39             }
40         } else {
41             for (int r = 0; r < num_r; ++r) {
42                 const prb_t p(&reorders[r], &q10ns[q]);
43                 check(&p);
44             }
45         }
46     }
47
48     return OK;
49 }
50
51 void check(const prb_t *p) {
52     res_t res{};
53     char pstr[max_prb_len];
54     prb2str(p, &res, pstr);
55
56     int status = reorder::doit(p, &res);
57
58     prb2str(p, &res, pstr);
59     bool want_perf_report = false;
60
61     parse_result(res, want_perf_report, false, status, pstr);
62
63     if (bench_mode & PERF)
64         perf_report(p, &res, pstr);
65
66     benchdnn_stat.tests++;
67 }
68
69 void perf_report(const prb_t *p, const res_t *r, const char *pstr) {
70     const auto &t = r->timer;
71     const int max_len = 400;
72     char buffer[max_len], *buf = buffer;
73     int rem_len = max_len - 1;
74
75     #   define DPRINT(...) do { \
76         int l = snprintf(buf, rem_len, __VA_ARGS__); \
77         buf += l; rem_len -= l; \
78     } while(0)
79
80     DPRINT("perf,");
81     DPRINT("%s,", pstr);
82     DPRINT("min_ms=%g,", t.ms(benchdnn_timer_t::min));
83     DPRINT("max_ms=%g", t.ms(benchdnn_timer_t::max));
84
85 #   undef DPRINT
86     print(0, "%s\n", buffer);
87 }
88
89 }