[CPU] Xor: convert to LogicalXor (#14115)
This commit is contained in:
1 parent
62e2a672fb
commit
3448681de9
5 files changed
+123
No files matched your search
+26
@@ -0,0 +1,26 @@
|
||||
// Copyright (C) 2018-2022 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <openvino/pass/graph_rewrite.hpp>
|
||||
#include <transformations_visibility.hpp>
|
||||
|
||||
namespace ov {
|
||||
namespace pass {
|
||||
|
||||
class TRANSFORMATIONS_API ConvertXorToLogicalXor;
|
||||
|
||||
} // namespace pass
|
||||
} // namespace ov
|
||||
|
||||
/**
|
||||
* @ingroup ie_transformation_common_api
|
||||
* @brief ConvertXorToLogicalXor converts v0::Xor to v1::LogicalXor.
|
||||
*/
|
||||
class ov::pass::ConvertXorToLogicalXor : public ov::pass::MatcherPass {
|
||||
public:
|
||||
OPENVINO_RTTI("ConvertXorToLogicalXor", "0");
|
||||
ConvertXorToLogicalXor();
|
||||
};
|
||||
+2
@@ -92,6 +92,7 @@
|
||||
#include "transformations/op_conversions/convert_softmax_upgrade.hpp"
|
||||
#include "transformations/op_conversions/convert_space_to_depth.hpp"
|
||||
#include "transformations/op_conversions/convert_subtract.hpp"
|
||||
#include "transformations/op_conversions/convert_xor_to_logical_xor.hpp"
|
||||
#include "transformations/op_conversions/detection_output_downgrade.hpp"
|
||||
#include "transformations/op_conversions/detection_output_upgrade.hpp"
|
||||
#include "transformations/op_conversions/einsum_decomposition.hpp"
|
||||
@@ -206,6 +207,7 @@ bool ov::pass::CommonOptimizations::run_on_model(const std::shared_ptr<ngraph::F
|
||||
REGISTER_DISABLED_PASS(manager, ConvertROIAlign3To9)
|
||||
REGISTER_PASS(manager, ConvertROIAlign9To3)
|
||||
REGISTER_PASS(manager, ConvertMulticlassNms8ToMulticlassNms9)
|
||||
REGISTER_PASS(manager, ConvertXorToLogicalXor)
|
||||
|
||||
auto fq_fusions = manager.register_pass<ngraph::pass::GraphRewrite>();
|
||||
ADD_MATCHER(fq_fusions, FakeQuantizeMulFusion)
|
||||
|
||||
@@ -289,6 +289,7 @@ bool ov::pass::ConvertPrecision::run_on_model(const std::shared_ptr<ngraph::Func
|
||||
{opset4::LogicalOr::get_type_info_static(), fuse_type_to_logical<opset4::LogicalOr>},
|
||||
{opset4::LogicalXor::get_type_info_static(), fuse_type_to_logical<opset4::LogicalXor>},
|
||||
{opset4::LogicalNot::get_type_info_static(), fuse_type_to_logical<opset4::LogicalNot>},
|
||||
{opset1::Xor::get_type_info_static(), fuse_type_to_logical<opset1::Xor>},
|
||||
{opset4::ReduceLogicalAnd::get_type_info_static(), fuse_type_to_reduce_logical<opset4::ReduceLogicalAnd>},
|
||||
{opset4::ReduceLogicalOr::get_type_info_static(), fuse_type_to_reduce_logical<opset4::ReduceLogicalOr>},
|
||||
{opset1::ShapeOf::get_type_info_static(), fuse_type_to_shapeof_v0},
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// Copyright (C) 2018-2022 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "transformations/op_conversions/convert_xor_to_logical_xor.hpp"
|
||||
|
||||
#include <ngraph/pattern/op/wrap_type.hpp>
|
||||
#include <ngraph/rt_info.hpp>
|
||||
#include <openvino/opsets/opset1.hpp>
|
||||
#include <openvino/opsets/opset10.hpp>
|
||||
|
||||
#include "itt.hpp"
|
||||
|
||||
ov::pass::ConvertXorToLogicalXor::ConvertXorToLogicalXor() {
|
||||
MATCHER_SCOPE(ConvertXorToLogicalXor);
|
||||
|
||||
auto xor_v1 = pattern::wrap_type<ov::opset1::Xor>();
|
||||
|
||||
matcher_pass_callback callback = [=](pattern::Matcher& m) {
|
||||
auto xor_v1_node = std::dynamic_pointer_cast<ov::opset1::Xor>(m.get_match_root());
|
||||
if (!xor_v1_node)
|
||||
return false;
|
||||
|
||||
const auto& autobroad = xor_v1_node->get_autob();
|
||||
|
||||
auto logical_xor_v10 = std::make_shared<ov::opset10::LogicalXor>(xor_v1_node->input_value(0),
|
||||
xor_v1_node->input_value(1),
|
||||
autobroad);
|
||||
logical_xor_v10->set_friendly_name(xor_v1_node->get_friendly_name());
|
||||
ov::copy_runtime_info(xor_v1_node, logical_xor_v10);
|
||||
ov::replace_node(xor_v1_node, logical_xor_v10);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
auto m = std::make_shared<pattern::Matcher>(xor_v1, matcher_name);
|
||||
register_matcher(m, callback);
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
// Copyright (C) 2018-2022 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <memory>
|
||||
#include <ngraph/function.hpp>
|
||||
#include <openvino/opsets/opset1.hpp>
|
||||
#include <openvino/opsets/opset10.hpp>
|
||||
#include <openvino/pass/manager.hpp>
|
||||
#include <string>
|
||||
#include <transformations/init_node_info.hpp>
|
||||
#include <transformations/op_conversions/convert_xor_to_logical_xor.hpp>
|
||||
|
||||
#include "common_test_utils/ngraph_test_utils.hpp"
|
||||
|
||||
using namespace testing;
|
||||
using namespace ov;
|
||||
|
||||
TEST_F(TransformationTestsF, ConvertXorToLogicalXor) {
|
||||
{
|
||||
constexpr int N = 1;
|
||||
constexpr int C = 3;
|
||||
constexpr int H = 5;
|
||||
constexpr int W = 5;
|
||||
|
||||
const auto data_shape = Shape{N, C, H, W};
|
||||
const auto input1 = std::make_shared<opset1::Parameter>(element::boolean, data_shape);
|
||||
const auto input2 = std::make_shared<opset1::Parameter>(element::boolean, data_shape);
|
||||
|
||||
auto xor_op = std::make_shared<opset1::Xor>(input1,
|
||||
input2,
|
||||
ov::op::AutoBroadcastSpec(ov::op::AutoBroadcastType::NUMPY));
|
||||
|
||||
function = std::make_shared<ngraph::Function>(NodeVector{xor_op}, ParameterVector{input1, input2});
|
||||
manager.register_pass<ov::pass::ConvertXorToLogicalXor>();
|
||||
}
|
||||
|
||||
{
|
||||
constexpr int N = 1;
|
||||
constexpr int C = 3;
|
||||
constexpr int H = 5;
|
||||
constexpr int W = 5;
|
||||
|
||||
const auto data_shape = Shape{N, C, H, W};
|
||||
const auto input1 = std::make_shared<opset10::Parameter>(element::boolean, data_shape);
|
||||
const auto input2 = std::make_shared<opset10::Parameter>(element::boolean, data_shape);
|
||||
|
||||
auto logical_xor = std::make_shared<opset10::LogicalXor>(input1,
|
||||
input2,
|
||||
ov::op::AutoBroadcastSpec(ov::op::AutoBroadcastType::NUMPY));
|
||||
|
||||
function_ref = std::make_shared<ngraph::Function>(NodeVector{logical_xor}, ParameterVector{input1, input2});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user