1 /*******************************************************************************
2 * Copyright 2017-2018 Intel Corporation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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 *******************************************************************************/
17 #ifndef _INPUT_REORDER_HPP
18 #define _INPUT_REORDER_HPP
20 #include "mkldnn_common.hpp"
21 #include "reorder/reorder.hpp"
23 #define MASK_SUPPORTED 1
24 #define SCALE_SUPPORTED 1
27 const float default_scales[] = {0.125, 0.25, 0.5, 1, 2, 4, 8};
29 const float default_scales[] = {1};
32 const int int_max_exact = 1<<24;
34 const reorder::dt_conf_t conf_f32 = {mkldnn_f32, -int_max_exact, 2*int_max_exact};
35 const reorder::dt_conf_t conf_s8 = {mkldnn_s8, INT8_MIN, -2*INT8_MIN};
36 const reorder::dt_conf_t conf_u8 = {mkldnn_u8, 0, UINT8_MAX};
37 const reorder::dt_conf_t conf_s16 = {mkldnn_s16, INT16_MIN, -2*INT16_MIN};
38 const reorder::dt_conf_t conf_s32 = {mkldnn_s32, -int_max_exact, 2*int_max_exact};
40 static reorder::reorder_conf_t reorders[] = {
41 /* ndims, dims, fmt_in, fmt_out */
42 {4, {2, 64, 13, 13}, mkldnn_nchw, mkldnn_nchw},
43 {4, {2, 64, 13, 13}, mkldnn_nChw8c, mkldnn_nhwc},
44 {4, {2, 64, 13, 13}, mkldnn_nhwc, mkldnn_nChw8c},
45 {4, {2, 64, 13, 13}, mkldnn_nChw16c, mkldnn_nhwc},
46 {4, {2, 64, 13, 13}, mkldnn_nhwc, mkldnn_nChw16c},
47 {4, {2, 64, 13, 13}, mkldnn_nchw, mkldnn_nhwc},
48 {4, {2, 64, 13, 13}, mkldnn_nhwc, mkldnn_nchw},
49 {4, {2, 64, 13, 13}, mkldnn_oihw, mkldnn_oihw},
50 {4, {2, 64, 13, 13}, mkldnn_hwio, mkldnn_oihw},
53 static reorder::q10n_conf_t q10ns[] = {
54 /* dt_{in,out}, conf, rmode, policy, scale */
56 { conf_f32, conf_f32, attr_t::round_mode_t::NEAREST,
57 attr_t::scale_t::policy_t::COMMON},
59 { conf_u8, conf_u8, attr_t::round_mode_t::NEAREST,
60 attr_t::scale_t::policy_t::COMMON},
62 { conf_s8, conf_s8, attr_t::round_mode_t::NEAREST,
63 attr_t::scale_t::policy_t::COMMON},
65 { conf_s32, conf_s32, attr_t::round_mode_t::NEAREST,
66 attr_t::scale_t::policy_t::COMMON},
68 { conf_s8, conf_u8, attr_t::round_mode_t::NEAREST,
69 attr_t::scale_t::policy_t::COMMON},
70 { conf_u8, conf_s8, attr_t::round_mode_t::NEAREST,
71 attr_t::scale_t::policy_t::COMMON},
73 { conf_f32, conf_s32, attr_t::round_mode_t::NEAREST,
74 attr_t::scale_t::policy_t::COMMON},
75 { conf_f32, conf_s32, attr_t::round_mode_t::DOWN,
76 attr_t::scale_t::policy_t::COMMON},
77 { conf_s32, conf_f32, attr_t::round_mode_t::NEAREST,
78 attr_t::scale_t::policy_t::COMMON},
80 { conf_f32, conf_s8, attr_t::round_mode_t::NEAREST,
81 attr_t::scale_t::policy_t::COMMON},
82 { conf_s8, conf_f32, attr_t::round_mode_t::NEAREST,
83 attr_t::scale_t::policy_t::COMMON},
85 { conf_f32, conf_u8, attr_t::round_mode_t::NEAREST,
86 attr_t::scale_t::policy_t::COMMON},
87 { conf_u8, conf_f32, attr_t::round_mode_t::NEAREST,
88 attr_t::scale_t::policy_t::COMMON},
90 { conf_s32, conf_s8, attr_t::round_mode_t::NEAREST,
91 attr_t::scale_t::policy_t::COMMON},
92 { conf_s8, conf_s32, attr_t::round_mode_t::NEAREST,
93 attr_t::scale_t::policy_t::COMMON},
95 { conf_s32, conf_u8, attr_t::round_mode_t::NEAREST,
96 attr_t::scale_t::policy_t::COMMON},
97 { conf_u8, conf_s32, attr_t::round_mode_t::NEAREST,
98 attr_t::scale_t::policy_t::COMMON},
101 { conf_f32, conf_f32, attr_t::round_mode_t::NEAREST,
102 attr_t::scale_t::policy_t::PER_OC},
103 { conf_s8, conf_f32, attr_t::round_mode_t::NEAREST,
104 attr_t::scale_t::policy_t::PER_OC},