2 // Copyright (c) 2016 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.
18 #include "common_types.h"
19 #include <type_traits>
21 namespace kernel_selector
23 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
25 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
26 inline uint32_t BytesPerElement(Datatype dt)
35 case Datatype::UINT16:
39 case Datatype::UINT32:
48 inline uint32_t BytesPerElement(WeightsType wt)
52 case WeightsType::INT8:
53 case WeightsType::UINT8:
55 case WeightsType::F16:
57 case WeightsType::F32:
64 inline uint8_t GetActivationAdditionalParamsNumber(ActivationFunction func)
66 uint8_t paramsNum = 0;
70 case ActivationFunction::LINEAR:
71 case ActivationFunction::CLAMP:
74 case ActivationFunction::RELU_NEGATIVE_SLOPE:
75 case ActivationFunction::ELU:
76 case ActivationFunction::RELU_NEGATIVE_SLOPE_GRAD:
87 typename std::enable_if<std::is_integral<T>::value, T>::type Align(T size, size_t align) {
88 return static_cast<T>((size % align == 0) ? size : size - size % align + align);
92 typename std::enable_if<std::is_integral<T>::value, T>::type Pad(T size, size_t align) {
93 return static_cast<T>((size % align == 0) ? 0 : align - size % align);
97 typename std::enable_if<std::is_integral<T>::value, bool>::type IsAligned(T size, size_t align)
99 return !(size % align);
102 template <typename T1, typename T2>
103 constexpr auto CeilDiv(T1 val, T2 divider)
104 -> typename std::enable_if<std::is_integral<T1>::value && std::is_integral<T2>::value,
105 decltype(std::declval<typename std::make_unsigned<T1>::type>() / std::declval<typename std::make_unsigned<T2>::type>())>::type
107 typedef typename std::make_unsigned<T1>::type UT1;
108 typedef typename std::make_unsigned<T2>::type UT2;
109 typedef decltype(std::declval<UT1>() / std::declval<UT2>()) RetT;
111 return static_cast<RetT>((static_cast<UT1>(val) + static_cast<UT2>(divider) - 1U) / static_cast<UT2>(divider));
114 template <typename T1, typename T2>
115 constexpr auto RoundUp(T1 val, T2 rounding)
116 -> typename std::enable_if<std::is_integral<T1>::value && std::is_integral<T2>::value,
117 decltype(std::declval<typename std::make_unsigned<T1>::type>() / std::declval<typename std::make_unsigned<T2>::type>())>::type
119 typedef typename std::make_unsigned<T1>::type UT1;
120 typedef typename std::make_unsigned<T2>::type UT2;
121 typedef decltype(std::declval<UT1>() / std::declval<UT2>()) RetT;
123 return static_cast<RetT>(CeilDiv(val, rounding) * static_cast<UT2>(rounding));