Variant replaced with Runtime Attribute (#8520)

This commit is contained in:
Anton Pankratov authored and GitHub committed 2021-12-07 13:02:31 +03:00
1 parent 2e290a6e72
commit 9a5b911856
189 files changed
+1771 -2178

No files matched your search

+23 -23
View File
@@ -47,7 +47,7 @@ For examples of how to build an nGraph function, see the [Build nGraph Function]
## Transformations types <a name="transformations_types"></a>
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<Node> neg_const = opset1::Constant::create(sub->get_input_elemen
Output<Node> data = node->input_value(0);
auto neg = std::make_shared<ngraph::opset1::Multiply>(data, neg_const);
```
In this example, the `opset3::Multiply` operation takes `Output<Node>` and `std::shared_ptr<Node>` as inputs. But the constructor takes both as `Output<Node>`.
In this case, `std::shared_ptr<Node>` will be automatically converted to `Output<Node>` if node has exactly one output port; otherwise, conversion raises an exception.
In this example, the `opset3::Multiply` operation takes `Output<Node>` and `std::shared_ptr<Node>` as inputs. But the constructor takes both as `Output<Node>`.
In this case, `std::shared_ptr<Node>` will be automatically converted to `Output<Node>` 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<std::string, std::shared_ptr<Variant>>` located inside `ngraph::Node` class. It represents additional attributes in `ngraph::Node`.
Runtime info is a map `std::map<std::string, ov::Any>` 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<ngraph::opset3::Power>(
opset3::Constant::create(element::f32, Shape{1}, {2})
opset3::Constant::create(element::f32, Shape{1}, {3}));
auto mul = std::make_shared<ngraph::opset3::Multiply>(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<Node>` 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 <a name="using_pass_manager"></a>
`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`
+1 -1
View File
@@ -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<bool>();
auto cachingSupported = (it != keys.end()) && ie.GetMetric(deviceName, METRIC_KEY(IMPORT_EXPORT_SUPPORT)).as<bool>();
//! [part3]
return 0;
}
@@ -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<bool>();
auto defaultPerfCount = ie.GetConfig(deviceName, CONFIG_KEY(PERF_COUNT)).as<bool>();
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<bool>();
auto defaultExclusive = ie.GetConfig(deviceName, CONFIG_KEY(EXCLUSIVE_ASYNC_REQUESTS)).as<bool>();
std::cout << CONFIG_KEY(EXCLUSIVE_ASYNC_REQUESTS) << " : " << defaultExclusive << std::endl;
}
}
@@ -186,7 +186,7 @@ std::shared_ptr<ngraph::Function> 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<std::string>>(kvp.second);
return_node->get_rt_info()[kvp.first] = std::make_shared<::ov::RuntimeAttributeWrapper<std::string>>(kvp.second);
return_node->set_friendly_name(node->getName());
return return_node;
@@ -137,7 +137,7 @@ MKLDNNNode::MKLDNNNode(const std::shared_ptr<ngraph::Node>& 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<ngraph::Node>& 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<ngraph::Node>& op, const mkldnn::en
const auto it = rtInfo.find("enforceBF16evenForGraphTail");
if (it != rtInfo.end()) {
if (const auto value = std::dynamic_pointer_cast<ngraph::VariantImpl<int64_t>>(it->second))
if (const auto value = std::dynamic_pointer_cast<ov::RuntimeAttributeImpl<int64_t>>(it->second))
enforceBF16evenForGraphTail = value->get();
}
}
@@ -67,7 +67,7 @@ namespace {
ngraph::replace_node(transposeAfter, {reshape2->output(0)});
}
sequenceOp->get_rt_info()["seqAxis"] = std::make_shared<ngraph::VariantWrapper<int64_t>>(seqAxis);
sequenceOp->get_rt_info()["seqAxis"] = std::make_shared<ov::RuntimeAttributeWrapper<int64_t>>(seqAxis);
return true;
}
@@ -367,7 +367,7 @@ void MKLDNNRNN::initSeq(const std::shared_ptr<ngraph::Node>& op) {
const auto rtInfo = op->get_rt_info();
if (rtInfo.count("seqAxis")) {
nativeOrder = std::dynamic_pointer_cast<ngraph::VariantWrapper<int64_t>>(rtInfo.at("seqAxis"))->get() == 0;
nativeOrder = std::dynamic_pointer_cast<ov::RuntimeAttributeWrapper<int64_t>>(rtInfo.at("seqAxis"))->get() == 0;
}
out_data_dims.erase(out_data_dims.begin() + 1);
@@ -13,7 +13,7 @@ namespace MKLDNNPlugin {
inline std::string getRTInfoValue(const std::map<std::string, ov::Any>& rtInfo, std::string paramName) {
auto it = rtInfo.find(paramName);
if (it != rtInfo.end()) {
auto value = std::dynamic_pointer_cast<ngraph::VariantImpl<std::string>>(it->second);
auto value = std::dynamic_pointer_cast<ov::RuntimeAttributeImpl<std::string>>(it->second);
return value->get();
} else {
return "";
@@ -23,10 +23,13 @@ inline std::string getRTInfoValue(const std::map<std::string, ov::Any>& rtInfo,
inline std::string getPrimitivesPriorityValue(const std::shared_ptr<ngraph::Node> &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<ov::PrimitivesPriority>(attr)->get();
if (it_info == rtInfo.end()) {
return {};
}
return it_info->second.as<ov::PrimitivesPriority>().value;
}
template <typename T>
@@ -11,25 +11,25 @@
using namespace ngraph;
using namespace ov;
MLKDNNInputMemoryFormats::~MLKDNNInputMemoryFormats() = default;
MKLDNNInputMemoryFormats::~MKLDNNInputMemoryFormats() = default;
std::string ngraph::getMLKDNNInputMemoryFormats(const std::shared_ptr<ngraph::Node>& node) {
auto it_info = node->get_rt_info().find(MLKDNNInputMemoryFormatsAttr);
std::string ngraph::getMKLDNNInputMemoryFormats(const std::shared_ptr<ngraph::Node>& 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<std::shared_ptr<MLKDNNInputMemoryFormats>>()) {
return ptr->getMemoryFormats();
if (it_info->second.is<MKLDNNInputMemoryFormats>()) {
return it_info->second.as<MKLDNNInputMemoryFormats>().getMemoryFormats();
}
}
return {};
}
MLKDNNOutputMemoryFormats::~MLKDNNOutputMemoryFormats() = default;
MKLDNNOutputMemoryFormats::~MKLDNNOutputMemoryFormats() = default;
std::string ngraph::getMLKDNNOutputMemoryFormats(const std::shared_ptr<ngraph::Node>& node) {
auto it_info = node->get_rt_info().find(MLKDNNOutputMemoryFormatsAttr);
std::string ngraph::getMKLDNNOutputMemoryFormats(const std::shared_ptr<ngraph::Node>& 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<std::shared_ptr<MLKDNNOutputMemoryFormats>>()) {
return ptr->getMemoryFormats();
if (it_info->second.is<MKLDNNOutputMemoryFormats>()) {
return it_info->second.as<MKLDNNOutputMemoryFormats>().getMemoryFormats();
}
}
return {};
@@ -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<typename MemoryFormat>
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<std::string> 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::shared_ptr<MemoryFormat>>()) {
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<MemoryFormat>().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<MemoryFormat>(final_mem_format);
return MemoryFormat{final_mem_format};
}
};
class MLKDNNInputMemoryFormats : public MLKDNNMemoryFormats<MLKDNNInputMemoryFormats> {
class MKLDNNInputMemoryFormats : public MKLDNNMemoryFormats<MKLDNNInputMemoryFormats> {
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<ngraph::Node>& node);
std::string getMKLDNNInputMemoryFormats(const std::shared_ptr<ngraph::Node>& node);
class MLKDNNOutputMemoryFormats : public MLKDNNMemoryFormats<MLKDNNOutputMemoryFormats> {
class MKLDNNOutputMemoryFormats : public MKLDNNMemoryFormats<MKLDNNOutputMemoryFormats> {
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<ngraph::Node>& node);
std::string getMKLDNNOutputMemoryFormats(const std::shared_ptr<ngraph::Node>& node);
} // namespace ngraph
@@ -16,7 +16,6 @@
#include <set>
#include <ngraph/node.hpp>
#include <ngraph/variant.hpp>
namespace ngraph {
@@ -28,6 +27,11 @@ namespace ngraph {
class Mask : public std::vector<std::set<uint64_t>>,
public std::enable_shared_from_this<Mask> {
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>;
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<Node> & output);
void setMask(Output<Node> output, const Mask::Ptr & mask);
} // namespace ngraph
namespace ov {
extern template class VariantImpl<ngraph::Mask::Ptr>;
template<>
class VariantWrapper<ngraph::Mask::Ptr> : public VariantImpl<ngraph::Mask::Ptr> {
public:
OPENVINO_RTTI("VariantWrapper<Mask::Ptr>");
BWDCMP_RTTI_DECLARATION;
static std::shared_ptr<VariantWrapper<ngraph::Mask::Ptr>> create(const value_type & value) {
return std::make_shared<VariantWrapper<ngraph::Mask::Ptr>>(value);
}
explicit VariantWrapper(const value_type &value) : VariantImpl<value_type>(value) {}
};
} // namespace ov
@@ -14,28 +14,22 @@ namespace ngraph {
Mask::Ptr getMask(const Output<const Node> & output) {
auto &rtInfo = output.get_rt_info();
using MaskWrapper = VariantWrapper<Mask::Ptr>;
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<MaskWrapper>(attr)->get();
const auto &attr = rtInfo.at(Mask::get_type_info_static());
return attr.as<Mask::Ptr>();
}
Mask::Ptr getMask(const Output<Node> & output) {
auto &rtInfo = output.get_rt_info();
using MaskWrapper = VariantWrapper<Mask::Ptr>;
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<MaskWrapper>(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<Mask::Ptr>();
}
void setMask(Output<Node> output, const Mask::Ptr & mask) {
auto &rtInfo = output.get_rt_info();
using MaskWrapper = VariantWrapper<Mask::Ptr>;
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<ngraph::Mask::Ptr>;
BWDCMP_RTTI_DEFINITION(VariantWrapper<ngraph::Mask::Ptr>);
} // namespace ov
@@ -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<ngraph::FusedNames>::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<ngraph::FusedNames>::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<ngraph::FusedNames>::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<VariantWrapper<ngraph::FusedNames>>(info.at(key));
ASSERT_TRUE(fused_names_attr);
EXPECT_EQ(fused_names_attr->get().getNames(), names);
auto fused_names_attr = info.at(key).as<ngraph::FusedNames>();
EXPECT_EQ(fused_names_attr.getNames(), names);
};
auto check_old_api_map_order = [](const RTMap & info, const std::vector<uint64_t> & 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<ov::OldApiMapOrder>(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<ov::OldApiMapOrder>().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<ov::OldApiMapElementType>(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<ov::OldApiMapElementType>().value;
EXPECT_EQ(old_api_map_attr_val, type);
};
@@ -501,8 +496,7 @@ TEST_F(RTInfoDeserialization, NodeV11) {
auto round = std::make_shared<opset8::Round>(convert_param,
ngraph::opset8::Round::RoundMode::HALF_TO_EVEN);
// TODO: runtime information should migrate as well?
round->get_rt_info()[VariantWrapper<ngraph::FusedNames>::get_type_info_static()] =
std::make_shared<VariantWrapper<ngraph::FusedNames>>(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<opset8::Constant>(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<ngraph::FusedNames>::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<VariantWrapper<ngraph::FusedNames>>(info.at(key));
ASSERT_TRUE(fused_names_attr);
ASSERT_EQ(fused_names_attr->get().getNames(), names);
auto fused_names_attr = info.at(key).as<ngraph::FusedNames>();
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<ov::preprocess::TensorInfoMemoryType>(
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<ov::preprocess::TensorInfoMemoryType>().value;
EXPECT_EQ(var0, "test_memory_type");
auto result = f->get_result();
check_fused_names(result->input(0).get_rt_info(), "test5,test6");
@@ -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<ngraph::FusedNames>::get_type_info_static()] =
std::make_shared<VariantWrapper<ngraph::FusedNames>>(ngraph::FusedNames("add"));
info[ov::PrimitivesPriority::get_type_info_static()] =
std::make_shared<ov::PrimitivesPriority>("priority");
info[ov::OldApiMapOrder::get_type_info_static()] =
std::make_shared<ov::OldApiMapOrder>(std::vector<uint64_t>{0, 2, 3, 1});
info[ov::OldApiMapElementType::get_type_info_static()] = std::make_shared<ov::OldApiMapElementType>(
ngraph::element::Type_t::f32);
info[ov::Decompression::get_type_info_static()] = std::make_shared<ov::Decompression>();
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<uint64_t>{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<ngraph::Function> 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<ngraph::FusedNames>::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<VariantWrapper<ngraph::FusedNames>>(info.at(key));
ASSERT_TRUE(fused_names_attr);
ASSERT_EQ(fused_names_attr->get().getNames(), "add");
auto fused_names_attr = info.at(key).as<ngraph::FusedNames>();
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<ov::PrimitivesPriority>(info.at(pkey));
ASSERT_TRUE(primitives_priority_attr);
ASSERT_EQ(primitives_priority_attr->get(), "priority");
auto primitives_priority_attr = info.at(pkey).as<ov::PrimitivesPriority>().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<ov::OldApiMapOrder>(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<ov::OldApiMapOrder>().value;
ASSERT_EQ(old_api_map_attr_val, std::vector<uint64_t>({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<ov::OldApiMapElementType>(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<ov::OldApiMapElementType>().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<ov::Decompression>(info.at(dkey));
ASSERT_TRUE(decompression_attr);
ASSERT_NO_THROW(info.at(dkey).as<ov::Decompression>());
};
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<ngraph::FusedNames>::get_type_info_static()] =
std::make_shared<VariantWrapper<ngraph::FusedNames>>(ngraph::FusedNames("add"));
info[ov::PrimitivesPriority::get_type_info_static()] =
std::make_shared<ov::PrimitivesPriority>("priority");
info[ngraph::FusedNames::get_type_info_static()] = ngraph::FusedNames("add");
info["PrimitivesPriority"] = ov::PrimitivesPriority("priority");
};
std::shared_ptr<ngraph::Function> 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<ngraph::FusedNames>::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<ngraph::FusedNames>::get_type_info_static()] =
std::make_shared<VariantWrapper<ngraph::FusedNames>>(ngraph::FusedNames("add"));
info[ov::PrimitivesPriority::get_type_info_static()] =
std::make_shared<ov::PrimitivesPriority>("priority");
info[ngraph::FusedNames::get_type_info_static()] = ngraph::FusedNames("add");
info[ov::PrimitivesPriority::get_type_info_static()] = ov::PrimitivesPriority("priority");
};
std::shared_ptr<ngraph::Function> 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<ngraph::FusedNames>::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<VariantWrapper<ngraph::FusedNames>>(info.at(key));
ASSERT_TRUE(fused_names_attr);
ASSERT_EQ(fused_names_attr->get().getNames(), "add");
auto fused_names_attr = info.at(key).as<ngraph::FusedNames>();
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<ov::PrimitivesPriority>(info.at(pkey));
ASSERT_TRUE(primitives_priority_attr);
ASSERT_EQ(primitives_priority_attr->get(), "priority");
auto primitives_priority_attr = info.at(pkey).as<ov::PrimitivesPriority>().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<ov::preprocess::TensorInfoMemoryType>(
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<ov::preprocess::TensorInfoMemoryType>().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());
@@ -199,9 +199,9 @@ public:
testValues.result.convert2,
testValues.result.dequantization2,
{
make_shared_attribute_ptr<PrecisionPreservedAttribute>(true),
make_shared_attribute_ptr<IntervalsAlignmentAttribute>(interval, 256),
make_shared_attribute_ptr<QuantizationAlignmentAttribute>(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<opset1::FakeQuantize>(actualFunction);
if (testValues.axis == 1) {
ASSERT_TRUE(checkIfOutputAttributesSharedValuesAreTheSame<std::shared_ptr<PrecisionsAttribute>>(actualFakeQuantizes)) <<
ASSERT_TRUE(checkIfOutputAttributesSharedValuesAreTheSame<PrecisionsAttribute>(actualFakeQuantizes)) <<
"PrecisionsAttribute are not the same";
if (testValues.checkIntervalsAlignmentAttributes) {
auto operations = LayerTransformation::get<opset1::Concat>(actualFunction);
operations.insert(operations.end(), actualFakeQuantizes.begin(), actualFakeQuantizes.end());
ASSERT_TRUE(checkIfAttributesSharedValuesAreTheSame<std::shared_ptr<IntervalsAlignmentAttribute>>(operations)) <<
ASSERT_TRUE(checkIfAttributesSharedValuesAreTheSame<IntervalsAlignmentAttribute>(operations)) <<
"IntervalsAlignmentAttribute are not the same";
}
}
@@ -275,13 +275,13 @@ const std::vector<ConcatTransformationTestValues> testValues = {
{
{
256ul, {}, {0.f}, {2550.f}, {0.f}, {255.f}, ngraph::element::u8,
{ make_shared_attribute_ptr<IntervalsAlignmentAttribute>(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<IntervalsAlignmentAttribute>(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
{ IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
},
{},
{},
@@ -304,7 +304,7 @@ const std::vector<ConcatTransformationTestValues> testValues = {
{
{
256ul, {}, {0.f}, {2.55f}, {0.f}, {2.55f}, ngraph::element::f32,
{ make_shared_attribute_ptr<IntervalsAlignmentAttribute>(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
{ IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
},
{},
{},
@@ -331,7 +331,7 @@ const std::vector<ConcatTransformationTestValues> testValues = {
{},
{
256ul, {}, {0.f}, {2.55f}, {0.f}, {2.55f}, ngraph::element::f32,
{ make_shared_attribute_ptr<IntervalsAlignmentAttribute>(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
{ IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
},
{},
{},
@@ -352,13 +352,13 @@ const std::vector<ConcatTransformationTestValues> testValues = {
{
{
256ul, {}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8,
{ make_shared_attribute_ptr<IntervalsAlignmentAttribute>(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<IntervalsAlignmentAttribute>(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
{ IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
},
{},
{},
@@ -390,13 +390,13 @@ const std::vector<ConcatTransformationTestValues> testValues = {
{
{
256ul, {}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8,
{ make_shared_attribute_ptr<IntervalsAlignmentAttribute>(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<IntervalsAlignmentAttribute>(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
{ IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
},
{},
{},
@@ -428,13 +428,13 @@ const std::vector<ConcatTransformationTestValues> testValues = {
{
{
256ul, {}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8,
{ make_shared_attribute_ptr<IntervalsAlignmentAttribute>(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<IntervalsAlignmentAttribute>(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
{ IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
},
{},
{},
@@ -462,13 +462,13 @@ const std::vector<ConcatTransformationTestValues> testValues = {
{
{
256ul, {}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8,
{ make_shared_attribute_ptr<IntervalsAlignmentAttribute>(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<IntervalsAlignmentAttribute>(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
{ IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
},
{},
{},
@@ -496,13 +496,13 @@ const std::vector<ConcatTransformationTestValues> testValues = {
{
{
256ul, {}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8,
{ make_shared_attribute_ptr<IntervalsAlignmentAttribute>(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<IntervalsAlignmentAttribute>(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
{ IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
},
{},
{},
@@ -526,13 +526,13 @@ const std::vector<ConcatTransformationTestValues> testValues = {
{
{
256ul, {{1}, {1}, {}, {}}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8,
{ make_shared_attribute_ptr<IntervalsAlignmentAttribute>(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<IntervalsAlignmentAttribute>(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
{ IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
},
{},
{},
@@ -556,13 +556,13 @@ const std::vector<ConcatTransformationTestValues> 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<IntervalsAlignmentAttribute>(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<IntervalsAlignmentAttribute>(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
{ IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
},
{},
{},
@@ -586,13 +586,13 @@ const std::vector<ConcatTransformationTestValues> testValues = {
{
{
256ul, {}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8,
{ make_shared_attribute_ptr<IntervalsAlignmentAttribute>(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<IntervalsAlignmentAttribute>(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
{ IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
},
{},
{},
@@ -616,13 +616,13 @@ const std::vector<ConcatTransformationTestValues> testValues = {
{
{
256ul, {{1}, {1}, {}, {}}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8,
{ make_shared_attribute_ptr<IntervalsAlignmentAttribute>(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<IntervalsAlignmentAttribute>(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
{ IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
},
{},
{},
@@ -657,7 +657,7 @@ const std::vector<ConcatTransformationTestValues> 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<IntervalsAlignmentAttribute>(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
{ IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
},
{},
{},
@@ -666,7 +666,7 @@ const std::vector<ConcatTransformationTestValues> 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<IntervalsAlignmentAttribute>(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
{ IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
},
{},
{},
@@ -692,13 +692,13 @@ const std::vector<ConcatTransformationTestValues> testValues = {
{
{
256ul, {}, {-1.28f}, {1.27f}, {-128.f}, {127.f}, ngraph::element::i8,
{ make_shared_attribute_ptr<IntervalsAlignmentAttribute>(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<IntervalsAlignmentAttribute>(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
{ IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
},
{},
{},
@@ -722,13 +722,13 @@ const std::vector<ConcatTransformationTestValues> testValues = {
{
{
256ul, {}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8,
{ make_shared_attribute_ptr<IntervalsAlignmentAttribute>(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<IntervalsAlignmentAttribute>(IntervalsAlignmentSharedValue::Interval{-1.28f, 2.55f}, 256ul) }
{ IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{-1.28f, 2.55f}, 256ul) }
},
{},
{},
@@ -752,13 +752,13 @@ const std::vector<ConcatTransformationTestValues> testValues = {
{
{
256ul, {}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8,
{ make_shared_attribute_ptr<IntervalsAlignmentAttribute>(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<IntervalsAlignmentAttribute>(IntervalsAlignmentSharedValue::Interval{-1.28f, 2.55f}, 256ul) }
{ IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{-1.28f, 2.55f}, 256ul) }
},
{},
{},
@@ -896,13 +896,13 @@ const std::vector<ConcatTransformationTestValues> testValues = {
{
{
256ul, {}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8,
{ make_shared_attribute_ptr<IntervalsAlignmentAttribute>(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<IntervalsAlignmentAttribute>(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
{ IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
},
{},
{},
@@ -940,13 +940,13 @@ const std::vector<ConcatTransformationTestValues> testValues = {
{
{
256ul, {}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8,
{ make_shared_attribute_ptr<IntervalsAlignmentAttribute>(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<IntervalsAlignmentAttribute>(IntervalsAlignmentSharedValue::Interval{-1.28f, 2.55f}, 256ul) }
{ IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{-1.28f, 2.55f}, 256ul) }
},
{},
{},
@@ -974,13 +974,13 @@ const std::vector<ConcatTransformationTestValues> testValues = {
{
{
256ul, {}, {0.f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8,
{ make_shared_attribute_ptr<IntervalsAlignmentAttribute>(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<IntervalsAlignmentAttribute>(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
{ IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul) }
},
{},
{},
@@ -1012,13 +1012,13 @@ const std::vector<ConcatTransformationTestValues> testValues = {
{
{
256ul, {}, {1.275f}, {2.55f}, {0.f}, {255.f}, ngraph::element::u8,
{ make_shared_attribute_ptr<IntervalsAlignmentAttribute>(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<IntervalsAlignmentAttribute>(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul)
{ IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{0.f, 2.55f}, 256ul)
}
},
{},
@@ -160,16 +160,16 @@ TEST_P(ConcatWithNeighborsWithConvolutionTransformation, CompareFunctions) {
auto actualFakeQuantizes = LayerTransformation::get<opset1::FakeQuantize>(actualFunction);
ASSERT_EQ(3ul, actualFakeQuantizes.size()) << "unexpected FakeQuantize operations count " << actualFakeQuantizes.size();
ASSERT_TRUE(checkIfOutputAttributesSharedValuesAreTheSame<std::shared_ptr<PrecisionsAttribute>>(actualFakeQuantizes)) <<
ASSERT_TRUE(checkIfOutputAttributesSharedValuesAreTheSame<PrecisionsAttribute>(actualFakeQuantizes)) <<
"PrecisionsAttribute shared values are not the same";
auto actualConcatOperations = LayerTransformation::get<opset1::Concat>(actualFunction);
ASSERT_EQ(2ul, actualConcatOperations.size()) << "unexpected concat operations";
ASSERT_NE(nullptr, ngraph::pass::low_precision::getAttribute<std::shared_ptr<QuantizationAlignmentAttribute>>(actualConcatOperations[0]));
ASSERT_NE(nullptr, ngraph::pass::low_precision::getAttribute<std::shared_ptr<QuantizationAlignmentAttribute>>(actualConcatOperations[1]));
ASSERT_FALSE(ngraph::pass::low_precision::getAttribute<QuantizationAlignmentAttribute>(actualConcatOperations[0]).empty());
ASSERT_FALSE(ngraph::pass::low_precision::getAttribute<QuantizationAlignmentAttribute>(actualConcatOperations[1]).empty());
actualConcatOperations.insert(actualConcatOperations.end(), actualFakeQuantizes.begin(), actualFakeQuantizes.end());
ASSERT_TRUE(checkIfAttributesSharedValuesAreTheSame<std::shared_ptr<IntervalsAlignmentAttribute>>(actualConcatOperations)) <<
ASSERT_TRUE(checkIfAttributesSharedValuesAreTheSame<IntervalsAlignmentAttribute>(actualConcatOperations)) <<
"IntervalsAlignmentAttribute shared values are not the same";
auto convolutions = LayerTransformation::get<opset1::Convolution>(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<ngraph::VariantWrapper<std::shared_ptr<PrecisionsAttribute>>>(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<PrecisionsAttribute>();
ASSERT_EQ(element::i8, a1.value().front());
}
const std::vector<ngraph::element::Type> precisions = {
@@ -204,15 +204,15 @@ const std::vector<ConcatWithNeighborsWithConvolutionTestValues> testValues = {
{
{
256ul, ngraph::Shape({}), {-1.28f / 3.f}, {1.27f / 3.f}, {0.f}, {255.f}, element::u8,
{ make_shared_attribute_ptr<IntervalsAlignmentAttribute>(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<IntervalsAlignmentAttribute>(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<IntervalsAlignmentAttribute>(IntervalsAlignmentSharedValue::Interval{-1.28f, 1.27f}, 256ul) }
{ IntervalsAlignmentAttribute(IntervalsAlignmentSharedValue::Interval{-1.28f, 1.27f}, 256ul) }
},
ngraph::element::u8,
{{}, {}, {}},
@@ -218,9 +218,9 @@ public:
testValues.result.dequantization2,
true,
{
make_shared_attribute_ptr<PrecisionPreservedAttribute>(true),
make_shared_attribute_ptr<IntervalsAlignmentAttribute>(IntervalsAlignmentSharedValue::Interval{-1.28f, 2.55f}, 256ul),
make_shared_attribute_ptr<QuantizationAlignmentAttribute>(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<std::shared_ptr<PrecisionsAttribute>>(actualFakeQuantizes)) <<
ASSERT_TRUE(checkIfOutputAttributesSharedValuesAreTheSame<PrecisionsAttribute>(actualFakeQuantizes)) <<
"PrecisionsAttribute are not the same";
ConcatWithNotQuantizedParentTransformationTestValues testValues = std::get<2>(GetParam());
if (testValues.checkIntervalsAlignmentAttributes) {
auto operations = LayerTransformation::get<opset1::Concat>(actualFunction);
operations.insert(operations.end(), actualFakeQuantizes.begin(), actualFakeQuantizes.end());
ASSERT_TRUE(checkIfAttributesSharedValuesAreTheSame<std::shared_ptr<IntervalsAlignmentAttribute>>(operations)) <<
ASSERT_TRUE(checkIfAttributesSharedValuesAreTheSame<IntervalsAlignmentAttribute>(operations)) <<
"IntervalsAlignmentAttribute are not the same";
}
}
@@ -169,7 +169,8 @@ const std::vector<ConvertSubtractConstantTransformationTestValues> 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<float>{ 2.f }, ngraph::element::i8},
@@ -284,7 +284,8 @@ const std::vector<ConvolutionBackpropDataTransformationTestValues> 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<float>{ 2.f }),
true
@@ -174,7 +174,8 @@ const std::vector<ConvolutionQDqTransformationTestValues> 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<float>{ 100.f }, ngraph::element::i8},
@@ -349,7 +350,8 @@ const std::vector<ConvolutionQDqTransformationTestValues> 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<float>{ 2.f }, ngraph::element::i8},
@@ -417,7 +419,8 @@ const std::vector<ConvolutionQDqTransformationTestValues> 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<float>{ 2.f }, ngraph::element::i8},
@@ -145,12 +145,14 @@ const std::vector<DisableConvertOnConstPathTransformationValues> 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<float>{ 1.f }, ngraph::element::f32},
@@ -198,7 +198,9 @@ const std::vector<FakeQuantizeWithNotOptimalTransformationTestValues> fakeQuanti
{},
{
{},
{ std::vector<float>(64, 127.f), ngraph::element::f32, {64, 1, 1, 1}, false, 1ul, ngraph::element::i8, false, {"disabled_constant_folding_0"}},
{ std::vector<float>(64, 127.f), ngraph::element::f32,
{64, 1, 1, 1}, false, 1ul, ngraph::element::i8, false,
{ov::pass::DisableConstantFolding::get_type_info_static()}},
{}
},
{
@@ -473,7 +473,7 @@ const std::vector<GroupConvolutionTestValues> testValuesGroupConv = {
1,
ngraph::element::i8,
false,
{"disabled_constant_folding_0"}
{ov::pass::DisableConstantFolding::get_type_info_static()}
},
{}
},
@@ -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<VariantWrapper<std::shared_ptr<IntervalsAlignmentAttribute>>>(it.second);
assert(reference != nullptr);
if ((reference->get()->sharedValue->combinedInterval.low != intervalLow) &&
(reference->get()->sharedValue->combinedInterval.high != intervalHigh)) {
auto& reference = it.second.as<IntervalsAlignmentAttribute>();
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<IntervalsAlignmentAttribute>& value1,
const std::shared_ptr<IntervalsAlignmentAttribute>& 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<VariantWrapper<Operation>>(referenceIt->second);
auto actual = std::dynamic_pointer_cast<VariantWrapper<Operation>>(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<Operation>(), actualIt.second.template as<Operation>())) {
return false;
}
}
@@ -139,24 +136,22 @@ public:
template <class Attribute>
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<Attribute>::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>().attribute != first.template as<Attribute>().attribute) {
return false;
}
OPENVINO_SUPPRESS_DEPRECATED_END
}
}
return true;
@@ -164,15 +159,15 @@ public:
template <class Attribute>
static bool checkIfOutputAttributesSharedValuesAreTheSame(const NodeVector& nodes) {
std::shared_ptr<Variant> first = nullptr;
ov::Any first;
for (auto node : nodes) {
for (auto output : node->outputs()) {
auto value = ngraph::pass::low_precision::getAttributeFromOutput<Attribute>(output);
if (first == nullptr) {
if (first.empty()) {
first = value;
} else {
const auto sharedValue1 = std::dynamic_pointer_cast<ngraph::VariantWrapper<Attribute>>(value)->get()->sharedValue;
const auto sharedValue2 = std::dynamic_pointer_cast<ngraph::VariantWrapper<Attribute>>(first)->get()->sharedValue;
const auto sharedValue1 = value.template as<Attribute>().attribute->sharedValue;
const auto sharedValue2 = first.template as<Attribute>().attribute->sharedValue;
if (sharedValue1 != sharedValue2) {
return false;
}
@@ -184,18 +179,18 @@ public:
template <class Attribute>
static bool checkIfAttributesSharedValuesAreTheSame(const NodeVector& nodes) {
std::shared_ptr<Variant> first = nullptr;
ov::Any first;
for (auto node : nodes) {
auto value = ngraph::pass::low_precision::getAttribute<Attribute>(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<ngraph::VariantWrapper<Attribute>>(value)->get()->sharedValue;
const auto sharedValue2 = std::dynamic_pointer_cast<ngraph::VariantWrapper<Attribute>>(first)->get()->sharedValue;
const auto sharedValue1 = value.template as<Attribute>().attribute->sharedValue;
const auto sharedValue2 = first.template as<Attribute>().attribute->sharedValue;
if (sharedValue1 != sharedValue2) {
return false;
}
@@ -206,16 +201,16 @@ public:
template <class Attribute>
static bool checkIfAttributesAreTheSame(const NodeVector& nodes) {
Variant* first = nullptr;
ov::Any first;
for (auto node : nodes) {
auto value = ngraph::pass::low_precision::getAttribute<Attribute>(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>().attribute != first.template as<Attribute>().attribute) {
return false;
}
}
@@ -227,9 +227,7 @@ TEST(LPT, AvoidDequantizationToShapeOfPropagationFakeQuantizeDecompositionTransf
auto shapeOf = std::make_shared<opset1::ShapeOf>(fakeQuantize);
auto& outInfo = fakeQuantize->output(0).get_rt_info();
auto attribute = ngraph::pass::low_precision::make_shared_attribute<PrecisionsAttribute>(element::TypeVector{ element::u8, element::i8 });
auto attributeWrapper = std::make_shared<ngraph::VariantWrapper<std::shared_ptr<PrecisionsAttribute>>>(attribute);
outInfo.emplace(ngraph::VariantWrapper<std::shared_ptr<PrecisionsAttribute>>::type_info.name, attributeWrapper);
outInfo.emplace(PrecisionsAttribute::get_type_info_static(), PrecisionsAttribute(element::TypeVector{ element::u8, element::i8 }));
auto result1 = std::make_shared<opset1::Result>(fakeQuantize);
auto result2 = std::make_shared<opset1::Result>(shapeOf);
@@ -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<AvgPoolPrecisionPreservedAttributePtr>(
auto avgPoolPrecisioinPreservedAttribute = ngraph::pass::low_precision::getAttribute<AvgPoolPrecisionPreservedAttribute>(
*avgPoolOperations.begin());
ASSERT_NE(nullptr, avgPoolPrecisioinPreservedAttribute);
ASSERT_EQ(true, avgPoolPrecisioinPreservedAttribute->get()->sharedValue->value);
ASSERT_FALSE(avgPoolPrecisioinPreservedAttribute.empty());
ASSERT_EQ(true, avgPoolPrecisioinPreservedAttribute.as<AvgPoolPrecisionPreservedAttribute>().value());
}
const auto precisionPreserved = LayerTransformation::get<opset1::MaxPool>(actualFunction);
ASSERT_TRUE(checkIfAttributesAreTheSame<std::shared_ptr<AvgPoolPrecisionPreservedAttribute>>(precisionPreserved)) <<
ASSERT_TRUE(checkIfAttributesAreTheSame<AvgPoolPrecisionPreservedAttribute>(precisionPreserved)) <<
"AvgPoolPrecisionPreservedAttribute are not the same";
//auto res = compare_functions(referenceFunction, actualFunction, true, true);
@@ -162,9 +162,9 @@ public:
testValues.actual.convertAfter,
testValues.actual.dequantizationAfter,
{
ngraph::builder::subgraph::make_shared_attribute_ptr<PrecisionPreservedAttribute>(true),
ngraph::builder::subgraph::make_shared_attribute_ptr<IntervalsAlignmentAttribute>(interval, 256),
ngraph::builder::subgraph::make_shared_attribute_ptr<QuantizationAlignmentAttribute>(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<PrecisionPreservedAttribute>(true),
ngraph::builder::subgraph::make_shared_attribute_ptr<IntervalsAlignmentAttribute>(interval, 256),
ngraph::builder::subgraph::make_shared_attribute_ptr<QuantizationAlignmentAttribute>(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<opset1::FakeQuantize>(actualFunction);
ASSERT_TRUE(checkIfOutputAttributesSharedValuesAreTheSame<std::shared_ptr<PrecisionsAttribute>>(actualFakeQuantizes)) <<
ASSERT_TRUE(checkIfOutputAttributesSharedValuesAreTheSame<PrecisionsAttribute>(actualFakeQuantizes)) <<
"PrecisionsAttribute are not the same";
}
@@ -9,7 +9,6 @@
#include <ngraph/variant.hpp>
#include <snippets/snippets_isa.hpp>
#include <snippets/register_info.hpp>
#include <snippets/pass/assign_registers.hpp>
#include <transformations/init_node_info.hpp>
@@ -53,7 +52,7 @@ TEST(TransformationTests, AssignRegisters) {
auto it_rinfo = rt.find("reginfo");
if (it_rinfo != rt.end()) {
auto reginfo = ov::as_type_ptr<VariantWrapper<std::vector<size_t>>>(it_rinfo->second)->get();
auto reginfo = it_rinfo->second.as<std::vector<size_t>>();
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<VariantWrapper<std::vector<size_t>>>(it_rinfo->second)->get();
auto reginfo = it_rinfo->second.as<std::vector<size_t>>();
auto reg = reginfo[0];
ASSERT_TRUE(ref_registers[op->get_friendly_name()] == reg);
total_ops++;
@@ -50,7 +50,7 @@ TEST(TransformationTests, ConvBiasFusion) {
for (auto & op : nGraph->get_ops()) {
if (auto conv = std::dynamic_pointer_cast<ngraph::opset1::Convolution>(op)) {
auto & rtInfo = conv->get_rt_info();
rtInfo["PrimitivesPriority"] = std::make_shared<ngraph::VariantWrapper<std::string>>("test");
rtInfo[ov::PrimitivesPriority::get_type_info_static()] = ov::PrimitivesPriority("test");
pp[op->get_friendly_name()] = "test";
}
}
@@ -265,18 +265,18 @@ CPUTestsBase::makeCPUInfo(std::vector<cpu_memory_format_t> inFmts, std::vector<c
CPUInfo cpuInfo;
if (!inFmts.empty()) {
cpuInfo.insert({std::string(ngraph::MLKDNNInputMemoryFormatsAttr),
std::make_shared<ngraph::MLKDNNInputMemoryFormats>(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<ngraph::MLKDNNOutputMemoryFormats>(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<ngraph::VariantWrapper<std::string>>(impls2str(priority))});
}
cpuInfo.insert({"enforceBF16evenForGraphTail", ov::make_variant<int64_t>(true)});
cpuInfo.insert({"enforceBF16evenForGraphTail", ov::make_runtime_attribute<int64_t>(true)});
return cpuInfo;
}
@@ -120,7 +120,7 @@ bool LoadNetworkCacheTestBase::importExportSupported(InferenceEngine::Core& ie)
std::vector<std::string> 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<bool>();
return supported;
}
@@ -46,9 +46,9 @@ namespace LayerTestsDefinitions {
}
auto hostTensor = std::make_shared<HostTensor>(ngPrc, inputShape);
auto variable_context = std::make_shared<VariantWrapper<VariableContext>>(VariableContext());
auto variable_context = VariableContext();
auto variable_value = std::make_shared<VariableValue>(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;
}
@@ -94,46 +94,7 @@ std::shared_ptr<ngraph::opset1::FakeQuantize> makeFakeQuantizeTypeRelaxed(
const ngraph::element::Type constantPrecision,
const FakeQuantizeOnDataWithConstant& fqOnData);
template <typename ... Args>
void addAttribute(std::vector<std::shared_ptr<ngraph::Node>> nodes, Args&& ... args) {
const auto attribute = std::make_shared<ngraph::VariantWrapper<QuantizationAlignmentAttributePtr>>(
QuantizationAlignmentAttribute(std::forward<Args>(args)...));
for (const auto& node : nodes) {
node->get_rt_info()[ngraph::VariantWrapper<QuantizationAlignmentAttributePtr>::type_info.name] = attribute;
}
}
template <typename T>
void addAttribute2(std::vector<std::shared_ptr<ngraph::Node>> 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 <typename T, typename ... Args>
void addAttribute3(std::vector<std::shared_ptr<ngraph::Node>> nodes, Args&& ... args) {
const auto attribute = std::make_shared<::ngraph::VariantWrapper<T>>(T(std::forward<Args>(args)...));
for (const auto& node : nodes) {
node->get_rt_info()[ngraph::VariantWrapper<T>::type_info.name] = attribute;
}
}
void addAttributes(std::vector<std::shared_ptr<ngraph::Node>> nodes, std::vector<std::shared_ptr<Variant>> attributes);
template <typename T, typename ... Args>
std::shared_ptr<Variant> make_shared_attribute(Args&& ... args) {
const auto attribute = std::make_shared<::ngraph::VariantWrapper<T>>(T(std::forward<Args>(args)...));
return attribute;
}
template <typename T, typename ... Args>
std::shared_ptr<Variant> make_shared_attribute_ptr(Args&& ... args) {
const auto attribute = std::make_shared<::ngraph::VariantWrapper<std::shared_ptr<T>>>(std::make_shared<T>(std::forward<Args>(args)...));
return attribute;
}
void addAttributes(std::vector<std::shared_ptr<ngraph::Node>> nodes, std::vector<ov::Any> attributes);
std::shared_ptr<Node> makeConvolution(
const std::shared_ptr<Node>& parent,
@@ -24,7 +24,7 @@ public:
const std::vector<float>& outputLowValues,
const std::vector<float>& outputHighValues,
const ngraph::element::Type outputPrecision = ngraph::element::undefined,
const std::vector<std::shared_ptr<Variant>>& attributes = {});
const std::vector<ov::Any>& attributes = {});
virtual ~FakeQuantizeOnData();
@@ -38,7 +38,7 @@ public:
std::vector<float> outputLowValues;
std::vector<float> outputHighValues;
ngraph::element::Type outputPrecision;
std::vector<std::shared_ptr<Variant>> attributes;
std::vector<ov::Any> attributes;
};
inline std::ostream& operator<<(std::ostream& os, const std::vector<float>& values) {
@@ -71,8 +71,8 @@ public:
const std::vector<float>& outputLowValues,
const std::vector<float>& outputHighValues,
const ngraph::element::Type outputPrecision = ngraph::element::undefined,
const std::vector<std::shared_ptr<Variant>>& attributes = {});
const std::vector<ov::Any>& attributes = {});
virtual ~FakeQuantizeOnDataWithConstant();
virtual bool empty() const;
@@ -84,7 +84,7 @@ public:
std::vector<float> outputLowValues;
std::vector<float> outputHighValues;
ngraph::element::Type outputPrecision;
std::vector<std::shared_ptr<Variant>> attributes;
std::vector<ov::Any> attributes;
};
inline std::ostream& operator<<(std::ostream& out, const FakeQuantizeOnDataWithConstant& data) {
@@ -123,7 +123,7 @@ public:
const FakeQuantizeOnDataWithConstant& fakeQuantize2,
const DequantizationOperations::Convert& convert2,
const DequantizationOperations& dequantization2,
const std::vector<std::shared_ptr<Variant>>& concatAttributes,
const std::vector<ov::Any>& 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<std::shared_ptr<Variant>>& concatAttributes,
const std::vector<ov::Any>& concatAttributes,
const ngraph::element::Type precisionAfterOperation,
const DequantizationOperations& dequantizationAfter,
const std::int64_t& axis,
@@ -30,7 +30,7 @@ public:
const FakeQuantizeOnDataWithConstant& fqOnData3,
const DequantizationOperations::Convert& convert3,
const DequantizationOperations& dequantization3,
const std::vector<std::shared_ptr<Variant>>& concatAttributes,
const std::vector<ov::Any>& concatAttributes,
const ngraph::element::Type precisionAfterOperation,
const DequantizationOperations& dequantizationAfter,
const std::int64_t& axis);
@@ -282,7 +282,9 @@ std::shared_ptr<ngraph::opset1::FakeQuantize> makeFakeQuantize(
auto& rt = fq->get_rt_info();
for (auto& attribute : fqOnData.attributes) {
rt[attribute->get_type_info().name] = attribute;
if (attribute.is<ov::RuntimeAttribute>()) {
rt[attribute.as<ov::RuntimeAttribute>().get_type_info()] = attribute;
}
}
return fq;
@@ -298,12 +300,12 @@ std::shared_ptr<ngraph::opset1::FakeQuantize> makeFakeQuantizeTypeRelaxed(
fqOnData.outputPrecision == ngraph::element::undefined ? constantPrecision : fqOnData.outputPrecision);
}
void addAttributes(std::vector<std::shared_ptr<ngraph::Node>> nodes, std::vector<std::shared_ptr<Variant>> attributes) {
void addAttributes(std::vector<std::shared_ptr<ngraph::Node>> nodes, std::vector<ov::Any> 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<ov::RuntimeAttribute>()) {
node->get_rt_info()[attribute.as<ov::RuntimeAttribute>().get_type_info()] = attribute;
}
}
}
}
@@ -19,7 +19,7 @@ FakeQuantizeOnData::FakeQuantizeOnData(
const std::vector<float>& outputLowValues,
const std::vector<float>& outputHighValues,
const ngraph::element::Type outputPrecision,
const std::vector<std::shared_ptr<Variant>>& attributes) :
const std::vector<ov::Any>& attributes) :
quantizationLevel(quantizationLevel),
constantShape(constantShape),
inputLowValues(inputLowValues),
@@ -58,7 +58,7 @@ FakeQuantizeOnDataWithConstant::FakeQuantizeOnDataWithConstant(
const std::vector<float>& outputLowValues,
const std::vector<float>& outputHighValues,
const ngraph::element::Type outputPrecision,
const std::vector<std::shared_ptr<Variant>>& attributes) :
const std::vector<ov::Any>& attributes) :
quantizationLevel(quantizationLevel),
constantShapes(constantShapes),
inputLowValues(inputLowValues),
@@ -874,7 +874,7 @@ std::shared_ptr<ngraph::Function> ConcatFunction::get(
const FakeQuantizeOnDataWithConstant& fqOnData2,
const DequantizationOperations::Convert& convert2,
const DequantizationOperations& dequantization2,
const std::vector<std::shared_ptr<Variant>>& concatAttributes,
const std::vector<ov::Any>& concatAttributes,
const ngraph::element::Type precisionAfterOperation,
const DequantizationOperations& dequantizationAfter,
const std::int64_t& axis,
@@ -960,7 +960,7 @@ std::shared_ptr<ngraph::Function> ConcatFunction::get(
const DequantizationOperations::Convert& convert2,
const DequantizationOperations& dequantization2,
const bool addReshape2,
const std::vector<std::shared_ptr<Variant>>& concatAttributes,
const std::vector<ov::Any>& concatAttributes,
const ngraph::element::Type precisionAfterOperation,
const DequantizationOperations& dequantizationAfter,
const std::int64_t& axis,
@@ -32,7 +32,7 @@ std::shared_ptr<ngraph::Function> MoveFakeQuantize::get(
const FakeQuantizeOnDataWithConstant& fqOnData3,
const DequantizationOperations::Convert& convert3,
const DequantizationOperations& dequantization3,
const std::vector<std::shared_ptr<Variant>>& concatAttributes,
const std::vector<ov::Any>& concatAttributes,
const ngraph::element::Type precisionAfterOperation,
const DequantizationOperations& dequantizationAfter,
const std::int64_t& axis) {
@@ -134,13 +134,22 @@ static std::shared_ptr<ngraph::Function> 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<ngraph::opset6::Multiply>(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<ngraph::opset6::Add>(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<ngraph::opset6::Result>(add);
res->set_friendly_name("res");
// Create nGraph function
auto func = std::make_shared<ngraph::Function>(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<ngraph::VariantWrapper<std::string> > ("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<ngraph::VariantWrapper<std::string> > ("testPriority");
@@ -222,24 +231,20 @@ TEST(NetworkContext_CNNNetwork, HashWithPrimitivesPriority) {
TEST(NetworkContext_CNNNetwork, HashWithFusedNames) {
auto setFusedEmpty = [&](Node::RTMap& rtInfo) {
rtInfo[VariantWrapper<ngraph::FusedNames>::get_type_info_static()] =
std::make_shared<VariantWrapper<ngraph::FusedNames>>(ngraph::FusedNames());
rtInfo[ngraph::FusedNames::get_type_info_static()] = ngraph::FusedNames();
};
auto setFused = [&](Node::RTMap& rtInfo, const std::string& name) {
rtInfo[VariantWrapper<ngraph::FusedNames>::get_type_info_static()] =
std::make_shared<VariantWrapper<ngraph::FusedNames>>(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<ov::PrimitivesPriority>("");
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<ov::PrimitivesPriority>(name);
rtInfo[ov::PrimitivesPriority::get_type_info_static()] = ov::PrimitivesPriority(name);
};
checkCustomRt(setPrimEmpty, setPrim);
}
@@ -414,10 +414,10 @@ class MOCK_API FrontEndMockPy : public FrontEnd
public:
FrontEndMockPy() {}
std::shared_ptr<ngraph::Function> convert(InputModel::Ptr model) const override
std::shared_ptr<ov::Function> convert(InputModel::Ptr model) const override
{
m_stat.m_convert_model++;
return std::make_shared<ngraph::Function>(NodeVector{}, ParameterVector{});
return std::make_shared<ov::Function>(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<std::shared_ptr<Variant>>& params) const override
InputModel::Ptr load_impl(const std::vector<ov::Any>& params) const override
{
if (params.size() > 0 && ov::is_type<VariantWrapper<std::string>>(params[0]))
if (params.size() > 0 && params[0].is<std::string>())
{
auto path = ov::as_type_ptr<VariantWrapper<std::string>>(params[0])->get();
auto path = params[0].as<std::string>();
m_stat.m_load_paths.push_back(path);
}
return std::make_shared<InputModelMockPy>();
}
bool supported_impl(const std::vector<std::shared_ptr<Variant>>& params) const override
bool supported_impl(const std::vector<ov::Any>& params) const override
{
m_stat.m_supported++;
if (params.size() > 0 && ov::is_type<VariantWrapper<std::string>>(params[0]))
if (params.size() > 0 && params[0].is<std::string>())
{
auto path = ov::as_type_ptr<VariantWrapper<std::string>>(params[0])->get();
auto path = params[0].as<std::string>();
if (path.find(".test_mo_mock_mdl") != std::string::npos)
{
return true;
@@ -20,7 +20,7 @@
namespace py = pybind11;
using PyRTMap = std::map<std::string, ov::Any>;
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<std::shared_ptr<ngraph::Variant>>();
});
}
@@ -9,7 +9,7 @@
#include <pybind11/stl_bind.h>
#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"
@@ -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"
@@ -10,7 +10,7 @@
#include <sstream>
#include <string>
#include "openvino/core/any.hpp" // ov::Variant
#include "openvino/core/any.hpp" // ov::RuntimeAttribute
namespace py = pybind11;
@@ -614,16 +614,16 @@ class MOCK_API FrontEndMockPy : public FrontEnd {
public:
FrontEndMockPy() {}
InputModel::Ptr load_impl(const std::vector<std::shared_ptr<Variant>>& params) const override {
if (params.size() > 0 && ov::is_type<VariantWrapper<std::string>>(params[0]))
m_stat.m_load_paths.push_back(ov::as_type_ptr<VariantWrapper<std::string>>(params[0])->get());
InputModel::Ptr load_impl(const std::vector<ov::Any>& params) const override {
if (params.size() > 0 && params[0].is<std::string>())
m_stat.m_load_paths.push_back(params[0].as<std::string>());
return std::make_shared<InputModelMockPy>();
}
bool supported_impl(const std::vector<std::shared_ptr<Variant>>& params) const override {
bool supported_impl(const std::vector<ov::Any>& params) const override {
m_stat.m_supported++;
if (params.size() > 0 && ov::is_type<VariantWrapper<std::string>>(params[0])) {
auto path = ov::as_type_ptr<VariantWrapper<std::string>>(params[0])->get();
if (params.size() > 0 && params[0].is<std::string>()) {
auto path = params[0].as<std::string>();
if (path.find(".test_mock_py_mdl") != std::string::npos) {
return true;
}
@@ -631,26 +631,26 @@ public:
return false;
}
std::shared_ptr<ngraph::Function> convert(InputModel::Ptr model) const override {
std::shared_ptr<ov::Function> convert(InputModel::Ptr model) const override {
m_stat.m_convert_model++;
return std::make_shared<ngraph::Function>(NodeVector{}, ParameterVector{});
return std::make_shared<ov::Function>(ov::NodeVector{}, ov::ParameterVector{});
}
void convert(std::shared_ptr<ngraph::Function> func) const override {
void convert(std::shared_ptr<ov::Function> func) const override {
m_stat.m_convert++;
}
std::shared_ptr<ngraph::Function> convert_partially(InputModel::Ptr model) const override {
std::shared_ptr<ov::Function> convert_partially(InputModel::Ptr model) const override {
m_stat.m_convert_partially++;
return std::make_shared<ngraph::Function>(NodeVector{}, ParameterVector{});
return std::make_shared<ov::Function>(ov::NodeVector{}, ov::ParameterVector{});
}
std::shared_ptr<ngraph::Function> decode(InputModel::Ptr model) const override {
std::shared_ptr<ov::Function> decode(InputModel::Ptr model) const override {
m_stat.m_decode++;
return std::make_shared<ngraph::Function>(NodeVector{}, ParameterVector{});
return std::make_shared<ov::Function>(ov::NodeVector{}, ov::ParameterVector{});
}
void normalize(std::shared_ptr<ngraph::Function> function) const override {
void normalize(std::shared_ptr<ov::Function> function) const override {
m_stat.m_normalize++;
}
@@ -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<ngraph::Variant> & variant) {
auto getStringValue = [] (const ov::Any& variant) {
auto castedVariant = std::dynamic_pointer_cast<ngraph::VariantImpl<std::string>>(variant);
IE_ASSERT(castedVariant != nullptr);
return castedVariant->get();
@@ -1932,13 +1932,13 @@ void convertFunctionToICNNNetwork(const std::shared_ptr<const ::ngraph::Function
}
// Copy runtime info attributes from Nodes to CNNLayers if they have VariantWrapper<std::string> type
using VariantString = ::ngraph::VariantWrapper<std::string>;
for (const auto &rt : rt_info) {
if (auto str_attr = std::dynamic_pointer_cast<VariantString>(rt.second)) {
if (rt.second.is<std::string>()) {
auto str_attr = rt.second.as<std::string>();
if (details::CaselessEq<std::string>()(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;
}
}
}
@@ -47,8 +47,8 @@ public:
}
{
OV_ITT_SCOPE(FIRST_INFERENCE, itt::domains::LPT_LT, "CreateAttribute");
const auto attribute = ngraph::VariantWrapper<AttributeType>::create(op, params);
if (attribute == nullptr) {
const auto attribute = AttributeType::create(op, params);
if (attribute.empty()) {
return false;
}
}
@@ -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<ngraph::VariantWrapper<PrecisionPreservedAttributePtr>>(
std::make_shared<PrecisionPreservedAttribute>(false));
rt[ngraph::VariantWrapper<PrecisionPreservedAttributePtr>::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<ngraph::VariantWrapper<std::shared_ptr<AttributeType>>>(
std::make_shared<AttributeType>());
rt[ngraph::VariantWrapper<std::shared_ptr<AttributeType>>::type_info.name] = attribute;
const auto attribute = AttributeType{};
rt[AttributeType::get_type_info_static()] = attribute;
ngraph::pass::low_precision::NetworkHelper::reassign<PrecisionPreservedSharedValue, PrecisionPreservedAttribute>(
ngraph::pass::low_precision::NetworkHelper::reassign<AttributeType>(
targetSharedValue,
{
std::dynamic_pointer_cast<PrecisionPreservedAttribute>(attribute->get()),
std::dynamic_pointer_cast<PrecisionPreservedAttribute>(precisionPreservedAttribute->get())
attribute.attribute,
precisionPreservedAttribute.attribute
});
}
return true;
@@ -218,8 +218,8 @@ public:
static void replaceAttributeInNodes(
std::shared_ptr<ngraph::Function> f,
const std::string& name,
const std::shared_ptr<ngraph::Variant> newAttribute,
const std::shared_ptr<ngraph::Variant> oldAttribute,
const ov::Any& newAttribute,
const ov::Any& oldAttribute,
const std::shared_ptr<ngraph::Node>& initialNode) {
std::set<std::shared_ptr<Node>> visited;
std::deque<std::shared_ptr<Node>> 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<ngraph::Variant>(currentAttribute)) {
if (oldAttribute == currentAttribute) {
rt[name] = newAttribute;
}
handleConnectedNodes = true;
@@ -296,10 +296,10 @@ public:
}
}
template <typename SharedValueType, typename SharedAttributeType>
template <typename SharedAttribute>
static void reassign(
const std::shared_ptr<SharedValueType>& sharedValue,
const std::vector<std::weak_ptr<SharedAttributeType>>& attributes) {
const std::shared_ptr<typename SharedAttribute::SharedValueAttribute::SharedValue>& sharedValue,
const std::vector<std::weak_ptr<typename SharedAttribute::SharedValueAttribute>>& attributes) {
for (const auto attributeWeakPtr : attributes) {
auto attribute = attributeWeakPtr.lock();
if (attribute == nullptr) {
@@ -415,53 +415,37 @@ std::shared_ptr<Node> fold_reshape(Args&&... args) {
}
template <typename T>
std::shared_ptr<ngraph::VariantWrapper<T>> getAttribute(const std::shared_ptr<Node>& inputNode) {
auto& rt = inputNode->get_rt_info();
auto it = rt.find(ngraph::VariantWrapper<T>::type_info.name);
ov::Any getAttribute(const std::shared_ptr<Node>& 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<ngraph::VariantWrapper<T>>(it->second);
assert(attribute != nullptr);
return attribute;
return it->second;
}
template <typename T>
std::shared_ptr<ngraph::VariantWrapper<T>> getAttribute(const Input<Node>& input) {
ov::Any getAttribute(const Input<Node>& input) {
auto& rt = input.get_rt_info();
auto it = rt.find(ngraph::VariantWrapper<T>::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<ngraph::VariantWrapper<T>>(it->second);
assert(attribute != nullptr);
return attribute;
return it->second;
}
template <typename T>
std::shared_ptr<ngraph::VariantWrapper<T>> getAttributeFromOutput(const Output<Node>& output) {
ov::Any getAttributeFromOutput(const Output<Node>& output) {
auto& rt = output.get_rt_info();
auto it = rt.find(ngraph::VariantWrapper<T>::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<ngraph::VariantWrapper<T>>(it->second);
assert(attribute != nullptr);
return attribute;
return it->second;
}
bool isDisabled(const std::shared_ptr<Node>& node);
template <typename T, typename ... Args>
std::shared_ptr<T> make_shared_attribute(Args&& ... args) {
std::shared_ptr<T> attribute = std::make_shared<T>(std::forward<Args>(args)...);
attribute->sharedValue->attributes.push_back(attribute);
return attribute;
}
} // namespace low_precision
} // namespace pass
} // namespace ngraph
@@ -39,11 +39,7 @@ public:
if (ov::is_type<opset1::FakeQuantize>(node)) {
assert(node->get_output_size() == 1ul);
auto& outputRtInfo = node->output(0).get_rt_info();
auto attribute = make_shared_attribute<AttributeType>(std::set<element::Type>{element::u8, element::i8});
auto attributeWrapper = std::make_shared<ngraph::VariantWrapper<std::shared_ptr<PrecisionsAttribute>>>(attribute);
outputRtInfo[ngraph::VariantWrapper<std::shared_ptr<PrecisionsAttribute>>::type_info.name] = attributeWrapper;
outputRtInfo[AttributeType::get_type_info_static()] = AttributeType{std::set<element::Type>{element::u8, element::i8}};
continue;
}
@@ -52,17 +48,16 @@ public:
auto parentNode = input.get_source_output().get_node_shared_ptr();
auto getAttributes = [](const Input<Node>& nodeInput) {
const std::string name = ngraph::VariantWrapper<std::shared_ptr<PrecisionsAttribute>>::type_info.name;
const std::string name = PrecisionsAttribute::get_type_info_static();
auto node = nodeInput.get_source_output().get_node_shared_ptr();
std::vector<std::shared_ptr<ngraph::VariantWrapper<std::shared_ptr<PrecisionsAttribute>>>> attributes;
std::vector<ov::Any> attributes;
if (ov::is_type<opset1::FakeQuantize>(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<ngraph::VariantWrapper<std::shared_ptr<PrecisionsAttribute>>>(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<std::shared_ptr<PrecisionsAttribute>>::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<ngraph::VariantWrapper<std::shared_ptr<PrecisionsAttribute>>>(it->second);
std::vector<std::shared_ptr<VariantWrapper<std::shared_ptr<PrecisionsAttribute>>>> attributes{ attribute };
std::vector<ov::Any> attributes{ it->second };
auto parentAttributes = getAttributes(input);
if (parentAttributes.empty()) {
@@ -86,7 +80,7 @@ public:
}
for (auto& parentAttribute : parentAttributes) {
parentAttribute->merge(attributes);
parentAttribute.as<PrecisionsAttribute>.merge(attributes);
}
nodeRt[name] = parentAttributes[0];
@@ -100,9 +94,9 @@ public:
}
private:
std::vector<std::shared_ptr<ngraph::VariantWrapper<std::shared_ptr<PrecisionsAttribute>>>> getParentInputRestrictions(
std::vector<ov::Any> getParentInputRestrictions(
const std::shared_ptr<ngraph::Node> node) {
std::vector<std::shared_ptr<ngraph::VariantWrapper<std::shared_ptr<PrecisionsAttribute>>>> parentAttributes;
std::vector<ov::Any> parentAttributes;
for (size_t index = 0ul; index < node->get_input_size(); index++) {
const Input<Node>& 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<opset1::Convert>(dequantization.data.get_node())) &&
ov::is_type<opset1::FakeQuantize>(dequantization.data.get_node()->get_input_node_ptr(0))) {
ov::is_type<opset1::FakeQuantize>(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<std::shared_ptr<PrecisionsAttribute>>::type_info.name);
auto inputAttributeIt = inputRtInfo.find(PrecisionsAttribute::get_type_info_static());
if (inputAttributeIt != inputRtInfo.end()) {
const auto attribute = std::dynamic_pointer_cast<ngraph::VariantWrapper<std::shared_ptr<PrecisionsAttribute>>>(inputAttributeIt->second);
parentAttributes.push_back(attribute);
parentAttributes.push_back(inputAttributeIt->second);
}
} else if (ov::is_type<opset1::FakeQuantize>(inputNode)) {
const auto& outputPortRtInfo = inputNode->outputs()[0].get_rt_info();
auto attributeIt = outputPortRtInfo.find(ngraph::VariantWrapper<std::shared_ptr<PrecisionsAttribute>>::type_info.name);
auto attributeIt = outputPortRtInfo.find(PrecisionsAttribute::get_type_info_static());
if (attributeIt != outputPortRtInfo.end()) {
const auto attribute = std::dynamic_pointer_cast<ngraph::VariantWrapper<std::shared_ptr<PrecisionsAttribute>>>(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<std::shared_ptr<ngraph::VariantWrapper<std::shared_ptr<PrecisionsAttribute>>>> toMerge = parentRestrictions;
std::vector<ov::Any> toMerge = parentRestrictions;
toMerge.erase(toMerge.begin());
resultAttribute->merge(toMerge);
resultAttribute.as<PrecisionsAttribute>().merge(toMerge);
for (size_t index = 1ul; index < parentRestrictions.size(); index++) {
const auto oldAttribute = parentRestrictions[index]->get();
NetworkHelper::reassign<PrecisionsSharedValue, PrecisionsAttribute>(
resultAttribute->get()->sharedValue,
parentRestrictions[index]->get()->sharedValue->attributes);
NetworkHelper::reassign(
resultAttribute.as<PrecisionsAttribute>().attribute->sharedValue,
parentRestrictions[index].as<PrecisionsAttribute>().attribute->sharedValue->attributes);
}
auto& rt = node->get_rt_info();
rt[ngraph::VariantWrapper<std::shared_ptr<PrecisionsAttribute>>::type_info.name] = resultAttribute;
rt[PrecisionsAttribute::get_type_info_static()] = resultAttribute;
}
}
};
@@ -49,27 +49,27 @@ public:
return false;
}
auto resultAttribute = parentRestrictions[0];
auto& resultAttribute = parentRestrictions[0].template as<AttributeType>();
std::vector<std::shared_ptr<ngraph::VariantWrapper<std::shared_ptr<AttributeType>>>> toMerge = parentRestrictions;
// TODO: LPT: handle pointer on itself in VariantWrapper<IntervalsAlignmentAttributePtr>::merge and remove erase, task #59498
std::vector<ov::Any> 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<AttributeType&>(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<AttributeType>().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<std::shared_ptr<AttributeType>>::type_info.name] = resultAttribute;
rt[AttributeType::get_type_info_static()] = resultAttribute;
}
return true;
};
@@ -79,20 +79,20 @@ public:
}
private:
std::shared_ptr<ngraph::VariantWrapper<std::shared_ptr<AttributeType>>> getSourceOutputAttribute(const Input<Node>& input) {
ov::Any getSourceOutputAttribute(const Input<Node>& input) {
auto input2 = input;
auto output = input2.get_source_output();
std::shared_ptr<ngraph::VariantWrapper<std::shared_ptr<AttributeType>>> attribute = getAttributeFromOutput<std::shared_ptr<AttributeType>>(output);
if (attribute == nullptr) {
attribute = getAttribute<std::shared_ptr<AttributeType>>(output.get_node_shared_ptr());
auto attribute = getAttributeFromOutput<AttributeType>(output);
if (attribute.empty()) {
attribute = getAttribute<AttributeType>(output.get_node_shared_ptr());
}
return attribute;
}
// TODO: possible duplicate: PropagateToInput::getSourceOutputAttribute
std::vector<std::shared_ptr<ngraph::VariantWrapper<std::shared_ptr<AttributeType>>>> getParentInputRestrictions(
std::vector<ov::Any> getParentInputRestrictions(
const std::shared_ptr<ngraph::Node> node) {
std::vector<std::shared_ptr<ngraph::VariantWrapper<std::shared_ptr<AttributeType>>>> parentAttributes;
std::vector<ov::Any> parentAttributes;
auto getInput = [](const std::shared_ptr<ngraph::Node>& node, const size_t index) -> Input<Node> {
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<Node>& input = getInput(node, index);
const auto attribute = getSourceOutputAttribute(input);
if (attribute != nullptr) {
if (!attribute.empty()) {
parentAttributes.push_back(attribute);
}
}
@@ -45,18 +45,19 @@ public:
continue;
}
auto attribute = getAttribute<std::shared_ptr<AttributeType>>(input);
if (attribute != nullptr) {
if ((attribute->get()->sharedValue != nullptr) && (attribute->get()->sharedValue->precisions.empty())) {
auto attribute = getAttribute<AttributeType>(input);
if (!attribute.empty()) {
if ((attribute.template as<AttributeType>().attribute->sharedValue != nullptr) &&
(attribute.template as<AttributeType>().value().empty())) {
return false;
}
std::vector<std::shared_ptr<VariantWrapper<std::shared_ptr<AttributeType>>>> attributes = { attribute };
parentAttribute->merge(attributes);
std::vector<ov::Any> attributes = { attribute };
parentAttribute.template as<AttributeType>().merge(attributes);
}
auto& rt = input.get_rt_info();
rt[ngraph::VariantWrapper<std::shared_ptr<AttributeType>>::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<ngraph::VariantWrapper<std::shared_ptr<AttributeType>>> getSourceOutputAttribute(const Input<Node>& input) {
ov::Any getSourceOutputAttribute(const Input<Node>& input) {
auto getInput = [](const Input<Node>& 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<ngraph::VariantWrapper<std::shared_ptr<AttributeType>>> attribute = getAttributeFromOutput<std::shared_ptr<AttributeType>>(output);
if (attribute == nullptr) {
attribute = getAttribute<std::shared_ptr<AttributeType>>(output.get_node_shared_ptr());
auto attribute = getAttributeFromOutput<AttributeType>(output);
if (attribute.empty()) {
attribute = getAttribute<AttributeType>(output.get_node_shared_ptr());
}
return attribute;
}
std::vector<std::shared_ptr<ngraph::VariantWrapper<std::shared_ptr<AttributeType>>>> getParentInputRestrictions(
std::vector<ov::Any> getParentInputRestrictions(
const std::shared_ptr<ngraph::Node> node) {
std::vector<std::shared_ptr<ngraph::VariantWrapper<std::shared_ptr<AttributeType>>>> parentAttributes;
std::vector<ov::Any> parentAttributes;
for (size_t index = 0ul; index < node->get_input_size(); index++) {
const Input<Node>& input = node->input(index);
const auto attribute = getSourceOutputAttribute(input);
if (attribute != nullptr) {
if (!attribute.empty()) {
parentAttributes.push_back(attribute);
}
}
@@ -14,28 +14,11 @@
namespace ngraph {
class LP_TRANSFORMATIONS_API AvgPoolPrecisionPreservedAttribute : public PrecisionPreservedAttribute {
};
using AvgPoolPrecisionPreservedAttributePtr = std::shared_ptr<AvgPoolPrecisionPreservedAttribute>;
} // namespace ngraph
namespace ov {
extern template class LP_TRANSFORMATIONS_API VariantImpl<ngraph::AvgPoolPrecisionPreservedAttributePtr>;
template<>
class LP_TRANSFORMATIONS_API VariantWrapper<ngraph::AvgPoolPrecisionPreservedAttributePtr> : public VariantImpl<ngraph::AvgPoolPrecisionPreservedAttributePtr> {
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_type>(value) {}
ngraph::AvgPoolPrecisionPreservedAttributePtr get() { return this->m_value; }
void merge(std::vector<std::shared_ptr<ngraph::VariantWrapper<std::shared_ptr<ngraph::AvgPoolPrecisionPreservedAttribute>>>>& attributes);
std::string to_string() override;
OPENVINO_RTTI("LowPrecision::AvgPoolPrecisionPreserved", "", ov::RuntimeAttribute, 0);
using PrecisionPreservedAttribute::PrecisionPreservedAttribute;
void merge(std::vector<ov::Any>& attributes);
std::string to_string() const override;
};
} // namespace ov
} // namespace ngraph
@@ -15,16 +15,14 @@
#include "low_precision/lpt_visibility.hpp"
namespace ngraph {
class IntervalsAlignmentAttribute;
class LP_TRANSFORMATIONS_API IntervalsAlignmentSharedValue : public SharedValue<IntervalsAlignmentAttribute> {
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<element::Type> preferablePrecisions;
@@ -47,8 +45,9 @@ public:
#endif
};
class LP_TRANSFORMATIONS_API IntervalsAlignmentAttribute : public SharedValueAttribute<IntervalsAlignmentSharedValue> {
class LP_TRANSFORMATIONS_API IntervalsAlignmentAttribute : public SharedAttribute<IntervalsAlignmentSharedValue> {
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<ngraph::Node>& node,
const AttributeParameters& params);
void merge(std::vector<ov::Any>& attributes);
std::string to_string() const override;
// specify subgraph original levels
size_t levels;
};
using IntervalsAlignmentAttributePtr = std::shared_ptr<IntervalsAlignmentAttribute>;
} // namespace ngraph
namespace ov {
extern template class LP_TRANSFORMATIONS_API ngraph::VariantImpl<ngraph::IntervalsAlignmentAttributePtr>;
template<>
class LP_TRANSFORMATIONS_API VariantWrapper<std::shared_ptr<ngraph::IntervalsAlignmentAttribute>> :
public VariantImpl<std::shared_ptr<ngraph::IntervalsAlignmentAttribute>> {
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_type>(value) {}
std::shared_ptr<ngraph::IntervalsAlignmentAttribute> get() const { return this->m_value; }
static std::shared_ptr<VariantWrapper<std::shared_ptr<ngraph::IntervalsAlignmentAttribute>>> create(
const std::shared_ptr<ngraph::Node>& node,
const AttributeParameters& params);
void merge(std::vector<std::shared_ptr<VariantWrapper<std::shared_ptr<ngraph::IntervalsAlignmentAttribute>>>>& attributes);
std::string to_string() override;
};
} // namespace ov
@@ -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<ngraph::PerTensorQuantizationAttribute>;
template<>
class LP_TRANSFORMATIONS_API VariantWrapper<ngraph::PerTensorQuantizationAttribute> : public VariantImpl<ngraph::PerTensorQuantizationAttribute> {
public:
static constexpr VariantTypeInfo type_info { "LowPrecision::PerTensorQuantization", 0 };
VariantWrapper(const value_type& value) : VariantImpl<value_type>(value) {}
const VariantTypeInfo& get_type_info() const override {
return type_info;
}
};
} // namespace ov
@@ -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<PrecisionPreservedAttribute> {
class LP_TRANSFORMATIONS_API PrecisionPreservedAttribute : public SharedAttribute<bool> {
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<PrecisionPreservedSharedValue> {
public:
PrecisionPreservedAttribute() = default;
PrecisionPreservedAttribute(const bool value);
};
using PrecisionPreservedAttributePtr = std::shared_ptr<PrecisionPreservedAttribute>;
std::string to_string() const override;
};
} // namespace ngraph
namespace ov {
extern template class LP_TRANSFORMATIONS_API ngraph::VariantImpl<ngraph::PrecisionPreservedAttributePtr>;
template<>
class LP_TRANSFORMATIONS_API VariantWrapper<ngraph::PrecisionPreservedAttributePtr> : public VariantImpl<ngraph::PrecisionPreservedAttributePtr> {
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_type>(value) {}
ngraph::PrecisionPreservedAttributePtr get() { return this->m_value; }
std::string to_string() override;
};
} // namespace ov
@@ -20,49 +20,18 @@
namespace ngraph {
class PrecisionsAttribute;
class LP_TRANSFORMATIONS_API PrecisionsSharedValue : public SharedValue<PrecisionsAttribute> {
public:
std::vector<ngraph::element::Type> precisions;
};
using PrecisionsAttributePtr = std::shared_ptr<PrecisionsAttribute>;
class LP_TRANSFORMATIONS_API PrecisionsAttribute : public SharedValueAttribute<PrecisionsSharedValue> {
class LP_TRANSFORMATIONS_API PrecisionsAttribute : public SharedAttribute<std::vector<ngraph::element::Type>> {
public:
OPENVINO_RTTI("LowPrecision::Precisions", "", ov::RuntimeAttribute, 0);
static std::vector<ngraph::element::Type> defaultPrecisions;
PrecisionsAttribute(const std::vector<ngraph::element::Type>& precisions = defaultPrecisions);
};
} // namespace ngraph
namespace ov {
extern template class LP_TRANSFORMATIONS_API ngraph::VariantImpl<std::shared_ptr<ngraph::PrecisionsAttribute>>;
template<>
class LP_TRANSFORMATIONS_API VariantWrapper<std::shared_ptr<ngraph::PrecisionsAttribute>> : public VariantImpl<std::shared_ptr<ngraph::PrecisionsAttribute>> {
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_type>(value) {}
ov::Any init(const std::shared_ptr<ngraph::Node>& node) override;
std::shared_ptr<ngraph::PrecisionsAttribute> get() { return this->m_value; }
// create attribute instance for node
static std::shared_ptr<VariantWrapper<std::shared_ptr<ngraph::PrecisionsAttribute>>> create(
static ov::Any create(
const std::shared_ptr<ngraph::Node>& node,
const AttributeParameters& params);
// merge attribute instances which can be got from different sources: node, input port or output port
void merge(std::vector<std::shared_ptr<VariantWrapper<std::shared_ptr<ngraph::PrecisionsAttribute>>>>& attributes);
void merge(std::vector<ov::Any>& attributes);
// vizualize shared attributes details in VizualizeTree pass
std::string to_string() override;
std::string to_string() const override;
};
} // namespace ov
} // namespace ngraph
@@ -18,46 +18,16 @@
#include "attribute_parameters.hpp"
namespace ngraph {
class QuantizationAlignmentAttribute;
class LP_TRANSFORMATIONS_API QuantizationAlignmentSharedValue : public SharedValue<QuantizationAlignmentAttribute> {
public:
QuantizationAlignmentSharedValue(const bool value = false) : value(value) {}
bool value;
};
class LP_TRANSFORMATIONS_API QuantizationAlignmentAttribute : public SharedValueAttribute<QuantizationAlignmentSharedValue>{
class LP_TRANSFORMATIONS_API QuantizationAlignmentAttribute : public SharedAttribute<bool> {
public:
OPENVINO_RTTI("LowPrecision::QuantizationAlignment", "", ov::RuntimeAttribute, 0);
QuantizationAlignmentAttribute(const bool value = false);
};
using QuantizationAlignmentAttributePtr = std::shared_ptr<QuantizationAlignmentAttribute>;
} // namespace ngraph
namespace ov {
extern template class LP_TRANSFORMATIONS_API ngraph::VariantImpl<ngraph::QuantizationAlignmentAttributePtr>;
template<>
class LP_TRANSFORMATIONS_API VariantWrapper<std::shared_ptr<ngraph::QuantizationAlignmentAttribute>> :
public VariantImpl<std::shared_ptr<ngraph::QuantizationAlignmentAttribute>> {
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_type>(value) {}
ov::Any init(const std::shared_ptr<ngraph::Node>& node) override;
std::shared_ptr<ngraph::QuantizationAlignmentAttribute> get() { return this->m_value; }
static std::shared_ptr<VariantWrapper<std::shared_ptr<ngraph::QuantizationAlignmentAttribute>>> create(
static ov::Any create(
const std::shared_ptr<ngraph::Node>& node,
const AttributeParameters& params);
void merge(std::vector<std::shared_ptr<VariantWrapper<std::shared_ptr<ngraph::QuantizationAlignmentAttribute>>>>& attributes);
std::string to_string() override;
void merge(std::vector<ov::Any>& attributes);
std::string to_string() const override;
};
} // namespace ov
} // namespace ngraph
@@ -14,46 +14,70 @@
#include <low_precision/lpt_visibility.hpp>
#include <ngraph/pass/graph_rewrite.hpp>
template <class SharedAttributeType>
class LP_TRANSFORMATIONS_API SharedValue;
template <class SharedValueType>
class LP_TRANSFORMATIONS_API SharedValueAttribute {
template <class T>
class LP_TRANSFORMATIONS_API SharedAttribute : public ov::RuntimeAttribute {
public:
SharedValueAttribute() : sharedValue(std::make_shared<SharedValueType>()) {}
virtual ~SharedValueAttribute() = default;
std::shared_ptr<SharedValueType> sharedValue;
std::string get_string() {
std::stringstream ss;
virtual ~SharedAttribute() = default;
class LP_TRANSFORMATIONS_API SharedValueAttribute : public std::enable_shared_from_this<SharedValueAttribute> {
public:
struct LP_TRANSFORMATIONS_API SharedValue : public std::enable_shared_from_this<SharedValue> {
SharedValue() = default;
SharedValue(const T& value) : value{value} {}
T value = {};
std::vector<std::weak_ptr<SharedValueAttribute>> attributes;
};
SharedValueAttribute() : sharedValue(std::make_shared<SharedValue>()) {}
const size_t rawPointer = (size_t)this;
ss << rawPointer << ": ";
SharedValueAttribute(const T& value) : sharedValue{std::make_shared<SharedValue>(value)} {}
const size_t sharedValueRawPointer = (size_t)sharedValue.get();
ss << "sharedValue: " << sharedValueRawPointer;
std::shared_ptr<SharedValue> 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<SharedValueAttribute>()} {
attribute->sharedValue->attributes.emplace_back(attribute);
}
SharedAttribute(const T& value) : attribute{std::make_shared<SharedValueAttribute>(value)} {
attribute->sharedValue->attributes.emplace_back(attribute);
}
std::shared_ptr<SharedValueAttribute> 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 SharedValueAttributeType>
class LP_TRANSFORMATIONS_API SharedValue {
public:
virtual ~SharedValue() = default;
std::vector<std::weak_ptr<SharedValueAttributeType>> attributes;
};
@@ -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<PrecisionsAttributePtr>(input);
if (precisionsAttributeWrapper != nullptr) {
const auto precisionsAttribute = precisionsAttributeWrapper->get();
assert(precisionsAttribute != nullptr);
if (precisionsAttribute->sharedValue->precisions.empty()) {
auto precisionsAttributeWrapper = getAttribute<PrecisionsAttribute>(input);
if (!precisionsAttributeWrapper.empty()) {
if (precisionsAttributeWrapper.as<PrecisionsAttribute>().value().empty()) {
return false;
}
}
@@ -63,16 +61,15 @@ public:
for (auto input : node->inputs()) {
if (needToCheckExpectedAttributeType) {
if (getAttribute<ExpectedAttributeType>(input) == nullptr) {
if (getAttribute<ExpectedAttributeType>(input).empty()) {
return false;
}
}
auto parentAttribute = getSourceAttribute(input);
if (parentAttribute == nullptr) {
if (parentAttribute.empty()) {
continue;
}
parentAttribute->get()->sharedValue->value = true;
parentAttribute.template as<AttributeType>().value() = true;
}
}
@@ -95,11 +92,11 @@ private:
return input;
}
std::shared_ptr<ngraph::VariantWrapper<AttributeType>> getSourceAttribute(const Input<Node>& input) {
ov::Any getSourceAttribute(const Input<Node>& input) {
const auto dequantizationInput = getDequantizationInput(input);
const auto output = dequantizationInput.get_source_output();
auto attribute = ngraph::pass::low_precision::getAttribute<AttributeType>(output.get_node()->shared_from_this());
if (attribute == nullptr) {
if (attribute.empty()) {
attribute = ngraph::pass::low_precision::getAttribute<AttributeType>(output.get_node_shared_ptr());
}
return attribute;
@@ -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<ngraph::pass::GraphRewrite> intervalsAlignment = manager.register_pass<ngraph::pass::GraphRewrite>();
intervalsAlignment->add_matcher<low_precision::CreateAttribute<IntervalsAlignmentAttributePtr, opset1::FakeQuantize>>();
intervalsAlignment->add_matcher<low_precision::CreateAttribute<IntervalsAlignmentAttribute, opset1::FakeQuantize>>();
intervalsAlignment->add_matcher<low_precision::PropagateThroughPrecisionPreserved<IntervalsAlignmentAttribute>>();
manager.run_passes(f);
return false;
@@ -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<ngraph::pass::GraphRewrite> propagation = manager.register_pass<ngraph::pass::GraphRewrite>();
propagation->add_matcher<low_precision::CreateAttribute<QuantizationAlignmentAttributePtr>>();
propagation->add_matcher<low_precision::CreateAttribute<QuantizationAlignmentAttribute>>();
propagation->add_matcher<low_precision::PropagateThroughPrecisionPreserved<QuantizationAlignmentAttribute>>();
propagation->add_matcher<low_precision::UpdateSharedPrecisionPreserved<QuantizationAlignmentAttributePtr, PerTensorQuantizationAttribute>>();
propagation->add_matcher<low_precision::UpdateSharedPrecisionPreserved<QuantizationAlignmentAttribute, PerTensorQuantizationAttribute>>();
manager.run_passes(f);
return false;
}
@@ -45,8 +45,8 @@ namespace {
// 2. Precisions on port
DataPrecision getDataPrecisionByOutputPortAndFakeQuantize(std::shared_ptr<opset1::FakeQuantize> layer) {
const QuantizationDetails quantizationDetails = QuantizationDetails::getDetails(layer);
auto precisionsAttribute = getAttributeFromOutput<std::shared_ptr<PrecisionsAttribute>>(layer->output(0));
if (precisionsAttribute == nullptr) {
auto precisionsAttribute = getAttributeFromOutput<PrecisionsAttribute>(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_ptr<opset1
precisionDetailsAtOutputIntervals.hasZeroPoint);
}
const auto& precisions = precisionsAttribute->get()->sharedValue->precisions;
const auto& precisions = precisionsAttribute.as<PrecisionsAttribute>().value();
ngraph::element::Type precision;
bool hasZeroPoint;
@@ -77,7 +77,7 @@ DataPrecision getDataPrecisionByOutputPortAndFakeQuantize(std::shared_ptr<opset1
}
// update shared attribute to affect all operations in subgraph
precisionsAttribute->get()->sharedValue->precisions = { precision };
precisionsAttribute.as<PrecisionsAttribute>().value() = { precision };
} else {
// use only available precision
precision = *precisions.begin();
@@ -100,8 +100,8 @@ DataPrecision getDataPrecisionByOutputPort(std::shared_ptr<opset1::FakeQuantize>
const std::vector<float> outputLowValues = ov::as_type_ptr<opset1::Constant>(layer->get_input_node_shared_ptr(3))->cast_vector<float>();
const std::vector<float> outputHighValues = ov::as_type_ptr<opset1::Constant>(layer->get_input_node_shared_ptr(4))->cast_vector<float>();
auto precisionsAttribute = getAttributeFromOutput<std::shared_ptr<PrecisionsAttribute>>(layer->output(0));
if (precisionsAttribute == nullptr) {
auto precisionsAttribute = getAttributeFromOutput<PrecisionsAttribute>(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<opset1::FakeQuantize>
precisionDetailsAtOutputIntervals.hasZeroPoint);
}
const auto& precisions = precisionsAttribute->get()->sharedValue->precisions;
const auto& precisions = precisionsAttribute.as<PrecisionsAttribute>().value();
std::vector<element::Type> precisionsForLevels{};
switch (levels) {
case 65536:
@@ -153,7 +153,7 @@ DataPrecision getDataPrecisionByOutputPort(std::shared_ptr<opset1::FakeQuantize>
}
// update shared attribute to affect all operations in subgraph
precisionsAttribute->get()->sharedValue->precisions = { precision };
precisionsAttribute.as<PrecisionsAttribute>().value() = { precision };
} else {
// use only available precision
precision = *resultPrecisions.begin();
@@ -175,14 +175,14 @@ DataPrecision getDataPrecisionByOutputPort(std::shared_ptr<opset1::FakeQuantize>
std::tuple<std::shared_ptr<Node>, std::shared_ptr<Node>> decomposeFakeQuantize(
MatcherPass* matcherPass,
std::shared_ptr<opset1::FakeQuantize>& layer,
const std::shared_ptr<IntervalsAlignmentAttribute>& intervalsAlignment,
const ov::Any& intervalsAlignment,
const DataPrecision& dataPrecision,
const bool updatePrecisions,
const element::Type deqPrecision) {
std::shared_ptr<ngraph::Node> dequantize;
std::shared_ptr<ngraph::Node> newFQ;
if (intervalsAlignment != nullptr) {
if (!intervalsAlignment.empty()) {
OV_ITT_SCOPE(FIRST_INFERENCE, itt::domains::LPT_LT, "decomposeFakeQuantize1");
const std::vector<float> outputLowValues = ov::as_type_ptr<opset1::Constant>(layer->get_input_node_shared_ptr(3))->cast_vector<float>();
const std::vector<float> outputHighValues = ov::as_type_ptr<opset1::Constant>(layer->get_input_node_shared_ptr(4))->cast_vector<float>();
@@ -194,8 +194,8 @@ std::tuple<std::shared_ptr<Node>, std::shared_ptr<Node>> decomposeFakeQuantize(
const size_t levels = NetworkHelper::calculateLevels(
dataPrecision.min,
dataPrecision.max,
intervalsAlignment->sharedValue->combinedInterval.low,
intervalsAlignment->sharedValue->combinedInterval.high,
intervalsAlignment.as<IntervalsAlignmentAttribute>().value().combinedInterval.low,
intervalsAlignment.as<IntervalsAlignmentAttribute>().value().combinedInterval.high,
outputLowValues[0],
outputHighValues[0],
dequantizationMul,
@@ -286,8 +286,8 @@ bool FakeQuantizeDecompositionTransformation::transform(TransformationContext& c
return false;
}
auto attribute = getAttributeFromOutput<std::shared_ptr<PrecisionsAttribute>>(layer->output(0));
if ((attribute == nullptr) || (attribute->get()->sharedValue->precisions.empty())) {
auto attribute = getAttributeFromOutput<PrecisionsAttribute>(layer->output(0));
if (attribute.empty() || (attribute.as<PrecisionsAttribute>().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 precisionsAttribute;
{
// TODO: LPT: return attribute (not wrapper)
auto attributeWrapper = getAttributeFromOutput<std::shared_ptr<PrecisionsAttribute>>(layer->output(0));
if (attributeWrapper == nullptr) {
THROW_IE_LPT_EXCEPTION(*layer) << "PrecisionAttribute is absent";
}
precisionsAttribute = attributeWrapper->get();
if (precisionsAttribute == nullptr) {
auto attributeWrapper = getAttributeFromOutput<PrecisionsAttribute>(layer->output(0));
if (attributeWrapper.empty()) {
THROW_IE_LPT_EXCEPTION(*layer) << "PrecisionAttribute is absent";
}
precisionsAttribute = attributeWrapper.as<PrecisionsAttribute>();
}
std::shared_ptr<QuantizationAlignmentAttribute> quantizationAlignment;
ov::Any quantizationAlignment;
for (const auto& input : layer->output(0).get_target_inputs()) {
const auto alignmentValueWrapper = low_precision::getAttribute<std::shared_ptr<QuantizationAlignmentAttribute>>(input.get_node()->shared_from_this());
if (alignmentValueWrapper != nullptr) {
quantizationAlignment = alignmentValueWrapper->get();
if (quantizationAlignment->sharedValue->value) {
quantizationAlignment = low_precision::getAttribute<QuantizationAlignmentAttribute>(input.get_node()->shared_from_this());
if (!quantizationAlignment.empty()) {
if (quantizationAlignment.as<QuantizationAlignmentAttribute>().value()) {
break;
}
}
}
std::shared_ptr<IntervalsAlignmentAttribute> intervalsAlignment;
{
if ((quantizationAlignment != nullptr) && quantizationAlignment->sharedValue->value) {
auto intervalsAlignmentWrapper = low_precision::getAttribute<std::shared_ptr<IntervalsAlignmentAttribute>>(layer);
if (intervalsAlignmentWrapper != nullptr) {
intervalsAlignment = intervalsAlignmentWrapper->get();
}
}
ov::Any intervalsAlignment;
if (!quantizationAlignment.empty() && quantizationAlignment.as<QuantizationAlignmentAttribute>().value()) {
intervalsAlignment = low_precision::getAttribute<IntervalsAlignmentAttribute>(layer);
}
// FakeQuantize operations are combined in supported cascade (per tensor quantization)
if ((intervalsAlignment != nullptr) && (intervalsAlignment->sharedValue->minLevels <= 2ul)) {
if (!intervalsAlignment.empty() && (intervalsAlignment.as<IntervalsAlignmentAttribute>().value().minLevels <= 2ul)) {
return false;
}
@@ -366,20 +357,20 @@ bool FakeQuantizeDecompositionTransformation::transform(TransformationContext& c
const auto levels = layer->get_levels();
const std::vector<float> outputLowValues = ov::as_type_ptr<opset1::Constant>(layer->get_input_node_shared_ptr(3))->cast_vector<float>();
const std::vector<float> outputHighValues = ov::as_type_ptr<opset1::Constant>(layer->get_input_node_shared_ptr(4))->cast_vector<float>();
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<IntervalsAlignmentAttribute>().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<IntervalsAlignmentAttribute>().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;
@@ -80,9 +80,9 @@ bool FuseMultiplyToFakeQuantizeTransformation::transform(TransformationContext&
replace_node(multiply, newFakeQuantize);
NetworkHelper::copyInfo(fakeQuantize, newFakeQuantize);
const auto intervalAlignment = getAttribute<IntervalsAlignmentAttributePtr>(fakeQuantize);
if ((intervalAlignment != nullptr) && (intervalAlignment->get()->levels != 0ul)) {
newFakeQuantize->set_levels(intervalAlignment->get()->levels);
const auto intervalAlignment = getAttribute<IntervalsAlignmentAttribute>(fakeQuantize);
if (!intervalAlignment.empty() && (intervalAlignment.as<IntervalsAlignmentAttribute>().levels != 0ul)) {
newFakeQuantize->set_levels(intervalAlignment.as<IntervalsAlignmentAttribute>().levels);
}
updateOutput(context, newFakeQuantize, multiply);
@@ -20,7 +20,7 @@ bool ngraph::pass::low_precision::MarkupAvgPoolPrecisionPreserved::run_on_functi
std::shared_ptr<ngraph::pass::GraphRewrite> markupAvgPoolPrecision = manager.register_pass<ngraph::pass::GraphRewrite>();
markupAvgPoolPrecision->add_matcher<low_precision::CreatePrecisionsDependentAttribute<AvgPoolPrecisionPreservedAttribute, opset1::AvgPool>>();
markupAvgPoolPrecision->add_matcher<low_precision::PropagateThroughPrecisionPreserved<AvgPoolPrecisionPreservedAttribute>>();
markupAvgPoolPrecision->add_matcher<low_precision::UpdateSharedPrecisionPreserved<AvgPoolPrecisionPreservedAttributePtr>>();
markupAvgPoolPrecision->add_matcher<low_precision::UpdateSharedPrecisionPreserved<AvgPoolPrecisionPreservedAttribute>>();
manager.run_passes(f);
return false;
}
@@ -22,13 +22,9 @@ bool ngraph::pass::low_precision::MarkupCanBeQuantized::run_on_function(std::sha
auto setEmptyPrecisions = [](const std::shared_ptr<ngraph::Node>& node) {
for (auto& input : node->inputs()) {
auto& rt = input.get_rt_info();
auto attribute = ngraph::pass::low_precision::make_shared_attribute<PrecisionsAttribute>(std::vector<element::Type>());
auto attributeWrapper = std::make_shared<ngraph::VariantWrapper<std::shared_ptr<PrecisionsAttribute>>>(attribute);
rt.emplace(
ngraph::VariantWrapper<std::shared_ptr<PrecisionsAttribute>>::type_info.name,
attributeWrapper);
PrecisionsAttribute::get_type_info_static(),
PrecisionsAttribute(std::vector<element::Type>()));
}
};
@@ -33,8 +33,8 @@ bool ngraph::pass::low_precision::MarkupPerTensorQuantization::run_on_function(s
auto createAttribute = [](Input<Node>& input){
auto &rt = input.get_rt_info();
rt.emplace(
ngraph::VariantWrapper<PerTensorQuantizationAttribute>::type_info.name,
std::make_shared<::ngraph::VariantWrapper<PerTensorQuantizationAttribute>>(PerTensorQuantizationAttribute()));
PerTensorQuantizationAttribute::get_type_info_static(),
PerTensorQuantizationAttribute());
};
if (restrictedPorts.empty()) {
@@ -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<PrecisionsAttribute>(std::vector<element::Type>());
auto attributeWrapper = std::make_shared<ngraph::VariantWrapper<std::shared_ptr<PrecisionsAttribute>>>(attribute);
rt.emplace(
ngraph::VariantWrapper<std::shared_ptr<PrecisionsAttribute>>::type_info.name,
attributeWrapper);
PrecisionsAttribute::get_type_info_static(),
PrecisionsAttribute(std::vector<element::Type>()));
}
} else {
for (const std::pair<size_t, std::vector<ngraph::element::Type>>& item : precisionsByPort) {
Input<Node> input = node->input(item.first);
auto& rt = input.get_rt_info();
auto precisionsAttribute = ngraph::pass::low_precision::getAttribute<std::shared_ptr<PrecisionsAttribute>>(input);
if ((precisionsAttribute != nullptr) &&
(precisionsAttribute->get()->sharedValue != nullptr) &&
(precisionsAttribute->get()->sharedValue->precisions.empty())) {
auto precisionsAttribute = ngraph::pass::low_precision::getAttribute<PrecisionsAttribute>(input);
if ((!precisionsAttribute.empty()) &&
(precisionsAttribute.as<PrecisionsAttribute>().value().empty())) {
return;
}
auto attribute = ngraph::pass::low_precision::make_shared_attribute<PrecisionsAttribute>(item.second);
auto attributeWrapper = std::make_shared<ngraph::VariantWrapper<std::shared_ptr<PrecisionsAttribute>>>(attribute);
auto& rt = input.get_rt_info();
rt[ngraph::VariantWrapper<std::shared_ptr<PrecisionsAttribute>>::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<PrecisionPreservedAttributePtr>::type_info.name,
std::make_shared<::ngraph::VariantWrapper<PrecisionPreservedAttributePtr>>(
make_shared_attribute<PrecisionPreservedAttribute>(precisionPreserved)));
PrecisionPreservedAttribute::get_type_info_static(),
PrecisionPreservedAttribute(precisionPreserved));
}
const auto& typeInfo = node->get_type_info();
@@ -54,10 +54,10 @@ bool MatMulTransformation::transform(TransformationContext &context, ngraph::pat
if (fakeQuantize != nullptr) {
const QuantizationDetails quantizationDetails = QuantizationDetails::getDetails(fakeQuantize);
const auto precisionsAttribute = getAttributeFromOutput<PrecisionsAttributePtr>(fakeQuantize);
const auto precisions = precisionsAttribute == nullptr ?
const auto precisionsAttribute = getAttributeFromOutput<PrecisionsAttribute>(fakeQuantize);
const auto precisions = precisionsAttribute.empty() ?
PrecisionsAttribute::defaultPrecisions :
precisionsAttribute->get()->sharedValue->precisions;
precisionsAttribute.as<PrecisionsAttribute>().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<PrecisionsAttributePtr>(matMul->input(1));
const auto precisions = precisionsAttribute == nullptr ?
const auto precisionsAttribute = getAttribute<PrecisionsAttribute>(matMul->input(1));
const auto precisions = precisionsAttribute.empty() ?
PrecisionsAttribute::defaultPrecisions :
precisionsAttribute->get()->sharedValue->precisions;
precisionsAttribute.as<PrecisionsAttribute>().value();
const DataPrecision dataPrecision = getDataPrecision(fakeQuantize, quantizationDetails, precisions);
if (dataPrecision.hasZeroPoint) {
@@ -66,10 +66,10 @@ bool MultiplyToGroupConvolutionTransformation::transform(TransformationContext&
// if restrictions are absent precisions attribute is used
if (weightsPrecision == element::undefined) {
const auto precisionsAttribute = getAttribute<PrecisionsAttributePtr>(multiply->input(inputIndex == 0ul ? 1ul : 0ul));
const auto precisionsAttribute = getAttribute<PrecisionsAttribute>(multiply->input(inputIndex == 0ul ? 1ul : 0ul));
const auto precisions = precisionsAttribute == nullptr ?
PrecisionsAttribute::defaultPrecisions :
precisionsAttribute->get()->sharedValue->precisions;
precisionsAttribute.as<PrecisionsAttribute>().value();
weightsPrecision = precisions[0];
}
} else {
@@ -668,13 +668,12 @@ std::shared_ptr<opset1::FakeQuantize> NetworkHelper::fuseConvert(const std::shar
bool NetworkHelper::isPrecisionPreserved(const std::shared_ptr<ngraph::Node>& node) {
auto& rt = node->get_rt_info();
auto it = rt.find(ngraph::VariantWrapper<PrecisionPreservedAttributePtr>::type_info.name);
auto it = rt.find(PrecisionPreservedAttribute::get_type_info_static());
if (it == rt.end()) {
return false;
}
auto attribute = std::dynamic_pointer_cast<ngraph::VariantWrapper<PrecisionPreservedAttributePtr>>(it->second);
assert(attribute != nullptr);
return attribute->get()->sharedValue->value;
auto attribute = it->second;
return attribute.as<PrecisionPreservedAttribute>().value();
}
size_t NetworkHelper::calculateLevels(
@@ -1854,15 +1853,11 @@ bool NetworkHelper::isDQByDynamicDimension(const std::shared_ptr<Node>& layer, s
bool isDisabled(const std::shared_ptr<Node>& node) {
for (const auto& input : node->inputs()) {
auto precisionAttribute = getAttribute<std::shared_ptr<PrecisionsAttribute>>(input);
if (precisionAttribute == nullptr) {
auto precisionAttribute = getAttribute<PrecisionsAttribute>(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<PrecisionsAttribute>().value();
if (precisionRestrictions.empty()) {
return true;
}
@@ -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<ngraph::pass::GraphRewrite> precisionsPropagation = manager.register_pass<ngraph::pass::GraphRewrite>();
precisionsPropagation->add_matcher<low_precision::CreateAttribute<PrecisionsAttributePtr, opset1::FakeQuantize>>(AttributeSource::OutputPort);
precisionsPropagation->add_matcher<low_precision::CreateAttribute<PrecisionsAttribute, opset1::FakeQuantize>>(AttributeSource::OutputPort);
precisionsPropagation->add_matcher<low_precision::PropagateThroughPrecisionPreserved<PrecisionsAttribute>>();
precisionsPropagation->add_matcher<low_precision::PropagateToInput<PrecisionsAttribute>>();
manager.run_passes(f);
@@ -11,18 +11,13 @@
using namespace ngraph;
using namespace ov;
template class ngraph::VariantImpl<AvgPoolPrecisionPreservedAttributePtr>;
constexpr VariantTypeInfo VariantWrapper<AvgPoolPrecisionPreservedAttributePtr>::type_info;
void VariantWrapper<AvgPoolPrecisionPreservedAttributePtr>::merge(
std::vector<std::shared_ptr<ngraph::VariantWrapper<std::shared_ptr<AvgPoolPrecisionPreservedAttribute>>>>& attributes) {
void AvgPoolPrecisionPreservedAttribute::merge(std::vector<ov::Any>& attributes) {
}
std::string VariantWrapper<AvgPoolPrecisionPreservedAttributePtr>::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();
}
@@ -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<IntervalsAlignmentSharedValue>(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<IntervalsAlignmentSharedValue>(combinedInterval, minInterval, minLevels);
const size_t minLevels) :
SharedAttribute(IntervalsAlignmentSharedValue{combinedInterval, minInterval, minLevels}),
levels(levels) {
}
template class ngraph::VariantImpl<IntervalsAlignmentAttributePtr>;
constexpr VariantTypeInfo VariantWrapper<IntervalsAlignmentAttributePtr>::type_info;
std::shared_ptr<VariantWrapper<std::shared_ptr<IntervalsAlignmentAttribute>>> VariantWrapper<IntervalsAlignmentAttributePtr>::create(
ov::Any IntervalsAlignmentAttribute::create(
const std::shared_ptr<ngraph::Node>& node,
const AttributeParameters& params) {
if (!ov::is_type<opset1::FakeQuantize>(node)) {
@@ -109,11 +107,10 @@ std::shared_ptr<VariantWrapper<std::shared_ptr<IntervalsAlignmentAttribute>>> Va
auto& rtInfo = node->get_rt_info();
const IntervalsAlignmentSharedValue::Interval interval{ lowInterval, highInterval };
const auto attribute = std::make_shared<::ngraph::VariantWrapper<IntervalsAlignmentAttributePtr>>(
ngraph::pass::low_precision::make_shared_attribute<IntervalsAlignmentAttribute>(
auto attribute = IntervalsAlignmentAttribute(
interval,
fakeQuantize->get_levels()));
rtInfo[ngraph::VariantWrapper<IntervalsAlignmentAttributePtr>::type_info.name] = attribute;
fakeQuantize->get_levels());
auto& result = (rtInfo[IntervalsAlignmentAttribute::get_type_info_static()] = attribute);
const std::vector<float> outputLowValues = ov::as_type_ptr<opset1::Constant>(fakeQuantize->get_input_node_shared_ptr(3))->cast_vector<float>();
const std::vector<float> outputHighValues = ov::as_type_ptr<opset1::Constant>(fakeQuantize->get_input_node_shared_ptr(4))->cast_vector<float>();
@@ -123,50 +120,49 @@ std::shared_ptr<VariantWrapper<std::shared_ptr<IntervalsAlignmentAttribute>>> 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<IntervalsAlignmentAttributePtr>::merge(
std::vector<std::shared_ptr<VariantWrapper<std::shared_ptr<IntervalsAlignmentAttribute>>>>& attributes) {
std::shared_ptr<IntervalsAlignmentAttribute> resultAttribute = get();
void IntervalsAlignmentAttribute::merge(
std::vector<ov::Any>& attributes) {
for (const auto& attributeWrapper : attributes) {
auto attribute = attributeWrapper->get();
auto attribute = attributeWrapper.as<IntervalsAlignmentAttribute>().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<IntervalsAlignmentAttribute>().value();
if (levels != attributeWrapper.as<IntervalsAlignmentAttribute>().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<IntervalsAlignmentAttributePtr>::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<IntervalsAlignmentAttributePtr>::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();
@@ -7,5 +7,4 @@
using namespace ngraph;
using namespace ov;
template class ngraph::VariantImpl<PerTensorQuantizationAttribute>;
constexpr VariantTypeInfo VariantWrapper<PerTensorQuantizationAttribute>::type_info;
PerTensorQuantizationAttribute::~PerTensorQuantizationAttribute() = default;
@@ -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<PrecisionPreservedAttributePtr>;
constexpr VariantTypeInfo VariantWrapper<PrecisionPreservedAttributePtr>::type_info;
std::string VariantWrapper<PrecisionPreservedAttributePtr>::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();
}
@@ -19,30 +19,21 @@ using namespace ov;
// order defines default precision
std::vector<ngraph::element::Type> PrecisionsAttribute::defaultPrecisions = {ngraph::element::u8, ngraph::element::i8};
PrecisionsAttribute::PrecisionsAttribute(const std::vector<ngraph::element::Type>& precisions) {
sharedValue->precisions = precisions;
PrecisionsAttribute::PrecisionsAttribute(const std::vector<ngraph::element::Type>& precisions) :
SharedAttribute(precisions) {
}
template class ngraph::VariantImpl<std::shared_ptr<PrecisionsAttribute>>;
constexpr VariantTypeInfo VariantWrapper<std::shared_ptr<PrecisionsAttribute>>::type_info;
std::shared_ptr<VariantWrapper<std::shared_ptr<PrecisionsAttribute>>> VariantWrapper<std::shared_ptr<PrecisionsAttribute>>::create(
ov::Any PrecisionsAttribute::create(
const std::shared_ptr<ngraph::Node>& node,
const AttributeParameters& params) {
auto attribute = ngraph::pass::low_precision::make_shared_attribute<PrecisionsAttribute>();
auto wrapper = std::make_shared<ngraph::VariantWrapper<std::shared_ptr<PrecisionsAttribute>>>(attribute);
auto& rt = ov::is_type<opset1::FakeQuantize>(node) ? node->output(0).get_rt_info() : node->get_rt_info();
rt[ngraph::VariantWrapper<std::shared_ptr<PrecisionsAttribute>>::type_info.name] = wrapper;
return wrapper;
return (rt[PrecisionsAttribute::get_type_info_static()] = PrecisionsAttribute());
}
void VariantWrapper<std::shared_ptr<PrecisionsAttribute>>::merge(
std::vector<std::shared_ptr<VariantWrapper<std::shared_ptr<PrecisionsAttribute>>>>& attributes) {
auto& my = this->get()->sharedValue->precisions;
void PrecisionsAttribute::merge(std::vector<ov::Any>& attributes) {
auto& my = value();
for (auto attribute : attributes) {
const auto& attributeValues = attribute->get()->sharedValue->precisions;
const auto& attributeValues = attribute.as<PrecisionsAttribute>().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<std::shared_ptr<PrecisionsAttribute>>::merge(
}
}
ov::Any VariantWrapper<std::shared_ptr<PrecisionsAttribute>>::init(const std::shared_ptr<ngraph::Node>& node) {
return {};
}
std::string VariantWrapper<std::shared_ptr<PrecisionsAttribute>>::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 << "}";
@@ -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<QuantizationAlignmentSharedValue>(hasToBeAligned);
QuantizationAlignmentAttribute::QuantizationAlignmentAttribute(const bool hasToBeAligned) :
SharedAttribute(hasToBeAligned) {
}
template class ngraph::VariantImpl<QuantizationAlignmentAttributePtr>;
constexpr VariantTypeInfo VariantWrapper<QuantizationAlignmentAttributePtr>::type_info;
ov::Any VariantWrapper<QuantizationAlignmentAttributePtr>::init(const std::shared_ptr<ngraph::Node>& node) {
return nullptr;
}
std::shared_ptr<VariantWrapper<std::shared_ptr<QuantizationAlignmentAttribute>>> VariantWrapper<QuantizationAlignmentAttributePtr>::create(
ov::Any QuantizationAlignmentAttribute::create(
const std::shared_ptr<ngraph::Node>& node,
const AttributeParameters& params) {
if (getAttribute<std::shared_ptr<QuantizationAlignmentAttribute>>(node) != nullptr) {
return nullptr;
if (!getAttribute<QuantizationAlignmentAttribute>(node).empty()) {
return {};
}
if (!NetworkHelper::isPrecisionPreserved(node)) {
return nullptr;
return {};
}
bool leastOneOperationIsFakeQuantize = false;
@@ -66,26 +58,22 @@ std::shared_ptr<VariantWrapper<std::shared_ptr<QuantizationAlignmentAttribute>>>
if (leastOneOperationIsFakeQuantize && !leastOneOperationIsNotFakeQuantize) {
auto& rt = node->get_rt_info();
const auto attribute = std::make_shared<ngraph::VariantWrapper<QuantizationAlignmentAttributePtr>>(
make_shared_attribute<QuantizationAlignmentAttribute>());
rt[ngraph::VariantWrapper<QuantizationAlignmentAttributePtr>::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<QuantizationAlignmentAttributePtr>::merge(
std::vector<std::shared_ptr<VariantWrapper<std::shared_ptr<QuantizationAlignmentAttribute>>>>& attributes) {
auto currentAttributte = get();
for (const auto& attribute : attributes) {
currentAttributte->sharedValue->value = currentAttributte->sharedValue->value || attribute->get()->sharedValue->value;
void QuantizationAlignmentAttribute::merge(std::vector<ov::Any>& attributes) {
for (const auto& other_attribute : attributes) {
value() = value() || other_attribute.as<QuantizationAlignmentAttribute>().value();
}
}
std::string VariantWrapper<QuantizationAlignmentAttributePtr>::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();
}
@@ -298,10 +298,10 @@ bool WeightableLayerTransformation::decomposeFakeQuantizeForWeightsPath(const st
}
const QuantizationDetails quantizationDetails = QuantizationDetails::getDetails(fq);
const auto precisionsAttribute = getAttributeFromOutput<PrecisionsAttributePtr>(fq);
const auto precisions = precisionsAttribute == nullptr ?
const auto precisionsAttribute = getAttributeFromOutput<PrecisionsAttribute>(fq);
const auto precisions = precisionsAttribute.empty() ?
PrecisionsAttribute::defaultPrecisions :
precisionsAttribute->get()->sharedValue->precisions;
precisionsAttribute.as<PrecisionsAttribute>().value();
const DataPrecision dataPrecision = getDataPrecision(fq, quantizationDetails, precisions);
@@ -365,10 +365,10 @@ DataPrecision WeightableLayerTransformation::getDataPrecisionOnWeights(const std
return DataPrecision();
}
const auto precisionsAttribute = getAttributeFromOutput<PrecisionsAttributePtr>(fq);
const auto precisions = precisionsAttribute == nullptr ?
const auto precisionsAttribute = getAttributeFromOutput<PrecisionsAttribute>(fq);
const auto precisions = precisionsAttribute.empty() ?
PrecisionsAttribute::defaultPrecisions :
precisionsAttribute->get()->sharedValue->precisions;
precisionsAttribute.as<PrecisionsAttribute>().value();
return getDataPrecision(fq, quantizationDetails, precisions);
}
@@ -1,21 +0,0 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <ngraph/axis_vector.hpp>
#include <ngraph/variant.hpp>
#include <transformations_visibility.hpp>
namespace ov {
template <>
class TRANSFORMATIONS_API VariantWrapper<std::vector<size_t>> : public VariantImpl<std::vector<size_t>> {
public:
OPENVINO_RTTI("VariantWrapper<std::vector<size_t>>");
BWDCMP_RTTI_DECLARATION;
VariantWrapper(const value_type& value) : VariantImpl<value_type>(value) {}
};
} // namespace ov
+6 -9
View File
@@ -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<ngraph::Node>& n) -> ngraph:
// ToDo: change to reg_t
std::vector<size_t> rout;
auto rinfo = rt["reginfo"];
if (!rinfo.empty()) {
auto reginfo = ngraph::as_type_ptr<ngraph::VariantWrapper<std::vector<size_t>>>(rinfo)->get();
for (auto reg : reginfo) {
auto it_rt = rt.find("reginfo");
if (it_rt == rt.end()) {
for (auto reg : it_rt->second.as<std::vector<size_t>>()) {
rout.push_back(reg);
}
}
@@ -28,10 +26,9 @@ auto ngraph::snippets::getRegisters(std::shared_ptr<ngraph::Node>& n) -> ngraph:
std::vector<size_t> 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<ngraph::VariantWrapper<std::vector<size_t>>>(rinfo)->get();
for (auto reg : reginfo) {
auto it_rt = rt.find("reginfo");
if (it_rt == rt.end()) {
for (auto reg : it_rt->second.as<std::vector<size_t>>()) {
rin.push_back(reg);
}
}
@@ -7,7 +7,6 @@
#include "remarks.hpp"
#include "snippets/pass/assign_registers.hpp"
#include "snippets/register_info.hpp"
#include "snippets/snippets_isa.hpp"
#include <ngraph/opsets/opset1.hpp>
@@ -152,7 +151,7 @@ bool ngraph::snippets::pass::AssignRegisters::run_on_function(std::shared_ptr<Fu
// store only effective address
if (auto result = std::dynamic_pointer_cast<snippets::op::Store>(n)) {
auto ea = reg64_tmp_start+static_cast<int64_t>(f->get_result_index(result) + f->get_parameters().size());
rt["effectiveAddress"] = std::make_shared<VariantWrapper<int64_t>>(VariantWrapper<int64_t>(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<Fu
if (auto param = ov::as_type_ptr<opset1::Parameter>(source)) {
auto ea = reg64_tmp_start+static_cast<int64_t>(f->get_parameter_index(param));
rt["effectiveAddress"] = std::make_shared<VariantWrapper<int64_t>>(VariantWrapper<int64_t>(ea));
rt["effectiveAddress"] = ea;
} else if (auto constant = ov::as_type_ptr<opset1::Constant>(source)) {
auto ea = reg64_tmp_start+static_cast<int64_t>(f->get_parameters().size() + f->get_results().size() + 1 + constantID);
rt["effectiveAddress"] = std::make_shared<VariantWrapper<int64_t>>(VariantWrapper<int64_t>(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<Fu
auto allocated = physical_regs[output.get_tensor_ptr()];
regs.push_back(allocated);
}
rt["reginfo"] = std::make_shared<VariantWrapper<std::vector<size_t>>>(VariantWrapper<std::vector<size_t>>(regs));
rt["reginfo"] = regs;
}
return false;
@@ -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<std::vector<size_t>>;
BWDCMP_RTTI_DEFINITION(ngraph::VariantWrapper<std::vector<size_t>>);
@@ -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 <vector>
#include <memory>
#include <ngraph/pass/graph_rewrite.hpp>
/**
* @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<ngraph::Function> f) override;
};
@@ -10,7 +10,6 @@
#include <ngraph/factory.hpp>
#include <ngraph/node.hpp>
#include <openvino/core/preprocess/input_tensor_info.hpp>
#include <openvino/core/variant.hpp>
#include <openvino/core/any.hpp>
#include <set>
#include <transformations/rt_info/disable_constant_folding.hpp>
@@ -30,19 +29,18 @@ namespace pass {
class TRANSFORMATIONS_API Attributes {
public:
Attributes();
~Attributes();
std::shared_ptr<Variant> create_by_type_info(const ov::DiscreteTypeInfo& type_info);
Any create_by_type_info(const ov::DiscreteTypeInfo& type_info_name);
private:
template <class T>
void register_factory() {
m_factory_registry.emplace(T::get_type_info_static(), [] {
return std::make_shared<T>();
m_factory_registry.emplace(T::get_type_info_static(), [] () -> Any {
return T{};
});
}
std::unordered_map<DiscreteTypeInfo, std::function<std::shared_ptr<Variant>()>> m_factory_registry;
std::unordered_map<ov::DiscreteTypeInfo, std::function<Any()>> m_factory_registry;
};
} // namespace pass
} // namespace ov
@@ -11,7 +11,7 @@
#include <set>
#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>& 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<void> {
class TRANSFORMATIONS_API Decompression : public RuntimeAttribute {
public:
OPENVINO_RTTI("decompression", "0");
@@ -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<Node
* @brief DisableFP16Compression class represents runtime info attribute that marks operation
* as prohibitted to convert to FP16 as part of Compressed Only format.
*/
class TRANSFORMATIONS_API DisableFP16Compression : public VariantImpl<void> {
class TRANSFORMATIONS_API DisableFP16Compression : public RuntimeAttribute {
public:
OPENVINO_RTTI("disable_fp16_compression", "0");
@@ -19,6 +19,7 @@
#include <ngraph/variant.hpp>
#include <openvino/core/rtti.hpp>
#include <ngraph/attribute_visitor.hpp>
#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<std::string> fused_names;
public:
friend class VariantWrapper<FusedNames>;
OPENVINO_RTTI("fused_names", "0");
/**
* A default constructor
@@ -64,6 +64,14 @@ public:
* @return vector if strings
*/
std::vector<std::string> getVectorNames() const;
ov::Any merge(const ngraph::NodeVector& nodes) const override;
ov::Any init(const std::shared_ptr<ngraph::Node>& 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<ngraph::Node> & node)
NGRAPH_API std::vector<std::string> getFusedNamesVector(const std::shared_ptr<ngraph::Node> & node);
} // namespace ngraph
namespace ov {
extern template class NGRAPH_API VariantImpl<ngraph::FusedNames>;
template<>
class NGRAPH_API VariantWrapper<ngraph::FusedNames> : public VariantImpl<ngraph::FusedNames> {
public:
OPENVINO_RTTI("fused_names", "0");
VariantWrapper() = default;
VariantWrapper(const value_type &value) : VariantImpl<value_type>(value) {}
Any merge(const ngraph::NodeVector & nodes) override;
Any init(const std::shared_ptr<ngraph::Node> & node) override;
bool visit_attributes(AttributeVisitor & visitor) override;
};
} // namespace ov
@@ -13,6 +13,7 @@
#include <ngraph/node.hpp>
#include <ngraph/variant.hpp>
#include <transformations_visibility.hpp>
#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<bool> {
class TRANSFORMATIONS_API NmsSelectedIndices : ov::RuntimeAttribute {
public:
OPENVINO_RTTI("nms_selected_indices", "0");
NmsSelectedIndices() = default;
NmsSelectedIndices(const value_type &value) : VariantImpl<value_type>(value) {}
bool is_copyable() const override { return false; }
};
@@ -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<ngraph::element::Type> {
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_type>(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>& node) {
@@ -57,13 +59,12 @@ inline bool has_old_api_map_element_type(const std::shared_ptr<Node>& node) {
inline OldApiMapElementType get_old_api_map_element_type(const std::shared_ptr<Node>& 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<OldApiMapElementType>(var)->get();
return rt_map.at(OldApiMapElementType::get_type_info_static()).as<OldApiMapElementType>();
}
inline void set_old_api_map_element_type(std::shared_ptr<Node>& node, const OldApiMapElementType& old_api_map) {
auto& rt_map = node->get_rt_info();
rt_map[OldApiMapElementType::get_type_info_static()] = std::make_shared<OldApiMapElementType>(old_api_map);
rt_map[OldApiMapElementType::get_type_info_static()] = old_api_map;
}
} // namespace ov
@@ -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<std::vector<uint64_t>> {
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_type>(value) {}
OldApiMapOrder(const std::vector<uint64_t>& value) : value(value) {}
bool is_copyable() const override {
return false;
}
bool visit_attributes(AttributeVisitor& visitor) override;
std::vector<uint64_t> value;
};
inline bool has_old_api_map_order(const std::shared_ptr<Node>& node) {
@@ -68,13 +70,12 @@ inline bool has_old_api_map_order(const std::shared_ptr<Node>& node) {
inline OldApiMapOrder get_old_api_map_order(const std::shared_ptr<Node>& 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<OldApiMapOrder>(var)->get();
return rt_map.at(OldApiMapOrder::get_type_info_static()).as<OldApiMapOrder>();
}
inline void set_old_api_map_order(std::shared_ptr<Node>& node, const OldApiMapOrder& old_api_map) {
auto& rt_map = node->get_rt_info();
rt_map[OldApiMapOrder::get_type_info_static()] = std::make_shared<OldApiMapOrder>(old_api_map);
rt_map[OldApiMapOrder::get_type_info_static()] = old_api_map;
}
} // namespace ov
@@ -18,6 +18,8 @@
#include <ngraph/node.hpp>
#include <ngraph/variant.hpp>
#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<ngraph::Node> & node);
class NGRAPH_API PrimitivesPriority : public VariantImpl<std::string> {
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_type>(value) {}
Any merge(const ngraph::NodeVector & nodes) override;
Any init(const std::shared_ptr<ngraph::Node> & 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
@@ -8,18 +8,17 @@
#include <ngraph/node_input.hpp>
#include <ngraph/variant.hpp>
#include <transformations_visibility.hpp>
#include "openvino/core/runtime_attribute.hpp"
namespace ov {
class TRANSFORMATIONS_API StridesPropagation : public VariantImpl<ngraph::Strides> {
public:
OPENVINO_RTTI("strides_propagation", "0");
StridesPropagation() = default;
StridesPropagation(const value_type& value) : VariantImpl<value_type>(value) {}
};
TRANSFORMATIONS_API bool has_strides_prop(const ngraph::Input<ngraph::Node>& node);
TRANSFORMATIONS_API ngraph::Strides get_strides_prop(const ngraph::Input<ngraph::Node>& node);
TRANSFORMATIONS_API void insert_strides_prop(ngraph::Input<ngraph::Node>& 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
@@ -5,20 +5,20 @@
#include "transformations/rt_info/attributes.hpp"
ov::pass::Attributes::Attributes() {
register_factory<VariantWrapper<ngraph::FusedNames>>();
register_factory<ngraph::FusedNames>();
register_factory<PrimitivesPriority>();
register_factory<DisableConstantFolding>();
register_factory<DisableFP16Compression>();
register_factory<NmsSelectedIndices>();
register_factory<StridesPropagation>();
register_factory<OldApiMapOrder>();
register_factory<OldApiMapElementType>();
register_factory<LayoutAttribute>();
register_factory<Decompression>();
register_factory<ov::preprocess::TensorInfoMemoryType>();
register_factory<StridesPropagation>();
}
std::shared_ptr<ov::Variant> 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::Variant> ov::pass::Attributes::create_by_type_info(const ov:
return {};
}
}
ov::pass::Attributes::~Attributes() = default;
@@ -6,7 +6,7 @@
void ov::mark_as_decompression(const std::shared_ptr<Node>& node) {
auto& rt_info = node->get_rt_info();
rt_info[Decompression::get_type_info_static()] = std::make_shared<Decompression>();
rt_info[Decompression::get_type_info_static()] = Decompression();
}
void ov::unmark_as_decompression(const std::shared_ptr<Node>& node) {
@@ -6,7 +6,7 @@
void ov::disable_fp16_compression(const std::shared_ptr<Node>& node) {
auto& rt_info = node->get_rt_info();
rt_info[DisableFP16Compression::get_type_info_static()] = std::make_shared<DisableFP16Compression>();
rt_info[DisableFP16Compression::get_type_info_static()] = DisableFP16Compression{};
}
void ov::enable_fp16_compression(const std::shared_ptr<Node>& node) {
@@ -4,14 +4,11 @@
#include "transformations/rt_info/nms_selected_indices.hpp"
template class ov::VariantImpl<ov::NmsSelectedIndices>;
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<NmsSelectedIndices>(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());
}
@@ -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;
}
Loaded 100 of 189 files, more files were not shown because too many files have changed in this diff. Show more