-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'openvinotoolkit:master' into alexeyl1/tools/update_benc…
…hmark
- Loading branch information
Showing
126 changed files
with
1,347 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
inference-engine/src/mkldnn_plugin/ngraph_transformations/move_eltwise_up_data_movement.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// Copyright (C) 2021 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "move_eltwise_up_data_movement.hpp" | ||
|
||
#include <memory> | ||
#include <vector> | ||
#include <numeric> | ||
|
||
#include <ngraph/opsets/opset8.hpp> | ||
#include <ngraph/rt_info.hpp> | ||
#include <ngraph/pattern/op/wrap_type.hpp> | ||
|
||
|
||
NGRAPH_RTTI_DEFINITION(MKLDNNPlugin::MoveEltwiseUpThroughDataMov, "MoveEltwiseUpThroughDataMov", 0); | ||
|
||
namespace { | ||
bool is_data_movement_operation(const std::shared_ptr<ngraph::Node>& node) { | ||
return ov::is_type<ngraph::op::v0::Squeeze>(node) || | ||
ov::is_type<ngraph::op::v0::Unsqueeze>(node) || | ||
ov::is_type<ngraph::op::v1::Reshape>(node) || | ||
ov::is_type<ngraph::op::v1::Transpose>(node) || | ||
ov::is_type<ngraph::op::v0::ShuffleChannels>(node) || | ||
ov::is_type<ngraph::op::v7::Roll>(node) || | ||
ov::is_type<ngraph::op::v0::ReverseSequence>(node) || | ||
ov::is_type<ngraph::op::v0::DepthToSpace>(node) || | ||
ov::is_type<ngraph::op::v1::BatchToSpace>(node) || | ||
ov::is_type<ngraph::op::v1::Broadcast>(node) || | ||
ov::is_type<ngraph::op::v3::Broadcast>(node) || | ||
ov::is_type<ngraph::op::v1::Gather>(node) || | ||
ov::is_type<ngraph::op::v7::Gather>(node) || | ||
ov::is_type<ngraph::op::v8::Gather>(node); | ||
} | ||
|
||
bool is_scalar_like(const std::shared_ptr<ngraph::Node>& node) { | ||
auto constantNode = std::dynamic_pointer_cast<ngraph::opset8::Constant>(node); | ||
return constantNode != nullptr && shape_size(constantNode->get_shape()) == 1; | ||
} | ||
} // namespace | ||
|
||
MKLDNNPlugin::MoveEltwiseUpThroughDataMov::MoveEltwiseUpThroughDataMov() { | ||
auto eltwise_pattern = ngraph::pattern::wrap_type<ngraph::op::util::UnaryElementwiseArithmetic, | ||
ngraph::op::util::BinaryElementwiseArithmetic>(ngraph::pattern::has_static_rank()); | ||
|
||
ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { | ||
const auto& pattern_map = m.get_pattern_value_map(); | ||
|
||
auto eltwise = pattern_map.at(eltwise_pattern).get_node_shared_ptr(); | ||
if (transformation_callback(eltwise)) { | ||
return false; | ||
} | ||
|
||
if (eltwise->get_output_size() == 0 || | ||
eltwise->get_input_size() == 0 || | ||
eltwise->get_output_element_type(0) != eltwise->get_input_element_type(0) || | ||
eltwise->get_output_target_inputs(0).size() != 1) { | ||
return false; | ||
} | ||
|
||
bool is_binary_op = std::dynamic_pointer_cast<ngraph::op::util::BinaryElementwiseArithmetic>(eltwise) != nullptr; | ||
if (is_binary_op && !is_scalar_like(eltwise->get_input_node_shared_ptr(1))) { | ||
return false; | ||
} | ||
|
||
|
||
|
||
auto current = eltwise->get_input_node_shared_ptr(0); | ||
auto child = eltwise; | ||
|
||
while (is_data_movement_operation(current)) { | ||
if (current->get_output_size() != 1 || | ||
current->get_output_target_inputs(0).size() != 1 || | ||
current->get_output_element_type(0) != current->get_input_element_type(0)) { | ||
return false; | ||
} | ||
|
||
child = current; | ||
current = current->get_input_node_shared_ptr(0); | ||
} | ||
|
||
// now current is the first not data movement op | ||
if (child == eltwise) { | ||
return false; | ||
} | ||
|
||
// eltwise constant shape should match new input shape | ||
if (is_binary_op && current->get_output_shape(0).size() != eltwise->get_input_shape(1).size()) { | ||
auto old_eltwise_const = std::dynamic_pointer_cast<ngraph::opset8::Constant>(eltwise->get_input_node_shared_ptr(1)); | ||
auto new_constant = std::make_shared<ngraph::opset8::Constant>(*old_eltwise_const.get(), ngraph::Shape{}); | ||
ngraph::replace_node(old_eltwise_const, new_constant); | ||
} | ||
ngraph::replace_output_update_name(eltwise->output(0), eltwise->input_value(0)); | ||
|
||
ngraph::OutputVector eltwiseInputs = eltwise->input_values(); | ||
eltwiseInputs[0] = child->input_value(0); | ||
auto newEltwise = eltwise->clone_with_new_inputs(eltwiseInputs); | ||
ngraph::copy_runtime_info(eltwise, newEltwise); | ||
newEltwise->set_friendly_name(eltwise->get_friendly_name()); | ||
|
||
ngraph::OutputVector childInputs = child->input_values(); | ||
childInputs[0] = newEltwise; | ||
auto newChild = child->clone_with_new_inputs(childInputs); | ||
ngraph::copy_runtime_info(child, newChild); | ||
newChild->set_friendly_name(child->get_friendly_name()); | ||
|
||
ngraph::replace_node(child, newChild); | ||
return true; | ||
}; | ||
|
||
auto m = std::make_shared<ngraph::pattern::Matcher>(eltwise_pattern, "MoveEltwiseUpThroughDataMov"); | ||
register_matcher(m, callback); | ||
} |
17 changes: 17 additions & 0 deletions
17
inference-engine/src/mkldnn_plugin/ngraph_transformations/move_eltwise_up_data_movement.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (C) 2021 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include <ngraph/pass/graph_rewrite.hpp> | ||
|
||
namespace MKLDNNPlugin { | ||
|
||
class MoveEltwiseUpThroughDataMov : public ngraph::pass::MatcherPass { | ||
public: | ||
NGRAPH_RTTI_DECLARATION; | ||
MoveEltwiseUpThroughDataMov(); | ||
}; | ||
|
||
} // namespace MKLDNNPlugin |
Oops, something went wrong.