Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / mkl-dnn / tests / benchdnn / ip / cfg.cpp
1 /*******************************************************************************
2 * Copyright 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
22 #include "mkldnn.h"
23 #include "mkldnn_common.hpp"
24
25 #include "ip.hpp"
26
27 namespace ip {
28
29 /* cfgs definition
30  * arrays: SRC, WEI, BIA, DST, ACC
31  * params: {data_type, min, max, f_min, f_max, f_base, f_step, f_sparsity, eps}
32  */
33
34 const int int_max_exact = 1<<24;
35 const _dt_conf_t conf_f32 = {
36     {mkldnn_f32, -int_max_exact, int_max_exact,  -32,  32, 0, 1, .35, 0.},
37     {mkldnn_f32, -int_max_exact, int_max_exact,  -32,  32, 0, 1, 1.0, 0.},
38     {mkldnn_f32, -int_max_exact, int_max_exact, -512, 512, 0, 1, 1.0, 0.},
39     {mkldnn_f32, -int_max_exact, int_max_exact,  -32,  32, 0, 1, .35, 0.},
40     {mkldnn_f32,},
41 };
42
43 const _dt_conf_t conf_s16s16s32s32 = {
44     {mkldnn_s16, INT16_MIN, INT16_MAX, -4,  4, 0, 1, .35, 0.},
45     {mkldnn_s16, INT16_MIN, INT16_MAX, -5,  5, 0, 1, .35, 0.},
46     {mkldnn_s32, INT32_MIN, INT32_MAX, -8, 32, 0, 1, .35, 0.},
47     {mkldnn_s32, INT32_MIN, INT32_MAX, -4,  4, 0, 1, .35, 0.},
48     {mkldnn_s32,},
49 };
50
51 const _dt_conf_t conf_u8s8f32s32 = {
52     {mkldnn_u8,               0,     UINT8_MAX,    0,   8, 0, 1, .35, 0.},
53     {mkldnn_s8,        INT8_MIN,      INT8_MAX,   -5,   5, 0, 1, .35, 0.},
54     {mkldnn_f32, -int_max_exact, int_max_exact,   -8,  32, 0, 1, .35, 0.},
55     {mkldnn_f32, -int_max_exact, int_max_exact, -255, 255, 0, 1, .35, 0.},
56     {mkldnn_s32,},
57 };
58
59 const _dt_conf_t conf_u8s8s32s32 = {
60     {mkldnn_u8,               0,     UINT8_MAX,    0,   8, 0, 1, .35, 0.},
61     {mkldnn_s8,        INT8_MIN,      INT8_MAX,   -5,   5, 0, 1, .35, 0.},
62     {mkldnn_f32, -int_max_exact, int_max_exact,   -8,  32, 0, 1, .35, 0.},
63     {mkldnn_s32,      INT32_MIN,     INT32_MAX, -255, 255, 0, 1, .35, 0.},
64     {mkldnn_s32,},
65 };
66
67 const _dt_conf_t conf_u8s8s8s32 = {
68     {mkldnn_u8,               0,     UINT8_MAX,    0,   8, 0, 1, .35, 0.},
69     {mkldnn_s8,        INT8_MIN,      INT8_MAX,   -5,   5, 0, 1, .35, 0.},
70     {mkldnn_f32, -int_max_exact, int_max_exact,   -8,  32, 0, 1, .35, 0.},
71     {mkldnn_s8,        INT8_MIN,      INT8_MAX, -127, 127, 0, 1, .35, 0.},
72     {mkldnn_s32,},
73 };
74
75 const _dt_conf_t conf_u8s8u8s32 = {
76     {mkldnn_u8,               0,     UINT8_MAX,    0,   8, 0, 1, .35, 0.},
77     {mkldnn_s8,        INT8_MIN,      INT8_MAX,   -5,   5, 0, 1, .35, 0.},
78     {mkldnn_f32, -int_max_exact, int_max_exact,   -8,  32, 0, 1, .35, 0.},
79     {mkldnn_u8,               0,     UINT8_MAX,    0, 255, 0, 1, .35, 0.},
80     {mkldnn_s32,},
81 };
82
83 const _dt_conf_t conf_s8s8f32s32 = {
84     {mkldnn_s8,        INT8_MIN,      INT8_MAX,   -5,   5, 0, 1, .35, 0.},
85     {mkldnn_s8,        INT8_MIN,      INT8_MAX,   -5,   5, 0, 1, .35, 0.},
86     {mkldnn_f32, -int_max_exact, int_max_exact,   -8,  32, 0, 1, .35, 0.},
87     {mkldnn_f32, -int_max_exact, int_max_exact, -255, 255, 0, 1, .35, 0.},
88     {mkldnn_s32,},
89 };
90
91 const _dt_conf_t conf_s8s8s32s32 = {
92     {mkldnn_s8,        INT8_MIN,      INT8_MAX,   -5,   5, 0, 1, .35, 0.},
93     {mkldnn_s8,        INT8_MIN,      INT8_MAX,   -5,   5, 0, 1, .35, 0.},
94     {mkldnn_f32, -int_max_exact, int_max_exact,   -8,  32, 0, 1, .35, 0.},
95     {mkldnn_s32,      INT32_MIN,     INT32_MAX, -255, 255, 0, 1, .35, 0.},
96     {mkldnn_s32,},
97 };
98
99 const _dt_conf_t conf_s8s8s8s32 = {
100     {mkldnn_s8,        INT8_MIN,      INT8_MAX,   -5,   5, 0, 1, .35, 0.},
101     {mkldnn_s8,        INT8_MIN,      INT8_MAX,   -5,   5, 0, 1, .35, 0.},
102     {mkldnn_f32, -int_max_exact, int_max_exact,   -8,  32, 0, 1, .35, 0.},
103     {mkldnn_s8,        INT8_MIN,      INT8_MAX, -127, 127, 0, 1, .35, 0.},
104     {mkldnn_s32,},
105 };
106
107 const _dt_conf_t conf_s8s8u8s32 = {
108     {mkldnn_s8,        INT8_MIN,      INT8_MAX,   -5,   5, 0, 1, .35, 0.},
109     {mkldnn_s8,        INT8_MIN,      INT8_MAX,   -5,   5, 0, 1, .35, 0.},
110     {mkldnn_f32, -int_max_exact, int_max_exact,   -8,  32, 0, 1, .35, 0.},
111     {mkldnn_u8,               0,     UINT8_MAX,    0, 255, 0, 1, .35, 0.},
112     {mkldnn_s32,},
113 };
114
115 const dt_conf_t *str2cfg(const char *str) {
116 #define CASE(cfg) \
117     if (!strcasecmp(STRINGIFY(cfg), str)) return CONCAT2(conf_,cfg)
118     CASE(f32);
119     CASE(s16s16s32s32);
120     CASE(u8s8f32s32);
121     CASE(u8s8s32s32);
122     CASE(u8s8s8s32);
123     CASE(u8s8u8s32);
124     CASE(s8s8f32s32);
125     CASE(s8s8s32s32);
126     CASE(s8s8s8s32);
127     CASE(s8s8u8s32);
128 #undef CASE
129     []() { SAFE(FAIL, CRIT); return 0; }();
130     return (const dt_conf_t *)1;
131 }
132
133 const char *cfg2str(const dt_conf_t *cfg) {
134 #define CASE(_cfg) if (cfg == CONCAT2(conf_,_cfg)) return STRINGIFY(_cfg)
135     CASE(f32);
136     CASE(s16s16s32s32);
137     CASE(u8s8f32s32);
138     CASE(u8s8s32s32);
139     CASE(u8s8s8s32);
140     CASE(u8s8u8s32);
141     CASE(s8s8f32s32);
142     CASE(s8s8s32s32);
143     CASE(s8s8s8s32);
144     CASE(s8s8u8s32);
145 #undef CASE
146     []() { SAFE(FAIL, CRIT); return 0; }();
147     return NULL;
148 }
149
150 }