-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[CPU][Android] Normalize late Convert in PostSnippets and fix FC pass namespace #32640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
621e3fa
7c3c36c
b54e085
9ccd03e
2c01ea6
b3e00ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,65 @@ | ||||||||
| // Copyright (C) 2025 Intel Corporation | ||||||||
| // SPDX-License-Identifier: Apache-2.0 | ||||||||
|
|
||||||||
| #include "transformations/snippets/normalize_convert_pre_lower.hpp" | ||||||||
|
|
||||||||
| #include <openvino/op/convert.hpp> | ||||||||
| #include <openvino/opsets/opset1.hpp> | ||||||||
| #include <openvino/pass/manager.hpp> | ||||||||
| #include <openvino/pass/pattern/matcher.hpp> | ||||||||
| #include <openvino/pass/pattern/op/wrap_type.hpp> | ||||||||
|
|
||||||||
| #include "snippets/op/convert_truncation.hpp" | ||||||||
| #include "snippets/op/subgraph.hpp" | ||||||||
|
|
||||||||
| namespace ov::intel_cpu::pass { | ||||||||
|
|
||||||||
| namespace { | ||||||||
| class ReplaceConvertInBody : public ov::pass::MatcherPass { | ||||||||
| public: | ||||||||
| OPENVINO_MATCHER_PASS_RTTI("CPU::ReplaceConvertInBody"); | ||||||||
| ReplaceConvertInBody() { | ||||||||
| auto m_v0 = ov::pass::pattern::wrap_type<ov::op::v0::Convert>(); | ||||||||
| auto m_v1 = ov::pass::pattern::wrap_type<ov::opset1::Convert>(); | ||||||||
|
Comment on lines
+22
to
+23
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please try this option?
Suggested change
If it works for android, I'd prefer leaving it since it is shorter |
||||||||
|
|
||||||||
| auto callback = [](ov::pass::pattern::Matcher& m) { | ||||||||
| const auto root = m.get_match_root(); | ||||||||
| std::shared_ptr<ov::Node> cv = root; | ||||||||
| ov::element::Type dst; | ||||||||
| if (auto c0 = std::dynamic_pointer_cast<ov::op::v0::Convert>(cv)) { | ||||||||
| dst = c0->get_destination_type(); | ||||||||
| } else if (auto c1 = std::dynamic_pointer_cast<ov::opset1::Convert>(cv)) { | ||||||||
| dst = c1->get_destination_type(); | ||||||||
| } else { | ||||||||
| return false; | ||||||||
| } | ||||||||
|
Comment on lines
+28
to
+35
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dst can be always get as |
||||||||
| auto in = cv->input_value(0); | ||||||||
| auto ct = std::make_shared<ov::snippets::op::ConvertTruncation>(in, dst); | ||||||||
| ct->set_friendly_name(cv->get_friendly_name()); | ||||||||
| ov::copy_runtime_info(cv, ct); | ||||||||
| ov::replace_node(cv, ct); | ||||||||
| return true; | ||||||||
| }; | ||||||||
|
|
||||||||
| register_matcher(std::make_shared<ov::pass::pattern::Matcher>(m_v0, "CPUReplaceConvertV0"), callback); | ||||||||
| register_matcher(std::make_shared<ov::pass::pattern::Matcher>(m_v1, "CPUReplaceConvertV1"), callback); | ||||||||
| } | ||||||||
| }; | ||||||||
| } // namespace | ||||||||
|
|
||||||||
| NormalizeConvertPreLower::NormalizeConvertPreLower() { | ||||||||
| auto m_subgraph = ov::pass::pattern::wrap_type<ov::snippets::op::Subgraph>(); | ||||||||
| register_matcher(std::make_shared<ov::pass::pattern::Matcher>(m_subgraph, get_type_info_static().name), | ||||||||
| [](ov::pass::pattern::Matcher& m) { | ||||||||
| auto s = std::dynamic_pointer_cast<ov::snippets::op::Subgraph>(m.get_match_root()); | ||||||||
| if (!s) | ||||||||
| return false; | ||||||||
| ov::pass::Manager body_mgr("CPU::NormalizeConvertPreLowerBody"); | ||||||||
| body_mgr.set_per_pass_validation(false); | ||||||||
| body_mgr.register_pass<ReplaceConvertInBody>(); | ||||||||
| body_mgr.run_passes(s->body_ptr()); | ||||||||
| return true; | ||||||||
| }); | ||||||||
| } | ||||||||
|
|
||||||||
| } // namespace ov::intel_cpu::pass | ||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,23 @@ | ||||||
| // Copyright (C) 2025 Intel Corporation | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| // SPDX-License-Identifier: Apache-2.0 | ||||||
|
|
||||||
| #pragma once | ||||||
|
|
||||||
| #include <openvino/pass/graph_rewrite.hpp> | ||||||
|
|
||||||
| namespace ov { | ||||||
| namespace intel_cpu { | ||||||
| namespace pass { | ||||||
|
|
||||||
| // CPU-side pass: for every ov::snippets::op::Subgraph, replace any remaining | ||||||
| // ov::op::v0::Convert / opset1::Convert inside subgraph body with | ||||||
| // ov::snippets::op::ConvertTruncation right before lowering in CPU pipeline. | ||||||
|
Comment on lines
+12
to
+14
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please specify more context in the pass description (That we workaround android specific problem, its details etc.)? |
||||||
| class NormalizeConvertPreLower final : public ov::pass::MatcherPass { | ||||||
| public: | ||||||
| OPENVINO_MATCHER_PASS_RTTI("CPU::NormalizeConvertPreLower"); | ||||||
| NormalizeConvertPreLower(); | ||||||
| }; | ||||||
|
|
||||||
| } // namespace pass | ||||||
| } // namespace intel_cpu | ||||||
| } // namespace ov | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.