1 /*******************************************************************************
2 * Copyright 2016-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 MKLDNN_TRAITS_HPP
18 #define MKLDNN_TRAITS_HPP
24 #include "c_types_map.hpp"
27 #include "z_magic.hpp"
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 */
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; };
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; };
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; };
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); \
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
86 // vim: et ts=4 sw=4 cindent cino^=l0,\:0,N-s