diff --git a/ngraph/core/include/ngraph/type/bfloat16.hpp b/ngraph/core/include/ngraph/type/bfloat16.hpp index 7128e8250eb478..53179cc61877d0 100644 --- a/ngraph/core/include/ngraph/type/bfloat16.hpp +++ b/ngraph/core/include/ngraph/type/bfloat16.hpp @@ -4,233 +4,8 @@ #pragma once -#include -#include -#include -#include -#include -#include - -#include "ngraph/ngraph_visibility.hpp" - -#define ROUND_MODE_TO_NEAREST_EVEN +#include "openvino/core/type/bfloat16.hpp" namespace ngraph { -class NGRAPH_API bfloat16 { -public: - constexpr bfloat16() : m_value{0} {} - bfloat16(float value) : m_value { -#if defined ROUND_MODE_TO_NEAREST - round_to_nearest(value) -#elif defined ROUND_MODE_TO_NEAREST_EVEN - round_to_nearest_even(value) -#elif defined ROUND_MODE_TRUNCATE - truncate(value) -#else -# error "ROUNDING_MODE must be one of ROUND_MODE_TO_NEAREST, ROUND_MODE_TO_NEAREST_EVEN, or ROUND_MODE_TRUNCATE" -#endif - } - {} - - template - explicit bfloat16(I value) : m_value{bfloat16{static_cast(value)}.m_value} {} - - std::string to_string() const; - size_t size() const; - template - bool operator==(const T& other) const; - template - bool operator!=(const T& other) const { - return !(*this == other); - } - template - bool operator<(const T& other) const; - template - bool operator<=(const T& other) const; - template - bool operator>(const T& other) const; - template - bool operator>=(const T& other) const; - template - bfloat16 operator+(const T& other) const; - template - bfloat16 operator+=(const T& other); - template - bfloat16 operator-(const T& other) const; - template - bfloat16 operator-=(const T& other); - template - bfloat16 operator*(const T& other) const; - template - bfloat16 operator*=(const T& other); - template - bfloat16 operator/(const T& other) const; - template - bfloat16 operator/=(const T& other); - operator float() const; - - static std::vector to_float_vector(const std::vector&); - static std::vector from_float_vector(const std::vector&); - static constexpr bfloat16 from_bits(uint16_t bits) { - return bfloat16(bits, true); - } - uint16_t to_bits() const; - friend std::ostream& operator<<(std::ostream& out, const bfloat16& obj) { - out << static_cast(obj); - return out; - } - -#define cu32(x) (F32(x).i) - - static uint16_t round_to_nearest_even(float x) { - return static_cast((cu32(x) + ((cu32(x) & 0x00010000) >> 1)) >> 16); - } - - static uint16_t round_to_nearest(float x) { - return static_cast((cu32(x) + 0x8000) >> 16); - } - - static uint16_t truncate(float x) { - return static_cast((cu32(x)) >> 16); - } - -private: - constexpr bfloat16(uint16_t x, bool) : m_value{x} {} - union F32 { - F32(float val) : f{val} {} - F32(uint32_t val) : i{val} {} - float f; - uint32_t i; - }; - - uint16_t m_value; -}; - -template -bool bfloat16::operator==(const T& other) const { -#if defined(__GNUC__) -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wfloat-equal" -#endif - return (static_cast(*this) == static_cast(other)); -#if defined(__GNUC__) -# pragma GCC diagnostic pop -#endif -} - -template -bool bfloat16::operator<(const T& other) const { - return (static_cast(*this) < static_cast(other)); -} - -template -bool bfloat16::operator<=(const T& other) const { - return (static_cast(*this) <= static_cast(other)); -} - -template -bool bfloat16::operator>(const T& other) const { - return (static_cast(*this) > static_cast(other)); -} - -template -bool bfloat16::operator>=(const T& other) const { - return (static_cast(*this) >= static_cast(other)); -} - -template -bfloat16 bfloat16::operator+(const T& other) const { - return {static_cast(*this) + static_cast(other)}; -} - -template -bfloat16 bfloat16::operator+=(const T& other) { - return *this = *this + other; -} - -template -bfloat16 bfloat16::operator-(const T& other) const { - return {static_cast(*this) - static_cast(other)}; -} - -template -bfloat16 bfloat16::operator-=(const T& other) { - return *this = *this - other; -} - -template -bfloat16 bfloat16::operator*(const T& other) const { - return {static_cast(*this) * static_cast(other)}; -} - -template -bfloat16 bfloat16::operator*=(const T& other) { - return *this = *this * other; -} - -template -bfloat16 bfloat16::operator/(const T& other) const { - return {static_cast(*this) / static_cast(other)}; -} - -template -bfloat16 bfloat16::operator/=(const T& other) { - return *this = *this / other; -} +using ov::bfloat16; } // namespace ngraph - -namespace std { -template <> -class numeric_limits { -public: - static constexpr bool is_specialized = true; - static constexpr ngraph::bfloat16 min() noexcept { - return ngraph::bfloat16::from_bits(0x007F); - } - static constexpr ngraph::bfloat16 max() noexcept { - return ngraph::bfloat16::from_bits(0x7F7F); - } - static constexpr ngraph::bfloat16 lowest() noexcept { - return ngraph::bfloat16::from_bits(0xFF7F); - } - static constexpr int digits = 7; - static constexpr int digits10 = 2; - static constexpr bool is_signed = true; - static constexpr bool is_integer = false; - static constexpr bool is_exact = false; - static constexpr int radix = 2; - static constexpr ngraph::bfloat16 epsilon() noexcept { - return ngraph::bfloat16::from_bits(0x3C00); - } - static constexpr ngraph::bfloat16 round_error() noexcept { - return ngraph::bfloat16::from_bits(0x3F00); - } - static constexpr int min_exponent = -125; - static constexpr int min_exponent10 = -37; - static constexpr int max_exponent = 128; - static constexpr int max_exponent10 = 38; - static constexpr bool has_infinity = true; - static constexpr bool has_quiet_NaN = true; - static constexpr bool has_signaling_NaN = true; - static constexpr float_denorm_style has_denorm = denorm_absent; - static constexpr bool has_denorm_loss = false; - static constexpr ngraph::bfloat16 infinity() noexcept { - return ngraph::bfloat16::from_bits(0x7F80); - } - static constexpr ngraph::bfloat16 quiet_NaN() noexcept { - return ngraph::bfloat16::from_bits(0x7FC0); - } - static constexpr ngraph::bfloat16 signaling_NaN() noexcept { - return ngraph::bfloat16::from_bits(0x7FC0); - } - static constexpr ngraph::bfloat16 denorm_min() noexcept { - return ngraph::bfloat16::from_bits(0); - } - static constexpr bool is_iec559 = false; - static constexpr bool is_bounded = false; - static constexpr bool is_modulo = false; - static constexpr bool traps = false; - static constexpr bool tinyness_before = false; - static constexpr float_round_style round_style = round_to_nearest; -}; -} // namespace std diff --git a/ngraph/core/include/ngraph/type/element_type.hpp b/ngraph/core/include/ngraph/type/element_type.hpp index 45ef3af2b80ad8..78a5dc1f13a068 100644 --- a/ngraph/core/include/ngraph/type/element_type.hpp +++ b/ngraph/core/include/ngraph/type/element_type.hpp @@ -8,194 +8,42 @@ #pragma once -#include -#include -#include -#include -#include - -#include "ngraph/attribute_adapter.hpp" -#include "ngraph/deprecated.hpp" -#include "ngraph/except.hpp" -#include "ngraph/ngraph_visibility.hpp" #include "ngraph/type/bfloat16.hpp" #include "ngraph/type/float16.hpp" +#include "openvino/core/type/element_type.hpp" namespace ngraph { namespace element { -enum class Type_t { - undefined, - dynamic, - boolean, - bf16, - f16, - f32, - f64, - i4, - i8, - i16, - i32, - i64, - u1, - u4, - u8, - u16, - u32, - u64 -}; - -class NGRAPH_API Type { -public: - Type() : m_type{element::Type_t::undefined} {} - Type(const Type&) = default; - constexpr Type(const Type_t t) : m_type{t} {} - Type(size_t bitwidth, bool is_real, bool is_signed, bool is_quantized, const std::string& cname); - Type& operator=(const Type&) = default; - const std::string& c_type_string() const; - size_t size() const; - size_t hash() const; - bool is_static() const; - bool is_dynamic() const { - return !is_static(); - } - bool is_real() const; - // TODO: We may want to revisit this definition when we do a more general cleanup of - // element types: - bool is_integral() const { - return !is_real(); - } - bool is_integral_number() const; - bool is_signed() const; - bool is_quantized() const; - size_t bitwidth() const; - // The name of this type, the enum name of this type - const std::string& get_type_name() const; - friend NGRAPH_API std::ostream& operator<<(std::ostream&, const Type&); - static std::vector get_known_types(); - - /// \brief Checks whether this element type is merge-compatible with `t`. - /// \param t The element type to compare this element type to. - /// \return `true` if this element type is compatible with `t`, else `false`. - bool compatible(const element::Type& t) const; - - /// \brief Merges two element types t1 and t2, writing the result into dst and - /// returning true if successful, else returning false. - /// - /// To "merge" two element types t1 and t2 is to find the least restrictive - /// element type t that is no more restrictive than t1 and t2, if t exists. - /// More simply: - /// - /// merge(dst,element::Type::dynamic,t) - /// writes t to dst and returns true - /// - /// merge(dst,t,element::Type::dynamic) - /// writes t to dst and returns true - /// - /// merge(dst,t1,t2) where t1, t2 both static and equal - /// writes t1 to dst and returns true - /// - /// merge(dst,t1,t2) where t1, t2 both static and unequal - /// does nothing to dst, and returns false - static bool merge(element::Type& dst, const element::Type& t1, const element::Type& t2); - - // \brief This allows switch(element_type) - constexpr operator Type_t() const { - return m_type; - } - -private: - Type_t m_type{Type_t::undefined}; -}; - -typedef std::vector TypeVector; - -constexpr Type undefined(Type_t::undefined); -constexpr Type dynamic(Type_t::dynamic); -constexpr Type boolean(Type_t::boolean); -constexpr Type bf16(Type_t::bf16); -constexpr Type f16(Type_t::f16); -constexpr Type f32(Type_t::f32); -constexpr Type f64(Type_t::f64); -constexpr Type i4(Type_t::i4); -constexpr Type i8(Type_t::i8); -constexpr Type i16(Type_t::i16); -constexpr Type i32(Type_t::i32); -constexpr Type i64(Type_t::i64); -constexpr Type u1(Type_t::u1); -constexpr Type u4(Type_t::u4); -constexpr Type u8(Type_t::u8); -constexpr Type u16(Type_t::u16); -constexpr Type u32(Type_t::u32); -constexpr Type u64(Type_t::u64); +using ov::element::Type; +using ov::element::Type_t; +using TypeVector = std::vector; + +using ov::element::bf16; +using ov::element::boolean; +using ov::element::dynamic; +using ov::element::f16; +using ov::element::f32; +using ov::element::f64; +using ov::element::i16; +using ov::element::i32; +using ov::element::i4; +using ov::element::i64; +using ov::element::i8; +using ov::element::u1; +using ov::element::u16; +using ov::element::u32; +using ov::element::u4; +using ov::element::u64; +using ov::element::u8; +using ov::element::undefined; template Type from() { - throw std::invalid_argument("Unknown type"); + return ov::element::from(); } -template <> -NGRAPH_API Type from(); -template <> -NGRAPH_API Type from(); -template <> -NGRAPH_API Type from(); -template <> -NGRAPH_API Type from(); -template <> -NGRAPH_API Type from(); -template <> -NGRAPH_API Type from(); -template <> -NGRAPH_API Type from(); -template <> -NGRAPH_API Type from(); -template <> -NGRAPH_API Type from(); -template <> -NGRAPH_API Type from(); -template <> -NGRAPH_API Type from(); -template <> -NGRAPH_API Type from(); -template <> -NGRAPH_API Type from(); -template <> -NGRAPH_API Type from(); - -NGRAPH_API -std::ostream& operator<<(std::ostream& out, const ngraph::element::Type& obj); } // namespace element -template <> -class NGRAPH_API AttributeAdapter : public EnumAttributeAdapterBase { -public: - AttributeAdapter(element::Type_t& value) : EnumAttributeAdapterBase(value) {} - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } -}; - -template <> -class NGRAPH_API AttributeAdapter : public ValueAccessor { -public: - AttributeAdapter(element::Type& value) : m_ref(value) {} - - const std::string& get() override; - void set(const std::string& value) override; - - static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; - const DiscreteTypeInfo& get_type_info() const override { - return type_info; - } - operator element::Type&() { - return m_ref; - } - -protected: - element::Type& m_ref; -}; - /// \brief Return the number of bytes in the compile-time representation of the element type. +NGRAPH_DEPRECATED("This method is deprecated and will be removed soon") size_t compiler_byte_size(element::Type_t et); } // namespace ngraph diff --git a/ngraph/core/include/ngraph/type/element_type_traits.hpp b/ngraph/core/include/ngraph/type/element_type_traits.hpp index 6d37c3776f0acc..abbf9551809e3b 100644 --- a/ngraph/core/include/ngraph/type/element_type_traits.hpp +++ b/ngraph/core/include/ngraph/type/element_type_traits.hpp @@ -4,92 +4,11 @@ #pragma once -#include "ngraph/type/element_type.hpp" +#include "openvino/core/type/element_type_traits.hpp" namespace ngraph { -template -struct element_type_traits {}; +using ov::element_type_traits; -template -using fundamental_type_for = typename element_type_traits::value_type; +using ov::fundamental_type_for; -template <> -struct element_type_traits { - using value_type = char; -}; - -template <> -struct element_type_traits { - using value_type = bfloat16; -}; - -template <> -struct element_type_traits { - using value_type = float16; -}; - -template <> -struct element_type_traits { - using value_type = float; -}; - -template <> -struct element_type_traits { - using value_type = double; -}; - -template <> -struct element_type_traits { - using value_type = int8_t; -}; - -template <> -struct element_type_traits { - using value_type = int8_t; -}; - -template <> -struct element_type_traits { - using value_type = int16_t; -}; - -template <> -struct element_type_traits { - using value_type = int32_t; -}; - -template <> -struct element_type_traits { - using value_type = int64_t; -}; - -template <> -struct element_type_traits { - using value_type = int8_t; -}; - -template <> -struct element_type_traits { - using value_type = int8_t; -}; - -template <> -struct element_type_traits { - using value_type = uint8_t; -}; - -template <> -struct element_type_traits { - using value_type = uint16_t; -}; - -template <> -struct element_type_traits { - using value_type = uint32_t; -}; - -template <> -struct element_type_traits { - using value_type = uint64_t; -}; } // namespace ngraph diff --git a/ngraph/core/include/ngraph/type/float16.hpp b/ngraph/core/include/ngraph/type/float16.hpp index 6a7bdf62dbb210..64418d426a5fea 100644 --- a/ngraph/core/include/ngraph/type/float16.hpp +++ b/ngraph/core/include/ngraph/type/float16.hpp @@ -4,216 +4,8 @@ #pragma once -#include -#include -#include -#include -#include -#include - -#include "ngraph/ngraph_visibility.hpp" - -#define ROUND_MODE_TO_NEAREST_EVEN +#include "openvino/core/type/float16.hpp" namespace ngraph { -class NGRAPH_API float16 { -public: - constexpr float16() : m_value{0} {} - - static uint32_t constexpr frac_size = 10; - static uint32_t constexpr exp_size = 5; - static uint32_t constexpr exp_bias = 15; - - float16(uint32_t sign, uint32_t biased_exponent, uint32_t fraction) - : m_value((sign & 0x01) << 15 | (biased_exponent & 0x1F) << 10 | (fraction & 0x03FF)) {} - - float16(float value); - - template - explicit float16(I value) : m_value{float16{static_cast(value)}.m_value} {} - - std::string to_string() const; - size_t size() const; - template - bool operator==(const T& other) const; - template - bool operator!=(const T& other) const { - return !(*this == other); - } - template - bool operator<(const T& other) const; - template - bool operator<=(const T& other) const; - template - bool operator>(const T& other) const; - template - bool operator>=(const T& other) const; - template - float16 operator+(const T& other) const; - template - float16 operator+=(const T& other); - template - float16 operator-(const T& other) const; - template - float16 operator-=(const T& other); - template - float16 operator*(const T& other) const; - template - float16 operator*=(const T& other); - template - float16 operator/(const T& other) const; - template - float16 operator/=(const T& other); - operator float() const; - - static constexpr float16 from_bits(uint16_t bits) { - return float16(bits, true); - } - uint16_t to_bits() const; - friend std::ostream& operator<<(std::ostream& out, const float16& obj) { - out << static_cast(obj); - return out; - } - -private: - constexpr float16(uint16_t x, bool) : m_value{x} {} - union F32 { - F32(float val) : f{val} {} - F32(uint32_t val) : i{val} {} - float f; - uint32_t i; - }; - - uint16_t m_value; -}; - -template -bool float16::operator==(const T& other) const { -#if defined(__GNUC__) -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wfloat-equal" -#endif - return (static_cast(*this) == static_cast(other)); -#if defined(__GNUC__) -# pragma GCC diagnostic pop -#endif -} - -template -bool float16::operator<(const T& other) const { - return (static_cast(*this) < static_cast(other)); -} - -template -bool float16::operator<=(const T& other) const { - return (static_cast(*this) <= static_cast(other)); -} - -template -bool float16::operator>(const T& other) const { - return (static_cast(*this) > static_cast(other)); -} - -template -bool float16::operator>=(const T& other) const { - return (static_cast(*this) >= static_cast(other)); -} - -template -float16 float16::operator+(const T& other) const { - return {static_cast(*this) + static_cast(other)}; -} - -template -float16 float16::operator+=(const T& other) { - return *this = *this + other; -} - -template -float16 float16::operator-(const T& other) const { - return {static_cast(*this) - static_cast(other)}; -} - -template -float16 float16::operator-=(const T& other) { - return *this = *this - other; -} - -template -float16 float16::operator*(const T& other) const { - return {static_cast(*this) * static_cast(other)}; -} - -template -float16 float16::operator*=(const T& other) { - return *this = *this * other; -} - -template -float16 float16::operator/(const T& other) const { - return {static_cast(*this) / static_cast(other)}; -} - -template -float16 float16::operator/=(const T& other) { - return *this = *this / other; -} +using ov::float16; } // namespace ngraph - -namespace std { -bool NGRAPH_API isnan(ngraph::float16 x); - -template <> -class numeric_limits { -public: - static constexpr bool is_specialized = true; - static constexpr ngraph::float16 min() noexcept { - return ngraph::float16::from_bits(0x0200); - } - static constexpr ngraph::float16 max() noexcept { - return ngraph::float16::from_bits(0x7BFF); - } - static constexpr ngraph::float16 lowest() noexcept { - return ngraph::float16::from_bits(0xFBFF); - } - static constexpr int digits = 11; - static constexpr int digits10 = 3; - static constexpr bool is_signed = true; - static constexpr bool is_integer = false; - static constexpr bool is_exact = false; - static constexpr int radix = 2; - static constexpr ngraph::float16 epsilon() noexcept { - return ngraph::float16::from_bits(0x1200); - } - static constexpr ngraph::float16 round_error() noexcept { - return ngraph::float16::from_bits(0x3C00); - } - static constexpr int min_exponent = -13; - static constexpr int min_exponent10 = -4; - static constexpr int max_exponent = 16; - static constexpr int max_exponent10 = 4; - static constexpr bool has_infinity = true; - static constexpr bool has_quiet_NaN = true; - static constexpr bool has_signaling_NaN = true; - static constexpr float_denorm_style has_denorm = denorm_absent; - static constexpr bool has_denorm_loss = false; - static constexpr ngraph::float16 infinity() noexcept { - return ngraph::float16::from_bits(0x7C00); - } - static constexpr ngraph::float16 quiet_NaN() noexcept { - return ngraph::float16::from_bits(0x7FFF); - } - static constexpr ngraph::float16 signaling_NaN() noexcept { - return ngraph::float16::from_bits(0x7DFF); - } - static constexpr ngraph::float16 denorm_min() noexcept { - return ngraph::float16::from_bits(0); - } - static constexpr bool is_iec559 = false; - static constexpr bool is_bounded = false; - static constexpr bool is_modulo = false; - static constexpr bool traps = false; - static constexpr bool tinyness_before = false; - static constexpr float_round_style round_style = round_to_nearest; -}; -} // namespace std diff --git a/ngraph/core/include/openvino/core/type/bfloat16.hpp b/ngraph/core/include/openvino/core/type/bfloat16.hpp new file mode 100644 index 00000000000000..4d7e2cd9570fe7 --- /dev/null +++ b/ngraph/core/include/openvino/core/type/bfloat16.hpp @@ -0,0 +1,236 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include +#include +#include +#include + +#include "openvino/core/core_visibility.hpp" + +#define ROUND_MODE_TO_NEAREST_EVEN + +namespace ov { +class OPENVINO_API bfloat16 { +public: + constexpr bfloat16() : m_value{0} {} + bfloat16(float value) : m_value { +#if defined ROUND_MODE_TO_NEAREST + round_to_nearest(value) +#elif defined ROUND_MODE_TO_NEAREST_EVEN + round_to_nearest_even(value) +#elif defined ROUND_MODE_TRUNCATE + truncate(value) +#else +# error "ROUNDING_MODE must be one of ROUND_MODE_TO_NEAREST, ROUND_MODE_TO_NEAREST_EVEN, or ROUND_MODE_TRUNCATE" +#endif + } + {} + + template + explicit bfloat16(I value) : m_value{bfloat16{static_cast(value)}.m_value} {} + + std::string to_string() const; + size_t size() const; + template + bool operator==(const T& other) const; + template + bool operator!=(const T& other) const { + return !(*this == other); + } + template + bool operator<(const T& other) const; + template + bool operator<=(const T& other) const; + template + bool operator>(const T& other) const; + template + bool operator>=(const T& other) const; + template + bfloat16 operator+(const T& other) const; + template + bfloat16 operator+=(const T& other); + template + bfloat16 operator-(const T& other) const; + template + bfloat16 operator-=(const T& other); + template + bfloat16 operator*(const T& other) const; + template + bfloat16 operator*=(const T& other); + template + bfloat16 operator/(const T& other) const; + template + bfloat16 operator/=(const T& other); + operator float() const; + + static std::vector to_float_vector(const std::vector&); + static std::vector from_float_vector(const std::vector&); + static constexpr bfloat16 from_bits(uint16_t bits) { + return bfloat16(bits, true); + } + uint16_t to_bits() const; + friend std::ostream& operator<<(std::ostream& out, const bfloat16& obj) { + out << static_cast(obj); + return out; + } + +#define cu32(x) (F32(x).i) + + static uint16_t round_to_nearest_even(float x) { + return static_cast((cu32(x) + ((cu32(x) & 0x00010000) >> 1)) >> 16); + } + + static uint16_t round_to_nearest(float x) { + return static_cast((cu32(x) + 0x8000) >> 16); + } + + static uint16_t truncate(float x) { + return static_cast((cu32(x)) >> 16); + } + +private: + constexpr bfloat16(uint16_t x, bool) : m_value{x} {} + union F32 { + F32(float val) : f{val} {} + F32(uint32_t val) : i{val} {} + float f; + uint32_t i; + }; + + uint16_t m_value; +}; + +template +bool bfloat16::operator==(const T& other) const { +#if defined(__GNUC__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wfloat-equal" +#endif + return (static_cast(*this) == static_cast(other)); +#if defined(__GNUC__) +# pragma GCC diagnostic pop +#endif +} + +template +bool bfloat16::operator<(const T& other) const { + return (static_cast(*this) < static_cast(other)); +} + +template +bool bfloat16::operator<=(const T& other) const { + return (static_cast(*this) <= static_cast(other)); +} + +template +bool bfloat16::operator>(const T& other) const { + return (static_cast(*this) > static_cast(other)); +} + +template +bool bfloat16::operator>=(const T& other) const { + return (static_cast(*this) >= static_cast(other)); +} + +template +bfloat16 bfloat16::operator+(const T& other) const { + return {static_cast(*this) + static_cast(other)}; +} + +template +bfloat16 bfloat16::operator+=(const T& other) { + return *this = *this + other; +} + +template +bfloat16 bfloat16::operator-(const T& other) const { + return {static_cast(*this) - static_cast(other)}; +} + +template +bfloat16 bfloat16::operator-=(const T& other) { + return *this = *this - other; +} + +template +bfloat16 bfloat16::operator*(const T& other) const { + return {static_cast(*this) * static_cast(other)}; +} + +template +bfloat16 bfloat16::operator*=(const T& other) { + return *this = *this * other; +} + +template +bfloat16 bfloat16::operator/(const T& other) const { + return {static_cast(*this) / static_cast(other)}; +} + +template +bfloat16 bfloat16::operator/=(const T& other) { + return *this = *this / other; +} +} // namespace ov + +namespace std { +template <> +class numeric_limits { +public: + static constexpr bool is_specialized = true; + static constexpr ov::bfloat16 min() noexcept { + return ov::bfloat16::from_bits(0x007F); + } + static constexpr ov::bfloat16 max() noexcept { + return ov::bfloat16::from_bits(0x7F7F); + } + static constexpr ov::bfloat16 lowest() noexcept { + return ov::bfloat16::from_bits(0xFF7F); + } + static constexpr int digits = 7; + static constexpr int digits10 = 2; + static constexpr bool is_signed = true; + static constexpr bool is_integer = false; + static constexpr bool is_exact = false; + static constexpr int radix = 2; + static constexpr ov::bfloat16 epsilon() noexcept { + return ov::bfloat16::from_bits(0x3C00); + } + static constexpr ov::bfloat16 round_error() noexcept { + return ov::bfloat16::from_bits(0x3F00); + } + static constexpr int min_exponent = -125; + static constexpr int min_exponent10 = -37; + static constexpr int max_exponent = 128; + static constexpr int max_exponent10 = 38; + static constexpr bool has_infinity = true; + static constexpr bool has_quiet_NaN = true; + static constexpr bool has_signaling_NaN = true; + static constexpr float_denorm_style has_denorm = denorm_absent; + static constexpr bool has_denorm_loss = false; + static constexpr ov::bfloat16 infinity() noexcept { + return ov::bfloat16::from_bits(0x7F80); + } + static constexpr ov::bfloat16 quiet_NaN() noexcept { + return ov::bfloat16::from_bits(0x7FC0); + } + static constexpr ov::bfloat16 signaling_NaN() noexcept { + return ov::bfloat16::from_bits(0x7FC0); + } + static constexpr ov::bfloat16 denorm_min() noexcept { + return ov::bfloat16::from_bits(0); + } + static constexpr bool is_iec559 = false; + static constexpr bool is_bounded = false; + static constexpr bool is_modulo = false; + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_to_nearest; +}; +} // namespace std diff --git a/ngraph/core/include/openvino/core/type/element_type.hpp b/ngraph/core/include/openvino/core/type/element_type.hpp new file mode 100644 index 00000000000000..b3ccc0e02199be --- /dev/null +++ b/ngraph/core/include/openvino/core/type/element_type.hpp @@ -0,0 +1,202 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +//================================================================================================ +// ElementType +//================================================================================================ + +#pragma once + +#include +#include +#include +#include +#include + +#include "ngraph/attribute_adapter.hpp" +#include "ngraph/deprecated.hpp" +#include "ngraph/except.hpp" +#include "openvino/core/core_visibility.hpp" +#include "openvino/core/type/bfloat16.hpp" +#include "openvino/core/type/float16.hpp" + +namespace ov { +namespace element { +enum class Type_t { + undefined, + dynamic, + boolean, + bf16, + f16, + f32, + f64, + i4, + i8, + i16, + i32, + i64, + u1, + u4, + u8, + u16, + u32, + u64 +}; + +class OPENVINO_API Type { +public: + Type() = default; + Type(const Type&) = default; + constexpr Type(const Type_t t) : m_type{t} {} + Type(size_t bitwidth, bool is_real, bool is_signed, bool is_quantized, const std::string& cname); + Type& operator=(const Type&) = default; + const std::string& c_type_string() const; + size_t size() const; + size_t hash() const; + bool is_static() const; + bool is_dynamic() const { + return !is_static(); + } + bool is_real() const; + // TODO: We may want to revisit this definition when we do a more general cleanup of + // element types: + bool is_integral() const { + return !is_real(); + } + bool is_integral_number() const; + bool is_signed() const; + bool is_quantized() const; + size_t bitwidth() const; + // The name of this type, the enum name of this type + const std::string& get_type_name() const; + friend OPENVINO_API std::ostream& operator<<(std::ostream&, const Type&); + static std::vector get_known_types(); + + /// \brief Checks whether this element type is merge-compatible with `t`. + /// \param t The element type to compare this element type to. + /// \return `true` if this element type is compatible with `t`, else `false`. + bool compatible(const element::Type& t) const; + + /// \brief Merges two element types t1 and t2, writing the result into dst and + /// returning true if successful, else returning false. + /// + /// To "merge" two element types t1 and t2 is to find the least restrictive + /// element type t that is no more restrictive than t1 and t2, if t exists. + /// More simply: + /// + /// merge(dst,element::Type::dynamic,t) + /// writes t to dst and returns true + /// + /// merge(dst,t,element::Type::dynamic) + /// writes t to dst and returns true + /// + /// merge(dst,t1,t2) where t1, t2 both static and equal + /// writes t1 to dst and returns true + /// + /// merge(dst,t1,t2) where t1, t2 both static and unequal + /// does nothing to dst, and returns false + static bool merge(element::Type& dst, const element::Type& t1, const element::Type& t2); + + // \brief This allows switch(element_type) + constexpr operator Type_t() const { + return m_type; + } + +private: + Type_t m_type{Type_t::undefined}; +}; + +using TypeVector = std::vector; + +constexpr Type undefined(Type_t::undefined); +constexpr Type dynamic(Type_t::dynamic); +constexpr Type boolean(Type_t::boolean); +constexpr Type bf16(Type_t::bf16); +constexpr Type f16(Type_t::f16); +constexpr Type f32(Type_t::f32); +constexpr Type f64(Type_t::f64); +constexpr Type i4(Type_t::i4); +constexpr Type i8(Type_t::i8); +constexpr Type i16(Type_t::i16); +constexpr Type i32(Type_t::i32); +constexpr Type i64(Type_t::i64); +constexpr Type u1(Type_t::u1); +constexpr Type u4(Type_t::u4); +constexpr Type u8(Type_t::u8); +constexpr Type u16(Type_t::u16); +constexpr Type u32(Type_t::u32); +constexpr Type u64(Type_t::u64); + +template +Type from() { + throw std::invalid_argument("Unknown type"); +} +template <> +OPENVINO_API Type from(); +template <> +OPENVINO_API Type from(); +template <> +OPENVINO_API Type from(); +template <> +OPENVINO_API Type from(); +template <> +OPENVINO_API Type from(); +template <> +OPENVINO_API Type from(); +template <> +OPENVINO_API Type from(); +template <> +OPENVINO_API Type from(); +template <> +OPENVINO_API Type from(); +template <> +OPENVINO_API Type from(); +template <> +OPENVINO_API Type from(); +template <> +OPENVINO_API Type from(); +template <> +OPENVINO_API Type from(); +template <> +OPENVINO_API Type from(); + +OPENVINO_API +std::ostream& operator<<(std::ostream& out, const ov::element::Type& obj); +} // namespace element + +} // namespace ov + +namespace ngraph { + +template <> +class OPENVINO_API AttributeAdapter : public EnumAttributeAdapterBase { +public: + AttributeAdapter(ov::element::Type_t& value) : EnumAttributeAdapterBase(value) {} + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } +}; + +template <> +class OPENVINO_API AttributeAdapter : public ValueAccessor { +public: + AttributeAdapter(ov::element::Type& value) : m_ref(value) {} + + const std::string& get() override; + void set(const std::string& value) override; + + static constexpr DiscreteTypeInfo type_info{"AttributeAdapter", 0}; + const DiscreteTypeInfo& get_type_info() const override { + return type_info; + } + operator ov::element::Type&() { + return m_ref; + } + +protected: + ov::element::Type& m_ref; +}; +} // namespace ngraph diff --git a/ngraph/core/include/openvino/core/type/element_type_traits.hpp b/ngraph/core/include/openvino/core/type/element_type_traits.hpp new file mode 100644 index 00000000000000..07d4230ddbccef --- /dev/null +++ b/ngraph/core/include/openvino/core/type/element_type_traits.hpp @@ -0,0 +1,95 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "openvino/core/type/element_type.hpp" + +namespace ov { +template +struct element_type_traits {}; + +template +using fundamental_type_for = typename element_type_traits::value_type; + +template <> +struct element_type_traits { + using value_type = char; +}; + +template <> +struct element_type_traits { + using value_type = bfloat16; +}; + +template <> +struct element_type_traits { + using value_type = float16; +}; + +template <> +struct element_type_traits { + using value_type = float; +}; + +template <> +struct element_type_traits { + using value_type = double; +}; + +template <> +struct element_type_traits { + using value_type = int8_t; +}; + +template <> +struct element_type_traits { + using value_type = int8_t; +}; + +template <> +struct element_type_traits { + using value_type = int16_t; +}; + +template <> +struct element_type_traits { + using value_type = int32_t; +}; + +template <> +struct element_type_traits { + using value_type = int64_t; +}; + +template <> +struct element_type_traits { + using value_type = int8_t; +}; + +template <> +struct element_type_traits { + using value_type = int8_t; +}; + +template <> +struct element_type_traits { + using value_type = uint8_t; +}; + +template <> +struct element_type_traits { + using value_type = uint16_t; +}; + +template <> +struct element_type_traits { + using value_type = uint32_t; +}; + +template <> +struct element_type_traits { + using value_type = uint64_t; +}; +} // namespace ov diff --git a/ngraph/core/include/openvino/core/type/float16.hpp b/ngraph/core/include/openvino/core/type/float16.hpp new file mode 100644 index 00000000000000..60c1560c24a254 --- /dev/null +++ b/ngraph/core/include/openvino/core/type/float16.hpp @@ -0,0 +1,219 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include +#include +#include +#include + +#include "openvino/core/core_visibility.hpp" + +#define ROUND_MODE_TO_NEAREST_EVEN + +namespace ov { +class OPENVINO_API float16 { +public: + constexpr float16() : m_value{0} {} + + static uint32_t constexpr frac_size = 10; + static uint32_t constexpr exp_size = 5; + static uint32_t constexpr exp_bias = 15; + + float16(uint32_t sign, uint32_t biased_exponent, uint32_t fraction) + : m_value((sign & 0x01) << 15 | (biased_exponent & 0x1F) << 10 | (fraction & 0x03FF)) {} + + float16(float value); + + template + explicit float16(I value) : m_value{float16{static_cast(value)}.m_value} {} + + std::string to_string() const; + size_t size() const; + template + bool operator==(const T& other) const; + template + bool operator!=(const T& other) const { + return !(*this == other); + } + template + bool operator<(const T& other) const; + template + bool operator<=(const T& other) const; + template + bool operator>(const T& other) const; + template + bool operator>=(const T& other) const; + template + float16 operator+(const T& other) const; + template + float16 operator+=(const T& other); + template + float16 operator-(const T& other) const; + template + float16 operator-=(const T& other); + template + float16 operator*(const T& other) const; + template + float16 operator*=(const T& other); + template + float16 operator/(const T& other) const; + template + float16 operator/=(const T& other); + operator float() const; + + static constexpr float16 from_bits(uint16_t bits) { + return float16(bits, true); + } + uint16_t to_bits() const; + friend std::ostream& operator<<(std::ostream& out, const float16& obj) { + out << static_cast(obj); + return out; + } + +private: + constexpr float16(uint16_t x, bool) : m_value{x} {} + union F32 { + F32(float val) : f{val} {} + F32(uint32_t val) : i{val} {} + float f; + uint32_t i; + }; + + uint16_t m_value; +}; + +template +bool float16::operator==(const T& other) const { +#if defined(__GNUC__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wfloat-equal" +#endif + return (static_cast(*this) == static_cast(other)); +#if defined(__GNUC__) +# pragma GCC diagnostic pop +#endif +} + +template +bool float16::operator<(const T& other) const { + return (static_cast(*this) < static_cast(other)); +} + +template +bool float16::operator<=(const T& other) const { + return (static_cast(*this) <= static_cast(other)); +} + +template +bool float16::operator>(const T& other) const { + return (static_cast(*this) > static_cast(other)); +} + +template +bool float16::operator>=(const T& other) const { + return (static_cast(*this) >= static_cast(other)); +} + +template +float16 float16::operator+(const T& other) const { + return {static_cast(*this) + static_cast(other)}; +} + +template +float16 float16::operator+=(const T& other) { + return *this = *this + other; +} + +template +float16 float16::operator-(const T& other) const { + return {static_cast(*this) - static_cast(other)}; +} + +template +float16 float16::operator-=(const T& other) { + return *this = *this - other; +} + +template +float16 float16::operator*(const T& other) const { + return {static_cast(*this) * static_cast(other)}; +} + +template +float16 float16::operator*=(const T& other) { + return *this = *this * other; +} + +template +float16 float16::operator/(const T& other) const { + return {static_cast(*this) / static_cast(other)}; +} + +template +float16 float16::operator/=(const T& other) { + return *this = *this / other; +} +} // namespace ov + +namespace std { +bool OPENVINO_API isnan(ov::float16 x); + +template <> +class numeric_limits { +public: + static constexpr bool is_specialized = true; + static constexpr ov::float16 min() noexcept { + return ov::float16::from_bits(0x0200); + } + static constexpr ov::float16 max() noexcept { + return ov::float16::from_bits(0x7BFF); + } + static constexpr ov::float16 lowest() noexcept { + return ov::float16::from_bits(0xFBFF); + } + static constexpr int digits = 11; + static constexpr int digits10 = 3; + static constexpr bool is_signed = true; + static constexpr bool is_integer = false; + static constexpr bool is_exact = false; + static constexpr int radix = 2; + static constexpr ov::float16 epsilon() noexcept { + return ov::float16::from_bits(0x1200); + } + static constexpr ov::float16 round_error() noexcept { + return ov::float16::from_bits(0x3C00); + } + static constexpr int min_exponent = -13; + static constexpr int min_exponent10 = -4; + static constexpr int max_exponent = 16; + static constexpr int max_exponent10 = 4; + static constexpr bool has_infinity = true; + static constexpr bool has_quiet_NaN = true; + static constexpr bool has_signaling_NaN = true; + static constexpr float_denorm_style has_denorm = denorm_absent; + static constexpr bool has_denorm_loss = false; + static constexpr ov::float16 infinity() noexcept { + return ov::float16::from_bits(0x7C00); + } + static constexpr ov::float16 quiet_NaN() noexcept { + return ov::float16::from_bits(0x7FFF); + } + static constexpr ov::float16 signaling_NaN() noexcept { + return ov::float16::from_bits(0x7DFF); + } + static constexpr ov::float16 denorm_min() noexcept { + return ov::float16::from_bits(0); + } + static constexpr bool is_iec559 = false; + static constexpr bool is_bounded = false; + static constexpr bool is_modulo = false; + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_to_nearest; +}; +} // namespace std diff --git a/ngraph/core/src/type/element_type.cpp b/ngraph/core/src/type/element_type.cpp index 247928dfafdc58..cc5042a81d6f34 100644 --- a/ngraph/core/src/type/element_type.cpp +++ b/ngraph/core/src/type/element_type.cpp @@ -12,9 +12,8 @@ #include "ngraph/log.hpp" #include "ngraph/type/element_type_traits.hpp" -using namespace ngraph; +constexpr ngraph::DiscreteTypeInfo ngraph::AttributeAdapter::type_info; -constexpr DiscreteTypeInfo AttributeAdapter::type_info; namespace { class TypeInfo { public: @@ -40,73 +39,77 @@ class TypeInfo { struct ElementTypes { struct TypeHash { - size_t operator()(element::Type_t t) const { + size_t operator()(ov::element::Type_t t) const { return static_cast(t); } }; - using ElementsMap = std::unordered_map; + using ElementsMap = std::unordered_map; static const ElementsMap elements_map; }; const ElementTypes::ElementsMap ElementTypes::elements_map{ - {element::Type_t::undefined, + {ov::element::Type_t::undefined, TypeInfo(std::numeric_limits::max(), false, false, false, "undefined", "undefined")}, - {element::Type_t::dynamic, TypeInfo(0, false, false, false, "dynamic", "dynamic")}, - {element::Type_t::boolean, TypeInfo(8, false, true, false, "char", "boolean")}, - {element::Type_t::bf16, TypeInfo(16, true, true, false, "bfloat16", "bf16")}, - {element::Type_t::f16, TypeInfo(16, true, true, false, "float16", "f16")}, - {element::Type_t::f32, TypeInfo(32, true, true, false, "float", "f32")}, - {element::Type_t::f64, TypeInfo(64, true, true, false, "double", "f64")}, - {element::Type_t::i4, TypeInfo(4, false, true, true, "int4_t", "i4")}, - {element::Type_t::i8, TypeInfo(8, false, true, true, "int8_t", "i8")}, - {element::Type_t::i16, TypeInfo(16, false, true, false, "int16_t", "i16")}, - {element::Type_t::i32, TypeInfo(32, false, true, true, "int32_t", "i32")}, - {element::Type_t::i64, TypeInfo(64, false, true, false, "int64_t", "i64")}, - {element::Type_t::u1, TypeInfo(1, false, false, false, "uint1_t", "u1")}, - {element::Type_t::u4, TypeInfo(4, false, false, false, "uint4_t", "u4")}, - {element::Type_t::u8, TypeInfo(8, false, false, true, "uint8_t", "u8")}, - {element::Type_t::u16, TypeInfo(16, false, false, false, "uint16_t", "u16")}, - {element::Type_t::u32, TypeInfo(32, false, false, false, "uint32_t", "u32")}, - {element::Type_t::u64, TypeInfo(64, false, false, false, "uint64_t", "u64")}, + {ov::element::Type_t::dynamic, TypeInfo(0, false, false, false, "dynamic", "dynamic")}, + {ov::element::Type_t::boolean, TypeInfo(8, false, true, false, "char", "boolean")}, + {ov::element::Type_t::bf16, TypeInfo(16, true, true, false, "bfloat16", "bf16")}, + {ov::element::Type_t::f16, TypeInfo(16, true, true, false, "float16", "f16")}, + {ov::element::Type_t::f32, TypeInfo(32, true, true, false, "float", "f32")}, + {ov::element::Type_t::f64, TypeInfo(64, true, true, false, "double", "f64")}, + {ov::element::Type_t::i4, TypeInfo(4, false, true, true, "int4_t", "i4")}, + {ov::element::Type_t::i8, TypeInfo(8, false, true, true, "int8_t", "i8")}, + {ov::element::Type_t::i16, TypeInfo(16, false, true, false, "int16_t", "i16")}, + {ov::element::Type_t::i32, TypeInfo(32, false, true, true, "int32_t", "i32")}, + {ov::element::Type_t::i64, TypeInfo(64, false, true, false, "int64_t", "i64")}, + {ov::element::Type_t::u1, TypeInfo(1, false, false, false, "uint1_t", "u1")}, + {ov::element::Type_t::u4, TypeInfo(4, false, false, false, "uint4_t", "u4")}, + {ov::element::Type_t::u8, TypeInfo(8, false, false, true, "uint8_t", "u8")}, + {ov::element::Type_t::u16, TypeInfo(16, false, false, false, "uint16_t", "u16")}, + {ov::element::Type_t::u32, TypeInfo(32, false, false, false, "uint32_t", "u32")}, + {ov::element::Type_t::u64, TypeInfo(64, false, false, false, "uint64_t", "u64")}, }; const ElementTypes::ElementsMap& get_type_info_map() { return ElementTypes::elements_map; }; -const TypeInfo& get_type_info(element::Type_t type) { +const TypeInfo& get_type_info(ov::element::Type_t type) { const auto& tim = get_type_info_map(); const auto& found = tim.find(type); if (found == tim.end()) { - throw std::out_of_range{"element::Type_t not supported"}; + throw std::out_of_range{"ov::element::Type_t not supported"}; } return found->second; }; } // namespace -std::vector element::Type::get_known_types() { - std::vector rc = {&element::dynamic, - &element::boolean, - &element::bf16, - &element::f16, - &element::f32, - &element::f64, - &element::i4, - &element::i8, - &element::i16, - &element::i32, - &element::i64, - &element::u1, - &element::u4, - &element::u8, - &element::u16, - &element::u32, - &element::u64}; +std::vector ov::element::Type::get_known_types() { + std::vector rc = {&ov::element::dynamic, + &ov::element::boolean, + &ov::element::bf16, + &ov::element::f16, + &ov::element::f32, + &ov::element::f64, + &ov::element::i4, + &ov::element::i8, + &ov::element::i16, + &ov::element::i32, + &ov::element::i64, + &ov::element::u1, + &ov::element::u4, + &ov::element::u8, + &ov::element::u16, + &ov::element::u32, + &ov::element::u64}; return rc; } -element::Type::Type(size_t bitwidth, bool is_real, bool is_signed, bool is_quantized, const std::string& /* cname */) { +ov::element::Type::Type(size_t bitwidth, + bool is_real, + bool is_signed, + bool is_quantized, + const std::string& /* cname */) { for (const auto& t : get_type_info_map()) { const TypeInfo& info = t.second; if (bitwidth == info.m_bitwidth && is_real == info.m_is_real && is_signed == info.m_is_signed && @@ -117,23 +120,23 @@ element::Type::Type(size_t bitwidth, bool is_real, bool is_signed, bool is_quant } } -const std::string& element::Type::c_type_string() const { +const std::string& ov::element::Type::c_type_string() const { return get_type_info(m_type).m_cname; } -size_t element::Type::size() const { +size_t ov::element::Type::size() const { return std::ceil(static_cast(bitwidth()) / 8.0f); } -size_t element::Type::hash() const { +size_t ov::element::Type::hash() const { return static_cast(m_type); } -const std::string& element::Type::get_type_name() const { +const std::string& ov::element::Type::get_type_name() const { return get_type_info(m_type).m_type_name; } -namespace ngraph { +namespace ov { namespace element { template <> Type from() { @@ -192,17 +195,17 @@ Type from() { return Type_t::bf16; } } // namespace element -} // namespace ngraph +} // namespace ov -std::ostream& element::operator<<(std::ostream& out, const element::Type& obj) { +std::ostream& ov::element::operator<<(std::ostream& out, const ov::element::Type& obj) { return out << obj.get_type_name(); } -bool element::Type::compatible(const element::Type& t) const { +bool ov::element::Type::compatible(const ov::element::Type& t) const { return (is_dynamic() || t.is_dynamic() || *this == t); } -bool element::Type::merge(element::Type& dst, const element::Type& t1, const element::Type& t2) { +bool ov::element::Type::merge(ov::element::Type& dst, const ov::element::Type& t1, const ov::element::Type& t2) { if (t1.is_dynamic()) { dst = t2; return true; @@ -217,35 +220,35 @@ bool element::Type::merge(element::Type& dst, const element::Type& t1, const ele } } -bool element::Type::is_static() const { +bool ov::element::Type::is_static() const { return get_type_info(m_type).m_bitwidth != 0; } -bool element::Type::is_real() const { +bool ov::element::Type::is_real() const { return get_type_info(m_type).m_is_real; } -bool element::Type::is_integral_number() const { - return is_integral() && (m_type != element::boolean); +bool ov::element::Type::is_integral_number() const { + return is_integral() && (m_type != ov::element::boolean); } -bool element::Type::is_signed() const { +bool ov::element::Type::is_signed() const { return get_type_info(m_type).m_is_signed; } -bool element::Type::is_quantized() const { +bool ov::element::Type::is_quantized() const { return get_type_info(m_type).m_is_quantized; } -size_t element::Type::bitwidth() const { +size_t ov::element::Type::bitwidth() const { return get_type_info(m_type).m_bitwidth; } -size_t ngraph::compiler_byte_size(element::Type_t et) { +size_t compiler_byte_size(ov::element::Type_t et) { switch (et) { -#define ET_CASE(et) \ - case element::Type_t::et: \ - return sizeof(element_type_traits::value_type); +#define ET_CASE(et) \ + case ov::element::Type_t::et: \ + return sizeof(ov::element_type_traits::value_type); ET_CASE(boolean); ET_CASE(bf16); ET_CASE(f16); @@ -263,48 +266,48 @@ size_t ngraph::compiler_byte_size(element::Type_t et) { ET_CASE(u32); ET_CASE(u64); #undef ET_CASE - case element::Type_t::undefined: + case ov::element::Type_t::undefined: return 0; - case element::Type_t::dynamic: + case ov::element::Type_t::dynamic: return 0; } - throw ngraph_error("compiler_byte_size: Unsupported value of element::Type_t: " + - std::to_string(static_cast(et))); + throw ngraph::ngraph_error("compiler_byte_size: Unsupported value of ov::element::Type_t: " + + std::to_string(static_cast(et))); } namespace ngraph { template <> -NGRAPH_API EnumNames& EnumNames::get() { - static auto enum_names = EnumNames("element::Type_t", - {{"undefined", element::Type_t::undefined}, - {"dynamic", element::Type_t::dynamic}, - {"boolean", element::Type_t::boolean}, - {"bf16", element::Type_t::bf16}, - {"f16", element::Type_t::f16}, - {"f32", element::Type_t::f32}, - {"f64", element::Type_t::f64}, - {"i4", element::Type_t::i4}, - {"i8", element::Type_t::i8}, - {"i16", element::Type_t::i16}, - {"i32", element::Type_t::i32}, - {"i64", element::Type_t::i64}, - {"u1", element::Type_t::u1}, - {"u4", element::Type_t::u4}, - {"u8", element::Type_t::u8}, - {"u16", element::Type_t::u16}, - {"u32", element::Type_t::u32}, - {"u64", element::Type_t::u64}}); +NGRAPH_API EnumNames& EnumNames::get() { + static auto enum_names = EnumNames("ov::element::Type_t", + {{"undefined", ov::element::Type_t::undefined}, + {"dynamic", ov::element::Type_t::dynamic}, + {"boolean", ov::element::Type_t::boolean}, + {"bf16", ov::element::Type_t::bf16}, + {"f16", ov::element::Type_t::f16}, + {"f32", ov::element::Type_t::f32}, + {"f64", ov::element::Type_t::f64}, + {"i4", ov::element::Type_t::i4}, + {"i8", ov::element::Type_t::i8}, + {"i16", ov::element::Type_t::i16}, + {"i32", ov::element::Type_t::i32}, + {"i64", ov::element::Type_t::i64}, + {"u1", ov::element::Type_t::u1}, + {"u4", ov::element::Type_t::u4}, + {"u8", ov::element::Type_t::u8}, + {"u16", ov::element::Type_t::u16}, + {"u32", ov::element::Type_t::u32}, + {"u64", ov::element::Type_t::u64}}); return enum_names; } } // namespace ngraph -constexpr DiscreteTypeInfo AttributeAdapter::type_info; +constexpr ngraph::DiscreteTypeInfo ngraph::AttributeAdapter::type_info; -const std::string& AttributeAdapter::get() { - return as_string(static_cast(m_ref)); +const std::string& ngraph::AttributeAdapter::get() { + return as_string(static_cast(m_ref)); } -void AttributeAdapter::set(const std::string& value) { - m_ref = as_enum(value); +void ngraph::AttributeAdapter::set(const std::string& value) { + m_ref = as_enum(value); }