12 #include <unordered_map> 44 struct PrecisionInfo {
49 const char*
name =
"UNSPECIFIED";
54 PrecisionInfo precisionInfo;
75 precisionInfo.bitsSize = bitsSize;
76 if (
name ==
nullptr) {
77 precisionInfo.name =
"CUSTOM";
79 precisionInfo.name =
name;
81 precisionInfo.value =
CUSTOM;
87 return Precision(8 *
sizeof(T), typeName ==
nullptr ?
typeid(T).
name() : typeName);
94 if (precisionInfo.value !=
BIN) {
95 if (
sizeof(T) !=
size()) {
101 return std::is_same<T, y>() 102 #define CASE2(x, y1, y2) \ 104 return std::is_same<T, y1>() || std::is_same<T, y2>() 106 switch (precisionInfo.value) {
108 CASE2(
FP16, int16_t, uint16_t);
117 CASE2(
Q78, int16_t, uint16_t);
118 CASE2(
BIN, int8_t, uint8_t);
131 return precisionInfo.value == p && precisionInfo.bitsSize == p.precisionInfo.bitsSize &&
137 return precisionInfo.value == p;
142 return precisionInfo.value != p;
152 explicit operator bool() const noexcept {
163 return precisionInfo.value;
171 return precisionInfo.value;
175 const char*
name() const noexcept {
176 return precisionInfo.name;
181 static std::unordered_map<std::string, ePrecision> names = {
182 #define PRECISION_NAME(s) {#s, s} 183 PRECISION_NAME(
Q78), PRECISION_NAME(
U8), PRECISION_NAME(
I8), PRECISION_NAME(
I16),
184 PRECISION_NAME(
I32), PRECISION_NAME(
I64), PRECISION_NAME(
U64), PRECISION_NAME(
U16),
185 PRECISION_NAME(
FP32), PRECISION_NAME(
FP16), PRECISION_NAME(
MIXED), PRECISION_NAME(
BIN),
186 PRECISION_NAME(
BOOL),
187 #undef PRECISION_NAME 189 auto i = names.find(str);
198 if (precisionInfo.bitsSize == 0) {
199 THROW_IE_EXCEPTION <<
" cannot estimate element if precision is " << precisionInfo.name;
201 return precisionInfo.bitsSize >> 3;
209 return precisionInfo.isFloat;
232 template <Precision::ePrecision precision>
243 if (l == r)
return true;
245 if (l ==
nullptr || r ==
nullptr)
return false;
247 for (; *l && *r; l++, r++) {
248 if (*l != *r)
return false;
259 return makePrecisionInfo<x>(#x); 275 return makePrecisionInfo<UNSPECIFIED>(
"UNSPECIFIED");
284 template <Precision::ePrecision p>
290 using value_type = float;
295 using value_type = int16_t;
299 using value_type = uint16_t;
303 using value_type = int16_t;
307 using value_type = uint16_t;
311 using value_type = uint8_t;
315 using value_type = int8_t;
319 using value_type = uint8_t;
323 using value_type = int32_t;
327 using value_type = int64_t;
331 using value_type = uint64_t;
335 using value_type = int8_t;
339 inline uint8_t type_size_or_zero() {
345 using value_type = void;
352 inline uint8_t type_size_or_zero<void>() {
356 template <Precision::ePrecision T>
357 inline typename std::enable_if<std::is_same<std::integral_constant<Precision::ePrecision, Precision::FP16>,
358 std::integral_constant<Precision::ePrecision, T>>::value,
364 template <Precision::ePrecision T>
365 inline typename std::enable_if<!std::is_same<std::integral_constant<Precision::ePrecision, Precision::FP16>,
366 std::integral_constant<Precision::ePrecision, T>>::value,
369 return std::is_floating_point<typename PrecisionTrait<T>::value_type>::value;
372 template <Precision::ePrecision precision>
374 Precision::PrecisionInfo info;
378 info.bitsSize = nBits * type_size_or_zero<typename PrecisionTrait<precision>::value_type>();
379 info.isFloat = is_floating<precision>();
385 return out << p.
name();
392 inline std::ostream& operator<<(std::ostream& os, const std::vector<Precision>& values) {
394 for (
size_t i = 0; i < values.size(); ++i) {
396 if (i != (values.size() - 1ul)) {
404 inline constexpr uint32_t getPrecisionMask(
408 return (precision1) | (precision2 << 8) | (precision3 << 16) | (precision4 << 24);
#define THROW_IE_EXCEPTION
A macro used to throw the exception with a notable description.
Definition: ie_exception.hpp:25
Definition: ie_precision.hpp:34
Definition: ie_precision.hpp:28
ePrecision
Definition: ie_precision.hpp:25
Particular precision traits.
Definition: ie_precision.hpp:285
static Precision fromType(const char *typeName=nullptr)
Creates custom precision with specific underlined type.
Definition: ie_precision.hpp:86
Inference Engine API.
Definition: ie_argmax_layer.hpp:15
static PrecisionInfo getPrecisionInfo(ePrecision v)
Return PrecisionInfo.
Definition: ie_precision.hpp:256
Definition: ie_precision.hpp:33
bool operator!() const noexcept
Logical negation operator.
Definition: ie_precision.hpp:157
Precision & operator=(const ePrecision p) noexcept
Assignment operator with ePrecision enum value.
Definition: ie_precision.hpp:146
Definition: ie_precision.hpp:30
size_t size() const
Returns size of single element of that precision in bits.
Definition: ie_precision.hpp:197
Definition: ie_precision.hpp:29
bool operator==(const Precision &p) const noexcept
Equality operator with Precision object.
Definition: ie_precision.hpp:130
Definition: ie_precision.hpp:38
bool is_float() const noexcept
Checks if it is a floating point value.
Definition: ie_precision.hpp:208
Definition: ie_precision.hpp:40
static PrecisionInfo makePrecisionInfo(const char *name)
Creates PrecisionInfo by precision with a specified name.
static Precision FromStr(const std::string &str)
Creates from string with precision name.
Definition: ie_precision.hpp:180
Precision(size_t bitsSize, const char *name=nullptr)
Custom precision constructor.
Definition: ie_precision.hpp:71
Definition: ie_precision.hpp:36
bool isSigned() const noexcept
Checks if it is a signed value.
Definition: ie_precision.hpp:216
bool operator==(const ePrecision p) const noexcept
Equality operator with ePrecision enum value.
Definition: ie_precision.hpp:136
Definition: ie_precision.hpp:32
Definition: ie_precision.hpp:27
Definition: ie_precision.hpp:35
Definition: ie_precision.hpp:37
constexpr uint8_t getPrecVal() const noexcept
Gets the precision value of type ePrecision.
Definition: ie_precision.hpp:170
Definition: ie_precision.hpp:31
Precision(const Precision::ePrecision value)
Constructor with specified precision.
Definition: ie_precision.hpp:61
std::string type
Layer type.
Definition: ie_layers.h:47
Precision precision
Layer precision.
Definition: ie_layers.h:54
Definition: ie_precision.hpp:39
bool operator!=(const ePrecision p) const noexcept
Inequality operator with ePrecision enum value.
Definition: ie_precision.hpp:141
static bool areSameStrings(const char *l, const char *r) noexcept
Compare two c-strings.
Definition: ie_precision.hpp:242
Precision()=default
Default constructor.
A header file for the main Inference Engine exception.
This class holds precision value and provides precision related operations.
Definition: ie_precision.hpp:22
Definition: ie_precision.hpp:26
bool hasStorageType(const char *typeName=nullptr) const noexcept
checks whether given storage class T can be used to store objects of current precision ...
Definition: ie_precision.hpp:92
const char * name() const noexcept
Getter of precision name.
Definition: ie_precision.hpp:175