From 15fc2549c7bf5867b54723190c01a698ddaeb699 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Wed, 5 Feb 2025 13:45:22 +0100 Subject: [PATCH] Use OV RTTI for ConversionExtensions --- .../compile_flags/os_flags.cmake | 1 - src/cmake/openvino.cmake | 12 +++++++++++- src/core/include/openvino/core/extension.hpp | 15 ++++++++++++--- src/core/include/openvino/core/op_extension.hpp | 7 +------ .../core/preprocess/input_tensor_info.hpp | 2 ++ src/core/include/openvino/core/rtti.hpp | 4 ---- src/core/include/openvino/core/shape.hpp | 4 +--- src/core/include/openvino/core/type.hpp | 8 +++++++- .../op/util/precision_sensitive_attribute.hpp | 2 ++ .../include/openvino/op/util/symbolic_info.hpp | 1 + .../src/op/util/precision_sensitive_attribute.cpp | 2 ++ src/core/src/op/util/symbolic_info.cpp | 2 ++ src/core/src/preprocess/pre_post_process.cpp | 3 +++ .../openvino/frontend/extension/conversion.hpp | 12 +++++++++++- src/frontends/ir/src/frontend.cpp | 3 ++- .../frontend/jax/extension/conversion.hpp | 12 +++++++++--- src/frontends/jax/src/extensions.cpp | 7 ------- src/frontends/jax/src/frontend.cpp | 2 +- .../frontend/onnx/extension/conversion.hpp | 15 +++++++++++---- src/frontends/onnx/frontend/src/core/graph.cpp | 2 +- src/frontends/onnx/frontend/src/extensions.cpp | 7 ------- src/frontends/onnx/frontend/src/frontend.cpp | 2 +- .../frontend/paddle/extension/conversion.hpp | 12 +++++++++--- src/frontends/paddle/src/extensions.cpp | 7 ------- src/frontends/paddle/src/frontend.cpp | 2 +- src/frontends/paddle/tests/conversion.cpp | 2 +- .../frontend/pytorch/extension/conversion.hpp | 12 +++++++++--- src/frontends/pytorch/src/extensions.cpp | 7 ------- src/frontends/pytorch/src/frontend.cpp | 2 +- .../frontend/tensorflow/extension/conversion.hpp | 12 +++++++++--- .../tensorflow/src/extension/conversion.cpp | 9 --------- src/frontends/tensorflow/src/frontend.cpp | 3 +-- src/frontends/tensorflow/tests/conversion.cpp | 2 +- .../tensorflow_lite/extension/conversion.hpp | 12 +++++++++--- .../tensorflow_lite/src/extension/conversion.cpp | 9 --------- src/frontends/tensorflow_lite/src/frontend.cpp | 2 +- .../tensorflow_lite/tests/conversion.cpp | 2 +- 37 files changed, 123 insertions(+), 97 deletions(-) delete mode 100644 src/frontends/jax/src/extensions.cpp delete mode 100644 src/frontends/onnx/frontend/src/extensions.cpp delete mode 100644 src/frontends/paddle/src/extensions.cpp delete mode 100644 src/frontends/pytorch/src/extensions.cpp delete mode 100644 src/frontends/tensorflow/src/extension/conversion.cpp delete mode 100644 src/frontends/tensorflow_lite/src/extension/conversion.cpp diff --git a/cmake/developer_package/compile_flags/os_flags.cmake b/cmake/developer_package/compile_flags/os_flags.cmake index 429113efa9ddc5..b6edc57459707b 100644 --- a/cmake/developer_package/compile_flags/os_flags.cmake +++ b/cmake/developer_package/compile_flags/os_flags.cmake @@ -674,7 +674,6 @@ endfunction() # ov_target_link_libraries_as_system( ) # function(ov_target_link_libraries_as_system TARGET_NAME LINK_TYPE) - message("Link to ${TARGET_NAME} using ${LINK_TYPE} the following ${ARGN}") target_link_libraries(${TARGET_NAME} ${LINK_TYPE} ${ARGN}) # include directories as SYSTEM diff --git a/src/cmake/openvino.cmake b/src/cmake/openvino.cmake index f6cdb54417501d..273e32a1a0b061 100644 --- a/src/cmake/openvino.cmake +++ b/src/cmake/openvino.cmake @@ -36,8 +36,18 @@ ov_add_vs_version_file(NAME ${TARGET_NAME} FILEDESCRIPTION "OpenVINO runtime lib target_include_directories(${TARGET_NAME} PUBLIC $ + $ + $) + +# to be aligned with OpenVINO archive, where all headers are located in the same folder and +# exposed via openvino::runtime +target_include_directories(${TARGET_NAME} INTERFACE $ - $) + $ + $ + $ + $ + $) target_link_libraries(${TARGET_NAME} PRIVATE openvino::reference openvino::shape_inference diff --git a/src/core/include/openvino/core/extension.hpp b/src/core/include/openvino/core/extension.hpp index cbb1f65a61e572..ace5711b23432d 100644 --- a/src/core/include/openvino/core/extension.hpp +++ b/src/core/include/openvino/core/extension.hpp @@ -10,6 +10,7 @@ #include "openvino/core/core_visibility.hpp" #include "openvino/core/type.hpp" +#include "openvino/core/rtti.hpp" #define OPENVINO_EXTENSION_C_API OPENVINO_EXTERN_C OPENVINO_CORE_EXPORTS #define OPENVINO_EXTENSION_API OPENVINO_CORE_EXPORTS @@ -24,6 +25,14 @@ class Extension; */ class OPENVINO_API Extension { public: + _OPENVINO_HIDDEN_METHOD static const DiscreteTypeInfo& get_type_info_static() { + static const ::ov::DiscreteTypeInfo type_info_static{"Extension"}; + return type_info_static; + } + virtual const DiscreteTypeInfo& get_type_info() const { + return get_type_info_static(); + } + using Ptr = std::shared_ptr; virtual ~Extension(); @@ -37,15 +46,15 @@ class OPENVINO_API Extension { /** * @brief The entry point for library with OpenVINO extensions * - * @param vector of extensions + * @param ext of extensions */ OPENVINO_EXTENSION_C_API -void OV_CREATE_EXTENSION(std::vector&); +void OV_CREATE_EXTENSION(std::vector& ext); /** * @brief Macro generates the entry point for the library * - * @param vector of extensions + * @param ext of extensions */ #define OPENVINO_CREATE_EXTENSIONS(extensions) \ OPENVINO_EXTENSION_C_API void OV_CREATE_EXTENSION(std::vector& ext); \ diff --git a/src/core/include/openvino/core/op_extension.hpp b/src/core/include/openvino/core/op_extension.hpp index 930d733c196125..7416a4d7b8c276 100644 --- a/src/core/include/openvino/core/op_extension.hpp +++ b/src/core/include/openvino/core/op_extension.hpp @@ -17,12 +17,7 @@ namespace ov { class OPENVINO_API BaseOpExtension : public Extension { public: using Ptr = std::shared_ptr; - /** - * @brief Returns the type info of operation - * - * @return ov::DiscreteTypeInfo - */ - virtual const ov::DiscreteTypeInfo& get_type_info() const = 0; + /** * @brief Method creates an OpenVINO operation * diff --git a/src/core/include/openvino/core/preprocess/input_tensor_info.hpp b/src/core/include/openvino/core/preprocess/input_tensor_info.hpp index 1461e29705b965..55dd63f907b317 100644 --- a/src/core/include/openvino/core/preprocess/input_tensor_info.hpp +++ b/src/core/include/openvino/core/preprocess/input_tensor_info.hpp @@ -20,6 +20,8 @@ class OPENVINO_API TensorInfoMemoryType : public RuntimeAttribute { TensorInfoMemoryType() = default; + ~TensorInfoMemoryType() override; + explicit TensorInfoMemoryType(const std::string& value) : value(value) {} bool visit_attributes(AttributeVisitor& visitor) override { diff --git a/src/core/include/openvino/core/rtti.hpp b/src/core/include/openvino/core/rtti.hpp index 82973e1bb8e906..abf3f9f764104c 100644 --- a/src/core/include/openvino/core/rtti.hpp +++ b/src/core/include/openvino/core/rtti.hpp @@ -93,7 +93,3 @@ _OPENVINO_RTTI_WITH_TYPE_VERSION_PARENT, \ _OPENVINO_RTTI_WITH_TYPE_VERSION, \ _OPENVINO_RTTI_WITH_TYPE)(__VA_ARGS__)) - -/// Note: Please don't use this macros for new operations -#define BWDCMP_RTTI_DECLARATION -#define BWDCMP_RTTI_DEFINITION(CLASS) diff --git a/src/core/include/openvino/core/shape.hpp b/src/core/include/openvino/core/shape.hpp index fc55b2b8c73098..e10e7e33b1dc5d 100644 --- a/src/core/include/openvino/core/shape.hpp +++ b/src/core/include/openvino/core/shape.hpp @@ -140,9 +140,7 @@ OPENVINO_API std::ostream& operator<<(std::ostream& s, const Shape& shape); template <> -class OPENVINO_API AttributeAdapter : public IndirectVectorValueAccessor> - -{ +class OPENVINO_API AttributeAdapter : public IndirectVectorValueAccessor> { public: OPENVINO_RTTI("AttributeAdapter"); diff --git a/src/core/include/openvino/core/type.hpp b/src/core/include/openvino/core/type.hpp index 812208855fa7f3..5ad40a437a8e4a 100644 --- a/src/core/include/openvino/core/type.hpp +++ b/src/core/include/openvino/core/type.hpp @@ -118,9 +118,15 @@ struct AsTypePtr> { }; } // namespace util + +namespace frontend { +class ConversionExtensionBase; +} // frontend + /// Casts a std::shared_ptr to a std::shared_ptr if it is of type /// Type, nullptr otherwise -template +template >> auto as_type_ptr(const U& value) -> decltype(::ov::util::AsTypePtr::template call(value)) { #ifdef OPENVINO_DYNAMIC_CAST return ::ov::util::AsTypePtr::template call(value); diff --git a/src/core/include/openvino/op/util/precision_sensitive_attribute.hpp b/src/core/include/openvino/op/util/precision_sensitive_attribute.hpp index c9df3902db1b08..76dedfb34e8a78 100644 --- a/src/core/include/openvino/op/util/precision_sensitive_attribute.hpp +++ b/src/core/include/openvino/op/util/precision_sensitive_attribute.hpp @@ -27,6 +27,8 @@ class OPENVINO_API PrecisionSensitive : public RuntimeAttribute { PrecisionSensitive() = default; + ~PrecisionSensitive() override; + bool is_copyable() const override { return false; } diff --git a/src/core/include/openvino/op/util/symbolic_info.hpp b/src/core/include/openvino/op/util/symbolic_info.hpp index dfb3170b793937..aa0828257238e9 100644 --- a/src/core/include/openvino/op/util/symbolic_info.hpp +++ b/src/core/include/openvino/op/util/symbolic_info.hpp @@ -28,6 +28,7 @@ class OPENVINO_API SkipInvalidation : public RuntimeAttribute { public: OPENVINO_RTTI("SkipInvalidation", "0", RuntimeAttribute); SkipInvalidation() = default; + ~SkipInvalidation() override; bool is_copyable() const override { return false; } diff --git a/src/core/src/op/util/precision_sensitive_attribute.cpp b/src/core/src/op/util/precision_sensitive_attribute.cpp index 320972dfe40f29..71750fb25f0079 100644 --- a/src/core/src/op/util/precision_sensitive_attribute.cpp +++ b/src/core/src/op/util/precision_sensitive_attribute.cpp @@ -4,6 +4,8 @@ #include "openvino/op/util/precision_sensitive_attribute.hpp" +ov::PrecisionSensitive::~PrecisionSensitive() = default; + void ov::mark_as_precision_sensitive(ov::Input node_input) { auto& rt_info = node_input.get_rt_info(); rt_info[PrecisionSensitive::get_type_info_static()] = PrecisionSensitive{}; diff --git a/src/core/src/op/util/symbolic_info.cpp b/src/core/src/op/util/symbolic_info.cpp index a7de90d2d76e40..bddf386f4d116b 100644 --- a/src/core/src/op/util/symbolic_info.cpp +++ b/src/core/src/op/util/symbolic_info.cpp @@ -8,6 +8,8 @@ #include "openvino/op/util/multi_subgraph_base.hpp" +ov::SkipInvalidation::~SkipInvalidation() = default; + void ov::skip_invalidation(const ov::Output& output) { output.get_tensor().get_rt_info()[ov::SkipInvalidation::get_type_info_static()] = nullptr; } diff --git a/src/core/src/preprocess/pre_post_process.cpp b/src/core/src/preprocess/pre_post_process.cpp index 1d42462a40d0ed..a74eb8bc5ad835 100644 --- a/src/core/src/preprocess/pre_post_process.cpp +++ b/src/core/src/preprocess/pre_post_process.cpp @@ -205,6 +205,9 @@ std::shared_ptr PrePostProcessor::build() { return function; } +// ------------------ TensorInfoMemoryType ---------------- +TensorInfoMemoryType::~TensorInfoMemoryType() = default; + // --------------------- InputTensorInfo ------------------ InputTensorInfo::InputTensorInfo() : m_impl(std::unique_ptr(new InputTensorInfoImpl())) {} InputTensorInfo::~InputTensorInfo() = default; diff --git a/src/frontends/common/include/openvino/frontend/extension/conversion.hpp b/src/frontends/common/include/openvino/frontend/extension/conversion.hpp index 46f8ff1e793072..91445505b3b156 100644 --- a/src/frontends/common/include/openvino/frontend/extension/conversion.hpp +++ b/src/frontends/common/include/openvino/frontend/extension/conversion.hpp @@ -11,8 +11,10 @@ namespace ov { namespace frontend { -class FRONTEND_API ConversionExtensionBase : public ov::Extension { +class FRONTEND_API ConversionExtensionBase : public Extension { public: + OPENVINO_RTTI("ConversionExtensionBase", "0", Extension); + using Ptr = std::shared_ptr; explicit ConversionExtensionBase(const std::string& op_type) : m_op_type(op_type) {} @@ -28,6 +30,8 @@ class FRONTEND_API ConversionExtensionBase : public ov::Extension { class FRONTEND_API ConversionExtension : public ConversionExtensionBase { public: + OPENVINO_RTTI("ConversionExtension", "0", ConversionExtensionBase); + using Ptr = std::shared_ptr; ConversionExtension(const std::string& op_type, const CreatorFunction& converter) : ConversionExtensionBase(op_type), @@ -61,5 +65,11 @@ class FRONTEND_API ConversionExtension : public ConversionExtensionBase { CreatorFunctionNamedAndIndexed m_converter_named_and_indexed; }; +template ::value, bool>::type = true> +auto as_type_ptr(const Value& value) -> decltype(::ov::util::AsTypePtr::template call(value)) { + return std::dynamic_pointer_cast(value); +} + } // namespace frontend } // namespace ov diff --git a/src/frontends/ir/src/frontend.cpp b/src/frontends/ir/src/frontend.cpp index 0c9cfa8b8a2665..c5a5710cabfd7f 100644 --- a/src/frontends/ir/src/frontend.cpp +++ b/src/frontends/ir/src/frontend.cpp @@ -149,8 +149,9 @@ void FrontEnd::add_extension(const ov::Extension::Ptr& ext) { if (std::dynamic_pointer_cast(so_ext->extension())) { m_extensions.emplace_back(so_ext->extension()); } - } else if (std::dynamic_pointer_cast(ext)) + } else if (std::dynamic_pointer_cast(ext)) { m_extensions.emplace_back(ext); + } } InputModel::Ptr FrontEnd::load_impl(const std::vector& variants) const { diff --git a/src/frontends/jax/include/openvino/frontend/jax/extension/conversion.hpp b/src/frontends/jax/include/openvino/frontend/jax/extension/conversion.hpp index 2fb18cd4907fe1..b7baeed06a4349 100644 --- a/src/frontends/jax/include/openvino/frontend/jax/extension/conversion.hpp +++ b/src/frontends/jax/include/openvino/frontend/jax/extension/conversion.hpp @@ -13,8 +13,10 @@ namespace ov { namespace frontend { namespace jax { -class JAX_FRONTEND_API ConversionExtension : public ConversionExtensionBase { +class ConversionExtension : public ConversionExtensionBase { public: + OPENVINO_RTTI("JaxConversionExtension", "0", ConversionExtensionBase); + using Ptr = std::shared_ptr; ConversionExtension() = delete; @@ -27,12 +29,16 @@ class JAX_FRONTEND_API ConversionExtension : public ConversionExtensionBase { return m_converter; } - ~ConversionExtension() override; - private: ov::frontend::CreatorFunction m_converter; }; +template ::value, bool>::type = true> +auto as_type_ptr(const Value& value) -> decltype(::ov::util::AsTypePtr::template call(value)) { + return ::ov::util::AsTypePtr::template call(value); +} + } // namespace jax } // namespace frontend } // namespace ov diff --git a/src/frontends/jax/src/extensions.cpp b/src/frontends/jax/src/extensions.cpp deleted file mode 100644 index 0e0cc7c08ac17f..00000000000000 --- a/src/frontends/jax/src/extensions.cpp +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright (C) 2018-2025 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "openvino/frontend/jax/extension/conversion.hpp" - -ov::frontend::jax::ConversionExtension::~ConversionExtension() = default; diff --git a/src/frontends/jax/src/frontend.cpp b/src/frontends/jax/src/frontend.cpp index b2dec7bcada59f..32ae3bdd7187aa 100644 --- a/src/frontends/jax/src/frontend.cpp +++ b/src/frontends/jax/src/frontend.cpp @@ -127,7 +127,7 @@ void FrontEnd::add_extension(const std::shared_ptr& extension) { m_op_extension_translators[conv_ext->get_op_type()] = [=](const NodeContext& context) { return conv_ext->get_converter()(context); }; - } else if (auto conv_ext = std::dynamic_pointer_cast(extension)) { + } else if (auto conv_ext = as_type_ptr(extension)) { m_conversion_extensions.push_back(conv_ext); m_op_extension_translators[conv_ext->get_op_type()] = [=](const NodeContext& context) { return conv_ext->get_converter()(context); diff --git a/src/frontends/onnx/frontend/include/openvino/frontend/onnx/extension/conversion.hpp b/src/frontends/onnx/frontend/include/openvino/frontend/onnx/extension/conversion.hpp index e8d1c9aea23121..90cb2fee602425 100644 --- a/src/frontends/onnx/frontend/include/openvino/frontend/onnx/extension/conversion.hpp +++ b/src/frontends/onnx/frontend/include/openvino/frontend/onnx/extension/conversion.hpp @@ -11,8 +11,10 @@ namespace ov { namespace frontend { namespace onnx { -class ONNX_FRONTEND_API ConversionExtension : public ConversionExtensionBase { +class ConversionExtension : public ConversionExtensionBase { public: + OPENVINO_RTTI("OnnxConversionExtension", "0", ConversionExtensionBase); + using Ptr = std::shared_ptr; ConversionExtension(const std::string& op_type, const ov::frontend::CreatorFunction& converter) @@ -26,8 +28,6 @@ class ONNX_FRONTEND_API ConversionExtension : public ConversionExtensionBase { m_domain{domain}, m_converter(converter) {} - ~ConversionExtension() override; - const std::string& get_domain() const { return m_domain; } @@ -37,9 +37,16 @@ class ONNX_FRONTEND_API ConversionExtension : public ConversionExtensionBase { } private: - std::string m_domain = ""; + std::string m_domain; ov::frontend::CreatorFunction m_converter; }; + +template ::value, bool>::type = true> +auto as_type_ptr(const Value& value) -> decltype(::ov::util::AsTypePtr::template call(value)) { + return ::ov::util::AsTypePtr::template call(value); +} + } // namespace onnx } // namespace frontend } // namespace ov diff --git a/src/frontends/onnx/frontend/src/core/graph.cpp b/src/frontends/onnx/frontend/src/core/graph.cpp index d01a8f6249037b..acd66438c64d1d 100644 --- a/src/frontends/onnx/frontend/src/core/graph.cpp +++ b/src/frontends/onnx/frontend/src/core/graph.cpp @@ -52,7 +52,7 @@ OperatorsBridge register_extensions(OperatorsBridge& bridge, return common_conv_ext->get_converter()(ov::frontend::onnx::NodeContext(node)); }); } else if (const auto onnx_conv_ext = - std::dynamic_pointer_cast(extension)) { + as_type_ptr(extension)) { bridge.overwrite_operator(onnx_conv_ext->get_op_type(), onnx_conv_ext->get_domain(), [onnx_conv_ext](const ov::frontend::onnx::Node& node) -> ov::OutputVector { diff --git a/src/frontends/onnx/frontend/src/extensions.cpp b/src/frontends/onnx/frontend/src/extensions.cpp deleted file mode 100644 index 26c5f904479521..00000000000000 --- a/src/frontends/onnx/frontend/src/extensions.cpp +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright (C) 2018-2025 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "openvino/frontend/onnx/extension/conversion.hpp" - -ov::frontend::onnx::ConversionExtension::~ConversionExtension() = default; diff --git a/src/frontends/onnx/frontend/src/frontend.cpp b/src/frontends/onnx/frontend/src/frontend.cpp index 667cf8c51c4d5e..86a51f81f916e3 100644 --- a/src/frontends/onnx/frontend/src/frontend.cpp +++ b/src/frontends/onnx/frontend/src/frontend.cpp @@ -263,7 +263,7 @@ void FrontEnd::add_extension(const std::shared_ptr& extension) { m_other_extensions.push_back(so_ext); } else if (auto common_conv_ext = std::dynamic_pointer_cast(extension)) { m_extensions.conversions.push_back(common_conv_ext); - } else if (const auto onnx_conv_ext = std::dynamic_pointer_cast(extension)) { + } else if (const auto onnx_conv_ext = as_type_ptr(extension)) { m_extensions.conversions.push_back(onnx_conv_ext); } else if (auto progress_reporter = std::dynamic_pointer_cast(extension)) { m_extensions.progress_reporter = progress_reporter; diff --git a/src/frontends/paddle/include/openvino/frontend/paddle/extension/conversion.hpp b/src/frontends/paddle/include/openvino/frontend/paddle/extension/conversion.hpp index d1b32052eb08bb..5635b556dd636f 100644 --- a/src/frontends/paddle/include/openvino/frontend/paddle/extension/conversion.hpp +++ b/src/frontends/paddle/include/openvino/frontend/paddle/extension/conversion.hpp @@ -13,8 +13,10 @@ namespace ov { namespace frontend { namespace paddle { -class PADDLE_FRONTEND_API ConversionExtension : public ConversionExtensionBase { +class ConversionExtension : public ConversionExtensionBase { public: + OPENVINO_RTTI("PaddleConversionExtension", "0", ConversionExtensionBase); + using Ptr = std::shared_ptr; ConversionExtension() = delete; @@ -23,8 +25,6 @@ class PADDLE_FRONTEND_API ConversionExtension : public ConversionExtensionBase { : ConversionExtensionBase(op_type), m_converter(converter) {} - ~ConversionExtension() override; - const ov::frontend::CreatorFunctionNamed& get_converter() const { return m_converter; } @@ -33,6 +33,12 @@ class PADDLE_FRONTEND_API ConversionExtension : public ConversionExtensionBase { ov::frontend::CreatorFunctionNamed m_converter; }; +template ::value, bool>::type = true> +auto as_type_ptr(const Value& value) -> decltype(::ov::util::AsTypePtr::template call(value)) { + return ::ov::util::AsTypePtr::template call(value); +} + } // namespace paddle } // namespace frontend } // namespace ov diff --git a/src/frontends/paddle/src/extensions.cpp b/src/frontends/paddle/src/extensions.cpp deleted file mode 100644 index 98200d0584c779..00000000000000 --- a/src/frontends/paddle/src/extensions.cpp +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright (C) 2018-2025 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "openvino/frontend/paddle/extension/conversion.hpp" - -ov::frontend::paddle::ConversionExtension::~ConversionExtension() = default; diff --git a/src/frontends/paddle/src/frontend.cpp b/src/frontends/paddle/src/frontend.cpp index c20852ebff655d..b79af42691da5f 100644 --- a/src/frontends/paddle/src/frontend.cpp +++ b/src/frontends/paddle/src/frontend.cpp @@ -564,7 +564,7 @@ void FrontEnd::add_extension(const std::shared_ptr& extension) { m_op_translators[common_conv_ext->get_op_type()] = [=](const NodeContext& context) { return common_conv_ext->get_converter_named()(context); }; - } else if (const auto& paddle_conv_ext = std::dynamic_pointer_cast(extension)) { + } else if (const auto& paddle_conv_ext = as_type_ptr(extension)) { m_conversion_extensions.push_back(paddle_conv_ext); m_op_translators[paddle_conv_ext->get_op_type()] = [=](const NodeContext& context) { return paddle_conv_ext->get_converter()(context); diff --git a/src/frontends/paddle/tests/conversion.cpp b/src/frontends/paddle/tests/conversion.cpp index c2ad29a42a3303..dee29e5a7f78d9 100644 --- a/src/frontends/paddle/tests/conversion.cpp +++ b/src/frontends/paddle/tests/conversion.cpp @@ -18,7 +18,7 @@ class PaddleFrontendWrapper : public ov::frontend::paddle::FrontEnd { void add_extension(const std::shared_ptr& extension) override { ov::frontend::paddle::FrontEnd::add_extension(extension); - if (auto conv_ext = std::dynamic_pointer_cast(extension)) { + if (auto conv_ext = ov::as_type_ptr(extension)) { EXPECT_NE(std::find(m_conversion_extensions.begin(), m_conversion_extensions.end(), conv_ext), m_conversion_extensions.end()) << "ConversionExtension is not registered."; diff --git a/src/frontends/pytorch/include/openvino/frontend/pytorch/extension/conversion.hpp b/src/frontends/pytorch/include/openvino/frontend/pytorch/extension/conversion.hpp index cf1f8632045a46..f5d957e2f08d13 100644 --- a/src/frontends/pytorch/include/openvino/frontend/pytorch/extension/conversion.hpp +++ b/src/frontends/pytorch/include/openvino/frontend/pytorch/extension/conversion.hpp @@ -13,8 +13,10 @@ namespace ov { namespace frontend { namespace pytorch { -class PYTORCH_FRONTEND_API ConversionExtension : public ConversionExtensionBase { +class ConversionExtension : public ConversionExtensionBase { public: + OPENVINO_RTTI("PyTorchConversionExtension", "0", ConversionExtensionBase); + using Ptr = std::shared_ptr; ConversionExtension() = delete; @@ -27,12 +29,16 @@ class PYTORCH_FRONTEND_API ConversionExtension : public ConversionExtensionBase return m_converter; } - ~ConversionExtension() override; - private: ov::frontend::CreatorFunction m_converter; }; +template ::value, bool>::type = true> +auto as_type_ptr(const Value& value) -> decltype(::ov::util::AsTypePtr::template call(value)) { + return ::ov::util::AsTypePtr::template call(value); +} + } // namespace pytorch } // namespace frontend } // namespace ov diff --git a/src/frontends/pytorch/src/extensions.cpp b/src/frontends/pytorch/src/extensions.cpp deleted file mode 100644 index 333d4888a26bef..00000000000000 --- a/src/frontends/pytorch/src/extensions.cpp +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright (C) 2018-2025 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "openvino/frontend/pytorch/extension/conversion.hpp" - -ov::frontend::pytorch::ConversionExtension::~ConversionExtension() = default; diff --git a/src/frontends/pytorch/src/frontend.cpp b/src/frontends/pytorch/src/frontend.cpp index 29a81e65ea7647..a1811cecbe490c 100644 --- a/src/frontends/pytorch/src/frontend.cpp +++ b/src/frontends/pytorch/src/frontend.cpp @@ -365,7 +365,7 @@ void FrontEnd::add_extension(const std::shared_ptr& extension) { m_op_extension_translators[conv_ext->get_op_type()] = [=](const NodeContext& context) { return conv_ext->get_converter()(context); }; - } else if (auto conv_ext = std::dynamic_pointer_cast(extension)) { + } else if (auto conv_ext = as_type_ptr(extension)) { m_conversion_extensions.push_back(conv_ext); m_op_extension_translators[conv_ext->get_op_type()] = [=](const NodeContext& context) { return conv_ext->get_converter()(context); diff --git a/src/frontends/tensorflow/include/openvino/frontend/tensorflow/extension/conversion.hpp b/src/frontends/tensorflow/include/openvino/frontend/tensorflow/extension/conversion.hpp index cec9d2b872c345..4acba1dc02a8da 100644 --- a/src/frontends/tensorflow/include/openvino/frontend/tensorflow/extension/conversion.hpp +++ b/src/frontends/tensorflow/include/openvino/frontend/tensorflow/extension/conversion.hpp @@ -13,8 +13,10 @@ namespace ov { namespace frontend { namespace tensorflow { -class TENSORFLOW_FRONTEND_API ConversionExtension : public ConversionExtensionBase { +class ConversionExtension : public ConversionExtensionBase { public: + OPENVINO_RTTI("TenflowFlowConversionExtension", "0", ConversionExtensionBase); + using Ptr = std::shared_ptr; ConversionExtension() = delete; @@ -32,12 +34,16 @@ class TENSORFLOW_FRONTEND_API ConversionExtension : public ConversionExtensionBa return m_converter; } - ~ConversionExtension() override; - private: ov::frontend::tensorflow::CreatorFunction m_converter; }; +template ::value, bool>::type = true> +auto as_type_ptr(const Value& value) -> decltype(::ov::util::AsTypePtr::template call(value)) { + return ::ov::util::AsTypePtr::template call(value); +} + } // namespace tensorflow } // namespace frontend } // namespace ov diff --git a/src/frontends/tensorflow/src/extension/conversion.cpp b/src/frontends/tensorflow/src/extension/conversion.cpp deleted file mode 100644 index 57da7c04c2e0d5..00000000000000 --- a/src/frontends/tensorflow/src/extension/conversion.cpp +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (C) 2018-2025 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "openvino/frontend/tensorflow/extension/conversion.hpp" - -using namespace ov::frontend::tensorflow; - -ConversionExtension::~ConversionExtension() = default; diff --git a/src/frontends/tensorflow/src/frontend.cpp b/src/frontends/tensorflow/src/frontend.cpp index 86f96f48be8908..802f0777b9c19c 100644 --- a/src/frontends/tensorflow/src/frontend.cpp +++ b/src/frontends/tensorflow/src/frontend.cpp @@ -609,8 +609,7 @@ void FrontEnd::add_extension(const std::shared_ptr& extension) { } // Ignore other types of extensions in particular CreatorFunctionNamed which cannot be used with tensorflow // frontend - } else if (const auto& tensorflow_conv_ext = - std::dynamic_pointer_cast(extension)) { + } else if (const auto& tensorflow_conv_ext = as_type_ptr(extension)) { m_conversion_extensions.push_back(tensorflow_conv_ext); m_op_translators[tensorflow_conv_ext->get_op_type()] = tensorflow_conv_ext->get_converter(); } else if (auto op_base_ext = std::dynamic_pointer_cast(extension)) { diff --git a/src/frontends/tensorflow/tests/conversion.cpp b/src/frontends/tensorflow/tests/conversion.cpp index db95a045351779..4c8e9c54ba97c8 100644 --- a/src/frontends/tensorflow/tests/conversion.cpp +++ b/src/frontends/tensorflow/tests/conversion.cpp @@ -19,7 +19,7 @@ class TensorflowFrontendWrapper : public ov::frontend::tensorflow::FrontEnd { void add_extension(const std::shared_ptr& extension) override { ov::frontend::tensorflow::FrontEnd::add_extension(extension); - if (auto conv_ext = std::dynamic_pointer_cast(extension)) { + if (auto conv_ext = ov::as_type_ptr(extension)) { if (conv_ext->get_converter() || conv_ext->get_converter_named_and_indexed()) { EXPECT_NE(std::find(m_conversion_extensions.begin(), m_conversion_extensions.end(), conv_ext), m_conversion_extensions.end()) diff --git a/src/frontends/tensorflow_lite/include/openvino/frontend/tensorflow_lite/extension/conversion.hpp b/src/frontends/tensorflow_lite/include/openvino/frontend/tensorflow_lite/extension/conversion.hpp index 1f87626918277c..1381d14dec67ac 100644 --- a/src/frontends/tensorflow_lite/include/openvino/frontend/tensorflow_lite/extension/conversion.hpp +++ b/src/frontends/tensorflow_lite/include/openvino/frontend/tensorflow_lite/extension/conversion.hpp @@ -12,8 +12,10 @@ namespace ov { namespace frontend { namespace tensorflow_lite { -class TENSORFLOW_LITE_FRONTEND_API ConversionExtension : public ConversionExtensionBase { +class ConversionExtension : public ConversionExtensionBase { public: + OPENVINO_RTTI("TenslowFlowLiteConversionExtension", "0", ConversionExtensionBase); + using Ptr = std::shared_ptr; ConversionExtension() = delete; @@ -26,12 +28,16 @@ class TENSORFLOW_LITE_FRONTEND_API ConversionExtension : public ConversionExtens return m_converter; } - ~ConversionExtension() override; - private: ov::frontend::CreatorFunction m_converter; }; +template ::value, bool>::type = true> +auto as_type_ptr(const Value& value) -> decltype(::ov::util::AsTypePtr::template call(value)) { + return ::ov::util::AsTypePtr::template call(value); +} + } // namespace tensorflow_lite } // namespace frontend } // namespace ov diff --git a/src/frontends/tensorflow_lite/src/extension/conversion.cpp b/src/frontends/tensorflow_lite/src/extension/conversion.cpp deleted file mode 100644 index edbffb4c9f547a..00000000000000 --- a/src/frontends/tensorflow_lite/src/extension/conversion.cpp +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (C) 2018-2025 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "openvino/frontend/tensorflow_lite/extension/conversion.hpp" - -using namespace ov::frontend::tensorflow_lite; - -ConversionExtension::~ConversionExtension() = default; diff --git a/src/frontends/tensorflow_lite/src/frontend.cpp b/src/frontends/tensorflow_lite/src/frontend.cpp index 30cceeeb10b7dc..869b5d557438d5 100644 --- a/src/frontends/tensorflow_lite/src/frontend.cpp +++ b/src/frontends/tensorflow_lite/src/frontend.cpp @@ -318,7 +318,7 @@ void FrontEnd::add_extension(const std::shared_ptr& extension) { return common_conv_ext->get_converter()(context); }; } else if (const auto& tensorflow_conv_ext = - std::dynamic_pointer_cast(extension)) { + as_type_ptr(extension)) { m_conversion_extensions.push_back(tensorflow_conv_ext); m_op_translators[tensorflow_conv_ext->get_op_type()] = [=](const NodeContext& context) { return tensorflow_conv_ext->get_converter()(context); diff --git a/src/frontends/tensorflow_lite/tests/conversion.cpp b/src/frontends/tensorflow_lite/tests/conversion.cpp index 56484a0b9dcf47..b5101f8b968a8e 100644 --- a/src/frontends/tensorflow_lite/tests/conversion.cpp +++ b/src/frontends/tensorflow_lite/tests/conversion.cpp @@ -18,7 +18,7 @@ class TensorflowLiteFrontendWrapper : public ov::frontend::tensorflow_lite::Fron void add_extension(const std::shared_ptr& extension) override { ov::frontend::tensorflow_lite::FrontEnd::add_extension(extension); - if (auto conv_ext = std::dynamic_pointer_cast(extension)) { + if (auto conv_ext = ov::as_type_ptr(extension)) { EXPECT_NE(std::find(m_conversion_extensions.begin(), m_conversion_extensions.end(), conv_ext), m_conversion_extensions.end()) << "ConversionExtension is not registered.";