Skip to content

Commit 25910a7

Browse files
authored
[RTTI] Add helper macro for OV RTTI definition in base classes (openvinotoolkit#28911)
### Details: - Adds OPENVINO_RTTI_BASE helper macro which places type info getter member functions' definitions. - Adds interface IRtti class definition with pure abstract virtual type info getter to be a base of OV RTTI base class. This class can be expanded with type trait definition to drop [dependency from `core/type.hpp`](https://github.com/openvinotoolkit/openvino/blob/b5a8d8080b6002f24c02adfbba0ea62f3ecbb0a3/src/core/include/openvino/core/type.hpp#L98) ### Tickets: - CVS-162038 --------- Signed-off-by: Tomasz Jankowski <tomasz1.jankowski@intel.com>
1 parent df6161d commit 25910a7

File tree

6 files changed

+59
-44
lines changed

6 files changed

+59
-44
lines changed

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

+1-7
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,7 @@ class Extension;
2525
*/
2626
class OPENVINO_API Extension {
2727
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-
}
28+
OPENVINO_RTTI_BASE("Extension")
3529

3630
using Ptr = std::shared_ptr<Extension>;
3731

src/core/include/openvino/core/model.hpp

+1-7
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,7 @@ class OPENVINO_API Model : public std::enable_shared_from_this<Model> {
5151
std::shared_ptr<void> m_shared_object; // plugin shared object handle.
5252

5353
public:
54-
_OPENVINO_HIDDEN_METHOD static const ::ov::DiscreteTypeInfo& get_type_info_static() {
55-
static const ::ov::DiscreteTypeInfo type_info_static{"Model"};
56-
return type_info_static;
57-
}
58-
const ::ov::DiscreteTypeInfo& get_type_info() const {
59-
return get_type_info_static();
60-
}
54+
OPENVINO_RTTI_BASE("Model")
6155

6256
Model(const ov::NodeVector& results, const ov::ParameterVector& parameters, const std::string& name = "");
6357

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

+47-3
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,59 @@
8181
/// for all operations and doesn't provide ability to define some perfect subset of
8282
/// operations. PARENT_CLASS should define RTTI with OPENVINO_RTTI_{DECLARATION/DEFINITION}
8383
/// macros.
84-
/// \param _VERSION_INDEX is an unsigned integer index to distinguish different versions of
85-
/// operations that shares the same TYPE_NAME (for backward compatibility)
8684
///
8785
/// OPENVINO_RTTI(name)
8886
/// OPENVINO_RTTI(name, version_id)
8987
/// OPENVINO_RTTI(name, version_id, parent)
90-
/// OPENVINO_RTTI(name, version_id, parent, old_version)
88+
9189
#define OPENVINO_RTTI(...) \
9290
_OPENVINO_RTTI_EXPAND(_OPENVINO_RTTI_DEFINITION_SELECTOR_3(__VA_ARGS__, \
9391
_OPENVINO_RTTI_WITH_TYPE_VERSION_PARENT, \
9492
_OPENVINO_RTTI_WITH_TYPE_VERSION, \
9593
_OPENVINO_RTTI_WITH_TYPE)(__VA_ARGS__))
94+
95+
#define _OPENVINO_RTTI_BASE_WITH_TYPE(TYPE_NAME) _OPENVINO_RTTI_BASE_WITH_TYPE_VERSION(TYPE_NAME, "util")
96+
97+
#define _OPENVINO_RTTI_BASE_WITH_TYPE_VERSION(TYPE_NAME, VERSION_NAME) \
98+
_OPENVINO_HIDDEN_METHOD static const ::ov::DiscreteTypeInfo& get_type_info_static() { \
99+
static ::ov::DiscreteTypeInfo type_info_static{TYPE_NAME, VERSION_NAME}; \
100+
type_info_static.hash(); \
101+
return type_info_static; \
102+
} \
103+
virtual const ::ov::DiscreteTypeInfo& get_type_info() const { return get_type_info_static(); }
104+
105+
/// Helper macro for base (without rtti parrent) class that provides RTTI block definition.
106+
/// It's a two parameter version of OPENVINO_RTTI macro, without PARENT_CLASS.
107+
#define OPENVINO_RTTI_BASE(...) \
108+
_OPENVINO_RTTI_EXPAND(_OPENVINO_RTTI_DEFINITION_SELECTOR_2(__VA_ARGS__, \
109+
_OPENVINO_RTTI_BASE_WITH_TYPE_VERSION, \
110+
_OPENVINO_RTTI_BASE_WITH_TYPE)(__VA_ARGS__))
111+
112+
#if defined(__GNUC__)
113+
# define OPENVINO_DO_PRAGMA(x) _Pragma(#x)
114+
#elif defined(_MSC_VER)
115+
# define OPENVINO_DO_PRAGMA(x) __pragma(x)
116+
#else
117+
# define OPENVINO_DO_PRAGMA(x)
118+
#endif
119+
120+
#if defined(__clang__)
121+
# define OPENVINO_SUPPRESS_SUGGEST_OVERRIDE_START \
122+
OPENVINO_DO_PRAGMA(clang diagnostic push) \
123+
OPENVINO_DO_PRAGMA(clang diagnostic ignored "-Wsuggest-override") \
124+
OPENVINO_DO_PRAGMA(clang diagnostic ignored "-Winconsistent-missing-override")
125+
# define OPENVINO_SUPPRESS_SUGGEST_OVERRIDE_END OPENVINO_DO_PRAGMA(clang diagnostic pop)
126+
#elif (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ > 405))
127+
# define OPENVINO_SUPPRESS_SUGGEST_OVERRIDE_START \
128+
OPENVINO_DO_PRAGMA(GCC diagnostic push) \
129+
OPENVINO_DO_PRAGMA(GCC diagnostic ignored "-Wsuggest-override")
130+
# define OPENVINO_SUPPRESS_SUGGEST_OVERRIDE_END OPENVINO_DO_PRAGMA(GCC diagnostic pop)
131+
#elif defined(_MSC_VER)
132+
# define OPENVINO_SUPPRESS_SUGGEST_OVERRIDE_START \
133+
OPENVINO_DO_PRAGMA(warning(push)) \
134+
OPENVINO_DO_PRAGMA(warning(disable : 4373))
135+
# define OPENVINO_SUPPRESS_SUGGEST_OVERRIDE_END OPENVINO_DO_PRAGMA(warning(pop))
136+
#else
137+
# define OPENVINO_SUPPRESS_SUGGEST_OVERRIDE_START
138+
# define OPENVINO_SUPPRESS_SUGGEST_OVERRIDE_END
139+
#endif

src/core/include/openvino/core/runtime_attribute.hpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,8 @@ class Any;
1919

2020
class OPENVINO_API RuntimeAttribute {
2121
public:
22-
_OPENVINO_HIDDEN_METHOD static const DiscreteTypeInfo& get_type_info_static() {
23-
static const ::ov::DiscreteTypeInfo type_info_static{"RuntimeAttribute"};
24-
return type_info_static;
25-
}
26-
virtual const DiscreteTypeInfo& get_type_info() const {
27-
return get_type_info_static();
28-
}
22+
OPENVINO_RTTI_BASE("RuntimeAttribute")
23+
2924
using Ptr = std::shared_ptr<RuntimeAttribute>;
3025
using Base = std::tuple<::ov::RuntimeAttribute>;
3126
virtual ~RuntimeAttribute();

src/core/include/openvino/op/op.hpp

+5-10
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,14 @@ namespace op {
3333
/// \brief Root of all actual ops
3434
/// \ingroup ov_ops_cpp_api
3535
class OPENVINO_API Op : public Node {
36+
public:
37+
OPENVINO_SUPPRESS_SUGGEST_OVERRIDE_START
38+
OPENVINO_RTTI_BASE("Op", "util")
39+
OPENVINO_SUPPRESS_SUGGEST_OVERRIDE_END
40+
3641
protected:
3742
Op() : Node() {}
3843
Op(const OutputVector& arguments);
39-
40-
public:
41-
_OPENVINO_HIDDEN_METHOD static const ::ov::Node::type_info_t& get_type_info_static() {
42-
static ::ov::Node::type_info_t info{"Op", "util"};
43-
info.hash();
44-
return info;
45-
}
46-
const ::ov::Node::type_info_t& get_type_info() const override {
47-
return get_type_info_static();
48-
}
4944
};
5045
} // namespace op
5146
} // namespace ov

src/core/tests/node_test.cpp

+3-10
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,9 @@ using namespace testing;
1313
class TestNode : public ov::Node {
1414
public:
1515
TestNode() : Node() {}
16-
17-
static const type_info_t& get_type_info_static() {
18-
static const type_info_t info{"TestNode", ""};
19-
info.hash();
20-
return info;
21-
}
22-
23-
const type_info_t& get_type_info() const override {
24-
return get_type_info_static();
25-
}
16+
OPENVINO_SUPPRESS_SUGGEST_OVERRIDE_START
17+
OPENVINO_RTTI_BASE("TestNode", "")
18+
OPENVINO_SUPPRESS_SUGGEST_OVERRIDE_END
2619

2720
std::shared_ptr<Node> clone_with_new_inputs(const ov::OutputVector&) const override {
2821
return std::make_shared<TestNode>();

0 commit comments

Comments
 (0)