Skip to content

Commit b5a8d80

Browse files
authoredFeb 8, 2025
Use OV RTTI for ConversionExtensions (#28834)
### Details: - Use OV RTTI for ConversionExtensions ### Tickets: - CVS-160510
1 parent ffc15bf commit b5a8d80

File tree

38 files changed

+105
-120
lines changed

38 files changed

+105
-120
lines changed
 

‎cmake/developer_package/compile_flags/os_flags.cmake

-1
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,6 @@ endfunction()
674674
# ov_target_link_libraries_as_system(<TARGET NAME> <PUBLIC | PRIVATE | INTERFACE> <target1 target2 ...>)
675675
#
676676
function(ov_target_link_libraries_as_system TARGET_NAME LINK_TYPE)
677-
message("Link to ${TARGET_NAME} using ${LINK_TYPE} the following ${ARGN}")
678677
target_link_libraries(${TARGET_NAME} ${LINK_TYPE} ${ARGN})
679678

680679
# include directories as SYSTEM

‎cmake/developer_package/ncc_naming_style/openvino.style

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# custom OpenVINO values
2-
CppMethod: '^(operator\W+|[a-z_\d]+|signaling_NaN|quiet_NaN|OPENVINO_OP)$'
2+
CppMethod: '^(operator\W+|[a-z_\d]+|signaling_NaN|quiet_NaN|OPENVINO_OP|OPENVINO_RTTI)$'
33
ClassName: '^([A-Z][\w]+|b?float16|float8_e4m3|float8_e5m2|float4_e2m1|float8_e8m0|numeric_limits|ngraph_error|stopwatch|unsupported_op)$'
44
StructName: '^([A-Z][\w]+|element_type_traits|hash|oi_pair|stat)$'
55
FunctionName: '^(operator\W+|[a-z_\d]+)|PrintTo$'
6-
Namespace: '^([a-z\d_]*|InferenceEngine)$'
7-
NamespaceAlias: '^([a-z\d_]+|InferenceEngine)$'
6+
Namespace: '^([a-z\d_]*)$'
7+
NamespaceAlias: '^([a-z\d_]+)$'
88
UnionName: '[A-Z][\w]+$'
99
TemplateTemplateParameter: '[A-Z][\w]+'
10-
NamespaceReference: '^([a-z\d_]+|InferenceEngine|GPUContextParams)$'
10+
NamespaceReference: '^([a-z\d_]+)$'
1111
TemplateNonTypeParameter: '^\w*$'
1212
ClassTemplate: '^([A-Z][\w]+|element_type_traits)$'
1313
TemplateTypeParameter: '^\w*$'

‎src/cmake/openvino.cmake

+11-1
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,18 @@ ov_add_vs_version_file(NAME ${TARGET_NAME} FILEDESCRIPTION "OpenVINO runtime lib
3636

3737
target_include_directories(${TARGET_NAME} PUBLIC
3838
$<BUILD_INTERFACE:${OpenVINO_SOURCE_DIR}/src/core/include>
39+
$<BUILD_INTERFACE:${OpenVINO_SOURCE_DIR}/src/inference/include>
40+
$<BUILD_INTERFACE:${OpenVINO_SOURCE_DIR}/src/frontends/common/include>)
41+
42+
# to be aligned with OpenVINO archive, where all headers are located in the same folder and
43+
# exposed via openvino::runtime
44+
target_include_directories(${TARGET_NAME} INTERFACE
3945
$<BUILD_INTERFACE:${OpenVINO_SOURCE_DIR}/src/frontends/common/include>
40-
$<BUILD_INTERFACE:${OpenVINO_SOURCE_DIR}/src/inference/include>)
46+
$<BUILD_INTERFACE:${OpenVINO_SOURCE_DIR}/src/frontends/onnx/frontend/include>
47+
$<BUILD_INTERFACE:${OpenVINO_SOURCE_DIR}/src/frontends/paddle/include>
48+
$<BUILD_INTERFACE:${OpenVINO_SOURCE_DIR}/src/frontends/pytorch/include>
49+
$<BUILD_INTERFACE:${OpenVINO_SOURCE_DIR}/src/frontends/tensorflow/include>
50+
$<BUILD_INTERFACE:${OpenVINO_SOURCE_DIR}/src/frontends/tensorflow_lite/include>)
4151

4252
target_link_libraries(${TARGET_NAME} PRIVATE openvino::reference
4353
openvino::shape_inference

‎src/core/include/openvino/core/extension.hpp

+12-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "openvino/core/core_visibility.hpp"
1212
#include "openvino/core/type.hpp"
13+
#include "openvino/core/rtti.hpp"
1314

1415
#define OPENVINO_EXTENSION_C_API OPENVINO_EXTERN_C OPENVINO_CORE_EXPORTS
1516
#define OPENVINO_EXTENSION_API OPENVINO_CORE_EXPORTS
@@ -24,6 +25,14 @@ class Extension;
2425
*/
2526
class OPENVINO_API Extension {
2627
public:
28+
_OPENVINO_HIDDEN_METHOD static const DiscreteTypeInfo& get_type_info_static() {
29+
static const ::ov::DiscreteTypeInfo type_info_static{"Extension"};
30+
return type_info_static;
31+
}
32+
virtual const DiscreteTypeInfo& get_type_info() const {
33+
return get_type_info_static();
34+
}
35+
2736
using Ptr = std::shared_ptr<Extension>;
2837

2938
virtual ~Extension();
@@ -37,15 +46,15 @@ class OPENVINO_API Extension {
3746
/**
3847
* @brief The entry point for library with OpenVINO extensions
3948
*
40-
* @param vector of extensions
49+
* @param ext of extensions
4150
*/
4251
OPENVINO_EXTENSION_C_API
43-
void OV_CREATE_EXTENSION(std::vector<ov::Extension::Ptr>&);
52+
void OV_CREATE_EXTENSION(std::vector<ov::Extension::Ptr>& ext);
4453

4554
/**
4655
* @brief Macro generates the entry point for the library
4756
*
48-
* @param vector of extensions
57+
* @param ext of extensions
4958
*/
5059
#define OPENVINO_CREATE_EXTENSIONS(extensions) \
5160
OPENVINO_EXTENSION_C_API void OV_CREATE_EXTENSION(std::vector<ov::Extension::Ptr>& ext); \

‎src/core/include/openvino/core/op_extension.hpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@ namespace ov {
1717
class OPENVINO_API BaseOpExtension : public Extension {
1818
public:
1919
using Ptr = std::shared_ptr<BaseOpExtension>;
20-
/**
21-
* @brief Returns the type info of operation
22-
*
23-
* @return ov::DiscreteTypeInfo
24-
*/
25-
virtual const ov::DiscreteTypeInfo& get_type_info() const = 0;
20+
2621
/**
2722
* @brief Method creates an OpenVINO operation
2823
*

‎src/core/include/openvino/core/preprocess/input_tensor_info.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class OPENVINO_API TensorInfoMemoryType : public RuntimeAttribute {
2020

2121
TensorInfoMemoryType() = default;
2222

23+
~TensorInfoMemoryType() override;
24+
2325
explicit TensorInfoMemoryType(const std::string& value) : value(value) {}
2426

2527
bool visit_attributes(AttributeVisitor& visitor) override {

‎src/core/include/openvino/core/rtti.hpp

-4
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,3 @@
9393
_OPENVINO_RTTI_WITH_TYPE_VERSION_PARENT, \
9494
_OPENVINO_RTTI_WITH_TYPE_VERSION, \
9595
_OPENVINO_RTTI_WITH_TYPE)(__VA_ARGS__))
96-
97-
/// Note: Please don't use this macros for new operations
98-
#define BWDCMP_RTTI_DECLARATION
99-
#define BWDCMP_RTTI_DEFINITION(CLASS)

‎src/core/include/openvino/core/shape.hpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,7 @@ OPENVINO_API
140140
std::ostream& operator<<(std::ostream& s, const Shape& shape);
141141

142142
template <>
143-
class OPENVINO_API AttributeAdapter<ov::Shape> : public IndirectVectorValueAccessor<ov::Shape, std::vector<int64_t>>
144-
145-
{
143+
class OPENVINO_API AttributeAdapter<ov::Shape> : public IndirectVectorValueAccessor<ov::Shape, std::vector<int64_t>> {
146144
public:
147145
OPENVINO_RTTI("AttributeAdapter<Shape>");
148146

‎src/core/include/openvino/core/type.hpp

+20-13
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,18 @@ struct OPENVINO_API DiscreteTypeInfo {
7777
OPENVINO_API
7878
std::ostream& operator<<(std::ostream& s, const DiscreteTypeInfo& info);
7979

80+
namespace frontend {
81+
class ConversionExtensionBase;
82+
} // frontend
83+
84+
template <typename T>
85+
constexpr bool use_ov_dynamic_cast() {
8086
#if defined(__ANDROID__) || defined(ANDROID)
81-
# define OPENVINO_DYNAMIC_CAST
87+
return true;
88+
#else
89+
return std::is_base_of_v<ov::frontend::ConversionExtensionBase, T>;
8290
#endif
91+
}
8392

8493
/// \brief Tests if value is a pointer/shared_ptr that can be statically cast to a
8594
/// Type*/shared_ptr<Type>
@@ -97,11 +106,10 @@ template <typename Type, typename Value>
97106
typename std::enable_if<std::is_convertible<decltype(static_cast<Type*>(std::declval<Value>())), Type*>::value,
98107
Type*>::type
99108
as_type(Value value) {
100-
#ifdef OPENVINO_DYNAMIC_CAST
101-
return ov::is_type<Type>(value) ? static_cast<Type*>(value) : nullptr;
102-
#else
103-
return dynamic_cast<Type*>(value);
104-
#endif
109+
if constexpr (use_ov_dynamic_cast<Type>())
110+
return is_type<Type>(value) ? static_cast<Type*>(value) : nullptr;
111+
else
112+
return dynamic_cast<Type*>(value);
105113
}
106114

107115
namespace util {
@@ -120,13 +128,12 @@ struct AsTypePtr<std::shared_ptr<In>> {
120128

121129
/// Casts a std::shared_ptr<Value> to a std::shared_ptr<Type> if it is of type
122130
/// Type, nullptr otherwise
123-
template <typename T, typename U>
124-
auto as_type_ptr(const U& value) -> decltype(::ov::util::AsTypePtr<U>::template call<T>(value)) {
125-
#ifdef OPENVINO_DYNAMIC_CAST
126-
return ::ov::util::AsTypePtr<U>::template call<T>(value);
127-
#else
128-
return std::dynamic_pointer_cast<T>(value);
129-
#endif
131+
template <typename Type, typename Value>
132+
auto as_type_ptr(const Value& value) -> decltype(::ov::util::AsTypePtr<Value>::template call<Type>(value)) {
133+
if constexpr (use_ov_dynamic_cast<Type>())
134+
return ::ov::util::AsTypePtr<Value>::template call<Type>(value);
135+
else
136+
return std::dynamic_pointer_cast<Type>(value);
130137
}
131138
} // namespace ov
132139

‎src/core/include/openvino/op/util/precision_sensitive_attribute.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class OPENVINO_API PrecisionSensitive : public RuntimeAttribute {
2727

2828
PrecisionSensitive() = default;
2929

30+
~PrecisionSensitive() override;
31+
3032
bool is_copyable() const override {
3133
return false;
3234
}

‎src/core/include/openvino/op/util/symbolic_info.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class OPENVINO_API SkipInvalidation : public RuntimeAttribute {
2828
public:
2929
OPENVINO_RTTI("SkipInvalidation", "0", RuntimeAttribute);
3030
SkipInvalidation() = default;
31+
~SkipInvalidation() override;
3132
bool is_copyable() const override {
3233
return false;
3334
}

‎src/core/src/op/util/precision_sensitive_attribute.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include "openvino/op/util/precision_sensitive_attribute.hpp"
66

7+
ov::PrecisionSensitive::~PrecisionSensitive() = default;
8+
79
void ov::mark_as_precision_sensitive(ov::Input<ov::Node> node_input) {
810
auto& rt_info = node_input.get_rt_info();
911
rt_info[PrecisionSensitive::get_type_info_static()] = PrecisionSensitive{};

‎src/core/src/op/util/symbolic_info.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include "openvino/op/util/multi_subgraph_base.hpp"
1010

11+
ov::SkipInvalidation::~SkipInvalidation() = default;
12+
1113
void ov::skip_invalidation(const ov::Output<ov::Node>& output) {
1214
output.get_tensor().get_rt_info()[ov::SkipInvalidation::get_type_info_static()] = nullptr;
1315
}

‎src/core/src/preprocess/pre_post_process.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ std::shared_ptr<Model> PrePostProcessor::build() {
205205
return function;
206206
}
207207

208+
// ------------------ TensorInfoMemoryType ----------------
209+
TensorInfoMemoryType::~TensorInfoMemoryType() = default;
210+
208211
// --------------------- InputTensorInfo ------------------
209212
InputTensorInfo::InputTensorInfo() : m_impl(std::unique_ptr<InputTensorInfoImpl>(new InputTensorInfoImpl())) {}
210213
InputTensorInfo::~InputTensorInfo() = default;

‎src/frontends/common/include/openvino/frontend/extension/conversion.hpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
namespace ov {
1212
namespace frontend {
1313

14-
class FRONTEND_API ConversionExtensionBase : public ov::Extension {
14+
class FRONTEND_API ConversionExtensionBase : public Extension {
1515
public:
16+
OPENVINO_RTTI("ConversionExtensionBase", "0", Extension);
17+
1618
using Ptr = std::shared_ptr<ConversionExtensionBase>;
1719
explicit ConversionExtensionBase(const std::string& op_type) : m_op_type(op_type) {}
1820

@@ -28,6 +30,8 @@ class FRONTEND_API ConversionExtensionBase : public ov::Extension {
2830

2931
class FRONTEND_API ConversionExtension : public ConversionExtensionBase {
3032
public:
33+
OPENVINO_RTTI("ConversionExtension", "", ConversionExtensionBase);
34+
3135
using Ptr = std::shared_ptr<ConversionExtension>;
3236
ConversionExtension(const std::string& op_type, const CreatorFunction& converter)
3337
: ConversionExtensionBase(op_type),

‎src/frontends/ir/src/frontend.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ void FrontEnd::add_extension(const ov::Extension::Ptr& ext) {
149149
if (std::dynamic_pointer_cast<ov::BaseOpExtension>(so_ext->extension())) {
150150
m_extensions.emplace_back(so_ext->extension());
151151
}
152-
} else if (std::dynamic_pointer_cast<ov::BaseOpExtension>(ext))
152+
} else if (std::dynamic_pointer_cast<ov::BaseOpExtension>(ext)) {
153153
m_extensions.emplace_back(ext);
154+
}
154155
}
155156

156157
InputModel::Ptr FrontEnd::load_impl(const std::vector<ov::Any>& variants) const {

‎src/frontends/jax/include/openvino/frontend/jax/extension/conversion.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ namespace ov {
1313
namespace frontend {
1414
namespace jax {
1515

16-
class JAX_FRONTEND_API ConversionExtension : public ConversionExtensionBase {
16+
class ConversionExtension : public ConversionExtensionBase {
1717
public:
18+
OPENVINO_RTTI("frontend::jax::ConversionExtension", "", ConversionExtensionBase);
19+
1820
using Ptr = std::shared_ptr<ConversionExtension>;
1921

2022
ConversionExtension() = delete;
@@ -27,8 +29,6 @@ class JAX_FRONTEND_API ConversionExtension : public ConversionExtensionBase {
2729
return m_converter;
2830
}
2931

30-
~ConversionExtension() override;
31-
3232
private:
3333
ov::frontend::CreatorFunction m_converter;
3434
};

‎src/frontends/jax/src/extensions.cpp

-7
This file was deleted.

‎src/frontends/jax/src/frontend.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,12 @@ std::shared_ptr<Model> FrontEnd::decode(const InputModel::Ptr& model) const {
122122
}
123123

124124
void FrontEnd::add_extension(const std::shared_ptr<ov::Extension>& extension) {
125-
if (auto conv_ext = std::dynamic_pointer_cast<ov::frontend::ConversionExtension>(extension)) {
125+
if (auto conv_ext = ov::as_type_ptr<ov::frontend::ConversionExtension>(extension)) {
126126
m_conversion_extensions.push_back(conv_ext);
127127
m_op_extension_translators[conv_ext->get_op_type()] = [=](const NodeContext& context) {
128128
return conv_ext->get_converter()(context);
129129
};
130-
} else if (auto conv_ext = std::dynamic_pointer_cast<ov::frontend::jax::ConversionExtension>(extension)) {
130+
} else if (auto conv_ext = ov::as_type_ptr<ov::frontend::jax::ConversionExtension>(extension)) {
131131
m_conversion_extensions.push_back(conv_ext);
132132
m_op_extension_translators[conv_ext->get_op_type()] = [=](const NodeContext& context) {
133133
return conv_ext->get_converter()(context);

‎src/frontends/onnx/frontend/include/openvino/frontend/onnx/extension/conversion.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
namespace ov {
1212
namespace frontend {
1313
namespace onnx {
14-
class ONNX_FRONTEND_API ConversionExtension : public ConversionExtensionBase {
14+
class ConversionExtension : public ConversionExtensionBase {
1515
public:
16+
OPENVINO_RTTI("frontend::onnx::ConversionExtension", "", ConversionExtensionBase);
17+
1618
using Ptr = std::shared_ptr<ConversionExtension>;
1719

1820
ConversionExtension(const std::string& op_type, const ov::frontend::CreatorFunction& converter)
@@ -26,8 +28,6 @@ class ONNX_FRONTEND_API ConversionExtension : public ConversionExtensionBase {
2628
m_domain{domain},
2729
m_converter(converter) {}
2830

29-
~ConversionExtension() override;
30-
3131
const std::string& get_domain() const {
3232
return m_domain;
3333
}
@@ -37,9 +37,10 @@ class ONNX_FRONTEND_API ConversionExtension : public ConversionExtensionBase {
3737
}
3838

3939
private:
40-
std::string m_domain = "";
40+
std::string m_domain;
4141
ov::frontend::CreatorFunction m_converter;
4242
};
43+
4344
} // namespace onnx
4445
} // namespace frontend
4546
} // namespace ov

‎src/frontends/onnx/frontend/src/core/graph.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ bool common_node_for_all_outputs(const ov::OutputVector& outputs) {
4444
OperatorsBridge register_extensions(OperatorsBridge& bridge,
4545
const std::vector<ov::frontend::ConversionExtensionBase::Ptr>& conversions) {
4646
for (const auto& extension : conversions) {
47-
if (const auto common_conv_ext = std::dynamic_pointer_cast<ov::frontend::ConversionExtension>(extension)) {
47+
if (const auto common_conv_ext = ov::as_type_ptr<ov::frontend::ConversionExtension>(extension)) {
4848
bridge.overwrite_operator(
4949
common_conv_ext->get_op_type(),
5050
"",
5151
[common_conv_ext](const ov::frontend::onnx::Node& node) -> ov::OutputVector {
5252
return common_conv_ext->get_converter()(ov::frontend::onnx::NodeContext(node));
5353
});
5454
} else if (const auto onnx_conv_ext =
55-
std::dynamic_pointer_cast<ov::frontend::onnx::ConversionExtension>(extension)) {
55+
ov::as_type_ptr<ov::frontend::onnx::ConversionExtension>(extension)) {
5656
bridge.overwrite_operator(onnx_conv_ext->get_op_type(),
5757
onnx_conv_ext->get_domain(),
5858
[onnx_conv_ext](const ov::frontend::onnx::Node& node) -> ov::OutputVector {

‎src/frontends/onnx/frontend/src/extensions.cpp

-7
This file was deleted.

‎src/frontends/onnx/frontend/src/frontend.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,9 @@ void FrontEnd::add_extension(const std::shared_ptr<ov::Extension>& extension) {
261261
} else if (const auto& so_ext = std::dynamic_pointer_cast<ov::detail::SOExtension>(extension)) {
262262
add_extension(so_ext->extension());
263263
m_other_extensions.push_back(so_ext);
264-
} else if (auto common_conv_ext = std::dynamic_pointer_cast<ov::frontend::ConversionExtension>(extension)) {
264+
} else if (auto common_conv_ext = ov::as_type_ptr<ov::frontend::ConversionExtension>(extension)) {
265265
m_extensions.conversions.push_back(common_conv_ext);
266-
} else if (const auto onnx_conv_ext = std::dynamic_pointer_cast<onnx::ConversionExtension>(extension)) {
266+
} else if (const auto onnx_conv_ext = ov::as_type_ptr<onnx::ConversionExtension>(extension)) {
267267
m_extensions.conversions.push_back(onnx_conv_ext);
268268
} else if (auto progress_reporter = std::dynamic_pointer_cast<ProgressReporterExtension>(extension)) {
269269
m_extensions.progress_reporter = progress_reporter;

‎src/frontends/paddle/include/openvino/frontend/paddle/extension/conversion.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ namespace ov {
1313
namespace frontend {
1414
namespace paddle {
1515

16-
class PADDLE_FRONTEND_API ConversionExtension : public ConversionExtensionBase {
16+
class ConversionExtension : public ConversionExtensionBase {
1717
public:
18+
OPENVINO_RTTI("frontend::paddle::ConversionExtension", "", ConversionExtensionBase);
19+
1820
using Ptr = std::shared_ptr<ConversionExtension>;
1921

2022
ConversionExtension() = delete;
@@ -23,8 +25,6 @@ class PADDLE_FRONTEND_API ConversionExtension : public ConversionExtensionBase {
2325
: ConversionExtensionBase(op_type),
2426
m_converter(converter) {}
2527

26-
~ConversionExtension() override;
27-
2828
const ov::frontend::CreatorFunctionNamed& get_converter() const {
2929
return m_converter;
3030
}

0 commit comments

Comments
 (0)