Skip to content

Commit

Permalink
try use string_view for type aliases
Browse files Browse the repository at this point in the history
Signed-off-by: Raasz, Pawel <pawel.raasz@intel.com>
  • Loading branch information
praasz committed Jan 23, 2025
1 parent 08b087b commit f2a5029
Showing 1 changed file with 32 additions and 29 deletions.
61 changes: 32 additions & 29 deletions src/core/src/type/element_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <cmath>
#include <functional>
#include <iostream>
#include <string_view>
#include <unordered_map>

#include "openvino/core/type/element_type_traits.hpp"
Expand All @@ -28,7 +29,7 @@ struct TypeInfo {
bool m_is_quantized;
const char* m_cname;
const char* m_type_name;
const std::initializer_list<const char*> m_aliases;
const std::initializer_list<const std::string_view> 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();
Expand All @@ -40,40 +41,42 @@ struct TypeInfo {
}
};

static constexpr std::array<TypeInfo, enum_types_size> types_info{
using std::string_view_literals::operator""sv;

static constexpr std::array<TypeInfo, enum_types_size> types_info = {
TypeInfo{std::numeric_limits<size_t>::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) {
Expand Down

0 comments on commit f2a5029

Please sign in to comment.