12 #include <unordered_map> 45 struct PrecisionInfo {
50 const char*
name =
"UNSPECIFIED";
55 PrecisionInfo precisionInfo;
76 precisionInfo.bitsSize = bitsSize;
77 if (
name ==
nullptr) {
78 precisionInfo.name =
"CUSTOM";
80 precisionInfo.name =
name;
82 precisionInfo.value =
CUSTOM;
88 return Precision(8 *
sizeof(T), typeName ==
nullptr ?
typeid(T).
name() : typeName);
95 if (precisionInfo.value !=
BIN) {
96 if (
sizeof(T) !=
size()) {
102 return std::is_same<T, y>() 103 #define CASE2(x, y1, y2) \ 105 return std::is_same<T, y1>() || std::is_same<T, y2>() 107 switch (precisionInfo.value) {
109 CASE2(
FP16, int16_t, uint16_t);
110 CASE2(
BF16, int16_t, uint16_t);
119 CASE2(
Q78, int16_t, uint16_t);
120 CASE2(
BIN, int8_t, uint8_t);
133 return precisionInfo.value == p && precisionInfo.bitsSize == p.precisionInfo.bitsSize &&
139 return precisionInfo.value == p;
144 return precisionInfo.value != p;
154 explicit operator bool() const noexcept {
165 return precisionInfo.value;
173 return precisionInfo.value;
177 const char*
name() const noexcept {
178 return precisionInfo.name;
183 static std::unordered_map<std::string, ePrecision> names = {
184 #define PRECISION_NAME(s) {#s, s} 185 PRECISION_NAME(
Q78), PRECISION_NAME(
U8), PRECISION_NAME(
I8), PRECISION_NAME(
I16),
186 PRECISION_NAME(
I32), PRECISION_NAME(
I64), PRECISION_NAME(
U64), PRECISION_NAME(
U16),
187 PRECISION_NAME(
FP32), PRECISION_NAME(
FP16), PRECISION_NAME(
MIXED), PRECISION_NAME(
BIN),
188 PRECISION_NAME(
BOOL), PRECISION_NAME(
BF16),
189 #undef PRECISION_NAME 191 auto i = names.find(str);
200 if (precisionInfo.bitsSize == 0) {
201 THROW_IE_EXCEPTION <<
" cannot estimate element if precision is " << precisionInfo.name;
203 return precisionInfo.bitsSize >> 3;
211 return precisionInfo.isFloat;
234 template <Precision::ePrecision precision>
245 if (l == r)
return true;
247 if (l ==
nullptr || r ==
nullptr)
return false;
249 for (; *l && *r; l++, r++) {
250 if (*l != *r)
return false;
261 return makePrecisionInfo<x>(#x); 278 return makePrecisionInfo<UNSPECIFIED>(
"UNSPECIFIED");
287 template <Precision::ePrecision p>
293 using value_type = float;
298 using value_type = int16_t;
302 using value_type = int16_t;
306 using value_type = uint16_t;
310 using value_type = int16_t;
314 using value_type = uint16_t;
318 using value_type = uint8_t;
322 using value_type = int8_t;
326 using value_type = uint8_t;
330 using value_type = int32_t;
334 using value_type = int64_t;
338 using value_type = uint64_t;
342 using value_type = int8_t;
346 inline uint8_t type_size_or_zero() {
352 using value_type = void;
359 inline uint8_t type_size_or_zero<void>() {
363 template <Precision::ePrecision T>
364 inline typename std::enable_if<std::is_same<std::integral_constant<Precision::ePrecision, Precision::FP16>,
365 std::integral_constant<Precision::ePrecision, T>>::value,
371 template <Precision::ePrecision T>
372 inline typename std::enable_if<!std::is_same<std::integral_constant<Precision::ePrecision, Precision::FP16>,
373 std::integral_constant<Precision::ePrecision, T>>::value,
376 return std::is_floating_point<typename PrecisionTrait<T>::value_type>::value;
379 template <Precision::ePrecision precision>
381 Precision::PrecisionInfo info;
385 info.bitsSize = nBits * type_size_or_zero<typename PrecisionTrait<precision>::value_type>();
386 info.isFloat = is_floating<precision>();
392 return out << p.
name();
399 inline std::ostream& operator<<(std::ostream& os, const std::vector<Precision>& values) {
401 for (
size_t i = 0; i < values.size(); ++i) {
403 if (i != (values.size() - 1ul)) {
411 inline constexpr uint32_t getPrecisionMask(
415 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:35
Definition: ie_precision.hpp:28
ePrecision
Definition: ie_precision.hpp:25
Particular precision traits.
Definition: ie_precision.hpp:288
static Precision fromType(const char *typeName=nullptr)
Creates custom precision with specific underlined type.
Definition: ie_precision.hpp:87
Definition: cldnn_config.hpp:16
static PrecisionInfo getPrecisionInfo(ePrecision v)
Return PrecisionInfo.
Definition: ie_precision.hpp:258
Definition: ie_precision.hpp:34
bool operator!() const noexcept
Logical negation operator.
Definition: ie_precision.hpp:159
Precision & operator=(const ePrecision p) noexcept
Assignment operator with ePrecision enum value.
Definition: ie_precision.hpp:148
Definition: ie_precision.hpp:31
size_t size() const
Returns size of single element of that precision in bits.
Definition: ie_precision.hpp:199
Definition: ie_precision.hpp:29
bool operator==(const Precision &p) const noexcept
Equality operator with Precision object.
Definition: ie_precision.hpp:132
Precision precision
Layer precision.
Definition: ie_layers.h:52
Definition: ie_precision.hpp:39
bool is_float() const noexcept
Checks if it is a floating point value.
Definition: ie_precision.hpp:210
Definition: ie_precision.hpp:41
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:182
Precision(size_t bitsSize, const char *name=nullptr)
Custom precision constructor.
Definition: ie_precision.hpp:72
Definition: ie_precision.hpp:37
bool isSigned() const noexcept
Checks if it is a signed value.
Definition: ie_precision.hpp:218
bool operator==(const ePrecision p) const noexcept
Equality operator with ePrecision enum value.
Definition: ie_precision.hpp:138
Definition: ie_precision.hpp:33
Definition: ie_precision.hpp:27
Definition: ie_precision.hpp:36
Definition: ie_precision.hpp:38
constexpr uint8_t getPrecVal() const noexcept
Gets the precision value of type ePrecision.
Definition: ie_precision.hpp:172
Definition: ie_precision.hpp:32
Precision(const Precision::ePrecision value)
Constructor with specified precision.
Definition: ie_precision.hpp:62
Definition: ie_precision.hpp:40
bool operator!=(const ePrecision p) const noexcept
Inequality operator with ePrecision enum value.
Definition: ie_precision.hpp:143
static bool areSameStrings(const char *l, const char *r) noexcept
Compare two c-strings.
Definition: ie_precision.hpp:244
Precision()=default
Default constructor.
A header file for the main Inference Engine exception.
Definition: ie_precision.hpp:30
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:93
const char * name() const noexcept
Getter of precision name.
Definition: ie_precision.hpp:177