ie_precision: added FloatTrait to fix VS2015 client compilation (#5810)
This commit is contained in:
parent
0e86b095cc
commit
84392f33d1
@ -344,72 +344,89 @@ struct PrecisionTrait {};
|
||||
template <>
|
||||
struct PrecisionTrait<Precision::FP32> {
|
||||
using value_type = float;
|
||||
enum { is_float = true };
|
||||
};
|
||||
|
||||
template <>
|
||||
struct PrecisionTrait<Precision::FP64> {
|
||||
using value_type = double;
|
||||
enum { is_float = true };
|
||||
};
|
||||
|
||||
template <>
|
||||
struct PrecisionTrait<Precision::FP16> {
|
||||
using value_type = int16_t;
|
||||
enum { is_float = true };
|
||||
};
|
||||
template <>
|
||||
struct PrecisionTrait<Precision::BF16> {
|
||||
using value_type = int16_t;
|
||||
enum { is_float = true };
|
||||
};
|
||||
template<>
|
||||
struct PrecisionTrait<Precision::Q78> {
|
||||
using value_type = uint16_t;
|
||||
enum { is_float = false };
|
||||
};
|
||||
template <>
|
||||
struct PrecisionTrait<Precision::I16> {
|
||||
using value_type = int16_t;
|
||||
enum { is_float = false };
|
||||
};
|
||||
template <>
|
||||
struct PrecisionTrait<Precision::U16> {
|
||||
using value_type = uint16_t;
|
||||
enum { is_float = false };
|
||||
};
|
||||
template <>
|
||||
struct PrecisionTrait<Precision::U4> {
|
||||
using value_type = uint8_t;
|
||||
enum { is_float = false };
|
||||
};
|
||||
template <>
|
||||
struct PrecisionTrait<Precision::U8> {
|
||||
using value_type = uint8_t;
|
||||
enum { is_float = false };
|
||||
};
|
||||
template <>
|
||||
struct PrecisionTrait<Precision::I4> {
|
||||
using value_type = int8_t;
|
||||
enum { is_float = false };
|
||||
};
|
||||
template <>
|
||||
struct PrecisionTrait<Precision::I8> {
|
||||
using value_type = int8_t;
|
||||
enum { is_float = false };
|
||||
};
|
||||
template <>
|
||||
struct PrecisionTrait<Precision::BOOL> {
|
||||
using value_type = uint8_t;
|
||||
enum { is_float = false };
|
||||
};
|
||||
template <>
|
||||
struct PrecisionTrait<Precision::I32> {
|
||||
using value_type = int32_t;
|
||||
enum { is_float = false };
|
||||
};
|
||||
template <>
|
||||
struct PrecisionTrait<Precision::U32> {
|
||||
using value_type = uint32_t;
|
||||
enum { is_float = false };
|
||||
};
|
||||
template <>
|
||||
struct PrecisionTrait<Precision::I64> {
|
||||
using value_type = int64_t;
|
||||
enum { is_float = false };
|
||||
};
|
||||
template <>
|
||||
struct PrecisionTrait<Precision::U64> {
|
||||
using value_type = uint64_t;
|
||||
enum { is_float = false };
|
||||
};
|
||||
template <>
|
||||
struct PrecisionTrait<Precision::BIN> {
|
||||
using value_type = int8_t;
|
||||
enum { is_float = false };
|
||||
};
|
||||
|
||||
template <class T>
|
||||
@ -420,6 +437,7 @@ inline uint8_t type_size_or_zero() {
|
||||
template <>
|
||||
struct PrecisionTrait<Precision::UNSPECIFIED> {
|
||||
using value_type = void;
|
||||
enum { is_float = false };
|
||||
};
|
||||
|
||||
template <>
|
||||
@ -430,24 +448,6 @@ inline uint8_t type_size_or_zero<void>() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace {
|
||||
constexpr bool isSpecificFloatPrecision(const Precision::ePrecision& precision) {
|
||||
return precision == Precision::FP16 || precision == Precision::BF16;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
template <Precision::ePrecision T>
|
||||
inline typename std::enable_if<isSpecificFloatPrecision(T), bool>::type
|
||||
is_floating() {
|
||||
return true;
|
||||
}
|
||||
|
||||
template <Precision::ePrecision T>
|
||||
inline typename std::enable_if<!isSpecificFloatPrecision(T), bool>::type
|
||||
is_floating() {
|
||||
return std::is_floating_point<typename PrecisionTrait<T>::value_type>::value;
|
||||
}
|
||||
|
||||
template <Precision::ePrecision precision>
|
||||
inline Precision::PrecisionInfo Precision::makePrecisionInfo(const char* name) {
|
||||
Precision::PrecisionInfo info;
|
||||
@ -455,7 +455,7 @@ inline Precision::PrecisionInfo Precision::makePrecisionInfo(const char* name) {
|
||||
|
||||
size_t nBits = precision == BIN ? 1 : 8;
|
||||
info.bitsSize = nBits * type_size_or_zero<typename PrecisionTrait<precision>::value_type>();
|
||||
info.isFloat = is_floating<precision>();
|
||||
info.isFloat = PrecisionTrait<precision>::is_float;
|
||||
info.value = precision;
|
||||
return info;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user