Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / mkl-dnn / tests / benchdnn / reorder / reorder.hpp
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 #ifndef _REORDER_HPP
18 #define _REORDER_HPP
19
20 #include <vector>
21
22 #include "mkldnn.h"
23
24 #include "common.hpp"
25 #include "dnn_types.hpp"
26 #include "mkldnn_common.hpp"
27 #include "mkldnn_memory.hpp"
28
29 namespace reorder {
30
31 using dims_t = std::vector<ptrdiff_t>;
32
33 struct dt_conf_s {
34     mkldnn_data_type_t dt;
35     int min;
36     int range;
37 };
38 typedef const dt_conf_s *dt_conf_t;
39
40 struct reorder_conf_t {
41     dims_t dims;
42     mkldnn_memory_format_t fmt_in, fmt_out;
43 };
44
45 struct q10n_conf_t {
46     dt_conf_t conf_in;
47     dt_conf_t conf_out;
48     /* TODO: add attrs */
49     attr_t::round_mode_t irmode;
50     attr_t::scale_t::policy_t policy;
51     float scale;
52 };
53
54 struct prb_t {
55     prb_t(const reorder_conf_t &r, const dt_conf_t &conf_in,
56             const dt_conf_t &conf_out, const attr_t &attr, float scale = 0.f)
57         : reorder(r), conf_in(conf_in), conf_out(conf_out), attr(attr) {
58         if (scale != 0.f) this->attr.oscale.scale = scale;
59     }
60
61     const reorder_conf_t reorder;
62     dt_conf_t conf_in;
63     dt_conf_t conf_out;
64     attr_t attr;
65 };
66
67 extern const char *perf_template; /* performance output template */
68
69 extern const dt_conf_t conf_f32;
70 extern const dt_conf_t conf_s8;
71 extern const dt_conf_t conf_u8;
72 extern const dt_conf_t conf_s16;
73 extern const dt_conf_t conf_s32;
74 dt_conf_t dt2cfg(mkldnn_data_type_t dt);
75 mkldnn_data_type_t cfg2dt(dt_conf_t cfg);
76
77 const size_t max_dims_len = 20;
78 const size_t max_prb_len = 392;
79 dims_t str2dims(const char *str);
80 void dims2str(const dims_t &dims, char *buffer);
81 void prb2str(const prb_t *p, const res_t *res, char *buffer);
82 void perf_report(const prb_t *p, const res_t *r, const char *pstr);
83
84 inline size_t data_off_f(const prb_t *p, int mb, int ic, int ih, int iw) {
85     const auto &dims = p->reorder.dims;
86     return ((mb * dims[1] + ic) * dims[2] + ih) * dims[3] + iw;
87 }
88
89 int doit(const prb_t *p, res_t *res);
90 int bench(int argc, char **argv, bool main_bench = true);
91
92 }
93
94 #endif