forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GNA] Fix handling of 0-3-2-1 transpose in GNA plugin (openvinotoolki…
…t#12587) * [GNA] Fix handling of 0-3-2-1 transpose in GNA plugin * Remove unnessesary checks * Review comments * Make GNATransposeFusable string
- Loading branch information
Showing
11 changed files
with
186 additions
and
20 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
55 changes: 55 additions & 0 deletions
55
src/plugins/intel_gna/transformations/markup_fusable_transpose.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,55 @@ | ||
// Copyright (C) 2022 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
#include <ngraph/opsets/opset9.hpp> | ||
#include <legacy/ngraph_ops/convolution_ie.hpp> | ||
#include <legacy/ngraph_ops/fully_connected.hpp> | ||
#include <legacy/ngraph_ops/scaleshift.hpp> | ||
#include <openvino/cc/ngraph/itt.hpp> | ||
#include <ngraph/rt_info.hpp> | ||
#include <ops/util/util.hpp> | ||
#include <transformations/utils/transformation_helper.hpp> | ||
#include <transformations/rt_info/gna_transpose_fusable.hpp> | ||
|
||
#include "markup_fusable_transpose.hpp" | ||
|
||
using namespace ov::intel_gna::pass; | ||
using namespace ov::intel_gna::pass::helper; | ||
using namespace ov::intel_gna::ngraph_util; | ||
using namespace ov::intel_gna::rt_info; | ||
|
||
namespace { | ||
bool is_skip_operation(const std::shared_ptr<ngraph::Node>& node) { | ||
return (!std::dynamic_pointer_cast<ngraph::opset9::Transpose>(node) && | ||
!std::dynamic_pointer_cast<ngraph::op::FullyConnected>(node) && | ||
!std::dynamic_pointer_cast<ngraph::op::ScaleShiftIE>(node) && | ||
!std::dynamic_pointer_cast<ngraph::opset9::Result>(node) && | ||
(!is_gna_non_functional_node(node) || | ||
node->output(0).get_shape().size() == node->input(0).get_shape().size())); | ||
} | ||
} // namespace | ||
|
||
bool MarkupFusableTranspose::run_on_model(const std::shared_ptr<ngraph::Function>& f) { | ||
RUN_ON_FUNCTION_SCOPE(MarkupFusableTranspose); | ||
|
||
for (auto& node : f->get_ordered_ops()) { | ||
if (!std::dynamic_pointer_cast<ngraph::opset9::Convolution>(node) && | ||
!std::dynamic_pointer_cast<ngraph::op::ConvolutionIE>(node)) { | ||
continue; | ||
} | ||
auto in_dims = node->input(0).get_shape(); | ||
auto out_dims = node->output(0).get_shape(); | ||
|
||
if (is_one_dim_shapes(in_dims, out_dims)) { | ||
continue; | ||
} | ||
|
||
auto current_node = get_next_node_skipping_certain(node, is_skip_operation); | ||
if (!TransposeOrderMatches(std::dynamic_pointer_cast<ngraph::opset9::Transpose>(current_node), {0, 3, 2, 1})) { | ||
continue; | ||
} | ||
add_transpose_fusable(current_node); | ||
} | ||
|
||
return false; | ||
} |
27 changes: 27 additions & 0 deletions
27
src/plugins/intel_gna/transformations/markup_fusable_transpose.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,27 @@ | ||
// Copyright (C) 2022 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include <ngraph/pass/graph_rewrite.hpp> | ||
|
||
namespace ov { | ||
namespace intel_gna { | ||
namespace pass { | ||
|
||
/** | ||
* @brief Markup fusable tranpose | ||
* This transformation is written to support old IRs for Kaldi models | ||
* with specific 0-3-2-1 transpose after Convolution and mark it up | ||
* for special handling in compiler for backward compatibility purposes | ||
*/ | ||
class MarkupFusableTranspose : public ngraph::pass::FunctionPass { | ||
public: | ||
OPENVINO_RTTI("MarkupFusableTranspose", "0"); | ||
bool run_on_model(const std::shared_ptr<ngraph::Function>& f) override; | ||
}; | ||
|
||
} // namespace pass | ||
} // namespace intel_gna | ||
} // namespace ov |
20 changes: 20 additions & 0 deletions
20
src/plugins/intel_gna/transformations/rt_info/gna_transpose_fusable.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,20 @@ | ||
// Copyright (C) 2018-2022 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "gna_transpose_fusable.hpp" | ||
|
||
void ov::intel_gna::rt_info::add_transpose_fusable(const std::shared_ptr<Node>& node) { | ||
auto& rt_info = node->get_rt_info(); | ||
rt_info[GNATransposeFusable::get_type_info_static()] = std::string(); | ||
} | ||
|
||
void ov::intel_gna::rt_info::remove_transpose_fusable(const std::shared_ptr<Node>& node) { | ||
auto& rt_info = node->get_rt_info(); | ||
rt_info.erase(GNATransposeFusable::get_type_info_static()); | ||
} | ||
|
||
bool ov::intel_gna::rt_info::is_transpose_fusable(const std::shared_ptr<Node>& node) { | ||
const auto& rt_info = node->get_rt_info(); | ||
return rt_info.count(GNATransposeFusable::get_type_info_static()); | ||
} |
38 changes: 38 additions & 0 deletions
38
src/plugins/intel_gna/transformations/rt_info/gna_transpose_fusable.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,38 @@ | ||
// Copyright (C) 2018-2022 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include "openvino/core/node.hpp" | ||
#include "openvino/core/runtime_attribute.hpp" | ||
#include "transformations_visibility.hpp" | ||
|
||
namespace ov { | ||
namespace intel_gna { | ||
namespace rt_info { | ||
|
||
void add_transpose_fusable(const std::shared_ptr<Node>& node); | ||
|
||
void remove_transpose_fusable(const std::shared_ptr<Node>& node); | ||
|
||
bool is_transpose_fusable(const std::shared_ptr<Node>& node); | ||
|
||
/** | ||
* @ingroup ie_runtime_attr_api | ||
* @brief GNATransposeFusable class represents runtime info attribute that marks operation | ||
* as fusable with functional layer | ||
*/ | ||
class GNATransposeFusable : public RuntimeAttribute { | ||
public: | ||
OPENVINO_RTTI("gna_transpose_fusable", "0"); | ||
|
||
GNATransposeFusable() = default; | ||
|
||
bool is_copyable() const override { | ||
return false; | ||
} | ||
}; | ||
} // namespace rt_info | ||
} // namespace intel_gna | ||
} // namespace ov |
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