OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[core] Reduce big templates from constant header (#32029)
Pawel Raasz6f9723239127
diff --git a/src/core/include/openvino/op/constant.hpp b/src/core/include/openvino/op/constant.hppindex 3801cf5927f..2bb67046008 100644--- a/src/core/include/openvino/op/constant.hpp+++ b/src/core/include/openvino/op/constant.hpp@@ -6,6 +6,7 @@#include <cmath>#include <cstring>+#include <variant>#include "openvino/core/axis_set.hpp"#include "openvino/core/axis_vector.hpp"@@ -19,11 +20,6 @@ namespace ov {class AlignedBuffer;-namespace element {-template <Type_t ET, class T>-class Iterator;-}-namespace op {namespace v0 {/// \brief Class for constants.@@ -79,94 +75,12 @@ public:template <typename T>void fill_data(const element::Type& type, T value) {- using Type_t = element::Type_t;-#if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8)-# pragma GCC diagnostic push-# pragma GCC diagnostic error "-Wswitch"-# pragma GCC diagnostic error "-Wswitch-enum"-#endif- switch (type) {- case Type_t::boolean:- fill_data<Type_t::boolean>(value);- break;- case Type_t::bf16:- fill_data<Type_t::bf16>(value);- break;- case Type_t::f16:- fill_data<Type_t::f16>(value);- break;- case Type_t::f32:- fill_data<Type_t::f32>(value);- break;- case Type_t::f64:- fill_data<Type_t::f64>(value);- break;- case Type_t::i4:- fill_lp_data<Type_t::i4>(value);- break;- case Type_t::i8:- fill_data<Type_t::i8>(value);- break;- case Type_t::i16:- fill_data<Type_t::i16>(value);- break;- case Type_t::i32:- fill_data<Type_t::i32>(value);- break;- case Type_t::i64:- fill_data<Type_t::i64>(value);- break;- case Type_t::u1:- fill_lp_data<Type_t::u1>(value);- break;- case Type_t::u2:- fill_lp_data<Type_t::u2>(value);- break;- case Type_t::u3:- fill_lp_data<Type_t::u3>(value);- break;- case Type_t::u4:- fill_lp_data<Type_t::u4>(value);- break;- case Type_t::u6:- fill_lp_data<Type_t::u6>(value);- break;- case Type_t::u8:- fill_data<Type_t::u8>(value);- break;- case Type_t::u16:- fill_data<Type_t::u16>(value);- break;- case Type_t::u32:- fill_data<Type_t::u32>(value);- break;- case Type_t::u64:- fill_data<Type_t::u64>(value);- break;- case Type_t::nf4:- fill_lp_data<Type_t::nf4>(value);- break;- case Type_t::f8e4m3:- fill_data<Type_t::f8e4m3>(value);- break;- case Type_t::f8e5m2:- fill_data<Type_t::f8e5m2>(value);- break;- case Type_t::string:- fill_data<Type_t::string>(value);- break;- case Type_t::f4e2m1:- fill_lp_data<Type_t::f4e2m1>(value);- break;- case Type_t::f8e8m0:- fill_data<Type_t::f8e8m0>(value);- break;- case Type_t::dynamic:- OPENVINO_THROW("unsupported type");+ if constexpr (data::is_supported_type<T>) {+ data::fill(m_element_type, get_data_ptr_nc(), shape_size(m_shape), value);+ } else {+ proxy_type<T> proxy_value = value;+ data::fill(m_element_type, get_data_ptr_nc(), shape_size(m_shape), proxy_value);}-#if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8)-# pragma GCC diagnostic pop-#endif}/// \brief Constructs a tensor constant@@ -322,89 +236,22 @@ public:/// \return Constant's data vector.template <typename T>std::vector<T> cast_vector(int64_t num_elements = -1) const {- std::vector<T> rc;- using Type_t = element::Type_t;-const auto num_elements_to_cast = get_num_elements_to_cast(num_elements);- rc.reserve(num_elements_to_cast);-- switch (m_element_type) {- case Type_t::boolean:- cast_vector<Type_t::boolean>(rc, num_elements_to_cast);- break;- case Type_t::bf16:- cast_vector<Type_t::bf16>(rc, num_elements_to_cast);- break;- case Type_t::f16:- cast_vector<Type_t::f16>(rc, num_elements_to_cast);- break;- case Type_t::f32:- cast_vector<Type_t::f32>(rc, num_elements_to_cast);- break;- case Type_t::f64:- cast_vector<Type_t::f64>(rc, num_elements_to_cast);- break;- case Type_t::i4:- cast_lp_vector<Type_t::i4>(rc, num_elements_to_cast);- break;- case Type_t::i8:- cast_vector<Type_t::i8>(rc, num_elements_to_cast);- break;- case Type_t::i16:- cast_vector<Type_t::i16>(rc, num_elements_to_cast);- break;- case Type_t::i32:- cast_vector<Type_t::i32>(rc, num_elements_to_cast);- break;- case Type_t::i64:- cast_vector<Type_t::i64>(rc, num_elements_to_cast);- break;- case Type_t::u1:- cast_lp_vector<Type_t::u1>(rc, num_elements_to_cast);- break;- case Type_t::u2:- cast_lp_vector<Type_t::u2>(rc, num_elements_to_cast);- break;- case Type_t::u3:- cast_lp_vector<Type_t::u3>(rc, num_elements_to_cast);- break;- case Type_t::u4:- cast_lp_vector<Type_t::u4>(rc, num_elements_to_cast);- break;- case Type_t::u6:- cast_lp_vector<Type_t::u6>(rc, num_elements_to_cast);- break;- case Type_t::u8:- cast_vector<Type_t::u8>(rc, num_elements_to_cast);- break;- case Type_t::u16:- cast_vector<Type_t::u16>(rc, num_elements_to_cast);- break;- case Type_t::u32:- cast_vector<Type_t::u32>(rc, num_elements_to_cast);- break;- case Type_t::u64:- cast_vector<Type_t::u64>(rc, num_elements_to_cast);- break;- case Type_t::f8e4m3:- cast_vector<Type_t::f8e4m3>(rc, num_elements_to_cast);- break;- case Type_t::f8e5m2:- cast_vector<Type_t::f8e5m2>(rc, num_elements_to_cast);- break;- case Type_t::string:- cast_vector<Type_t::string>(rc, num_elements_to_cast);- break;- case Type_t::f4e2m1:- cast_lp_vector<Type_t::f4e2m1>(rc, num_elements_to_cast);- break;- case Type_t::f8e8m0:- cast_vector<Type_t::f8e8m0>(rc, num_elements_to_cast);- break;- default:- OPENVINO_THROW("unsupported type");++ if constexpr (data::is_supported_type<T>) {+ std::vector<T> rc(num_elements_to_cast);++ if constexpr (std::is_same_v<bool, T>) {+ data::cast_n(m_element_type, get_data_ptr(), num_elements_to_cast, rc.begin());+ } else {+ data::cast_n(m_element_type, get_data_ptr(), num_elements_to_cast, rc.data());+ }+ return rc;+ } else {+ std::vector<proxy_type<T>> rc(num_elements_to_cast);+ data::cast_n(m_element_type, get_data_ptr(), num_elements_to_cast, rc.data());+ return {rc.begin(), rc.end()};}- return rc;}const void* get_data_ptr() const;@@ -450,165 +297,6 @@ private:/// \param buffer Pointer to buffer with Constant values.void set_unused_bits(void* buffer) const;-#ifdef __clang__-# pragma clang diagnostic push-# ifdef __has_warning-# if __has_warning("-Wimplicit-const-int-float-conversion")-# pragma clang diagnostic ignored "-Wimplicit-const-int-float-conversion"-# elif __has_warning("-Wimplicit-int-float-conversion")-# pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"-# endif-# endif-#elif defined(__GNUC__)-# pragma GCC diagnostic push-# pragma GCC diagnostic ignored "-Wsign-compare"-# pragma GCC diagnostic ignored "-Wbool-compare"-#elif defined(_MSC_VER)-# pragma warning(push)-# pragma warning(disable : 4018)-# pragma warning(disable : 4804)-#endif- template <class U, class ConstantT, std::enable_if_t<!std::is_same_v<U, ConstantT>>* = nullptr>- static bool in_type_range(const ConstantT v) {- if constexpr (std::is_unsigned_v<ConstantT> && std::is_integral_v<U>) {- if constexpr (std::numeric_limits<ConstantT>::max() < std::numeric_limits<U>::max()) {- return true;- } else {- return v <= std::numeric_limits<U>::max();- }- } else if constexpr (std::is_unsigned_v<ConstantT>) {- return v <= std::numeric_limits<U>::max();- } else if constexpr (std::is_integral_v<ConstantT> && std::is_integral_v<U>) {- if constexpr (std::numeric_limits<U>::lowest() < std::numeric_limits<ConstantT>::lowest() &&- std::numeric_limits<U>::max() > std::numeric_limits<ConstantT>::max()) {- return true;- } else if constexpr (std::numeric_limits<ConstantT>::lowest() < std::numeric_limits<U>::lowest() &&- std::numeric_limits<U>::max() <= std::numeric_limits<ConstantT>::max()) {- return std::numeric_limits<U>::lowest() <= v;- } else if constexpr (std::numeric_limits<ConstantT>::lowest() >= std::numeric_limits<U>::lowest() &&- std::numeric_limits<U>::max() > std::numeric_limits<ConstantT>::max()) {- return v <= std::numeric_limits<U>::max();- } else {- return std::numeric_limits<U>::lowest() <= v && v <= std::numeric_limits<U>::max();- }- } else {- return std::numeric_limits<U>::lowest() <= v && v <= std::numeric_limits<U>::max();- }- }-#if defined(__clang__)-# pragma clang diagnostic pop-#elif defined(__GNUC__)-# pragma GCC diagnostic pop-#elif defined(_MSC_VER)-# pragma warning(pop)-#endif-- template <class U, class ConstantT, std::enable_if_t<std::is_same_v<U, ConstantT>>* = nullptr>- static constexpr bool in_type_range(const ConstantT) {- return true;- }-- /// \brief Cast constant data to std::vector of User type.- /// This version is for user type which is unknown for OpenVINO.- /// The minimum requirement for this type is to support conversion from OV type.- ///- /// \param output_vector Output vector with casted data.- /// \param num_elements number of elements to cast from constant.- template <- element::Type_t Type,- class UserT,- typename std::enable_if<Type != element::string && !std::is_same<UserT, std::string>::value>::type* = nullptr>- void cast_vector(std::vector<UserT>& output_vector, size_t num_elements) const {- using T = ov::fundamental_type_for<Type>;- const auto first = get_data_ptr<T>();- std::transform(first, first + num_elements, std::back_inserter(output_vector), [](const T v) {- return static_cast<UserT>(v);- });- }-- template <element::Type_t Type,- class U,- typename std::enable_if<Type == element::string && std::is_same<U, std::string>::value>::type* = nullptr>- void cast_vector(std::vector<U>& output_vector, size_t num_elements) const {- const auto p = get_data_ptr<Type>();- std::copy_n(p, num_elements, std::back_inserter(output_vector));- }-- template <- element::Type_t Type,- class U,- typename std::enable_if<(Type == element::string) != std::is_same<U, std::string>::value>::type* = nullptr>- void cast_vector(std::vector<U>& output, size_t num_elements) const {- OPENVINO_THROW("'cast_vector' does not support casting Constant of type ",- Type,- " into std::vector of ",- element::from<U>());- }-- // generic cast_LP_data if input is not std or OV type (do additional conversion)- template <element::Type_t ET, class U>- void cast_lp_vector(std::vector<U>& output, size_t num_elements) const {- auto lp_buffer = LPBuffer<ET>(get_data_ptr());- auto out_inserter = std::back_inserter(output);- for (size_t i = 0; i < num_elements; ++i, ++lp_buffer) {- using UT = typename std::decay<U>::type;- using LPT = decltype(lp_buffer.read());- using CastT = typename std::- conditional<!std::is_same<UT, LPT>::value && !std::is_integral<U>::value, float, LPT>::type;- *out_inserter = static_cast<CastT>(lp_buffer.read());- }- }-- template <element::Type_t ET>- void cast_lp_vector(std::vector<std::string>& output, size_t num_elements) const {- cast_vector<element::i8>(output, num_elements);- }-- template <element::Type_t Type,- class T,- typename std::enable_if<Type != element::string && !std::is_same<T, std::string>::value>::type* = nullptr>- void fill_data(const T& value) {- using StorageDataType = ov::fundamental_type_for<Type>;- OPENVINO_ASSERT(in_type_range<StorageDataType>(value),- "Cannot fill constant data. Values is outside the range.");- const auto size = shape_size(m_shape);- const auto v = static_cast<StorageDataType>(value);- std::fill_n(get_data_ptr_nc<Type>(), size, v);- }-- template <element::Type_t Type,- class T,- typename std::enable_if<Type == element::string && std::is_same<T, std::string>::value>::type* = nullptr>- void fill_data(const T& value) {- auto num_elements = shape_size(m_shape);- std::uninitialized_fill_n(get_data_ptr_nc<Type>(), num_elements, value);- }-- template <- element::Type_t Type,- class T,- typename std::enable_if<(Type == element::string) != std::is_same<T, std::string>::value>::type* = nullptr>- void fill_data(const T& value) {- if (Type == element::string) {- fill_data<element::string, std::string>(std::string());- }- OPENVINO_THROW("'fill_data' does not support writing elements of type ",- element::from<T>(),- " into Constant of type ",- Type);- }-- // generic fill_lp_data if input is not std or OV type (do additional conversion)- template <element::Type_t ET, class T>- void fill_lp_data(const T& value) {- fill_lp_data<ET>(static_cast<float>(value));- }-- template <element::Type_t ET>- void fill_lp_data(const std::string& value) {- fill_data<element::i8>(value);- }-void allocate_buffer(bool memset_allocation);void* get_data_ptr_nc();@@ -620,152 +308,17 @@ private:}template <typename T>- void write_values(const std::vector<T>& values) {- write_to_buffer(values);- }-- template <element::Type_t Type,- typename T,- typename std::enable_if<Type != element::string && !std::is_same<T, std::string>::value>::type* = nullptr>- void write_buffer(const std::vector<T>& source) {- using StorageDataType = fundamental_type_for<Type>;- auto p = get_data_ptr_nc<Type>();- for (size_t i = 0; i < source.size(); ++i) {- p[i] = static_cast<StorageDataType>(source[i]);- }- }-- template <element::Type_t Type,- typename T,- typename std::enable_if<Type == element::string && std::is_same<T, std::string>::value>::type* = nullptr>- void write_buffer(const std::vector<T>& source) {- // elements of string are already pre-initialized in allocate_buffer- auto p = get_data_ptr_nc<Type>();- std::uninitialized_copy_n(source.begin(), source.size(), p);- }-- template <- element::Type_t Type,- typename T,- typename std::enable_if<(Type == element::string) != std::is_same<T, std::string>::value>::type* = nullptr>- void write_buffer(const std::vector<T>& source) {- if (Type == element::string) {- fill_data<element::string>(std::string());- }- OPENVINO_THROW("'write_buffer' does not support writing elements of type ",- element::from<T>(),- " into Constant of type ",- Type);- }-- // generic write_lp_buffer if input is not std or OV type (do additional conversion)- template <element::Type_t ET, class T>- void write_lp_buffer(const std::vector<T>& source) {- auto lp_buffer = LPBuffer<ET>(get_data_ptr_nc());- for (const auto& value : source) {- lp_buffer.write(static_cast<float>(value));- ++lp_buffer;- }- }-- template <element::Type_t ET>- void write_lp_buffer(const std::vector<std::string>& source) {- write_buffer<element::i8>(source);- }-- template <typename T>- void write_to_buffer(const std::vector<T>& source) {- if (source.size() != shape_size(m_shape)) {- OPENVINO_THROW("Constant initializer does not match shape");- }- using Type_t = element::Type_t;-#if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8)-# pragma GCC diagnostic push-# pragma GCC diagnostic error "-Wswitch"-# pragma GCC diagnostic error "-Wswitch-enum"-#endif- switch (m_element_type) {- case Type_t::boolean:- write_buffer<Type_t::boolean>(source);- break;- case Type_t::bf16:- write_buffer<Type_t::bf16>(source);- break;- case Type_t::f16:- write_buffer<Type_t::f16>(source);- break;- case Type_t::f32:- write_buffer<Type_t::f32>(source);- break;- case Type_t::f64:- write_buffer<Type_t::f64>(source);- break;- case Type_t::i4:- write_lp_buffer<Type_t::i4>(source);- break;- case Type_t::i8:- write_buffer<Type_t::i8>(source);- break;- case Type_t::i16:- write_buffer<Type_t::i16>(source);- break;- case Type_t::i32:- write_buffer<Type_t::i32>(source);- break;- case Type_t::i64:- write_buffer<Type_t::i64>(source);- break;- case Type_t::u1:- write_lp_buffer<Type_t::u1>(source);- break;- case Type_t::u2:- write_lp_buffer<Type_t::u2>(source);- break;- case Type_t::u3:- write_lp_buffer<Type_t::u3>(source);- break;- case Type_t::u4:- write_lp_buffer<Type_t::u4>(source);- break;- case Type_t::u6:- write_lp_buffer<Type_t::u6>(source);- break;- case Type_t::u8:- write_buffer<Type_t::u8>(source);- break;- case Type_t::u16:- write_buffer<Type_t::u16>(source);- break;- case Type_t::u32:- write_buffer<Type_t::u32>(source);- break;- case Type_t::u64:- write_buffer<Type_t::u64>(source);- break;- case Type_t::nf4:- write_lp_buffer<Type_t::nf4>(source);- break;- case Type_t::f8e4m3:- write_buffer<Type_t::f8e4m3>(source);- break;- case Type_t::f8e5m2:- write_buffer<Type_t::f8e5m2>(source);- break;- case Type_t::string:- write_buffer<Type_t::string>(source);- break;- case Type_t::f4e2m1:- write_lp_buffer<Type_t::f4e2m1>(source);- break;- case Type_t::f8e8m0:- write_buffer<Type_t::f8e8m0>(source);- break;- case Type_t::dynamic:- OPENVINO_THROW("unsupported type");+ void write_values(const std::vector<T>& source) {+ OPENVINO_ASSERT(source.size() == shape_size(m_shape), "Constant initializer does not match shape");++ if constexpr (!data::is_supported_type<T>) {+ std::vector<proxy_type<T>> temp{source.begin(), source.end()};+ data::copy_n(m_element_type, temp.data(), temp.size(), get_data_ptr_nc());+ } else if constexpr (std::is_same_v<bool, T>) {+ data::copy_n(m_element_type, source.begin(), source.size(), get_data_ptr_nc());+ } else {+ data::copy_n(m_element_type, source.data(), source.size(), get_data_ptr_nc());}-#if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8)-# pragma GCC diagnostic pop-#endif}template <class T>@@ -785,21 +338,49 @@ private:return 64;}- // Internal helper to read/write low precision values for not standard or OV type.- template <element::Type_t ET>- struct LPBuffer {- using lp_iter = element::Iterator<ET, typename ov::fundamental_type_for<ET>>;- using lp_iter_ptr = std::shared_ptr<lp_iter>;+ template <class... Ts>+ struct Data {+ using value = std::variant<Ts...>;+ using pointer =+ std::variant<std::conditional_t<std::is_same_v<Ts, bool>, typename std::vector<Ts>::iterator, Ts*>...>;+ using const_pointer = std::variant<+ std::conditional_t<std::is_same_v<Ts, bool>, typename std::vector<Ts>::const_iterator, const Ts*>...>;- LPBuffer(void* ptr);- LPBuffer(const void* ptr) : LPBuffer{const_cast<void*>(ptr)} {}- void write(const float value);- ov::fundamental_type_for<ET> read() const;- LPBuffer& operator++();+ template <class U>+ static constexpr auto is_supported_type = std::disjunction_v<std::is_same<U, Ts>...>;- lp_iter_ptr iter;+ static void fill(const element::Type& type, void* dst, const size_t n, const value& value);+ static void copy_n(const element::Type& type, const_pointer src, const size_t n, void* dst);+ static void cast_n(const element::Type& type, const void* src, const size_t n, pointer dst);};+ template <class U>+ using proxy_type = std::conditional_t<std::is_integral_v<U>,+ long long,+ std::conditional_t<std::is_unsigned_v<U>, unsigned long long, double>>;++ using data = Data<bool,+ char,+ signed char,+ unsigned char,+ short,+ unsigned short,+ int,+ unsigned int,+ long,+ unsigned long,+ long long,+ unsigned long long,+ float,+ double,+ float4_e2m1,+ float8_e4m3,+ float8_e5m2,+ float8_e8m0,+ float16,+ bfloat16,+ std::string>;+element::Type m_element_type{};Shape m_shape{};Strides m_byte_strides{};@@ -810,437 +391,13 @@ private:};template <>-OPENVINO_API Constant::LPBuffer<element::u1>::LPBuffer(void* ptr);-template <>-OPENVINO_API Constant::LPBuffer<element::u2>::LPBuffer(void* ptr);-template <>-OPENVINO_API Constant::LPBuffer<element::u3>::LPBuffer(void* ptr);-template <>-OPENVINO_API Constant::LPBuffer<element::u4>::LPBuffer(void* ptr);-template <>-OPENVINO_API Constant::LPBuffer<element::u6>::LPBuffer(void* ptr);-template <>-OPENVINO_API Constant::LPBuffer<element::i4>::LPBuffer(void* ptr);-template <>-OPENVINO_API Constant::LPBuffer<element::nf4>::LPBuffer(void* ptr);-template <>-OPENVINO_API Constant::LPBuffer<element::f4e2m1>::LPBuffer(void* ptr);+OPENVINO_API void Constant::data::fill(const element::Type& type, void* dst, const size_t n, const value& value);template <>-OPENVINO_API void Constant::LPBuffer<element::u1>::write(const float value);-template <>-OPENVINO_API void Constant::LPBuffer<element::u2>::write(const float value);-template <>-OPENVINO_API void Constant::LPBuffer<element::u3>::write(const float value);-template <>-OPENVINO_API void Constant::LPBuffer<element::u4>::write(const float value);-template <>-OPENVINO_API void Constant::LPBuffer<element::u6>::write(const float value);-template <>-OPENVINO_API void Constant::LPBuffer<element::i4>::write(const float value);-template <>-OPENVINO_API void Constant::LPBuffer<element::nf4>::write(const float value);-template <>-OPENVINO_API void Constant::LPBuffer<element::f4e2m1>::write(const float value);+OPENVINO_API void Constant::data::copy_n(const element::Type& type, const_pointer src, const size_t n, void* dst);template <>-OPENVINO_API ov::fundamental_type_for<element::u1> Constant::LPBuffer<element::u1>::read() const;-template <>-OPENVINO_API ov::fundamental_type_for<element::u2> Constant::LPBuffer<element::u2>::read() const;-template <>-OPENVINO_API ov::fundamental_type_for<element::u3> Constant::LPBuffer<element::u3>::read() const;-template <>-OPENVINO_API ov::fundamental_type_for<element::u4> Constant::LPBuffer<element::u4>::read() const;-template <>-OPENVINO_API ov::fundamental_type_for<element::u6> Constant::LPBuffer<element::u6>::read() const;-template <>-OPENVINO_API ov::fundamental_type_for<element::i4> Constant::LPBuffer<element::i4>::read() const;-template <>-OPENVINO_API ov::fundamental_type_for<element::nf4> Constant::LPBuffer<element::nf4>::read() const;-template <>-OPENVINO_API ov::fundamental_type_for<element::f4e2m1> Constant::LPBuffer<element::f4e2m1>::read() const;--template <>-OPENVINO_API Constant::LPBuffer<element::u1>& Constant::LPBuffer<element::u1>::operator++();-template <>-OPENVINO_API Constant::LPBuffer<element::u2>& Constant::LPBuffer<element::u2>::operator++();-template <>-OPENVINO_API Constant::LPBuffer<element::u3>& Constant::LPBuffer<element::u3>::operator++();-template <>-OPENVINO_API Constant::LPBuffer<element::u4>& Constant::LPBuffer<element::u4>::operator++();-template <>-OPENVINO_API Constant::LPBuffer<element::u6>& Constant::LPBuffer<element::u6>::operator++();-template <>-OPENVINO_API Constant::LPBuffer<element::i4>& Constant::LPBuffer<element::i4>::operator++();-template <>-OPENVINO_API Constant::LPBuffer<element::nf4>& Constant::LPBuffer<element::nf4>::operator++();-template <>-OPENVINO_API Constant::LPBuffer<element::f4e2m1>& Constant::LPBuffer<element::f4e2m1>::operator++();--#define CONSTANT_FILL_DATA_SPECIALIZATION(ET, SRC_TYPE) \- template <> \- OPENVINO_API void Constant::fill_lp_data<element::Type_t::ET>(const SRC_TYPE& value);--CONSTANT_FILL_DATA_SPECIALIZATION(u1, bool)-CONSTANT_FILL_DATA_SPECIALIZATION(u1, char)-CONSTANT_FILL_DATA_SPECIALIZATION(u1, signed char)-CONSTANT_FILL_DATA_SPECIALIZATION(u1, unsigned char)-CONSTANT_FILL_DATA_SPECIALIZATION(u1, short)-CONSTANT_FILL_DATA_SPECIALIZATION(u1, unsigned short)-CONSTANT_FILL_DATA_SPECIALIZATION(u1, int)-CONSTANT_FILL_DATA_SPECIALIZATION(u1, unsigned int)-CONSTANT_FILL_DATA_SPECIALIZATION(u1, long)-CONSTANT_FILL_DATA_SPECIALIZATION(u1, unsigned long)-CONSTANT_FILL_DATA_SPECIALIZATION(u1, long long)-CONSTANT_FILL_DATA_SPECIALIZATION(u1, unsigned long long)-CONSTANT_FILL_DATA_SPECIALIZATION(u1, float8_e4m3)-CONSTANT_FILL_DATA_SPECIALIZATION(u1, float8_e5m2)-CONSTANT_FILL_DATA_SPECIALIZATION(u1, float8_e8m0)-CONSTANT_FILL_DATA_SPECIALIZATION(u1, float16)-CONSTANT_FILL_DATA_SPECIALIZATION(u1, bfloat16)-CONSTANT_FILL_DATA_SPECIALIZATION(u1, float)-CONSTANT_FILL_DATA_SPECIALIZATION(u1, double)--CONSTANT_FILL_DATA_SPECIALIZATION(u2, bool)-CONSTANT_FILL_DATA_SPECIALIZATION(u2, char)-CONSTANT_FILL_DATA_SPECIALIZATION(u2, signed char)-CONSTANT_FILL_DATA_SPECIALIZATION(u2, unsigned char)-CONSTANT_FILL_DATA_SPECIALIZATION(u2, short)-CONSTANT_FILL_DATA_SPECIALIZATION(u2, unsigned short)-CONSTANT_FILL_DATA_SPECIALIZATION(u2, int)-CONSTANT_FILL_DATA_SPECIALIZATION(u2, unsigned int)-CONSTANT_FILL_DATA_SPECIALIZATION(u2, long)-CONSTANT_FILL_DATA_SPECIALIZATION(u2, unsigned long)-CONSTANT_FILL_DATA_SPECIALIZATION(u2, long long)-CONSTANT_FILL_DATA_SPECIALIZATION(u2, unsigned long long)-CONSTANT_FILL_DATA_SPECIALIZATION(u2, float8_e4m3)-CONSTANT_FILL_DATA_SPECIALIZATION(u2, float8_e5m2)-CONSTANT_FILL_DATA_SPECIALIZATION(u2, float8_e8m0)-CONSTANT_FILL_DATA_SPECIALIZATION(u2, float16)-CONSTANT_FILL_DATA_SPECIALIZATION(u2, bfloat16)-CONSTANT_FILL_DATA_SPECIALIZATION(u2, float)-CONSTANT_FILL_DATA_SPECIALIZATION(u2, double)--CONSTANT_FILL_DATA_SPECIALIZATION(u3, bool)-CONSTANT_FILL_DATA_SPECIALIZATION(u3, char)-CONSTANT_FILL_DATA_SPECIALIZATION(u3, signed char)-CONSTANT_FILL_DATA_SPECIALIZATION(u3, unsigned char)-CONSTANT_FILL_DATA_SPECIALIZATION(u3, short)-CONSTANT_FILL_DATA_SPECIALIZATION(u3, unsigned short)-CONSTANT_FILL_DATA_SPECIALIZATION(u3, int)-CONSTANT_FILL_DATA_SPECIALIZATION(u3, unsigned int)-CONSTANT_FILL_DATA_SPECIALIZATION(u3, long)-CONSTANT_FILL_DATA_SPECIALIZATION(u3, unsigned long)-CONSTANT_FILL_DATA_SPECIALIZATION(u3, long long)-CONSTANT_FILL_DATA_SPECIALIZATION(u3, unsigned long long)-CONSTANT_FILL_DATA_SPECIALIZATION(u3, float8_e4m3)-CONSTANT_FILL_DATA_SPECIALIZATION(u3, float8_e5m2)-CONSTANT_FILL_DATA_SPECIALIZATION(u3, float8_e8m0)-CONSTANT_FILL_DATA_SPECIALIZATION(u3, float16)-CONSTANT_FILL_DATA_SPECIALIZATION(u3, bfloat16)-CONSTANT_FILL_DATA_SPECIALIZATION(u3, float)-CONSTANT_FILL_DATA_SPECIALIZATION(u3, double)--CONSTANT_FILL_DATA_SPECIALIZATION(u4, bool)-CONSTANT_FILL_DATA_SPECIALIZATION(u4, char)-CONSTANT_FILL_DATA_SPECIALIZATION(u4, signed char)-CONSTANT_FILL_DATA_SPECIALIZATION(u4, unsigned char)-CONSTANT_FILL_DATA_SPECIALIZATION(u4, short)-CONSTANT_FILL_DATA_SPECIALIZATION(u4, unsigned short)-CONSTANT_FILL_DATA_SPECIALIZATION(u4, int)-CONSTANT_FILL_DATA_SPECIALIZATION(u4, unsigned int)-CONSTANT_FILL_DATA_SPECIALIZATION(u4, long)-CONSTANT_FILL_DATA_SPECIALIZATION(u4, unsigned long)-CONSTANT_FILL_DATA_SPECIALIZATION(u4, long long)-CONSTANT_FILL_DATA_SPECIALIZATION(u4, unsigned long long)-CONSTANT_FILL_DATA_SPECIALIZATION(u4, float8_e4m3)-CONSTANT_FILL_DATA_SPECIALIZATION(u4, float8_e5m2)-CONSTANT_FILL_DATA_SPECIALIZATION(u4, float8_e8m0)-CONSTANT_FILL_DATA_SPECIALIZATION(u4, float16)-CONSTANT_FILL_DATA_SPECIALIZATION(u4, bfloat16)-CONSTANT_FILL_DATA_SPECIALIZATION(u4, float)-CONSTANT_FILL_DATA_SPECIALIZATION(u4, double)--CONSTANT_FILL_DATA_SPECIALIZATION(u6, bool)-CONSTANT_FILL_DATA_SPECIALIZATION(u6, char)-CONSTANT_FILL_DATA_SPECIALIZATION(u6, signed char)-CONSTANT_FILL_DATA_SPECIALIZATION(u6, unsigned char)-CONSTANT_FILL_DATA_SPECIALIZATION(u6, short)-CONSTANT_FILL_DATA_SPECIALIZATION(u6, unsigned short)-CONSTANT_FILL_DATA_SPECIALIZATION(u6, int)-CONSTANT_FILL_DATA_SPECIALIZATION(u6, unsigned int)-CONSTANT_FILL_DATA_SPECIALIZATION(u6, long)-CONSTANT_FILL_DATA_SPECIALIZATION(u6, unsigned long)-CONSTANT_FILL_DATA_SPECIALIZATION(u6, long long)-CONSTANT_FILL_DATA_SPECIALIZATION(u6, unsigned long long)-CONSTANT_FILL_DATA_SPECIALIZATION(u6, float8_e4m3)-CONSTANT_FILL_DATA_SPECIALIZATION(u6, float8_e5m2)-CONSTANT_FILL_DATA_SPECIALIZATION(u6, float8_e8m0)-CONSTANT_FILL_DATA_SPECIALIZATION(u6, float16)-CONSTANT_FILL_DATA_SPECIALIZATION(u6, bfloat16)-CONSTANT_FILL_DATA_SPECIALIZATION(u6, float)-CONSTANT_FILL_DATA_SPECIALIZATION(u6, double)--CONSTANT_FILL_DATA_SPECIALIZATION(i4, bool)-CONSTANT_FILL_DATA_SPECIALIZATION(i4, char)-CONSTANT_FILL_DATA_SPECIALIZATION(i4, signed char)-CONSTANT_FILL_DATA_SPECIALIZATION(i4, unsigned char)-CONSTANT_FILL_DATA_SPECIALIZATION(i4, short)-CONSTANT_FILL_DATA_SPECIALIZATION(i4, unsigned short)-CONSTANT_FILL_DATA_SPECIALIZATION(i4, int)-CONSTANT_FILL_DATA_SPECIALIZATION(i4, unsigned int)-CONSTANT_FILL_DATA_SPECIALIZATION(i4, long)-CONSTANT_FILL_DATA_SPECIALIZATION(i4, unsigned long)-CONSTANT_FILL_DATA_SPECIALIZATION(i4, long long)-CONSTANT_FILL_DATA_SPECIALIZATION(i4, unsigned long long)-CONSTANT_FILL_DATA_SPECIALIZATION(i4, float8_e4m3)-CONSTANT_FILL_DATA_SPECIALIZATION(i4, float8_e5m2)-CONSTANT_FILL_DATA_SPECIALIZATION(i4, float8_e8m0)-CONSTANT_FILL_DATA_SPECIALIZATION(i4, float16)-CONSTANT_FILL_DATA_SPECIALIZATION(i4, bfloat16)-CONSTANT_FILL_DATA_SPECIALIZATION(i4, float)-CONSTANT_FILL_DATA_SPECIALIZATION(i4, double)--CONSTANT_FILL_DATA_SPECIALIZATION(nf4, bool)-CONSTANT_FILL_DATA_SPECIALIZATION(nf4, char)-CONSTANT_FILL_DATA_SPECIALIZATION(nf4, signed char)-CONSTANT_FILL_DATA_SPECIALIZATION(nf4, unsigned char)-CONSTANT_FILL_DATA_SPECIALIZATION(nf4, short)-CONSTANT_FILL_DATA_SPECIALIZATION(nf4, unsigned short)-CONSTANT_FILL_DATA_SPECIALIZATION(nf4, int)-CONSTANT_FILL_DATA_SPECIALIZATION(nf4, unsigned int)-CONSTANT_FILL_DATA_SPECIALIZATION(nf4, long)-CONSTANT_FILL_DATA_SPECIALIZATION(nf4, unsigned long)-CONSTANT_FILL_DATA_SPECIALIZATION(nf4, long long)-CONSTANT_FILL_DATA_SPECIALIZATION(nf4, unsigned long long)-CONSTANT_FILL_DATA_SPECIALIZATION(nf4, float8_e4m3)-CONSTANT_FILL_DATA_SPECIALIZATION(nf4, float8_e5m2)-CONSTANT_FILL_DATA_SPECIALIZATION(nf4, float8_e8m0)-CONSTANT_FILL_DATA_SPECIALIZATION(nf4, float16)-CONSTANT_FILL_DATA_SPECIALIZATION(nf4, bfloat16)-CONSTANT_FILL_DATA_SPECIALIZATION(nf4, float)-CONSTANT_FILL_DATA_SPECIALIZATION(nf4, double)--CONSTANT_FILL_DATA_SPECIALIZATION(f4e2m1, bool)-CONSTANT_FILL_DATA_SPECIALIZATION(f4e2m1, char)-CONSTANT_FILL_DATA_SPECIALIZATION(f4e2m1, signed char)-CONSTANT_FILL_DATA_SPECIALIZATION(f4e2m1, unsigned char)-CONSTANT_FILL_DATA_SPECIALIZATION(f4e2m1, short)-CONSTANT_FILL_DATA_SPECIALIZATION(f4e2m1, unsigned short)-CONSTANT_FILL_DATA_SPECIALIZATION(f4e2m1, int)-CONSTANT_FILL_DATA_SPECIALIZATION(f4e2m1, unsigned int)-CONSTANT_FILL_DATA_SPECIALIZATION(f4e2m1, long)-CONSTANT_FILL_DATA_SPECIALIZATION(f4e2m1, unsigned long)-CONSTANT_FILL_DATA_SPECIALIZATION(f4e2m1, long long)-CONSTANT_FILL_DATA_SPECIALIZATION(f4e2m1, unsigned long long)-CONSTANT_FILL_DATA_SPECIALIZATION(f4e2m1, float8_e4m3)-CONSTANT_FILL_DATA_SPECIALIZATION(f4e2m1, float8_e5m2)-CONSTANT_FILL_DATA_SPECIALIZATION(f4e2m1, float8_e8m0)-CONSTANT_FILL_DATA_SPECIALIZATION(f4e2m1, float16)-CONSTANT_FILL_DATA_SPECIALIZATION(f4e2m1, bfloat16)-CONSTANT_FILL_DATA_SPECIALIZATION(f4e2m1, float)-CONSTANT_FILL_DATA_SPECIALIZATION(f4e2m1, double)--#undef CONSTANT_FILL_DATA_SPECIALIZATION--#define CONSTANT_WRITE_BUFFER_SPECIALIZATION(ET, SRC_TYPE) \- template <> \- OPENVINO_API void Constant::write_lp_buffer<element::Type_t::ET>(const std::vector<SRC_TYPE>& source);--CONSTANT_WRITE_BUFFER_SPECIALIZATION(u1, bool)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u1, char)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u1, signed char)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u1, unsigned char)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u1, short)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u1, unsigned short)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u1, int)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u1, unsigned int)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u1, long)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u1, unsigned long)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u1, long long)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u1, unsigned long long)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u1, float8_e4m3)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u1, float8_e5m2)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u1, float8_e8m0)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u1, float16)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u1, bfloat16)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u1, float)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u1, double)--CONSTANT_WRITE_BUFFER_SPECIALIZATION(u2, bool)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u2, char)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u2, signed char)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u2, unsigned char)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u2, short)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u2, unsigned short)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u2, int)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u2, unsigned int)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u2, long)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u2, unsigned long)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u2, long long)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u2, unsigned long long)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u2, float8_e4m3)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u2, float8_e5m2)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u2, float8_e8m0)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u2, float16)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u2, bfloat16)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u2, float)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u2, double)--CONSTANT_WRITE_BUFFER_SPECIALIZATION(u3, bool)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u3, char)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u3, signed char)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u3, unsigned char)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u3, short)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u3, unsigned short)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u3, int)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u3, unsigned int)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u3, long)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u3, unsigned long)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u3, long long)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u3, unsigned long long)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u3, float8_e4m3)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u3, float8_e5m2)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u3, float8_e8m0)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u3, float16)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u3, bfloat16)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u3, float)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u3, double)--CONSTANT_WRITE_BUFFER_SPECIALIZATION(u4, bool)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u4, char)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u4, signed char)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u4, unsigned char)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u4, short)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u4, unsigned short)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u4, int)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u4, unsigned int)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u4, long)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u4, unsigned long)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u4, long long)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u4, unsigned long long)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u4, float8_e4m3)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u4, float8_e5m2)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u4, float8_e8m0)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u4, float16)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u4, bfloat16)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u4, float)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u4, double)--CONSTANT_WRITE_BUFFER_SPECIALIZATION(u6, bool)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u6, char)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u6, signed char)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u6, unsigned char)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u6, short)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u6, unsigned short)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u6, int)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u6, unsigned int)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u6, long)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u6, unsigned long)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u6, long long)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u6, unsigned long long)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u6, float8_e4m3)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u6, float8_e5m2)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u6, float8_e8m0)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u6, float16)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u6, bfloat16)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u6, float)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(u6, double)--CONSTANT_WRITE_BUFFER_SPECIALIZATION(i4, bool)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(i4, char)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(i4, signed char)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(i4, unsigned char)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(i4, short)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(i4, unsigned short)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(i4, int)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(i4, unsigned int)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(i4, long)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(i4, unsigned long)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(i4, long long)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(i4, unsigned long long)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(i4, float8_e4m3)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(i4, float8_e5m2)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(i4, float8_e8m0)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(i4, float16)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(i4, bfloat16)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(i4, float)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(i4, double)--CONSTANT_WRITE_BUFFER_SPECIALIZATION(nf4, bool)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(nf4, char)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(nf4, signed char)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(nf4, unsigned char)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(nf4, short)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(nf4, unsigned short)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(nf4, int)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(nf4, unsigned int)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(nf4, long)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(nf4, unsigned long)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(nf4, long long)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(nf4, unsigned long long)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(nf4, float8_e4m3)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(nf4, float8_e5m2)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(nf4, float8_e8m0)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(nf4, float16)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(nf4, bfloat16)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(nf4, float)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(nf4, double)--CONSTANT_WRITE_BUFFER_SPECIALIZATION(f4e2m1, bool)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(f4e2m1, char)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(f4e2m1, signed char)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(f4e2m1, unsigned char)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(f4e2m1, short)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(f4e2m1, unsigned short)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(f4e2m1, int)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(f4e2m1, unsigned int)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(f4e2m1, long)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(f4e2m1, unsigned long)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(f4e2m1, long long)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(f4e2m1, unsigned long long)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(f4e2m1, float8_e4m3)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(f4e2m1, float8_e5m2)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(f4e2m1, float8_e8m0)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(f4e2m1, float16)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(f4e2m1, bfloat16)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(f4e2m1, float)-CONSTANT_WRITE_BUFFER_SPECIALIZATION(f4e2m1, double)--#undef CONSTANT_WRITE_BUFFER_SPECIALIZATION--template <>-OPENVINO_API std::vector<bool> Constant::cast_vector(int64_t num_elements) const;-template <>-OPENVINO_API std::vector<char> Constant::cast_vector(int64_t num_elements) const;-template <>-OPENVINO_API std::vector<signed char> Constant::cast_vector(int64_t num_elements) const;-template <>-OPENVINO_API std::vector<unsigned char> Constant::cast_vector(int64_t num_elements) const;-template <>-OPENVINO_API std::vector<short> Constant::cast_vector(int64_t num_elements) const;-template <>-OPENVINO_API std::vector<unsigned short> Constant::cast_vector(int64_t num_elements) const;-template <>-OPENVINO_API std::vector<int> Constant::cast_vector(int64_t num_elements) const;-template <>-OPENVINO_API std::vector<unsigned int> Constant::cast_vector(int64_t num_elements) const;-template <>-OPENVINO_API std::vector<long> Constant::cast_vector(int64_t num_elements) const;-template <>-OPENVINO_API std::vector<unsigned long> Constant::cast_vector(int64_t num_elements) const;-template <>-OPENVINO_API std::vector<long long> Constant::cast_vector(int64_t num_elements) const;-template <>-OPENVINO_API std::vector<unsigned long long> Constant::cast_vector(int64_t num_elements) const;-template <>-OPENVINO_API std::vector<float16> Constant::cast_vector(int64_t num_elements) const;-template <>-OPENVINO_API std::vector<bfloat16> Constant::cast_vector(int64_t num_elements) const;-template <>-OPENVINO_API std::vector<float> Constant::cast_vector(int64_t num_elements) const;-template <>-OPENVINO_API std::vector<double> Constant::cast_vector(int64_t num_elements) const;+OPENVINO_API void Constant::data::cast_n(const element::Type& type, const void* src, const size_t n, pointer dst);} // namespace v0} // namespace opdiff --git a/src/core/src/op/constant.cpp b/src/core/src/op/constant.cppindex 5f361800852..3b6febca141 100644--- a/src/core/src/op/constant.cpp+++ b/src/core/src/op/constant.cpp@@ -23,9 +23,9 @@#include "openvino/runtime/shared_buffer.hpp"#include "openvino/runtime/string_aligned_buffer.hpp"#include "openvino/runtime/tensor.hpp"+#include "openvino/util/variant_visitor.hpp"-namespace ov {-namespace op {+namespace ov::op {#define SUPPORTED_ET \boolean, bf16, f16, f32, f64, i4, i8, i16, i32, i64, u1, u2, u3, u4, u6, u8, u16, u32, u64, nf4, f8e4m3, f8e5m2, \@@ -77,7 +77,7 @@ std::vector<T> from_string_vector(const std::vector<std::string>& str_values) {#ifdef __clang__# pragma clang diagnostic push-# ifdef __has_warning+# ifdef __has_warningop# if __has_warning("-Wimplicit-const-int-float-conversion")# pragma clang diagnostic ignored "-Wimplicit-const-int-float-conversion"# elif __has_warning("-Wimplicit-int-float-conversion")@@ -93,21 +93,74 @@ std::vector<T> from_string_vector(const std::vector<std::string>& str_values) {# pragma warning(disable : 4018)# pragma warning(disable : 4804)#endif-template <- class U,- class ConstantT,- typename std::enable_if<!std::is_unsigned<ConstantT>::value && !std::is_same<U, ConstantT>::value>::type* = nullptr>-static bool in_type_range(const ConstantT v) {- return std::numeric_limits<U>::lowest() <= v && v <= std::numeric_limits<U>::max();+template <element::Type_t ET, class U>+bool in_t_range(const U& v) {+ // return true;+ using ConstantT = fundamental_type_for<ET>;+ if constexpr (ET == element::u1) {+ return true;+ } else if constexpr (ET == element::u2) {+ const auto temp = static_cast<ConstantT>(v);+ return 0 <= temp && temp <= 3;+ } else if constexpr (ET == element::u3) {+ const auto temp = static_cast<ConstantT>(v);+ return 0 <= temp && temp <= 7;+ } else if constexpr (ET == element::u4 || (ET == element::nf4 && std::is_integral_v<U>)) {+ const auto temp = static_cast<ConstantT>(v);+ return 0 <= temp && temp <= 15;+ } else if constexpr (ET == element::u6) {+ const auto temp = static_cast<ConstantT>(v);+ return 0 <= temp && temp <= 63;+ } else if constexpr (ET == element::i4) {+ const auto temp = static_cast<ConstantT>(v);+ return -8 <= temp && temp <= 7;+ } else if (ET == element::nf4 && !std::is_integral_v<U>) {+ return true;+ } else if (ET == element::f4e2m1) {+ return true;+ } else if constexpr (std::is_same_v<U, ConstantT>) {+ return true;+ } else if constexpr (std::is_unsigned_v<ConstantT> && std::is_integral_v<U>) {+ if constexpr (std::numeric_limits<ConstantT>::max() < std::numeric_limits<U>::max()) {+ return true;+ } else {+ return v <= std::numeric_limits<U>::max();+ }+ } else if constexpr (std::is_unsigned_v<ConstantT>) {+ return v <= std::numeric_limits<U>::max();+ } else if constexpr (std::is_integral_v<ConstantT> && std::is_integral_v<U>) {+ if constexpr (std::numeric_limits<U>::lowest() < std::numeric_limits<ConstantT>::lowest() &&+ std::numeric_limits<U>::max() > std::numeric_limits<ConstantT>::max()) {+ return true;+ } else if constexpr (std::numeric_limits<ConstantT>::lowest() < std::numeric_limits<U>::lowest() &&+ std::numeric_limits<U>::max() <= std::numeric_limits<ConstantT>::max()) {+ return std::numeric_limits<U>::lowest() <= v;+ } else if constexpr (std::numeric_limits<ConstantT>::lowest() >= std::numeric_limits<U>::lowest() &&+ std::numeric_limits<U>::max() > std::numeric_limits<ConstantT>::max()) {+ return v <= std::numeric_limits<U>::max();+ } else {+ return std::numeric_limits<U>::lowest() <= v && v <= std::numeric_limits<U>::max();+ }+ } else {+ return std::numeric_limits<U>::lowest() <= v && v <= std::numeric_limits<U>::max();+ }}-template <- class U,- class ConstantT,- typename std::enable_if<std::is_unsigned<ConstantT>::value && !std::is_same<U, ConstantT>::value>::type* = nullptr>-static bool in_type_range(const ConstantT v) {- return v <= std::numeric_limits<U>::max();+template <element::Type_t ET, class U, bool enable_validation = true>+std::conditional_t<ET == element::nf4 && !std::is_integral_v<U>, float, fundamental_type_for<ET>> convert_if_in_range(+ const U& value) {+ if constexpr (enable_validation) {+ OPENVINO_ASSERT(in_t_range<ET>(value), value, " assigned value out of range for ", ET);+ }+ if constexpr (ET == element::u1) {+ return static_cast<fundamental_type_for<ET>>(static_cast<bool>(value));+ } else if constexpr (ET == element::nf4 && !std::is_integral_v<U>) {+ return static_cast<float>(value);+ } else {+ return static_cast<fundamental_type_for<ET>>(value);+ }}+#if defined(__clang__)# pragma clang diagnostic pop#elif defined(__GNUC__)@@ -116,78 +169,6 @@ static bool in_type_range(const ConstantT v) {# pragma warning(pop)#endif-template <element::Type_t ET, class U, typename std::enable_if<ET == element::u1>::type* = nullptr>-fundamental_type_for<ET> convert_if_in_element_range(const U& value) {- using T = fundamental_type_for<ET>;- return static_cast<T>(static_cast<bool>(value));-}--template <element::Type_t ET,- class U,- typename std::enable_if<ET == element::nf4 && !std::is_integral<U>::value>::type* = nullptr>-float convert_if_in_element_range(const U& value) {- return static_cast<float>(value);-}--template <- element::Type_t ET,- class U,- typename std::enable_if<ET == element::u4 || (ET == element::nf4 && std::is_integral<U>::value)>::type* = nullptr>-fundamental_type_for<ET> convert_if_in_element_range(const U& value) {- using T = fundamental_type_for<ET>;- auto result = static_cast<T>(value);- OPENVINO_ASSERT(0 <= result && result <= 15, "assigned value out of range for u4");- return result;-}--template <element::Type_t ET, class U, typename std::enable_if<ET == element::i4>::type* = nullptr>-fundamental_type_for<ET> convert_if_in_element_range(const U& value) {- using T = fundamental_type_for<ET>;- auto result = static_cast<T>(value);- OPENVINO_ASSERT(-8 <= result && result <= 7, "assigned value out of range for i4");- return result;-}--template <element::Type_t ET, class U, typename std::enable_if<ET == element::u2>::type* = nullptr>-fundamental_type_for<ET> convert_if_in_element_range(const U& value) {- using T = fundamental_type_for<ET>;- auto result = static_cast<T>(value);- OPENVINO_ASSERT(0 <= result && result <= 3, "assigned value out of range for u2");- return result;-}--template <element::Type_t ET, class U, typename std::enable_if<ET == element::u3>::type* = nullptr>-fundamental_type_for<ET> convert_if_in_element_range(const U& value) {- using T = fundamental_type_for<ET>;- auto result = static_cast<T>(value);- OPENVINO_ASSERT(0 <= result && result <= 7, "assigned value out of range for u3");- return result;-}--template <element::Type_t ET, class U, typename std::enable_if<ET == element::u6>::type* = nullptr>-fundamental_type_for<ET> convert_if_in_element_range(const U& value) {- using T = fundamental_type_for<ET>;- auto result = static_cast<T>(value);- OPENVINO_ASSERT(0 <= result && result <= 63, "assigned value out of range for u6");- return result;-}--template <element::Type_t ET, class U, typename std::enable_if<ET == element::f4e2m1>::type* = nullptr>-fundamental_type_for<ET> convert_if_in_element_range(const U& value) {- using T = fundamental_type_for<ET>;- return static_cast<T>(value);-}--template <element::Type_t ET, class T>-void fill_buffer(void* buffer, const Shape& shape, const T& value) {- std::fill_n(element::iterator<ET>(buffer), shape_size(shape), convert_if_in_element_range<ET>(value));-}--template <element::Type_t ET, class T>-void write_buffer(const std::vector<T>& source, void* buffer) {- std::transform(source.begin(), source.end(), element::iterator<ET>(buffer), convert_if_in_element_range<ET, T>);-}-Strides calc_byte_strides(const Shape& shape, const element::Type& et) {Strides strides;if (!shape.empty() && et.bitwidth() >= 8) {@@ -398,31 +379,7 @@ struct ValueToString : ov::element::NotSupported<std::string> {std::string Constant::convert_value_to_string(size_t index) const {using namespace ov::element;- return IfTypeOf<boolean,- bf16,- f16,- f32,- f64,- i4,- i8,- i16,- i32,- i64,- u1,- u2,- u3,- u4,- u6,- u8,- u16,- u32,- u64,- nf4,- f8e4m3,- f8e5m2,- string,- f4e2m1,- f8e8m0>::apply<ValueToString>(get_element_type(), get_data_ptr(), index);+ return IfTypeOf<SUPPORTED_ET, string>::apply<ValueToString>(get_element_type(), get_data_ptr(), index);}size_t Constant::get_byte_size() const {@@ -477,29 +434,7 @@ struct ValuesToString : ov::element::NotSupported<void> {std::vector<std::string> Constant::get_value_strings() const {std::vector<std::string> out;using namespace ov::element;- IfTypeOf<boolean,- bf16,- f16,- f32,- f64,- i4,- i8,- i16,- i32,- i64,- u1,- u2,- u3,- u4,- u6,- u8,- u16,- u32,- u64,- nf4,- string,- f4e2m1,- f8e8m0>::apply<ValuesToString>(get_element_type(), get_data_ptr(), shape_size(m_shape), out);+ IfTypeOf<SUPPORTED_ET, string>::apply<ValuesToString>(get_element_type(), get_data_ptr(), shape_size(m_shape), out);return out;}@@ -700,588 +635,120 @@ size_t Constant::get_num_elements_to_cast(const int64_t n) const {return (n < 0 ? num_elements_in_shape : std::min(static_cast<size_t>(n), num_elements_in_shape));}-template <>-Constant::LPBuffer<element::u1>::LPBuffer(void* ptr)- : iter{std::make_shared<lp_iter>(reinterpret_cast<ov::fundamental_type_for<element::u1>*>(ptr))} {}--template <>-Constant::LPBuffer<element::u2>::LPBuffer(void* ptr)- : iter{std::make_shared<lp_iter>(reinterpret_cast<ov::fundamental_type_for<element::u2>*>(ptr))} {}--template <>-Constant::LPBuffer<element::u3>::LPBuffer(void* ptr)- : iter{std::make_shared<lp_iter>(reinterpret_cast<ov::fundamental_type_for<element::u3>*>(ptr))} {}--template <>-Constant::LPBuffer<element::u4>::LPBuffer(void* ptr)- : iter{std::make_shared<lp_iter>(reinterpret_cast<ov::fundamental_type_for<element::u4>*>(ptr))} {}--template <>-Constant::LPBuffer<element::u6>::LPBuffer(void* ptr)- : iter{std::make_shared<lp_iter>(reinterpret_cast<ov::fundamental_type_for<element::u6>*>(ptr))} {}--template <>-Constant::LPBuffer<element::i4>::LPBuffer(void* ptr)- : iter{std::make_shared<lp_iter>(reinterpret_cast<ov::fundamental_type_for<element::i4>*>(ptr))} {}--template <>-Constant::LPBuffer<element::nf4>::LPBuffer(void* ptr)- : iter{std::make_shared<lp_iter>(reinterpret_cast<ov::fundamental_type_for<element::nf4>*>(ptr))} {}--template <>-Constant::LPBuffer<element::f4e2m1>::LPBuffer(void* ptr)- : iter{std::make_shared<lp_iter>(reinterpret_cast<ov::fundamental_type_for<element::f4e2m1>*>(ptr))} {}--template <>-void Constant::LPBuffer<element::u1>::write(const float value) {- iter->operator*() = convert_if_in_element_range<element::u1>(value);-}--template <>-void Constant::LPBuffer<element::u2>::write(const float value) {- iter->operator*() = convert_if_in_element_range<element::u2>(value);-}--template <>-void Constant::LPBuffer<element::u3>::write(const float value) {- iter->operator*() = convert_if_in_element_range<element::u3>(value);-}--template <>-void Constant::LPBuffer<element::u4>::write(const float value) {- iter->operator*() = convert_if_in_element_range<element::u4>(value);-}--template <>-void Constant::LPBuffer<element::u6>::write(const float value) {- iter->operator*() = convert_if_in_element_range<element::u6>(value);-}--template <>-void Constant::LPBuffer<element::i4>::write(const float value) {- iter->operator*() = convert_if_in_element_range<element::i4>(value);-}--template <>-void Constant::LPBuffer<element::nf4>::write(const float value) {- iter->operator*() = convert_if_in_element_range<element::nf4>(value);-}--template <>-void Constant::LPBuffer<element::f4e2m1>::write(const float value) {- iter->operator*() = convert_if_in_element_range<element::f4e2m1>(value);-}--template <>-ov::fundamental_type_for<element::u1> Constant::LPBuffer<element::u1>::read() const {- return iter->operator*();-}--template <>-ov::fundamental_type_for<element::u2> Constant::LPBuffer<element::u2>::read() const {- return iter->operator*();-}--template <>-ov::fundamental_type_for<element::u3> Constant::LPBuffer<element::u3>::read() const {- return iter->operator*();-}--template <>-ov::fundamental_type_for<element::u4> Constant::LPBuffer<element::u4>::read() const {- return iter->operator*();-}--template <>-ov::fundamental_type_for<element::u6> Constant::LPBuffer<element::u6>::read() const {- return iter->operator*();-}--template <>-ov::fundamental_type_for<element::i4> Constant::LPBuffer<element::i4>::read() const {- return iter->operator*();-}--template <>-ov::fundamental_type_for<element::nf4> Constant::LPBuffer<element::nf4>::read() const {- return iter->operator*();-}--template <>-ov::fundamental_type_for<element::f4e2m1> Constant::LPBuffer<element::f4e2m1>::read() const {- return iter->operator*();-}--template <>-Constant::LPBuffer<element::u1>& Constant::LPBuffer<element::u1>::operator++() {- iter->operator++();- return *this;-}--template <>-Constant::LPBuffer<element::u2>& Constant::LPBuffer<element::u2>::operator++() {- iter->operator++();- return *this;-}--template <>-Constant::LPBuffer<element::u3>& Constant::LPBuffer<element::u3>::operator++() {- iter->operator++();- return *this;-}--template <>-Constant::LPBuffer<element::u4>& Constant::LPBuffer<element::u4>::operator++() {- iter->operator++();- return *this;-}--template <>-Constant::LPBuffer<element::u6>& Constant::LPBuffer<element::u6>::operator++() {- iter->operator++();- return *this;-}--template <>-Constant::LPBuffer<element::i4>& Constant::LPBuffer<element::i4>::operator++() {- iter->operator++();- return *this;-}--template <>-Constant::LPBuffer<element::nf4>& Constant::LPBuffer<element::nf4>::operator++() {- iter->operator++();- return *this;-}--template <>-Constant::LPBuffer<element::f4e2m1>& Constant::LPBuffer<element::f4e2m1>::operator++() {- iter->operator++();- return *this;-}--#define CONSTANT_FILL_DATA(ET, SRC_TYPE) \- template <> \- void Constant::fill_lp_data<element::Type_t::ET>(const SRC_TYPE& value) { \- ov::op::fill_buffer<element::ET>(get_data_ptr_nc(), m_shape, value); \- }+struct ConstCast : element::NotSupported<void> {+ using element::NotSupported<void>::visit;-CONSTANT_FILL_DATA(u1, bool)-CONSTANT_FILL_DATA(u1, char)-CONSTANT_FILL_DATA(u1, signed char)-CONSTANT_FILL_DATA(u1, unsigned char)-CONSTANT_FILL_DATA(u1, short)-CONSTANT_FILL_DATA(u1, unsigned short)-CONSTANT_FILL_DATA(u1, int)-CONSTANT_FILL_DATA(u1, unsigned int)-CONSTANT_FILL_DATA(u1, long)-CONSTANT_FILL_DATA(u1, unsigned long)-CONSTANT_FILL_DATA(u1, long long)-CONSTANT_FILL_DATA(u1, unsigned long long)-CONSTANT_FILL_DATA(u1, float8_e4m3)-CONSTANT_FILL_DATA(u1, float8_e5m2)-CONSTANT_FILL_DATA(u1, float8_e8m0)-CONSTANT_FILL_DATA(u1, float16)-CONSTANT_FILL_DATA(u1, bfloat16)-CONSTANT_FILL_DATA(u1, float)-CONSTANT_FILL_DATA(u1, double)--CONSTANT_FILL_DATA(u2, bool)-CONSTANT_FILL_DATA(u2, char)-CONSTANT_FILL_DATA(u2, signed char)-CONSTANT_FILL_DATA(u2, unsigned char)-CONSTANT_FILL_DATA(u2, short)-CONSTANT_FILL_DATA(u2, unsigned short)-CONSTANT_FILL_DATA(u2, int)-CONSTANT_FILL_DATA(u2, unsigned int)-CONSTANT_FILL_DATA(u2, long)-CONSTANT_FILL_DATA(u2, unsigned long)-CONSTANT_FILL_DATA(u2, long long)-CONSTANT_FILL_DATA(u2, unsigned long long)-CONSTANT_FILL_DATA(u2, float8_e4m3)-CONSTANT_FILL_DATA(u2, float8_e5m2)-CONSTANT_FILL_DATA(u2, float8_e8m0)-CONSTANT_FILL_DATA(u2, float16)-CONSTANT_FILL_DATA(u2, bfloat16)-CONSTANT_FILL_DATA(u2, float)-CONSTANT_FILL_DATA(u2, double)--CONSTANT_FILL_DATA(u3, bool)-CONSTANT_FILL_DATA(u3, char)-CONSTANT_FILL_DATA(u3, signed char)-CONSTANT_FILL_DATA(u3, unsigned char)-CONSTANT_FILL_DATA(u3, short)-CONSTANT_FILL_DATA(u3, unsigned short)-CONSTANT_FILL_DATA(u3, int)-CONSTANT_FILL_DATA(u3, unsigned int)-CONSTANT_FILL_DATA(u3, long)-CONSTANT_FILL_DATA(u3, unsigned long)-CONSTANT_FILL_DATA(u3, long long)-CONSTANT_FILL_DATA(u3, unsigned long long)-CONSTANT_FILL_DATA(u3, float8_e4m3)-CONSTANT_FILL_DATA(u3, float8_e5m2)-CONSTANT_FILL_DATA(u3, float8_e8m0)-CONSTANT_FILL_DATA(u3, float16)-CONSTANT_FILL_DATA(u3, bfloat16)-CONSTANT_FILL_DATA(u3, float)-CONSTANT_FILL_DATA(u3, double)--CONSTANT_FILL_DATA(u4, bool)-CONSTANT_FILL_DATA(u4, char)-CONSTANT_FILL_DATA(u4, signed char)-CONSTANT_FILL_DATA(u4, unsigned char)-CONSTANT_FILL_DATA(u4, short)-CONSTANT_FILL_DATA(u4, unsigned short)-CONSTANT_FILL_DATA(u4, int)-CONSTANT_FILL_DATA(u4, unsigned int)-CONSTANT_FILL_DATA(u4, long)-CONSTANT_FILL_DATA(u4, unsigned long)-CONSTANT_FILL_DATA(u4, long long)-CONSTANT_FILL_DATA(u4, unsigned long long)-CONSTANT_FILL_DATA(u4, float8_e4m3)-CONSTANT_FILL_DATA(u4, float8_e5m2)-CONSTANT_FILL_DATA(u4, float8_e8m0)-CONSTANT_FILL_DATA(u4, float16)-CONSTANT_FILL_DATA(u4, bfloat16)-CONSTANT_FILL_DATA(u4, float)-CONSTANT_FILL_DATA(u4, double)--CONSTANT_FILL_DATA(u6, bool)-CONSTANT_FILL_DATA(u6, char)-CONSTANT_FILL_DATA(u6, signed char)-CONSTANT_FILL_DATA(u6, unsigned char)-CONSTANT_FILL_DATA(u6, short)-CONSTANT_FILL_DATA(u6, unsigned short)-CONSTANT_FILL_DATA(u6, int)-CONSTANT_FILL_DATA(u6, unsigned int)-CONSTANT_FILL_DATA(u6, long)-CONSTANT_FILL_DATA(u6, unsigned long)-CONSTANT_FILL_DATA(u6, long long)-CONSTANT_FILL_DATA(u6, unsigned long long)-CONSTANT_FILL_DATA(u6, float8_e4m3)-CONSTANT_FILL_DATA(u6, float8_e5m2)-CONSTANT_FILL_DATA(u6, float8_e8m0)-CONSTANT_FILL_DATA(u6, float16)-CONSTANT_FILL_DATA(u6, bfloat16)-CONSTANT_FILL_DATA(u6, float)-CONSTANT_FILL_DATA(u6, double)--CONSTANT_FILL_DATA(i4, bool)-CONSTANT_FILL_DATA(i4, char)-CONSTANT_FILL_DATA(i4, signed char)-CONSTANT_FILL_DATA(i4, unsigned char)-CONSTANT_FILL_DATA(i4, short)-CONSTANT_FILL_DATA(i4, unsigned short)-CONSTANT_FILL_DATA(i4, int)-CONSTANT_FILL_DATA(i4, unsigned int)-CONSTANT_FILL_DATA(i4, long)-CONSTANT_FILL_DATA(i4, unsigned long)-CONSTANT_FILL_DATA(i4, long long)-CONSTANT_FILL_DATA(i4, unsigned long long)-CONSTANT_FILL_DATA(i4, float8_e4m3)-CONSTANT_FILL_DATA(i4, float8_e5m2)-CONSTANT_FILL_DATA(i4, float8_e8m0)-CONSTANT_FILL_DATA(i4, float16)-CONSTANT_FILL_DATA(i4, bfloat16)-CONSTANT_FILL_DATA(i4, float)-CONSTANT_FILL_DATA(i4, double)--CONSTANT_FILL_DATA(nf4, bool)-CONSTANT_FILL_DATA(nf4, char)-CONSTANT_FILL_DATA(nf4, signed char)-CONSTANT_FILL_DATA(nf4, unsigned char)-CONSTANT_FILL_DATA(nf4, short)-CONSTANT_FILL_DATA(nf4, unsigned short)-CONSTANT_FILL_DATA(nf4, int)-CONSTANT_FILL_DATA(nf4, unsigned int)-CONSTANT_FILL_DATA(nf4, long)-CONSTANT_FILL_DATA(nf4, unsigned long)-CONSTANT_FILL_DATA(nf4, long long)-CONSTANT_FILL_DATA(nf4, unsigned long long)-CONSTANT_FILL_DATA(nf4, float8_e4m3)-CONSTANT_FILL_DATA(nf4, float8_e5m2)-CONSTANT_FILL_DATA(nf4, float8_e8m0)-CONSTANT_FILL_DATA(nf4, float16)-CONSTANT_FILL_DATA(nf4, bfloat16)-CONSTANT_FILL_DATA(nf4, float)-CONSTANT_FILL_DATA(nf4, double)--CONSTANT_FILL_DATA(f4e2m1, bool)-CONSTANT_FILL_DATA(f4e2m1, char)-CONSTANT_FILL_DATA(f4e2m1, signed char)-CONSTANT_FILL_DATA(f4e2m1, unsigned char)-CONSTANT_FILL_DATA(f4e2m1, short)-CONSTANT_FILL_DATA(f4e2m1, unsigned short)-CONSTANT_FILL_DATA(f4e2m1, int)-CONSTANT_FILL_DATA(f4e2m1, unsigned int)-CONSTANT_FILL_DATA(f4e2m1, long)-CONSTANT_FILL_DATA(f4e2m1, unsigned long)-CONSTANT_FILL_DATA(f4e2m1, long long)-CONSTANT_FILL_DATA(f4e2m1, unsigned long long)-CONSTANT_FILL_DATA(f4e2m1, float8_e4m3)-CONSTANT_FILL_DATA(f4e2m1, float8_e5m2)-CONSTANT_FILL_DATA(f4e2m1, float8_e8m0)-CONSTANT_FILL_DATA(f4e2m1, float16)-CONSTANT_FILL_DATA(f4e2m1, bfloat16)-CONSTANT_FILL_DATA(f4e2m1, float)-CONSTANT_FILL_DATA(f4e2m1, double)--#undef CONSTANT_FILL_DATA--#define CONSTANT_WRITE_BUFFER(ET, SRC_TYPE) \- template <> \- void Constant::write_lp_buffer<element::Type_t::ET>(const std::vector<SRC_TYPE>& source) { \- ov::op::write_buffer<element::ET>(source, get_data_ptr_nc()); \+ template <element::Type_t ET, class OutputIt>+ static result_type visit(const void* src, const size_t n, OutputIt dst) {+ reference::convert(element::iterator<ET>(src), dst, n);}+};-CONSTANT_WRITE_BUFFER(u1, bool)-CONSTANT_WRITE_BUFFER(u1, char)-CONSTANT_WRITE_BUFFER(u1, signed char)-CONSTANT_WRITE_BUFFER(u1, unsigned char)-CONSTANT_WRITE_BUFFER(u1, short)-CONSTANT_WRITE_BUFFER(u1, unsigned short)-CONSTANT_WRITE_BUFFER(u1, int)-CONSTANT_WRITE_BUFFER(u1, unsigned int)-CONSTANT_WRITE_BUFFER(u1, long)-CONSTANT_WRITE_BUFFER(u1, unsigned long)-CONSTANT_WRITE_BUFFER(u1, long long)-CONSTANT_WRITE_BUFFER(u1, unsigned long long)-CONSTANT_WRITE_BUFFER(u1, float8_e4m3)-CONSTANT_WRITE_BUFFER(u1, float8_e5m2)-CONSTANT_WRITE_BUFFER(u1, float8_e8m0)-CONSTANT_WRITE_BUFFER(u1, float16)-CONSTANT_WRITE_BUFFER(u1, bfloat16)-CONSTANT_WRITE_BUFFER(u1, float)-CONSTANT_WRITE_BUFFER(u1, double)--CONSTANT_WRITE_BUFFER(u2, bool)-CONSTANT_WRITE_BUFFER(u2, char)-CONSTANT_WRITE_BUFFER(u2, signed char)-CONSTANT_WRITE_BUFFER(u2, unsigned char)-CONSTANT_WRITE_BUFFER(u2, short)-CONSTANT_WRITE_BUFFER(u2, unsigned short)-CONSTANT_WRITE_BUFFER(u2, int)-CONSTANT_WRITE_BUFFER(u2, unsigned int)-CONSTANT_WRITE_BUFFER(u2, long)-CONSTANT_WRITE_BUFFER(u2, unsigned long)-CONSTANT_WRITE_BUFFER(u2, long long)-CONSTANT_WRITE_BUFFER(u2, unsigned long long)-CONSTANT_WRITE_BUFFER(u2, float8_e4m3)-CONSTANT_WRITE_BUFFER(u2, float8_e5m2)-CONSTANT_WRITE_BUFFER(u2, float8_e8m0)-CONSTANT_WRITE_BUFFER(u2, float16)-CONSTANT_WRITE_BUFFER(u2, bfloat16)-CONSTANT_WRITE_BUFFER(u2, float)-CONSTANT_WRITE_BUFFER(u2, double)--CONSTANT_WRITE_BUFFER(u3, bool)-CONSTANT_WRITE_BUFFER(u3, char)-CONSTANT_WRITE_BUFFER(u3, signed char)-CONSTANT_WRITE_BUFFER(u3, unsigned char)-CONSTANT_WRITE_BUFFER(u3, short)-CONSTANT_WRITE_BUFFER(u3, unsigned short)-CONSTANT_WRITE_BUFFER(u3, int)-CONSTANT_WRITE_BUFFER(u3, unsigned int)-CONSTANT_WRITE_BUFFER(u3, long)-CONSTANT_WRITE_BUFFER(u3, unsigned long)-CONSTANT_WRITE_BUFFER(u3, long long)-CONSTANT_WRITE_BUFFER(u3, unsigned long long)-CONSTANT_WRITE_BUFFER(u3, float8_e4m3)-CONSTANT_WRITE_BUFFER(u3, float8_e5m2)-CONSTANT_WRITE_BUFFER(u3, float8_e8m0)-CONSTANT_WRITE_BUFFER(u3, float16)-CONSTANT_WRITE_BUFFER(u3, bfloat16)-CONSTANT_WRITE_BUFFER(u3, float)-CONSTANT_WRITE_BUFFER(u3, double)--CONSTANT_WRITE_BUFFER(u4, bool)-CONSTANT_WRITE_BUFFER(u4, char)-CONSTANT_WRITE_BUFFER(u4, signed char)-CONSTANT_WRITE_BUFFER(u4, unsigned char)-CONSTANT_WRITE_BUFFER(u4, short)-CONSTANT_WRITE_BUFFER(u4, unsigned short)-CONSTANT_WRITE_BUFFER(u4, int)-CONSTANT_WRITE_BUFFER(u4, unsigned int)-CONSTANT_WRITE_BUFFER(u4, long)-CONSTANT_WRITE_BUFFER(u4, unsigned long)-CONSTANT_WRITE_BUFFER(u4, long long)-CONSTANT_WRITE_BUFFER(u4, unsigned long long)-CONSTANT_WRITE_BUFFER(u4, float8_e4m3)-CONSTANT_WRITE_BUFFER(u4, float8_e5m2)-CONSTANT_WRITE_BUFFER(u4, float8_e8m0)-CONSTANT_WRITE_BUFFER(u4, float16)-CONSTANT_WRITE_BUFFER(u4, bfloat16)-CONSTANT_WRITE_BUFFER(u4, float)-CONSTANT_WRITE_BUFFER(u4, double)--CONSTANT_WRITE_BUFFER(u6, bool)-CONSTANT_WRITE_BUFFER(u6, char)-CONSTANT_WRITE_BUFFER(u6, signed char)-CONSTANT_WRITE_BUFFER(u6, unsigned char)-CONSTANT_WRITE_BUFFER(u6, short)-CONSTANT_WRITE_BUFFER(u6, unsigned short)-CONSTANT_WRITE_BUFFER(u6, int)-CONSTANT_WRITE_BUFFER(u6, unsigned int)-CONSTANT_WRITE_BUFFER(u6, long)-CONSTANT_WRITE_BUFFER(u6, unsigned long)-CONSTANT_WRITE_BUFFER(u6, long long)-CONSTANT_WRITE_BUFFER(u6, unsigned long long)-CONSTANT_WRITE_BUFFER(u6, float8_e4m3)-CONSTANT_WRITE_BUFFER(u6, float8_e5m2)-CONSTANT_WRITE_BUFFER(u6, float8_e8m0)-CONSTANT_WRITE_BUFFER(u6, float16)-CONSTANT_WRITE_BUFFER(u6, bfloat16)-CONSTANT_WRITE_BUFFER(u6, float)-CONSTANT_WRITE_BUFFER(u6, double)--CONSTANT_WRITE_BUFFER(i4, bool)-CONSTANT_WRITE_BUFFER(i4, char)-CONSTANT_WRITE_BUFFER(i4, signed char)-CONSTANT_WRITE_BUFFER(i4, unsigned char)-CONSTANT_WRITE_BUFFER(i4, short)-CONSTANT_WRITE_BUFFER(i4, unsigned short)-CONSTANT_WRITE_BUFFER(i4, int)-CONSTANT_WRITE_BUFFER(i4, unsigned int)-CONSTANT_WRITE_BUFFER(i4, long)-CONSTANT_WRITE_BUFFER(i4, unsigned long)-CONSTANT_WRITE_BUFFER(i4, long long)-CONSTANT_WRITE_BUFFER(i4, unsigned long long)-CONSTANT_WRITE_BUFFER(i4, float8_e4m3)-CONSTANT_WRITE_BUFFER(i4, float8_e5m2)-CONSTANT_WRITE_BUFFER(i4, float8_e8m0)-CONSTANT_WRITE_BUFFER(i4, float16)-CONSTANT_WRITE_BUFFER(i4, bfloat16)-CONSTANT_WRITE_BUFFER(i4, float)-CONSTANT_WRITE_BUFFER(i4, double)--CONSTANT_WRITE_BUFFER(nf4, bool)-CONSTANT_WRITE_BUFFER(nf4, char)-CONSTANT_WRITE_BUFFER(nf4, signed char)-CONSTANT_WRITE_BUFFER(nf4, unsigned char)-CONSTANT_WRITE_BUFFER(nf4, short)-CONSTANT_WRITE_BUFFER(nf4, unsigned short)-CONSTANT_WRITE_BUFFER(nf4, int)-CONSTANT_WRITE_BUFFER(nf4, unsigned int)-CONSTANT_WRITE_BUFFER(nf4, long)-CONSTANT_WRITE_BUFFER(nf4, unsigned long)-CONSTANT_WRITE_BUFFER(nf4, long long)-CONSTANT_WRITE_BUFFER(nf4, unsigned long long)-CONSTANT_WRITE_BUFFER(nf4, float8_e4m3)-CONSTANT_WRITE_BUFFER(nf4, float8_e5m2)-CONSTANT_WRITE_BUFFER(nf4, float8_e8m0)-CONSTANT_WRITE_BUFFER(nf4, float16)-CONSTANT_WRITE_BUFFER(nf4, bfloat16)-CONSTANT_WRITE_BUFFER(nf4, float)-CONSTANT_WRITE_BUFFER(nf4, double)--CONSTANT_WRITE_BUFFER(f4e2m1, bool)-CONSTANT_WRITE_BUFFER(f4e2m1, char)-CONSTANT_WRITE_BUFFER(f4e2m1, signed char)-CONSTANT_WRITE_BUFFER(f4e2m1, unsigned char)-CONSTANT_WRITE_BUFFER(f4e2m1, short)-CONSTANT_WRITE_BUFFER(f4e2m1, unsigned short)-CONSTANT_WRITE_BUFFER(f4e2m1, int)-CONSTANT_WRITE_BUFFER(f4e2m1, unsigned int)-CONSTANT_WRITE_BUFFER(f4e2m1, long)-CONSTANT_WRITE_BUFFER(f4e2m1, unsigned long)-CONSTANT_WRITE_BUFFER(f4e2m1, long long)-CONSTANT_WRITE_BUFFER(f4e2m1, unsigned long long)-CONSTANT_WRITE_BUFFER(f4e2m1, float8_e4m3)-CONSTANT_WRITE_BUFFER(f4e2m1, float8_e5m2)-CONSTANT_WRITE_BUFFER(f4e2m1, float8_e8m0)-CONSTANT_WRITE_BUFFER(f4e2m1, float16)-CONSTANT_WRITE_BUFFER(f4e2m1, bfloat16)-CONSTANT_WRITE_BUFFER(f4e2m1, float)-CONSTANT_WRITE_BUFFER(f4e2m1, double)--#undef CONSTANT_WRITE_BUFFER--template <class U>-struct ElementConvert : element::NotSupported<void> {+struct ConstFill : element::NotSupported<void> {using element::NotSupported<void>::visit;- template <element::Type_t ET,- class InputIt,- class OutputIt,- typename std::enable_if<ET != element::string>::type* = nullptr>- static result_type visit(const InputIt src, OutputIt dst, const size_t n) {- auto first = element::iterator<ET>(src);- reference::convert(first, dst, n);- }-- template <element::Type_t ET,- class InputIt,- class OutputIt,- typename std::enable_if<ET == element::string>::type* = nullptr>- [[noreturn]] static result_type visit(const InputIt, OutputIt, const size_t) {- OPENVINO_THROW("'cast_vector' does not support casting Constant of type ",- ET,- " into std::vector of ",- element::from<U>());+ template <element::Type_t ET, class T>+ static result_type visit(void* dst, const size_t n, const T& value) {+ std::fill_n(element::iterator<ET>(dst), n, convert_if_in_range<ET, T>(value));}};-template <>-struct ElementConvert<bool> : element::NotSupported<void> {+struct ConstWrite : element::NotSupported<void> {using element::NotSupported<void>::visit;- template <element::Type_t ET,- class InputIt,- class OutputIt,- typename std::enable_if<ET != element::string>::type* = nullptr>- static result_type visit(InputIt src, OutputIt dst, const size_t n) {- auto first = element::iterator<ET>(src);- using T = ov::fundamental_type_for<ET>;- std::transform(first, first + n, dst, [](const T v) {- return static_cast<bool>(v);- });- }-- template <element::Type_t ET,- class InputIt,- class OutputIt,- typename std::enable_if<ET == element::string>::type* = nullptr>- [[noreturn]] static result_type visit(InputIt, OutputIt, const size_t) {- OPENVINO_THROW("'cast_vector' does not support casting Constant of type ", ET, " into std::vector of boolean");+ template <element::Type_t ET, class InputIt>+ static result_type visit(const InputIt src, const size_t n, void* dst) {+ using T = std::decay_t<typename std::iterator_traits<InputIt>::value_type>;+ constexpr auto enable_validation = !element::is_byte_type(ET);+ std::transform(src, src + n, element::iterator<ET>(dst), convert_if_in_range<ET, T, enable_validation>);}};+template <class T, class = void>+struct has_indirection : std::false_type {};++template <class T>+struct has_indirection<T, std::void_t<decltype(*std::declval<T>())>> : std::true_type {};++template <class T>+constexpr bool has_indirection_v = has_indirection<T>::value;-#define CONSTANT_CAST_VECTOR(DTYPE) \- template <> \- OPENVINO_API std::vector<DTYPE> Constant::cast_vector(int64_t num_elements) const { \- std::vector<DTYPE> output(get_num_elements_to_cast(num_elements)); \- using namespace ov::element; \- IfTypeOf<SUPPORTED_ET>::apply<ElementConvert<DTYPE>>(m_element_type, \- get_data_ptr(), \- output.data(), \- output.size()); \- return output; \+const auto element_type_from_variant = ov::util::VariantVisitor{[](auto&& value) -> element::Type {+ if constexpr (has_indirection_v<decltype(value)>) {+ return element::from<std::decay_t<decltype(*value)>>();+ } else {+ return element::from<decltype(value)>();+ }+}};++template <>+OPENVINO_API void Constant::data::fill(const element::Type& type, void* dst, const size_t n, const value& value) {+ if (const auto is_str = (type == element::string); is_str == std::holds_alternative<std::string>(value)) {+ const auto fill_visitor =+ ov::util::VariantVisitor{[&type, dst, n](const auto& v) {+ using namespace ov::element;+ IfTypeOf<SUPPORTED_ET>::apply<ConstFill>(type, dst, n, v);+ },+ [dst, n](const std::string& v) {+ std::uninitialized_fill_n(element::iterator<element::string>(dst), n, v);+ }};+ std::visit(fill_visitor, value);+ } else {+ if (is_str) {+ std::uninitialized_fill_n(element::iterator<element::string>(dst), n, std::string{});+ }+ OPENVINO_THROW("Constant does not support writing elements of type '",+ std::visit(element_type_from_variant, value),+ "' into Constant of type '",+ type,+ "'");}+}template <>-OPENVINO_API std::vector<bool> Constant::cast_vector(int64_t num_elements) const {- std::vector<bool> output(get_num_elements_to_cast(num_elements));- using namespace ov::element;- IfTypeOf<SUPPORTED_ET>::apply<ElementConvert<bool>>(m_element_type, get_data_ptr(), output.begin(), output.size());- return output;+OPENVINO_API void Constant::data::copy_n(const element::Type& type,+ const const_pointer src,+ const size_t n,+ void* dst) {+ if (const auto is_str = (type == element::string); is_str == std::holds_alternative<const std::string*>(src)) {+ const auto write_visitor =+ ov::util::VariantVisitor{[&type, n, dst](const auto src) {+ using namespace ov::element;+ IfTypeOf<SUPPORTED_ET>::apply<ConstWrite>(type, src, n, dst);+ },+ [n, dst](const std::string* src) {+ std::uninitialized_copy_n(src, n, element::iterator<element::string>(dst));+ }};+ std::visit(write_visitor, src);+ } else {+ if (is_str) {+ std::uninitialized_fill_n(element::iterator<element::string>(dst), n, std::string{});+ }+ OPENVINO_THROW("Constant does not support writing elements of type '",+ std::visit(element_type_from_variant, src),+ "' into Constant of type '",+ type,+ "'");+ }}-CONSTANT_CAST_VECTOR(char)-CONSTANT_CAST_VECTOR(signed char)-CONSTANT_CAST_VECTOR(unsigned char)-CONSTANT_CAST_VECTOR(short)-CONSTANT_CAST_VECTOR(unsigned short)-CONSTANT_CAST_VECTOR(int)-CONSTANT_CAST_VECTOR(unsigned int)-CONSTANT_CAST_VECTOR(long)-CONSTANT_CAST_VECTOR(unsigned long)-CONSTANT_CAST_VECTOR(long long)-CONSTANT_CAST_VECTOR(unsigned long long)-CONSTANT_CAST_VECTOR(float16)-CONSTANT_CAST_VECTOR(bfloat16)-CONSTANT_CAST_VECTOR(float)-CONSTANT_CAST_VECTOR(double)-+template <>+OPENVINO_API void Constant::data::cast_n(const element::Type& type, const void* src, const size_t n, pointer dst) {+ const auto is_visitable = (type == element::string) == std::holds_alternative<std::string*>(dst);+ OPENVINO_ASSERT(is_visitable,+ "Constant does not support casting elements of type '",+ type,+ "' into std::vector of type '",+ std::visit(element_type_from_variant, dst),+ "'");+ const auto cast_visitor =+ ov::util::VariantVisitor{[&type, src, n](auto dst) {+ using namespace ov::element;+ IfTypeOf<SUPPORTED_ET>::apply<ConstCast>(type, src, n, dst);+ },+ [src, n](std::string* dst) {+ std::uninitialized_copy_n(element::iterator<element::string>(src), n, dst);+ }};+ std::visit(cast_visitor, dst);+}} // namespace v0-} // namespace op-} // namespace ov+} // namespace ov::op