diff --git a/docs/nGraph_DG/nGraphTransformation.md b/docs/nGraph_DG/nGraphTransformation.md index 03777180ad8..524dbf59c6e 100644 --- a/docs/nGraph_DG/nGraphTransformation.md +++ b/docs/nGraph_DG/nGraphTransformation.md @@ -47,7 +47,7 @@ For examples of how to build an nGraph function, see the [Build nGraph Function] ## Transformations types -nGraph has three main transformation types: +nGraph has three main transformation types: * `ngraph::pass::FunctionPass` - straightforward way to work with `ngraph::Function` directly * `ngraph::pass::MatcherPass` - pattern-based transformation approach @@ -81,7 +81,7 @@ Template for MatcherPass transformation class To use `ngraph::pass::MatcherPass`, you need to complete these steps: 1. Create a pattern -2. Implement a callback +2. Implement a callback 3. Register the pattern and Matcher 4. Execute MatcherPass @@ -90,7 +90,7 @@ So let's go through each of these steps. ### Create a pattern Pattern is a single root `ngraph::Function`. But the only difference is that you do not need to create a function object, you just need to create and connect opset or special pattern operations. Then you need to take the last created operation and put it as a root of the pattern. This root node will be used as a root node in pattern matching. -> **NOTE**: Any nodes in a pattern that have no consumers and are not registered as root will not be used in pattern matching. +> **NOTE**: Any nodes in a pattern that have no consumers and are not registered as root will not be used in pattern matching. @snippet example_ngraph_utils.cpp pattern:simple_example @@ -105,7 +105,7 @@ Callback is an action applied to every pattern entrance. In general, callback is The example above shows the callback structure and how Matcher can be used for accessing nodes detected by pattern. Callback return value is `true` if root node was replaced and another pattern cannot be applied to the same root node; otherwise, it is `false`. -> **NOTE**: It is not recommended to manipulate with nodes that are under root node. This may affect GraphRewrite execution as it is expected that all nodes that come after root node in topological order are valid and can be used in pattern matching. +> **NOTE**: It is not recommended to manipulate with nodes that are under root node. This may affect GraphRewrite execution as it is expected that all nodes that come after root node in topological order are valid and can be used in pattern matching. MatcherPass also provides functionality that allows reporting of the newly created nodes that can be used in additional pattern matching. If MatcherPass was registered in `pass::Manager` or `pass::GraphRewrite`, these registered nodes will be added for additional pattern matching. @@ -144,7 +144,7 @@ Example: In addition, GraphRewrite handles nodes that were registered by MatcherPasses during their execution. This nodes will be added to the beginning of the sequence with nodes for pattern matching. -> **NOTE**: when using `pass::Manager` temporary GraphRewrite is used to execute single MatcherPass. +> **NOTE**: when using `pass::Manager` temporary GraphRewrite is used to execute single MatcherPass. GraphRewrite has two algorithms for MatcherPasses execution. First algorithm is straightforward. It applies each MatcherPass in registration order to current node. @@ -153,7 +153,7 @@ GraphRewrite has two algorithms for MatcherPasses execution. First algorithm is But it is not really efficient when you have a lot of registered passes. So first of all GraphRewrite checks that all MatcherPass patterns has type-based root node (it means that type of this node is not hidden into predicate). And then creates map from registered MatcherPasses. That helps to avoid additional cost of applying each MatcherPass for each node. -![graph_rewrite_efficient_search] +![graph_rewrite_efficient_search] > **NOTE**: GraphRewrite execution algorithm cannot be set manually and depends only on root nodes registered inside MatcherPasses. @@ -161,7 +161,7 @@ And then creates map from registered MatcherPasses. That helps to avoid addition Sometimes patterns cannot be expressed via regular nGraph operations or it is too complicated. For example, if you want to detect Convolution->Add sub-graph without specifying particular input type for Convolution operation or you want to create a pattern where some of operations can have different types. -And for these cases nGraph provides additional helpers to construct patterns for GraphRewrite transformations. +And for these cases nGraph provides additional helpers to construct patterns for GraphRewrite transformations. There are two main helpers: 1. `ngraph::pattern::any_input` - helps to express inputs if their types are undefined. @@ -172,7 +172,7 @@ Let's go through the example to have better understanding of how it works: > **NOTE**: Node attributes do not participate in pattern matching and are needed only for operations creation. Only operation types participate in pattern matching. The example below shows basic usage of `pattern::any_input`. -Here we construct Multiply pattern with arbitrary first input and Constant as a second input. +Here we construct Multiply pattern with arbitrary first input and Constant as a second input. Also as Multiply is commutative operation, it does not matter in which order we set inputs (any_input/Constant or Constant/any_input) because both cases will be matched. @snippet example_ngraph_utils.cpp pattern:label_example @@ -196,7 +196,7 @@ In this chapter we will review nGraph API that allows us to manipulate with `ngr First of all let's talk about `ngraph::Node` input/output ports. Each nGraph operation has input and output ports except cases when operation has `Result`, `Parameter`, or `Constant` type. Every port belongs to its node, so using a port we can access parent node, get shape and type for particular input/output, get all consumers in case of output port, and get producer node in case of input port. -With output port we can set inputs for newly created operations. +With output port we can set inputs for newly created operations. Lets look at the code example. @@ -208,8 +208,8 @@ std::shared_ptr neg_const = opset1::Constant::create(sub->get_input_elemen Output data = node->input_value(0); auto neg = std::make_shared(data, neg_const); ``` -In this example, the `opset3::Multiply` operation takes `Output` and `std::shared_ptr` as inputs. But the constructor takes both as `Output`. -In this case, `std::shared_ptr` will be automatically converted to `Output` if node has exactly one output port; otherwise, conversion raises an exception. +In this example, the `opset3::Multiply` operation takes `Output` and `std::shared_ptr` as inputs. But the constructor takes both as `Output`. +In this case, `std::shared_ptr` will be automatically converted to `Output` if node has exactly one output port; otherwise, conversion raises an exception. ### ngraph::Node replacement @@ -251,9 +251,9 @@ To eliminate operation, nGraph has special method that considers all limitations @snippet example_ngraph_utils.cpp ngraph:eliminate_node `replace_output_update_name` in case of successful replacement it automatically preserves friendly name and runtime info. - -## Transformation conditional compilation + +## Transformation conditional compilation Transformation library has two internal macros to support conditional compilation feature. @@ -272,14 +272,14 @@ Use the latest version of OpSet in your transformation. An exception is op_conve ###2. Dynamic Shape and Rank -nGraph has two types for shape representation: +nGraph has two types for shape representation: `ngraph::Shape` - represents static shape. `ngraph::PartialShape` - represents dynamic shape. It means that rank or some of dimensions are dynamic (undefined). `ngraph::PartialShape` can be converted to `ngraph::Shape` using the `get_shape()` method if all dimensions are static; otherwise, conversion raises an exception. @snippet example_ngraph_utils.cpp ngraph:shape -But in most cases before getting static shape using `get_shape()` method, you need to check that shape is static. +But in most cases before getting static shape using `get_shape()` method, you need to check that shape is static. Also if your transformation requires only input shape rank or particular dimension value, please do not use the `get_shape()` method. See the example below demonstrating how to avoid using `get_shape()` @@ -289,7 +289,7 @@ Not using `get_shape()` method makes your transformation more flexible and appli ###3. Friendly Names -Each `ngraph::Node` has a unique name (used for nGraph internals) and a friendly name. In transformations we care only about friendly name because it represents the name from intermediate representation (IR). +Each `ngraph::Node` has a unique name (used for nGraph internals) and a friendly name. In transformations we care only about friendly name because it represents the name from intermediate representation (IR). Also friendly name is used as output tensor name (until we do not have other way to represent output tensor name) and user code that requests intermediate outputs based on these names. To avoid losing friendly name when replacing node with other node or subgraph, set the original friendly name to the latest node in replacing subgraph. See the example below. @@ -306,7 +306,7 @@ In more advanced cases, when replaced operation has several outputs and we add a ###4. Runtime Info -Runtime info is a map `std::map>` located inside `ngraph::Node` class. It represents additional attributes in `ngraph::Node`. +Runtime info is a map `std::map` located inside `ngraph::Node` class. It represents additional attributes in `ngraph::Node`. These attributes can be set by users or by plugins and when executing transformation that changes `ngraph::Function` we need to preserve these attributes as they will not be automatically propagated. In most cases, transformations have the following types: 1:1 (replace node with another node), 1:N (replace node with a sub-graph), N:1 (fuse sub-graph into a single node), N:M (any other transformation). Currently, there is no mechanism that automatically detects transformation types, so we need to propagate this runtime information manually. See the examples below. @@ -331,7 +331,7 @@ ngraph::copy_runtime_info({conv, bias}, {conv_ie}); ngraph::copy_runtime_info({a, b, c}, {e, f}); ``` -When transformation has multiple fusions or decompositions, `ngraph::copy_runtime_info` must be called multiple times for each case. +When transformation has multiple fusions or decompositions, `ngraph::copy_runtime_info` must be called multiple times for each case. > **Note**: copy_runtime_info removes rt_info from destination nodes. If you want to keep it, you need to specify them in source nodes like this: copy_runtime_info({a, b, c}, {a, b}) @@ -341,12 +341,12 @@ If your transformation inserts constant sub-graphs that need to be folded, do no The example below shows how constant subgraph can be constructed. ```cpp -// After ConstantFolding pass Power will be replaced with Constant +// After ConstantFolding pass Power will be replaced with Constant auto pow = std::make_shared( opset3::Constant::create(element::f32, Shape{1}, {2}) opset3::Constant::create(element::f32, Shape{1}, {3})); auto mul = std::make_shared(input /* not constant input */, pow); -``` +``` Manual constant folding is more preferable than `ngraph::pass::ConstantFolding()` because it is much faster. @@ -358,18 +358,18 @@ Below you can find an example of manual constant folding: In transformation development process: -* Do not use deprecated nGraph API. Deprecated methods has the `NGRAPH_DEPRECATED` macros in its definition. +* Do not use deprecated nGraph API. Deprecated methods has the `NGRAPH_DEPRECATED` macros in its definition. * Do not pass `shared_ptr` as an input for other node if type of node is unknown or it has multiple outputs. Use explicit output port. * If you replace node with another node that produces different shape, remember that new shape will not be propagated until the first `validate_nodes_and_infer_types` call for `ngraph::Function`. If you are using `pass::Manager`, it will automatically call this method after each transformation execution. * Do not forget to call the `ngraph::ConstantFolding` pass if your transformation creates constant subgraphs. * Use latest OpSet if you are not developing downgrade transformation pass. -* When developing a callback for `ngraph::pass::MatcherPass`, do not change nodes that come after the root node in topological order. +* When developing a callback for `ngraph::pass::MatcherPass`, do not change nodes that come after the root node in topological order. ## Using pass manager `ngraph::pass::Manager` is a container class that can store the list of transformations and execute them. The main idea of this class is to have high-level representation for grouped list of transformations. It can register and apply any [transformation types](#transformations_types) on function. -In addition, `ngraph::pass::Manager` has extended debug capabilities (find more information in the [how to debug transformations](#how_to_debug_transformations) section). +In addition, `ngraph::pass::Manager` has extended debug capabilities (find more information in the [how to debug transformations](#how_to_debug_transformations) section). The example below shows basic usage of `ngraph::pass::Manager` diff --git a/docs/snippets/InferenceEngine_Caching3.cpp b/docs/snippets/InferenceEngine_Caching3.cpp index 282d07b1dc9..db6cd89e5c6 100644 --- a/docs/snippets/InferenceEngine_Caching3.cpp +++ b/docs/snippets/InferenceEngine_Caching3.cpp @@ -14,7 +14,7 @@ using namespace InferenceEngine; auto it = std::find(keys.begin(), keys.end(), METRIC_KEY(IMPORT_EXPORT_SUPPORT)); // If metric 'IMPORT_EXPORT_SUPPORT' exists, check it's value - bool cachingSupported = (it != keys.end()) && ie.GetMetric(deviceName, METRIC_KEY(IMPORT_EXPORT_SUPPORT)).as(); + auto cachingSupported = (it != keys.end()) && ie.GetMetric(deviceName, METRIC_KEY(IMPORT_EXPORT_SUPPORT)).as(); //! [part3] return 0; } diff --git a/docs/template_plugin/tests/functional/shared_tests_instances/behavior/plugin/core_integration.cpp b/docs/template_plugin/tests/functional/shared_tests_instances/behavior/plugin/core_integration.cpp index 78cf8bfaecf..83701ec9030 100644 --- a/docs/template_plugin/tests/functional/shared_tests_instances/behavior/plugin/core_integration.cpp +++ b/docs/template_plugin/tests/functional/shared_tests_instances/behavior/plugin/core_integration.cpp @@ -130,10 +130,10 @@ TEST_F(IEClassGetConfigTestTEMPLATE, smoke_GetConfigNoThrow) { std::string defaultDeviceID = ie.GetConfig(deviceName, CONFIG_KEY(DEVICE_ID)); std::cout << CONFIG_KEY(DEVICE_ID) << " : " << defaultDeviceID << std::endl; } else if (CONFIG_KEY(PERF_COUNT) == confKey) { - bool defaultPerfCount = ie.GetConfig(deviceName, CONFIG_KEY(PERF_COUNT)).as(); + auto defaultPerfCount = ie.GetConfig(deviceName, CONFIG_KEY(PERF_COUNT)).as(); std::cout << CONFIG_KEY(PERF_COUNT) << " : " << defaultPerfCount << std::endl; } else if (CONFIG_KEY(EXCLUSIVE_ASYNC_REQUESTS) == confKey) { - bool defaultExclusive = ie.GetConfig(deviceName, CONFIG_KEY(EXCLUSIVE_ASYNC_REQUESTS)).as(); + auto defaultExclusive = ie.GetConfig(deviceName, CONFIG_KEY(EXCLUSIVE_ASYNC_REQUESTS)).as(); std::cout << CONFIG_KEY(EXCLUSIVE_ASYNC_REQUESTS) << " : " << defaultExclusive << std::endl; } } diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_graph_dumper.cpp b/inference-engine/src/mkldnn_plugin/mkldnn_graph_dumper.cpp index 4ffa1845f6c..aae2495bb2a 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_graph_dumper.cpp +++ b/inference-engine/src/mkldnn_plugin/mkldnn_graph_dumper.cpp @@ -186,7 +186,7 @@ std::shared_ptr dump_graph_as_ie_ngraph_net(const MKLDNNGraph } for (auto && kvp : meta_data) - return_node->get_rt_info()[kvp.first] = std::make_shared<::ngraph::VariantWrapper>(kvp.second); + return_node->get_rt_info()[kvp.first] = std::make_shared<::ov::RuntimeAttributeWrapper>(kvp.second); return_node->set_friendly_name(node->getName()); return return_node; diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_node.cpp b/inference-engine/src/mkldnn_plugin/mkldnn_node.cpp index 11fe2d4006b..03b2156e183 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_node.cpp +++ b/inference-engine/src/mkldnn_plugin/mkldnn_node.cpp @@ -137,7 +137,7 @@ MKLDNNNode::MKLDNNNode(const std::shared_ptr& op, const mkldnn::en } if (op != nullptr) { - std::string inputMemoryFormats = ngraph::getMLKDNNInputMemoryFormats(op); + std::string inputMemoryFormats = ngraph::getMKLDNNInputMemoryFormats(op); if (!inputMemoryFormats.empty()) { std::istringstream stream(inputMemoryFormats); std::string str; @@ -148,7 +148,7 @@ MKLDNNNode::MKLDNNNode(const std::shared_ptr& op, const mkldnn::en } } - std::string outputMemoryFormats = ngraph::getMLKDNNOutputMemoryFormats(op); + std::string outputMemoryFormats = ngraph::getMKLDNNOutputMemoryFormats(op); if (!outputMemoryFormats.empty()) { std::istringstream stream(outputMemoryFormats); std::string str; @@ -162,7 +162,7 @@ MKLDNNNode::MKLDNNNode(const std::shared_ptr& op, const mkldnn::en const auto it = rtInfo.find("enforceBF16evenForGraphTail"); if (it != rtInfo.end()) { - if (const auto value = std::dynamic_pointer_cast>(it->second)) + if (const auto value = std::dynamic_pointer_cast>(it->second)) enforceBF16evenForGraphTail = value->get(); } } diff --git a/inference-engine/src/mkldnn_plugin/ngraph_transformations/rnn_sequences_optimization.cpp b/inference-engine/src/mkldnn_plugin/ngraph_transformations/rnn_sequences_optimization.cpp index 0b81fdcc81e..8a6c9fbbe8e 100644 --- a/inference-engine/src/mkldnn_plugin/ngraph_transformations/rnn_sequences_optimization.cpp +++ b/inference-engine/src/mkldnn_plugin/ngraph_transformations/rnn_sequences_optimization.cpp @@ -67,7 +67,7 @@ namespace { ngraph::replace_node(transposeAfter, {reshape2->output(0)}); } - sequenceOp->get_rt_info()["seqAxis"] = std::make_shared>(seqAxis); + sequenceOp->get_rt_info()["seqAxis"] = std::make_shared>(seqAxis); return true; } diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_rnn.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_rnn.cpp index 7c3e3eb2c20..76e20434d1e 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_rnn.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_rnn.cpp @@ -367,7 +367,7 @@ void MKLDNNRNN::initSeq(const std::shared_ptr& op) { const auto rtInfo = op->get_rt_info(); if (rtInfo.count("seqAxis")) { - nativeOrder = std::dynamic_pointer_cast>(rtInfo.at("seqAxis"))->get() == 0; + nativeOrder = std::dynamic_pointer_cast>(rtInfo.at("seqAxis"))->get() == 0; } out_data_dims.erase(out_data_dims.begin() + 1); diff --git a/inference-engine/src/mkldnn_plugin/utils/ngraph_utils.hpp b/inference-engine/src/mkldnn_plugin/utils/ngraph_utils.hpp index 08ae121a7db..fe27efb885d 100644 --- a/inference-engine/src/mkldnn_plugin/utils/ngraph_utils.hpp +++ b/inference-engine/src/mkldnn_plugin/utils/ngraph_utils.hpp @@ -13,7 +13,7 @@ namespace MKLDNNPlugin { inline std::string getRTInfoValue(const std::map& rtInfo, std::string paramName) { auto it = rtInfo.find(paramName); if (it != rtInfo.end()) { - auto value = std::dynamic_pointer_cast>(it->second); + auto value = std::dynamic_pointer_cast>(it->second); return value->get(); } else { return ""; @@ -23,10 +23,13 @@ inline std::string getRTInfoValue(const std::map& rtInfo, inline std::string getPrimitivesPriorityValue(const std::shared_ptr &node) { const auto &rtInfo = node->get_rt_info(); - if (!rtInfo.count(ov::PrimitivesPriority::get_type_info_static())) return ""; + auto it_info = rtInfo.find(ov::PrimitivesPriority::get_type_info_static()); - const auto &attr = rtInfo.at(ov::PrimitivesPriority::get_type_info_static()); - return ngraph::as_type_ptr(attr)->get(); + if (it_info == rtInfo.end()) { + return {}; + } + + return it_info->second.as().value; } template diff --git a/inference-engine/src/mkldnn_plugin/utils/rt_info/memory_formats_attribute.cpp b/inference-engine/src/mkldnn_plugin/utils/rt_info/memory_formats_attribute.cpp index 5dca9699645..9217816bca7 100644 --- a/inference-engine/src/mkldnn_plugin/utils/rt_info/memory_formats_attribute.cpp +++ b/inference-engine/src/mkldnn_plugin/utils/rt_info/memory_formats_attribute.cpp @@ -11,25 +11,25 @@ using namespace ngraph; using namespace ov; -MLKDNNInputMemoryFormats::~MLKDNNInputMemoryFormats() = default; +MKLDNNInputMemoryFormats::~MKLDNNInputMemoryFormats() = default; -std::string ngraph::getMLKDNNInputMemoryFormats(const std::shared_ptr& node) { - auto it_info = node->get_rt_info().find(MLKDNNInputMemoryFormatsAttr); +std::string ngraph::getMKLDNNInputMemoryFormats(const std::shared_ptr& node) { + auto it_info = node->get_rt_info().find(MKLDNNInputMemoryFormats::get_type_info_static()); if (it_info != node->get_rt_info().end()) { - if (auto ptr = it_info->second.as>()) { - return ptr->getMemoryFormats(); + if (it_info->second.is()) { + return it_info->second.as().getMemoryFormats(); } } return {}; } -MLKDNNOutputMemoryFormats::~MLKDNNOutputMemoryFormats() = default; +MKLDNNOutputMemoryFormats::~MKLDNNOutputMemoryFormats() = default; -std::string ngraph::getMLKDNNOutputMemoryFormats(const std::shared_ptr& node) { - auto it_info = node->get_rt_info().find(MLKDNNOutputMemoryFormatsAttr); +std::string ngraph::getMKLDNNOutputMemoryFormats(const std::shared_ptr& node) { + auto it_info = node->get_rt_info().find(MKLDNNOutputMemoryFormats::get_type_info_static()); if (it_info != node->get_rt_info().end()) { - if (auto ptr = it_info->second.as>()) { - return ptr->getMemoryFormats(); + if (it_info->second.is()) { + return it_info->second.as().getMemoryFormats(); } } return {}; diff --git a/inference-engine/src/mkldnn_plugin/utils/rt_info/memory_formats_attribute.hpp b/inference-engine/src/mkldnn_plugin/utils/rt_info/memory_formats_attribute.hpp index c2e7498bb58..ea5611558b6 100644 --- a/inference-engine/src/mkldnn_plugin/utils/rt_info/memory_formats_attribute.hpp +++ b/inference-engine/src/mkldnn_plugin/utils/rt_info/memory_formats_attribute.hpp @@ -12,30 +12,28 @@ namespace ngraph { -constexpr const char *MLKDNNInputMemoryFormatsAttr = "MLKDNNInputMemoryFormats"; -constexpr const char *MLKDNNOutputMemoryFormatsAttr = "MLKDNNOutputMemoryFormats"; +constexpr const char *MKLDNNInputMemoryFormatsAttr = "MKLDNNInputMemoryFormats"; +constexpr const char *MKLDNNOutputMemoryFormatsAttr = "MKLDNNOutputMemoryFormats"; template -class MLKDNNMemoryFormats : public Variant { +class MKLDNNMemoryFormats : public ov::RuntimeAttribute { protected: std::string memory_format; public: - MLKDNNMemoryFormats() = default; - explicit MLKDNNMemoryFormats(const std::string &_memory_format) : memory_format(_memory_format) {} + MKLDNNMemoryFormats() = default; + explicit MKLDNNMemoryFormats(const std::string &_memory_format) : memory_format(_memory_format) {} std::string getMemoryFormats() const { return memory_format; } - ov::Any merge(const ngraph::NodeVector & nodes) override { + ov::Any merge(const ngraph::NodeVector & nodes) const override { std::set unique_mem_format; for (auto &node : nodes) { - auto it_info = node->get_rt_info().find(MemoryFormat::get_type_info_static().name); + auto it_info = node->get_rt_info().find(MemoryFormat::get_type_info_static()); if (it_info != node->get_rt_info().end()) { - if (auto ptr = it_info->second.template as>()) { - std::string mem_format = ptr->getMemoryFormats(); - if (!mem_format.empty()) { - unique_mem_format.insert(mem_format); - } + std::string mem_format = it_info->second.template as().getMemoryFormats(); + if (!mem_format.empty()) { + unique_mem_format.insert(mem_format); } } } @@ -50,28 +48,28 @@ public: if (unique_mem_format.size() == 1) { final_mem_format = *unique_mem_format.begin(); } - return std::make_shared(final_mem_format); + return MemoryFormat{final_mem_format}; } }; -class MLKDNNInputMemoryFormats : public MLKDNNMemoryFormats { +class MKLDNNInputMemoryFormats : public MKLDNNMemoryFormats { public: - OPENVINO_RTTI(MLKDNNInputMemoryFormatsAttr); - MLKDNNInputMemoryFormats() = default; - explicit MLKDNNInputMemoryFormats(const std::string &_memory_format) : MLKDNNMemoryFormats(_memory_format) {} - ~MLKDNNInputMemoryFormats() override; + OPENVINO_RTTI(MKLDNNInputMemoryFormatsAttr); + MKLDNNInputMemoryFormats() = default; + explicit MKLDNNInputMemoryFormats(const std::string &_memory_format) : MKLDNNMemoryFormats(_memory_format) {} + ~MKLDNNInputMemoryFormats() override; }; -std::string getMLKDNNInputMemoryFormats(const std::shared_ptr& node); +std::string getMKLDNNInputMemoryFormats(const std::shared_ptr& node); -class MLKDNNOutputMemoryFormats : public MLKDNNMemoryFormats { +class MKLDNNOutputMemoryFormats : public MKLDNNMemoryFormats { public: - OPENVINO_RTTI(MLKDNNOutputMemoryFormatsAttr); - MLKDNNOutputMemoryFormats() = default; - explicit MLKDNNOutputMemoryFormats(const std::string &_memory_format) : MLKDNNMemoryFormats(_memory_format) {} - ~MLKDNNOutputMemoryFormats() override; + OPENVINO_RTTI(MKLDNNOutputMemoryFormatsAttr); + MKLDNNOutputMemoryFormats() = default; + explicit MKLDNNOutputMemoryFormats(const std::string &_memory_format) : MKLDNNMemoryFormats(_memory_format) {} + ~MKLDNNOutputMemoryFormats() override; }; -std::string getMLKDNNOutputMemoryFormats(const std::shared_ptr& node); +std::string getMKLDNNOutputMemoryFormats(const std::shared_ptr& node); } // namespace ngraph diff --git a/inference-engine/src/offline_transformations/include/mask_attribute.hpp b/inference-engine/src/offline_transformations/include/mask_attribute.hpp index 4c74a64c074..0d57808949b 100644 --- a/inference-engine/src/offline_transformations/include/mask_attribute.hpp +++ b/inference-engine/src/offline_transformations/include/mask_attribute.hpp @@ -16,7 +16,6 @@ #include #include -#include namespace ngraph { @@ -28,6 +27,11 @@ namespace ngraph { class Mask : public std::vector>, public std::enable_shared_from_this { public: + static const ::ov::DiscreteTypeInfo& get_type_info_static() { + static const ::ov::DiscreteTypeInfo type_info{"Mask", 0, "0"}; + return type_info; + } + using Ptr = std::shared_ptr; Mask() = default; @@ -180,6 +184,7 @@ public: item.clear(); } } + private: bool m_is_shape_like{false}; @@ -199,22 +204,3 @@ Mask::Ptr getMask(const Output & output); void setMask(Output output, const Mask::Ptr & mask); } // namespace ngraph - -namespace ov { - -extern template class VariantImpl; - -template<> -class VariantWrapper : public VariantImpl { -public: - OPENVINO_RTTI("VariantWrapper"); - BWDCMP_RTTI_DECLARATION; - - static std::shared_ptr> create(const value_type & value) { - return std::make_shared>(value); - } - - explicit VariantWrapper(const value_type &value) : VariantImpl(value) {} -}; - -} // namespace ov diff --git a/inference-engine/src/offline_transformations/src/pruning/mask_attribute.cpp b/inference-engine/src/offline_transformations/src/pruning/mask_attribute.cpp index 9ee1c023137..90f79e049f9 100644 --- a/inference-engine/src/offline_transformations/src/pruning/mask_attribute.cpp +++ b/inference-engine/src/offline_transformations/src/pruning/mask_attribute.cpp @@ -14,28 +14,22 @@ namespace ngraph { Mask::Ptr getMask(const Output & output) { auto &rtInfo = output.get_rt_info(); - using MaskWrapper = VariantWrapper; + if (!rtInfo.count(Mask::get_type_info_static())) return nullptr; - if (!rtInfo.count(MaskWrapper::get_type_info_static().name)) return nullptr; - - const auto &attr = rtInfo.at(MaskWrapper::get_type_info_static().name); - return ov::as_type_ptr(attr)->get(); + const auto &attr = rtInfo.at(Mask::get_type_info_static()); + return attr.as(); } Mask::Ptr getMask(const Output & output) { auto &rtInfo = output.get_rt_info(); - using MaskWrapper = VariantWrapper; - - if (!rtInfo.count(MaskWrapper::get_type_info_static().name)) return nullptr; - - const auto &attr = rtInfo.at(MaskWrapper::get_type_info_static().name); - return ov::as_type_ptr(attr)->get(); + if (!rtInfo.count(Mask::get_type_info_static())) return nullptr; + const auto &attr = rtInfo.at(Mask::get_type_info_static()); + return attr.as(); } void setMask(Output output, const Mask::Ptr & mask) { auto &rtInfo = output.get_rt_info(); - using MaskWrapper = VariantWrapper; - rtInfo[MaskWrapper::get_type_info_static().name] = MaskWrapper::create(mask); + rtInfo[Mask::get_type_info_static()] = mask; } std::ostream & operator<< (std::ostream & out, const Mask & mask) { @@ -54,11 +48,3 @@ std::ostream & operator<< (std::ostream & out, const Mask & mask) { } } // namespace ngraph - -namespace ov { - -template class ngraph::VariantImpl; - -BWDCMP_RTTI_DEFINITION(VariantWrapper); - -} // namespace ov diff --git a/inference-engine/tests/functional/inference_engine/ir_serialization/rt_info_deserialization.cpp b/inference-engine/tests/functional/inference_engine/ir_serialization/rt_info_deserialization.cpp index 2ba736b3090..c8c14c7b7d7 100644 --- a/inference-engine/tests/functional/inference_engine/ir_serialization/rt_info_deserialization.cpp +++ b/inference-engine/tests/functional/inference_engine/ir_serialization/rt_info_deserialization.cpp @@ -40,7 +40,7 @@ protected: ov::frontend::FrontEnd::Ptr FE; ov::frontend::InputModel::Ptr inputModel; - ov::VariantVector params{ov::make_variant(&modelStream)}; + ov::RuntimeAttributeVector params{&modelStream}; FE = manager.load_by_model(params); if (FE) @@ -119,7 +119,7 @@ TEST_F(RTInfoDeserialization, NodeV10) { ASSERT_NE(nullptr, f); auto check_rt_info = [](const RTMap& info) { - const std::string& key = VariantWrapper::get_type_info_static(); + const std::string& key = ngraph::FusedNames::get_type_info_static(); EXPECT_FALSE(info.count(key)); const std::string& key_old_api_order = ov::OldApiMapOrder::get_type_info_static(); @@ -278,7 +278,7 @@ TEST_F(RTInfoDeserialization, InputAndOutputV10) { ASSERT_NE(nullptr, f); auto check_rt_info = [](const RTMap& info) { - const std::string& key = VariantWrapper::get_type_info_static(); + const std::string& key = ngraph::FusedNames::get_type_info_static(); ASSERT_FALSE(info.count(key)); }; @@ -421,27 +421,22 @@ TEST_F(RTInfoDeserialization, NodeV11) { ASSERT_NE(nullptr, f); auto check_fused_names = [](const RTMap& info, const std::string& names) { - const std::string& key = VariantWrapper::get_type_info_static(); + const std::string& key = ngraph::FusedNames::get_type_info_static(); ASSERT_TRUE(info.count(key)); - auto fused_names_attr = std::dynamic_pointer_cast>(info.at(key)); - ASSERT_TRUE(fused_names_attr); - EXPECT_EQ(fused_names_attr->get().getNames(), names); + auto fused_names_attr = info.at(key).as(); + EXPECT_EQ(fused_names_attr.getNames(), names); }; auto check_old_api_map_order = [](const RTMap & info, const std::vector & order) { const std::string & old_api_map_key = ov::OldApiMapOrder::get_type_info_static(); ASSERT_TRUE(info.count(old_api_map_key)); - auto old_api_map_attr = std::dynamic_pointer_cast(info.at(old_api_map_key)); - ASSERT_TRUE(old_api_map_attr); - auto old_api_map_attr_val = old_api_map_attr->get(); + auto old_api_map_attr_val = info.at(old_api_map_key).as().value; EXPECT_EQ(old_api_map_attr_val, order); }; auto check_old_api_map_type = [](const RTMap & info, const ngraph::element::Type& type) { const std::string & old_api_map_key = ov::OldApiMapElementType::get_type_info_static(); ASSERT_TRUE(info.count(old_api_map_key)); - auto old_api_map_attr = std::dynamic_pointer_cast(info.at(old_api_map_key)); - ASSERT_TRUE(old_api_map_attr); - auto old_api_map_attr_val = old_api_map_attr->get(); + auto old_api_map_attr_val = info.at(old_api_map_key).as().value; EXPECT_EQ(old_api_map_attr_val, type); }; @@ -501,8 +496,7 @@ TEST_F(RTInfoDeserialization, NodeV11) { auto round = std::make_shared(convert_param, ngraph::opset8::Round::RoundMode::HALF_TO_EVEN); // TODO: runtime information should migrate as well? - round->get_rt_info()[VariantWrapper::get_type_info_static()] = - std::make_shared>(ngraph::FusedNames("Round1,Round2")); + round->get_rt_info()[ngraph::FusedNames::get_type_info_static()] = ngraph::FusedNames("Round1,Round2"); // TODO: No guarantee that exactly 'convert, then transpose' will be added by implicit post-processing auto constant_result = std::make_shared(ngraph::element::u64, @@ -722,20 +716,20 @@ TEST_F(RTInfoDeserialization, InputAndOutputV11) { check_version(f, 11); auto check_fused_names = [](const RTMap& info, const std::string& names) { - const std::string& key = VariantWrapper::get_type_info_static(); + const std::string& key = ngraph::FusedNames::get_type_info_static(); ASSERT_TRUE(info.count(key)); - auto fused_names_attr = std::dynamic_pointer_cast>(info.at(key)); - ASSERT_TRUE(fused_names_attr); - ASSERT_EQ(fused_names_attr->get().getNames(), names); + auto fused_names_attr = info.at(key).as(); + ASSERT_EQ(fused_names_attr.getNames(), names); }; auto param = f->get_parameters()[0]; check_fused_names(param->output(0).get_rt_info(), "test1,test2"); EXPECT_EQ(param->get_layout(), "NCHW"); - auto var0 = std::dynamic_pointer_cast( - f->input(0).get_rt_info()[ov::preprocess::TensorInfoMemoryType::get_type_info_static()]); - EXPECT_EQ(var0->get(), "test_memory_type"); + auto var0 = f->input(0).get_rt_info() + .at(ov::preprocess::TensorInfoMemoryType::get_type_info_static()) + .as().value; + EXPECT_EQ(var0, "test_memory_type"); auto result = f->get_result(); check_fused_names(result->input(0).get_rt_info(), "test5,test6"); diff --git a/inference-engine/tests/functional/inference_engine/ir_serialization/rt_info_serialization.cpp b/inference-engine/tests/functional/inference_engine/ir_serialization/rt_info_serialization.cpp index 8f32c89d1ec..e3cf7db8ae9 100644 --- a/inference-engine/tests/functional/inference_engine/ir_serialization/rt_info_serialization.cpp +++ b/inference-engine/tests/functional/inference_engine/ir_serialization/rt_info_serialization.cpp @@ -34,7 +34,7 @@ protected: ov::frontend::FrontEnd::Ptr FE; ov::frontend::InputModel::Ptr inputModel; - ov::VariantVector params{ov::make_variant(model_path), ov::make_variant(weights_path)}; + ov::RuntimeAttributeVector params{model_path, weights_path}; FE = manager.load_by_model(params); if (FE) @@ -51,16 +51,12 @@ private: }; TEST_F(RTInfoSerializationTest, all_attributes_latest) { - auto init_info = [](RTMap& info) { - info[VariantWrapper::get_type_info_static()] = - std::make_shared>(ngraph::FusedNames("add")); - info[ov::PrimitivesPriority::get_type_info_static()] = - std::make_shared("priority"); - info[ov::OldApiMapOrder::get_type_info_static()] = - std::make_shared(std::vector{0, 2, 3, 1}); - info[ov::OldApiMapElementType::get_type_info_static()] = std::make_shared( - ngraph::element::Type_t::f32); - info[ov::Decompression::get_type_info_static()] = std::make_shared(); + auto init_info = [](RTMap & info) { + info[ngraph::FusedNames::get_type_info_static()] = ngraph::FusedNames("add"); + info[ov::PrimitivesPriority::get_type_info_static()] = ov::PrimitivesPriority("priority"); + info[ov::OldApiMapOrder::get_type_info_static()] = ov::OldApiMapOrder(std::vector{0, 2, 3, 1}); + info[ov::OldApiMapElementType::get_type_info_static()] = ov::OldApiMapElementType(ngraph::element::Type_t::f32); + info[ov::Decompression::get_type_info_static()] = ov::Decompression{}; }; std::shared_ptr function; @@ -85,36 +81,29 @@ TEST_F(RTInfoSerializationTest, all_attributes_latest) { ASSERT_NE(nullptr, f); auto check_info = [](const RTMap & info) { - const std::string & key = VariantWrapper::get_type_info_static(); + const std::string & key = ngraph::FusedNames::get_type_info_static(); ASSERT_TRUE(info.count(key)); - auto fused_names_attr = std::dynamic_pointer_cast>(info.at(key)); - ASSERT_TRUE(fused_names_attr); - ASSERT_EQ(fused_names_attr->get().getNames(), "add"); + auto fused_names_attr = info.at(key).as(); + ASSERT_EQ(fused_names_attr.getNames(), "add"); const std::string & pkey = ov::PrimitivesPriority::get_type_info_static(); ASSERT_TRUE(info.count(pkey)); - auto primitives_priority_attr = std::dynamic_pointer_cast(info.at(pkey)); - ASSERT_TRUE(primitives_priority_attr); - ASSERT_EQ(primitives_priority_attr->get(), "priority"); + auto primitives_priority_attr = info.at(pkey).as().value; + ASSERT_EQ(primitives_priority_attr, "priority"); const std::string & old_api_map_key_order = ov::OldApiMapOrder::get_type_info_static(); ASSERT_TRUE(info.count(old_api_map_key_order)); - auto old_api_map_attr = std::dynamic_pointer_cast(info.at(old_api_map_key_order)); - ASSERT_TRUE(old_api_map_attr); - auto old_api_map_attr_val = old_api_map_attr->get(); + auto old_api_map_attr_val = info.at(old_api_map_key_order).as().value; ASSERT_EQ(old_api_map_attr_val, std::vector({0, 2, 3, 1})); const std::string & old_api_map_key = ov::OldApiMapElementType::get_type_info_static(); ASSERT_TRUE(info.count(old_api_map_key)); - auto old_api_map_type = std::dynamic_pointer_cast(info.at(old_api_map_key)); - ASSERT_TRUE(old_api_map_type); - auto old_api_map_type_val = old_api_map_type->get(); + auto old_api_map_type_val = info.at(old_api_map_key).as().value; ASSERT_EQ(old_api_map_type_val, ngraph::element::Type_t::f32); const std::string& dkey = ov::Decompression::get_type_info_static(); ASSERT_TRUE(info.count(dkey)); - auto decompression_attr = std::dynamic_pointer_cast(info.at(dkey)); - ASSERT_TRUE(decompression_attr); + ASSERT_NO_THROW(info.at(dkey).as()); }; auto add = f->get_results()[0]->get_input_node_ptr(0); @@ -128,10 +117,8 @@ TEST_F(RTInfoSerializationTest, all_attributes_latest) { TEST_F(RTInfoSerializationTest, all_attributes_v10) { auto init_info = [](RTMap & info) { - info[VariantWrapper::get_type_info_static()] = - std::make_shared>(ngraph::FusedNames("add")); - info[ov::PrimitivesPriority::get_type_info_static()] = - std::make_shared("priority"); + info[ngraph::FusedNames::get_type_info_static()] = ngraph::FusedNames("add"); + info["PrimitivesPriority"] = ov::PrimitivesPriority("priority"); }; std::shared_ptr function; @@ -154,7 +141,7 @@ TEST_F(RTInfoSerializationTest, all_attributes_v10) { ASSERT_NE(nullptr, f); auto check_info = [](const RTMap & info) { - const std::string & key = VariantWrapper::get_type_info_static(); + const std::string & key = ngraph::FusedNames::get_type_info_static(); ASSERT_FALSE(info.count(key)); }; @@ -168,10 +155,8 @@ TEST_F(RTInfoSerializationTest, all_attributes_v10) { TEST_F(RTInfoSerializationTest, all_attributes_v11) { auto init_info = [](RTMap & info) { - info[VariantWrapper::get_type_info_static()] = - std::make_shared>(ngraph::FusedNames("add")); - info[ov::PrimitivesPriority::get_type_info_static()] = - std::make_shared("priority"); + info[ngraph::FusedNames::get_type_info_static()] = ngraph::FusedNames("add"); + info[ov::PrimitivesPriority::get_type_info_static()] = ov::PrimitivesPriority("priority"); }; std::shared_ptr function; @@ -199,24 +184,23 @@ TEST_F(RTInfoSerializationTest, all_attributes_v11) { ASSERT_NE(nullptr, f); auto check_info = [](const RTMap & info) { - const std::string & key = VariantWrapper::get_type_info_static(); + const std::string & key = ngraph::FusedNames::get_type_info_static(); ASSERT_TRUE(info.count(key)); - auto fused_names_attr = std::dynamic_pointer_cast>(info.at(key)); - ASSERT_TRUE(fused_names_attr); - ASSERT_EQ(fused_names_attr->get().getNames(), "add"); + auto fused_names_attr = info.at(key).as(); + ASSERT_EQ(fused_names_attr.getNames(), "add"); const std::string & pkey = ov::PrimitivesPriority::get_type_info_static(); ASSERT_TRUE(info.count(pkey)); - auto primitives_priority_attr = std::dynamic_pointer_cast(info.at(pkey)); - ASSERT_TRUE(primitives_priority_attr); - ASSERT_EQ(primitives_priority_attr->get(), "priority"); + auto primitives_priority_attr = info.at(pkey).as().value; + ASSERT_EQ(primitives_priority_attr, "priority"); }; auto add = f->get_results()[0]->get_input_node_ptr(0); EXPECT_EQ(f->get_parameters()[0]->get_layout(), "NCHW"); - auto var0 = std::dynamic_pointer_cast( - f->input(0).get_rt_info()[ov::preprocess::TensorInfoMemoryType::get_type_info_static()]); - EXPECT_EQ(var0->get(), "test_memory_type"); + auto var0 = f->input(0).get_rt_info() + .at(ov::preprocess::TensorInfoMemoryType::get_type_info_static()) + .as().value; + EXPECT_EQ(var0, "test_memory_type"); EXPECT_EQ(f->get_results()[0]->get_layout(), "????"); check_info(add->get_rt_info()); check_info(add->input(0).get_rt_info()); diff --git a/inference-engine/tests/functional/inference_engine/lp_transformations/concat_transformation.cpp b/inference-engine/tests/functional/inference_engine/lp_transformations/concat_transformation.cpp index 9073e67100a..7b2480a42a9 100644 --- a/inference-engine/tests/functional/inference_engine/lp_transformations/concat_transformation.cpp +++ b/inference-engine/tests/functional/inference_engine/lp_transformations/concat_transformation.cpp @@ -199,9 +199,9 @@ public: testValues.result.convert2, testValues.result.dequantization2, { - make_shared_attribute_ptr(true), - make_shared_attribute_ptr(interval, 256), - make_shared_attribute_ptr(false) + PrecisionPreservedAttribute(true), + IntervalsAlignmentAttribute(interval, 256), + QuantizationAlignmentAttribute(false) }, testValues.result.precisionAfterOperation, testValues.result.dequantizationAfter, @@ -235,13 +235,13 @@ TEST_P(ConcatTransformation, CompareFunctions) { ConcatTransformationTestValues testValues = std::get<2>(GetParam()); const auto actualFakeQuantizes = LayerTransformation::get(actualFunction); if (testValues.axis == 1) { - ASSERT_TRUE(checkIfOutputAttributesSharedValuesAreTheSame>(actualFakeQuantizes)) << + ASSERT_TRUE(checkIfOutputAttributesSharedValuesAreTheSame(actualFakeQuantizes)) << "PrecisionsAttribute are not the same"; if (testValues.checkIntervalsAlignmentAttributes) { auto operations = LayerTransformation::get(actualFunction); operations.insert(operations.end(), actualFakeQuantizes.begin(), actualFakeQuantizes.end()); - ASSERT_TRUE(checkIfAttributesSharedValuesAreTheSame>(operations)) << + ASSERT_TRUE(checkIfAttributesSharedValuesAreTheSame(operations)) << "IntervalsAlignmentAttribute are not the same"; } } @@ -275,13 +275,13 @@ const std::vector testValues = { { { 256ul, {}, {0.f}, {2550.f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } }, {}, {}, { 256ul, {}, {0.f}, {0.1f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } }, {}, {}, @@ -304,7 +304,7 @@ const std::vector testValues = { { { 256ul, {}, {0.f}, {2.55f}, {0.f}, {2.55f}, ngraph::element::f32, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } }, {}, {}, @@ -331,7 +331,7 @@ const std::vector testValues = { {}, { 256ul, {}, {0.f}, {2.55f}, {0.f}, {2.55f}, ngraph::element::f32, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } }, {}, {}, @@ -352,13 +352,13 @@ const std::vector testValues = { { { 256ul, {}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } }, {}, {}, { 256ul, {}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } }, {}, {}, @@ -390,13 +390,13 @@ const std::vector testValues = { { { 256ul, {}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } }, {}, {}, { 256ul, {}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } }, {}, {}, @@ -428,13 +428,13 @@ const std::vector testValues = { { { 256ul, {}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } }, {}, {}, { 256ul, {}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } }, {}, {}, @@ -462,13 +462,13 @@ const std::vector testValues = { { { 256ul, {}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } }, {}, {}, { 256ul, {}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } }, {}, {}, @@ -496,13 +496,13 @@ const std::vector testValues = { { { 256ul, {}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } }, {}, {}, { 256ul, {}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } }, {}, {}, @@ -526,13 +526,13 @@ const std::vector testValues = { { { 256ul, {{1}, {1}, {}, {}}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } }, {}, {}, { 256ul, {{1}, {1}, {}, {}}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } }, {}, {}, @@ -556,13 +556,13 @@ const std::vector testValues = { { { 256ul, {{1, 1, 1, 1}, {1, 1, 1, 1}, {}, {}}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } }, {}, {}, { 256ul, {{1, 1, 1, 1}, {1, 1, 1, 1}, {}, {}}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } }, {}, {}, @@ -586,13 +586,13 @@ const std::vector testValues = { { { 256ul, {}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } }, {}, {}, { 256ul, {}, {0.f}, {1.275f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } }, {}, {}, @@ -616,13 +616,13 @@ const std::vector testValues = { { { 256ul, {{1}, {1}, {}, {}}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } }, {}, {}, { 256ul, {{1}, {1}, {}, {}}, {0.f}, {1.275f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } }, {}, {}, @@ -657,7 +657,7 @@ const std::vector testValues = { {{1, 3, 1, 1}, {1, 3, 1, 1}, {}, {}}, {0.f, 0.f, 0.f}, {2.55f, 2.55f, 2.55f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } }, {}, {}, @@ -666,7 +666,7 @@ const std::vector testValues = { {{1, 3, 1, 1}, {1, 3, 1, 1}, {}, {}}, {0.f, 0.f, 0.f}, {1.275f, 1.275f, 1.275f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } }, {}, {}, @@ -692,13 +692,13 @@ const std::vector testValues = { { { 256ul, {}, {-1.28f}, {1.27f}, {-128.f}, {127.f}, ngraph::element::i8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } }, {}, {}, { 256ul, {}, {-1.28f}, {1.27f}, {-128.f}, {127.f}, ngraph::element::i8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } }, {}, {}, @@ -722,13 +722,13 @@ const std::vector testValues = { { { 256ul, {}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{-1.28f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{-1.28f, 2.55f}, 256ul) } }, {}, {}, { 256ul, {}, {-1.28f}, {1.27f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{-1.28f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{-1.28f, 2.55f}, 256ul) } }, {}, {}, @@ -752,13 +752,13 @@ const std::vector testValues = { { { 256ul, {}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{-1.28f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{-1.28f, 2.55f}, 256ul) } }, {}, {}, { 256ul, {}, {-1.28f}, {1.27f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{-1.28f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{-1.28f, 2.55f}, 256ul) } }, {}, {}, @@ -896,13 +896,13 @@ const std::vector testValues = { { { 256ul, {}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } }, {}, {}, { 256ul, {}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } }, {}, {}, @@ -940,13 +940,13 @@ const std::vector testValues = { { { 256ul, {}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{-1.28f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{-1.28f, 2.55f}, 256ul) } }, {}, {}, { 256ul, {}, {-1.28f}, {1.27f}, {-1.28f}, {1.27f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{-1.28f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{-1.28f, 2.55f}, 256ul) } }, {}, {}, @@ -974,13 +974,13 @@ const std::vector testValues = { { { 256ul, {}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } }, {}, {}, { 256ul, {}, {1.275f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } }, {}, {}, @@ -1012,13 +1012,13 @@ const std::vector testValues = { { { 256ul, {}, {1.275f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } }, {}, {}, { 256ul, {}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) } }, {}, diff --git a/inference-engine/tests/functional/inference_engine/lp_transformations/concat_with_neighbors_transformation_with_convolution.cpp b/inference-engine/tests/functional/inference_engine/lp_transformations/concat_with_neighbors_transformation_with_convolution.cpp index 1b22f085f23..0cb4cd1fafe 100644 --- a/inference-engine/tests/functional/inference_engine/lp_transformations/concat_with_neighbors_transformation_with_convolution.cpp +++ b/inference-engine/tests/functional/inference_engine/lp_transformations/concat_with_neighbors_transformation_with_convolution.cpp @@ -160,16 +160,16 @@ TEST_P(ConcatWithNeighborsWithConvolutionTransformation, CompareFunctions) { auto actualFakeQuantizes = LayerTransformation::get(actualFunction); ASSERT_EQ(3ul, actualFakeQuantizes.size()) << "unexpected FakeQuantize operations count " << actualFakeQuantizes.size(); - ASSERT_TRUE(checkIfOutputAttributesSharedValuesAreTheSame>(actualFakeQuantizes)) << + ASSERT_TRUE(checkIfOutputAttributesSharedValuesAreTheSame(actualFakeQuantizes)) << "PrecisionsAttribute shared values are not the same"; auto actualConcatOperations = LayerTransformation::get(actualFunction); ASSERT_EQ(2ul, actualConcatOperations.size()) << "unexpected concat operations"; - ASSERT_NE(nullptr, ngraph::pass::low_precision::getAttribute>(actualConcatOperations[0])); - ASSERT_NE(nullptr, ngraph::pass::low_precision::getAttribute>(actualConcatOperations[1])); + ASSERT_FALSE(ngraph::pass::low_precision::getAttribute(actualConcatOperations[0]).empty()); + ASSERT_FALSE(ngraph::pass::low_precision::getAttribute(actualConcatOperations[1]).empty()); actualConcatOperations.insert(actualConcatOperations.end(), actualFakeQuantizes.begin(), actualFakeQuantizes.end()); - ASSERT_TRUE(checkIfAttributesSharedValuesAreTheSame>(actualConcatOperations)) << + ASSERT_TRUE(checkIfAttributesSharedValuesAreTheSame(actualConcatOperations)) << "IntervalsAlignmentAttribute shared values are not the same"; auto convolutions = LayerTransformation::get(actualFunction); @@ -177,8 +177,8 @@ TEST_P(ConcatWithNeighborsWithConvolutionTransformation, CompareFunctions) { ASSERT_EQ(2ul, convolutions[0]->input(0).get_rt_info().size()) << "unexpected input 0 attributes count: LowPrecision::PerTensorQuantization & LowPrecision::Precisions"; ASSERT_EQ(1ul, convolutions[0]->input(1).get_rt_info().size()) << "unexpected input 1 attributes count"; - auto a1 = std::dynamic_pointer_cast>>(convolutions[0]->input(1).get_rt_info().begin()->second); - ASSERT_EQ(element::i8, *a1->get().get()->sharedValue->precisions.begin()); + auto& a1 = convolutions[0]->input(1).get_rt_info().begin()->second.as(); + ASSERT_EQ(element::i8, a1.value().front()); } const std::vector precisions = { @@ -204,15 +204,15 @@ const std::vector testValues = { { { 256ul, ngraph::Shape({}), {-1.28f / 3.f}, {1.27f / 3.f}, {0.f}, {255.f}, element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{-1.28f, 1.27f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{-1.28f, 1.27f}, 256ul) } }, { 256ul, ngraph::Shape({}), {-1.28f / 2.f}, {1.27f / 2.f}, {64.f}, {192.f}, element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{-1.28f, 1.27f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{-1.28f, 1.27f}, 256ul) } }, { 256ul, ngraph::Shape({}), {-1.28f}, {1.27f}, {0.f}, {255.f}, element::u8, - { make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{-1.28f, 1.27f}, 256ul) } + { IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{-1.28f, 1.27f}, 256ul) } }, ngraph::element::u8, {{}, {}, {}}, diff --git a/inference-engine/tests/functional/inference_engine/lp_transformations/concat_with_not_quantized_parent_transformation.cpp b/inference-engine/tests/functional/inference_engine/lp_transformations/concat_with_not_quantized_parent_transformation.cpp index b34480ad5a4..b9d82357805 100644 --- a/inference-engine/tests/functional/inference_engine/lp_transformations/concat_with_not_quantized_parent_transformation.cpp +++ b/inference-engine/tests/functional/inference_engine/lp_transformations/concat_with_not_quantized_parent_transformation.cpp @@ -218,9 +218,9 @@ public: testValues.result.dequantization2, true, { - make_shared_attribute_ptr(true), - make_shared_attribute_ptr(IntervalsAlignmentSharedValue::Interval{-1.28f, 2.55f}, 256ul), - make_shared_attribute_ptr(false) + PrecisionPreservedAttribute(true), + IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{-1.28f, 2.55f}, 256ul), + QuantizationAlignmentAttribute(false) }, testValues.result.precisionAfterOperation, testValues.result.dequantizationAfter, @@ -258,14 +258,14 @@ TEST_P(ConcatWithNotQuantizedParentTransformation, CompareFunctions) { break; } } - ASSERT_TRUE(checkIfOutputAttributesSharedValuesAreTheSame>(actualFakeQuantizes)) << + ASSERT_TRUE(checkIfOutputAttributesSharedValuesAreTheSame(actualFakeQuantizes)) << "PrecisionsAttribute are not the same"; ConcatWithNotQuantizedParentTransformationTestValues testValues = std::get<2>(GetParam()); if (testValues.checkIntervalsAlignmentAttributes) { auto operations = LayerTransformation::get(actualFunction); operations.insert(operations.end(), actualFakeQuantizes.begin(), actualFakeQuantizes.end()); - ASSERT_TRUE(checkIfAttributesSharedValuesAreTheSame>(operations)) << + ASSERT_TRUE(checkIfAttributesSharedValuesAreTheSame(operations)) << "IntervalsAlignmentAttribute are not the same"; } } diff --git a/inference-engine/tests/functional/inference_engine/lp_transformations/convert_subtract_constant_transformation.cpp b/inference-engine/tests/functional/inference_engine/lp_transformations/convert_subtract_constant_transformation.cpp index e910cbf6b8e..a952e3ef173 100644 --- a/inference-engine/tests/functional/inference_engine/lp_transformations/convert_subtract_constant_transformation.cpp +++ b/inference-engine/tests/functional/inference_engine/lp_transformations/convert_subtract_constant_transformation.cpp @@ -169,7 +169,8 @@ const std::vector testValues = }, { { ngraph::element::f32, false }, - { {127.f}, element::f32, {}, false, 1ul, element::i8, true, {}, { "disabled_constant_folding_0" } }, + { {127.f}, element::f32, {}, false, 1ul, element::i8, true, {}, + { ov::pass::DisableConstantFolding::get_type_info_static() } }, { {0.03f}, element::f32, {}, false } }, { std::vector{ 2.f }, ngraph::element::i8}, diff --git a/inference-engine/tests/functional/inference_engine/lp_transformations/convolution_backprop_data_transformation.cpp b/inference-engine/tests/functional/inference_engine/lp_transformations/convolution_backprop_data_transformation.cpp index a2fc719a092..4ddef412cab 100644 --- a/inference-engine/tests/functional/inference_engine/lp_transformations/convolution_backprop_data_transformation.cpp +++ b/inference-engine/tests/functional/inference_engine/lp_transformations/convolution_backprop_data_transformation.cpp @@ -284,7 +284,8 @@ const std::vector testValues = { ngraph::element::u8, {{}, { { 128.f }, ngraph::element::f32, {}, false }, {}}, - {{}, { { 2.f }, ngraph::element::f32, {1, 2, 1, 1}, true, 1ul, element::i8, false, { "disabled_constant_folding_0" } }, {}}, + {{}, { { 2.f }, ngraph::element::f32, {1, 2, 1, 1}, true, 1ul, element::i8, false, + { ov::pass::DisableConstantFolding::get_type_info_static() } }, {}}, {{}, {}, {{ 0.0002f }, ngraph::element::f32, {}}}, op::Constant::create(ngraph::element::i8, ngraph::Shape{}, std::vector{ 2.f }), true diff --git a/inference-engine/tests/functional/inference_engine/lp_transformations/convolution_qdq_transformation.cpp b/inference-engine/tests/functional/inference_engine/lp_transformations/convolution_qdq_transformation.cpp index fb54eb596cb..69aec47af04 100644 --- a/inference-engine/tests/functional/inference_engine/lp_transformations/convolution_qdq_transformation.cpp +++ b/inference-engine/tests/functional/inference_engine/lp_transformations/convolution_qdq_transformation.cpp @@ -174,7 +174,8 @@ const std::vector testValues = { }, { {}, - { { 127.f }, ngraph::element::f32, { 6, 1, 1, 1 }, false, 1ul, element::i8, false, { "disabled_constant_folding_0" } }, + { { 127.f }, ngraph::element::f32, { 6, 1, 1, 1 }, false, 1ul, element::i8, false, + { ov::pass::DisableConstantFolding::get_type_info_static() } }, {} }, { std::vector{ 100.f }, ngraph::element::i8}, @@ -349,7 +350,8 @@ const std::vector testValues = { }, { {}, - { { 127.f }, ngraph::element::f32, { 6, 1, 1, 1 }, false, 1ul, element::i8, false, { "disabled_constant_folding_0" } }, + { { 127.f }, ngraph::element::f32, { 6, 1, 1, 1 }, false, 1ul, element::i8, false, + { ov::pass::DisableConstantFolding::get_type_info_static() } }, {} }, { std::vector{ 2.f }, ngraph::element::i8}, @@ -417,7 +419,8 @@ const std::vector testValues = { }, { {}, - { { 127.f }, ngraph::element::f32, { 6, 1, 1, 1 }, false, 1ul, element::i8, false, { "disabled_constant_folding_0" } }, + { { 127.f }, ngraph::element::f32, { 6, 1, 1, 1 }, false, 1ul, element::i8, false, + { ov::pass::DisableConstantFolding::get_type_info_static() } }, {} }, { std::vector{ 2.f }, ngraph::element::i8}, diff --git a/inference-engine/tests/functional/inference_engine/lp_transformations/disable_convert_on_const_path_transformation.cpp b/inference-engine/tests/functional/inference_engine/lp_transformations/disable_convert_on_const_path_transformation.cpp index cafdd3a76b8..41dfb4b2020 100644 --- a/inference-engine/tests/functional/inference_engine/lp_transformations/disable_convert_on_const_path_transformation.cpp +++ b/inference-engine/tests/functional/inference_engine/lp_transformations/disable_convert_on_const_path_transformation.cpp @@ -145,12 +145,14 @@ const std::vector testValues = { ngraph::element::u8, { {ngraph::element::f32}, - { {128.f}, element::f32, {}, false, 1ul, element::u8, true, {}, { "disabled_constant_folding_0" } }, + { {128.f}, element::f32, {}, false, 1ul, element::u8, true, {}, + {ov::pass::DisableConstantFolding::get_type_info_static() } }, { {0.02f}, element::f32, {}, false } }, { { ngraph::element::f32, false }, - { {128.f}, element::f32, {}, false, 1ul, element::i8, true, {}, { "disabled_constant_folding_0" } }, + { {128.f}, element::f32, {}, false, 1ul, element::i8, true, {}, + {ov::pass::DisableConstantFolding::get_type_info_static() } }, { {0.03f}, element::f32, {}, false } }, { std::vector{ 1.f }, ngraph::element::f32}, diff --git a/inference-engine/tests/functional/inference_engine/lp_transformations/fake_quantize_with_dq_not_optimal_transformation.cpp b/inference-engine/tests/functional/inference_engine/lp_transformations/fake_quantize_with_dq_not_optimal_transformation.cpp index 2dddf5e7dcc..1cdcd700944 100644 --- a/inference-engine/tests/functional/inference_engine/lp_transformations/fake_quantize_with_dq_not_optimal_transformation.cpp +++ b/inference-engine/tests/functional/inference_engine/lp_transformations/fake_quantize_with_dq_not_optimal_transformation.cpp @@ -198,7 +198,9 @@ const std::vector fakeQuanti {}, { {}, - { std::vector(64, 127.f), ngraph::element::f32, {64, 1, 1, 1}, false, 1ul, ngraph::element::i8, false, {"disabled_constant_folding_0"}}, + { std::vector(64, 127.f), ngraph::element::f32, + {64, 1, 1, 1}, false, 1ul, ngraph::element::i8, false, + {ov::pass::DisableConstantFolding::get_type_info_static()}}, {} }, { diff --git a/inference-engine/tests/functional/inference_engine/lp_transformations/group_convolution_transformation.cpp b/inference-engine/tests/functional/inference_engine/lp_transformations/group_convolution_transformation.cpp index 6ce4e41ef28..aa65dd44312 100644 --- a/inference-engine/tests/functional/inference_engine/lp_transformations/group_convolution_transformation.cpp +++ b/inference-engine/tests/functional/inference_engine/lp_transformations/group_convolution_transformation.cpp @@ -473,7 +473,7 @@ const std::vector testValuesGroupConv = { 1, ngraph::element::i8, false, - {"disabled_constant_folding_0"} + {ov::pass::DisableConstantFolding::get_type_info_static()} }, {} }, diff --git a/inference-engine/tests/functional/inference_engine/lp_transformations/layer_transformation.hpp b/inference-engine/tests/functional/inference_engine/lp_transformations/layer_transformation.hpp index b90717de7ac..708b5d0c2ca 100644 --- a/inference-engine/tests/functional/inference_engine/lp_transformations/layer_transformation.hpp +++ b/inference-engine/tests/functional/inference_engine/lp_transformations/layer_transformation.hpp @@ -83,10 +83,9 @@ public: for (size_t nodeIndex = 0ul; nodeIndex < nodes.size(); nodeIndex++) { auto& rt = nodes[nodeIndex]->get_rt_info(); for (auto& it : rt) { - auto reference = std::dynamic_pointer_cast>>(it.second); - assert(reference != nullptr); - if ((reference->get()->sharedValue->combinedInterval.low != intervalLow) && - (reference->get()->sharedValue->combinedInterval.high != intervalHigh)) { + auto& reference = it.second.as(); + if ((reference.value().combinedInterval.low != intervalLow) && + (reference.value().combinedInterval.high != intervalHigh)) { return false; } } @@ -96,10 +95,10 @@ public: } static bool compare( - const std::shared_ptr& value1, - const std::shared_ptr& value2) { - if ((value1->sharedValue->combinedInterval.low != value2->sharedValue->combinedInterval.low) || - (value1->sharedValue->combinedInterval.high != value2->sharedValue->combinedInterval.high)) { + const IntervalsAlignmentAttribute& value1, + const IntervalsAlignmentAttribute& value2) { + if ((value1.value().combinedInterval.low != value2.value().combinedInterval.low) || + (value1.value().combinedInterval.high != value2.value().combinedInterval.high)) { return false; } return true; @@ -124,10 +123,8 @@ public: return false; } - auto reference = std::dynamic_pointer_cast>(referenceIt->second); - auto actual = std::dynamic_pointer_cast>(actualIt.second); - if ((actual != nullptr) && (reference != nullptr)) { - if (!compare(reference->get(), actual->get())) { + if (!referenceIt->second.empty() && !actualIt.second.empty()) { + if (!compare(referenceIt->second.template as(), actualIt.second.template as())) { return false; } } @@ -139,24 +136,22 @@ public: template static bool checkIfOutputAttributesAreTheSame(const NodeVector& nodes) { - void* first = nullptr; + ov::Any first; for (auto node : nodes) { for (auto output : node->outputs()) { auto& rt = output.get_rt_info(); - const std::string& name = VariantWrapper::type_info.name; + const std::string& name = Attribute::get_type_info_static(); auto it = rt.find(name); if (it == rt.end()) { return false; } auto value = it->second; - OPENVINO_SUPPRESS_DEPRECATED_START - if (first == nullptr) { - first = value.get(); - } else if (value.get() != first) { + if (first.empty()) { + first = value; + } else if (value.template as().attribute != first.template as().attribute) { return false; } - OPENVINO_SUPPRESS_DEPRECATED_END } } return true; @@ -164,15 +159,15 @@ public: template static bool checkIfOutputAttributesSharedValuesAreTheSame(const NodeVector& nodes) { - std::shared_ptr first = nullptr; + ov::Any first; for (auto node : nodes) { for (auto output : node->outputs()) { auto value = ngraph::pass::low_precision::getAttributeFromOutput(output); - if (first == nullptr) { + if (first.empty()) { first = value; } else { - const auto sharedValue1 = std::dynamic_pointer_cast>(value)->get()->sharedValue; - const auto sharedValue2 = std::dynamic_pointer_cast>(first)->get()->sharedValue; + const auto sharedValue1 = value.template as().attribute->sharedValue; + const auto sharedValue2 = first.template as().attribute->sharedValue; if (sharedValue1 != sharedValue2) { return false; } @@ -184,18 +179,18 @@ public: template static bool checkIfAttributesSharedValuesAreTheSame(const NodeVector& nodes) { - std::shared_ptr first = nullptr; + ov::Any first; for (auto node : nodes) { auto value = ngraph::pass::low_precision::getAttribute(node); - if (value == nullptr) { + if (value.empty()) { return false; } - if (first == nullptr) { + if (first.empty()) { first = value; } else { - const auto sharedValue1 = std::dynamic_pointer_cast>(value)->get()->sharedValue; - const auto sharedValue2 = std::dynamic_pointer_cast>(first)->get()->sharedValue; + const auto sharedValue1 = value.template as().attribute->sharedValue; + const auto sharedValue2 = first.template as().attribute->sharedValue; if (sharedValue1 != sharedValue2) { return false; } @@ -206,16 +201,16 @@ public: template static bool checkIfAttributesAreTheSame(const NodeVector& nodes) { - Variant* first = nullptr; + ov::Any first; for (auto node : nodes) { auto value = ngraph::pass::low_precision::getAttribute(node); - if (value == nullptr) { + if (value.empty()) { return false; } - if (first == nullptr) { - first = value.get(); - } else if (value.get() != first) { + if (first.empty()) { + first = value; + } else if (value.template as().attribute != first.template as().attribute) { return false; } } diff --git a/inference-engine/tests/functional/inference_engine/lp_transformations/lpt_avoid_shapeof_propagation_test.cpp b/inference-engine/tests/functional/inference_engine/lp_transformations/lpt_avoid_shapeof_propagation_test.cpp index a49749405fd..6cfe443b5e5 100644 --- a/inference-engine/tests/functional/inference_engine/lp_transformations/lpt_avoid_shapeof_propagation_test.cpp +++ b/inference-engine/tests/functional/inference_engine/lp_transformations/lpt_avoid_shapeof_propagation_test.cpp @@ -227,9 +227,7 @@ TEST(LPT, AvoidDequantizationToShapeOfPropagationFakeQuantizeDecompositionTransf auto shapeOf = std::make_shared(fakeQuantize); auto& outInfo = fakeQuantize->output(0).get_rt_info(); - auto attribute = ngraph::pass::low_precision::make_shared_attribute(element::TypeVector{ element::u8, element::i8 }); - auto attributeWrapper = std::make_shared>>(attribute); - outInfo.emplace(ngraph::VariantWrapper>::type_info.name, attributeWrapper); + outInfo.emplace(PrecisionsAttribute::get_type_info_static(), PrecisionsAttribute(element::TypeVector{ element::u8, element::i8 })); auto result1 = std::make_shared(fakeQuantize); auto result2 = std::make_shared(shapeOf); diff --git a/inference-engine/tests/functional/inference_engine/lp_transformations/markup_avg_pool_precisions_transformation.cpp b/inference-engine/tests/functional/inference_engine/lp_transformations/markup_avg_pool_precisions_transformation.cpp index ce38a8a4dba..dd17e8e12f9 100644 --- a/inference-engine/tests/functional/inference_engine/lp_transformations/markup_avg_pool_precisions_transformation.cpp +++ b/inference-engine/tests/functional/inference_engine/lp_transformations/markup_avg_pool_precisions_transformation.cpp @@ -140,14 +140,14 @@ TEST_P(MarkupAvgPoolPrecisionsTransformation, CompareFunctions) { ASSERT_EQ(1ul, avgPoolOperations.size()) << "unexpected avgPoolOperations size: " << avgPoolOperations.size(); { - auto avgPoolPrecisioinPreservedAttribute = ngraph::pass::low_precision::getAttribute( + auto avgPoolPrecisioinPreservedAttribute = ngraph::pass::low_precision::getAttribute( *avgPoolOperations.begin()); - ASSERT_NE(nullptr, avgPoolPrecisioinPreservedAttribute); - ASSERT_EQ(true, avgPoolPrecisioinPreservedAttribute->get()->sharedValue->value); + ASSERT_FALSE(avgPoolPrecisioinPreservedAttribute.empty()); + ASSERT_EQ(true, avgPoolPrecisioinPreservedAttribute.as().value()); } const auto precisionPreserved = LayerTransformation::get(actualFunction); - ASSERT_TRUE(checkIfAttributesAreTheSame>(precisionPreserved)) << + ASSERT_TRUE(checkIfAttributesAreTheSame(precisionPreserved)) << "AvgPoolPrecisionPreservedAttribute are not the same"; //auto res = compare_functions(referenceFunction, actualFunction, true, true); diff --git a/inference-engine/tests/functional/inference_engine/lp_transformations/move_fake_quantize_transformation.cpp b/inference-engine/tests/functional/inference_engine/lp_transformations/move_fake_quantize_transformation.cpp index 5a24340e230..6f3e9806f21 100644 --- a/inference-engine/tests/functional/inference_engine/lp_transformations/move_fake_quantize_transformation.cpp +++ b/inference-engine/tests/functional/inference_engine/lp_transformations/move_fake_quantize_transformation.cpp @@ -162,9 +162,9 @@ public: testValues.actual.convertAfter, testValues.actual.dequantizationAfter, { - ngraph::builder::subgraph::make_shared_attribute_ptr(true), - ngraph::builder::subgraph::make_shared_attribute_ptr(interval, 256), - ngraph::builder::subgraph::make_shared_attribute_ptr(false) + PrecisionPreservedAttribute(true), + IntervalsAlignmentAttribute(interval, 256), + QuantizationAlignmentAttribute(false) }, ngraph::element::undefined, {}, @@ -209,9 +209,9 @@ public: testValues.result.convertAfter, testValues.result.dequantizationAfter, { - ngraph::builder::subgraph::make_shared_attribute_ptr(true), - ngraph::builder::subgraph::make_shared_attribute_ptr(interval, 256), - ngraph::builder::subgraph::make_shared_attribute_ptr(false) + PrecisionPreservedAttribute(true), + IntervalsAlignmentAttribute(interval, 256), + QuantizationAlignmentAttribute(false) }, testValues.result.precisionAfterOperation, {}, @@ -242,7 +242,7 @@ TEST_P(MoveFakeQuantizeTransformation, CompareFunctions) { ASSERT_TRUE(LayerTransformation::allNamesAreUnique(actualFunction)) << "Not all names are unique"; const auto actualFakeQuantizes = LayerTransformation::get(actualFunction); - ASSERT_TRUE(checkIfOutputAttributesSharedValuesAreTheSame>(actualFakeQuantizes)) << + ASSERT_TRUE(checkIfOutputAttributesSharedValuesAreTheSame(actualFakeQuantizes)) << "PrecisionsAttribute are not the same"; } diff --git a/inference-engine/tests/functional/inference_engine/snippets/registers.cpp b/inference-engine/tests/functional/inference_engine/snippets/registers.cpp index 54ce843308a..99dc5c6675d 100644 --- a/inference-engine/tests/functional/inference_engine/snippets/registers.cpp +++ b/inference-engine/tests/functional/inference_engine/snippets/registers.cpp @@ -9,7 +9,6 @@ #include #include -#include #include #include @@ -53,7 +52,7 @@ TEST(TransformationTests, AssignRegisters) { auto it_rinfo = rt.find("reginfo"); if (it_rinfo != rt.end()) { - auto reginfo = ov::as_type_ptr>>(it_rinfo->second)->get(); + auto reginfo = it_rinfo->second.as>(); auto reg = reginfo[0]; ASSERT_TRUE(ref_registers[op->get_friendly_name()] == reg); total_ops++; @@ -127,7 +126,7 @@ TEST(TransformationTests, AssignRegisters2) { auto& rt = op->get_rt_info(); auto it_rinfo = rt.find("reginfo"); if (it_rinfo != rt.end()) { - auto reginfo = ov::as_type_ptr>>(it_rinfo->second)->get(); + auto reginfo = it_rinfo->second.as>(); auto reg = reginfo[0]; ASSERT_TRUE(ref_registers[op->get_friendly_name()] == reg); total_ops++; diff --git a/inference-engine/tests/functional/inference_engine/transformations/primitives_priority_test.cpp b/inference-engine/tests/functional/inference_engine/transformations/primitives_priority_test.cpp index 9df0ba186fc..e87c1669eef 100644 --- a/inference-engine/tests/functional/inference_engine/transformations/primitives_priority_test.cpp +++ b/inference-engine/tests/functional/inference_engine/transformations/primitives_priority_test.cpp @@ -50,7 +50,7 @@ TEST(TransformationTests, ConvBiasFusion) { for (auto & op : nGraph->get_ops()) { if (auto conv = std::dynamic_pointer_cast(op)) { auto & rtInfo = conv->get_rt_info(); - rtInfo["PrimitivesPriority"] = std::make_shared>("test"); + rtInfo[ov::PrimitivesPriority::get_type_info_static()] = ov::PrimitivesPriority("test"); pp[op->get_friendly_name()] = "test"; } } diff --git a/inference-engine/tests/functional/plugin/cpu/test_utils/cpu_test_utils.cpp b/inference-engine/tests/functional/plugin/cpu/test_utils/cpu_test_utils.cpp index 8fd24783dfa..005f1702029 100644 --- a/inference-engine/tests/functional/plugin/cpu/test_utils/cpu_test_utils.cpp +++ b/inference-engine/tests/functional/plugin/cpu/test_utils/cpu_test_utils.cpp @@ -265,18 +265,18 @@ CPUTestsBase::makeCPUInfo(std::vector inFmts, std::vector(fmts2str(inFmts, "cpu:"))}); + cpuInfo.insert({ngraph::MKLDNNInputMemoryFormats::get_type_info_static(), + ngraph::MKLDNNInputMemoryFormats(fmts2str(inFmts, "cpu:"))}); } if (!outFmts.empty()) { - cpuInfo.insert({std::string(ngraph::MLKDNNOutputMemoryFormatsAttr), - std::make_shared(fmts2str(outFmts, "cpu:"))}); + cpuInfo.insert({ngraph::MKLDNNOutputMemoryFormats::get_type_info_static(), + ngraph::MKLDNNOutputMemoryFormats(fmts2str(outFmts, "cpu:"))}); } if (!priority.empty()) { cpuInfo.insert({"PrimitivesPriority", std::make_shared>(impls2str(priority))}); } - cpuInfo.insert({"enforceBF16evenForGraphTail", ov::make_variant(true)}); + cpuInfo.insert({"enforceBF16evenForGraphTail", ov::make_runtime_attribute(true)}); return cpuInfo; } diff --git a/inference-engine/tests/functional/plugin/shared/src/behavior/caching/caching_tests.cpp b/inference-engine/tests/functional/plugin/shared/src/behavior/caching/caching_tests.cpp index 734630d61e5..a206e529c1d 100644 --- a/inference-engine/tests/functional/plugin/shared/src/behavior/caching/caching_tests.cpp +++ b/inference-engine/tests/functional/plugin/shared/src/behavior/caching/caching_tests.cpp @@ -120,7 +120,7 @@ bool LoadNetworkCacheTestBase::importExportSupported(InferenceEngine::Core& ie) std::vector supportedMetricKeys = ie.GetMetric(targetDevice, METRIC_KEY(SUPPORTED_METRICS)); auto it = std::find(supportedMetricKeys.begin(), supportedMetricKeys.end(), METRIC_KEY(IMPORT_EXPORT_SUPPORT)); - bool supported = (it != supportedMetricKeys.end()) && + auto supported = (it != supportedMetricKeys.end()) && ie.GetMetric(targetDevice, METRIC_KEY(IMPORT_EXPORT_SUPPORT)).as(); return supported; } diff --git a/inference-engine/tests/functional/shared_test_classes/src/single_layer/memory.cpp b/inference-engine/tests/functional/shared_test_classes/src/single_layer/memory.cpp index bf8e79a8e30..5b08a7327b8 100644 --- a/inference-engine/tests/functional/shared_test_classes/src/single_layer/memory.cpp +++ b/inference-engine/tests/functional/shared_test_classes/src/single_layer/memory.cpp @@ -46,9 +46,9 @@ namespace LayerTestsDefinitions { } auto hostTensor = std::make_shared(ngPrc, inputShape); - auto variable_context = std::make_shared>(VariableContext()); + auto variable_context = VariableContext(); auto variable_value = std::make_shared(hostTensor); - variable_context->get().set_variable_value(function->get_variable_by_id("v0"), variable_value); + variable_context.set_variable_value(function->get_variable_by_id("v0"), variable_value); eval_context["VariableContext"] = variable_context; } diff --git a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/include/lpt_ngraph_functions/common/builders.hpp b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/include/lpt_ngraph_functions/common/builders.hpp index 9d8183efc0e..efed4204a3d 100644 --- a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/include/lpt_ngraph_functions/common/builders.hpp +++ b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/include/lpt_ngraph_functions/common/builders.hpp @@ -94,46 +94,7 @@ std::shared_ptr makeFakeQuantizeTypeRelaxed( const ngraph::element::Type constantPrecision, const FakeQuantizeOnDataWithConstant& fqOnData); -template -void addAttribute(std::vector> nodes, Args&& ... args) { - const auto attribute = std::make_shared>( - QuantizationAlignmentAttribute(std::forward(args)...)); - - for (const auto& node : nodes) { - node->get_rt_info()[ngraph::VariantWrapper::type_info.name] = attribute; - } -} - -template -void addAttribute2(std::vector> nodes, T attribute) { - const std::string typeInfoName = attribute->get_type_info().name; - for (const auto& node : nodes) { - auto& rt = node->get_rt_info(); - rt[typeInfoName] = attribute; - } -} - -template -void addAttribute3(std::vector> nodes, Args&& ... args) { - const auto attribute = std::make_shared<::ngraph::VariantWrapper>(T(std::forward(args)...)); - for (const auto& node : nodes) { - node->get_rt_info()[ngraph::VariantWrapper::type_info.name] = attribute; - } -} - -void addAttributes(std::vector> nodes, std::vector> attributes); - -template -std::shared_ptr make_shared_attribute(Args&& ... args) { - const auto attribute = std::make_shared<::ngraph::VariantWrapper>(T(std::forward(args)...)); - return attribute; -} - -template -std::shared_ptr make_shared_attribute_ptr(Args&& ... args) { - const auto attribute = std::make_shared<::ngraph::VariantWrapper>>(std::make_shared(std::forward(args)...)); - return attribute; -} +void addAttributes(std::vector> nodes, std::vector attributes); std::shared_ptr makeConvolution( const std::shared_ptr& parent, diff --git a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/include/lpt_ngraph_functions/common/fake_quantize_on_data.hpp b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/include/lpt_ngraph_functions/common/fake_quantize_on_data.hpp index af98d72327d..0ca59f7b5d0 100644 --- a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/include/lpt_ngraph_functions/common/fake_quantize_on_data.hpp +++ b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/include/lpt_ngraph_functions/common/fake_quantize_on_data.hpp @@ -24,7 +24,7 @@ public: const std::vector& outputLowValues, const std::vector& outputHighValues, const ngraph::element::Type outputPrecision = ngraph::element::undefined, - const std::vector>& attributes = {}); + const std::vector& attributes = {}); virtual ~FakeQuantizeOnData(); @@ -38,7 +38,7 @@ public: std::vector outputLowValues; std::vector outputHighValues; ngraph::element::Type outputPrecision; - std::vector> attributes; + std::vector attributes; }; inline std::ostream& operator<<(std::ostream& os, const std::vector& values) { @@ -71,8 +71,8 @@ public: const std::vector& outputLowValues, const std::vector& outputHighValues, const ngraph::element::Type outputPrecision = ngraph::element::undefined, - const std::vector>& attributes = {}); + const std::vector& attributes = {}); virtual ~FakeQuantizeOnDataWithConstant(); virtual bool empty() const; @@ -84,7 +84,7 @@ public: std::vector outputLowValues; std::vector outputHighValues; ngraph::element::Type outputPrecision; - std::vector> attributes; + std::vector attributes; }; inline std::ostream& operator<<(std::ostream& out, const FakeQuantizeOnDataWithConstant& data) { diff --git a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/include/lpt_ngraph_functions/concat_function.hpp b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/include/lpt_ngraph_functions/concat_function.hpp index 0aa75c2cfbc..b723c4cfbe1 100644 --- a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/include/lpt_ngraph_functions/concat_function.hpp +++ b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/include/lpt_ngraph_functions/concat_function.hpp @@ -123,7 +123,7 @@ public: const FakeQuantizeOnDataWithConstant& fakeQuantize2, const DequantizationOperations::Convert& convert2, const DequantizationOperations& dequantization2, - const std::vector>& concatAttributes, + const std::vector& concatAttributes, const ngraph::element::Type precisionAfterOperation, const DequantizationOperations& dequantizationAfter, const std::int64_t& axis, @@ -141,7 +141,7 @@ public: const DequantizationOperations::Convert& convert2, const DequantizationOperations& dequantization2, const bool addReshape2, - const std::vector>& concatAttributes, + const std::vector& concatAttributes, const ngraph::element::Type precisionAfterOperation, const DequantizationOperations& dequantizationAfter, const std::int64_t& axis, diff --git a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/include/lpt_ngraph_functions/move_fake_quantize_function.hpp b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/include/lpt_ngraph_functions/move_fake_quantize_function.hpp index 9640845c8be..bdd2f6fbc8c 100644 --- a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/include/lpt_ngraph_functions/move_fake_quantize_function.hpp +++ b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/include/lpt_ngraph_functions/move_fake_quantize_function.hpp @@ -30,7 +30,7 @@ public: const FakeQuantizeOnDataWithConstant& fqOnData3, const DequantizationOperations::Convert& convert3, const DequantizationOperations& dequantization3, - const std::vector>& concatAttributes, + const std::vector& concatAttributes, const ngraph::element::Type precisionAfterOperation, const DequantizationOperations& dequantizationAfter, const std::int64_t& axis); diff --git a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/common/builders.cpp b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/common/builders.cpp index 0d639b78519..3c11cefbd63 100644 --- a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/common/builders.cpp +++ b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/common/builders.cpp @@ -282,7 +282,9 @@ std::shared_ptr makeFakeQuantize( auto& rt = fq->get_rt_info(); for (auto& attribute : fqOnData.attributes) { - rt[attribute->get_type_info().name] = attribute; + if (attribute.is()) { + rt[attribute.as().get_type_info()] = attribute; + } } return fq; @@ -298,12 +300,12 @@ std::shared_ptr makeFakeQuantizeTypeRelaxed( fqOnData.outputPrecision == ngraph::element::undefined ? constantPrecision : fqOnData.outputPrecision); } -void addAttributes(std::vector> nodes, std::vector> attributes) { +void addAttributes(std::vector> nodes, std::vector attributes) { for (const auto& node : nodes) { for (const auto& attribute : attributes) { - auto& rt = node->get_rt_info(); - const std::string typeInfoName = attribute->get_type_info().name; - rt[typeInfoName] = attribute; + if (attribute.is()) { + node->get_rt_info()[attribute.as().get_type_info()] = attribute; + } } } } diff --git a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/common/fake_quantize_on_data.cpp b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/common/fake_quantize_on_data.cpp index 2c4f2468fe4..6affee88336 100644 --- a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/common/fake_quantize_on_data.cpp +++ b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/common/fake_quantize_on_data.cpp @@ -19,7 +19,7 @@ FakeQuantizeOnData::FakeQuantizeOnData( const std::vector& outputLowValues, const std::vector& outputHighValues, const ngraph::element::Type outputPrecision, - const std::vector>& attributes) : + const std::vector& attributes) : quantizationLevel(quantizationLevel), constantShape(constantShape), inputLowValues(inputLowValues), @@ -58,7 +58,7 @@ FakeQuantizeOnDataWithConstant::FakeQuantizeOnDataWithConstant( const std::vector& outputLowValues, const std::vector& outputHighValues, const ngraph::element::Type outputPrecision, - const std::vector>& attributes) : + const std::vector& attributes) : quantizationLevel(quantizationLevel), constantShapes(constantShapes), inputLowValues(inputLowValues), diff --git a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/concat_function.cpp b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/concat_function.cpp index 28c04e0ed4d..9e5d914db09 100644 --- a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/concat_function.cpp +++ b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/concat_function.cpp @@ -874,7 +874,7 @@ std::shared_ptr ConcatFunction::get( const FakeQuantizeOnDataWithConstant& fqOnData2, const DequantizationOperations::Convert& convert2, const DequantizationOperations& dequantization2, - const std::vector>& concatAttributes, + const std::vector& concatAttributes, const ngraph::element::Type precisionAfterOperation, const DequantizationOperations& dequantizationAfter, const std::int64_t& axis, @@ -960,7 +960,7 @@ std::shared_ptr ConcatFunction::get( const DequantizationOperations::Convert& convert2, const DequantizationOperations& dequantization2, const bool addReshape2, - const std::vector>& concatAttributes, + const std::vector& concatAttributes, const ngraph::element::Type precisionAfterOperation, const DequantizationOperations& dequantizationAfter, const std::int64_t& axis, diff --git a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/move_fake_quantize_function.cpp b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/move_fake_quantize_function.cpp index c53ddd3f6df..6c3ea3a09b9 100644 --- a/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/move_fake_quantize_function.cpp +++ b/inference-engine/tests/ngraph_helpers/lpt_ngraph_functions/src/move_fake_quantize_function.cpp @@ -32,7 +32,7 @@ std::shared_ptr MoveFakeQuantize::get( const FakeQuantizeOnDataWithConstant& fqOnData3, const DequantizationOperations::Convert& convert3, const DequantizationOperations& dequantization3, - const std::vector>& concatAttributes, + const std::vector& concatAttributes, const ngraph::element::Type precisionAfterOperation, const DequantizationOperations& dequantizationAfter, const std::int64_t& axis) { diff --git a/inference-engine/tests/unit/inference_engine/ie_compilation_context_test.cpp b/inference-engine/tests/unit/inference_engine/ie_compilation_context_test.cpp index 1989dd11bab..d3f49772975 100644 --- a/inference-engine/tests/unit/inference_engine/ie_compilation_context_test.cpp +++ b/inference-engine/tests/unit/inference_engine/ie_compilation_context_test.cpp @@ -134,13 +134,22 @@ static std::shared_ptr create_simple_function() { data->get_output_tensor(0).set_names({"parameter"}); auto mul_constant = ngraph::opset6::Constant::create(ngraph::element::i8, ngraph::Shape{1}, {3}); + mul_constant->set_friendly_name("mul_constant"); + mul_constant->get_output_tensor(0).set_names({"mul_constant"}); auto mul = std::make_shared(data, mul_constant); + mul->set_friendly_name("mul"); + mul->get_output_tensor(0).set_names({"mul"}); auto add_constant = ngraph::opset6::Constant::create(ngraph::element::i8, ngraph::Shape{1}, {2}); + add_constant->set_friendly_name("add_constant"); + add_constant->get_output_tensor(0).set_names({"add_constant"}); auto add = std::make_shared(mul, add_constant); + add->set_friendly_name("add"); + add->get_output_tensor(0).set_names({"add"}); // Create opset3::Result operation auto res = std::make_shared(add); + res->set_friendly_name("res"); // Create nGraph function auto func = std::make_shared(ngraph::ResultVector{res}, ngraph::ParameterVector{data}); @@ -208,7 +217,7 @@ TEST(NetworkContext_CNNNetwork, HashWithPrimitivesPriority) { auto net2 = createNetwork(); auto net3 = createNetwork(); auto & op2 = net2.getFunction()->get_ops().front()->get_rt_info(); - op2["PrimitivesPriority"] = std::make_shared > ("testPriority"); + op2[ov::PrimitivesPriority::get_type_info_static()] = ov::PrimitivesPriority("testPriority"); auto & op3 = net3.getFunction()->get_ops().front()->get_rt_info(); op3["PrimitivesPriority"] = std::make_shared > ("testPriority"); @@ -222,24 +231,20 @@ TEST(NetworkContext_CNNNetwork, HashWithPrimitivesPriority) { TEST(NetworkContext_CNNNetwork, HashWithFusedNames) { auto setFusedEmpty = [&](Node::RTMap& rtInfo) { - rtInfo[VariantWrapper::get_type_info_static()] = - std::make_shared>(ngraph::FusedNames()); + rtInfo[ngraph::FusedNames::get_type_info_static()] = ngraph::FusedNames(); }; auto setFused = [&](Node::RTMap& rtInfo, const std::string& name) { - rtInfo[VariantWrapper::get_type_info_static()] = - std::make_shared>(ngraph::FusedNames(name)); + rtInfo[ngraph::FusedNames::get_type_info_static()] = ngraph::FusedNames(name); }; checkCustomRt(setFusedEmpty, setFused); } TEST(NetworkContext_CNNNetwork, HashWithPrimitivesPriorityType) { auto setPrimEmpty = [&](Node::RTMap& rtInfo) { - rtInfo[ov::PrimitivesPriority::get_type_info_static()] = - std::make_shared(""); + rtInfo[ov::PrimitivesPriority::get_type_info_static()] = ov::PrimitivesPriority(""); }; auto setPrim = [&](Node::RTMap& rtInfo, const std::string& name) { - rtInfo[ov::PrimitivesPriority::get_type_info_static()] = - std::make_shared(name); + rtInfo[ov::PrimitivesPriority::get_type_info_static()] = ov::PrimitivesPriority(name); }; checkCustomRt(setPrimEmpty, setPrim); } diff --git a/model-optimizer/unit_tests/mock_mo_frontend/mock_mo_ov_frontend/mock_mo_frontend.hpp b/model-optimizer/unit_tests/mock_mo_frontend/mock_mo_ov_frontend/mock_mo_frontend.hpp index 5f000ab5131..7ad504a24a4 100644 --- a/model-optimizer/unit_tests/mock_mo_frontend/mock_mo_ov_frontend/mock_mo_frontend.hpp +++ b/model-optimizer/unit_tests/mock_mo_frontend/mock_mo_ov_frontend/mock_mo_frontend.hpp @@ -414,10 +414,10 @@ class MOCK_API FrontEndMockPy : public FrontEnd public: FrontEndMockPy() {} - std::shared_ptr convert(InputModel::Ptr model) const override + std::shared_ptr convert(InputModel::Ptr model) const override { m_stat.m_convert_model++; - return std::make_shared(NodeVector{}, ParameterVector{}); + return std::make_shared(ov::NodeVector{}, ov::ParameterVector{}); } static FeStat get_stat() { return m_stat; } @@ -425,22 +425,22 @@ public: static void clear_stat() { m_stat = {}; } private: - InputModel::Ptr load_impl(const std::vector>& params) const override + InputModel::Ptr load_impl(const std::vector& params) const override { - if (params.size() > 0 && ov::is_type>(params[0])) + if (params.size() > 0 && params[0].is()) { - auto path = ov::as_type_ptr>(params[0])->get(); + auto path = params[0].as(); m_stat.m_load_paths.push_back(path); } return std::make_shared(); } - bool supported_impl(const std::vector>& params) const override + bool supported_impl(const std::vector& params) const override { m_stat.m_supported++; - if (params.size() > 0 && ov::is_type>(params[0])) + if (params.size() > 0 && params[0].is()) { - auto path = ov::as_type_ptr>(params[0])->get(); + auto path = params[0].as(); if (path.find(".test_mo_mock_mdl") != std::string::npos) { return true; diff --git a/src/bindings/python/src/compatibility/pyngraph/rt_map.cpp b/src/bindings/python/src/compatibility/pyngraph/rt_map.cpp index 535594f0564..5bcc81423c3 100644 --- a/src/bindings/python/src/compatibility/pyngraph/rt_map.cpp +++ b/src/bindings/python/src/compatibility/pyngraph/rt_map.cpp @@ -20,7 +20,7 @@ namespace py = pybind11; -using PyRTMap = std::map; +using PyRTMap = ngraph::RTMap; PYBIND11_MAKE_OPAQUE(PyRTMap); @@ -35,4 +35,7 @@ void regclass_pyngraph_PyRTMap(py::module m) { py_map.def("__setitem__", [](PyRTMap& m, const std::string& k, const int64_t v) { m[k] = v; }); + py_map.def("__getitem__", [](PyRTMap& m, const std::string& k) { + return m.at(k).as>(); + }); } diff --git a/src/bindings/python/src/pyopenvino/graph/node.cpp b/src/bindings/python/src/pyopenvino/graph/node.cpp index 1552367b965..f556b580843 100644 --- a/src/bindings/python/src/pyopenvino/graph/node.cpp +++ b/src/bindings/python/src/pyopenvino/graph/node.cpp @@ -9,7 +9,7 @@ #include #include "dict_attribute_visitor.hpp" -#include "openvino/core/variant.hpp" +#include "openvino/core/runtime_attribute.hpp" #include "openvino/op/add.hpp" #include "openvino/op/divide.hpp" #include "openvino/op/multiply.hpp" diff --git a/src/bindings/python/src/pyopenvino/graph/rt_map.cpp b/src/bindings/python/src/pyopenvino/graph/rt_map.cpp index 95f1d8f0f42..ec60f8d0f36 100644 --- a/src/bindings/python/src/pyopenvino/graph/rt_map.cpp +++ b/src/bindings/python/src/pyopenvino/graph/rt_map.cpp @@ -10,7 +10,7 @@ #include "dict_attribute_visitor.hpp" #include "openvino/core/node.hpp" -#include "openvino/core/variant.hpp" +#include "openvino/core/runtime_attribute.hpp" #include "openvino/op/add.hpp" #include "openvino/op/divide.hpp" #include "openvino/op/multiply.hpp" diff --git a/src/bindings/python/src/pyopenvino/graph/variant.hpp b/src/bindings/python/src/pyopenvino/graph/variant.hpp index 3dee3c6d6f0..fe84fd63d30 100644 --- a/src/bindings/python/src/pyopenvino/graph/variant.hpp +++ b/src/bindings/python/src/pyopenvino/graph/variant.hpp @@ -10,7 +10,7 @@ #include #include -#include "openvino/core/any.hpp" // ov::Variant +#include "openvino/core/any.hpp" // ov::RuntimeAttribute namespace py = pybind11; diff --git a/src/bindings/python/tests/mock/mock_py_ov_frontend/mock_py_frontend.hpp b/src/bindings/python/tests/mock/mock_py_ov_frontend/mock_py_frontend.hpp index 416787a6a0b..0e45241492c 100644 --- a/src/bindings/python/tests/mock/mock_py_ov_frontend/mock_py_frontend.hpp +++ b/src/bindings/python/tests/mock/mock_py_ov_frontend/mock_py_frontend.hpp @@ -614,16 +614,16 @@ class MOCK_API FrontEndMockPy : public FrontEnd { public: FrontEndMockPy() {} - InputModel::Ptr load_impl(const std::vector>& params) const override { - if (params.size() > 0 && ov::is_type>(params[0])) - m_stat.m_load_paths.push_back(ov::as_type_ptr>(params[0])->get()); + InputModel::Ptr load_impl(const std::vector& params) const override { + if (params.size() > 0 && params[0].is()) + m_stat.m_load_paths.push_back(params[0].as()); return std::make_shared(); } - bool supported_impl(const std::vector>& params) const override { + bool supported_impl(const std::vector& params) const override { m_stat.m_supported++; - if (params.size() > 0 && ov::is_type>(params[0])) { - auto path = ov::as_type_ptr>(params[0])->get(); + if (params.size() > 0 && params[0].is()) { + auto path = params[0].as(); if (path.find(".test_mock_py_mdl") != std::string::npos) { return true; } @@ -631,26 +631,26 @@ public: return false; } - std::shared_ptr convert(InputModel::Ptr model) const override { + std::shared_ptr convert(InputModel::Ptr model) const override { m_stat.m_convert_model++; - return std::make_shared(NodeVector{}, ParameterVector{}); + return std::make_shared(ov::NodeVector{}, ov::ParameterVector{}); } - void convert(std::shared_ptr func) const override { + void convert(std::shared_ptr func) const override { m_stat.m_convert++; } - std::shared_ptr convert_partially(InputModel::Ptr model) const override { + std::shared_ptr convert_partially(InputModel::Ptr model) const override { m_stat.m_convert_partially++; - return std::make_shared(NodeVector{}, ParameterVector{}); + return std::make_shared(ov::NodeVector{}, ov::ParameterVector{}); } - std::shared_ptr decode(InputModel::Ptr model) const override { + std::shared_ptr decode(InputModel::Ptr model) const override { m_stat.m_decode++; - return std::make_shared(NodeVector{}, ParameterVector{}); + return std::make_shared(ov::NodeVector{}, ov::ParameterVector{}); } - void normalize(std::shared_ptr function) const override { + void normalize(std::shared_ptr function) const override { m_stat.m_normalize++; } diff --git a/src/common/legacy/src/convert_function_to_cnn_network.cpp b/src/common/legacy/src/convert_function_to_cnn_network.cpp index ddc4ae231d3..3e05992d0d2 100644 --- a/src/common/legacy/src/convert_function_to_cnn_network.cpp +++ b/src/common/legacy/src/convert_function_to_cnn_network.cpp @@ -1629,7 +1629,7 @@ CNNLayerCreator::CNNLayerCreator(const std::shared_ptr<::ngraph::Node>& node): n << " attribute is set in " << node->get_friendly_name() << " node"; } - auto getStringValue = [] (const std::shared_ptr & variant) { + auto getStringValue = [] (const ov::Any& variant) { auto castedVariant = std::dynamic_pointer_cast>(variant); IE_ASSERT(castedVariant != nullptr); return castedVariant->get(); @@ -1932,13 +1932,13 @@ void convertFunctionToICNNNetwork(const std::shared_ptr type - using VariantString = ::ngraph::VariantWrapper; for (const auto &rt : rt_info) { - if (auto str_attr = std::dynamic_pointer_cast(rt.second)) { + if (rt.second.is()) { + auto str_attr = rt.second.as(); if (details::CaselessEq()(rt.first, "affinity")) { - cnnLayer->affinity = str_attr->get(); + cnnLayer->affinity = str_attr; } else { - cnnLayer->params[rt.first] = str_attr->get(); + cnnLayer->params[rt.first] = str_attr; } } } diff --git a/src/common/low_precision_transformations/include/low_precision/create_attribute.hpp b/src/common/low_precision_transformations/include/low_precision/create_attribute.hpp index 819cd11b430..c7b7c468826 100644 --- a/src/common/low_precision_transformations/include/low_precision/create_attribute.hpp +++ b/src/common/low_precision_transformations/include/low_precision/create_attribute.hpp @@ -47,8 +47,8 @@ public: } { OV_ITT_SCOPE(FIRST_INFERENCE, itt::domains::LPT_LT, "CreateAttribute"); - const auto attribute = ngraph::VariantWrapper::create(op, params); - if (attribute == nullptr) { + const auto attribute = AttributeType::create(op, params); + if (attribute.empty()) { return false; } } diff --git a/src/common/low_precision_transformations/include/low_precision/create_precisions_dependent_attribute.hpp b/src/common/low_precision_transformations/include/low_precision/create_precisions_dependent_attribute.hpp index 4104d646e23..2e05cc85761 100644 --- a/src/common/low_precision_transformations/include/low_precision/create_precisions_dependent_attribute.hpp +++ b/src/common/low_precision_transformations/include/low_precision/create_precisions_dependent_attribute.hpp @@ -45,20 +45,18 @@ public: OV_ITT_SCOPE(FIRST_INFERENCE, itt::domains::LPT_LT, "CreatePrecisionsDependentAttribute"); auto &rt = node->get_rt_info(); - const auto precisionPreservedAttribute = std::make_shared>( - std::make_shared(false)); - rt[ngraph::VariantWrapper::type_info.name] = precisionPreservedAttribute; - const auto &targetSharedValue = precisionPreservedAttribute->get()->sharedValue; + const auto precisionPreservedAttribute = PrecisionPreservedAttribute(false); + rt[PrecisionPreservedAttribute::get_type_info_static()] = precisionPreservedAttribute; + const auto &targetSharedValue = precisionPreservedAttribute.attribute->sharedValue; - const auto attribute = std::make_shared>>( - std::make_shared()); - rt[ngraph::VariantWrapper>::type_info.name] = attribute; + const auto attribute = AttributeType{}; + rt[AttributeType::get_type_info_static()] = attribute; - ngraph::pass::low_precision::NetworkHelper::reassign( + ngraph::pass::low_precision::NetworkHelper::reassign( targetSharedValue, { - std::dynamic_pointer_cast(attribute->get()), - std::dynamic_pointer_cast(precisionPreservedAttribute->get()) + attribute.attribute, + precisionPreservedAttribute.attribute }); } return true; diff --git a/src/common/low_precision_transformations/include/low_precision/network_helper.hpp b/src/common/low_precision_transformations/include/low_precision/network_helper.hpp index 9da92e72631..dc040b7cb2c 100644 --- a/src/common/low_precision_transformations/include/low_precision/network_helper.hpp +++ b/src/common/low_precision_transformations/include/low_precision/network_helper.hpp @@ -218,8 +218,8 @@ public: static void replaceAttributeInNodes( std::shared_ptr f, const std::string& name, - const std::shared_ptr newAttribute, - const std::shared_ptr oldAttribute, + const ov::Any& newAttribute, + const ov::Any& oldAttribute, const std::shared_ptr& initialNode) { std::set> visited; std::deque> nodes; @@ -246,7 +246,7 @@ public: auto it = rt.find(name); if (it != rt.end()) { const auto currentAttribute = it->second; - if (oldAttribute == as_type_ptr(currentAttribute)) { + if (oldAttribute == currentAttribute) { rt[name] = newAttribute; } handleConnectedNodes = true; @@ -296,10 +296,10 @@ public: } } - template + template static void reassign( - const std::shared_ptr& sharedValue, - const std::vector>& attributes) { + const std::shared_ptr& sharedValue, + const std::vector>& attributes) { for (const auto attributeWeakPtr : attributes) { auto attribute = attributeWeakPtr.lock(); if (attribute == nullptr) { @@ -415,53 +415,37 @@ std::shared_ptr fold_reshape(Args&&... args) { } template -std::shared_ptr> getAttribute(const std::shared_ptr& inputNode) { - auto& rt = inputNode->get_rt_info(); - auto it = rt.find(ngraph::VariantWrapper::type_info.name); +ov::Any getAttribute(const std::shared_ptr& node) { + auto& rt = node->get_rt_info(); + auto it = rt.find(T::get_type_info_static()); if (it == rt.end()) { - return nullptr; + return {}; } - - auto attribute = std::dynamic_pointer_cast>(it->second); - assert(attribute != nullptr); - return attribute; + return it->second; } template -std::shared_ptr> getAttribute(const Input& input) { +ov::Any getAttribute(const Input& input) { auto& rt = input.get_rt_info(); - auto it = rt.find(ngraph::VariantWrapper::type_info.name); + auto it = rt.find(T::get_type_info_static()); if (it == rt.end()) { - return nullptr; + return {}; } - - auto attribute = std::dynamic_pointer_cast>(it->second); - assert(attribute != nullptr); - return attribute; + return it->second; } template -std::shared_ptr> getAttributeFromOutput(const Output& output) { +ov::Any getAttributeFromOutput(const Output& output) { auto& rt = output.get_rt_info(); - auto it = rt.find(ngraph::VariantWrapper::type_info.name); + auto it = rt.find(T::get_type_info_static()); if (it == rt.end()) { - return nullptr; + return {}; } - - auto attribute = std::dynamic_pointer_cast>(it->second); - assert(attribute != nullptr); - return attribute; + return it->second; } bool isDisabled(const std::shared_ptr& node); -template -std::shared_ptr make_shared_attribute(Args&& ... args) { - std::shared_ptr attribute = std::make_shared(std::forward(args)...); - attribute->sharedValue->attributes.push_back(attribute); - return attribute; -} - } // namespace low_precision } // namespace pass } // namespace ngraph diff --git a/src/common/low_precision_transformations/include/low_precision/propagate_shared_value.hpp b/src/common/low_precision_transformations/include/low_precision/propagate_shared_value.hpp index 6a83a74089a..0be0cf20fa2 100644 --- a/src/common/low_precision_transformations/include/low_precision/propagate_shared_value.hpp +++ b/src/common/low_precision_transformations/include/low_precision/propagate_shared_value.hpp @@ -39,11 +39,7 @@ public: if (ov::is_type(node)) { assert(node->get_output_size() == 1ul); auto& outputRtInfo = node->output(0).get_rt_info(); - - auto attribute = make_shared_attribute(std::set{element::u8, element::i8}); - - auto attributeWrapper = std::make_shared>>(attribute); - outputRtInfo[ngraph::VariantWrapper>::type_info.name] = attributeWrapper; + outputRtInfo[AttributeType::get_type_info_static()] = AttributeType{std::set{element::u8, element::i8}}; continue; } @@ -52,17 +48,16 @@ public: auto parentNode = input.get_source_output().get_node_shared_ptr(); auto getAttributes = [](const Input& nodeInput) { - const std::string name = ngraph::VariantWrapper>::type_info.name; + const std::string name = PrecisionsAttribute::get_type_info_static(); auto node = nodeInput.get_source_output().get_node_shared_ptr(); - std::vector>>> attributes; + std::vector attributes; if (ov::is_type(node)) { // output auto& rt = nodeInput.get_source_output().get_rt_info(); auto it = rt.find(name); if (it != rt.end()) { - const auto& attribute = std::dynamic_pointer_cast>>(it->second); - attributes.push_back(attribute); + attributes.push_back(it->second); } } @@ -71,14 +66,13 @@ public: auto& nodeRt = input.get_rt_info(); - const std::string name = ngraph::VariantWrapper>::type_info.name; + const std::string name = PrecisionsAttribute::get_type_info_static(); const auto it = nodeRt.find(name); if (it == nodeRt.end()) { continue; } - const auto& attribute = std::dynamic_pointer_cast>>(it->second); - std::vector>>> attributes{ attribute }; + std::vector attributes{ it->second }; auto parentAttributes = getAttributes(input); if (parentAttributes.empty()) { @@ -86,7 +80,7 @@ public: } for (auto& parentAttribute : parentAttributes) { - parentAttribute->merge(attributes); + parentAttribute.as.merge(attributes); } nodeRt[name] = parentAttributes[0]; @@ -100,9 +94,9 @@ public: } private: - std::vector>>> getParentInputRestrictions( + std::vector getParentInputRestrictions( const std::shared_ptr node) { - std::vector>>> parentAttributes; + std::vector parentAttributes; for (size_t index = 0ul; index < node->get_input_size(); index++) { const Input& input = node->input(index); auto inputNode = input.get_source_output().get_node()->shared_from_this(); @@ -110,23 +104,21 @@ private: const auto dequantization = NetworkHelper::getDequantization(node, index); if (!dequantization.empty() && (ov::is_type(dequantization.data.get_node())) && - ov::is_type(dequantization.data.get_node()->get_input_node_ptr(0))) { + ov::is_type(dequantization.data.get_node()->get_input_node_ptr(0))) { inputNode = dequantization.data.get_node()->get_input_node_shared_ptr(0); } if (NetworkHelper::isPrecisionPreserved(inputNode)) { auto& inputRtInfo = inputNode->get_rt_info(); - auto inputAttributeIt = inputRtInfo.find(ngraph::VariantWrapper>::type_info.name); + auto inputAttributeIt = inputRtInfo.find(PrecisionsAttribute::get_type_info_static()); if (inputAttributeIt != inputRtInfo.end()) { - const auto attribute = std::dynamic_pointer_cast>>(inputAttributeIt->second); - parentAttributes.push_back(attribute); + parentAttributes.push_back(inputAttributeIt->second); } } else if (ov::is_type(inputNode)) { const auto& outputPortRtInfo = inputNode->outputs()[0].get_rt_info(); - auto attributeIt = outputPortRtInfo.find(ngraph::VariantWrapper>::type_info.name); + auto attributeIt = outputPortRtInfo.find(PrecisionsAttribute::get_type_info_static()); if (attributeIt != outputPortRtInfo.end()) { - const auto attribute = std::dynamic_pointer_cast>>(attributeIt->second); - parentAttributes.push_back(attribute); + parentAttributes.push_back(attributeIt->second); } } } @@ -145,19 +137,18 @@ private: // merge parent inputs to one current output auto resultAttribute = parentRestrictions[0]; - std::vector>>> toMerge = parentRestrictions; + std::vector toMerge = parentRestrictions; toMerge.erase(toMerge.begin()); - resultAttribute->merge(toMerge); + resultAttribute.as().merge(toMerge); for (size_t index = 1ul; index < parentRestrictions.size(); index++) { - const auto oldAttribute = parentRestrictions[index]->get(); - NetworkHelper::reassign( - resultAttribute->get()->sharedValue, - parentRestrictions[index]->get()->sharedValue->attributes); + NetworkHelper::reassign( + resultAttribute.as().attribute->sharedValue, + parentRestrictions[index].as().attribute->sharedValue->attributes); } auto& rt = node->get_rt_info(); - rt[ngraph::VariantWrapper>::type_info.name] = resultAttribute; + rt[PrecisionsAttribute::get_type_info_static()] = resultAttribute; } } }; diff --git a/src/common/low_precision_transformations/include/low_precision/propagate_through_precision_preserved.hpp b/src/common/low_precision_transformations/include/low_precision/propagate_through_precision_preserved.hpp index bfa0e1fcceb..844e23bfb95 100644 --- a/src/common/low_precision_transformations/include/low_precision/propagate_through_precision_preserved.hpp +++ b/src/common/low_precision_transformations/include/low_precision/propagate_through_precision_preserved.hpp @@ -49,27 +49,27 @@ public: return false; } - auto resultAttribute = parentRestrictions[0]; + auto& resultAttribute = parentRestrictions[0].template as(); - std::vector>>> toMerge = parentRestrictions; - // TODO: LPT: handle pointer on itself in VariantWrapper::merge and remove erase, task #59498 + std::vector toMerge = parentRestrictions; + // TODO: LPT: handle pointer on itself in IntervalsAlignmentAttribute::merge and remove erase, task #59498 toMerge.erase(toMerge.begin()); - resultAttribute->merge(toMerge); + const_cast(resultAttribute).merge(toMerge); for (size_t index = 1ul; index < parentRestrictions.size(); index++) { - const auto attributes = parentRestrictions[index]->get()->sharedValue->attributes; - for (const auto attributeWeakPtr : attributes) { + auto& attributes = parentRestrictions[index].template as().attribute->sharedValue->attributes; + for (auto&& attributeWeakPtr : attributes) { auto attribute = attributeWeakPtr.lock(); if (attribute == nullptr) { continue; } - attribute->sharedValue = resultAttribute->get()->sharedValue; - resultAttribute->get()->sharedValue->attributes.push_back(attribute); + attribute->sharedValue = resultAttribute.attribute->sharedValue; + resultAttribute.attribute->sharedValue->attributes.push_back(attribute); } } auto &rt = node->get_rt_info(); - rt[ngraph::VariantWrapper>::type_info.name] = resultAttribute; + rt[AttributeType::get_type_info_static()] = resultAttribute; } return true; }; @@ -79,20 +79,20 @@ public: } private: - std::shared_ptr>> getSourceOutputAttribute(const Input& input) { + ov::Any getSourceOutputAttribute(const Input& input) { auto input2 = input; auto output = input2.get_source_output(); - std::shared_ptr>> attribute = getAttributeFromOutput>(output); - if (attribute == nullptr) { - attribute = getAttribute>(output.get_node_shared_ptr()); + auto attribute = getAttributeFromOutput(output); + if (attribute.empty()) { + attribute = getAttribute(output.get_node_shared_ptr()); } return attribute; } // TODO: possible duplicate: PropagateToInput::getSourceOutputAttribute - std::vector>>> getParentInputRestrictions( + std::vector getParentInputRestrictions( const std::shared_ptr node) { - std::vector>>> parentAttributes; + std::vector parentAttributes; auto getInput = [](const std::shared_ptr& node, const size_t index) -> Input { const auto dequantization = NetworkHelper::getDequantization(node, index); if (!dequantization.empty() && @@ -108,7 +108,7 @@ private: for (size_t index = 0ul; index < node->get_input_size(); index++) { const Input& input = getInput(node, index); const auto attribute = getSourceOutputAttribute(input); - if (attribute != nullptr) { + if (!attribute.empty()) { parentAttributes.push_back(attribute); } } diff --git a/src/common/low_precision_transformations/include/low_precision/propagate_to_input.hpp b/src/common/low_precision_transformations/include/low_precision/propagate_to_input.hpp index 64268e9270b..42f840c1573 100644 --- a/src/common/low_precision_transformations/include/low_precision/propagate_to_input.hpp +++ b/src/common/low_precision_transformations/include/low_precision/propagate_to_input.hpp @@ -45,18 +45,19 @@ public: continue; } - auto attribute = getAttribute>(input); - if (attribute != nullptr) { - if ((attribute->get()->sharedValue != nullptr) && (attribute->get()->sharedValue->precisions.empty())) { + auto attribute = getAttribute(input); + if (!attribute.empty()) { + if ((attribute.template as().attribute->sharedValue != nullptr) && + (attribute.template as().value().empty())) { return false; } - std::vector>>> attributes = { attribute }; - parentAttribute->merge(attributes); + std::vector attributes = { attribute }; + parentAttribute.template as().merge(attributes); } auto& rt = input.get_rt_info(); - rt[ngraph::VariantWrapper>::type_info.name] = parentAttribute; + rt[AttributeType::get_type_info_static()] = parentAttribute; } } return true; @@ -68,7 +69,7 @@ public: private: // TODO: possible duplicate: PropagateThroughPrecisionPreserved::getParentInputRestrictions - std::shared_ptr>> getSourceOutputAttribute(const Input& input) { + ov::Any getSourceOutputAttribute(const Input& input) { auto getInput = [](const Input& input) { const auto dequantization = NetworkHelper::getDequantization(input.get_node()->shared_from_this(), input.get_index()); if (!dequantization.empty() && @@ -83,20 +84,20 @@ private: auto input2 = getInput(input); auto output = input2.get_source_output(); - std::shared_ptr>> attribute = getAttributeFromOutput>(output); - if (attribute == nullptr) { - attribute = getAttribute>(output.get_node_shared_ptr()); + auto attribute = getAttributeFromOutput(output); + if (attribute.empty()) { + attribute = getAttribute(output.get_node_shared_ptr()); } return attribute; } - std::vector>>> getParentInputRestrictions( + std::vector getParentInputRestrictions( const std::shared_ptr node) { - std::vector>>> parentAttributes; + std::vector parentAttributes; for (size_t index = 0ul; index < node->get_input_size(); index++) { const Input& input = node->input(index); const auto attribute = getSourceOutputAttribute(input); - if (attribute != nullptr) { + if (!attribute.empty()) { parentAttributes.push_back(attribute); } } diff --git a/src/common/low_precision_transformations/include/low_precision/rt_info/avg_pool_precision_preserved_attribute.hpp b/src/common/low_precision_transformations/include/low_precision/rt_info/avg_pool_precision_preserved_attribute.hpp index 1e8794c5d5b..9da87cba5ce 100644 --- a/src/common/low_precision_transformations/include/low_precision/rt_info/avg_pool_precision_preserved_attribute.hpp +++ b/src/common/low_precision_transformations/include/low_precision/rt_info/avg_pool_precision_preserved_attribute.hpp @@ -14,28 +14,11 @@ namespace ngraph { class LP_TRANSFORMATIONS_API AvgPoolPrecisionPreservedAttribute : public PrecisionPreservedAttribute { -}; - -using AvgPoolPrecisionPreservedAttributePtr = std::shared_ptr; -} // namespace ngraph - -namespace ov { -extern template class LP_TRANSFORMATIONS_API VariantImpl; - -template<> -class LP_TRANSFORMATIONS_API VariantWrapper : public VariantImpl { public: - static constexpr VariantTypeInfo type_info{ "LowPrecision::AvgPoolPrecisionPreserved", 0 }; - - const VariantTypeInfo& get_type_info() const override { - return type_info; - } - - VariantWrapper(const value_type& value) : VariantImpl(value) {} - - ngraph::AvgPoolPrecisionPreservedAttributePtr get() { return this->m_value; } - - void merge(std::vector>>>& attributes); - std::string to_string() override; + OPENVINO_RTTI("LowPrecision::AvgPoolPrecisionPreserved", "", ov::RuntimeAttribute, 0); + using PrecisionPreservedAttribute::PrecisionPreservedAttribute; + void merge(std::vector& attributes); + std::string to_string() const override; }; -} // namespace ov + +} // namespace ngraph diff --git a/src/common/low_precision_transformations/include/low_precision/rt_info/intervals_alignment_attribute.hpp b/src/common/low_precision_transformations/include/low_precision/rt_info/intervals_alignment_attribute.hpp index 964989a04ec..af8664110d3 100644 --- a/src/common/low_precision_transformations/include/low_precision/rt_info/intervals_alignment_attribute.hpp +++ b/src/common/low_precision_transformations/include/low_precision/rt_info/intervals_alignment_attribute.hpp @@ -15,16 +15,14 @@ #include "low_precision/lpt_visibility.hpp" namespace ngraph { -class IntervalsAlignmentAttribute; - -class LP_TRANSFORMATIONS_API IntervalsAlignmentSharedValue : public SharedValue { +class LP_TRANSFORMATIONS_API IntervalsAlignmentSharedValue { public: class Interval { public: Interval() = default; Interval(const float low, const float high) : low(low), high(high) {} - float low; - float high; + float low = 0.f; + float high = 0.f; }; IntervalsAlignmentSharedValue() = default; @@ -38,7 +36,7 @@ public: Interval combinedInterval; Interval minInterval; - size_t minLevels; + size_t minLevels = 0; // preferable precisions which are preferred by affected quantization operations to avoid zero points std::set preferablePrecisions; @@ -47,8 +45,9 @@ public: #endif }; -class LP_TRANSFORMATIONS_API IntervalsAlignmentAttribute : public SharedValueAttribute { +class LP_TRANSFORMATIONS_API IntervalsAlignmentAttribute : public SharedAttribute { public: + OPENVINO_RTTI("LowPrecision::IntervalsAlignment", "", ov::RuntimeAttribute, 0); IntervalsAlignmentAttribute() = default; IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval combinedInterval, size_t levels); IntervalsAlignmentAttribute( @@ -57,36 +56,14 @@ public: const IntervalsAlignmentSharedValue::Interval minInterval, const size_t minLevels); + static ov::Any create( + const std::shared_ptr& node, + const AttributeParameters& params); + void merge(std::vector& attributes); + std::string to_string() const override; + // specify subgraph original levels size_t levels; }; -using IntervalsAlignmentAttributePtr = std::shared_ptr; } // namespace ngraph - -namespace ov { - -extern template class LP_TRANSFORMATIONS_API ngraph::VariantImpl; - -template<> -class LP_TRANSFORMATIONS_API VariantWrapper> : - public VariantImpl> { -public: - static constexpr VariantTypeInfo type_info{ "LowPrecision::IntervalsAlignment", 0 }; - - const VariantTypeInfo& get_type_info() const override { - return type_info; - } - - VariantWrapper(const value_type& value) : VariantImpl(value) {} - - std::shared_ptr get() const { return this->m_value; } - - static std::shared_ptr>> create( - const std::shared_ptr& node, - const AttributeParameters& params); - void merge(std::vector>>>& attributes); - std::string to_string() override; -}; - -} // namespace ov diff --git a/src/common/low_precision_transformations/include/low_precision/rt_info/per_tensor_quantization_attribute.hpp b/src/common/low_precision_transformations/include/low_precision/rt_info/per_tensor_quantization_attribute.hpp index 84f5216bda7..9a991dbf684 100644 --- a/src/common/low_precision_transformations/include/low_precision/rt_info/per_tensor_quantization_attribute.hpp +++ b/src/common/low_precision_transformations/include/low_precision/rt_info/per_tensor_quantization_attribute.hpp @@ -14,24 +14,9 @@ #include "attribute_parameters.hpp" namespace ngraph { -class LP_TRANSFORMATIONS_API PerTensorQuantizationAttribute { +class LP_TRANSFORMATIONS_API PerTensorQuantizationAttribute : public ov::RuntimeAttribute { +public: + OPENVINO_RTTI("LowPrecision::PerTensorQuantization", "", ov::RuntimeAttribute, 0); + ~PerTensorQuantizationAttribute(); }; } // namespace ngraph - -namespace ov { - -extern template class LP_TRANSFORMATIONS_API ngraph::VariantImpl; - -template<> -class LP_TRANSFORMATIONS_API VariantWrapper : public VariantImpl { -public: - static constexpr VariantTypeInfo type_info { "LowPrecision::PerTensorQuantization", 0 }; - - VariantWrapper(const value_type& value) : VariantImpl(value) {} - - const VariantTypeInfo& get_type_info() const override { - return type_info; - } -}; - -} // namespace ov diff --git a/src/common/low_precision_transformations/include/low_precision/rt_info/precision_preserved_attribute.hpp b/src/common/low_precision_transformations/include/low_precision/rt_info/precision_preserved_attribute.hpp index 08a4e213586..3a82a18d979 100644 --- a/src/common/low_precision_transformations/include/low_precision/rt_info/precision_preserved_attribute.hpp +++ b/src/common/low_precision_transformations/include/low_precision/rt_info/precision_preserved_attribute.hpp @@ -13,44 +13,14 @@ #include "low_precision/rt_info/shared_value_attribute.hpp" namespace ngraph { - -class LP_TRANSFORMATIONS_API PrecisionPreservedAttribute; - -class LP_TRANSFORMATIONS_API PrecisionPreservedSharedValue : public SharedValue { +class LP_TRANSFORMATIONS_API PrecisionPreservedAttribute : public SharedAttribute { public: - PrecisionPreservedSharedValue() = default; - PrecisionPreservedSharedValue(const bool value) : value(value) {} - bool value; -}; + OPENVINO_RTTI("LowPrecision::PrecisionPreserved", "", ov::RuntimeAttribute, 0); -class LP_TRANSFORMATIONS_API PrecisionPreservedAttribute : public SharedValueAttribute { -public: PrecisionPreservedAttribute() = default; PrecisionPreservedAttribute(const bool value); -}; -using PrecisionPreservedAttributePtr = std::shared_ptr; + std::string to_string() const override; +}; } // namespace ngraph - -namespace ov { - -extern template class LP_TRANSFORMATIONS_API ngraph::VariantImpl; - -template<> -class LP_TRANSFORMATIONS_API VariantWrapper : public VariantImpl { -public: - static constexpr VariantTypeInfo type_info{ "LowPrecision::PrecisionPreserved", 0 }; - - const VariantTypeInfo& get_type_info() const override { - return type_info; - } - - VariantWrapper(const value_type& value) : VariantImpl(value) {} - - ngraph::PrecisionPreservedAttributePtr get() { return this->m_value; } - - std::string to_string() override; -}; - -} // namespace ov diff --git a/src/common/low_precision_transformations/include/low_precision/rt_info/precisions_attribute.hpp b/src/common/low_precision_transformations/include/low_precision/rt_info/precisions_attribute.hpp index b7057464c4f..14bb7742b96 100644 --- a/src/common/low_precision_transformations/include/low_precision/rt_info/precisions_attribute.hpp +++ b/src/common/low_precision_transformations/include/low_precision/rt_info/precisions_attribute.hpp @@ -20,49 +20,18 @@ namespace ngraph { -class PrecisionsAttribute; - -class LP_TRANSFORMATIONS_API PrecisionsSharedValue : public SharedValue { -public: - std::vector precisions; -}; - -using PrecisionsAttributePtr = std::shared_ptr; - -class LP_TRANSFORMATIONS_API PrecisionsAttribute : public SharedValueAttribute { +class LP_TRANSFORMATIONS_API PrecisionsAttribute : public SharedAttribute> { public: + OPENVINO_RTTI("LowPrecision::Precisions", "", ov::RuntimeAttribute, 0); static std::vector defaultPrecisions; PrecisionsAttribute(const std::vector& precisions = defaultPrecisions); -}; -} // namespace ngraph -namespace ov { - -extern template class LP_TRANSFORMATIONS_API ngraph::VariantImpl>; - -template<> -class LP_TRANSFORMATIONS_API VariantWrapper> : public VariantImpl> { -public: - static constexpr VariantTypeInfo type_info{ "LowPrecision::Precisions", 0 }; - - const VariantTypeInfo& get_type_info() const override { - return type_info; - } - - VariantWrapper(const value_type& value) : VariantImpl(value) {} - - ov::Any init(const std::shared_ptr& node) override; - - std::shared_ptr get() { return this->m_value; } - - // create attribute instance for node - static std::shared_ptr>> create( + static ov::Any create( const std::shared_ptr& node, const AttributeParameters& params); // merge attribute instances which can be got from different sources: node, input port or output port - void merge(std::vector>>>& attributes); + void merge(std::vector& attributes); // vizualize shared attributes details in VizualizeTree pass - std::string to_string() override; + std::string to_string() const override; }; - -} // namespace ov +} // namespace ngraph diff --git a/src/common/low_precision_transformations/include/low_precision/rt_info/quantization_alignment_attribute.hpp b/src/common/low_precision_transformations/include/low_precision/rt_info/quantization_alignment_attribute.hpp index 57f43d06cfe..d8a09ccdc54 100644 --- a/src/common/low_precision_transformations/include/low_precision/rt_info/quantization_alignment_attribute.hpp +++ b/src/common/low_precision_transformations/include/low_precision/rt_info/quantization_alignment_attribute.hpp @@ -18,46 +18,16 @@ #include "attribute_parameters.hpp" namespace ngraph { -class QuantizationAlignmentAttribute; - -class LP_TRANSFORMATIONS_API QuantizationAlignmentSharedValue : public SharedValue { -public: - QuantizationAlignmentSharedValue(const bool value = false) : value(value) {} - bool value; -}; - -class LP_TRANSFORMATIONS_API QuantizationAlignmentAttribute : public SharedValueAttribute{ +class LP_TRANSFORMATIONS_API QuantizationAlignmentAttribute : public SharedAttribute { public: + OPENVINO_RTTI("LowPrecision::QuantizationAlignment", "", ov::RuntimeAttribute, 0); QuantizationAlignmentAttribute(const bool value = false); -}; -using QuantizationAlignmentAttributePtr = std::shared_ptr; -} // namespace ngraph - -namespace ov { - -extern template class LP_TRANSFORMATIONS_API ngraph::VariantImpl; - -template<> -class LP_TRANSFORMATIONS_API VariantWrapper> : - public VariantImpl> { -public: - static constexpr VariantTypeInfo type_info{ "LowPrecision::QuantizationAlignment", 0 }; - - const VariantTypeInfo& get_type_info() const override { - return type_info; - } - - VariantWrapper(const value_type& value) : VariantImpl(value) {} - - ov::Any init(const std::shared_ptr& node) override; - - std::shared_ptr get() { return this->m_value; } - - static std::shared_ptr>> create( + static ov::Any create( const std::shared_ptr& node, const AttributeParameters& params); - void merge(std::vector>>>& attributes); - std::string to_string() override; + void merge(std::vector& attributes); + std::string to_string() const override; }; -} // namespace ov + +} // namespace ngraph diff --git a/src/common/low_precision_transformations/include/low_precision/rt_info/shared_value_attribute.hpp b/src/common/low_precision_transformations/include/low_precision/rt_info/shared_value_attribute.hpp index 706ff46d590..5b922c07b5c 100644 --- a/src/common/low_precision_transformations/include/low_precision/rt_info/shared_value_attribute.hpp +++ b/src/common/low_precision_transformations/include/low_precision/rt_info/shared_value_attribute.hpp @@ -14,46 +14,70 @@ #include #include -template -class LP_TRANSFORMATIONS_API SharedValue; - -template -class LP_TRANSFORMATIONS_API SharedValueAttribute { +template +class LP_TRANSFORMATIONS_API SharedAttribute : public ov::RuntimeAttribute { public: - SharedValueAttribute() : sharedValue(std::make_shared()) {} - virtual ~SharedValueAttribute() = default; - std::shared_ptr sharedValue; - std::string get_string() { - std::stringstream ss; + virtual ~SharedAttribute() = default; + class LP_TRANSFORMATIONS_API SharedValueAttribute : public std::enable_shared_from_this { + public: + struct LP_TRANSFORMATIONS_API SharedValue : public std::enable_shared_from_this { + SharedValue() = default; + SharedValue(const T& value) : value{value} {} + T value = {}; + std::vector> attributes; + }; + SharedValueAttribute() : sharedValue(std::make_shared()) {} - const size_t rawPointer = (size_t)this; - ss << rawPointer << ": "; + SharedValueAttribute(const T& value) : sharedValue{std::make_shared(value)} {} - const size_t sharedValueRawPointer = (size_t)sharedValue.get(); - ss << "sharedValue: " << sharedValueRawPointer; + std::shared_ptr sharedValue; - bool firstAttribute = true; - ss << ", attributes: {"; - for (auto& attributeWeakPtr : sharedValue->attributes) { - auto attribute = attributeWeakPtr.lock(); - if (attribute == nullptr) { - continue; + std::string get_string() { + std::stringstream ss; + + const size_t rawPointer = (size_t)this; + ss << rawPointer << ": "; + + const size_t sharedValueRawPointer = (size_t)sharedValue.get(); + ss << "sharedValue: " << sharedValueRawPointer; + + bool firstAttribute = true; + ss << ", attributes: {"; + for (auto& attributeWeakPtr : sharedValue->attributes) { + auto attribute = attributeWeakPtr.lock(); + if (attribute == nullptr) { + continue; + } + + if (!firstAttribute) { + ss << ", "; + } + ss << (size_t)attribute.get(); + firstAttribute = false; } - - if (!firstAttribute) { - ss << ", "; - } - ss << (size_t)attribute.get(); - firstAttribute = false; + ss << "}, "; + return ss.str(); } - ss << "}, "; - return ss.str(); + }; + + SharedAttribute() : attribute{std::make_shared()} { + attribute->sharedValue->attributes.emplace_back(attribute); + } + SharedAttribute(const T& value) : attribute{std::make_shared(value)} { + attribute->sharedValue->attributes.emplace_back(attribute); + } + + std::shared_ptr attribute; + + const T& value() const { + OPENVINO_ASSERT(attribute != nullptr, "Empty attribute"); + OPENVINO_ASSERT(attribute->sharedValue != nullptr, "Empty shared value"); + return attribute->sharedValue->value; + } + + T& value() { + OPENVINO_ASSERT(attribute != nullptr, "Empty attribute"); + OPENVINO_ASSERT(attribute->sharedValue != nullptr, "Empty shared value"); + return attribute->sharedValue->value; } }; - -template -class LP_TRANSFORMATIONS_API SharedValue { -public: - virtual ~SharedValue() = default; - std::vector> attributes; -}; diff --git a/src/common/low_precision_transformations/include/low_precision/update_shared_precision_preserved.hpp b/src/common/low_precision_transformations/include/low_precision/update_shared_precision_preserved.hpp index 0a17f7328ac..42745f8f793 100644 --- a/src/common/low_precision_transformations/include/low_precision/update_shared_precision_preserved.hpp +++ b/src/common/low_precision_transformations/include/low_precision/update_shared_precision_preserved.hpp @@ -51,11 +51,9 @@ public: // TODO: check if node can be quantized, if not, then doesn't update for (auto input : node->inputs()) { - auto precisionsAttributeWrapper = getAttribute(input); - if (precisionsAttributeWrapper != nullptr) { - const auto precisionsAttribute = precisionsAttributeWrapper->get(); - assert(precisionsAttribute != nullptr); - if (precisionsAttribute->sharedValue->precisions.empty()) { + auto precisionsAttributeWrapper = getAttribute(input); + if (!precisionsAttributeWrapper.empty()) { + if (precisionsAttributeWrapper.as().value().empty()) { return false; } } @@ -63,16 +61,15 @@ public: for (auto input : node->inputs()) { if (needToCheckExpectedAttributeType) { - if (getAttribute(input) == nullptr) { + if (getAttribute(input).empty()) { return false; } } auto parentAttribute = getSourceAttribute(input); - if (parentAttribute == nullptr) { + if (parentAttribute.empty()) { continue; } - - parentAttribute->get()->sharedValue->value = true; + parentAttribute.template as().value() = true; } } @@ -95,11 +92,11 @@ private: return input; } - std::shared_ptr> getSourceAttribute(const Input& input) { + ov::Any getSourceAttribute(const Input& input) { const auto dequantizationInput = getDequantizationInput(input); const auto output = dequantizationInput.get_source_output(); auto attribute = ngraph::pass::low_precision::getAttribute(output.get_node()->shared_from_this()); - if (attribute == nullptr) { + if (attribute.empty()) { attribute = ngraph::pass::low_precision::getAttribute(output.get_node_shared_ptr()); } return attribute; diff --git a/src/common/low_precision_transformations/src/align_quantization_intervals.cpp b/src/common/low_precision_transformations/src/align_quantization_intervals.cpp index 728161d0207..882bc757b61 100644 --- a/src/common/low_precision_transformations/src/align_quantization_intervals.cpp +++ b/src/common/low_precision_transformations/src/align_quantization_intervals.cpp @@ -18,7 +18,7 @@ bool ngraph::pass::low_precision::AlignQuantizationIntervals::run_on_function(st ngraph::pass::Manager manager; manager.set_per_pass_validation(false); std::shared_ptr intervalsAlignment = manager.register_pass(); - intervalsAlignment->add_matcher>(); + intervalsAlignment->add_matcher>(); intervalsAlignment->add_matcher>(); manager.run_passes(f); return false; diff --git a/src/common/low_precision_transformations/src/align_quantization_parameters.cpp b/src/common/low_precision_transformations/src/align_quantization_parameters.cpp index 72d4ed1184c..c33bbc22994 100644 --- a/src/common/low_precision_transformations/src/align_quantization_parameters.cpp +++ b/src/common/low_precision_transformations/src/align_quantization_parameters.cpp @@ -19,9 +19,9 @@ bool ngraph::pass::low_precision::AlignQuantizationParameters::run_on_function(s ngraph::pass::Manager manager; manager.set_per_pass_validation(false); std::shared_ptr propagation = manager.register_pass(); - propagation->add_matcher>(); + propagation->add_matcher>(); propagation->add_matcher>(); - propagation->add_matcher>(); + propagation->add_matcher>(); manager.run_passes(f); return false; } diff --git a/src/common/low_precision_transformations/src/fake_quantize_decomposition.cpp b/src/common/low_precision_transformations/src/fake_quantize_decomposition.cpp index d13d3b54f2e..dafcd031f64 100644 --- a/src/common/low_precision_transformations/src/fake_quantize_decomposition.cpp +++ b/src/common/low_precision_transformations/src/fake_quantize_decomposition.cpp @@ -45,8 +45,8 @@ namespace { // 2. Precisions on port DataPrecision getDataPrecisionByOutputPortAndFakeQuantize(std::shared_ptr layer) { const QuantizationDetails quantizationDetails = QuantizationDetails::getDetails(layer); - auto precisionsAttribute = getAttributeFromOutput>(layer->output(0)); - if (precisionsAttribute == nullptr) { + auto precisionsAttribute = getAttributeFromOutput(layer->output(0)); + if (precisionsAttribute.empty()) { // TODO: explore this case in more details: // 1. we should not be here assert(true); @@ -60,7 +60,7 @@ DataPrecision getDataPrecisionByOutputPortAndFakeQuantize(std::shared_ptrget()->sharedValue->precisions; + const auto& precisions = precisionsAttribute.as().value(); ngraph::element::Type precision; bool hasZeroPoint; @@ -77,7 +77,7 @@ DataPrecision getDataPrecisionByOutputPortAndFakeQuantize(std::shared_ptrget()->sharedValue->precisions = { precision }; + precisionsAttribute.as().value() = { precision }; } else { // use only available precision precision = *precisions.begin(); @@ -100,8 +100,8 @@ DataPrecision getDataPrecisionByOutputPort(std::shared_ptr const std::vector outputLowValues = ov::as_type_ptr(layer->get_input_node_shared_ptr(3))->cast_vector(); const std::vector outputHighValues = ov::as_type_ptr(layer->get_input_node_shared_ptr(4))->cast_vector(); - auto precisionsAttribute = getAttributeFromOutput>(layer->output(0)); - if (precisionsAttribute == nullptr) { + auto precisionsAttribute = getAttributeFromOutput(layer->output(0)); + if (precisionsAttribute.empty()) { // TODO: explore this case in more details: // 1. we should not be here assert(true); @@ -119,7 +119,7 @@ DataPrecision getDataPrecisionByOutputPort(std::shared_ptr precisionDetailsAtOutputIntervals.hasZeroPoint); } - const auto& precisions = precisionsAttribute->get()->sharedValue->precisions; + const auto& precisions = precisionsAttribute.as().value(); std::vector precisionsForLevels{}; switch (levels) { case 65536: @@ -153,7 +153,7 @@ DataPrecision getDataPrecisionByOutputPort(std::shared_ptr } // update shared attribute to affect all operations in subgraph - precisionsAttribute->get()->sharedValue->precisions = { precision }; + precisionsAttribute.as().value() = { precision }; } else { // use only available precision precision = *resultPrecisions.begin(); @@ -175,14 +175,14 @@ DataPrecision getDataPrecisionByOutputPort(std::shared_ptr std::tuple, std::shared_ptr> decomposeFakeQuantize( MatcherPass* matcherPass, std::shared_ptr& layer, - const std::shared_ptr& intervalsAlignment, + const ov::Any& intervalsAlignment, const DataPrecision& dataPrecision, const bool updatePrecisions, const element::Type deqPrecision) { std::shared_ptr dequantize; std::shared_ptr newFQ; - if (intervalsAlignment != nullptr) { + if (!intervalsAlignment.empty()) { OV_ITT_SCOPE(FIRST_INFERENCE, itt::domains::LPT_LT, "decomposeFakeQuantize1"); const std::vector outputLowValues = ov::as_type_ptr(layer->get_input_node_shared_ptr(3))->cast_vector(); const std::vector outputHighValues = ov::as_type_ptr(layer->get_input_node_shared_ptr(4))->cast_vector(); @@ -194,8 +194,8 @@ std::tuple, std::shared_ptr> decomposeFakeQuantize( const size_t levels = NetworkHelper::calculateLevels( dataPrecision.min, dataPrecision.max, - intervalsAlignment->sharedValue->combinedInterval.low, - intervalsAlignment->sharedValue->combinedInterval.high, + intervalsAlignment.as().value().combinedInterval.low, + intervalsAlignment.as().value().combinedInterval.high, outputLowValues[0], outputHighValues[0], dequantizationMul, @@ -286,8 +286,8 @@ bool FakeQuantizeDecompositionTransformation::transform(TransformationContext& c return false; } - auto attribute = getAttributeFromOutput>(layer->output(0)); - if ((attribute == nullptr) || (attribute->get()->sharedValue->precisions.empty())) { + auto attribute = getAttributeFromOutput(layer->output(0)); + if (attribute.empty() || (attribute.as().value().empty())) { return false; } @@ -320,42 +320,33 @@ bool FakeQuantizeDecompositionTransformation::transform(TransformationContext& c DataPrecision dataPrecision = fq_decomposition::getDataPrecisionByOutputPort(layer); - std::shared_ptr precisionsAttribute; + PrecisionsAttribute precisionsAttribute; { // TODO: LPT: return attribute (not wrapper) - auto attributeWrapper = getAttributeFromOutput>(layer->output(0)); - if (attributeWrapper == nullptr) { - THROW_IE_LPT_EXCEPTION(*layer) << "PrecisionAttribute is absent"; - } - precisionsAttribute = attributeWrapper->get(); - if (precisionsAttribute == nullptr) { + auto attributeWrapper = getAttributeFromOutput(layer->output(0)); + if (attributeWrapper.empty()) { THROW_IE_LPT_EXCEPTION(*layer) << "PrecisionAttribute is absent"; } + precisionsAttribute = attributeWrapper.as(); } - std::shared_ptr quantizationAlignment; + ov::Any quantizationAlignment; for (const auto& input : layer->output(0).get_target_inputs()) { - const auto alignmentValueWrapper = low_precision::getAttribute>(input.get_node()->shared_from_this()); - if (alignmentValueWrapper != nullptr) { - quantizationAlignment = alignmentValueWrapper->get(); - if (quantizationAlignment->sharedValue->value) { + quantizationAlignment = low_precision::getAttribute(input.get_node()->shared_from_this()); + if (!quantizationAlignment.empty()) { + if (quantizationAlignment.as().value()) { break; } } } - std::shared_ptr intervalsAlignment; - { - if ((quantizationAlignment != nullptr) && quantizationAlignment->sharedValue->value) { - auto intervalsAlignmentWrapper = low_precision::getAttribute>(layer); - if (intervalsAlignmentWrapper != nullptr) { - intervalsAlignment = intervalsAlignmentWrapper->get(); - } - } + ov::Any intervalsAlignment; + if (!quantizationAlignment.empty() && quantizationAlignment.as().value()) { + intervalsAlignment = low_precision::getAttribute(layer); } // FakeQuantize operations are combined in supported cascade (per tensor quantization) - if ((intervalsAlignment != nullptr) && (intervalsAlignment->sharedValue->minLevels <= 2ul)) { + if (!intervalsAlignment.empty() && (intervalsAlignment.as().value().minLevels <= 2ul)) { return false; } @@ -366,20 +357,20 @@ bool FakeQuantizeDecompositionTransformation::transform(TransformationContext& c const auto levels = layer->get_levels(); const std::vector outputLowValues = ov::as_type_ptr(layer->get_input_node_shared_ptr(3))->cast_vector(); const std::vector outputHighValues = ov::as_type_ptr(layer->get_input_node_shared_ptr(4))->cast_vector(); - if (intervalsAlignment == nullptr) { + if (intervalsAlignment.empty()) { // define precision by FakeQuantize intervals LayerTransformation::PrecisionDetails precisionDetailsAtOutputIntervals = LayerTransformation::getPrecisionDetails( levels, outputLowValues, outputHighValues); const auto foundIt = std::find( - precisionsAttribute->sharedValue->precisions.begin(), - precisionsAttribute->sharedValue->precisions.end(), + precisionsAttribute.value().begin(), + precisionsAttribute.value().end(), precisionDetailsAtOutputIntervals.precision); bool hasZeroPoint; - if (foundIt == precisionsAttribute->sharedValue->precisions.end()) { - precision = *precisionsAttribute->sharedValue->precisions.begin(); + if (foundIt == precisionsAttribute.value().end()) { + precision = *precisionsAttribute.value().begin(); hasZeroPoint = true; } else { precision = precisionDetailsAtOutputIntervals.precision; @@ -393,12 +384,12 @@ bool FakeQuantizeDecompositionTransformation::transform(TransformationContext& c hasZeroPoint); } else { // define precision by attribute - if (intervalsAlignment->sharedValue->preferablePrecisions.empty()) { + if (intervalsAlignment.as().value().preferablePrecisions.empty()) { // TODO: LPT: add user defined preferredPrecision - precision = *precisionsAttribute->sharedValue->precisions.begin(); + precision = *precisionsAttribute.value().begin(); } else { // TODO: LPT: add user defined preferredPrecision - precision = *intervalsAlignment->sharedValue->preferablePrecisions.begin(); + precision = *intervalsAlignment.as().value().preferablePrecisions.begin(); } dataPrecision = DataPrecision( @@ -425,8 +416,8 @@ bool FakeQuantizeDecompositionTransformation::transform(TransformationContext& c updateOutput(context, dequantize, newFakeQuantize); - if (precisionsAttribute->sharedValue->precisions.size() != 1ul) { - precisionsAttribute->sharedValue->precisions = { dataPrecision.precision }; + if (precisionsAttribute.value().size() != 1ul) { + precisionsAttribute.value() = { dataPrecision.precision }; } return true; diff --git a/src/common/low_precision_transformations/src/fuse_multiply_to_fake_quantize.cpp b/src/common/low_precision_transformations/src/fuse_multiply_to_fake_quantize.cpp index 9d48b5a23f3..b48e97f0a90 100644 --- a/src/common/low_precision_transformations/src/fuse_multiply_to_fake_quantize.cpp +++ b/src/common/low_precision_transformations/src/fuse_multiply_to_fake_quantize.cpp @@ -80,9 +80,9 @@ bool FuseMultiplyToFakeQuantizeTransformation::transform(TransformationContext& replace_node(multiply, newFakeQuantize); NetworkHelper::copyInfo(fakeQuantize, newFakeQuantize); - const auto intervalAlignment = getAttribute(fakeQuantize); - if ((intervalAlignment != nullptr) && (intervalAlignment->get()->levels != 0ul)) { - newFakeQuantize->set_levels(intervalAlignment->get()->levels); + const auto intervalAlignment = getAttribute(fakeQuantize); + if (!intervalAlignment.empty() && (intervalAlignment.as().levels != 0ul)) { + newFakeQuantize->set_levels(intervalAlignment.as().levels); } updateOutput(context, newFakeQuantize, multiply); diff --git a/src/common/low_precision_transformations/src/markup_avg_pool_precision_preserved.cpp b/src/common/low_precision_transformations/src/markup_avg_pool_precision_preserved.cpp index 2dc256920c7..fff8b62e533 100644 --- a/src/common/low_precision_transformations/src/markup_avg_pool_precision_preserved.cpp +++ b/src/common/low_precision_transformations/src/markup_avg_pool_precision_preserved.cpp @@ -20,7 +20,7 @@ bool ngraph::pass::low_precision::MarkupAvgPoolPrecisionPreserved::run_on_functi std::shared_ptr markupAvgPoolPrecision = manager.register_pass(); markupAvgPoolPrecision->add_matcher>(); markupAvgPoolPrecision->add_matcher>(); - markupAvgPoolPrecision->add_matcher>(); + markupAvgPoolPrecision->add_matcher>(); manager.run_passes(f); return false; } diff --git a/src/common/low_precision_transformations/src/markup_can_be_quantized.cpp b/src/common/low_precision_transformations/src/markup_can_be_quantized.cpp index 10553e07fd7..64bf123fd95 100644 --- a/src/common/low_precision_transformations/src/markup_can_be_quantized.cpp +++ b/src/common/low_precision_transformations/src/markup_can_be_quantized.cpp @@ -22,13 +22,9 @@ bool ngraph::pass::low_precision::MarkupCanBeQuantized::run_on_function(std::sha auto setEmptyPrecisions = [](const std::shared_ptr& node) { for (auto& input : node->inputs()) { auto& rt = input.get_rt_info(); - - auto attribute = ngraph::pass::low_precision::make_shared_attribute(std::vector()); - auto attributeWrapper = std::make_shared>>(attribute); - rt.emplace( - ngraph::VariantWrapper>::type_info.name, - attributeWrapper); + PrecisionsAttribute::get_type_info_static(), + PrecisionsAttribute(std::vector())); } }; diff --git a/src/common/low_precision_transformations/src/markup_per_tensor_quantization.cpp b/src/common/low_precision_transformations/src/markup_per_tensor_quantization.cpp index 4cd37c94658..d2dfa732f57 100644 --- a/src/common/low_precision_transformations/src/markup_per_tensor_quantization.cpp +++ b/src/common/low_precision_transformations/src/markup_per_tensor_quantization.cpp @@ -33,8 +33,8 @@ bool ngraph::pass::low_precision::MarkupPerTensorQuantization::run_on_function(s auto createAttribute = [](Input& input){ auto &rt = input.get_rt_info(); rt.emplace( - ngraph::VariantWrapper::type_info.name, - std::make_shared<::ngraph::VariantWrapper>(PerTensorQuantizationAttribute())); + PerTensorQuantizationAttribute::get_type_info_static(), + PerTensorQuantizationAttribute()); }; if (restrictedPorts.empty()) { diff --git a/src/common/low_precision_transformations/src/markup_precisions.cpp b/src/common/low_precision_transformations/src/markup_precisions.cpp index 620a229e662..eab0401604d 100644 --- a/src/common/low_precision_transformations/src/markup_precisions.cpp +++ b/src/common/low_precision_transformations/src/markup_precisions.cpp @@ -42,30 +42,21 @@ void setRestriction( // if available precisions for any port is empty then mark all input ports for (auto& input : node->inputs()) { auto& rt = input.get_rt_info(); - - auto attribute = ngraph::pass::low_precision::make_shared_attribute(std::vector()); - auto attributeWrapper = std::make_shared>>(attribute); - rt.emplace( - ngraph::VariantWrapper>::type_info.name, - attributeWrapper); + PrecisionsAttribute::get_type_info_static(), + PrecisionsAttribute(std::vector())); } } else { for (const std::pair>& item : precisionsByPort) { Input input = node->input(item.first); + auto& rt = input.get_rt_info(); - auto precisionsAttribute = ngraph::pass::low_precision::getAttribute>(input); - if ((precisionsAttribute != nullptr) && - (precisionsAttribute->get()->sharedValue != nullptr) && - (precisionsAttribute->get()->sharedValue->precisions.empty())) { + auto precisionsAttribute = ngraph::pass::low_precision::getAttribute(input); + if ((!precisionsAttribute.empty()) && + (precisionsAttribute.as().value().empty())) { return; } - - auto attribute = ngraph::pass::low_precision::make_shared_attribute(item.second); - auto attributeWrapper = std::make_shared>>(attribute); - - auto& rt = input.get_rt_info(); - rt[ngraph::VariantWrapper>::type_info.name] = attributeWrapper; + rt[PrecisionsAttribute::get_type_info_static()] = PrecisionsAttribute(item.second); } } } @@ -93,9 +84,8 @@ bool ngraph::pass::low_precision::MarkupPrecisions::run_on_function(std::shared_ if (precisionPreserved) { auto& rt = node->get_rt_info(); rt.emplace( - ngraph::VariantWrapper::type_info.name, - std::make_shared<::ngraph::VariantWrapper>( - make_shared_attribute(precisionPreserved))); + PrecisionPreservedAttribute::get_type_info_static(), + PrecisionPreservedAttribute(precisionPreserved)); } const auto& typeInfo = node->get_type_info(); diff --git a/src/common/low_precision_transformations/src/mat_mul.cpp b/src/common/low_precision_transformations/src/mat_mul.cpp index 1ced4c45188..1533fdee2ea 100644 --- a/src/common/low_precision_transformations/src/mat_mul.cpp +++ b/src/common/low_precision_transformations/src/mat_mul.cpp @@ -54,10 +54,10 @@ bool MatMulTransformation::transform(TransformationContext &context, ngraph::pat if (fakeQuantize != nullptr) { const QuantizationDetails quantizationDetails = QuantizationDetails::getDetails(fakeQuantize); - const auto precisionsAttribute = getAttributeFromOutput(fakeQuantize); - const auto precisions = precisionsAttribute == nullptr ? + const auto precisionsAttribute = getAttributeFromOutput(fakeQuantize); + const auto precisions = precisionsAttribute.empty() ? PrecisionsAttribute::defaultPrecisions : - precisionsAttribute->get()->sharedValue->precisions; + precisionsAttribute.as().value(); const DataPrecision dataPrecision = getDataPrecision(fakeQuantize, quantizationDetails, precisions); auto tuple = NetworkHelper::decomposeFakeQuantize( @@ -259,10 +259,10 @@ bool MatMulTransformation::canBeTransformed(const TransformationContext& context const QuantizationDetails quantizationDetails = QuantizationDetails::getDetails(fakeQuantize); - const auto precisionsAttribute = getAttribute(matMul->input(1)); - const auto precisions = precisionsAttribute == nullptr ? + const auto precisionsAttribute = getAttribute(matMul->input(1)); + const auto precisions = precisionsAttribute.empty() ? PrecisionsAttribute::defaultPrecisions : - precisionsAttribute->get()->sharedValue->precisions; + precisionsAttribute.as().value(); const DataPrecision dataPrecision = getDataPrecision(fakeQuantize, quantizationDetails, precisions); if (dataPrecision.hasZeroPoint) { diff --git a/src/common/low_precision_transformations/src/multiply_to_group_convolution.cpp b/src/common/low_precision_transformations/src/multiply_to_group_convolution.cpp index 2caf1fa9940..10695f13eb7 100644 --- a/src/common/low_precision_transformations/src/multiply_to_group_convolution.cpp +++ b/src/common/low_precision_transformations/src/multiply_to_group_convolution.cpp @@ -66,10 +66,10 @@ bool MultiplyToGroupConvolutionTransformation::transform(TransformationContext& // if restrictions are absent precisions attribute is used if (weightsPrecision == element::undefined) { - const auto precisionsAttribute = getAttribute(multiply->input(inputIndex == 0ul ? 1ul : 0ul)); + const auto precisionsAttribute = getAttribute(multiply->input(inputIndex == 0ul ? 1ul : 0ul)); const auto precisions = precisionsAttribute == nullptr ? PrecisionsAttribute::defaultPrecisions : - precisionsAttribute->get()->sharedValue->precisions; + precisionsAttribute.as().value(); weightsPrecision = precisions[0]; } } else { diff --git a/src/common/low_precision_transformations/src/network_helper.cpp b/src/common/low_precision_transformations/src/network_helper.cpp index 50d6da8fc1b..f72a2511384 100644 --- a/src/common/low_precision_transformations/src/network_helper.cpp +++ b/src/common/low_precision_transformations/src/network_helper.cpp @@ -668,13 +668,12 @@ std::shared_ptr NetworkHelper::fuseConvert(const std::shar bool NetworkHelper::isPrecisionPreserved(const std::shared_ptr& node) { auto& rt = node->get_rt_info(); - auto it = rt.find(ngraph::VariantWrapper::type_info.name); + auto it = rt.find(PrecisionPreservedAttribute::get_type_info_static()); if (it == rt.end()) { return false; } - auto attribute = std::dynamic_pointer_cast>(it->second); - assert(attribute != nullptr); - return attribute->get()->sharedValue->value; + auto attribute = it->second; + return attribute.as().value(); } size_t NetworkHelper::calculateLevels( @@ -1854,15 +1853,11 @@ bool NetworkHelper::isDQByDynamicDimension(const std::shared_ptr& layer, s bool isDisabled(const std::shared_ptr& node) { for (const auto& input : node->inputs()) { - auto precisionAttribute = getAttribute>(input); - if (precisionAttribute == nullptr) { + auto precisionAttribute = getAttribute(input); + if (precisionAttribute.empty()) { continue; } - - assert(precisionAttribute->get() != nullptr); - assert(precisionAttribute->get()->sharedValue != nullptr); - - const auto& precisionRestrictions = precisionAttribute->get()->sharedValue->precisions; + const auto& precisionRestrictions = precisionAttribute.as().value(); if (precisionRestrictions.empty()) { return true; } diff --git a/src/common/low_precision_transformations/src/propagate_precisions.cpp b/src/common/low_precision_transformations/src/propagate_precisions.cpp index 4b15dd7e7b9..1e671f4e091 100644 --- a/src/common/low_precision_transformations/src/propagate_precisions.cpp +++ b/src/common/low_precision_transformations/src/propagate_precisions.cpp @@ -21,7 +21,7 @@ bool ngraph::pass::low_precision::PropagatePrecisions::run_on_function(std::shar ngraph::pass::Manager manager; manager.set_per_pass_validation(false); std::shared_ptr precisionsPropagation = manager.register_pass(); - precisionsPropagation->add_matcher>(AttributeSource::OutputPort); + precisionsPropagation->add_matcher>(AttributeSource::OutputPort); precisionsPropagation->add_matcher>(); precisionsPropagation->add_matcher>(); manager.run_passes(f); diff --git a/src/common/low_precision_transformations/src/rt_info/avg_pool_precision_preserved_attribute.cpp b/src/common/low_precision_transformations/src/rt_info/avg_pool_precision_preserved_attribute.cpp index aba2aa578e5..dea564d37ca 100644 --- a/src/common/low_precision_transformations/src/rt_info/avg_pool_precision_preserved_attribute.cpp +++ b/src/common/low_precision_transformations/src/rt_info/avg_pool_precision_preserved_attribute.cpp @@ -11,18 +11,13 @@ using namespace ngraph; using namespace ov; -template class ngraph::VariantImpl; -constexpr VariantTypeInfo VariantWrapper::type_info; - -void VariantWrapper::merge( - std::vector>>>& attributes) { +void AvgPoolPrecisionPreservedAttribute::merge(std::vector& attributes) { } -std::string VariantWrapper::to_string() { - auto value = this->m_value; +std::string AvgPoolPrecisionPreservedAttribute::to_string() const { std::stringstream ss; - ss << m_value->get_string(); - ss << "value: " << (value->sharedValue->value ? "true" : "false"); + ss << attribute->get_string(); + ss << "value: " << (value() ? "true" : "false"); return ss.str(); } diff --git a/src/common/low_precision_transformations/src/rt_info/intervals_alignment_attribute.cpp b/src/common/low_precision_transformations/src/rt_info/intervals_alignment_attribute.cpp index 7beb4722459..269c1e82645 100644 --- a/src/common/low_precision_transformations/src/rt_info/intervals_alignment_attribute.cpp +++ b/src/common/low_precision_transformations/src/rt_info/intervals_alignment_attribute.cpp @@ -17,23 +17,21 @@ using namespace ngraph::pass::low_precision; IntervalsAlignmentAttribute::IntervalsAlignmentAttribute( const IntervalsAlignmentSharedValue::Interval combinedInterval, - size_t levels) : levels(levels) { - sharedValue = std::make_shared(combinedInterval, combinedInterval, levels); + size_t levels) : + SharedAttribute(IntervalsAlignmentSharedValue{combinedInterval, combinedInterval, levels}), + levels(levels) { } IntervalsAlignmentAttribute::IntervalsAlignmentAttribute( const IntervalsAlignmentSharedValue::Interval combinedInterval, const size_t levels, const IntervalsAlignmentSharedValue::Interval minInterval, - const size_t minLevels) : levels(levels) { - sharedValue = std::make_shared(combinedInterval, minInterval, minLevels); + const size_t minLevels) : + SharedAttribute(IntervalsAlignmentSharedValue{combinedInterval, minInterval, minLevels}), + levels(levels) { } -template class ngraph::VariantImpl; - -constexpr VariantTypeInfo VariantWrapper::type_info; - -std::shared_ptr>> VariantWrapper::create( +ov::Any IntervalsAlignmentAttribute::create( const std::shared_ptr& node, const AttributeParameters& params) { if (!ov::is_type(node)) { @@ -109,11 +107,10 @@ std::shared_ptr>> Va auto& rtInfo = node->get_rt_info(); const IntervalsAlignmentSharedValue::Interval interval{ lowInterval, highInterval }; - const auto attribute = std::make_shared<::ngraph::VariantWrapper>( - ngraph::pass::low_precision::make_shared_attribute( + auto attribute = IntervalsAlignmentAttribute( interval, - fakeQuantize->get_levels())); - rtInfo[ngraph::VariantWrapper::type_info.name] = attribute; + fakeQuantize->get_levels()); + auto& result = (rtInfo[IntervalsAlignmentAttribute::get_type_info_static()] = attribute); const std::vector outputLowValues = ov::as_type_ptr(fakeQuantize->get_input_node_shared_ptr(3))->cast_vector(); const std::vector outputHighValues = ov::as_type_ptr(fakeQuantize->get_input_node_shared_ptr(4))->cast_vector(); @@ -123,50 +120,49 @@ std::shared_ptr>> Va outputHighValues); if (preferablePrecision.precision != element::undefined) { - attribute->get()->sharedValue->preferablePrecisions.insert(preferablePrecision.precision); + attribute.value().preferablePrecisions.insert(preferablePrecision.precision); } #ifdef LPT_DEBUG - attribute->get()->sharedValue->minLevelsOperation = node->get_friendly_name(); + attribute.value().minLevelsOperation = node->get_friendly_name(); #endif - return attribute; + return result; } } -void VariantWrapper::merge( - std::vector>>>& attributes) { - std::shared_ptr resultAttribute = get(); +void IntervalsAlignmentAttribute::merge( + std::vector& attributes) { for (const auto& attributeWrapper : attributes) { - auto attribute = attributeWrapper->get(); + auto attribute = attributeWrapper.as().attribute; // TODO: LPT: copy/past: merge() - const auto& resultSharedValue = resultAttribute->sharedValue; - const auto& sharedValue = attribute->sharedValue; - if (resultAttribute->levels != attribute->levels) { + auto& resultSharedValue = value(); + auto& sharedValue = attributeWrapper.as().value(); + if (levels != attributeWrapper.as().levels) { // TODO: LPT: not supported right now - resultAttribute->levels = 0ul; - resultSharedValue->minLevels = 0ul; + levels = 0ul; + resultSharedValue.minLevels = 0ul; } - if (resultSharedValue->combinedInterval.low > sharedValue->combinedInterval.low) { - resultSharedValue->combinedInterval.low = sharedValue->combinedInterval.low; + if (resultSharedValue.combinedInterval.low > sharedValue.combinedInterval.low) { + resultSharedValue.combinedInterval.low = sharedValue.combinedInterval.low; } - if (resultSharedValue->combinedInterval.high < sharedValue->combinedInterval.high) { - resultSharedValue->combinedInterval.high = sharedValue->combinedInterval.high; + if (resultSharedValue.combinedInterval.high < sharedValue.combinedInterval.high) { + resultSharedValue.combinedInterval.high = sharedValue.combinedInterval.high; } - assert(!std::isinf(resultSharedValue->combinedInterval.low)); - assert(!std::isinf(resultSharedValue->combinedInterval.high)); + assert(!std::isinf(resultSharedValue.combinedInterval.low)); + assert(!std::isinf(resultSharedValue.combinedInterval.high)); - resultSharedValue->preferablePrecisions.insert(sharedValue->preferablePrecisions.begin(), sharedValue->preferablePrecisions.end()); + resultSharedValue.preferablePrecisions.insert(sharedValue.preferablePrecisions.begin(), sharedValue.preferablePrecisions.end()); - const auto resultSize = std::abs(resultSharedValue->minInterval.high - resultSharedValue->minInterval.low); - const auto size = std::abs(sharedValue->minInterval.high - sharedValue->minInterval.low); + const auto resultSize = std::abs(resultSharedValue.minInterval.high - resultSharedValue.minInterval.low); + const auto size = std::abs(sharedValue.minInterval.high - sharedValue.minInterval.low); if (resultSize > size) { - resultSharedValue->minInterval = sharedValue->minInterval; - if (resultAttribute->levels != 0ul) { + resultSharedValue.minInterval = sharedValue.minInterval; + if (levels != 0ul) { float dequantizationMul; float dequantizationSub; float updatedOutputLowValue; @@ -174,44 +170,44 @@ void VariantWrapper::merge( const size_t minLevels = NetworkHelper::calculateLevels( 0.f, - DataPrecision::getMaxValue(resultAttribute->levels), - resultSharedValue->combinedInterval.low, - resultSharedValue->combinedInterval.high, - resultSharedValue->minInterval.low, - resultSharedValue->minInterval.high, + DataPrecision::getMaxValue(levels), + resultSharedValue.combinedInterval.low, + resultSharedValue.combinedInterval.high, + resultSharedValue.minInterval.low, + resultSharedValue.minInterval.high, dequantizationMul, dequantizationSub, updatedOutputLowValue, updatedOutputHighValue); - resultSharedValue->minLevels = minLevels; + resultSharedValue.minLevels = minLevels; } #ifdef LPT_DEBUG - resultSharedValue->minLevelsOperation = sharedValue->minLevelsOperation; + resultSharedValue.minLevelsOperation = sharedValue.minLevelsOperation; #endif } } } -std::string VariantWrapper::to_string() { +std::string IntervalsAlignmentAttribute::to_string() const { std::stringstream preferablePrecisions; preferablePrecisions << "{"; size_t index = 0; - for (const auto& precision : m_value->sharedValue->preferablePrecisions) { + for (const auto& precision : value().preferablePrecisions) { preferablePrecisions << (index > 0 ? ", " : "") << precision; ++index; } preferablePrecisions << "}"; std::stringstream ss; - ss << m_value->get_string(); - ss << "levels: " + std::to_string(m_value->levels) << ", " << - "combined: { " << m_value->sharedValue->combinedInterval.low << ", " << m_value->sharedValue->combinedInterval.high << " }, " << - "min: { " << m_value->sharedValue->minInterval.low << ", " << m_value->sharedValue->minInterval.high << " }, " - "minLevels: " << m_value->sharedValue->minLevels << + ss << attribute->get_string(); + ss << "levels: " + std::to_string(levels) << ", " << + "combined: { " << value().combinedInterval.low << ", " << value().combinedInterval.high << " }, " << + "min: { " << value().minInterval.low << ", " << value().minInterval.high << " }, " + "minLevels: " << value().minLevels << #ifdef LPT_DEBUG - ", minLevelsOperation: " << m_value->sharedValue->minLevelsOperation << + ", minLevelsOperation: " << value().minLevelsOperation << #endif ", preferablePrecisions: " << preferablePrecisions.str(); return ss.str(); diff --git a/src/common/low_precision_transformations/src/rt_info/per_tensor_quantization_attribute.cpp b/src/common/low_precision_transformations/src/rt_info/per_tensor_quantization_attribute.cpp index 0036e9e378a..78338a05b6d 100644 --- a/src/common/low_precision_transformations/src/rt_info/per_tensor_quantization_attribute.cpp +++ b/src/common/low_precision_transformations/src/rt_info/per_tensor_quantization_attribute.cpp @@ -7,5 +7,4 @@ using namespace ngraph; using namespace ov; -template class ngraph::VariantImpl; -constexpr VariantTypeInfo VariantWrapper::type_info; +PerTensorQuantizationAttribute::~PerTensorQuantizationAttribute() = default; diff --git a/src/common/low_precision_transformations/src/rt_info/precision_preserved_attribute.cpp b/src/common/low_precision_transformations/src/rt_info/precision_preserved_attribute.cpp index c2b94e425b0..ecb9bf9271a 100644 --- a/src/common/low_precision_transformations/src/rt_info/precision_preserved_attribute.cpp +++ b/src/common/low_precision_transformations/src/rt_info/precision_preserved_attribute.cpp @@ -10,18 +10,13 @@ using namespace ngraph; using namespace ov; -PrecisionPreservedAttribute::PrecisionPreservedAttribute(const bool value) { - sharedValue->value = value; +PrecisionPreservedAttribute::PrecisionPreservedAttribute(const bool value) : + SharedAttribute(value) { } -template class ngraph::VariantImpl; - -constexpr VariantTypeInfo VariantWrapper::type_info; - -std::string VariantWrapper::to_string() { - auto& value = this->m_value; +std::string PrecisionPreservedAttribute::to_string() const { std::stringstream ss; - ss << m_value->get_string(); - ss << "value: " << (value->sharedValue->value ? "true" : "false"); + ss << attribute->get_string(); + ss << "value: " << (value() ? "true" : "false"); return ss.str(); } diff --git a/src/common/low_precision_transformations/src/rt_info/precisions_attribute.cpp b/src/common/low_precision_transformations/src/rt_info/precisions_attribute.cpp index f7158632319..1d103efcc3b 100644 --- a/src/common/low_precision_transformations/src/rt_info/precisions_attribute.cpp +++ b/src/common/low_precision_transformations/src/rt_info/precisions_attribute.cpp @@ -19,30 +19,21 @@ using namespace ov; // order defines default precision std::vector PrecisionsAttribute::defaultPrecisions = {ngraph::element::u8, ngraph::element::i8}; -PrecisionsAttribute::PrecisionsAttribute(const std::vector& precisions) { - sharedValue->precisions = precisions; +PrecisionsAttribute::PrecisionsAttribute(const std::vector& precisions) : + SharedAttribute(precisions) { } -template class ngraph::VariantImpl>; - -constexpr VariantTypeInfo VariantWrapper>::type_info; - -std::shared_ptr>> VariantWrapper>::create( +ov::Any PrecisionsAttribute::create( const std::shared_ptr& node, const AttributeParameters& params) { - auto attribute = ngraph::pass::low_precision::make_shared_attribute(); - auto wrapper = std::make_shared>>(attribute); - auto& rt = ov::is_type(node) ? node->output(0).get_rt_info() : node->get_rt_info(); - rt[ngraph::VariantWrapper>::type_info.name] = wrapper; - return wrapper; + return (rt[PrecisionsAttribute::get_type_info_static()] = PrecisionsAttribute()); } -void VariantWrapper>::merge( - std::vector>>>& attributes) { - auto& my = this->get()->sharedValue->precisions; +void PrecisionsAttribute::merge(std::vector& attributes) { + auto& my = value(); for (auto attribute : attributes) { - const auto& attributeValues = attribute->get()->sharedValue->precisions; + const auto& attributeValues = attribute.as().value(); auto it = my.begin(); while (it != my.end()) { if (std::find(attributeValues.begin(), attributeValues.end(), *it) == attributeValues.end()) { @@ -57,22 +48,19 @@ void VariantWrapper>::merge( } } -ov::Any VariantWrapper>::init(const std::shared_ptr& node) { - return {}; -} -std::string VariantWrapper>::to_string() { +std::string PrecisionsAttribute::to_string() const { std::stringstream ss; - ss << m_value->get_string(); + ss << attribute->get_string(); bool firstPrecision = true; ss << "precisions: {"; - for (const auto& value : m_value->sharedValue->precisions) { + for (const auto& type : value()) { if (!firstPrecision) { ss << ", "; } - ss << value; + ss << type; firstPrecision = false; } ss << "}"; diff --git a/src/common/low_precision_transformations/src/rt_info/quantization_alignment_attribute.cpp b/src/common/low_precision_transformations/src/rt_info/quantization_alignment_attribute.cpp index f275f836f6d..d6621a39a77 100644 --- a/src/common/low_precision_transformations/src/rt_info/quantization_alignment_attribute.cpp +++ b/src/common/low_precision_transformations/src/rt_info/quantization_alignment_attribute.cpp @@ -16,27 +16,19 @@ using namespace ov; using namespace ngraph; using namespace ngraph::pass::low_precision; -QuantizationAlignmentAttribute::QuantizationAlignmentAttribute(const bool hasToBeAligned) { - sharedValue = std::make_shared(hasToBeAligned); +QuantizationAlignmentAttribute::QuantizationAlignmentAttribute(const bool hasToBeAligned) : + SharedAttribute(hasToBeAligned) { } -template class ngraph::VariantImpl; - -constexpr VariantTypeInfo VariantWrapper::type_info; - -ov::Any VariantWrapper::init(const std::shared_ptr& node) { - return nullptr; -} - -std::shared_ptr>> VariantWrapper::create( +ov::Any QuantizationAlignmentAttribute::create( const std::shared_ptr& node, const AttributeParameters& params) { - if (getAttribute>(node) != nullptr) { - return nullptr; + if (!getAttribute(node).empty()) { + return {}; } if (!NetworkHelper::isPrecisionPreserved(node)) { - return nullptr; + return {}; } bool leastOneOperationIsFakeQuantize = false; @@ -66,26 +58,22 @@ std::shared_ptr>> if (leastOneOperationIsFakeQuantize && !leastOneOperationIsNotFakeQuantize) { auto& rt = node->get_rt_info(); - const auto attribute = std::make_shared>( - make_shared_attribute()); - rt[ngraph::VariantWrapper::type_info.name] = attribute; - return attribute; + rt[QuantizationAlignmentAttribute::get_type_info_static()] = QuantizationAlignmentAttribute(); + return rt[QuantizationAlignmentAttribute::get_type_info_static()]; } - return nullptr; + return {}; } -void VariantWrapper::merge( - std::vector>>>& attributes) { - auto currentAttributte = get(); - for (const auto& attribute : attributes) { - currentAttributte->sharedValue->value = currentAttributte->sharedValue->value || attribute->get()->sharedValue->value; +void QuantizationAlignmentAttribute::merge(std::vector& attributes) { + for (const auto& other_attribute : attributes) { + value() = value() || other_attribute.as().value(); } } -std::string VariantWrapper::to_string() { +std::string QuantizationAlignmentAttribute::to_string() const { std::stringstream ss; - ss << m_value->get_string(); - ss << "value: " << (m_value->sharedValue->value ? "true" : "false"); + ss << attribute->get_string(); + ss << "value: " << (value() ? "true" : "false"); return ss.str(); } diff --git a/src/common/low_precision_transformations/src/weightable_layer_transformation.cpp b/src/common/low_precision_transformations/src/weightable_layer_transformation.cpp index 0a9a2a86690..c146be66495 100644 --- a/src/common/low_precision_transformations/src/weightable_layer_transformation.cpp +++ b/src/common/low_precision_transformations/src/weightable_layer_transformation.cpp @@ -298,10 +298,10 @@ bool WeightableLayerTransformation::decomposeFakeQuantizeForWeightsPath(const st } const QuantizationDetails quantizationDetails = QuantizationDetails::getDetails(fq); - const auto precisionsAttribute = getAttributeFromOutput(fq); - const auto precisions = precisionsAttribute == nullptr ? + const auto precisionsAttribute = getAttributeFromOutput(fq); + const auto precisions = precisionsAttribute.empty() ? PrecisionsAttribute::defaultPrecisions : - precisionsAttribute->get()->sharedValue->precisions; + precisionsAttribute.as().value(); const DataPrecision dataPrecision = getDataPrecision(fq, quantizationDetails, precisions); @@ -365,10 +365,10 @@ DataPrecision WeightableLayerTransformation::getDataPrecisionOnWeights(const std return DataPrecision(); } - const auto precisionsAttribute = getAttributeFromOutput(fq); - const auto precisions = precisionsAttribute == nullptr ? + const auto precisionsAttribute = getAttributeFromOutput(fq); + const auto precisions = precisionsAttribute.empty() ? PrecisionsAttribute::defaultPrecisions : - precisionsAttribute->get()->sharedValue->precisions; + precisionsAttribute.as().value(); return getDataPrecision(fq, quantizationDetails, precisions); } diff --git a/src/common/snippets/include/snippets/register_info.hpp b/src/common/snippets/include/snippets/register_info.hpp deleted file mode 100644 index 8d0e64ef2b6..00000000000 --- a/src/common/snippets/include/snippets/register_info.hpp +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include - -namespace ov { - -template <> -class TRANSFORMATIONS_API VariantWrapper> : public VariantImpl> { -public: - OPENVINO_RTTI("VariantWrapper>"); - BWDCMP_RTTI_DECLARATION; - VariantWrapper(const value_type& value) : VariantImpl(value) {} -}; - -} // namespace ov diff --git a/src/common/snippets/src/generator.cpp b/src/common/snippets/src/generator.cpp index 33b373f2d29..1668d1b474f 100644 --- a/src/common/snippets/src/generator.cpp +++ b/src/common/snippets/src/generator.cpp @@ -3,7 +3,6 @@ // #include "snippets/generator.hpp" -#include "snippets/register_info.hpp" #include "snippets/pass/assign_registers.hpp" #include "snippets/pass/vector_to_scalar.hpp" #include "snippets/pass/insert_load_store.hpp" @@ -17,10 +16,9 @@ auto ngraph::snippets::getRegisters(std::shared_ptr& n) -> ngraph: // ToDo: change to reg_t std::vector rout; - auto rinfo = rt["reginfo"]; - if (!rinfo.empty()) { - auto reginfo = ngraph::as_type_ptr>>(rinfo)->get(); - for (auto reg : reginfo) { + auto it_rt = rt.find("reginfo"); + if (it_rt == rt.end()) { + for (auto reg : it_rt->second.as>()) { rout.push_back(reg); } } @@ -28,10 +26,9 @@ auto ngraph::snippets::getRegisters(std::shared_ptr& n) -> ngraph: std::vector rin; for (auto input : n->inputs()) { auto rt = input.get_source_output().get_node_shared_ptr()->get_rt_info(); - auto rinfo = rt["reginfo"]; - if (!rinfo.empty()) { - auto reginfo = ngraph::as_type_ptr>>(rinfo)->get(); - for (auto reg : reginfo) { + auto it_rt = rt.find("reginfo"); + if (it_rt == rt.end()) { + for (auto reg : it_rt->second.as>()) { rin.push_back(reg); } } diff --git a/src/common/snippets/src/pass/assign_registers.cpp b/src/common/snippets/src/pass/assign_registers.cpp index 7561b2403a0..61ecdf4eba6 100644 --- a/src/common/snippets/src/pass/assign_registers.cpp +++ b/src/common/snippets/src/pass/assign_registers.cpp @@ -7,7 +7,6 @@ #include "remarks.hpp" #include "snippets/pass/assign_registers.hpp" -#include "snippets/register_info.hpp" #include "snippets/snippets_isa.hpp" #include @@ -152,7 +151,7 @@ bool ngraph::snippets::pass::AssignRegisters::run_on_function(std::shared_ptr(n)) { auto ea = reg64_tmp_start+static_cast(f->get_result_index(result) + f->get_parameters().size()); - rt["effectiveAddress"] = std::make_shared>(VariantWrapper(ea)); + rt["effectiveAddress"] = ea; continue; } // store effective address and procced with vector registers @@ -161,10 +160,10 @@ bool ngraph::snippets::pass::AssignRegisters::run_on_function(std::shared_ptr(source)) { auto ea = reg64_tmp_start+static_cast(f->get_parameter_index(param)); - rt["effectiveAddress"] = std::make_shared>(VariantWrapper(ea)); + rt["effectiveAddress"] = ea; } else if (auto constant = ov::as_type_ptr(source)) { auto ea = reg64_tmp_start+static_cast(f->get_parameters().size() + f->get_results().size() + 1 + constantID); - rt["effectiveAddress"] = std::make_shared>(VariantWrapper(ea)); + rt["effectiveAddress"] = ea; constantID++; } else { throw ngraph_error("load/broadcast should follow only Parameter or non-Scalar constant"); @@ -176,7 +175,7 @@ bool ngraph::snippets::pass::AssignRegisters::run_on_function(std::shared_ptr>>(VariantWrapper>(regs)); + rt["reginfo"] = regs; } return false; diff --git a/src/common/snippets/src/register_info.cpp b/src/common/snippets/src/register_info.cpp deleted file mode 100644 index 597ef5e2298..00000000000 --- a/src/common/snippets/src/register_info.cpp +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "snippets/register_info.hpp" - -template class ngraph::VariantImpl>; - -BWDCMP_RTTI_DEFINITION(ngraph::VariantWrapper>); diff --git a/src/common/transformations/include/transformations/fix_rt_info.hpp b/src/common/transformations/include/transformations/fix_rt_info.hpp new file mode 100644 index 00000000000..fbc0f4d7df6 --- /dev/null +++ b/src/common/transformations/include/transformations/fix_rt_info.hpp @@ -0,0 +1,44 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +/** + * @brief Defines initialize node runtime information pass + * @file init_node_info.hpp + */ + +#include +#include + +#include + +/** + * @brief ngraph namespace + */ +namespace ngraph { + +/** + * @brief ngraph::pass namespace + */ +namespace pass { + +class NGRAPH_API FixRtInfo; + +} // namespace pass +} // namespace ngraph + +/** + * @ingroup ie_transformation_common_api + * @brief FixRtInfo transformation helps to fix info attributes in a single place. + * User can pass runtime attribute using various types. + * This Pass should generalize them runtime info representation. + * + * Used to extract runtime attributes from shared pointer to `ov::RuntimeAttributeWrapper` to standard or trivial types + */ +class ngraph::pass::FixRtInfo: public ngraph::pass::FunctionPass { +public: + NGRAPH_RTTI_DECLARATION; + bool run_on_function(std::shared_ptr f) override; +}; diff --git a/src/common/transformations/include/transformations/rt_info/attributes.hpp b/src/common/transformations/include/transformations/rt_info/attributes.hpp index 11a0d515ccb..424a8104e86 100644 --- a/src/common/transformations/include/transformations/rt_info/attributes.hpp +++ b/src/common/transformations/include/transformations/rt_info/attributes.hpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -30,19 +29,18 @@ namespace pass { class TRANSFORMATIONS_API Attributes { public: Attributes(); - ~Attributes(); - std::shared_ptr create_by_type_info(const ov::DiscreteTypeInfo& type_info); + Any create_by_type_info(const ov::DiscreteTypeInfo& type_info_name); private: template void register_factory() { - m_factory_registry.emplace(T::get_type_info_static(), [] { - return std::make_shared(); + m_factory_registry.emplace(T::get_type_info_static(), [] () -> Any { + return T{}; }); } - std::unordered_map()>> m_factory_registry; + std::unordered_map> m_factory_registry; }; } // namespace pass } // namespace ov diff --git a/src/common/transformations/include/transformations/rt_info/decompression.hpp b/src/common/transformations/include/transformations/rt_info/decompression.hpp index 18965d1aee2..b68b6b3b345 100644 --- a/src/common/transformations/include/transformations/rt_info/decompression.hpp +++ b/src/common/transformations/include/transformations/rt_info/decompression.hpp @@ -11,7 +11,7 @@ #include #include "openvino/core/node.hpp" -#include "openvino/core/variant.hpp" +#include "openvino/core/runtime_attribute.hpp" #include "transformations_visibility.hpp" @@ -28,7 +28,7 @@ TRANSFORMATIONS_API bool is_decompression(const std::shared_ptr& node); * @brief Decompression class represents runtime info attribute that marks operation * as used as decompression for Compressed Only format. */ -class TRANSFORMATIONS_API Decompression : public VariantImpl { +class TRANSFORMATIONS_API Decompression : public RuntimeAttribute { public: OPENVINO_RTTI("decompression", "0"); diff --git a/src/common/transformations/include/transformations/rt_info/disable_fp16_compression.hpp b/src/common/transformations/include/transformations/rt_info/disable_fp16_compression.hpp index 00352928ba2..a7bd10d0dcd 100644 --- a/src/common/transformations/include/transformations/rt_info/disable_fp16_compression.hpp +++ b/src/common/transformations/include/transformations/rt_info/disable_fp16_compression.hpp @@ -5,7 +5,7 @@ #pragma once #include "openvino/core/node.hpp" -#include "openvino/core/variant.hpp" +#include "openvino/core/runtime_attribute.hpp" #include "transformations_visibility.hpp" @@ -22,7 +22,7 @@ TRANSFORMATIONS_API bool fp16_compression_is_disabled(const std::shared_ptr { +class TRANSFORMATIONS_API DisableFP16Compression : public RuntimeAttribute { public: OPENVINO_RTTI("disable_fp16_compression", "0"); diff --git a/src/common/transformations/include/transformations/rt_info/fused_names_attribute.hpp b/src/common/transformations/include/transformations/rt_info/fused_names_attribute.hpp index 98ab5b7ae9f..7dacdc018a7 100644 --- a/src/common/transformations/include/transformations/rt_info/fused_names_attribute.hpp +++ b/src/common/transformations/include/transformations/rt_info/fused_names_attribute.hpp @@ -19,6 +19,7 @@ #include #include #include +#include "openvino/core/runtime_attribute.hpp" namespace ngraph { @@ -28,12 +29,11 @@ namespace ngraph { * @brief FusedName class represents runtime info attribute that stores * all operation names that was fully or partially fused into node */ -class NGRAPH_API FusedNames { -private: +class NGRAPH_API FusedNames : public ov::RuntimeAttribute { std::set fused_names; public: - friend class VariantWrapper; + OPENVINO_RTTI("fused_names", "0"); /** * A default constructor @@ -64,6 +64,14 @@ public: * @return vector if strings */ std::vector getVectorNames() const; + + ov::Any merge(const ngraph::NodeVector& nodes) const override; + + ov::Any init(const std::shared_ptr& node) const override; + + bool visit_attributes(AttributeVisitor& visitor) override; + + std::string to_string() const override; }; /** @@ -82,24 +90,3 @@ NGRAPH_API std::string getFusedNames(const std::shared_ptr & node) NGRAPH_API std::vector getFusedNamesVector(const std::shared_ptr & node); } // namespace ngraph - -namespace ov { - -extern template class NGRAPH_API VariantImpl; - -template<> -class NGRAPH_API VariantWrapper : public VariantImpl { -public: - OPENVINO_RTTI("fused_names", "0"); - - VariantWrapper() = default; - - VariantWrapper(const value_type &value) : VariantImpl(value) {} - - Any merge(const ngraph::NodeVector & nodes) override; - - Any init(const std::shared_ptr & node) override; - - bool visit_attributes(AttributeVisitor & visitor) override; -}; -} // namespace ov diff --git a/src/common/transformations/include/transformations/rt_info/nms_selected_indices.hpp b/src/common/transformations/include/transformations/rt_info/nms_selected_indices.hpp index 312d0ee52d6..48e72367a7c 100644 --- a/src/common/transformations/include/transformations/rt_info/nms_selected_indices.hpp +++ b/src/common/transformations/include/transformations/rt_info/nms_selected_indices.hpp @@ -13,6 +13,7 @@ #include #include #include +#include "openvino/core/runtime_attribute.hpp" namespace ov { @@ -20,14 +21,10 @@ TRANSFORMATIONS_API bool has_nms_selected_indices(const Node * node); TRANSFORMATIONS_API void set_nms_selected_indices(Node * node); -class TRANSFORMATIONS_API NmsSelectedIndices : public VariantImpl { +class TRANSFORMATIONS_API NmsSelectedIndices : ov::RuntimeAttribute { public: OPENVINO_RTTI("nms_selected_indices", "0"); - NmsSelectedIndices() = default; - - NmsSelectedIndices(const value_type &value) : VariantImpl(value) {} - bool is_copyable() const override { return false; } }; diff --git a/src/common/transformations/include/transformations/rt_info/old_api_map_element_type_attribute.hpp b/src/common/transformations/include/transformations/rt_info/old_api_map_element_type_attribute.hpp index e28ae834c68..49b6b158917 100644 --- a/src/common/transformations/include/transformations/rt_info/old_api_map_element_type_attribute.hpp +++ b/src/common/transformations/include/transformations/rt_info/old_api_map_element_type_attribute.hpp @@ -28,7 +28,7 @@ namespace ov { * @brief OldApiMapElementType class represents runtime info attribute that stores legacy type * that is required for obtaining IR in old API. */ -class TRANSFORMATIONS_API OldApiMapElementType : public VariantImpl { +class TRANSFORMATIONS_API OldApiMapElementType : public RuntimeAttribute { public: OPENVINO_RTTI("old_api_map_element_type", "0"); @@ -41,13 +41,15 @@ public: * Constructs a new OldApiMapElementType object. * @param[in] value The object that stores values of OldApiMapElementType. */ - OldApiMapElementType(const value_type& value) : VariantImpl(value) {} + OldApiMapElementType(const ngraph::element::Type& value) : value(value) {} bool is_copyable() const override { return false; } bool visit_attributes(AttributeVisitor& visitor) override; + + ngraph::element::Type value; }; inline bool has_old_api_map_element_type(const std::shared_ptr& node) { @@ -57,13 +59,12 @@ inline bool has_old_api_map_element_type(const std::shared_ptr& node) { inline OldApiMapElementType get_old_api_map_element_type(const std::shared_ptr& node) { const auto& rt_map = node->get_rt_info(); - const auto& var = rt_map.at(OldApiMapElementType::get_type_info_static()); - return ngraph::as_type_ptr(var)->get(); + return rt_map.at(OldApiMapElementType::get_type_info_static()).as(); } inline void set_old_api_map_element_type(std::shared_ptr& node, const OldApiMapElementType& old_api_map) { auto& rt_map = node->get_rt_info(); - rt_map[OldApiMapElementType::get_type_info_static()] = std::make_shared(old_api_map); + rt_map[OldApiMapElementType::get_type_info_static()] = old_api_map; } } // namespace ov \ No newline at end of file diff --git a/src/common/transformations/include/transformations/rt_info/old_api_map_order_attribute.hpp b/src/common/transformations/include/transformations/rt_info/old_api_map_order_attribute.hpp index f650ab6f35a..4188003d628 100644 --- a/src/common/transformations/include/transformations/rt_info/old_api_map_order_attribute.hpp +++ b/src/common/transformations/include/transformations/rt_info/old_api_map_order_attribute.hpp @@ -39,7 +39,7 @@ class OldApiMapOrder; * Order of the transpose which should be applied to Result with new API layout to * obtain Result with old API layout. */ -class TRANSFORMATIONS_API OldApiMapOrder : public VariantImpl> { +class TRANSFORMATIONS_API OldApiMapOrder : public RuntimeAttribute { public: OPENVINO_RTTI("old_api_map_order", "0"); @@ -52,13 +52,15 @@ public: * Constructs a new OldApiMapOrder object. * @param[in] value The object that stores values of OldApiMapOrder. */ - OldApiMapOrder(const value_type& value) : VariantImpl(value) {} + OldApiMapOrder(const std::vector& value) : value(value) {} bool is_copyable() const override { return false; } bool visit_attributes(AttributeVisitor& visitor) override; + + std::vector value; }; inline bool has_old_api_map_order(const std::shared_ptr& node) { @@ -68,13 +70,12 @@ inline bool has_old_api_map_order(const std::shared_ptr& node) { inline OldApiMapOrder get_old_api_map_order(const std::shared_ptr& node) { const auto& rt_map = node->get_rt_info(); - const auto& var = rt_map.at(OldApiMapOrder::get_type_info_static()); - return ngraph::as_type_ptr(var)->get(); + return rt_map.at(OldApiMapOrder::get_type_info_static()).as(); } inline void set_old_api_map_order(std::shared_ptr& node, const OldApiMapOrder& old_api_map) { auto& rt_map = node->get_rt_info(); - rt_map[OldApiMapOrder::get_type_info_static()] = std::make_shared(old_api_map); + rt_map[OldApiMapOrder::get_type_info_static()] = old_api_map; } } // namespace ov diff --git a/src/common/transformations/include/transformations/rt_info/primitives_priority_attribute.hpp b/src/common/transformations/include/transformations/rt_info/primitives_priority_attribute.hpp index 49ccfaf674f..3db735d4379 100644 --- a/src/common/transformations/include/transformations/rt_info/primitives_priority_attribute.hpp +++ b/src/common/transformations/include/transformations/rt_info/primitives_priority_attribute.hpp @@ -18,6 +18,8 @@ #include #include +#include "openvino/core/runtime_attribute.hpp" + namespace ov { /** * @ingroup ie_runtime_attr_api @@ -26,20 +28,20 @@ namespace ov { */ NGRAPH_API std::string getPrimitivesPriority(const std::shared_ptr & node); -class NGRAPH_API PrimitivesPriority : public VariantImpl { +class NGRAPH_API PrimitivesPriority : public ov::RuntimeAttribute { public: OPENVINO_RTTI("primitives_priority", "0"); PrimitivesPriority() = default; - ~PrimitivesPriority() override = default; + PrimitivesPriority(const std::string &value) : value(value) {} - PrimitivesPriority(const value_type &value) : VariantImpl(value) {} - - Any merge(const ngraph::NodeVector & nodes) override; - - Any init(const std::shared_ptr & node) override; + Any merge(const ngraph::NodeVector & nodes) const override; bool visit_attributes(AttributeVisitor & visitor) override; + + std::string to_string() const override; + + std::string value; }; } // namespace ov diff --git a/src/common/transformations/include/transformations/rt_info/strides_property.hpp b/src/common/transformations/include/transformations/rt_info/strides_property.hpp index 01c1359f599..956f7e3c7a3 100644 --- a/src/common/transformations/include/transformations/rt_info/strides_property.hpp +++ b/src/common/transformations/include/transformations/rt_info/strides_property.hpp @@ -8,18 +8,17 @@ #include #include #include +#include "openvino/core/runtime_attribute.hpp" namespace ov { -class TRANSFORMATIONS_API StridesPropagation : public VariantImpl { -public: - OPENVINO_RTTI("strides_propagation", "0"); - - StridesPropagation() = default; - - StridesPropagation(const value_type& value) : VariantImpl(value) {} -}; - TRANSFORMATIONS_API bool has_strides_prop(const ngraph::Input& node); TRANSFORMATIONS_API ngraph::Strides get_strides_prop(const ngraph::Input& node); TRANSFORMATIONS_API void insert_strides_prop(ngraph::Input& node, const ngraph::Strides& strides); +class TRANSFORMATIONS_API StridesPropagation : public ov::RuntimeAttribute { +public: + OPENVINO_RTTI("strides_propagation", "0"); + StridesPropagation() = default; + StridesPropagation(const ngraph::Strides& value) : value{value} {} + ngraph::Strides value; +}; } // namespace ov diff --git a/src/common/transformations/src/transformations/rt_info/attributes.cpp b/src/common/transformations/src/transformations/rt_info/attributes.cpp index 641fc08d2be..821c959932f 100644 --- a/src/common/transformations/src/transformations/rt_info/attributes.cpp +++ b/src/common/transformations/src/transformations/rt_info/attributes.cpp @@ -5,20 +5,20 @@ #include "transformations/rt_info/attributes.hpp" ov::pass::Attributes::Attributes() { - register_factory>(); + register_factory(); register_factory(); register_factory(); register_factory(); register_factory(); - register_factory(); register_factory(); register_factory(); register_factory(); register_factory(); register_factory(); + register_factory(); } -std::shared_ptr ov::pass::Attributes::create_by_type_info(const ov::DiscreteTypeInfo& type_info) { +ov::Any ov::pass::Attributes::create_by_type_info(const ov::DiscreteTypeInfo& type_info) { auto it_type = m_factory_registry.find(type_info); if (it_type != m_factory_registry.end()) { return it_type->second(); @@ -26,5 +26,3 @@ std::shared_ptr ov::pass::Attributes::create_by_type_info(const ov: return {}; } } - -ov::pass::Attributes::~Attributes() = default; diff --git a/src/common/transformations/src/transformations/rt_info/decompression.cpp b/src/common/transformations/src/transformations/rt_info/decompression.cpp index 01b45f2bfab..8538c53e23a 100644 --- a/src/common/transformations/src/transformations/rt_info/decompression.cpp +++ b/src/common/transformations/src/transformations/rt_info/decompression.cpp @@ -6,7 +6,7 @@ void ov::mark_as_decompression(const std::shared_ptr& node) { auto& rt_info = node->get_rt_info(); - rt_info[Decompression::get_type_info_static()] = std::make_shared(); + rt_info[Decompression::get_type_info_static()] = Decompression(); } void ov::unmark_as_decompression(const std::shared_ptr& node) { diff --git a/src/common/transformations/src/transformations/rt_info/disable_fp16_compression.cpp b/src/common/transformations/src/transformations/rt_info/disable_fp16_compression.cpp index 79513ddf2b7..286dbdcf7c2 100644 --- a/src/common/transformations/src/transformations/rt_info/disable_fp16_compression.cpp +++ b/src/common/transformations/src/transformations/rt_info/disable_fp16_compression.cpp @@ -6,7 +6,7 @@ void ov::disable_fp16_compression(const std::shared_ptr& node) { auto& rt_info = node->get_rt_info(); - rt_info[DisableFP16Compression::get_type_info_static()] = std::make_shared(); + rt_info[DisableFP16Compression::get_type_info_static()] = DisableFP16Compression{}; } void ov::enable_fp16_compression(const std::shared_ptr& node) { diff --git a/src/common/transformations/src/transformations/rt_info/nms_selected_indices.cpp b/src/common/transformations/src/transformations/rt_info/nms_selected_indices.cpp index 640bb29d08f..a9303ef6bc9 100644 --- a/src/common/transformations/src/transformations/rt_info/nms_selected_indices.cpp +++ b/src/common/transformations/src/transformations/rt_info/nms_selected_indices.cpp @@ -4,14 +4,11 @@ #include "transformations/rt_info/nms_selected_indices.hpp" -template class ov::VariantImpl; void ov::set_nms_selected_indices(Node * node) { - auto & rt_info = node->get_rt_info(); - rt_info[NmsSelectedIndices::get_type_info_static()] = std::make_shared(true); + node->get_rt_info().emplace(NmsSelectedIndices::get_type_info_static(), NmsSelectedIndices{}); } bool ov::has_nms_selected_indices(const Node * node) { - const auto & rt_info = node->get_rt_info(); - return rt_info.count(NmsSelectedIndices::get_type_info_static()); + return node->get_rt_info().count(NmsSelectedIndices::get_type_info_static()); } diff --git a/src/common/transformations/src/transformations/rt_info/old_api_map_element_type_attribute.cpp b/src/common/transformations/src/transformations/rt_info/old_api_map_element_type_attribute.cpp index 3aca75d542d..c4bbebf4972 100644 --- a/src/common/transformations/src/transformations/rt_info/old_api_map_element_type_attribute.cpp +++ b/src/common/transformations/src/transformations/rt_info/old_api_map_element_type_attribute.cpp @@ -7,6 +7,6 @@ using namespace ov; bool OldApiMapElementType::visit_attributes(AttributeVisitor& visitor) { - visitor.on_attribute("value", m_value); + visitor.on_attribute("value", value); return true; } diff --git a/src/common/transformations/src/transformations/rt_info/old_api_map_order_attribute.cpp b/src/common/transformations/src/transformations/rt_info/old_api_map_order_attribute.cpp index 2a9ec1a0659..a700edc1972 100644 --- a/src/common/transformations/src/transformations/rt_info/old_api_map_order_attribute.cpp +++ b/src/common/transformations/src/transformations/rt_info/old_api_map_order_attribute.cpp @@ -7,6 +7,6 @@ using namespace ov; bool OldApiMapOrder::visit_attributes(AttributeVisitor& visitor) { - visitor.on_attribute("value", m_value); + visitor.on_attribute("value", value); return true; } diff --git a/src/common/transformations/src/transformations/rt_info/strides_property.cpp b/src/common/transformations/src/transformations/rt_info/strides_property.cpp index 63ede121c4e..4903cc43070 100644 --- a/src/common/transformations/src/transformations/rt_info/strides_property.cpp +++ b/src/common/transformations/src/transformations/rt_info/strides_property.cpp @@ -5,17 +5,13 @@ #include "transformations/rt_info/strides_property.hpp" bool ov::has_strides_prop(const ngraph::Input& node) { - const auto& rt_map = node.get_rt_info(); - return rt_map.count(StridesPropagation::get_type_info_static()); + return node.get_rt_info().count(StridesPropagation::get_type_info_static()); } ngraph::Strides ov::get_strides_prop(const ngraph::Input& node) { - const auto& rt_map = node.get_rt_info(); - const auto& var = rt_map.at(StridesPropagation::get_type_info_static()); - return ngraph::as_type_ptr(var)->get(); + return node.get_rt_info().at(StridesPropagation::get_type_info_static()).as().value; } void ov::insert_strides_prop(ngraph::Input& node, const ngraph::Strides& strides) { - auto& rt_map = node.get_rt_info(); - rt_map[StridesPropagation::get_type_info_static()] = std::make_shared(strides); + node.get_rt_info().emplace(StridesPropagation::get_type_info_static(), StridesPropagation{strides}); } diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 4cbb338d9e7..48bc4b6d698 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -93,6 +93,7 @@ file(GLOB_RECURSE smart_reshape_srcs ${CMAKE_CURRENT_SOURCE_DIR}/src/pass/smart_ file(GLOB_RECURSE rt_info_srcs ${CMAKE_CURRENT_SOURCE_DIR}/src/pass/rt_info/*.cpp) set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/src/pass/convert_precision.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/pass/convert_fp32_to_fp16.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/src/pass/fix_rt_info.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/pass/init_node_info.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/pass/serialize.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/op/type_relaxed.cpp" diff --git a/src/core/include/ngraph/variant.hpp b/src/core/include/ngraph/variant.hpp index a203a35d2df..df8716d69f4 100644 --- a/src/core/include/ngraph/variant.hpp +++ b/src/core/include/ngraph/variant.hpp @@ -8,20 +8,38 @@ #include #include "openvino/core/any.hpp" // used for ov::RTMap -#include "openvino/core/variant.hpp" +#include "openvino/core/runtime_attribute.hpp" namespace ov { class Node; } namespace ngraph { using ov::Node; -using ov::VariantTypeInfo; +using VariantTypeInfo = ov::DiscreteTypeInfo; -using ov::Variant; -using ov::VariantImpl; -using ov::VariantWrapper; +using Variant = ov::RuntimeAttribute; +template +using VariantImpl = ov::RuntimeAttributeImpl; -using ov::make_variant; +template +using VariantWrapper = ov::RuntimeAttributeWrapper; + +template +inline std::shared_ptr make_variant(const T& p) { + return ov::make_runtime_attribute(p); +} + +template +inline std::shared_ptr make_variant(const char (&s)[N]) { + return ov::make_runtime_attribute(s); +} + +#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) +template +inline std::shared_ptr make_variant(const wchar_t (&s)[N]) { + return ov::make_runtime_attribute(s); +} +#endif using ov::RTMap; } // namespace ngraph diff --git a/src/core/include/openvino/core/any.hpp b/src/core/include/openvino/core/any.hpp index db9ad76ee0c..01010add718 100644 --- a/src/core/include/openvino/core/any.hpp +++ b/src/core/include/openvino/core/any.hpp @@ -11,13 +11,14 @@ #include #include #include +#include #include #include #include #include "openvino/core/attribute_visitor.hpp" #include "openvino/core/except.hpp" -#include "openvino/core/variant.hpp" +#include "openvino/core/runtime_attribute.hpp" namespace InferenceEngine { class InferencePlugin; @@ -27,7 +28,7 @@ class ExecutableNetwork; namespace ov { class Node; -class Variant; +class RuntimeAttribute; class ParamMap; namespace runtime { @@ -84,6 +85,57 @@ class OPENVINO_API Any { constexpr static const bool value = sizeof(test>(nullptr)) == sizeof(char); }; + template + struct HasBaseMemberType { + template + static auto test(U*) -> decltype(std::is_class::value, std::true_type()) { + return {}; + } + template + static auto test(...) -> std::false_type { + return {}; + } + constexpr static const auto value = std::is_same(nullptr))>::value; + }; + + template + struct TupleToTypeIndex; + + template + struct TupleToTypeIndex> { + static std::vector get() { + return {typeid(Args)...}; + } + }; + + template + struct HasOnAttribute { + template + static auto test(U*) + -> decltype(std::declval().on_attribute(std::declval()), std::true_type()) { + return {}; + } + template + static auto test(...) -> std::false_type { + return {}; + } + constexpr static const auto value = std::is_same(nullptr))>::value; + }; + + template + struct Visitable { + template + static auto test(U*) + -> decltype(std::declval().visit_attributes(std::declval()), std::true_type()) { + return {}; + } + template + static auto test(...) -> std::false_type { + return {}; + } + constexpr static const auto value = std::is_same(nullptr))>::value; + }; + /** * @brief Base API of erased type */ @@ -93,23 +145,24 @@ class OPENVINO_API Any { using Ptr = std::shared_ptr; virtual const std::type_info& type_info() const = 0; + virtual std::vector base_type_info() const = 0; virtual const void* addressof() const = 0; void* addressof() { return const_cast(const_cast(this)->addressof()); } virtual Base::Ptr copy() const = 0; virtual bool equal(const Base& rhs) const = 0; - virtual void print(std::ostream&) const = 0; + virtual void print(std::ostream& os) const = 0; virtual const DiscreteTypeInfo& get_type_info() const = 0; - virtual std::shared_ptr as_variant() const; + virtual std::shared_ptr as_runtime_attribute() const; virtual bool is_copyable() const; virtual Any init(const std::shared_ptr& node); virtual Any merge(const std::vector>& nodes); virtual std::string to_string(); - std::string to_string() const; virtual bool visit_attributes(AttributeVisitor&); bool visit_attributes(AttributeVisitor&) const; + std::string to_string() const; template bool is() const { @@ -135,42 +188,47 @@ class OPENVINO_API Any { template struct Impl; template - struct Impl>::value>::type> + struct Impl>::value>::type> : public Base { const DiscreteTypeInfo& get_type_info() const override { - return static_cast(variant.get())->get_type_info(); + return static_cast(runtime_attribute.get())->get_type_info(); } - std::shared_ptr as_variant() const override { - return std::dynamic_pointer_cast(variant); + std::shared_ptr as_runtime_attribute() const override { + return std::static_pointer_cast(runtime_attribute); } bool is_copyable() const override { - return static_cast(variant.get())->is_copyable(); + return static_cast(runtime_attribute.get())->is_copyable(); } Any init(const std::shared_ptr& node) override { - return static_cast(variant.get())->init(node); + return static_cast(runtime_attribute.get())->init(node); } Any merge(const std::vector>& nodes) override { - return static_cast(variant.get())->merge(nodes); + return static_cast(runtime_attribute.get())->merge(nodes); } std::string to_string() override { - return static_cast(variant.get())->to_string(); - } - bool visit_attributes(AttributeVisitor& visitor) override { - return static_cast(variant.get())->visit_attributes(visitor); + return static_cast(runtime_attribute.get())->to_string(); } - Impl(const T& variant_) : variant{variant_} {} + bool visit_attributes(AttributeVisitor& visitor) override { + return static_cast(runtime_attribute.get())->visit_attributes(visitor); + } + + Impl(const T& runtime_attribute) : runtime_attribute{runtime_attribute} {} const std::type_info& type_info() const override { return typeid(T); } + std::vector base_type_info() const override { + return {typeid(std::shared_ptr)}; + } + const void* addressof() const override { - return std::addressof(variant); + return std::addressof(runtime_attribute); } Base::Ptr copy() const override { - return std::make_shared>(this->variant); + return std::make_shared>(this->runtime_attribute); } template @@ -186,20 +244,20 @@ class OPENVINO_API Any { bool equal(const Base& rhs) const override { if (rhs.is()) { - return equal_impl(this->variant, rhs.as()); + return equal_impl(this->runtime_attribute, rhs.as()); } return false; } void print(std::ostream& os) const override { - os << variant->to_string(); + os << runtime_attribute->to_string(); } - T variant; + T runtime_attribute; }; template - struct Impl>::value>::type> + struct Impl>::value>::type> : public Base { OPENVINO_RTTI(typeid(T).name()); @@ -218,6 +276,21 @@ class OPENVINO_API Any { return std::make_shared>(this->value); } + template + static std::vector base_type_info_impl( + typename std::enable_if::value, std::true_type>::type = {}) { + return TupleToTypeIndex::get(); + } + template + static std::vector base_type_info_impl( + typename std::enable_if::value, std::false_type>::type = {}) { + return {typeid(T)}; + } + + std::vector base_type_info() const override { + return base_type_info_impl(); + } + template static typename std::enable_if::value, bool>::type equal_impl(const U& rhs, const U& lhs) { @@ -251,7 +324,7 @@ class OPENVINO_API Any { T value; }; - friend class ::ov::Variant; + friend class ::ov::RuntimeAttribute; friend class ::ov::ParamMap; friend class ::InferenceEngine::InferencePlugin; friend class ::InferenceEngine::ExecutableNetwork; @@ -264,7 +337,7 @@ class OPENVINO_API Any { void impl_check() const; - mutable Base::Ptr _variant_impl; + mutable Base::Ptr _runtime_attribute_impl; Base::Ptr _impl; @@ -313,6 +386,12 @@ public: return any; } + /** + * Returns type info + * @return type info + */ + const std::type_info& type_info() const; + /** * Checks that any contains a value * @return false if any contains a value else false @@ -325,35 +404,18 @@ public: * @return true if type of value is correct */ template - typename std::enable_if>::value, bool>::type is() const { - if (_impl != nullptr) { - return _impl->type_info() == typeid(decay_t); - } else { - return false; - } - } - - /** - * @brief check the type of value in any - * @tparam T Type of value - * @return true if type of value is correct - */ - template - typename std::enable_if>::value, bool>::type is() const { + bool is() const { if (_impl != nullptr) { if (_impl->type_info() == typeid(decay_t)) { return true; - } else { - auto variant = _impl->as_variant(); - if (variant == nullptr) { - return false; - } else { - return std::dynamic_pointer_cast(variant) != nullptr; + } + for (const auto& type_index : _impl->base_type_info()) { + if (type_index == typeid(decay_t)) { + return true; } } - } else { - return false; } + return false; } /** @@ -362,30 +424,31 @@ public: * @return casted object */ template - typename std::enable_if>::value, T>::type&& as() && { + typename std::enable_if>::value, T>::type&& as() && { if (_impl == nullptr) { - _variant_impl = std::make_shared>>(T{}); - return _variant_impl->as(); + _runtime_attribute_impl = std::make_shared>>(T{}); + return _runtime_attribute_impl->as(); } else { if (_impl->type_info() == typeid(decay_t)) { return std::move(*static_cast*>(_impl->addressof())); } else { - auto variant = _impl->as_variant(); - if (variant == nullptr) { - throw ov::Exception{std::string{"Any does not contains pointer to variant. It contains "} + - _impl->type_info().name()}; + auto runtime_attribute = _impl->as_runtime_attribute(); + if (runtime_attribute == nullptr) { + throw ov::Exception{ + std::string{"Any does not contains pointer to runtime_attribute. It contains "} + + _impl->type_info().name()}; } - auto vptr = std::dynamic_pointer_cast(variant); - if (vptr == nullptr && T::element_type::get_type_info_static() != variant->get_type_info() && - T::element_type::get_type_info_static() != Variant::get_type_info_static()) { - throw ov::Exception{std::string{"Could not cast Any variant to "} + typeid(T).name() + " from " + - _impl->type_info().name() + "; from " + - static_cast(variant->get_type_info()) + " to " + + auto vptr = std::dynamic_pointer_cast(runtime_attribute); + if (vptr == nullptr && T::element_type::get_type_info_static() != runtime_attribute->get_type_info() && + T::element_type::get_type_info_static() != RuntimeAttribute::get_type_info_static()) { + throw ov::Exception{std::string{"Could not cast Any runtime_attribute to "} + typeid(T).name() + + " from " + _impl->type_info().name() + "; from " + + static_cast(runtime_attribute->get_type_info()) + " to " + static_cast(T::element_type::get_type_info_static())}; } - vptr = std::static_pointer_cast(variant); - _variant_impl = std::make_shared>>(vptr); - return _variant_impl->as(); + vptr = std::static_pointer_cast(runtime_attribute); + _runtime_attribute_impl = std::make_shared>>(vptr); + return _runtime_attribute_impl->as(); } } } @@ -396,30 +459,31 @@ public: * @return casted object */ template - typename std::enable_if>::value, T>::type& as() & { + typename std::enable_if>::value, T>::type& as() & { if (_impl == nullptr) { - _variant_impl = std::make_shared>>(T{}); - return _variant_impl->as(); + _runtime_attribute_impl = std::make_shared>>(T{}); + return _runtime_attribute_impl->as(); } else { if (_impl->type_info() == typeid(decay_t)) { return *static_cast*>(_impl->addressof()); } else { - auto variant = _impl->as_variant(); - if (variant == nullptr) { - throw ov::Exception{std::string{"Any does not contains pointer to variant. It contains "} + - _impl->type_info().name()}; + auto runtime_attribute = _impl->as_runtime_attribute(); + if (runtime_attribute == nullptr) { + throw ov::Exception{ + std::string{"Any does not contains pointer to runtime_attribute. It contains "} + + _impl->type_info().name()}; } - auto vptr = std::dynamic_pointer_cast(variant); - if (vptr == nullptr && T::element_type::get_type_info_static() != variant->get_type_info() && - T::element_type::get_type_info_static() != Variant::get_type_info_static()) { - throw ov::Exception{std::string{"Could not cast Any variant to "} + typeid(T).name() + " from " + - _impl->type_info().name() + "; from " + - static_cast(variant->get_type_info()) + " to " + + auto vptr = std::dynamic_pointer_cast(runtime_attribute); + if (vptr == nullptr && T::element_type::get_type_info_static() != runtime_attribute->get_type_info() && + T::element_type::get_type_info_static() != RuntimeAttribute::get_type_info_static()) { + throw ov::Exception{std::string{"Could not cast Any runtime_attribute to "} + typeid(T).name() + + " from " + _impl->type_info().name() + "; from " + + static_cast(runtime_attribute->get_type_info()) + " to " + static_cast(T::element_type::get_type_info_static())}; } - vptr = std::static_pointer_cast(variant); - _variant_impl = std::make_shared>>(vptr); - return _variant_impl->as(); + vptr = std::static_pointer_cast(runtime_attribute); + _runtime_attribute_impl = std::make_shared>>(vptr); + return _runtime_attribute_impl->as(); } } } @@ -430,30 +494,32 @@ public: * @return casted object */ template - const typename std::enable_if>::value, T>::type& as() const& { + const typename std::enable_if>::value, T>::type& as() + const& { if (_impl == nullptr) { - _variant_impl = std::make_shared>>(T{}); - return _variant_impl->as(); + _runtime_attribute_impl = std::make_shared>>(T{}); + return _runtime_attribute_impl->as(); } else { if (_impl->type_info() == typeid(decay_t)) { return *static_cast*>(_impl->addressof()); } else { - auto variant = _impl->as_variant(); - if (variant == nullptr) { - throw ov::Exception{std::string{"Any does not contains pointer to variant. It contains "} + - _impl->type_info().name()}; + auto runtime_attribute = _impl->as_runtime_attribute(); + if (runtime_attribute == nullptr) { + throw ov::Exception{ + std::string{"Any does not contains pointer to runtime_attribute. It contains "} + + _impl->type_info().name()}; } - auto vptr = std::dynamic_pointer_cast(variant); - if (vptr == nullptr && T::element_type::get_type_info_static() != variant->get_type_info() && - T::element_type::get_type_info_static() != Variant::get_type_info_static()) { - throw ov::Exception{std::string{"Could not cast Any variant to "} + typeid(T).name() + " from " + - _impl->type_info().name() + "; from " + - static_cast(variant->get_type_info()) + " to " + + auto vptr = std::dynamic_pointer_cast(runtime_attribute); + if (vptr == nullptr && T::element_type::get_type_info_static() != runtime_attribute->get_type_info() && + T::element_type::get_type_info_static() != RuntimeAttribute::get_type_info_static()) { + throw ov::Exception{std::string{"Could not cast Any runtime_attribute to "} + typeid(T).name() + + " from " + _impl->type_info().name() + "; from " + + static_cast(runtime_attribute->get_type_info()) + " to " + static_cast(T::element_type::get_type_info_static())}; } - vptr = std::static_pointer_cast(variant); - _variant_impl = std::make_shared>>(vptr); - return _variant_impl->as(); + vptr = std::static_pointer_cast(runtime_attribute); + _runtime_attribute_impl = std::make_shared>>(vptr); + return _runtime_attribute_impl->as(); } } } @@ -464,7 +530,7 @@ public: * @return casted object */ template - typename std::enable_if>::value, T>::type&& as() && { + typename std::enable_if>::value, T>::type&& as() && { impl_check(); _impl->type_check(typeid(decay_t)); return std::move(*static_cast*>(_impl->addressof())); @@ -476,10 +542,17 @@ public: * @return casted object */ template - typename std::enable_if>::value, T>::type& as() & { + typename std::enable_if>::value, T>::type& as() & { impl_check(); - _impl->type_check(typeid(decay_t)); - return *static_cast*>(_impl->addressof()); + if (_impl->type_info() == typeid(decay_t)) { + return *static_cast*>(_impl->addressof()); + } + for (const auto& type_index : _impl->base_type_info()) { + if (type_index == typeid(decay_t)) { + return *static_cast*>(_impl->addressof()); + } + } + throw ov::Exception{std::string{"Bad cast from: "} + _impl->type_info().name() + " to: " + typeid(T).name()}; } /** @@ -488,10 +561,18 @@ public: * @return casted object */ template - const typename std::enable_if>::value, T>::type& as() const& { + const typename std::enable_if>::value, T>::type& as() + const& { impl_check(); - _impl->type_check(typeid(decay_t)); - return *static_cast*>(_impl->addressof()); + if (_impl->type_info() == typeid(decay_t)) { + return *static_cast*>(_impl->addressof()); + } + for (const auto& type_index : _impl->base_type_info()) { + if (type_index == typeid(decay_t)) { + return *static_cast*>(_impl->addressof()); + } + } + throw ov::Exception{std::string{"Bad cast from: "} + _impl->type_info().name() + " to: " + typeid(T).name()}; } /** @@ -607,9 +688,9 @@ template <> struct AsTypePtr { template static std::shared_ptr call(const Any& any) { - if (any.is>()) { + try { return any.as>(); - } else { + } catch (...) { return {}; } } @@ -623,9 +704,9 @@ using RTMap = std::map; namespace std { template std::shared_ptr dynamic_pointer_cast(const ::ov::Any& any) { - if (any.is>()) { + try { return any.as>(); - } else { + } catch (...) { return {}; } } diff --git a/src/core/include/openvino/core/core.hpp b/src/core/include/openvino/core/core.hpp index 611af2ee1aa..f444ffd57cb 100644 --- a/src/core/include/openvino/core/core.hpp +++ b/src/core/include/openvino/core/core.hpp @@ -29,11 +29,11 @@ #include "openvino/core/partial_shape.hpp" #include "openvino/core/rank.hpp" #include "openvino/core/rtti.hpp" +#include "openvino/core/runtime_attribute.hpp" #include "openvino/core/shape.hpp" #include "openvino/core/strides.hpp" #include "openvino/core/type.hpp" #include "openvino/core/validation_util.hpp" -#include "openvino/core/variant.hpp" #include "openvino/core/version.hpp" #include "openvino/core/visibility.hpp" diff --git a/src/core/include/openvino/core/descriptor/input.hpp b/src/core/include/openvino/core/descriptor/input.hpp index 6081e2c9250..1d5994cf05b 100644 --- a/src/core/include/openvino/core/descriptor/input.hpp +++ b/src/core/include/openvino/core/descriptor/input.hpp @@ -9,7 +9,7 @@ #include "openvino/core/core_visibility.hpp" #include "openvino/core/descriptor/tensor.hpp" -#include "openvino/core/variant.hpp" +#include "openvino/core/runtime_attribute.hpp" namespace ov { class Node; diff --git a/src/core/include/openvino/core/descriptor/output.hpp b/src/core/include/openvino/core/descriptor/output.hpp index 30484f42dbb..dab168980f0 100644 --- a/src/core/include/openvino/core/descriptor/output.hpp +++ b/src/core/include/openvino/core/descriptor/output.hpp @@ -14,7 +14,7 @@ #include "openvino/core/descriptor/input.hpp" #include "openvino/core/descriptor/tensor.hpp" #include "openvino/core/node_output.hpp" -#include "openvino/core/variant.hpp" +#include "openvino/core/runtime_attribute.hpp" namespace ov { // The forward declaration of Node is needed here because Node has a deque of diff --git a/src/core/include/openvino/core/descriptor/tensor.hpp b/src/core/include/openvino/core/descriptor/tensor.hpp index 10d3fa00da1..c7909eee1db 100644 --- a/src/core/include/openvino/core/descriptor/tensor.hpp +++ b/src/core/include/openvino/core/descriptor/tensor.hpp @@ -16,7 +16,6 @@ #include "openvino/core/partial_shape.hpp" #include "openvino/core/shape.hpp" #include "openvino/core/type/element_type.hpp" -#include "openvino/core/variant.hpp" namespace ngraph { namespace runtime { @@ -114,7 +113,7 @@ protected: std::string m_name; std::unordered_set m_names; - std::map m_rt_info; + RTMap m_rt_info; mutable std::atomic_bool m_shape_changed; }; diff --git a/src/core/include/openvino/core/function.hpp b/src/core/include/openvino/core/function.hpp index 9fb61bbc853..6e451845037 100644 --- a/src/core/include/openvino/core/function.hpp +++ b/src/core/include/openvino/core/function.hpp @@ -15,7 +15,6 @@ #include "openvino/core/core_visibility.hpp" #include "openvino/core/node.hpp" #include "openvino/core/rtti.hpp" -#include "openvino/core/variant.hpp" #include "openvino/op/assign.hpp" #include "openvino/op/parameter.hpp" #include "openvino/op/read_value.hpp" diff --git a/src/core/include/openvino/core/layout.hpp b/src/core/include/openvino/core/layout.hpp index cf358babd4d..ef55e966a6e 100644 --- a/src/core/include/openvino/core/layout.hpp +++ b/src/core/include/openvino/core/layout.hpp @@ -11,7 +11,7 @@ #include "openvino/core/core_visibility.hpp" #include "openvino/core/partial_shape.hpp" #include "openvino/core/rank.hpp" -#include "openvino/core/variant.hpp" +#include "openvino/core/runtime_attribute.hpp" namespace ov { @@ -161,15 +161,19 @@ protected: std::string m_dump; }; -class OPENVINO_API LayoutAttribute : public VariantImpl { +class OPENVINO_API LayoutAttribute : public ov::RuntimeAttribute { public: OPENVINO_RTTI("layout", "0"); LayoutAttribute() = default; - explicit LayoutAttribute(const Layout& value) : VariantImpl(value) {} + explicit LayoutAttribute(const Layout& value) : value(value) {} bool visit_attributes(AttributeVisitor& visitor) override; + + std::string to_string() const override; + + Layout value; }; } // namespace ov diff --git a/src/core/include/openvino/core/node.hpp b/src/core/include/openvino/core/node.hpp index 4abdd23b1ea..11cfe250b8f 100644 --- a/src/core/include/openvino/core/node.hpp +++ b/src/core/include/openvino/core/node.hpp @@ -31,9 +31,9 @@ #include "openvino/core/node_output.hpp" #include "openvino/core/node_vector.hpp" #include "openvino/core/rtti.hpp" +#include "openvino/core/runtime_attribute.hpp" #include "openvino/core/strides.hpp" #include "openvino/core/type.hpp" -#include "openvino/core/variant.hpp" #include "openvino/op/util/attr_types.hpp" #include "openvino/op/util/variable.hpp" #include "openvino/op/util/variable_value.hpp" diff --git a/src/core/include/openvino/core/node_input.hpp b/src/core/include/openvino/core/node_input.hpp index 6004b34a836..c126f160472 100644 --- a/src/core/include/openvino/core/node_input.hpp +++ b/src/core/include/openvino/core/node_input.hpp @@ -10,9 +10,9 @@ #include "openvino/core/core_visibility.hpp" #include "openvino/core/descriptor/tensor.hpp" #include "openvino/core/partial_shape.hpp" +#include "openvino/core/runtime_attribute.hpp" #include "openvino/core/shape.hpp" #include "openvino/core/type/element_type.hpp" -#include "openvino/core/variant.hpp" namespace ov { class Node; diff --git a/src/core/include/openvino/core/node_output.hpp b/src/core/include/openvino/core/node_output.hpp index 83e89a0a4fd..2ceeba995e3 100644 --- a/src/core/include/openvino/core/node_output.hpp +++ b/src/core/include/openvino/core/node_output.hpp @@ -11,9 +11,9 @@ #include "openvino/core/core_visibility.hpp" #include "openvino/core/descriptor/tensor.hpp" #include "openvino/core/partial_shape.hpp" +#include "openvino/core/runtime_attribute.hpp" #include "openvino/core/shape.hpp" #include "openvino/core/type/element_type.hpp" -#include "openvino/core/variant.hpp" namespace ov { class Node; 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 0f56e973dd2..fc7c25e701a 100644 --- a/src/core/include/openvino/core/preprocess/input_tensor_info.hpp +++ b/src/core/include/openvino/core/preprocess/input_tensor_info.hpp @@ -13,18 +13,20 @@ namespace ov { namespace preprocess { -class OPENVINO_API TensorInfoMemoryType : public VariantImpl { +class OPENVINO_API TensorInfoMemoryType : public RuntimeAttribute { public: OPENVINO_RTTI("memory_type", "0"); TensorInfoMemoryType() = default; - explicit TensorInfoMemoryType(const std::string& value) : VariantImpl(value) {} + explicit TensorInfoMemoryType(const std::string& value) : value(value) {} bool visit_attributes(AttributeVisitor& visitor) override { - visitor.on_attribute("value", m_value); + visitor.on_attribute("value", value); return true; } + + std::string value; }; /// \brief Information about user's input tensor. By default, it will be initialized to same data (type/shape/etc) as diff --git a/src/core/include/openvino/core/runtime_attribute.hpp b/src/core/include/openvino/core/runtime_attribute.hpp new file mode 100644 index 00000000000..d9a9de0047d --- /dev/null +++ b/src/core/include/openvino/core/runtime_attribute.hpp @@ -0,0 +1,112 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include + +#include "openvino/core/core_visibility.hpp" +#include "openvino/core/node_vector.hpp" +#include "openvino/core/rtti.hpp" +#include "openvino/core/type.hpp" + +namespace ov { +class Node; +class AttributeVisitor; +class Any; + +class OPENVINO_API RuntimeAttribute { +public: + static const DiscreteTypeInfo& get_type_info_static() { + static const ::ov::DiscreteTypeInfo type_info{"RuntimeAttribute", 0}; + return type_info; + } + virtual const DiscreteTypeInfo& get_type_info() const { + return get_type_info_static(); + } + using Ptr = std::shared_ptr; + using Base = std::tuple<::ov::RuntimeAttribute>; + virtual ~RuntimeAttribute() = default; + virtual bool is_copyable() const; + virtual Any init(const std::shared_ptr& node) const; + virtual Any merge(const ov::NodeVector& nodes) const; + virtual std::string to_string() const; + virtual bool visit_attributes(AttributeVisitor&); + bool visit_attributes(AttributeVisitor& visitor) const { + return const_cast(this)->visit_attributes(visitor); + } +}; +OPENVINO_API std::ostream& operator<<(std::ostream& os, const RuntimeAttribute& attrubute); + +template +class RuntimeAttributeImpl : public RuntimeAttribute { +public: + OPENVINO_RTTI(typeid(VT).name()); + using value_type = VT; + + RuntimeAttributeImpl() = default; + + RuntimeAttributeImpl(const value_type& value) : m_value(value) {} + + const value_type& get() const { + return m_value; + } + value_type& get() { + return m_value; + } + void set(const value_type& value) { + m_value = value; + } + +protected: + value_type m_value; +}; + +extern template class OPENVINO_API RuntimeAttributeImpl; +extern template class OPENVINO_API RuntimeAttributeImpl; +extern template class OPENVINO_API RuntimeAttributeImpl; + +template +class RuntimeAttributeWrapper {}; + +template <> +class OPENVINO_API RuntimeAttributeWrapper : public RuntimeAttributeImpl { +public: + OPENVINO_RTTI("RuntimeAttributeWrapper"); + RuntimeAttributeWrapper(const value_type& value) : RuntimeAttributeImpl(value) {} + std::string to_string() const override { + return m_value; + } +}; + +template <> +class OPENVINO_API RuntimeAttributeWrapper : public RuntimeAttributeImpl { +public: + OPENVINO_RTTI("RuntimeAttributeWrapper"); + RuntimeAttributeWrapper(const value_type& value) : RuntimeAttributeImpl(value) {} + std::string to_string() const override { + return std::to_string(m_value); + } +}; + +template +inline std::shared_ptr make_runtime_attribute(const T& p) { + return std::static_pointer_cast(std::make_shared>(p)); +} + +template +inline std::shared_ptr make_runtime_attribute(const char (&s)[N]) { + return std::static_pointer_cast(std::make_shared>(s)); +} + +#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) +template +inline std::shared_ptr make_runtime_attribute(const wchar_t (&s)[N]) { + return std::static_pointer_cast(std::make_shared>(s)); +} +#endif + +using RuntimeAttributeVector = std::vector; +} // namespace ov diff --git a/src/core/include/openvino/core/variant.hpp b/src/core/include/openvino/core/variant.hpp deleted file mode 100644 index 015fb744bf1..00000000000 --- a/src/core/include/openvino/core/variant.hpp +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include - -#include "openvino/core/core_visibility.hpp" -#include "openvino/core/node_vector.hpp" -#include "openvino/core/rtti.hpp" -#include "openvino/core/type.hpp" - -namespace ov { -class Node; -class AttributeVisitor; -class Any; -using VariantTypeInfo = DiscreteTypeInfo; - -class OPENVINO_API Variant { -public: - static const ::ov::DiscreteTypeInfo& get_type_info_static() { - static const ::ov::DiscreteTypeInfo type_info{"Variant", 0}; - return type_info; - } - virtual ~Variant(); - virtual const VariantTypeInfo& get_type_info() const { - return get_type_info_static(); - } - virtual bool is_copyable() const; - virtual Any init(const std::shared_ptr& node); - virtual Any merge(const ov::NodeVector& nodes); - virtual std::string to_string() { - return ""; - } - virtual bool visit_attributes(AttributeVisitor&) { - return false; - } - - using type_info_t = DiscreteTypeInfo; -}; - -template -class VariantImpl : public Variant { -public: - OPENVINO_RTTI(typeid(VT).name(), "0"); - using value_type = VT; - - VariantImpl() = default; - - VariantImpl(const value_type& value) : m_value(value) {} - - const value_type& get() const { - return m_value; - } - value_type& get() { - return m_value; - } - void set(const value_type& value) { - m_value = value; - } - -protected: - value_type m_value; -}; - -template <> -class VariantImpl : public Variant { -public: - using value_type = void; - - VariantImpl() = default; -}; - -extern template class OPENVINO_API VariantImpl; -extern template class OPENVINO_API VariantImpl; -extern template class OPENVINO_API VariantImpl; - -template -class VariantWrapper {}; - -template <> -class OPENVINO_API VariantWrapper : public VariantImpl { -public: - OPENVINO_RTTI("VariantWrapper"); - VariantWrapper(const value_type& value) : VariantImpl(value) {} -}; - -template <> -class OPENVINO_API VariantWrapper : public VariantImpl { -public: - OPENVINO_RTTI("VariantWrapper"); - VariantWrapper(const value_type& value) : VariantImpl(value) {} -}; - -template -inline std::shared_ptr make_variant(const T& p) { - return std::dynamic_pointer_cast>(std::make_shared>(p)); -} - -template -inline std::shared_ptr make_variant(const char (&s)[N]) { - return std::dynamic_pointer_cast>(std::make_shared>(s)); -} - -#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) -template -inline std::shared_ptr make_variant(const wchar_t (&s)[N]) { - return std::dynamic_pointer_cast>(std::make_shared>(s)); -} -#endif -using VariantVector = std::vector>; -} // namespace ov 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 eb0f7308d4b..267d5ef1f60 100644 --- a/src/core/include/openvino/op/util/precision_sensitive_attribute.hpp +++ b/src/core/include/openvino/op/util/precision_sensitive_attribute.hpp @@ -6,7 +6,7 @@ #include "openvino/core/core_visibility.hpp" #include "openvino/core/node.hpp" -#include "openvino/core/variant.hpp" +#include "openvino/core/runtime_attribute.hpp" namespace ov { @@ -21,7 +21,7 @@ bool OPENVINO_API is_precision_sensitive(const ov::Input& node_input); * input to an operation as a precision sensitive and disables compression to FP16 * of the subgraph before this input. */ -class OPENVINO_API PrecisionSensitive : public VariantImpl { +class OPENVINO_API PrecisionSensitive : public RuntimeAttribute { public: OPENVINO_RTTI("precision_sensitive", "0"); diff --git a/src/core/include/openvino/op/util/variable_context.hpp b/src/core/include/openvino/op/util/variable_context.hpp index 463e57e2691..03e9935f092 100644 --- a/src/core/include/openvino/op/util/variable_context.hpp +++ b/src/core/include/openvino/op/util/variable_context.hpp @@ -8,7 +8,7 @@ #include #include "openvino/core/node_vector.hpp" -#include "openvino/core/variant.hpp" +#include "openvino/core/runtime_attribute.hpp" #include "openvino/op/util/variable.hpp" #include "openvino/op/util/variable_value.hpp" @@ -73,16 +73,4 @@ private: }; } // namespace util } // namespace op -template <> -class OPENVINO_API VariantWrapper : public VariantImpl { -public: - OPENVINO_RTTI("VariantWrapper"); - BWDCMP_RTTI_DECLARATION; - - explicit VariantWrapper(const value_type& value) : VariantImpl(value) {} - -private: - using Variant::init; - using Variant::merge; -}; } // namespace ov diff --git a/src/core/include/openvino/pass/constant_folding.hpp b/src/core/include/openvino/pass/constant_folding.hpp index 462d9916cb5..9e6128dc453 100644 --- a/src/core/include/openvino/pass/constant_folding.hpp +++ b/src/core/include/openvino/pass/constant_folding.hpp @@ -4,7 +4,7 @@ #pragma once -#include "openvino/core/variant.hpp" +#include "openvino/core/runtime_attribute.hpp" #include "openvino/pass/pass.hpp" namespace ov { @@ -32,14 +32,10 @@ OPENVINO_API void enable_constant_folding(const std::shared_ptr& node); OPENVINO_API bool constant_folding_is_disabled(const std::shared_ptr& node); -class OPENVINO_API DisableConstantFolding : public VariantImpl { +class OPENVINO_API DisableConstantFolding : public ov::RuntimeAttribute { public: - OPENVINO_RTTI("disabled_constant_folding", "0"); - + OPENVINO_RTTI("DisableConstantFolding"); DisableConstantFolding() = default; - - DisableConstantFolding(const value_type& value) : VariantImpl(value) {} - bool is_copyable() const override { return false; } diff --git a/src/core/src/any.cpp b/src/core/src/any.cpp index 2c28f292e04..93036af1ba7 100644 --- a/src/core/src/any.cpp +++ b/src/core/src/any.cpp @@ -10,7 +10,7 @@ void Any::Base::type_check(const std::type_info& type_info_) const { OPENVINO_ASSERT(type_info() == type_info_, "Bad cast from: ", type_info().name(), " To type: ", type_info_.name()); } -std::shared_ptr Any::Base::as_variant() const { +std::shared_ptr Any::Base::as_runtime_attribute() const { return {}; } @@ -50,6 +50,11 @@ void Any::impl_check() const { OPENVINO_ASSERT(_impl != nullptr, "Any was not initialized."); } +const std::type_info& Any::type_info() const { + impl_check(); + return _impl->type_info(); +} + bool Any::empty() const { return _impl == nullptr; } diff --git a/src/core/src/function.cpp b/src/core/src/function.cpp index 88b4355ea6c..3dc78ca07b7 100644 --- a/src/core/src/function.cpp +++ b/src/core/src/function.cpp @@ -513,9 +513,7 @@ bool ov::Function::evaluate(const HostTensorVector& output_tensors, bool ov::Function::evaluate(ov::runtime::TensorVector& output_tensors, const ov::runtime::TensorVector& input_tensors, ov::EvaluationContext evaluation_context) const { - if (evaluation_context.find("VariableContext") == evaluation_context.end()) - evaluation_context["VariableContext"] = - std::make_shared>(ov::op::util::VariableContext()); + evaluation_context.emplace("VariableContext", ov::op::util::VariableContext()); std::map value_map; for (size_t i = 0; i < m_parameters.size(); ++i) { value_map[m_parameters.at(i)->output(0)] = input_tensors.at(i); diff --git a/src/core/src/layout.cpp b/src/core/src/layout.cpp index d583f13750f..afeafa46551 100644 --- a/src/core/src/layout.cpp +++ b/src/core/src/layout.cpp @@ -425,10 +425,14 @@ void AttributeAdapter::set(const std::string& value) { } bool LayoutAttribute::visit_attributes(AttributeVisitor& visitor) { - std::string layout_str = m_value.to_string(); + std::string layout_str = value.to_string(); visitor.on_attribute("layout", layout_str); - m_value = Layout(layout_str); + value = Layout(layout_str); return true; } +std::string LayoutAttribute::to_string() const { + return value.to_string(); +} + } // namespace ov diff --git a/src/core/src/node.cpp b/src/core/src/node.cpp index 259cda314de..edbb0291fcd 100644 --- a/src/core/src/node.cpp +++ b/src/core/src/node.cpp @@ -18,6 +18,7 @@ #include "ngraph/op/result.hpp" #include "ngraph/pattern/matcher.hpp" #include "openvino/core/descriptor/input.hpp" +#include "openvino/pass/constant_folding.hpp" #include "shared_node_info.hpp" using namespace std; @@ -781,7 +782,7 @@ OPENVINO_SUPPRESS_DEPRECATED_END bool ov::Node::constant_fold(OutputVector& output_values, const OutputVector& input_values) { OV_ITT_SCOPED_TASK(ov::itt::domains::nGraph, "Node::constant_fold"); - if (m_rt_info.count("disabled_constant_folding_0")) { + if (m_rt_info.count(ov::pass::DisableConstantFolding::get_type_info_static())) { return false; } diff --git a/src/core/src/op/assign.cpp b/src/core/src/op/assign.cpp index b951c86b186..68d09e7915e 100644 --- a/src/core/src/op/assign.cpp +++ b/src/core/src/op/assign.cpp @@ -100,15 +100,15 @@ bool op::v6::Assign::evaluate(const HostTensorVector& outputs, const auto& found_context = evaluation_context.find("VariableContext"); NODE_VALIDATION_CHECK(this, found_context != evaluation_context.end(), "VariableContext not found."); - auto variable_context = std::dynamic_pointer_cast>(found_context->second); - NODE_VALIDATION_CHECK(this, variable_context != nullptr, "Cannot cast found Context to VariableContext."); - const auto& variable_values = variable_context->get().get_variable_values(); + auto& variable_context = const_cast(found_context->second.as()); + + const auto& variable_values = variable_context.get_variable_values(); // automatically allocate memory if not provided by user if (variable_values.find(m_variable) == variable_values.end()) { auto host_tensor = std::make_shared(m_variable->get_info().data_type, m_variable->get_info().data_shape); - variable_context->get().set_variable_value(m_variable, make_shared(host_tensor)); + variable_context.set_variable_value(m_variable, make_shared(host_tensor)); } const auto var_value = variable_values.find(m_variable)->second; diff --git a/src/core/src/op/parameter.cpp b/src/core/src/op/parameter.cpp index ad74129c7a1..7f00f2ffe7f 100644 --- a/src/core/src/op/parameter.cpp +++ b/src/core/src/op/parameter.cpp @@ -51,22 +51,16 @@ void op::Parameter::set_is_relevant_to_shapes(bool is_relevant) { ov::Layout op::Parameter::get_layout() const { auto it = output(0).get_rt_info().find(ov::LayoutAttribute::get_type_info_static()); if (it == output(0).get_rt_info().end()) { - return ""; + return {}; } - auto layout = std::dynamic_pointer_cast(it->second); - OPENVINO_ASSERT(layout, - "'", - ov::LayoutAttribute::get_type_info_static(), - "' runtime info for parameter is invalid, use set_layout API"); - return layout->get(); + return it->second.as().value; } void op::Parameter::set_layout(const ov::Layout& layout) { if (layout.empty()) { output(0).get_rt_info().erase(ov::LayoutAttribute::get_type_info_static()); } else { - output(0).get_rt_info()[ov::LayoutAttribute::get_type_info_static()] = - std::make_shared(layout); + output(0).get_rt_info()[ov::LayoutAttribute::get_type_info_static()] = ov::LayoutAttribute(layout); } } diff --git a/src/core/src/op/read_value.cpp b/src/core/src/op/read_value.cpp index 1f0bc7fb194..8d677698dd1 100644 --- a/src/core/src/op/read_value.cpp +++ b/src/core/src/op/read_value.cpp @@ -92,9 +92,7 @@ bool op::v6::ReadValue::evaluate(const HostTensorVector& outputs, const auto& found_context = evaluation_context.find("VariableContext"); NODE_VALIDATION_CHECK(this, found_context != evaluation_context.end(), "VariableContext not found."); - auto variable_context = std::dynamic_pointer_cast>(found_context->second); - NODE_VALIDATION_CHECK(this, variable_context != nullptr, "Cannot cast found Context to VariableContext."); - const auto& variable_values = variable_context->get().get_variable_values(); + const auto& variable_values = found_context->second.as().get_variable_values(); const auto& var_value = variable_values.find(m_variable); bool use_context = var_value != variable_values.end() && !var_value->second->get_reset(); diff --git a/src/core/src/op/result.cpp b/src/core/src/op/result.cpp index 09595715ca0..91b0d1d99ce 100644 --- a/src/core/src/op/result.cpp +++ b/src/core/src/op/result.cpp @@ -72,20 +72,14 @@ ov::Layout op::Result::get_layout() const { if (it == input(0).get_rt_info().end()) { return {}; } - auto layout = std::dynamic_pointer_cast(it->second); - OPENVINO_ASSERT(layout, - "'", - ov::LayoutAttribute::get_type_info_static(), - "' runtime info for result is invalid, use set_layout API"); - return layout->get(); + return it->second.as().value; } void op::Result::set_layout(const ov::Layout& layout) { if (layout.empty()) { input(0).get_rt_info().erase(ov::LayoutAttribute::get_type_info_static()); } else { - input(0).get_rt_info()[ov::LayoutAttribute::get_type_info_static()] = - std::make_shared(layout); + input(0).get_rt_info()[ov::LayoutAttribute::get_type_info_static()] = ov::LayoutAttribute{layout}; } } diff --git a/src/core/src/op/shape_of.cpp b/src/core/src/op/shape_of.cpp index 1ed1d31b446..16574b37a55 100644 --- a/src/core/src/op/shape_of.cpp +++ b/src/core/src/op/shape_of.cpp @@ -16,6 +16,7 @@ #include "ngraph/runtime/host_tensor.hpp" #include "ngraph/runtime/reference/shape_of.hpp" #include "ngraph/type/element_type_traits.hpp" +#include "openvino/pass/constant_folding.hpp" using namespace std; using namespace ngraph; @@ -182,7 +183,7 @@ bool op::v3::ShapeOf::evaluate_upper(const HostTensorVector& output_values) cons bool op::v3::ShapeOf::constant_fold(OutputVector& output_values, const OutputVector& input_values) { OV_ITT_SCOPED_TASK(ov::itt::domains::nGraph, "op::v3::ShapeOf::constant_fold"); - if (get_rt_info().count("disabled_constant_folding_0")) + if (get_rt_info().count(ov::pass::DisableConstantFolding::get_type_info_static())) return false; return shape_of::constant_fold_shape_of(this, output_values[0], input_values[0]); } @@ -241,7 +242,7 @@ bool op::v0::ShapeOf::has_evaluate() const { bool op::v0::ShapeOf::constant_fold(OutputVector& output_values, const OutputVector& input_values) { OV_ITT_SCOPED_TASK(ov::itt::domains::nGraph, "op::v0::ShapeOf::constant_fold"); - if (get_rt_info().count("disabled_constant_folding_0")) + if (get_rt_info().count(ov::pass::DisableConstantFolding::get_type_info_static())) return false; return shape_of::constant_fold_shape_of(this, output_values[0], input_values[0]); } diff --git a/src/core/src/op/util/evaluation_context.cpp b/src/core/src/op/util/evaluation_context.cpp deleted file mode 100644 index e3680bca154..00000000000 --- a/src/core/src/op/util/evaluation_context.cpp +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (C) 2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include - -#include "ngraph/op/util/variable_context.hpp" - -BWDCMP_RTTI_DEFINITION(ov::VariantWrapper); diff --git a/src/core/src/op/util/precision_sensitive_attribute.cpp b/src/core/src/op/util/precision_sensitive_attribute.cpp index 6591699a341..5664311b7f6 100644 --- a/src/core/src/op/util/precision_sensitive_attribute.cpp +++ b/src/core/src/op/util/precision_sensitive_attribute.cpp @@ -6,7 +6,7 @@ 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()] = std::make_shared(); + rt_info[PrecisionSensitive::get_type_info_static()] = PrecisionSensitive{}; } void ov::unmark_as_precision_sensitive(ov::Input node_input) { diff --git a/src/core/src/pass/constant_folding.cpp b/src/core/src/pass/constant_folding.cpp index 5be3c068808..ee25911f6a8 100644 --- a/src/core/src/pass/constant_folding.cpp +++ b/src/core/src/pass/constant_folding.cpp @@ -88,7 +88,7 @@ bool ngraph::pass::ConstantFolding::pre_calculated_values_folding(const std::sha if (status) { for (const auto& node : order) { const auto& rt_info = node->get_rt_info(); - if (rt_info.count("disabled_constant_folding_0")) { + if (rt_info.count(DisableConstantFolding::get_type_info_static())) { status = false; break; } @@ -122,16 +122,13 @@ bool ngraph::pass::ConstantFolding::pre_calculated_values_folding(const std::sha } void ov::pass::disable_constant_folding(const std::shared_ptr& node) { - auto& rt_info = node->get_rt_info(); - rt_info[DisableConstantFolding::get_type_info_static()] = std::make_shared(true); + node->get_rt_info().emplace(DisableConstantFolding::get_type_info_static(), DisableConstantFolding{}); } void ov::pass::enable_constant_folding(const std::shared_ptr& node) { - auto& rt_info = node->get_rt_info(); - rt_info.erase(DisableConstantFolding::get_type_info_static()); + node->get_rt_info().erase(DisableConstantFolding::get_type_info_static()); } bool ov::pass::constant_folding_is_disabled(const std::shared_ptr& node) { - const auto& rt_info = node->get_rt_info(); - return rt_info.count(DisableConstantFolding::get_type_info_static()); + return node->get_rt_info().count(DisableConstantFolding::get_type_info_static()); } diff --git a/src/core/src/pass/fix_rt_info.cpp b/src/core/src/pass/fix_rt_info.cpp new file mode 100644 index 00000000000..87ea78b7967 --- /dev/null +++ b/src/core/src/pass/fix_rt_info.cpp @@ -0,0 +1,58 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "transformations/fix_rt_info.hpp" + +#include +#include +#include +#include +#include + +#include "itt.hpp" +#include "transformations/rt_info/primitives_priority_attribute.hpp" + +NGRAPH_RTTI_DEFINITION(ngraph::pass::FixRtInfo, "FixRtInfo", 0); + +bool ngraph::pass::FixRtInfo::run_on_function(std::shared_ptr f) { + // TODO: enable conditional compile + // RUN_ON_FUNCTION_SCOPE(FixRtInfo); + + for (auto& node : f->get_ops()) { + // Recursively apply transformation for sub-graph based operations + if (auto sub_graph_node = std::dynamic_pointer_cast(node)) { + if (auto sub_graph = sub_graph_node->get_function()) { + run_on_function(sub_graph); + } + } + auto& rt_info = node->get_rt_info(); + { + auto it_info = rt_info.find("PrimitivesPriority"); + if (it_info != rt_info.end()) { + if (it_info->second.is>>()) { + rt_info.emplace(ov::PrimitivesPriority::get_type_info_static(), + ov::PrimitivesPriority{ + it_info->second.as>>()->get()}); + } else if (it_info->second.is()) { + rt_info.emplace(ov::PrimitivesPriority::get_type_info_static(), + it_info->second.as()); + } + if (it_info->second.is()) { + rt_info.emplace(ov::PrimitivesPriority::get_type_info_static(), + ov::PrimitivesPriority{it_info->second.as()}); + } + rt_info.erase(it_info); + } + } + { + auto it_info = rt_info.find("affinity"); + if (it_info != rt_info.end()) { + if (it_info->second.is>>()) { + it_info->second = it_info->second.as>>()->get(); + } + } + } + } + return false; +} diff --git a/src/core/src/pass/init_node_info.cpp b/src/core/src/pass/init_node_info.cpp index a40837fbd6d..e1dedd20b18 100644 --- a/src/core/src/pass/init_node_info.cpp +++ b/src/core/src/pass/init_node_info.cpp @@ -11,6 +11,7 @@ #include #include "itt.hpp" +#include "transformations/fix_rt_info.hpp" #include "transformations/rt_info/fused_names_attribute.hpp" #include "transformations/rt_info/primitives_priority_attribute.hpp" @@ -19,14 +20,6 @@ NGRAPH_RTTI_DEFINITION(ngraph::pass::InitNodeInfo, "InitNodeInfo", 0); bool ngraph::pass::InitNodeInfo::run_on_function(std::shared_ptr f) { // TODO: enable conditional compile // RUN_ON_FUNCTION_SCOPE(InitNodeInfo); - std::vector> attributes{ - std::make_shared>(ngraph::FusedNames())}; - - using VariantCreator = std::function(const std::string&)>; - std::map update_attributes{ - {"PrimitivesPriority", [](const std::string& value) -> std::shared_ptr { - return std::make_shared(value); - }}}; for (auto& node : f->get_ops()) { // Recursively apply transformation for sub-graph based operations @@ -36,27 +29,8 @@ bool ngraph::pass::InitNodeInfo::run_on_function(std::shared_ptrget_rt_info(); - // Default attributes initialization - for (auto& attr : attributes) { - // Skip initialization if attribute has been already set - if (rtInfo.count(attr->get_type_info())) - continue; - auto init_attr = attr->init(node); - if (!init_attr.empty()) { - rtInfo[attr->get_type_info()] = init_attr; - } - } - // Convert manually set attributes to appropriate VariantWrapper class instances - // all manually set attributes must belong to VariantWrapper class - for (auto& attr : update_attributes) { - if (rtInfo.count(attr.first)) { - if (auto variant_string = std::dynamic_pointer_cast>(rtInfo[attr.first])) { - rtInfo.erase(attr.first); - auto res = attr.second(variant_string->get()); - rtInfo[res->get_type_info()] = res; - } - } - } + rtInfo.emplace(FusedNames::get_type_info_static(), FusedNames{node->get_friendly_name()}); } + FixRtInfo{}.run_on_function(f); return false; } diff --git a/src/core/src/pass/low_latency.cpp b/src/core/src/pass/low_latency.cpp index 2bbbaab5d09..6cc86ed0b81 100644 --- a/src/core/src/pass/low_latency.cpp +++ b/src/core/src/pass/low_latency.cpp @@ -44,7 +44,7 @@ ngraph::pass::LowLatency::LowLatency() { } // Mark the TI layer to be unrolled. Enable unconditional ti unrolling for all plugins. auto& rt_info = sub_graph_op->get_rt_info(); - rt_info["UNROLL_TI"] = std::make_shared>(1); + rt_info["UNROLL_TI"] = std::make_shared>(1); int64_t variable_id = 0; std::vector> assigns; diff --git a/src/core/src/pass/rt_info/fused_names_attribute.cpp b/src/core/src/pass/rt_info/fused_names_attribute.cpp index 8a25cec593f..4d426e4349a 100644 --- a/src/core/src/pass/rt_info/fused_names_attribute.cpp +++ b/src/core/src/pass/rt_info/fused_names_attribute.cpp @@ -35,55 +35,52 @@ void FusedNames::fuseWith(const FusedNames& names) { } std::string ngraph::getFusedNames(const std::shared_ptr& node) { - const auto& rtInfo = node->get_rt_info(); - using FusedNamesWrapper = VariantWrapper; - - if (!rtInfo.count(FusedNamesWrapper::get_type_info_static())) - return {}; - - const auto& attr = rtInfo.at(FusedNamesWrapper::get_type_info_static()); - FusedNames fusedNames = ov::as_type_ptr(attr)->get(); - return fusedNames.getNames(); + if (node) { + const auto& rtInfo = node->get_rt_info(); + auto it_info = rtInfo.find(FusedNames::get_type_info_static()); + if (it_info != rtInfo.end()) { + return it_info->second.as().getNames(); + } else { + return {}; + } + } + return {}; } std::vector ngraph::getFusedNamesVector(const std::shared_ptr& node) { - if (!node) - return {}; - - const auto& rtInfo = node->get_rt_info(); - using FusedNamesWrapper = VariantWrapper; - - if (!rtInfo.count(FusedNamesWrapper::get_type_info_static())) - return {}; - - const auto& attr = rtInfo.at(FusedNamesWrapper::get_type_info_static()); - FusedNames fusedNames = ov::as_type_ptr(attr)->get(); - return fusedNames.getVectorNames(); + if (node) { + const auto& rtInfo = node->get_rt_info(); + auto it_info = rtInfo.find(FusedNames::get_type_info_static()); + if (it_info != rtInfo.end()) { + return it_info->second.as().getVectorNames(); + } else { + return {}; + } + } + return {}; } -template class ov::VariantImpl; - -Any VariantWrapper::merge(const ngraph::NodeVector& nodes) { +Any FusedNames::merge(const ngraph::NodeVector& nodes) const { FusedNames mergedNames; for (auto& node : nodes) { const auto& rtInfo = node->get_rt_info(); - - if (!rtInfo.count(VariantWrapper::get_type_info_static())) - continue; - - const auto attr = rtInfo.at(VariantWrapper::get_type_info_static()); - if (auto fusedNames = std::dynamic_pointer_cast>(attr)) { - mergedNames.fuseWith(fusedNames->get()); + auto it_info = rtInfo.find(FusedNames::get_type_info_static()); + if (it_info != rtInfo.end()) { + mergedNames.fuseWith(it_info->second.as()); } } - return std::make_shared>(mergedNames); + return mergedNames; } -Any VariantWrapper::init(const std::shared_ptr& node) { - return std::make_shared>(FusedNames(node->get_friendly_name())); +Any FusedNames::init(const std::shared_ptr& node) const { + return FusedNames{node->get_friendly_name()}; } -bool VariantWrapper::visit_attributes(AttributeVisitor& visitor) { - visitor.on_attribute("value", m_value.fused_names); +bool FusedNames::visit_attributes(AttributeVisitor& visitor) { + visitor.on_attribute("value", fused_names); return true; } + +std::string FusedNames::to_string() const { + return getNames(); +} diff --git a/src/core/src/pass/rt_info/primitives_priority_attribute.cpp b/src/core/src/pass/rt_info/primitives_priority_attribute.cpp index 036580253cc..f1628b531f2 100644 --- a/src/core/src/pass/rt_info/primitives_priority_attribute.cpp +++ b/src/core/src/pass/rt_info/primitives_priority_attribute.cpp @@ -18,16 +18,19 @@ using namespace ov; using namespace ngraph; std::string ov::getPrimitivesPriority(const std::shared_ptr& node) { - const auto& rtInfo = node->get_rt_info(); - - if (!rtInfo.count(PrimitivesPriority::get_type_info_static())) - return ""; - - const auto& attr = rtInfo.at(PrimitivesPriority::get_type_info_static()); - return ov::as_type_ptr(attr)->get(); + if (node) { + const auto& rtInfo = node->get_rt_info(); + auto it_info = rtInfo.find(PrimitivesPriority::get_type_info_static()); + if (it_info != rtInfo.end()) { + return it_info->second.as().value; + } else { + return {}; + } + } + return {}; } -Any PrimitivesPriority::merge(const ngraph::NodeVector& nodes) { +Any PrimitivesPriority::merge(const ngraph::NodeVector& nodes) const { auto isConvolutionBased = [](const std::shared_ptr& node) -> bool { if (std::dynamic_pointer_cast(node) || std::dynamic_pointer_cast(node) || @@ -49,21 +52,21 @@ Any PrimitivesPriority::merge(const ngraph::NodeVector& nodes) { } if (unique_pp.size() > 1) { - throw ngraph_error(std::string(get_type_info()) + " no rule defined for multiple values."); + throw ngraph_error("PrimitivesPriority no rule defined for multiple values."); } std::string final_primitives_priority; if (unique_pp.size() == 1) { final_primitives_priority = *unique_pp.begin(); } - return std::make_shared(final_primitives_priority); -} - -Any PrimitivesPriority::init(const std::shared_ptr& node) { - throw ngraph_error(std::string(get_type_info()) + " has no default initialization."); + return PrimitivesPriority(final_primitives_priority); } bool PrimitivesPriority::visit_attributes(AttributeVisitor& visitor) { - visitor.on_attribute("value", m_value); + visitor.on_attribute("value", value); return true; } + +std::string PrimitivesPriority::to_string() const { + return value; +} diff --git a/src/core/src/pass/serialize.cpp b/src/core/src/pass/serialize.cpp index b1dc8049364..e95b7000702 100644 --- a/src/core/src/pass/serialize.cpp +++ b/src/core/src/pass/serialize.cpp @@ -20,6 +20,7 @@ #include "openvino/pass/constant_folding.hpp" #include "pugixml.hpp" #include "transformations/hash.hpp" +#include "transformations/rt_info/primitives_priority_attribute.hpp" using namespace ngraph; @@ -139,20 +140,14 @@ public: for (const auto& rt_info_name : list_of_names) { const auto& found_rt_info = rt_info.find(rt_info_name); if (found_rt_info != rt_info.end()) { - xml_node_append_attribute(rt_info_name, found_rt_info->second); + std::stringstream strm; + found_rt_info->second.print(strm); + m_xml_node.append_attribute(rt_info_name.c_str()).set_value(strm.str().c_str()); } } } private: - template - void xml_node_append_attribute(const std::string& name, const std::shared_ptr& variant) { - if (auto v = std::dynamic_pointer_cast>(variant)) { - const auto& value = v->get(); - m_xml_node.append_attribute(name.c_str()).set_value(value.c_str()); - } - } - pugi::xml_node& m_xml_node; }; @@ -880,22 +875,23 @@ void ngfunction_2_ir(pugi::xml_node& netXml, // general attributes pugi::xml_node data = layer.append_child("data"); - auto append_runtime_info = [](pugi::xml_node& node, const RTMap& attributes) { + auto append_runtime_info = [](pugi::xml_node& node, RTMap& attributes) { pugi::xml_node rt_node = node.append_child("rt_info"); bool has_attrs = false; - for (const auto& item : attributes) { - auto attribute_node = rt_node.append_child("attribute"); - OPENVINO_SUPPRESS_DEPRECATED_START - attribute_node.append_attribute("name").set_value(item.second->get_type_info().name); - attribute_node.append_attribute("version").set_value( - item.second->get_type_info().get_version().c_str()); - rt_info::RTInfoSerializer serializer(attribute_node); - if (!item.second->visit_attributes(serializer)) { - rt_node.remove_child(attribute_node); - } else { - has_attrs = true; + for (auto& item : attributes) { + if (item.second.is()) { + auto attribute_node = rt_node.append_child("attribute"); + auto& rt_attribute = item.second.as(); + const auto& type_info = rt_attribute.get_type_info(); + attribute_node.append_attribute("name").set_value(type_info.name); + attribute_node.append_attribute("version").set_value(type_info.get_version().c_str()); + rt_info::RTInfoSerializer serializer(attribute_node); + if (!rt_attribute.visit_attributes(serializer)) { + rt_node.remove_child(attribute_node); + } else { + has_attrs = true; + } } - OPENVINO_SUPPRESS_DEPRECATED_END } if (!has_attrs) { node.remove_child(rt_node); @@ -910,7 +906,7 @@ void ngfunction_2_ir(pugi::xml_node& netXml, // if (node->get_input_size() > 0) { pugi::xml_node input = layer.append_child("input"); - for (const auto& i : node->inputs()) { + for (auto& i : node->inputs()) { // WA for LSTMCellv0, peephole input shall not be serialized if (i.get_index() == 6 && dynamic_cast(node)) { port_id++; @@ -940,7 +936,7 @@ void ngfunction_2_ir(pugi::xml_node& netXml, // if ((node->get_output_size() > 0) && !ngraph::op::is_output(node)) { pugi::xml_node output = layer.append_child("output"); - for (const auto& o : node->outputs()) { + for (auto& o : node->outputs()) { pugi::xml_node port = output.append_child("port"); port.append_attribute("id").set_value(port_id++); port.append_attribute("precision").set_value(get_precision_name(o.get_element_type()).c_str()); diff --git a/src/core/src/pass/visualize_tree.cpp b/src/core/src/pass/visualize_tree.cpp index 7f69d491055..2127d7250ec 100644 --- a/src/core/src/pass/visualize_tree.cpp +++ b/src/core/src/pass/visualize_tree.cpp @@ -161,11 +161,17 @@ static std::string get_attribute_values(const std::map& at bool first = true; for (const auto& item : attributes) { ss << (first ? " " : delimiter) << item.first; - OPENVINO_SUPPRESS_DEPRECATED_START - const auto attributeValue = item.second == nullptr ? "[EMPTY]" : item.second->to_string(); - OPENVINO_SUPPRESS_DEPRECATED_END - if (!attributeValue.empty()) - ss << "{" << attributeValue << "}"; + if (item.second.is()) { + ss << "{" << item.second.as().to_string() << "}"; + } else if (!item.second.empty()) { + ss << "{"; + item.second.print(ss); + ss << "}"; + } else { + ss << "{" + << "[EMPTY]" + << "}"; + } first = false; } diff --git a/src/core/src/preprocess/pre_post_process.cpp b/src/core/src/preprocess/pre_post_process.cpp index bdcae913e7d..07bb0cec76c 100644 --- a/src/core/src/preprocess/pre_post_process.cpp +++ b/src/core/src/preprocess/pre_post_process.cpp @@ -442,7 +442,7 @@ std::shared_ptr PrePostProcessor::build() { plane_param->output(0).get_rt_info().erase(TensorInfoMemoryType::get_type_info_static()); } else { plane_param->output(0).get_rt_info()[TensorInfoMemoryType::get_type_info_static()] = - std::make_shared(input->get_tensor_data()->get_memory_type()); + TensorInfoMemoryType(input->get_tensor_data()->get_memory_type()); } } new_params.push_back(plane_param); diff --git a/src/core/src/rt_info.cpp b/src/core/src/rt_info.cpp index eaed0197af7..be62a3eeb7e 100644 --- a/src/core/src/rt_info.cpp +++ b/src/core/src/rt_info.cpp @@ -11,10 +11,13 @@ namespace { ngraph::Node::RTMap mergeRuntimeInfo(const ngraph::NodeVector& nodes) { std::unordered_map> attrs; - OPENVINO_SUPPRESS_DEPRECATED_START for (const auto& node : nodes) { for (const auto& item : node->get_rt_info()) { - if (item.second->is_copyable() && item.first != "opset") { + bool copy = item.first != "opset"; + if (item.second.is()) { + copy &= item.second.as().is_copyable(); + } + if (copy) { attrs[item.first].push_back(item.second); } } @@ -26,18 +29,19 @@ ngraph::Node::RTMap mergeRuntimeInfo(const ngraph::NodeVector& nodes) { if (item.second.size() == 1) { merged_attrs[item.first] = attr; } else { - auto merge_attr = attr->merge(nodes); - if (!merge_attr.empty()) { - merged_attrs[item.first] = merge_attr; + if (attr.is()) { + auto merge_attr = attr.as().merge(nodes); + if (!merge_attr.empty()) { + merged_attrs[item.first] = merge_attr; + } } } } - OPENVINO_SUPPRESS_DEPRECATED_END return merged_attrs; } -std::shared_ptr get_opset(const ngraph::Node::RTMap& rt_info) { +ov::Any get_opset(const ngraph::Node::RTMap& rt_info) { auto it = rt_info.find("opset"); if (it != rt_info.end()) { return it->second; @@ -48,7 +52,7 @@ std::shared_ptr get_opset(const ngraph::Node::RTMap& rt_info) { void assign_runtime_info(const ngraph::Node::RTMap& from, ngraph::Node::RTMap& to) { auto opset = get_opset(to); to = from; - if (opset) { + if (!opset.empty()) { to["opset"] = opset; } } @@ -61,14 +65,16 @@ void ngraph::copy_runtime_info(std::shared_ptr from, std::shared_p attrs.clear(); for (const auto& item : from->get_rt_info()) { - OPENVINO_SUPPRESS_DEPRECATED_START - if (item.second->is_copyable() && item.first != "opset") { + bool copy = item.first != "opset"; + if (item.second.is()) { + copy &= item.second.as().is_copyable(); + } + if (copy) { attrs[item.first] = item.second; } - OPENVINO_SUPPRESS_DEPRECATED_END } - if (opset) { + if (!opset.empty()) { attrs["opset"] = opset; } } diff --git a/src/core/src/runtime_attribute.cpp b/src/core/src/runtime_attribute.cpp new file mode 100644 index 00000000000..f639c0c6017 --- /dev/null +++ b/src/core/src/runtime_attribute.cpp @@ -0,0 +1,39 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "openvino/core/runtime_attribute.hpp" + +#include "ngraph/node.hpp" +#include "openvino/core/attribute_visitor.hpp" + +namespace ov { + +std::string RuntimeAttribute::to_string() const { + return {}; +} +bool RuntimeAttribute::visit_attributes(AttributeVisitor&) { + return false; +} + +Any RuntimeAttribute::init(const std::shared_ptr& node) const { + return {}; +} + +Any RuntimeAttribute::merge(const ngraph::NodeVector& nodes) const { + return {}; +} + +bool RuntimeAttribute::is_copyable() const { + return true; +} + +std::ostream& operator<<(std::ostream& os, const RuntimeAttribute& attrubute) { + return os << attrubute.to_string(); +} + +template class ov::RuntimeAttributeImpl; +template class ov::RuntimeAttributeImpl; +template class ov::RuntimeAttributeImpl; + +} // namespace ov \ No newline at end of file diff --git a/src/core/src/shared_node_info.hpp b/src/core/src/shared_node_info.hpp index c14857c0693..eef60f20940 100644 --- a/src/core/src/shared_node_info.hpp +++ b/src/core/src/shared_node_info.hpp @@ -7,7 +7,6 @@ #include #include #include -#include namespace ov { class SharedRTInfo { diff --git a/src/core/src/validation_util.cpp b/src/core/src/validation_util.cpp index 244be50b167..cb62ec2fc44 100644 --- a/src/core/src/validation_util.cpp +++ b/src/core/src/validation_util.cpp @@ -1212,8 +1212,15 @@ void propagate_rt_info(Node* node, const Output& final_port) { auto& rt_info = consumer->get_rt_info(); for (const auto& it : orig_rt_info) { - if (rt_info.find(it.first) == rt_info.end() && it.second->is_copyable()) - rt_info[it.first] = it.second; + if (rt_info.find(it.first) == rt_info.end()) { + bool copy = true; + if (it.second.is()) { + copy = it.second.as().is_copyable(); + } + if (copy) { + rt_info[it.first] = it.second; + } + } } } } diff --git a/src/core/src/variant.cpp b/src/core/src/variant.cpp deleted file mode 100644 index 4e3c73bfcf4..00000000000 --- a/src/core/src/variant.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "ngraph/variant.hpp" - -#include "ngraph/node.hpp" -#include "openvino/core/any.hpp" -#include "openvino/core/attribute_visitor.hpp" - -using namespace ngraph; - -Variant::~Variant() = default; - -ov::Any Variant::init(const std::shared_ptr& node) { - return {}; -} - -ov::Any Variant::merge(const ngraph::NodeVector& nodes) { - return {}; -} - -bool Variant::is_copyable() const { - return true; -} - -template class ngraph::VariantImpl; -template class ngraph::VariantImpl; -template class ngraph::VariantImpl; diff --git a/src/core/tests/any.cpp b/src/core/tests/any.cpp index 47428262111..00747e0b868 100644 --- a/src/core/tests/any.cpp +++ b/src/core/tests/any.cpp @@ -7,12 +7,14 @@ #include #include "gtest/gtest.h" -#include "openvino/core/variant.hpp" +#include "openvino/core/runtime_attribute.hpp" using namespace ov; class DestructorTest { public: + // Base member type defined. ov:Any can access all derived class + using Base = std::tuple; DestructorTest() { constructorCount++; } @@ -29,9 +31,22 @@ public: destructorCount++; } + virtual const std::type_info& type_info() const { + return typeid(DestructorTest); + } + static size_t destructorCount; static size_t constructorCount; }; + +class Derived : public DestructorTest { +public: + using DestructorTest::DestructorTest; + const std::type_info& type_info() const override { + return typeid(Derived); + } +}; + size_t DestructorTest::destructorCount = 0; size_t DestructorTest::constructorCount = 0; @@ -392,55 +407,87 @@ TEST_F(AnyTests, PrintToMapOfAnysDoesNothing) { ASSERT_EQ(stream.str(), std::string{}); } -TEST_F(AnyTests, constructFromVariantImpl) { +TEST_F(AnyTests, constructFromRuntimeAttributeImpl) { auto parameter = Any{4}; auto get_impl = [&] { - return std::make_shared>(); + return std::make_shared>(); }; auto other_parameter = Any{get_impl()}; } -TEST_F(AnyTests, dynamicPointerCastToVariant) { - Any p = std::make_shared>("42"); - auto str_variant = std::dynamic_pointer_cast>(p); +TEST_F(AnyTests, dynamicPointerCastToRuntimeAttribute) { + Any p = std::make_shared>("42"); + auto str_variant = std::dynamic_pointer_cast>(p); ASSERT_EQ("42", str_variant->get()); } -TEST_F(AnyTests, asTypePtrToVariant) { - Any p = std::make_shared>("42"); - auto str_variant = ov::as_type_ptr>(p); +TEST_F(AnyTests, asTypePtrToRuntimeAttribute) { + Any p = std::make_shared>("42"); + auto str_variant = ov::as_type_ptr>(p); ASSERT_EQ("42", str_variant->get()); } -TEST_F(AnyTests, castToVariant) { +TEST_F(AnyTests, castToRuntimeAttribute) { { - Any p = std::make_shared>("42"); - std::shared_ptr> str_variant = p; + Any p = std::make_shared>("42"); + std::shared_ptr> str_variant = p; ASSERT_EQ("42", str_variant->get()); } { - Any p = std::make_shared>("42"); - auto f = [](const std::shared_ptr>& str_variant) { - ASSERT_NE(nullptr, str_variant); + Any p = std::make_shared>("42"); + auto f = [](const std::shared_ptr>& str_variant) { ASSERT_EQ("42", str_variant->get()); }; f(p); } { - Any p = std::make_shared>("42"); - auto f = [](std::shared_ptr>& str_variant) { - ASSERT_NE(nullptr, str_variant); + Any p = std::make_shared>("42"); + auto f = [](std::shared_ptr>& str_variant) { ASSERT_EQ("42", str_variant->get()); }; f(p); } { - std::shared_ptr v = std::make_shared>("42"); + std::shared_ptr v = std::make_shared>("42"); Any p = v; - auto f = [](std::shared_ptr>& str_variant) { + auto f = [](std::shared_ptr>& str_variant) { ASSERT_NE(nullptr, str_variant); ASSERT_EQ("42", str_variant->get()); }; f(p); } } + +TEST_F(AnyTests, accessUsingBaseReference) { + ASSERT_EQ(0, DestructorTest::constructorCount); + ASSERT_EQ(0, DestructorTest::destructorCount); + { + using Base = DestructorTest; + auto p = Any::make(); + ASSERT_TRUE(p.is()); + ASSERT_TRUE(p.is()); + ASSERT_NO_THROW(p.as()); + ASSERT_NO_THROW(p.as()); + ASSERT_EQ(typeid(Derived), p.as().type_info()); + } + ASSERT_EQ(1, DestructorTest::constructorCount); + ASSERT_EQ(1, DestructorTest::destructorCount); +} + +struct WrongBase { + // No Base member type defined + // Should be: using Base = std::tuple; +}; + +struct WrongDerived : public WrongBase { + // No Base member type defined + // Should be: using Base = std::tuple; +}; + +TEST_F(AnyTests, accessUsingWrongBaseReference) { + Any p = WrongDerived{}; + ASSERT_TRUE(p.is()); + ASSERT_FALSE(p.is()); + ASSERT_NO_THROW(p.as()); + ASSERT_THROW(p.as(), ov::Exception); +} diff --git a/src/core/tests/constant_folding.cpp b/src/core/tests/constant_folding.cpp index ba6c894b130..3452e4b062b 100644 --- a/src/core/tests/constant_folding.cpp +++ b/src/core/tests/constant_folding.cpp @@ -3177,7 +3177,7 @@ TEST(constant_folding, disable_constant_folding) { auto constant_shape = op::Constant::create(element::i64, Shape{1}, {3}); auto dyn_reshape = make_shared(input, constant_shape, true); auto& rt_info = dyn_reshape->get_rt_info(); - rt_info["disabled_constant_folding_0"]; + rt_info[ov::pass::DisableConstantFolding::get_type_info_static()]; auto f = make_shared(dyn_reshape, ParameterVector{input}); pass::Manager pass_manager; diff --git a/src/core/tests/frontend/shared/include/op_fuzzy.hpp b/src/core/tests/frontend/shared/include/op_fuzzy.hpp index ca345622152..92b3e23add3 100644 --- a/src/core/tests/frontend/shared/include/op_fuzzy.hpp +++ b/src/core/tests/frontend/shared/include/op_fuzzy.hpp @@ -30,5 +30,5 @@ protected: void doLoadFromFile(); - void runConvertedModel(const std::shared_ptr function, const std::string& model_file); + void runConvertedModel(const std::shared_ptr function, const std::string& model_file); }; diff --git a/src/core/tests/frontend/shared/src/load_from.cpp b/src/core/tests/frontend/shared/src/load_from.cpp index bbd371f5592..6050809e7b4 100644 --- a/src/core/tests/frontend/shared/src/load_from.cpp +++ b/src/core/tests/frontend/shared/src/load_from.cpp @@ -6,7 +6,7 @@ #include -#include "openvino/core/variant.hpp" +#include "openvino/core/runtime_attribute.hpp" #include "utils.hpp" using namespace ngraph; @@ -47,8 +47,8 @@ TEST_P(FrontEndLoadFromTest, testLoadFromFilePathWithExplicitVariants) { FrontEnd::Ptr fe; ASSERT_NO_THROW(frontends = m_fem.get_available_front_ends()); - std::vector> variants; - variants.emplace_back(ov::make_variant(model_path)); + std::vector variants; + variants.emplace_back(model_path); ASSERT_NO_THROW(m_frontEnd = m_fem.load_by_model(variants)); ASSERT_NE(m_frontEnd, nullptr); diff --git a/src/core/tests/op.cpp b/src/core/tests/op.cpp index 898e83315b9..c3294ee9244 100644 --- a/src/core/tests/op.cpp +++ b/src/core/tests/op.cpp @@ -62,60 +62,3 @@ TEST(op, opset_multi_thread) { doTest(ngraph::get_opset6); doTest(ngraph::get_opset7); } - -struct Ship { - std::string name; - int16_t x; - int16_t y; -}; - -namespace ov { -template <> -class VariantWrapper : public VariantImpl { -public: - OPENVINO_RTTI("VariantWrapper"); - VariantWrapper(const value_type& value) : VariantImpl(value) {} -}; - -} // namespace ov - -TEST(op, variant) { - shared_ptr var_std_string = make_variant("My string"); - ASSERT_TRUE((ov::is_type>(var_std_string))); - EXPECT_EQ((ov::as_type_ptr>(var_std_string)->get()), "My string"); - - shared_ptr var_int64_t = make_variant(27); - ASSERT_TRUE((ov::is_type>(var_int64_t))); - EXPECT_FALSE((ov::is_type>(var_int64_t))); - EXPECT_EQ((ov::as_type_ptr>(var_int64_t)->get()), 27); - - shared_ptr var_ship = make_variant(Ship{"Lollipop", 3, 4}); - ASSERT_TRUE((ov::is_type>(var_ship))); - Ship& ship = ov::as_type_ptr>(var_ship)->get(); - EXPECT_EQ(ship.name, "Lollipop"); - EXPECT_EQ(ship.x, 3); - EXPECT_EQ(ship.y, 4); - - auto node = make_shared(element::f32, Shape{1}); - // Check Node RTInfo - node->get_rt_info()["A"] = var_ship; - auto node_var_ship = node->get_rt_info().at("A"); - ASSERT_TRUE((ov::is_type>(node_var_ship))); - Ship& node_ship = ov::as_type_ptr>(node_var_ship)->get(); - EXPECT_EQ(&node_ship, &ship); - - // Check Node Input RTInfo - auto relu = make_shared(node); - relu->input(0).get_rt_info()["A"] = var_ship; - auto node_input_var_ship = node->get_rt_info().at("A"); - ASSERT_TRUE((ov::is_type>(node_input_var_ship))); - Ship& node_input_ship = ov::as_type_ptr>(node_input_var_ship)->get(); - EXPECT_EQ(&node_input_ship, &ship); - - // Check Node Input RTInfo - node->output(0).get_rt_info()["A"] = var_ship; - auto node_output_var_ship = node->get_rt_info().at("A"); - ASSERT_TRUE((ov::is_type>(node_output_var_ship))); - Ship& node_output_ship = ov::as_type_ptr>(node_input_var_ship)->get(); - EXPECT_EQ(&node_output_ship, &ship); -} diff --git a/src/core/tests/op_eval/memory.cpp b/src/core/tests/op_eval/memory.cpp index 68ac1bfd115..e4b7f41fe41 100644 --- a/src/core/tests/op_eval/memory.cpp +++ b/src/core/tests/op_eval/memory.cpp @@ -85,7 +85,7 @@ TEST(op_eval, assign_readvalue_evaluation_context) { HostTensorPtr h_tensor = make_host_tensor(Shape{3}, inputs); VariableContext variable_context; variable_context.set_variable_value(variables[0], std::make_shared(h_tensor)); - eval_context["VariableContext"] = std::make_shared>(variable_context); + eval_context.emplace("VariableContext", variable_context); const int COUNT_RUNS = 10; for (int i = 0; i < COUNT_RUNS; ++i) { @@ -106,10 +106,10 @@ TEST(op_eval, assign_readvalue_add) { // creating context EvaluationContext eval_context; - auto variable_context = std::make_shared>(VariableContext()); + auto variable_context = VariableContext(); auto variable_value = make_shared(make_host_tensor(Shape{3}, inputs)); - variable_context->get().set_variable_value(variables[0], variable_value); - eval_context["VariableContext"] = variable_context; + variable_context.set_variable_value(variables[0], variable_value); + eval_context.emplace("VariableContext", variable_context); auto result = make_shared(); const int COUNT_RUNS = 10; @@ -134,11 +134,11 @@ TEST(op_eval, assign_readvalue_reset_before_evaluate) { // creating context EvaluationContext eval_context; - auto variable_context = std::make_shared>(VariableContext()); + auto variable_context = VariableContext(); auto variable_value = make_shared(make_host_tensor(Shape{3}, inputs)); variable_value->set_reset(false); - variable_context->get().set_variable_value(variables[0], variable_value); - eval_context["VariableContext"] = variable_context; + variable_context.set_variable_value(variables[0], variable_value); + eval_context.emplace("VariableContext", variable_context); auto result = make_shared(); const int COUNT_RUNS = 10; @@ -162,10 +162,10 @@ TEST(op_eval, assign_readvalue_add_reset) { // creating a Context EvaluationContext eval_context; - auto variable_context = std::make_shared>(VariableContext()); + auto variable_context = VariableContext(); auto variable_value = make_shared(make_host_tensor(Shape{3}, inputs)); - variable_context->get().set_variable_value(variables[0], variable_value); - eval_context["VariableContext"] = variable_context; + variable_context.set_variable_value(variables[0], variable_value); + eval_context.emplace("VariableContext", variable_context); auto result = make_shared(); const int COUNT_RUNS = 10; @@ -182,9 +182,7 @@ TEST(op_eval, assign_readvalue_add_reset) { const auto& found_context = eval_context.find("VariableContext"); EXPECT_NE(found_context, eval_context.end()); - auto var_context = std::dynamic_pointer_cast>(found_context->second); - EXPECT_NE(var_context, nullptr); - variable_context->get().reset_variable_context(); + found_context->second.as().reset_variable_context(); for (int i = 0; i < COUNT_RUNS; ++i) { ASSERT_TRUE(fun->evaluate({result}, {make_host_tensor(Shape{3}, inputs)}, eval_context)); @@ -206,10 +204,10 @@ TEST(op_eval, assign_readvalue_add_modify) { // creating context EvaluationContext eval_context; - auto variable_context = std::make_shared>(VariableContext()); + auto variable_context = VariableContext(); auto variable_value = make_shared(make_host_tensor(Shape{3}, inputs)); - variable_context->get().set_variable_value(variables[0], variable_value); - eval_context["VariableContext"] = variable_context; + variable_context.set_variable_value(variables[0], variable_value); + eval_context.emplace("VariableContext", variable_context); auto result = make_shared(); const int COUNT_RUNS = 10; @@ -225,9 +223,7 @@ TEST(op_eval, assign_readvalue_add_modify) { const auto& found_context = eval_context.find("VariableContext"); EXPECT_NE(found_context, eval_context.end()); - auto var_context = std::dynamic_pointer_cast>(found_context->second); - EXPECT_NE(var_context, nullptr); - const auto& var_value = variable_context->get().get_variable_value(variables[0]); + const auto& var_value = found_context->second.as().get_variable_value(variables[0]); EXPECT_NE(var_value, nullptr); var_value->set_value(make_host_tensor(Shape{3}, {1, 2, 3})); @@ -253,14 +249,14 @@ TEST(op_eval, assign_readvalue_add_modify_multi_variables) { // creating context EvaluationContext eval_context; - auto variable_context = std::make_shared>(VariableContext()); + auto variable_context = VariableContext(); auto variable_value_1 = make_shared(make_host_tensor(Shape{3}, inputs_1)); auto variable_value_2 = make_shared(make_host_tensor(Shape{3}, inputs_2)); variable_value_1->set_reset(false); variable_value_2->set_reset(false); - variable_context->get().set_variable_value(var_1, variable_value_1); - variable_context->get().set_variable_value(var_2, variable_value_2); - eval_context["VariableContext"] = variable_context; + variable_context.set_variable_value(var_1, variable_value_1); + variable_context.set_variable_value(var_2, variable_value_2); + eval_context.emplace("VariableContext", variable_context); auto result = make_shared(); const int COUNT_RUNS = 10; @@ -279,14 +275,13 @@ TEST(op_eval, assign_readvalue_add_modify_multi_variables) { const auto& found_context = eval_context.find("VariableContext"); EXPECT_NE(found_context, eval_context.end()); - auto var_context = std::dynamic_pointer_cast>(found_context->second); - EXPECT_NE(var_context, nullptr); + auto var_context = found_context->second.as(); - auto var_value = variable_context->get().get_variable_value(var_1); + auto var_value = variable_context.get_variable_value(var_1); EXPECT_NE(var_value, nullptr); var_value->set_value(make_host_tensor(Shape{3}, {1, 2, 3})); - auto var_value_2 = variable_context->get().get_variable_value(var_2); + auto var_value_2 = variable_context.get_variable_value(var_2); EXPECT_NE(var_value_2, nullptr); var_value_2->set_reset(true); diff --git a/src/core/tests/pass/serialization/read_ir.hpp b/src/core/tests/pass/serialization/read_ir.hpp index 6e502845d39..e28d39e1e5a 100644 --- a/src/core/tests/pass/serialization/read_ir.hpp +++ b/src/core/tests/pass/serialization/read_ir.hpp @@ -16,9 +16,9 @@ inline std::shared_ptr readModel(const std::string& model_path, co ov::frontend::FrontEnd::Ptr FE; ov::frontend::InputModel::Ptr inputModel; - ov::VariantVector params{ov::make_variant(model_path)}; + ov::RuntimeAttributeVector params{model_path}; if (!weights_path.empty()) - params.emplace_back(ov::make_variant(weights_path)); + params.emplace_back(weights_path); FE = manager.load_by_model(params); if (FE) @@ -37,7 +37,7 @@ inline std::shared_ptr readModel(const std::string& model) { std::istringstream modelStringStream(model); std::istream& modelStream = modelStringStream; - ov::VariantVector params{ov::make_variant(&modelStream)}; + ov::RuntimeAttributeVector params{&modelStream}; FE = manager.load_by_model(params); if (FE) diff --git a/src/core/tests/preprocess.cpp b/src/core/tests/preprocess.cpp index 7227b3a2c05..19e407acc77 100644 --- a/src/core/tests/preprocess.cpp +++ b/src/core/tests/preprocess.cpp @@ -889,20 +889,20 @@ TEST(pre_post_process, preprocess_reverse_channels_no_c_dim) { TEST(pre_post_process, preprocess_preserve_rt_info) { auto f = create_simple_function(element::f32, Shape{1, 3, 2, 2}); - f->get_parameters()[0]->get_rt_info()["someKey"] = ov::make_variant("someValue"); - f->input().get_rt_info()["someKey_in"] = ov::make_variant("someValue_in"); + f->get_parameters()[0]->get_rt_info()["someKey"] = "someValue"; + f->input().get_rt_info()["someKey_in"] = "someValue_in"; auto p = PrePostProcessor(f); p.input().tensor().set_element_type(element::u8); f = p.build(); EXPECT_EQ(f->input().get_element_type(), element::u8); ASSERT_EQ(f->get_parameters()[0]->get_rt_info().count("someKey"), 1); - auto var0 = std::dynamic_pointer_cast>(f->get_parameters()[0]->get_rt_info()["someKey"]); - EXPECT_EQ(var0->get(), "someValue"); + auto var0 = f->get_parameters()[0]->get_rt_info()["someKey"].as(); + EXPECT_EQ(var0, "someValue"); ASSERT_EQ(f->input().get_rt_info().count("someKey_in"), 1); - auto var0_in = std::dynamic_pointer_cast>(f->input().get_rt_info()["someKey_in"]); - EXPECT_EQ(var0_in->get(), "someValue_in"); + auto var0_in = f->input().get_rt_info()["someKey_in"].as(); + EXPECT_EQ(var0_in, "someValue_in"); } TEST(pre_post_process, preprocess_memory_type) { @@ -911,14 +911,13 @@ TEST(pre_post_process, preprocess_memory_type) { p.input().tensor().set_memory_type("abc"); f = p.build(); ASSERT_EQ(f->input().get_rt_info().count(TensorInfoMemoryType::get_type_info_static()), 1); - auto var0 = std::dynamic_pointer_cast( - f->input().get_rt_info()[TensorInfoMemoryType::get_type_info_static()]); - EXPECT_EQ(var0->get(), "abc"); + auto var0 = f->input().get_rt_info()[TensorInfoMemoryType::get_type_info_static()].as().value; + EXPECT_EQ(var0, "abc"); } TEST(pre_post_process, preprocess_memory_type_clear) { auto f = create_simple_function(element::f32, Shape{1, 3, 2, 2}); - f->input().get_rt_info()[TensorInfoMemoryType::get_type_info_static()] = ov::make_variant("abc"); + f->input().get_rt_info()[TensorInfoMemoryType::get_type_info_static()] = TensorInfoMemoryType("abc"); auto p = PrePostProcessor(f); p.input().tensor().set_memory_type(""); f = p.build(); @@ -932,9 +931,8 @@ TEST(pre_post_process, preprocess_memory_type_not_cleared) { f = p.build(); ASSERT_EQ(f->input().get_rt_info().count(TensorInfoMemoryType::get_type_info_static()), 1); - auto var0 = std::dynamic_pointer_cast( - f->input().get_rt_info()[TensorInfoMemoryType::get_type_info_static()]); - EXPECT_EQ(var0->get(), "abc"); + auto var0 = f->input().get_rt_info()[TensorInfoMemoryType::get_type_info_static()].as().value; + EXPECT_EQ(var0, "abc"); } // --- PostProcess - set/convert element type --- diff --git a/src/core/tests/type_prop/parameter.cpp b/src/core/tests/type_prop/parameter.cpp index cc9e11a6828..27ef12b1037 100644 --- a/src/core/tests/type_prop/parameter.cpp +++ b/src/core/tests/type_prop/parameter.cpp @@ -47,7 +47,6 @@ TEST(type_prop, param_layout_empty) { TEST(type_prop, param_layout_invalid) { auto a = make_shared(element::f32, PartialShape::dynamic()); - a->get_output_tensor(0).get_rt_info()[ov::LayoutAttribute::get_type_info_static()] = - ov::make_variant("NCHW"); // incorrect way - ASSERT_THROW(a->get_layout(), ov::AssertFailure); + a->get_output_tensor(0).get_rt_info()[ov::LayoutAttribute::get_type_info_static()] = "NCHW"; // incorrect way + ASSERT_THROW(a->get_layout(), ov::Exception); } diff --git a/src/core/tests/type_prop/result.cpp b/src/core/tests/type_prop/result.cpp index 85c343d3592..6966c9f1997 100644 --- a/src/core/tests/type_prop/result.cpp +++ b/src/core/tests/type_prop/result.cpp @@ -48,7 +48,6 @@ TEST(type_prop, result_layout_empty) { TEST(type_prop, result_layout_invalid) { auto a = make_shared(element::f32, PartialShape::dynamic()); auto result = make_shared(a); - result->input(0).get_rt_info()[ov::LayoutAttribute::get_type_info_static()] = - ov::make_variant("NCHW"); // incorrect way - ASSERT_THROW(result->get_layout(), ov::AssertFailure); + result->input(0).get_rt_info()[ov::LayoutAttribute::get_type_info_static()] = "NCHW"; // incorrect way + ASSERT_THROW(result->get_layout(), ov::Exception); } diff --git a/src/core/tests/util/graph_comparator.cpp b/src/core/tests/util/graph_comparator.cpp index c529f2d1d84..8b99adb226a 100644 --- a/src/core/tests/util/graph_comparator.cpp +++ b/src/core/tests/util/graph_comparator.cpp @@ -43,7 +43,6 @@ bool compare_rt_keys(const Node& node1, const Node& node2) { // The "opset" parameter in RT info is optional // and mandatory only for TypeRelaxed operations. // Therefore, we ignore this key when comparing RT keys. - const auto& first_node_rt_info = node1->get_rt_info(); const auto& second_node_rt_info = node2->get_rt_info(); @@ -51,6 +50,10 @@ bool compare_rt_keys(const Node& node1, const Node& node2) { auto second_node_rt_info_it = second_node_rt_info.begin(); while (first_node_rt_info_it != first_node_rt_info.end() && second_node_rt_info_it != second_node_rt_info.end()) { + std::stringstream strm; + first_node_rt_info_it->second.print(strm); + strm << " "; + second_node_rt_info_it->second.print(strm); bool is_continue = false; if (first_node_rt_info_it->first == "opset") { ++first_node_rt_info_it; diff --git a/src/frontends/common/include/common/frontend.hpp b/src/frontends/common/include/common/frontend.hpp index 4dba69f4c2e..58ad1d66f64 100644 --- a/src/frontends/common/include/common/frontend.hpp +++ b/src/frontends/common/include/common/frontend.hpp @@ -10,10 +10,10 @@ #include "frontend_defs.hpp" #include "input_model.hpp" +#include "openvino/core/any.hpp" #include "openvino/core/extension.hpp" #include "openvino/core/function.hpp" #include "openvino/core/op_extension.hpp" -#include "openvino/core/variant.hpp" namespace ov { namespace frontend { @@ -36,7 +36,7 @@ public: /// \return true if model recognized, false - otherwise. template inline bool supported(const Types&... vars) const { - return supported_impl({ov::make_variant(vars)...}); + return supported_impl({ov::Any(vars)...}); } /// \brief Loads an input model by any specified arguments. Each FrontEnd separately @@ -48,10 +48,10 @@ public: /// \return Loaded input model. template inline InputModel::Ptr load(const Types&... vars) const { - return load_impl({ov::make_variant(vars)...}); + return load_impl({ov::Any{vars}...}); } - inline InputModel::Ptr load(const ov::VariantVector& vars) const { + inline InputModel::Ptr load(const ov::RuntimeAttributeVector& vars) const { return load_impl(vars); } @@ -125,12 +125,12 @@ public: } protected: - virtual bool supported_impl(const std::vector>& variants) const; - virtual InputModel::Ptr load_impl(const std::vector>& variants) const; + virtual bool supported_impl(const std::vector& variants) const; + virtual InputModel::Ptr load_impl(const std::vector& variants) const; }; template <> -inline bool FrontEnd::supported(const std::vector>& variants) const { +inline bool FrontEnd::supported(const std::vector& variants) const { return supported_impl(variants); } diff --git a/src/frontends/common/include/common/parameters.hpp b/src/frontends/common/include/common/parameters.hpp deleted file mode 100644 index f825a63de47..00000000000 --- a/src/frontends/common/include/common/parameters.hpp +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include - -#include "frontend_defs.hpp" -#include "ngraph/opsets/opset.hpp" -#include "openvino/core/rtti.hpp" -#include "openvino/core/variant.hpp" -#include "openvino/op/constant.hpp" - -namespace ov { - -template <> -class FRONTEND_API VariantWrapper : public VariantImpl { -public: - OPENVINO_RTTI("Variant::std::istream*"); - BWDCMP_RTTI_DECLARATION; - - VariantWrapper(const value_type& value) : VariantImpl(value) {} -}; - -template <> -class FRONTEND_API VariantWrapper : public VariantImpl { -public: - OPENVINO_RTTI("Variant::std::istringstream*"); - BWDCMP_RTTI_DECLARATION; - - VariantWrapper(const value_type& value) : VariantImpl(value) {} -}; - -#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) -template <> -class FRONTEND_API VariantWrapper : public VariantImpl { -public: - OPENVINO_RTTI("Variant::std::wstring"); - BWDCMP_RTTI_DECLARATION; - - VariantWrapper(const value_type& value) : VariantImpl(value) {} -}; -#endif - -using Weights = std::shared_ptr; - -template <> -class FRONTEND_API VariantWrapper : public VariantImpl { -public: - OPENVINO_RTTI("Variant::Weights"); - BWDCMP_RTTI_DECLARATION; - - VariantWrapper(const value_type& value) : VariantImpl(value) {} -}; - -using Extensions = std::map; - -template <> -class FRONTEND_API VariantWrapper : public VariantImpl { -public: - OPENVINO_RTTI("Variant::Extensions"); - BWDCMP_RTTI_DECLARATION; - - VariantWrapper(const value_type& value) : VariantImpl(value) {} -}; - -} // namespace ov diff --git a/src/frontends/common/include/manager.hpp b/src/frontends/common/include/manager.hpp index 5fed6c6d284..b79fc89ba2c 100644 --- a/src/frontends/common/include/manager.hpp +++ b/src/frontends/common/include/manager.hpp @@ -10,8 +10,7 @@ #include "common/frontend.hpp" #include "common/frontend_defs.hpp" -#include "common/parameters.hpp" -#include "openvino/core/variant.hpp" +#include "openvino/core/any.hpp" namespace ov { namespace frontend { @@ -56,7 +55,7 @@ public: /// if no suitable frontend is found template FrontEnd::Ptr load_by_model(const Types&... vars) { - return load_by_model_impl({make_variant(vars)...}); + return load_by_model_impl({ov::Any{vars}...}); } /// \brief Gets list of registered frontends. Any not loaded frontends will be loaded by this call @@ -73,13 +72,13 @@ public: private: class Impl; - FrontEnd::Ptr load_by_model_impl(const std::vector>& variants); + FrontEnd::Ptr load_by_model_impl(const std::vector& variants); std::unique_ptr m_impl; }; template <> -FRONTEND_API FrontEnd::Ptr FrontEndManager::load_by_model(const std::vector>& variants); +FRONTEND_API FrontEnd::Ptr FrontEndManager::load_by_model(const std::vector& variants); // --------- Plugin exporting information -------------- diff --git a/src/frontends/common/src/frontend_manager.cpp b/src/frontends/common/src/frontend_manager.cpp index 193a151f0dc..48525eca7af 100644 --- a/src/frontends/common/src/frontend_manager.cpp +++ b/src/frontends/common/src/frontend_manager.cpp @@ -73,7 +73,7 @@ public: return names; } - FrontEnd::Ptr load_by_model(const std::vector>& variants) { + FrontEnd::Ptr load_by_model(const std::vector& variants) { std::lock_guard guard(m_loading_mutex); // Step 1: Search from hard-coded prioritized frontends first auto ptr = search_priority(variants); @@ -116,7 +116,7 @@ private: return info.is_file_name_match(names.file_name) || info.get_creator().m_name == names.name; } - FrontEnd::Ptr search_priority(const std::vector>& variants) { + FrontEnd::Ptr search_priority(const std::vector& variants) { // Map between file extension and suitable frontend static const std::map priority_fe_extensions = { {".xml", {"ir", "ir"}}, @@ -138,12 +138,12 @@ private: std::string model_path; const auto& model_variant = variants.at(0); - if (ov::is_type>(model_variant)) { - const auto& tmp_path = ov::as_type_ptr>(model_variant)->get(); + if (model_variant.is()) { + const auto& tmp_path = model_variant.as(); model_path = tmp_path; #if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) - } else if (ov::is_type>(model_variant)) { - auto wpath = ov::as_type_ptr>(model_variant)->get(); + } else if (model_variant.is()) { + auto wpath = model_variant.as(); model_path = ov::util::wstring_to_string(wpath); #endif } @@ -216,7 +216,7 @@ FrontEnd::Ptr FrontEndManager::load_by_framework(const std::string& framework) { return m_impl->load_by_framework(framework); } -FrontEnd::Ptr FrontEndManager::load_by_model_impl(const std::vector>& variants) { +FrontEnd::Ptr FrontEndManager::load_by_model_impl(const std::vector& variants) { return m_impl->load_by_model(variants); } @@ -229,7 +229,7 @@ void FrontEndManager::register_front_end(const std::string& name, FrontEndFactor } template <> -FrontEnd::Ptr FrontEndManager::load_by_model(const std::vector>& variants) { +FrontEnd::Ptr FrontEndManager::load_by_model(const std::vector& variants) { return load_by_model_impl(variants); } @@ -239,30 +239,30 @@ FrontEnd::FrontEnd() = default; FrontEnd::~FrontEnd() = default; -bool FrontEnd::supported_impl(const std::vector>& variants) const { +bool FrontEnd::supported_impl(const std::vector& variants) const { return false; } -InputModel::Ptr FrontEnd::load_impl(const std::vector>& params) const { +InputModel::Ptr FrontEnd::load_impl(const std::vector& params) const { FRONT_END_NOT_IMPLEMENTED(load_impl); } -std::shared_ptr FrontEnd::convert(InputModel::Ptr model) const { +std::shared_ptr FrontEnd::convert(InputModel::Ptr model) const { FRONT_END_NOT_IMPLEMENTED(convert); } -void FrontEnd::convert(std::shared_ptr) const { +void FrontEnd::convert(std::shared_ptr) const { FRONT_END_NOT_IMPLEMENTED(convert); } -std::shared_ptr FrontEnd::convert_partially(InputModel::Ptr model) const { +std::shared_ptr FrontEnd::convert_partially(InputModel::Ptr model) const { FRONT_END_NOT_IMPLEMENTED(convert_partially); } -std::shared_ptr FrontEnd::decode(InputModel::Ptr model) const { +std::shared_ptr FrontEnd::decode(InputModel::Ptr model) const { FRONT_END_NOT_IMPLEMENTED(decode); } -void FrontEnd::normalize(std::shared_ptr function) const { +void FrontEnd::normalize(std::shared_ptr function) const { FRONT_END_NOT_IMPLEMENTED(normalize); } @@ -370,15 +370,15 @@ void InputModel::extract_subgraph(const std::vector& inputs, const s } // Setting tensor properties -void InputModel::set_partial_shape(Place::Ptr place, const ngraph::PartialShape&) { +void InputModel::set_partial_shape(Place::Ptr place, const PartialShape&) { FRONT_END_NOT_IMPLEMENTED(set_partial_shape); } -ngraph::PartialShape InputModel::get_partial_shape(Place::Ptr place) const { +PartialShape InputModel::get_partial_shape(Place::Ptr place) const { FRONT_END_NOT_IMPLEMENTED(get_partial_shape); } -void InputModel::set_element_type(Place::Ptr place, const ngraph::element::Type&) { +void InputModel::set_element_type(Place::Ptr place, const element::Type&) { FRONT_END_NOT_IMPLEMENTED(set_element_type); } diff --git a/src/frontends/common/src/parameters.cpp b/src/frontends/common/src/parameters.cpp deleted file mode 100644 index 0d7125d6642..00000000000 --- a/src/frontends/common/src/parameters.cpp +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "common/parameters.hpp" - -BWDCMP_RTTI_DEFINITION(ov::VariantWrapper); -BWDCMP_RTTI_DEFINITION(ov::VariantWrapper); -BWDCMP_RTTI_DEFINITION(ov::VariantWrapper); -BWDCMP_RTTI_DEFINITION(ov::VariantWrapper); - -#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) -BWDCMP_RTTI_DEFINITION(ov::VariantWrapper); -#endif diff --git a/src/frontends/ir/include/ir_frontend/frontend.hpp b/src/frontends/ir/include/ir_frontend/frontend.hpp index f5a85ea86c5..a3f554d843d 100644 --- a/src/frontends/ir/include/ir_frontend/frontend.hpp +++ b/src/frontends/ir/include/ir_frontend/frontend.hpp @@ -6,7 +6,6 @@ #include "common/frontend.hpp" #include "common/telemetry_extension.hpp" -#include "openvino/core/variant.hpp" #include "utility.hpp" namespace ov { @@ -35,12 +34,12 @@ protected: /// \brief Check if FrontEndIR can recognize model from given parts /// \param params Can be path to the model file or std::istream /// \return InputModel::Ptr - bool supported_impl(const std::vector>& variants) const override; + bool supported_impl(const std::vector& variants) const override; /// \brief Reads model from file or std::istream /// \param params Can be path to the model file or std::istream /// \return InputModel::Ptr - InputModel::Ptr load_impl(const std::vector>& params) const override; + InputModel::Ptr load_impl(const std::vector& params) const override; private: std::vector> shared_objects; diff --git a/src/frontends/ir/include/ir_frontend/model.hpp b/src/frontends/ir/include/ir_frontend/model.hpp index 8e92efcef8d..a05d5eecedf 100644 --- a/src/frontends/ir/include/ir_frontend/model.hpp +++ b/src/frontends/ir/include/ir_frontend/model.hpp @@ -9,6 +9,7 @@ #include "ir_frontend/utility.hpp" #include "manager.hpp" +#include "ngraph/runtime/aligned_buffer.hpp" namespace ov { namespace frontend { diff --git a/src/frontends/ir/src/frontend.cpp b/src/frontends/ir/src/frontend.cpp index 413c628d93b..096e84187f4 100644 --- a/src/frontends/ir/src/frontend.cpp +++ b/src/frontends/ir/src/frontend.cpp @@ -11,7 +11,7 @@ #include "ir_frontend/utility.hpp" #include "ngraph/runtime/aligned_buffer.hpp" #include "ngraph/runtime/shared_buffer.hpp" -#include "openvino/core/variant.hpp" +#include "openvino/core/any.hpp" #include "openvino/util/file_util.hpp" #include "so_extension.hpp" #include "xml_parse_utils.h" @@ -59,7 +59,7 @@ size_t GetIRVersion(std::istream& model) { } // namespace -bool FrontEndIR::supported_impl(const std::vector>& variants) const { +bool FrontEndIR::supported_impl(const std::vector& variants) const { std::ifstream local_model_stream; std::istream* provided_model_stream = nullptr; @@ -68,18 +68,18 @@ bool FrontEndIR::supported_impl(const std::vector>& var } const auto& model_variant = variants[0]; - if (ov::is_type>(model_variant)) { - const auto& path = ov::as_type_ptr>(model_variant)->get(); + if (model_variant.is()) { + const auto& path = model_variant.as(); local_model_stream.open(path, std::ios::in | std::ifstream::binary); #if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) - } else if (ov::is_type>(model_variant)) { - const auto& path = ov::as_type_ptr>(model_variant)->get(); + } else if (model_variant.is()) { + const auto& path = model_variant.as(); local_model_stream.open(path, std::ios::in | std::ifstream::binary); #endif - } else if (ov::is_type>(model_variant)) { - provided_model_stream = ov::as_type_ptr>(model_variant)->get(); - } else if (ov::is_type>(model_variant)) { - provided_model_stream = ov::as_type_ptr>(model_variant)->get(); + } else if (model_variant.is()) { + provided_model_stream = model_variant.as(); + } else if (model_variant.is()) { + provided_model_stream = model_variant.as(); } if (provided_model_stream && local_model_stream.is_open()) { @@ -111,7 +111,7 @@ void FrontEndIR::add_extension(const ov::Extension::Ptr& ext) { extensions.emplace_back(ext); } -InputModel::Ptr FrontEndIR::load_impl(const std::vector>& variants) const { +InputModel::Ptr FrontEndIR::load_impl(const std::vector& variants) const { std::ifstream local_model_stream; std::istream* provided_model_stream = nullptr; std::shared_ptr weights; @@ -142,10 +142,10 @@ InputModel::Ptr FrontEndIR::load_impl(const std::vector std::string weights_path, model_path; #endif - // Load model const auto& model_variant = variants.at(0); - if (ov::is_type>(model_variant)) { - const auto& tmp_path = ov::as_type_ptr>(model_variant)->get(); + + if (model_variant.is()) { + const auto& tmp_path = model_variant.as(); #if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) model_path = ov::util::string_to_wstring(tmp_path.c_str()); #else @@ -153,32 +153,32 @@ InputModel::Ptr FrontEndIR::load_impl(const std::vector #endif local_model_stream.open(model_path, std::ios::in | std::ifstream::binary); #if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) - } else if (ov::is_type>(model_variant)) { - model_path = ov::as_type_ptr>(model_variant)->get(); + } else if (model_variant.is()) { + model_path = model_variant.as(); local_model_stream.open(model_path, std::ios::in | std::ifstream::binary); #endif - } else if (ov::is_type>(model_variant)) { - provided_model_stream = ov::as_type_ptr>(model_variant)->get(); - } else if (ov::is_type>(model_variant)) { - provided_model_stream = ov::as_type_ptr>(model_variant)->get(); + } else if (model_variant.is()) { + provided_model_stream = model_variant.as(); + } else if (model_variant.is()) { + provided_model_stream = model_variant.as(); } // Check weights and extensions for (size_t variant_id = 1; variant_id < variants.size(); ++variant_id) { const auto& variant = variants.at(variant_id); - if (ov::is_type>(variant)) { - const auto& tmp_path = ov::as_type_ptr>(variant)->get(); + if (variant.is()) { + const auto& tmp_path = variant.as(); #if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) weights_path = ov::util::string_to_wstring(tmp_path.c_str()); #else weights_path = tmp_path; #endif #if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) - } else if (ov::is_type>(variant)) { - weights_path = ov::as_type_ptr>(variant)->get(); + } else if (variant.is()) { + weights_path = variant.as(); #endif - } else if (ov::is_type>>(variant)) { - weights = ov::as_type_ptr>>(variant)->get(); + } else if (variant.is>()) { + weights = variant.as>(); } } diff --git a/src/frontends/ir/src/ir_deserializer.cpp b/src/frontends/ir/src/ir_deserializer.cpp index c19c1e4d98c..b4d1c687260 100644 --- a/src/frontends/ir/src/ir_deserializer.cpp +++ b/src/frontends/ir/src/ir_deserializer.cpp @@ -601,10 +601,11 @@ GenericLayerParams XmlDeserializer::parseGenericParams(const pugi::xml_node& nod return params; } -std::shared_ptr XmlDeserializer::createNode(const std::vector>& inputs, - const pugi::xml_node& node, - const ov::Weights& weights, - const GenericLayerParams& params) { +std::shared_ptr XmlDeserializer::createNode( + const std::vector>& inputs, + const pugi::xml_node& node, + const std::shared_ptr& weights, + const GenericLayerParams& params) { // Check that inputs are correctly defined for (size_t i = 0; i < inputs.size(); i++) { if (!inputs[i].get_node()) @@ -700,7 +701,7 @@ std::shared_ptr XmlDeserializer::createNode(const std::vector>(pr_data.value()); + rtInfo.emplace(ov::PrimitivesPriority::get_type_info_static(), ov::PrimitivesPriority{pr_data.value()}); } const auto aw_data = dn.attribute("alt_width"); if (aw_data) { @@ -721,24 +722,33 @@ std::shared_ptr XmlDeserializer::createNode(const std::vectorvisit_attributes(attribute_visitor)) { - rt_info[type_info] = attr; + auto attr = attrs_factory.create_by_type_info(type_info); + if (!attr.empty()) { + if (attr.is()) { + RTInfoDeserializer attribute_visitor(item); + if (attr.as().visit_attributes(attribute_visitor)) { + auto res = rt_info.emplace(type_info, attr); + if (!res.second) { + IE_THROW() << "multiple rt_info attributes are detected: " << attribute_name; + } + } else { + IE_THROW() << "VisitAttributes is not supported for: " << item.name() << " attribute"; + } } else { - IE_THROW() << "VisitAttributes is not supported for: " << attribute_name << " attribute"; + IE_THROW() << "Attribute: " << item.name() << " is not recognized as runtime attribute"; } } else { - IE_THROW() << "Attribute: " << attribute_name << " is not recognized"; + IE_THROW() << "Attribute: " << item.name() << " is not recognized"; } } }; diff --git a/src/frontends/ir/src/ir_deserializer.hpp b/src/frontends/ir/src/ir_deserializer.hpp index 192d8b7276d..e018c3df2cc 100644 --- a/src/frontends/ir/src/ir_deserializer.hpp +++ b/src/frontends/ir/src/ir_deserializer.hpp @@ -10,6 +10,7 @@ #include "ie_ngraph_utils.hpp" #include "ir_frontend/model.hpp" +#include "ngraph/opsets/opset.hpp" #include "openvino/core/attribute_visitor.hpp" #include "openvino/core/op_extension.hpp" #include "openvino/op/loop.hpp" @@ -175,12 +176,12 @@ private: std::shared_ptr createNode(const ov::OutputVector& inputs, const pugi::xml_node& node, - const ov::Weights& weights, + const std::shared_ptr& weights, const GenericLayerParams& params); // -- DATA -- const pugi::xml_node m_node; - const ov::Weights& m_weights; + const std::shared_ptr& m_weights; const std::unordered_map& m_opsets; const std::unordered_map& m_extensions; std::unordered_map>& m_variables; diff --git a/src/frontends/onnx/frontend/include/onnx_frontend/frontend.hpp b/src/frontends/onnx/frontend/include/onnx_frontend/frontend.hpp index d35f3485daf..331975df663 100644 --- a/src/frontends/onnx/frontend/include/onnx_frontend/frontend.hpp +++ b/src/frontends/onnx/frontend/include/onnx_frontend/frontend.hpp @@ -27,11 +27,11 @@ public: void convert(std::shared_ptr partially_converted) const override; std::shared_ptr decode(InputModel::Ptr model) const override; std::string get_name() const override; - bool supported_impl(const std::vector>& variants) const override; + bool supported_impl(const std::vector& variants) const override; void add_extension(const std::shared_ptr& extension) override; protected: - InputModel::Ptr load_impl(const std::vector>& params) const override; + InputModel::Ptr load_impl(const std::vector& params) const override; private: std::shared_ptr m_telemetry; diff --git a/src/frontends/onnx/frontend/src/frontend.cpp b/src/frontends/onnx/frontend/src/frontend.cpp index db73a7fde03..6acec3bd5f3 100644 --- a/src/frontends/onnx/frontend/src/frontend.cpp +++ b/src/frontends/onnx/frontend/src/frontend.cpp @@ -17,10 +17,6 @@ using namespace ov; using namespace ov::frontend; -using VariantString = VariantWrapper; -using VariantWString = VariantWrapper; -using VariantIstreamPtr = VariantWrapper; - ONNX_FRONTEND_C_API FrontEndVersion GetAPIVersion() { return OV_FRONTEND_API_VERSION; } @@ -34,29 +30,29 @@ ONNX_FRONTEND_C_API void* GetFrontEndData() { return res; } -InputModel::Ptr FrontEndONNX::load_impl(const std::vector>& variants) const { +InputModel::Ptr FrontEndONNX::load_impl(const std::vector& variants) const { if (variants.size() == 0) { return nullptr; } - if (ov::is_type(variants[0])) { - const auto path = ov::as_type_ptr(variants[0])->get(); + if (variants[0].is()) { + const auto path = variants[0].as(); return std::make_shared(path, m_telemetry); } #if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) - if (ov::is_type(variants[0])) { - const auto path = ov::as_type_ptr(variants[0])->get(); + if (variants[0].is()) { + const auto path = variants[0].as(); return std::make_shared(path, m_telemetry); } #endif - if (ov::is_type(variants[0])) { - const auto stream = ov::as_type_ptr(variants[0])->get(); - if (variants.size() > 1 && ov::is_type(variants[1])) { - const auto path = ov::as_type_ptr(variants[1])->get(); + if (variants[0].is()) { + const auto stream = variants[0].as(); + if (variants.size() > 1 && variants[1].is()) { + const auto path = variants[0].as(); return std::make_shared(*stream, path, m_telemetry); } #if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) - if (variants.size() > 1 && ov::is_type(variants[1])) { - const auto path = ov::as_type_ptr(variants[1])->get(); + if (variants.size() > 1 && variants[1].is()) { + const auto path = variants[1].as(); return std::make_shared(*stream, path, m_telemetry); } #endif @@ -107,18 +103,18 @@ private: }; } // namespace -bool FrontEndONNX::supported_impl(const std::vector>& variants) const { +bool FrontEndONNX::supported_impl(const std::vector& variants) const { if (variants.size() == 0) { return false; } std::ifstream model_stream; - if (ov::is_type(variants[0])) { - const auto path = ov::as_type_ptr(variants[0])->get(); + if (variants[0].is()) { + const auto path = variants[0].as(); model_stream.open(path, std::ios::in | std::ifstream::binary); } #if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) - else if (ov::is_type(variants[0])) { - const auto path = ov::as_type_ptr(variants[0])->get(); + else if (variants[0].is()) { + const auto path = variants[0].as(); model_stream.open(path, std::ios::in | std::ifstream::binary); } #endif @@ -128,11 +124,12 @@ bool FrontEndONNX::supported_impl(const std::vector>& v model_stream.close(); return is_valid_model; } - if (ov::is_type(variants[0])) { - const auto stream = ov::as_type_ptr(variants[0])->get(); + if (variants[0].is()) { + const auto stream = variants[0].as(); StreamRewinder rwd{*stream}; return ngraph::onnx_common::is_valid_model(*stream); } + return false; } diff --git a/src/frontends/paddlepaddle/include/paddlepaddle_frontend/frontend.hpp b/src/frontends/paddlepaddle/include/paddlepaddle_frontend/frontend.hpp index 2020aa00fee..dd3eb2de449 100644 --- a/src/frontends/paddlepaddle/include/paddlepaddle_frontend/frontend.hpp +++ b/src/frontends/paddlepaddle/include/paddlepaddle_frontend/frontend.hpp @@ -55,14 +55,14 @@ protected: /// \param params Can be path to folder which contains __model__ file or path to /// .pdmodel file /// \return InputModel::Ptr - bool supported_impl(const std::vector>& variants) const override; + bool supported_impl(const std::vector& variants) const override; /// \brief Reads model from 1 or 2 given file names or 1 or 2 std::istream containing /// model in protobuf format and weights /// \param params Can contain path to folder with __model__ file or path to .pdmodel /// file or 1 or 2 streams with model and weights /// \return InputModel::Ptr - InputModel::Ptr load_impl(const std::vector>& params) const override; + InputModel::Ptr load_impl(const std::vector& params) const override; private: static std::shared_ptr convert_each_node( diff --git a/src/frontends/paddlepaddle/src/decoder.cpp b/src/frontends/paddlepaddle/src/decoder.cpp index 56f21f0d15b..816d7864fcd 100644 --- a/src/frontends/paddlepaddle/src/decoder.cpp +++ b/src/frontends/paddlepaddle/src/decoder.cpp @@ -31,39 +31,34 @@ std::map TYPE_MAP{ {proto::VarType_Type::VarType_Type_INT8, ov::element::i8}, {proto::VarType_Type::VarType_Type_BF16, ov::element::bf16}}; -std::shared_ptr DecoderPDPDProto::get_attribute(const std::string& name, - const VariantTypeInfo& type_info) const { +ov::Any DecoderPDPDProto::get_attribute(const std::string& name, const std::type_info& type_info) const { auto attrs = decode_attribute_helper(name); if (attrs.empty()) { - return nullptr; + return {}; } - if (type_info == VariantWrapper::get_type_info_static()) { - return std::make_shared>(attrs[0].s()); - } else if (type_info == VariantWrapper::get_type_info_static()) { - return std::make_shared>(attrs[0].l()); - } else if (type_info == VariantWrapper>::get_type_info_static()) { - auto longs = std::vector(attrs[0].longs().begin(), attrs[0].longs().end()); - return std::make_shared>>(longs); - } else if (type_info == VariantWrapper::get_type_info_static()) { - return std::make_shared>(attrs[0].i()); - } else if (type_info == VariantWrapper>::get_type_info_static()) { - auto ints = std::vector(attrs[0].ints().begin(), attrs[0].ints().end()); - return std::make_shared>>(ints); - } else if (type_info == VariantWrapper::get_type_info_static()) { - return std::make_shared>(attrs[0].f()); - } else if (type_info == VariantWrapper>::get_type_info_static()) { - auto floats = std::vector(attrs[0].floats().begin(), attrs[0].floats().end()); - return std::make_shared>>(floats); - } else if (type_info == VariantWrapper::get_type_info_static()) { - auto data_type = (paddle::framework::proto::VarType_Type)attrs[0].i(); - return std::make_shared>(TYPE_MAP[data_type]); - } else if (type_info == VariantWrapper::get_type_info_static()) { - return std::make_shared>(attrs[0].b()); + if (type_info == typeid(std::string)) { + return attrs[0].s(); + } else if (type_info == typeid(int64_t)) { + return attrs[0].l(); + } else if (type_info == typeid(std::vector)) { + return std::vector(attrs[0].longs().begin(), attrs[0].longs().end()); + } else if (type_info == typeid(int32_t)) { + return attrs[0].i(); + } else if (type_info == typeid(std::vector)) { + return std::vector(attrs[0].ints().begin(), attrs[0].ints().end()); + } else if (type_info == typeid(float)) { + return attrs[0].f(); + } else if (type_info == typeid(std::vector)) { + return std::vector(attrs[0].floats().begin(), attrs[0].floats().end()); + } else if (type_info == typeid(ngraph::element::Type)) { + return TYPE_MAP[static_cast(attrs[0].i())]; + } else if (type_info == typeid(bool)) { + return attrs[0].b(); } // Type is not supported by decoder - return nullptr; + return {}; } std::vector DecoderPDPDProto::get_output_names() const { diff --git a/src/frontends/paddlepaddle/src/decoder.hpp b/src/frontends/paddlepaddle/src/decoder.hpp index 29ef5ee9eda..b56ed58116e 100644 --- a/src/frontends/paddlepaddle/src/decoder.hpp +++ b/src/frontends/paddlepaddle/src/decoder.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -26,7 +27,7 @@ class DecoderPDPDProto : public pdpd::DecoderBase { public: explicit DecoderPDPDProto(const std::shared_ptr& op) : op_place(op) {} - std::shared_ptr get_attribute(const std::string& name, const VariantTypeInfo& type_info) const override; + ov::Any get_attribute(const std::string& name, const std::type_info& type_info) const override; std::vector get_output_names() const override; diff --git a/src/frontends/paddlepaddle/src/frontend.cpp b/src/frontends/paddlepaddle/src/frontend.cpp index e366eb85e90..e8a75903894 100644 --- a/src/frontends/paddlepaddle/src/frontend.cpp +++ b/src/frontends/paddlepaddle/src/frontend.cpp @@ -13,7 +13,6 @@ #include "framework.pb.h" #include "node_context.hpp" #include "op_table.hpp" -#include "openvino/core/variant.hpp" #include "openvino/opsets/opset7.hpp" #include "paddlepaddle_frontend/exceptions.hpp" #include "paddlepaddle_frontend/model.hpp" @@ -116,16 +115,16 @@ bool normalize_framework_node(const std::shared_ptr& node, return true; } -std::istream* variant_to_stream_ptr(const std::shared_ptr& variant, std::ifstream& ext_stream) { - if (ov::is_type>(variant)) { - return ov::as_type_ptr>(variant)->get(); - } else if (ov::is_type>(variant)) { - const auto& model_path = ov::as_type_ptr>(variant)->get(); +std::istream* variant_to_stream_ptr(const ov::Any& variant, std::ifstream& ext_stream) { + if (variant.is()) { + return variant.as(); + } else if (variant.is()) { + const auto& model_path = variant.as(); ext_stream.open(model_path, std::ios::in | std::ifstream::binary); } #if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) - else if (ov::is_type>(variant)) { - const auto& model_path = ov::as_type_ptr>(variant)->get(); + else if (variant.is()) { + const auto& model_path = variant.as(); ext_stream.open(model_path, std::ios::in | std::ifstream::binary); } #endif @@ -205,15 +204,15 @@ std::shared_ptr FrontEndPDPD::convert_each_node( return std::make_shared(result_nodes, parameter_nodes); } -bool FrontEndPDPD::supported_impl(const std::vector>& variants) const { +bool FrontEndPDPD::supported_impl(const std::vector& variants) const { // FrontEndPDPD can only load model specified by one path, one file or two files. if (variants.empty() || variants.size() > 2) return false; // Validating first path, it must contain a model - if (ov::is_type>(variants[0])) { + if (variants[0].is()) { std::string suffix = ".pdmodel"; - std::string model_path = ov::as_type_ptr>(variants[0])->get(); + std::string model_path = variants[0].as(); if (!pdpd::endsWith(model_path, suffix)) { model_path += pdpd::get_path_sep() + "__model__"; } @@ -223,9 +222,9 @@ bool FrontEndPDPD::supported_impl(const std::vector>& v return model_str && model_str.is_open(); } #if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) - else if (ov::is_type>(variants[0])) { + else if (variants[0].is()) { std::wstring suffix = L".pdmodel"; - std::wstring model_path = ov::as_type_ptr>(variants[0])->get(); + std::wstring model_path = variants[0].as(); if (!pdpd::endsWith(model_path, suffix)) { model_path += pdpd::get_path_sep() + L"__model__"; } @@ -235,32 +234,32 @@ bool FrontEndPDPD::supported_impl(const std::vector>& v return model_str && model_str.is_open(); } #endif - else if (ov::is_type>(variants[0])) { + else if (variants[0].is()) { // Validating first stream, it must contain a model - auto p_model_stream = ov::as_type_ptr>(variants[0])->get(); + auto p_model_stream = variants[0].as(); paddle::framework::proto::ProgramDesc fw; return fw.ParseFromIstream(p_model_stream); } return false; } -InputModel::Ptr FrontEndPDPD::load_impl(const std::vector>& variants) const { +InputModel::Ptr FrontEndPDPD::load_impl(const std::vector& variants) const { if (variants.size() == 1) { // The case when folder with __model__ and weight files is provided or .pdmodel file - if (ov::is_type>(variants[0])) { - std::string m_path = ov::as_type_ptr>(variants[0])->get(); + if (variants[0].is()) { + std::string m_path = variants[0].as(); return std::make_shared(m_path, m_telemetry); } #if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) - else if (ov::is_type>(variants[0])) { - std::wstring m_path = ov::as_type_ptr>(variants[0])->get(); + else if (variants[0].is()) { + std::wstring m_path = variants[0].as(); return std::make_shared(m_path, m_telemetry); } #endif // The case with only model stream provided and no weights. This means model has // no learnable weights - else if (ov::is_type>(variants[0])) { - auto p_model_stream = ov::as_type_ptr>(variants[0])->get(); + else if (variants[0].is()) { + auto p_model_stream = variants[0].as(); return std::make_shared(std::vector{p_model_stream}, m_telemetry); } } else if (variants.size() == 2) { diff --git a/src/frontends/paddlepaddle/src/node_context.hpp b/src/frontends/paddlepaddle/src/node_context.hpp index 28461725362..8b363d1f6ba 100644 --- a/src/frontends/paddlepaddle/src/node_context.hpp +++ b/src/frontends/paddlepaddle/src/node_context.hpp @@ -4,26 +4,11 @@ #pragma once #include "ngraph/compatibility.hpp" -#include "openvino/core/variant.hpp" +#include "openvino/core/any.hpp" #include "paddlepaddle_frontend/exceptions.hpp" #include "paddlepaddle_frontend/utility.hpp" -#define OPENVINO_VARIANT_DECLARATION(TYPE, info) \ - template <> \ - class VariantWrapper : public VariantImpl { \ - public: \ - OPENVINO_RTTI(info); \ - VariantWrapper(const value_type& value) : VariantImpl(value) {} \ - } - namespace ov { -OPENVINO_VARIANT_DECLARATION(int32_t, "Variant::int32"); -OPENVINO_VARIANT_DECLARATION(std::vector, "Variant::int32_vector"); -OPENVINO_VARIANT_DECLARATION(float, "Variant::float"); -OPENVINO_VARIANT_DECLARATION(std::vector, "Variant::float_vector"); -OPENVINO_VARIANT_DECLARATION(bool, "Variant::bool"); -OPENVINO_VARIANT_DECLARATION(ov::element::Type, "Variant::element_type"); -OPENVINO_VARIANT_DECLARATION(std::vector, "Variant::int64_vector"); namespace frontend { namespace pdpd { using InPortName = std::string; @@ -39,7 +24,7 @@ public: /// \param name Attribute name /// \param type_info Attribute type information /// \return Shared pointer to appropriate value if it exists, 'nullptr' otherwise - virtual std::shared_ptr get_attribute(const std::string& name, const VariantTypeInfo& type_info) const = 0; + virtual ov::Any get_attribute(const std::string& name, const std::type_info& type_info) const = 0; virtual std::vector get_output_names() const = 0; @@ -69,71 +54,26 @@ public: NodeContext(const DecoderBase& _decoder, const NamedInputs& _name_map) : decoder(_decoder), name_map(_name_map) {} /// Returns node attribute by name. Returns 'def' value if attribute does not exist - template >::value, bool>::type = true> + template T get_attribute(const std::string& name, const T& def) const { - std::shared_ptr res; - OPENVINO_SUPPRESS_DEPRECATED_START - res = decoder.get_attribute(name, VariantWrapper::type_info); - OPENVINO_SUPPRESS_DEPRECATED_END - if (res) { - auto ret = std::dynamic_pointer_cast>(res); - FRONT_END_GENERAL_CHECK(ret, "Attribute with name '", name, "' has invalid type"); - return ret->get(); - } else { - return def; - } - } - template >::value, bool>::type = true> - T get_attribute(const std::string& name, const T& def) const { - std::shared_ptr res; - res = decoder.get_attribute(name, VariantWrapper::get_type_info_static()); - if (res) { - auto ret = std::dynamic_pointer_cast>(res); - FRONT_END_GENERAL_CHECK(ret, "Attribute with name '", name, "' has invalid type"); - return ret->get(); + auto res = decoder.get_attribute(name, typeid(T)); + if (!res.empty()) { + return res.as(); } else { return def; } } - template >::value, bool>::type = true> + template T get_attribute(const std::string& name) const { - std::shared_ptr res; - OPENVINO_SUPPRESS_DEPRECATED_START - res = decoder.get_attribute(name, VariantWrapper::type_info); - OPENVINO_SUPPRESS_DEPRECATED_END - FRONT_END_GENERAL_CHECK(res, "Attribute with name '", name, "' does not exist"); - auto ret = std::dynamic_pointer_cast>(res); - FRONT_END_GENERAL_CHECK(ret, "Attribute with name '", name, "' has invalid type"); - return ret->get(); + auto res = decoder.get_attribute(name, typeid(T)); + FRONT_END_GENERAL_CHECK(!res.empty(), "Attribute with name '", name, "' does not exist"); + return res.as(); } - template >::value, bool>::type = true> - T get_attribute(const std::string& name) const { - std::shared_ptr res; - res = decoder.get_attribute(name, VariantWrapper::get_type_info_static()); - FRONT_END_GENERAL_CHECK(res, "Attribute with name '", name, "' does not exist"); - auto ret = std::dynamic_pointer_cast>(res); - FRONT_END_GENERAL_CHECK(ret, "Attribute with name '", name, "' has invalid type"); - return ret->get(); - } - - template >::value, bool>::type = true> + template bool has_attribute(const std::string& name) const { - std::shared_ptr res; - OPENVINO_SUPPRESS_DEPRECATED_START - res = decoder.get_attribute(name, VariantWrapper::type_info); - OPENVINO_SUPPRESS_DEPRECATED_END - return res != nullptr; - } - - template >::value, bool>::type = true> - bool has_attribute(const std::string& name) const { - std::shared_ptr res; - OPENVINO_SUPPRESS_DEPRECATED_START - res = decoder.get_attribute(name, VariantWrapper::get_type_info_static()); - OPENVINO_SUPPRESS_DEPRECATED_END - return res != nullptr; + return !decoder.get_attribute(name, typeid(T)).empty(); } /// Detects if there is at least one input attached with a given name diff --git a/src/frontends/paddlepaddle/src/op/conv2d_utils.hpp b/src/frontends/paddlepaddle/src/op/conv2d_utils.hpp index f5632612191..6ed034231f5 100644 --- a/src/frontends/paddlepaddle/src/op/conv2d_utils.hpp +++ b/src/frontends/paddlepaddle/src/op/conv2d_utils.hpp @@ -4,6 +4,7 @@ #pragma once #include "node_context.hpp" +#include "openvino/core/coordinate_diff.hpp" namespace ov { namespace frontend { diff --git a/src/frontends/tensorflow/include/tensorflow_frontend/decoder.hpp b/src/frontends/tensorflow/include/tensorflow_frontend/decoder.hpp index 80ecb99935f..423f030934c 100644 --- a/src/frontends/tensorflow/include/tensorflow_frontend/decoder.hpp +++ b/src/frontends/tensorflow/include/tensorflow_frontend/decoder.hpp @@ -4,8 +4,8 @@ #pragma once -#include "openvino/core/any.hpp" -#include "openvino/core/variant.hpp" +#include + #include "tensorflow_frontend/utility.hpp" namespace ov { @@ -18,8 +18,7 @@ public: /// \param name Attribute name /// \param type_info Attribute type information /// \return Shared pointer to appropriate value if it exists, 'nullptr' otherwise - virtual std::shared_ptr get_attribute(const std::string& name, - const VariantTypeInfo& type_info) const = 0; + virtual ov::Any get_attribute(const std::string& name, const std::type_info& type_info) const = 0; /// \brief Get a number of inputs virtual size_t get_input_size() const = 0; diff --git a/src/frontends/tensorflow/include/tensorflow_frontend/frontend.hpp b/src/frontends/tensorflow/include/tensorflow_frontend/frontend.hpp index 2a34b501abb..0066ac00267 100644 --- a/src/frontends/tensorflow/include/tensorflow_frontend/frontend.hpp +++ b/src/frontends/tensorflow/include/tensorflow_frontend/frontend.hpp @@ -12,7 +12,6 @@ #include "common/telemetry_extension.hpp" #include "openvino/core/any.hpp" #include "openvino/core/node_vector.hpp" -#include "openvino/core/variant.hpp" #include "tensorflow_frontend/utility.hpp" namespace ov { @@ -72,9 +71,9 @@ public: protected: /// \brief Check if FrontEndTensorflow can recognize model from given parts - bool supported_impl(const std::vector>& variants) const override; + bool supported_impl(const std::vector& variants) const override; - ov::frontend::InputModel::Ptr load_impl(const std::vector>& variants) const override; + ov::frontend::InputModel::Ptr load_impl(const std::vector& variants) const override; private: void translate_graph(const ov::frontend::InputModel::Ptr& model, diff --git a/src/frontends/tensorflow/include/tensorflow_frontend/graph_iterator.hpp b/src/frontends/tensorflow/include/tensorflow_frontend/graph_iterator.hpp index 613035894f5..de8a548fd14 100644 --- a/src/frontends/tensorflow/include/tensorflow_frontend/graph_iterator.hpp +++ b/src/frontends/tensorflow/include/tensorflow_frontend/graph_iterator.hpp @@ -5,15 +5,16 @@ #pragma once #include "openvino/core/any.hpp" -#include "openvino/core/variant.hpp" #include "tensorflow_frontend/decoder.hpp" #include "tensorflow_frontend/utility.hpp" namespace ov { namespace frontend { /// Abstract representation for an input model graph that gives nodes in topologically sorted order -class TF_API GraphIterator { +class TF_API GraphIterator : ov::RuntimeAttribute { public: + OPENVINO_RTTI("Variant::GraphIterator"); + using Ptr = std::shared_ptr; /// \brief Get a number of operation nodes in the graph @@ -36,15 +37,3 @@ public: }; } // namespace frontend } // namespace ov - -namespace ov { -/// Keep GraphIterator::Ptr object and type information for type-safe -/// dynamic conversions without using C++ RTTI -template <> -class TF_API VariantWrapper<::ov::frontend::GraphIterator::Ptr> - : public VariantImpl<::ov::frontend::GraphIterator::Ptr> { -public: - OPENVINO_RTTI("Variant::GraphIterator::Ptr"); - VariantWrapper(const value_type& value) : VariantImpl(value) {} -}; -} // namespace ov diff --git a/src/frontends/tensorflow/src/decoder_proto.cpp b/src/frontends/tensorflow/src/decoder_proto.cpp index 31ec6657ebe..5a7a26c4356 100644 --- a/src/frontends/tensorflow/src/decoder_proto.cpp +++ b/src/frontends/tensorflow/src/decoder_proto.cpp @@ -6,8 +6,6 @@ #include "node_context.hpp" -using namespace std; - namespace ov { namespace frontend { namespace tf { @@ -29,72 +27,62 @@ const std::map<::tensorflow::DataType, ov::element::Type>& TYPE_MAP() { } } // namespace -template -bool is_type(const VariantTypeInfo& type_info) { - return type_info == VariantWrapper::get_type_info_static(); -} - -template -shared_ptr> create_variant(const T& data) { - return make_shared>(data); -} - -shared_ptr DecoderTFProto::get_attribute(const string& name, const VariantTypeInfo& type_info) const { +ov::Any DecoderTFProto::get_attribute(const std::string& name, const std::type_info& type_info) const { auto attrs = decode_attribute_helper(name); if (attrs.empty()) { - return nullptr; + return {}; } - if (is_type(type_info)) { - return create_variant(attrs[0].s()); - } else if (is_type(type_info)) { - return create_variant(attrs[0].i()); - } else if (is_type>(type_info)) { - vector longs; + if (type_info == typeid(std::string)) { + return attrs[0].s(); + } else if (type_info == typeid(int64_t)) { + return attrs[0].i(); + } else if (type_info == typeid(std::vector)) { + std::vector longs; longs.reserve(attrs[0].list().i_size()); for (size_t idx = 0; idx < attrs[0].list().i_size(); ++idx) { longs.push_back(attrs[0].list().i(idx)); } - return create_variant>(longs); - } else if (is_type(type_info)) { - return create_variant(static_cast(attrs[0].i())); - } else if (is_type>(type_info)) { - vector ints; + return longs; + } else if (type_info == typeid(int32_t)) { + return static_cast(attrs[0].i()); + } else if (type_info == typeid(std::vector)) { + std::vector ints; ints.reserve(attrs[0].list().i_size()); for (size_t idx = 0; idx < attrs[0].list().i_size(); ++idx) { ints.push_back(static_cast(attrs[0].list().i(idx))); } - return create_variant>(ints); - } else if (is_type(type_info)) { - return create_variant(attrs[0].f()); - } else if (is_type>(type_info)) { - vector floats; + return ints; + } else if (type_info == typeid(float)) { + return attrs[0].f(); + } else if (type_info == typeid(std::vector)) { + std::vector floats; floats.reserve(attrs[0].list().i_size()); for (size_t idx = 0; idx < attrs[0].list().i_size(); ++idx) { floats.push_back(attrs[0].list().f(idx)); } - return create_variant>(floats); - } else if (is_type(type_info)) { + return floats; + } else if (type_info == typeid(ov::element::Type)) { auto data_type = attrs[0].type(); - return create_variant(TYPE_MAP().at(data_type)); - } else if (is_type(type_info)) { - return create_variant(attrs[0].b()); - } else if (is_type<::tensorflow::DataType>(type_info)) { - return create_variant<::tensorflow::DataType>(attrs[0].type()); - } else if (is_type<::tensorflow::TensorProto>(type_info)) { - return create_variant<::tensorflow::TensorProto>(attrs[0].tensor()); - } else if (is_type<::ov::PartialShape>(type_info)) { - vector dims; + return TYPE_MAP().at(data_type); + } else if (type_info == typeid(bool)) { + return attrs[0].b(); + } else if (type_info == typeid(::tensorflow::DataType)) { + return attrs[0].type(); + } else if (type_info == typeid(::tensorflow::TensorProto)) { + return attrs[0].tensor(); + } else if (type_info == typeid(::ov::PartialShape)) { + std::vector dims; auto tf_shape = attrs[0].shape(); for (int i = 0; i < tf_shape.dim_size(); i++) { - dims.emplace_back(tf_shape.dim(i).size()); + dims.push_back(tf_shape.dim(i).size()); } auto pshape = ov::PartialShape(dims); - return create_variant<::ov::PartialShape>(pshape); + return pshape; } // type is not supported by decoder - return nullptr; + return {}; } size_t DecoderTFProto::get_input_size() const { @@ -102,14 +90,14 @@ size_t DecoderTFProto::get_input_size() const { } void DecoderTFProto::get_input_node(size_t input_port_idx, - string& producer_name, + std::string& producer_name, size_t& producer_output_port_index) const { // TODO: handle body graph nodes with a couple of columns - string producer_port_name = m_node_def->input(input_port_idx); + std::string producer_port_name = m_node_def->input(input_port_idx); auto delim_pos = producer_port_name.find(':'); - if (delim_pos != string::npos) { + if (delim_pos != std::string::npos) { producer_name = producer_port_name.substr(0, delim_pos); - producer_output_port_index = stoi(producer_port_name.substr(delim_pos)); + producer_output_port_index = std::stoi(producer_port_name.substr(delim_pos)); return; } producer_name = producer_port_name; @@ -124,11 +112,16 @@ const std::string& DecoderTFProto::get_op_name() const { return m_node_def->name(); } -vector<::tensorflow::AttrValue> DecoderTFProto::decode_attribute_helper(const string& name) const { +std::vector<::tensorflow::AttrValue> DecoderTFProto::decode_attribute_helper(const std::string& name) const { auto attr_map = m_node_def->attr(); - if (attr_map.contains(name)) - return {m_node_def->attr().at(name)}; - return {}; + FRONT_END_GENERAL_CHECK(attr_map.contains(name), + "An error occurred while parsing the ", + name, + " attribute of ", + this->get_op_type(), + "node"); + auto value = m_node_def->attr().at(name); + return {value}; } } // namespace tf } // namespace frontend diff --git a/src/frontends/tensorflow/src/decoder_proto.hpp b/src/frontends/tensorflow/src/decoder_proto.hpp index 087986deeb3..a0871b20aa7 100644 --- a/src/frontends/tensorflow/src/decoder_proto.hpp +++ b/src/frontends/tensorflow/src/decoder_proto.hpp @@ -20,8 +20,7 @@ class DecoderTFProto : public DecoderBase { public: explicit DecoderTFProto(const ::tensorflow::NodeDef* node_def) : m_node_def(node_def) {} - std::shared_ptr get_attribute(const std::string& name, - const VariantTypeInfo& type_info) const override; + ov::Any get_attribute(const std::string& name, const std::type_info& type_info) const override; size_t get_input_size() const override; diff --git a/src/frontends/tensorflow/src/frontend.cpp b/src/frontends/tensorflow/src/frontend.cpp index 5c6c83fb9d9..1ad1b019c82 100644 --- a/src/frontends/tensorflow/src/frontend.cpp +++ b/src/frontends/tensorflow/src/frontend.cpp @@ -268,38 +268,38 @@ void FrontEndTF::translate_graph(const ov::frontend::InputModel::Ptr& model, } /// \brief Check if FrontEndTensorflow can recognize model from given parts -bool FrontEndTF::supported_impl(const std::vector>& variants) const { +bool FrontEndTF::supported_impl(const std::vector& variants) const { // TODO: Support other TensorFlow formats: SavedModel, .meta, checkpoint, pbtxt if (variants.size() != 1) return false; // Validating first path, it must contain a model - if (ov::is_type>(variants[0])) { + if (variants[0].is()) { std::string suffix = ".pb"; - std::string model_path = ov::as_type_ptr>(variants[0])->get(); + std::string model_path = variants[0].as(); if (ov::util::ends_with(model_path, suffix.c_str())) { return true; } - } else if (ov::is_type>(variants[0])) { + } else if (variants[0].is()) { return true; } return false; } -ov::frontend::InputModel::Ptr FrontEndTF::load_impl(const std::vector>& variants) const { +ov::frontend::InputModel::Ptr FrontEndTF::load_impl(const std::vector& variants) const { // TODO: Support other TensorFlow formats: SavedModel, .meta, checkpoint, pbtxt if (variants.size() == 1) { // a case when binary protobuf format is provided - if (ov::is_type>(variants[0])) { + if (variants[0].is()) { std::string suffix = ".pb"; - std::string model_path = ov::as_type_ptr>(variants[0])->get(); + std::string model_path = variants[0].as(); if (ov::util::ends_with(model_path, suffix.c_str())) { return std::make_shared( std::make_shared<::ov::frontend::tf::GraphIteratorProto>(model_path), m_telemetry); } - } else if (ov::is_type>(variants[0])) { - auto graph_iterator = ov::as_type_ptr>(variants[0])->get(); + } else if (variants[0].is()) { + auto graph_iterator = variants[0].as(); return std::make_shared(graph_iterator, m_telemetry); } } diff --git a/src/frontends/tensorflow/src/model.cpp b/src/frontends/tensorflow/src/model.cpp index 695217d22e4..e3e1aa76531 100644 --- a/src/frontends/tensorflow/src/model.cpp +++ b/src/frontends/tensorflow/src/model.cpp @@ -116,12 +116,10 @@ void InputModelTF::InputModelTFImpl::loadPlaces() { m_op_places.push_back(op_place); m_op_places_map[op_name] = op_place; if (op_type == "Placeholder") { - auto pshape = std::dynamic_pointer_cast>( - node_decoder->get_attribute("shape", VariantWrapper::get_type_info_static())); - auto type = std::dynamic_pointer_cast>( - node_decoder->get_attribute("dtype", VariantWrapper::get_type_info_static())); + auto pshape = node_decoder->get_attribute("shape", typeid(ov::PartialShape)).as(); + auto type = node_decoder->get_attribute("dtype", typeid(ov::element::Type)).as(); std::vector names = {op_name}; - auto tensor_place = std::make_shared(m_input_model, pshape->get(), type->get(), names); + auto tensor_place = std::make_shared(m_input_model, pshape, type, names); m_tensor_places[op_name] = tensor_place; m_inputs.push_back(tensor_place); } diff --git a/src/frontends/tensorflow/src/node_context.hpp b/src/frontends/tensorflow/src/node_context.hpp index 28a8729140f..2913a2fa799 100644 --- a/src/frontends/tensorflow/src/node_context.hpp +++ b/src/frontends/tensorflow/src/node_context.hpp @@ -3,38 +3,14 @@ // #pragma once +#include #include "exceptions.hpp" -#include "openvino/core/any.hpp" -#include "openvino/core/variant.hpp" #include "place.hpp" #include "tensor.pb.h" #include "tensorflow_frontend/utility.hpp" #include "types.pb.h" -#define OPENVINO_VARIANT_DECLARATION(TYPE, info) \ - template <> \ - class VariantWrapper : public VariantImpl { \ - public: \ - OPENVINO_RTTI(info); \ - VariantWrapper(const value_type& value) : VariantImpl(value) {} \ - } - -namespace ov { -OPENVINO_VARIANT_DECLARATION(int32_t, "Variant::int32"); -OPENVINO_VARIANT_DECLARATION(uint64_t, "Variant::uint64_t"); -OPENVINO_VARIANT_DECLARATION(std::vector, "Variant::int32_vector"); -OPENVINO_VARIANT_DECLARATION(float, "Variant::float"); -OPENVINO_VARIANT_DECLARATION(std::vector, "Variant::float_vector"); -OPENVINO_VARIANT_DECLARATION(bool, "Variant::bool"); -OPENVINO_VARIANT_DECLARATION(ov::element::Type, "Variant::ov_element_type"); -OPENVINO_VARIANT_DECLARATION(std::vector, "Variant::int64_vector"); -OPENVINO_VARIANT_DECLARATION(ov::PartialShape, "Variant:ov_PartialShape"); -OPENVINO_VARIANT_DECLARATION(std::vector, "Variant::string_vector"); -OPENVINO_VARIANT_DECLARATION(::tensorflow::DataType, "Variant::DataType"); -OPENVINO_VARIANT_DECLARATION(::tensorflow::TensorProto, "Variant::TensorProto"); -} // namespace ov - namespace ov { namespace frontend { namespace tf { @@ -55,11 +31,9 @@ public: /// Returns node attribute by name. Returns 'def' value if attribute does not exist template T get_attribute(const std::string& name, const T& def) const { - auto res = m_decoder.get_attribute(name, VariantWrapper::get_type_info_static()); - if (res) { - auto ret = std::dynamic_pointer_cast>(res); - FRONT_END_GENERAL_CHECK(ret, "Attribute with name '", name, "' has invalid type"); - return ret->get(); + auto res = m_decoder.get_attribute(name, typeid(T)); + if (!res.empty()) { + return res.as(); } return def; } @@ -67,17 +41,15 @@ public: /// Returns node attribute by name template T get_attribute(const std::string& name) const { - auto res = m_decoder.get_attribute(name, VariantWrapper::get_type_info_static()); - FRONT_END_GENERAL_CHECK(res, "Attribute with name '", name, "' does not exist"); - auto ret = std::dynamic_pointer_cast>(res); - FRONT_END_GENERAL_CHECK(ret, "Attribute with name '", name, "' has invalid type"); - return ret->get(); + auto res = m_decoder.get_attribute(name, typeid(T)); + FRONT_END_GENERAL_CHECK(!res.empty(), "Attribute with name '", name, "' does not exist"); + return res.as(); } /// Check if an attribute of a given name exists template bool has_attribute(const std::string& name) const { - return m_decoder.get_attribute(name, VariantWrapper::get_type_info_static()) != nullptr; + return !m_decoder.get_attribute(name, typeid(T)).empty(); } /// Detects if there is at least one input attached with a given name diff --git a/src/frontends/tensorflow/src/utils.hpp b/src/frontends/tensorflow/src/utils.hpp index 7ab6aa9f093..6de7e432ee2 100644 --- a/src/frontends/tensorflow/src/utils.hpp +++ b/src/frontends/tensorflow/src/utils.hpp @@ -91,18 +91,8 @@ void get_const_input(const NodeContext& node, int64_t input_index, std::vector void values_from_const_node(const NodeContext& node, ov::Shape* const_tensor_shape, std::vector* values) { TF_OP_VALIDATION_CHECK(node, node.get_op_type() == "Const", "Node is expected to be Constant."); - const auto* decoder = node.get_decoder(); - auto dt1 = decoder->get_attribute("dtype", ::ov::VariantWrapper<::tensorflow::DataType>::get_type_info_static()); - FRONT_END_GENERAL_CHECK(dt1 != nullptr); - auto dt = std::dynamic_pointer_cast<::ov::VariantWrapper<::tensorflow::DataType>>(dt1)->get(); - - auto tensor_proto_var = - decoder->get_attribute("value", ::ov::VariantWrapper<::tensorflow::TensorProto>::get_type_info_static()); - FRONT_END_GENERAL_CHECK(tensor_proto_var != nullptr); - - auto tensor_proto = - std::dynamic_pointer_cast<::ov::VariantWrapper<::tensorflow::TensorProto>>(tensor_proto_var)->get(); - + auto dt = node.get_attribute<::tensorflow::DataType>("dtype"); + auto tensor_proto = node.get_attribute<::tensorflow::TensorProto>("value"); const tensorflow::TensorShapeProto& shape = tensor_proto.tensor_shape(); ov::PartialShape pshape; tf_shape_to_ov_shape(shape, &pshape); diff --git a/src/inference/src/cnn_network_ngraph_impl.cpp b/src/inference/src/cnn_network_ngraph_impl.cpp index 69741ad39bf..4a704d2f600 100644 --- a/src/inference/src/cnn_network_ngraph_impl.cpp +++ b/src/inference/src/cnn_network_ngraph_impl.cpp @@ -24,6 +24,7 @@ #include "ngraph/pass/manager.hpp" #include "openvino/core/except.hpp" #include "openvino/pass/serialize.hpp" +#include "transformations/fix_rt_info.hpp" #include "transformations/smart_reshape/set_batch_size.hpp" #include "transformations/smart_reshape/smart_reshape.hpp" #include "transformations/utils/utils.hpp" @@ -132,6 +133,11 @@ CNNNetworkNGraphImpl::CNNNetworkNGraphImpl(const std::shared_ptr& nGra : _ngraph_function(nGraph), _ie_extensions(exts), _new_api(newAPI) { + { + ov::pass::Manager m; + m.register_pass(); + m.run_passes(_ngraph_function); + } // Restore usual attributes for CNNNetwork auto keep_input_info = [=](CNNNetworkNGraphImpl& network, const DataPtr& inData) { InputInfo::Ptr info(new InputInfo()); @@ -188,6 +194,11 @@ CNNNetworkNGraphImpl::CNNNetworkNGraphImpl(const CNNNetwork& network) { } _ngraph_function = ngraph::clone_function(*network.getFunction()); + { + ov::pass::Manager m; + m.register_pass(); + m.run_passes(_ngraph_function); + } validateFunctionNames(); InputsDataMap inputs = network.getInputsInfo(); OutputsDataMap outputs = network.getOutputsInfo(); @@ -427,9 +438,8 @@ void CNNNetworkNGraphImpl::reshape(const std::map(); manager.register_pass(); manager.register_pass<::ngraph::pass::ConvertNMS5ToLegacyMatcher>(false); - // TODO [DS NMS]: remove when nodes from models where nms is not last node in model supports DS - manager.register_pass<::ngraph::pass::ConvertMulticlassNmsToMulticlassNmsIE>(false); - manager.register_pass<::ngraph::pass::ConvertMatrixNmsToMatrixNmsIE>(false); + manager.register_pass<::ngraph::pass::ConvertMulticlassNmsToMulticlassNmsIE>(); + manager.register_pass<::ngraph::pass::ConvertMatrixNmsToMatrixNmsIE>(); manager.register_pass<::ngraph::pass::DisableConvertConstantFoldingOnConstPath>(); manager.register_pass<::ngraph::pass::ConstantFolding>(); // OneHotToLegacy changes output precision diff --git a/src/inference/src/compilation_context.cpp b/src/inference/src/compilation_context.cpp index 1f22668c0da..c2228677fdd 100644 --- a/src/inference/src/compilation_context.cpp +++ b/src/inference/src/compilation_context.cpp @@ -19,6 +19,7 @@ #include "ngraph/opsets/opset6.hpp" #include "ngraph/variant.hpp" #include "openvino/pass/manager.hpp" +#include "transformations/fix_rt_info.hpp" #include "transformations/hash.hpp" #include "transformations/rt_info/fused_names_attribute.hpp" #include "transformations/rt_info/primitives_priority_attribute.hpp" @@ -72,6 +73,7 @@ std::string NetworkCompilationContext::computeHash(const CNNNetwork& network, // 1. Calculate hash on function CNNNetwork net(network); ov::pass::Manager m; + m.register_pass(); m.register_pass(seed); m.run_passes(net.getFunction()); @@ -85,18 +87,9 @@ std::string NetworkCompilationContext::computeHash(const CNNNetwork& network, const auto& rt = op->get_rt_info(); for (const auto& rtMapData : rt) { seed = hash_combine(seed, rtMapData.first); - - if (auto stringData = std::dynamic_pointer_cast>(rtMapData.second)) { - seed = hash_combine(seed, stringData->get()); - } else if (auto intData = - std::dynamic_pointer_cast>(rtMapData.second)) { - seed = hash_combine(seed, intData->get()); - } else if (auto fNames = - std::dynamic_pointer_cast>(rtMapData.second)) { - seed = hash_combine(seed, fNames->get().getNames()); - } else if (auto prim = std::dynamic_pointer_cast(rtMapData.second)) { - seed = hash_combine(seed, prim->get()); - } + std::stringstream strm; + rtMapData.second.print(strm); + seed = hash_combine(seed, strm.str()); } } diff --git a/src/inference/src/cpp_interfaces/interface/ie_iplugin_internal.cpp b/src/inference/src/cpp_interfaces/interface/ie_iplugin_internal.cpp index 1d0469e1ba1..0ffa5e1e1b2 100644 --- a/src/inference/src/cpp_interfaces/interface/ie_iplugin_internal.cpp +++ b/src/inference/src/cpp_interfaces/interface/ie_iplugin_internal.cpp @@ -29,7 +29,7 @@ #include "openvino/core/deprecated.hpp" #include "openvino/core/except.hpp" #include "openvino/core/function.hpp" -#include "openvino/core/variant.hpp" +#include "openvino/core/runtime_attribute.hpp" #include "transformations/utils/utils.hpp" namespace InferenceEngine { @@ -296,7 +296,7 @@ void IInferencePlugin::SetExeNetworkInfo(const std::shared_ptrget_rt_info(); const auto it = rt_info.find("version"); if (it != rt_info.end()) { - auto ir_version_impl = std::dynamic_pointer_cast>(it->second); + auto ir_version_impl = std::dynamic_pointer_cast>(it->second); OPENVINO_ASSERT(ir_version_impl != nullptr, "Failed to extract IR version from 'version' attribute"); const int64_t ir_version = ir_version_impl->get(); // here we decide whether we need to add operation_names as tensor names for diff --git a/src/inference/src/ie_core.cpp b/src/inference/src/ie_core.cpp index 5c535af6982..59615b77432 100644 --- a/src/inference/src/ie_core.cpp +++ b/src/inference/src/ie_core.cpp @@ -199,7 +199,7 @@ class CoreImpl : public ie::ICore, public std::enable_shared_from_this supportedMetricKeys = plugin.get_metric(METRIC_KEY(SUPPORTED_METRICS), {}); auto it = std::find(supportedMetricKeys.begin(), supportedMetricKeys.end(), METRIC_KEY(IMPORT_EXPORT_SUPPORT)); - bool supported = + auto supported = (it != supportedMetricKeys.end()) && plugin.get_metric(METRIC_KEY(IMPORT_EXPORT_SUPPORT), {}).as(); return supported; } diff --git a/src/inference/src/ie_network_reader.cpp b/src/inference/src/ie_network_reader.cpp index 3d2dd117128..c4ca40e531b 100644 --- a/src/inference/src/ie_network_reader.cpp +++ b/src/inference/src/ie_network_reader.cpp @@ -301,7 +301,7 @@ CNNNetwork convert_to_cnnnetwork(std::shared_ptr& function, using namespace ov::preprocess; PrePostProcessor prepost(function); - auto ir_version_impl = std::dynamic_pointer_cast>(it->second); + auto ir_version_impl = it->second.as>>(); OPENVINO_ASSERT(ir_version_impl != nullptr, "Failed to extract IR version from 'version' attribute"); const int64_t ir_version = ir_version_impl->get(); @@ -347,7 +347,7 @@ CNNNetwork convert_to_cnnnetwork(std::shared_ptr& function, function = prepost.build(); // Set version to 10 - rt_info["version"] = std::make_shared>(10); + rt_info["version"] = std::make_shared>(10); } else if (ir_version == 11 && !newAPI) { const std::string& old_api_map_key_order = ov::OldApiMapOrder::get_type_info_static(); const std::string& old_api_map_key_type = ov::OldApiMapElementType::get_type_info_static(); @@ -359,9 +359,7 @@ CNNNetwork convert_to_cnnnetwork(std::shared_ptr& function, const auto it_type = rtInfo.find(old_api_map_key_type); auto& pre_input = prepost.input(i); if (it_type != rtInfo.end()) { - const auto old_api_map_attr = std::dynamic_pointer_cast(it_type->second); - OPENVINO_ASSERT(old_api_map_attr != nullptr, "Failed to cast to ov::OldApiMapElementType"); - const auto type = old_api_map_attr->get(); + auto type = it_type->second.as().value; pre_input.tensor().set_element_type(type); OPENVINO_ASSERT(!type.is_dynamic(), "Old API map does not support dynamic type"); @@ -369,9 +367,7 @@ CNNNetwork convert_to_cnnnetwork(std::shared_ptr& function, } const auto it_order = rtInfo.find(old_api_map_key_order); if (it_order != rtInfo.end()) { - const auto old_api_map_attr = std::dynamic_pointer_cast(it_order->second); - OPENVINO_ASSERT(old_api_map_attr != nullptr, "Failed to cast to ov::OldApiMapOrder"); - const auto order = old_api_map_attr->get(); + const auto order = it_order->second.as().value; pre_input.preprocess().convert_layout(order); rtInfo.erase(it_order); } @@ -385,9 +381,7 @@ CNNNetwork convert_to_cnnnetwork(std::shared_ptr& function, if (it == rtInfo.end()) continue; - const auto old_api_map_attr = std::dynamic_pointer_cast(it->second); - OPENVINO_ASSERT(old_api_map_attr != nullptr, "Failed to cast to ov::OldApiMapOrder"); - const auto order = old_api_map_attr->get(); + const auto order = it->second.as().value; auto& post_output = prepost.output(i); post_output.postprocess().convert_layout(order); @@ -396,7 +390,7 @@ CNNNetwork convert_to_cnnnetwork(std::shared_ptr& function, } // Set version to 10 - rt_info["version"] = std::make_shared>(10); + rt_info["version"] = std::make_shared>(10); function = prepost.build(); } @@ -459,7 +453,7 @@ CNNNetwork details::ReadNetwork(const std::string& modelPath, ov::frontend::FrontEnd::Ptr FE; ov::frontend::InputModel::Ptr inputModel; - ov::VariantVector params{ov::make_variant(model_path)}; + ov::RuntimeAttributeVector params{model_path}; if (!binPath.empty()) { #if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) @@ -467,7 +461,7 @@ CNNNetwork details::ReadNetwork(const std::string& modelPath, #else const std::string& weights_path = binPath; #endif - params.emplace_back(ov::make_variant(weights_path)); + params.emplace_back(weights_path); } FE = manager.load_by_model(params); @@ -525,12 +519,12 @@ CNNNetwork details::ReadNetwork(const std::string& model, ov::frontend::FrontEnd::Ptr FE; ov::frontend::InputModel::Ptr inputModel; - ov::VariantVector params{ov::make_variant(&modelStream)}; + ov::RuntimeAttributeVector params{&modelStream}; if (weights) { char* data = weights->cbuffer().as(); std::shared_ptr weights_buffer = std::make_shared>(data, weights->byteSize(), weights); - params.emplace_back(ov::make_variant(weights_buffer)); + params.emplace_back(weights_buffer); } FE = manager.load_by_model(params); diff --git a/src/plugins/hetero/executable_network.cpp b/src/plugins/hetero/executable_network.cpp index c79090d9c12..61586fbf7b3 100644 --- a/src/plugins/hetero/executable_network.cpp +++ b/src/plugins/hetero/executable_network.cpp @@ -82,10 +82,8 @@ HeteroExecutableNetwork::HeteroExecutableNetwork(const InferenceEngine::CNNNetwo auto& nodeInfo = node->get_rt_info(); auto itInfo = nodeInfo.find("affinity"); if (itInfo != nodeInfo.end()) { - IE_ASSERT((ngraph::is_type>(itInfo->second))); - queryNetworkResult.supportedLayersMap.emplace( - node->get_friendly_name(), - ngraph::as_type_ptr>(itInfo->second)->get()); + IE_ASSERT(itInfo->second.is()); + queryNetworkResult.supportedLayersMap.emplace(node->get_friendly_name(), itInfo->second.as()); allEmpty = false; } }