From f2a50296862d7310156007a14e2b99639f07728b Mon Sep 17 00:00:00 2001 From: "Raasz, Pawel" Date: Thu, 23 Jan 2025 15:36:12 +0000 Subject: [PATCH] try use string_view for type aliases Signed-off-by: Raasz, Pawel --- src/core/src/type/element_type.cpp | 61 ++++++++++++++++-------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/src/core/src/type/element_type.cpp b/src/core/src/type/element_type.cpp index e84cf1dd3e54e0..04ca8b16bf369d 100644 --- a/src/core/src/type/element_type.cpp +++ b/src/core/src/type/element_type.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "openvino/core/type/element_type_traits.hpp" @@ -28,7 +29,7 @@ struct TypeInfo { bool m_is_quantized; const char* m_cname; const char* m_type_name; - const std::initializer_list m_aliases; + const std::initializer_list m_aliases; bool has_name(const std::string& type) const { return type == m_type_name || std::find(m_aliases.begin(), m_aliases.end(), type) != m_aliases.end(); @@ -40,40 +41,42 @@ struct TypeInfo { } }; -static constexpr std::array types_info{ +using std::string_view_literals::operator""sv; + +static constexpr std::array types_info = { TypeInfo{std::numeric_limits::max(), false, false, false, "undefined", "undefined", - {"UNSPECIFIED"}}, // undefined - {0, false, false, false, "dynamic", "dynamic", {}}, // dynamic - {8, false, true, false, "char", "boolean", {"BOOL"}}, // boolean - {16, true, true, false, "bfloat16", "bf16", {"BF16"}}, // bf16 - {16, true, true, false, "float16", "f16", {"FP16"}}, // f16 - {32, true, true, false, "float", "f32", {"FP32"}}, // f32 - {64, true, true, false, "double", "f64", {"FP64"}}, // f64 - {4, false, true, true, "int4_t", "i4", {"I4"}}, // i4 - {8, false, true, true, "int8_t", "i8", {"I8"}}, // i8 - {16, false, true, false, "int16_t", "i16", {"I16"}}, // i16 - {32, false, true, true, "int32_t", "i32", {"I32"}}, // i32 - {64, false, true, false, "int64_t", "i64", {"I64"}}, // i64 - {1, false, false, false, "uint1_t", "u1", {"U1", "bin", "BIN"}}, // u1 - {2, false, false, false, "uint2_t", "u2", {"U2"}}, // u2 - {3, false, false, false, "uint3_t", "u3", {"U3"}}, // u3 - {4, false, false, false, "uint4_t", "u4", {"U4"}}, // u4 - {6, false, false, false, "uint6_t", "u6", {"U6"}}, // u6 - {8, false, false, true, "uint8_t", "u8", {"U8"}}, // u8 - {16, false, false, false, "uint16_t", "u16", {"U16"}}, // u16 - {32, false, false, false, "uint32_t", "u32", {"U32"}}, // u32 - {64, false, false, false, "uint64_t", "u64", {"U64"}}, // u64 - {4, false, false, true, "nfloat4", "nf4", {"NF4"}}, // nf4 - {8, true, true, true, "f8e4m3", "f8e4m3", {"F8E4M3"}}, // f8e4m3 - {8, true, true, true, "f8e5m2", "f8e5m2", {"F8E5M2"}}, // f8e5m2 - {8 * sizeof(std::string), false, false, false, "string", "string", {"STRING"}}, // string - {4, true, true, true, "f4e2m1", "f4e2m1", {"F4E2M1"}}, // f4e2m1 - {8, true, true, true, "f8e8m0", "f8e8m0", {"F8E8M0"}} // f8e8m0 + {"UNSPECIFIED"sv}}, // undefined + TypeInfo{0, false, false, false, "dynamic", "dynamic", {}}, // dynamic + TypeInfo{8, false, true, false, "char", "boolean", {"BOOL"sv}}, // boolean + TypeInfo{16, true, true, false, "bfloat16", "bf16", {"BF16"sv}}, // bf16 + TypeInfo{16, true, true, false, "float16", "f16", {"FP16"sv}}, // f16 + TypeInfo{32, true, true, false, "float", "f32", {"FP32"sv}}, // f32 + TypeInfo{64, true, true, false, "double", "f64", {"FP64"sv}}, // f64 + TypeInfo{4, false, true, true, "int4_t", "i4", {"I4"sv}}, // i4 + TypeInfo{8, false, true, true, "int8_t", "i8", {"I8"sv}}, // i8 + TypeInfo{16, false, true, false, "int16_t", "i16", {"I16"sv}}, // i16 + TypeInfo{32, false, true, true, "int32_t", "i32", {"I32"sv}}, // i32 + TypeInfo{64, false, true, false, "int64_t", "i64", {"I64"sv}}, // i64 + TypeInfo{1, false, false, false, "uint1_t", "u1", {"U1"sv, "bin"sv, "BIN"sv}}, // u1 + TypeInfo{2, false, false, false, "uint2_t", "u2", {"U2"sv}}, // u2 + TypeInfo{3, false, false, false, "uint3_t", "u3", {"U3"sv}}, // u3 + TypeInfo{4, false, false, false, "uint4_t", "u4", {"U4"sv}}, // u4 + TypeInfo{6, false, false, false, "uint6_t", "u6", {"U6"sv}}, // u6 + TypeInfo{8, false, false, true, "uint8_t", "u8", {"U8"sv}}, // u8 + TypeInfo{16, false, false, false, "uint16_t", "u16", {"U16"sv}}, // u16 + TypeInfo{32, false, false, false, "uint32_t", "u32", {"U32"sv}}, // u32 + TypeInfo{64, false, false, false, "uint64_t", "u64", {"U64"sv}}, // u64 + TypeInfo{4, false, false, true, "nfloat4", "nf4", {"NF4"sv}}, // nf4 + TypeInfo{8, true, true, true, "f8e4m3", "f8e4m3", {"F8E4M3"sv}}, // f8e4m3 + TypeInfo{8, true, true, true, "f8e5m2", "f8e5m2", {"F8E5M2"sv}}, // f8e5m2 + TypeInfo{8 * sizeof(std::string), false, false, false, "string", "string", {"STRING"sv}}, // string + TypeInfo{4, true, true, true, "f4e2m1", "f4e2m1", {"F4E2M1"sv}}, // f4e2m1 + TypeInfo{8, true, true, true, "f8e8m0", "f8e8m0", {"F8E8M0"sv}} // f8e8m0 }; constexpr bool validate_types_info(decltype(types_info)& info, size_t i = 0) {