Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ inline void ConvertToCPUSpecificOpset(std::shared_ptr<ov::Model>& model, const C

CPU_REGISTER_PASS_COMMON(
manager,
pass::ConvertFullyConnectedToFullyConnectedCompressed,
ov::pass::ConvertFullyConnectedToFullyConnectedCompressed,
ov::intel_cpu::node::FullyConnected::getSupportedCompressedActivationsTypes(),
ov::intel_cpu::node::FullyConnected::getSupportedCompressedWeightsTypes(),
[&config](const std::shared_ptr<ov::op::internal::FullyConnected>& fc, size_t IC, size_t OC, size_t G) {
return ov::intel_cpu::node::FullyConnected::isSupportedCompressedOperation(fc, IC, OC, G, config);
});

CPU_REGISTER_PASS_X64(manager, pass::ConvertFCToFCQuantizedLegacy);
CPU_REGISTER_PASS_X64(manager, ov::pass::ConvertFCToFCQuantizedLegacy);
CPU_REGISTER_PASS_COMMON(manager, MoveFCReshapeToWeights);
CPU_REGISTER_PASS_COMMON(manager, ov::pass::Validate);
CPU_REGISTER_PASS_COMMON(manager, AlignMatMulInputRanks);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright (C) 2025 Intel Corporation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Copyright (C) 2025 Intel Corporation
// Copyright (C) 2018-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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please try this option?

Suggested change
auto m_v0 = ov::pass::pattern::wrap_type<ov::op::v0::Convert>();
auto m_v1 = ov::pass::pattern::wrap_type<ov::opset1::Convert>();
auto convert_m = ov::pass::pattern::wrap_type<ov::op::v0::Convert, ov::opset1::Convert>();

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dst can be always get as cv->get_output_element_type(0), we can avoid the casting here

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Copyright (C) 2025 Intel Corporation
// Copyright (C) 2018-2025 Intel Corporation

// 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "transformation_pipeline.h"

#include "defs.hpp"
#include "transformations/snippets/normalize_convert_pre_lower.hpp"

// Operations
#include <algorithm>
Expand Down Expand Up @@ -1651,6 +1652,9 @@ void Transformations::PostSnippets() {
ov::pass::FakeQuantizeDecomposition);
CPU_REGISTER_PASS_COMMON(postSnippetsManager, ov::pass::FakeConvertDecomposition);
CPU_REGISTER_PASS_COMMON(postSnippetsManager, ov::pass::ConstantFolding);
#if defined(ANDROID) || defined(__ANDROID__)
CPU_REGISTER_PASS_COMMON(postSnippetsManager, ov::intel_cpu::pass::NormalizeConvertPreLower);
#endif
postSnippetsManager.run_passes(model);
}

Expand Down
Loading