Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / mkl-dnn / src / common / mkldnn_traits.hpp
1 /*******************************************************************************
2 * Copyright 2016-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 MKLDNN_TRAITS_HPP
18 #define MKLDNN_TRAITS_HPP
19
20 #include <assert.h>
21 #include <stdint.h>
22
23 #include "mkldnn.h"
24 #include "c_types_map.hpp"
25 #include "nstl.hpp"
26 #include "utils.hpp"
27 #include "z_magic.hpp"
28
29 namespace mkldnn {
30 namespace impl {
31
32 template <data_type_t> struct prec_traits {}; /* ::type -> float */
33 template <typename> struct data_traits {}; /* ::data_type -> f32 */
34 template <int> struct typesize_traits {}; /* ::data_type_size -> f32 */
35 template <primitive_kind_t> struct pkind_traits {}; /* ::desc_type, ::query_d */
36
37 template <> struct prec_traits<data_type::f32> { typedef float type; };
38 template <> struct prec_traits<data_type::s32> { typedef int32_t type; };
39 template <> struct prec_traits<data_type::s16> { typedef int16_t type; };
40 template <> struct prec_traits<data_type::s8> { typedef int8_t type; };
41 template <> struct prec_traits<data_type::u8> { typedef uint8_t type; };
42 template <> struct prec_traits<data_type::bin> { typedef uint8_t type; };
43
44 template <> struct data_traits<float>
45 { static constexpr data_type_t data_type = data_type::f32; };
46 template <> struct data_traits<int32_t>
47 { static constexpr data_type_t data_type = data_type::s32; };
48 template <> struct data_traits<int16_t>
49 { static constexpr data_type_t data_type = data_type::s16; };
50 template <> struct data_traits<int8_t>
51 { static constexpr data_type_t data_type = data_type::s8; };
52 template <> struct data_traits<uint8_t>
53 { static constexpr data_type_t data_type = data_type::u8; };
54
55 template <> struct typesize_traits<4> { typedef float type; };
56 template <> struct typesize_traits<2> { typedef int16_t type; };
57 template <> struct typesize_traits<1> { typedef uint8_t type; };
58
59 #define PKIND_TRAITS_INST(op) \
60 template <> struct pkind_traits<primitive_kind::op> { \
61     typedef CONCAT2(op, _desc_t) desc_type; \
62     static constexpr query_t query_d = query::CONCAT2(op, _d); \
63 }
64 PKIND_TRAITS_INST(memory);
65 PKIND_TRAITS_INST(convolution);
66 PKIND_TRAITS_INST(deconvolution);
67 PKIND_TRAITS_INST(shuffle);
68 PKIND_TRAITS_INST(eltwise);
69 PKIND_TRAITS_INST(depthwise);
70 PKIND_TRAITS_INST(softmax);
71 PKIND_TRAITS_INST(pooling);
72 PKIND_TRAITS_INST(lrn);
73 PKIND_TRAITS_INST(batch_normalization);
74 PKIND_TRAITS_INST(inner_product);
75 PKIND_TRAITS_INST(rnn);
76 PKIND_TRAITS_INST(roi_pooling);
77 PKIND_TRAITS_INST(binary_convolution);
78 PKIND_TRAITS_INST(binarization);
79 #undef PKIND_TRAITS_INST
80
81 }
82 }
83
84 #endif
85
86 // vim: et ts=4 sw=4 cindent cino^=l0,\:0,N-s