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::s8> { typedef int8_t type; }; |
40 | template <> struct prec_traits<data_type::u8> { typedef uint8_t type; }; |
41 | |
42 | template <> struct data_traits<float> |
43 | { static constexpr data_type_t data_type = data_type::f32; }; |
44 | template <> struct data_traits<int32_t> |
45 | { static constexpr data_type_t data_type = data_type::s32; }; |
46 | template <> struct data_traits<int8_t> |
47 | { static constexpr data_type_t data_type = data_type::s8; }; |
48 | template <> struct data_traits<uint8_t> |
49 | { static constexpr data_type_t data_type = data_type::u8; }; |
50 | |
51 | template <> struct typesize_traits<4> { typedef float type; }; |
52 | template <> struct typesize_traits<2> { typedef int16_t type; }; |
53 | template <> struct typesize_traits<1> { typedef uint8_t type; }; |
54 | |
55 | #define PKIND_TRAITS_INST(op) \ |
56 | template <> struct pkind_traits<primitive_kind::op> { \ |
57 | typedef CONCAT2(op, _desc_t) desc_type; \ |
58 | static constexpr query_t query_d = query::CONCAT2(op, _d); \ |
59 | } |
60 | PKIND_TRAITS_INST(convolution); |
61 | PKIND_TRAITS_INST(deconvolution); |
62 | PKIND_TRAITS_INST(shuffle); |
63 | PKIND_TRAITS_INST(eltwise); |
64 | PKIND_TRAITS_INST(softmax); |
65 | PKIND_TRAITS_INST(pooling); |
66 | PKIND_TRAITS_INST(lrn); |
67 | PKIND_TRAITS_INST(batch_normalization); |
68 | PKIND_TRAITS_INST(inner_product); |
69 | PKIND_TRAITS_INST(rnn); |
70 | #undef PKIND_TRAITS_INST |
71 | |
72 | } |
73 | } |
74 | |
75 | #endif |
76 | |
77 | // vim: et ts=4 sw=4 cindent cino^=l0,\:0,N-s |
78 |