Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / mkl-dnn / tests / benchdnn / bnorm / perf_report.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 #include "mkldnn_memory.hpp"
25
26 #include "bnorm/bnorm.hpp"
27
28 namespace bnorm {
29
30 #if 0
31 See conv/perf_report.cpp for details.
32 See modifiers at the same place.
33
34 | abbreviation  | description
35 |:------------  |:-----------
36 | %d            | problem descriptor
37 | %D            | expanded problem descriptor (parameters in csv format)
38 | %n            | problem name
39 | %z            | direction
40 | %F            | flags
41 | %q            | data type (precision)
42 | %f            | data format (layout)
43 | %@t           | time in ms
44
45 The definition of expanded problem descriptor is: `mb,ic,ih,iw,eps`.
46 #endif
47
48 void perf_report(const prb_t *p, const res_t *r, const char *pstr) {
49     const auto &t = r->timer;
50     const int max_len = 400;
51     int rem_len = max_len - 1;
52     char buffer[max_len], *buf = buffer;
53
54 #   define DPRINT(...) do { \
55         int l = snprintf(buf, rem_len, __VA_ARGS__); \
56         buf += l; rem_len -= l; \
57     } while(0)
58
59     auto modifier2mode = [](char c) {
60         if (c == '-') return benchdnn_timer_t::min;
61         if (c == '0') return benchdnn_timer_t::avg;
62         if (c == '+') return benchdnn_timer_t::max;
63         return benchdnn_timer_t::min;
64     };
65
66     auto modifier2unit = [](char c) {
67         if (c == 'K') return 1e3;
68         if (c == 'M') return 1e6;
69         if (c == 'G') return 1e9;
70         return 1e0;
71     };
72
73     const char *pt = perf_template;
74     char c;
75
76     while ((c = *pt++) != '\0') {
77         if (c != '%') { *buf++ = c; rem_len--; continue; }
78
79         c = *pt++;
80
81         benchdnn_timer_t::mode_t mode = benchdnn_timer_t::min;
82         double unit = 1e0;
83
84         if (c == '-' || c == '0' || c == '+') {
85             mode = modifier2mode(c);
86             c = *pt++;
87         }
88
89         if (c == 'K' || c == 'M' || c == 'G') {
90             unit = modifier2unit(c);
91             c = *pt++;
92         }
93
94         if (c == 'd')
95             DPRINT("%s", pstr);
96         else if (c == 'D')
97             DPRINT("%d,%d,%d,%d,%d,%g", p->mb, p->ic, p->id, p->ih, p->iw,
98                 p->eps);
99         else if (c == 'n')
100             DPRINT("%s", p->name);
101         else if (c == 'z')
102             DPRINT("%s", dir2str(p->dir));
103         else if (c == 'F')
104             DPRINT("%s", flags2str(p->flags));
105         else if (c == 'q')
106             DPRINT("%s", dt2str(p->dt));
107         else if (c == 'f')
108             DPRINT("%s", fmt2str(p->fmt));
109         else if (c == 't')
110             DPRINT("%g", t.ms(mode) / unit);
111         else
112             []() { SAFE(FAIL, CRIT); return 0; }();
113     }
114
115     *buf = '\0';
116     assert(rem_len >= 0);
117
118 #   undef DPRINT
119     print(0, "%s\n", buffer);
120 }
121
122 }