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
29namespace mkldnn {
30namespace impl {
31
32template <data_type_t> struct prec_traits {}; /* ::type -> float */
33template <typename> struct data_traits {}; /* ::data_type -> f32 */
34template <int> struct typesize_traits {}; /* ::data_type_size -> f32 */
35template <primitive_kind_t> struct pkind_traits {}; /* ::desc_type, ::query_d */
36
37template <> struct prec_traits<data_type::f32> { typedef float type; };
38template <> struct prec_traits<data_type::s32> { typedef int32_t type; };
39template <> struct prec_traits<data_type::s8> { typedef int8_t type; };
40template <> struct prec_traits<data_type::u8> { typedef uint8_t type; };
41
42template <> struct data_traits<float>
43{ static constexpr data_type_t data_type = data_type::f32; };
44template <> struct data_traits<int32_t>
45{ static constexpr data_type_t data_type = data_type::s32; };
46template <> struct data_traits<int8_t>
47{ static constexpr data_type_t data_type = data_type::s8; };
48template <> struct data_traits<uint8_t>
49{ static constexpr data_type_t data_type = data_type::u8; };
50
51template <> struct typesize_traits<4> { typedef float type; };
52template <> struct typesize_traits<2> { typedef int16_t type; };
53template <> struct typesize_traits<1> { typedef uint8_t type; };
54
55#define PKIND_TRAITS_INST(op) \
56template <> 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}
60PKIND_TRAITS_INST(convolution);
61PKIND_TRAITS_INST(deconvolution);
62PKIND_TRAITS_INST(shuffle);
63PKIND_TRAITS_INST(eltwise);
64PKIND_TRAITS_INST(softmax);
65PKIND_TRAITS_INST(pooling);
66PKIND_TRAITS_INST(lrn);
67PKIND_TRAITS_INST(batch_normalization);
68PKIND_TRAITS_INST(inner_product);
69PKIND_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