Use CC in CPUSpecificTransform (#11231)

This commit is contained in:
Egor Shulman 2022-03-30 18:26:35 +03:00 committed by GitHub
parent 8317493e65
commit e507b630eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 120 additions and 15 deletions

View File

@ -12,8 +12,10 @@
#include <ngraph/pattern/op/or.hpp>
#include <algorithm>
#include "itt.hpp"
ov::intel_cpu::AlignMatMulInputRanks::AlignMatMulInputRanks() {
MATCHER_SCOPE(AlignMatMulInputRanks);
ngraph::OutputVector twoInputs = {
ngraph::pattern::any_input(ngraph::pattern::has_static_rank()),
ngraph::pattern::any_input(ngraph::pattern::has_static_rank())
@ -135,6 +137,6 @@ ov::intel_cpu::AlignMatMulInputRanks::AlignMatMulInputRanks() {
return true;
};
auto m = std::make_shared<ngraph::pattern::Matcher>(matmulPattern, "AlignMatMulInputRanks");
auto m = std::make_shared<ngraph::pattern::Matcher>(matmulPattern, matcher_name);
this->register_matcher(m, callback);
}

View File

@ -8,7 +8,10 @@
#include <ngraph/rt_info.hpp>
#include <ngraph/pattern/op/wrap_type.hpp>
#include "itt.hpp"
ov::intel_cpu::ConvertBroadcastToTiles::ConvertBroadcastToTiles() {
MATCHER_SCOPE(ConvertBroadcastToTiles);
auto broadcast = ngraph::pattern::wrap_type<ngraph::opset1::Broadcast>();
ngraph::matcher_pass_callback callback = [this](ngraph::pattern::Matcher& m) {
@ -91,6 +94,6 @@ ov::intel_cpu::ConvertBroadcastToTiles::ConvertBroadcastToTiles() {
return true;
};
auto m = std::make_shared<ngraph::pattern::Matcher>(broadcast, "ConvertBroadcastToTiles");
auto m = std::make_shared<ngraph::pattern::Matcher>(broadcast, matcher_name);
this->register_matcher(m, callback);
}

View File

@ -9,7 +9,10 @@
#include <ngraph/pattern/op/wrap_type.hpp>
#include <transformations/utils/utils.hpp>
#include "itt.hpp"
ov::intel_cpu::ConvertMatMulToFC::ConvertMatMulToFC() {
MATCHER_SCOPE(ConvertMatMulToFC);
auto activations_m = ngraph::pattern::any_input(ngraph::pattern::has_static_rank());
auto weights_m = ngraph::pattern::wrap_type<ngraph::opset1::Constant>();
auto matmul_m = ngraph::pattern::wrap_type<ngraph::opset1::MatMul>({ activations_m, weights_m }, ngraph::pattern::has_static_rank());
@ -162,6 +165,6 @@ ov::intel_cpu::ConvertMatMulToFC::ConvertMatMulToFC() {
return true;
};
auto m = std::make_shared<ngraph::pattern::Matcher>(matmul_m, "ConvertMatMulToFC");
auto m = std::make_shared<ngraph::pattern::Matcher>(matmul_m, matcher_name);
this->register_matcher(m, callback);
}

View File

@ -12,7 +12,10 @@
#include <ngraph/rt_info.hpp>
#include "itt.hpp"
ov::intel_cpu::ConvertTileToSeqTiles::ConvertTileToSeqTiles() {
MATCHER_SCOPE(ConvertTileToSeqTiles);
auto tile = ngraph::pattern::wrap_type<ngraph::opset1::Tile>({ngraph::pattern::any_input(ngraph::pattern::has_static_rank()),
ngraph::pattern::wrap_type<ngraph::opset1::Constant>()});
@ -88,6 +91,6 @@ ov::intel_cpu::ConvertTileToSeqTiles::ConvertTileToSeqTiles() {
return true;
};
auto m = std::make_shared<ngraph::pattern::Matcher>(tile, "ConvertTileToSeqTiles");
auto m = std::make_shared<ngraph::pattern::Matcher>(tile, matcher_name);
this->register_matcher(m, callback);
}

View File

@ -20,10 +20,13 @@
#include "rnn_sequences_optimization.hpp"
#include "transformations/common_optimizations/reshape_sequence_fusion.hpp"
#include "itt.hpp"
namespace ov {
namespace intel_cpu {
inline void ConvertToCPUSpecificOpset(std::shared_ptr<ngraph::Function> &nGraphFunc) {
RUN_ON_FUNCTION_SCOPE(ConvertToCPUSpecificOpset);
ngraph::pass::Manager manager;
manager.register_pass<ConvertMatMulToFC>();
manager.register_pass<AlignMatMulInputRanks>();

View File

@ -9,7 +9,10 @@
#include <ngraph/pattern/op/wrap_type.hpp>
#include "op/leaky_relu.hpp"
#include "itt.hpp"
ov::intel_cpu::ConvertToLeakyRelu::ConvertToLeakyRelu() {
MATCHER_SCOPE(ConvertToLeakyRelu);
auto input = ngraph::pattern::any_input();
auto slope_constant = ngraph::pattern::wrap_type<ngraph::opset1::Constant>();
auto prelu = ngraph::pattern::wrap_type<ngraph::opset1::PRelu>({ input, slope_constant });
@ -32,6 +35,6 @@ ov::intel_cpu::ConvertToLeakyRelu::ConvertToLeakyRelu() {
return false;
};
auto m = std::make_shared<ngraph::pattern::Matcher>(prelu, "ConvertToLeakyRelu");
auto m = std::make_shared<ngraph::pattern::Matcher>(prelu, matcher_name);
this->register_matcher(m, callback);
}

View File

@ -14,6 +14,8 @@
#include "op/fully_connected.hpp"
#include "utils/general_utils.h"
#include "itt.hpp"
namespace {
int getConstPort(const std::shared_ptr<ngraph::Node> &node) {
@ -97,6 +99,7 @@ std::shared_ptr<ngraph::Node> convert(const std::shared_ptr<BaseOp> &node) {
} // namespace
ov::intel_cpu::ConvertToPowerStatic::ConvertToPowerStatic() {
MATCHER_SCOPE(ConvertToPowerStatic);
ngraph::OutputVector twoInputs = {ngraph::pattern::any_input(ngraph::pattern::has_static_rank()),
ngraph::pattern::any_input(ngraph::pattern::has_static_rank())};
auto power = ngraph::pattern::wrap_type<ngraph::opset1::Power>(twoInputs);
@ -134,6 +137,6 @@ ov::intel_cpu::ConvertToPowerStatic::ConvertToPowerStatic() {
return true;
};
auto m = std::make_shared<ngraph::pattern::Matcher>(candidate, "ConvertToPowerStatic");
auto m = std::make_shared<ngraph::pattern::Matcher>(candidate, matcher_name);
this->register_matcher(m, callback);
}

View File

@ -9,7 +9,10 @@
#include <ngraph/pattern/op/wrap_type.hpp>
#include "op/swish_cpu.hpp"
#include "itt.hpp"
ov::intel_cpu::ConvertToSwishCPU::ConvertToSwishCPU() {
MATCHER_SCOPE(ConvertToSwishCPU);
auto swish = ngraph::pattern::wrap_type<ngraph::opset4::Swish>();
ngraph::matcher_pass_callback callback = [](ngraph::pattern::Matcher& m) {
@ -34,6 +37,6 @@ ov::intel_cpu::ConvertToSwishCPU::ConvertToSwishCPU() {
return true;
};
auto m = std::make_shared<ngraph::pattern::Matcher>(swish, "ConvertToSwishCPU");
auto m = std::make_shared<ngraph::pattern::Matcher>(swish, matcher_name);
this->register_matcher(m, callback);
}

View File

@ -11,7 +11,10 @@
#include "transformations/utils/utils.hpp"
#include "itt.hpp"
ov::intel_cpu::FullyConnectedBiasFusion::FullyConnectedBiasFusion() {
MATCHER_SCOPE(FullyConnectedBiasFusion);
auto input = ngraph::pattern::any_input();
auto weights = ngraph::pattern::any_input(ngraph::pattern::has_static_shape());
auto m_fc = ngraph::pattern::wrap_type<ov::intel_cpu::FullyConnectedNode>({ input, weights }, [](ngraph::Output<ngraph::Node> output) {
@ -68,6 +71,6 @@ ov::intel_cpu::FullyConnectedBiasFusion::FullyConnectedBiasFusion() {
return true;
};
auto m = std::make_shared<ngraph::pattern::Matcher>(m_add, "FullyConnectedBiasFusion");
auto m = std::make_shared<ngraph::pattern::Matcher>(m_add, matcher_name);
this->register_matcher(m, callback);
}

View File

@ -0,0 +1,43 @@
// Copyright (C) 2018-2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
/**
* @brief Defines openvino domains for tracing
* @file itt.hpp
*/
#pragma once
#include <openvino/cc/ngraph/itt.hpp>
namespace ov {
namespace intel_cpu {
namespace itt {
namespace domains {
OV_ITT_DOMAIN(CPUSpecificTransform);
} // namespace domains
} // namespace itt
} // namespace intel_cpu
} // namespace ov
OV_CC_DOMAINS(internal_op);
/*
* RUN_ON_FUNCTION_SCOPE macro allows to disable the run_on_function pass
* MATCHER_SCOPE macro allows to disable the MatcherPass if matcher isn't applied
* INTERNAL_OP_SCOPE macro allows to disable parts of internal nGraph operations if they are not used
*/
#if defined(SELECTIVE_BUILD_ANALYZER)
#define INTERNAL_OP_SCOPE(region) OV_SCOPE(internal_op, region)
#elif defined(SELECTIVE_BUILD)
#define INTERNAL_OP_SCOPE(region) MATCHER_SCOPE_(internal_op, region)
#else
#define INTERNAL_OP_SCOPE(region)
#endif

View File

@ -12,6 +12,8 @@
#include <ngraph/rt_info.hpp>
#include <ngraph/pattern/op/wrap_type.hpp>
#include "itt.hpp"
namespace {
bool is_data_movement_operation(const std::shared_ptr<ngraph::Node>& node) {
@ -38,6 +40,7 @@ namespace {
} // namespace
ov::intel_cpu::MoveEltwiseUpThroughDataMov::MoveEltwiseUpThroughDataMov() {
MATCHER_SCOPE(MoveEltwiseUpThroughDataMov);
auto eltwise_pattern = ngraph::pattern::wrap_type<ngraph::op::util::UnaryElementwiseArithmetic,
ngraph::op::util::BinaryElementwiseArithmetic>(ngraph::pattern::has_static_rank());
@ -108,6 +111,6 @@ ov::intel_cpu::MoveEltwiseUpThroughDataMov::MoveEltwiseUpThroughDataMov() {
return true;
};
auto m = std::make_shared<ngraph::pattern::Matcher>(eltwise_pattern, "MoveEltwiseUpThroughDataMov");
auto m = std::make_shared<ngraph::pattern::Matcher>(eltwise_pattern, matcher_name);
register_matcher(m, callback);
}

View File

@ -3,6 +3,7 @@
//
#include "fully_connected.hpp"
#include "../itt.hpp"
ov::intel_cpu::FullyConnectedNode::FullyConnectedNode(const ngraph::Output<Node>& A,
const ngraph::Output<Node>& B,
@ -22,6 +23,7 @@ ov::intel_cpu::FullyConnectedNode::FullyConnectedNode(const ngraph::Output<Node>
}
std::shared_ptr<ngraph::Node> ov::intel_cpu::FullyConnectedNode::clone_with_new_inputs(const ngraph::OutputVector& new_args) const {
INTERNAL_OP_SCOPE(FullyConnectedNode_clone_with_new_inputs);
check_new_args_count(this, new_args);
if (new_args.size() == 2) {
return std::make_shared<ov::intel_cpu::FullyConnectedNode>(new_args.at(0), new_args.at(1), m_output_rank, m_output_type);
@ -33,6 +35,7 @@ std::shared_ptr<ngraph::Node> ov::intel_cpu::FullyConnectedNode::clone_with_new_
}
void ov::intel_cpu::FullyConnectedNode::validate_and_infer_types() {
INTERNAL_OP_SCOPE(FullyConnectedNode_validate_and_infer_types);
const auto input_size = get_input_size();
NODE_VALIDATION_CHECK(this,
input_size == 2 || input_size == 3,
@ -94,6 +97,7 @@ void ov::intel_cpu::FullyConnectedNode::validate_and_infer_types() {
}
bool ov::intel_cpu::FullyConnectedNode::visit_attributes(ngraph::AttributeVisitor &visitor) {
INTERNAL_OP_SCOPE(FullyConnectedNode_visit_attributes);
visitor.on_attribute("out-rank", m_output_rank);
visitor.on_attribute("out-type", m_output_type);
return true;

View File

@ -3,6 +3,7 @@
//
#include "leaky_relu.hpp"
#include "../itt.hpp"
ov::intel_cpu::LeakyReluNode::LeakyReluNode(const ngraph::Output<ngraph::Node> &data,
const float &negative_slope,
@ -12,11 +13,13 @@ ov::intel_cpu::LeakyReluNode::LeakyReluNode(const ngraph::Output<ngraph::Node> &
}
std::shared_ptr<ngraph::Node> ov::intel_cpu::LeakyReluNode::clone_with_new_inputs(const ngraph::OutputVector& new_args) const {
INTERNAL_OP_SCOPE(LeakyReluNode_clone_with_new_inputs);
check_new_args_count(this, new_args);
return std::make_shared<ov::intel_cpu::LeakyReluNode>(new_args.at(0), m_negative_slope, m_output_type);
}
void ov::intel_cpu::LeakyReluNode::validate_and_infer_types() {
INTERNAL_OP_SCOPE(LeakyReluNode_validate_and_infer_types);
set_output_type(
0,
m_output_type == ngraph::element::undefined ? get_input_element_type(0) : m_output_type,
@ -24,6 +27,7 @@ void ov::intel_cpu::LeakyReluNode::validate_and_infer_types() {
}
bool ov::intel_cpu::LeakyReluNode::visit_attributes(ngraph::AttributeVisitor &visitor) {
INTERNAL_OP_SCOPE(LeakyReluNode_visit_attributes);
visitor.on_attribute("negative_slope", m_negative_slope);
visitor.on_attribute("out-type", m_output_type);
return true;

View File

@ -3,6 +3,7 @@
//
#include "power_static.hpp"
#include "../itt.hpp"
ov::intel_cpu::PowerStaticNode::PowerStaticNode(const ngraph::Output<Node> &data,
const float &power,
@ -14,6 +15,7 @@ ov::intel_cpu::PowerStaticNode::PowerStaticNode(const ngraph::Output<Node> &data
}
std::shared_ptr<ngraph::Node> ov::intel_cpu::PowerStaticNode::clone_with_new_inputs(const ngraph::OutputVector &new_args) const {
INTERNAL_OP_SCOPE(PowerStaticNode_clone_with_new_inputs);
if (new_args.size() != 1) {
throw ngraph::ngraph_error("Incorrect number of new arguments");
}
@ -22,10 +24,12 @@ std::shared_ptr<ngraph::Node> ov::intel_cpu::PowerStaticNode::clone_with_new_inp
}
void ov::intel_cpu::PowerStaticNode::validate_and_infer_types() {
INTERNAL_OP_SCOPE(PowerStaticNode_validate_and_infer_types);
set_output_type(0, m_output_type == ngraph::element::undefined ? get_input_element_type(0) : m_output_type, get_input_partial_shape(0));
}
bool ov::intel_cpu::PowerStaticNode::visit_attributes(ngraph::AttributeVisitor &visitor) {
INTERNAL_OP_SCOPE(PowerStaticNode_visit_attributes);
visitor.on_attribute("scale", scale);
visitor.on_attribute("power", power);
visitor.on_attribute("shift", shift);

View File

@ -3,6 +3,7 @@
//
#include "swish_cpu.hpp"
#include "../itt.hpp"
ov::intel_cpu::SwishNode::SwishNode(const ngraph::Output<ngraph::Node> & input, const float alpha)
: Op({input}), m_alpha(alpha) {
@ -10,16 +11,19 @@ ov::intel_cpu::SwishNode::SwishNode(const ngraph::Output<ngraph::Node> & input,
}
std::shared_ptr<ngraph::Node> ov::intel_cpu::SwishNode::clone_with_new_inputs(const ngraph::OutputVector& new_args) const {
INTERNAL_OP_SCOPE(SwishNode_clone_with_new_inputs);
check_new_args_count(this, new_args);
return std::make_shared<ov::intel_cpu::SwishNode>(new_args.at(0), m_alpha);
}
bool ov::intel_cpu::SwishNode::visit_attributes(ngraph::AttributeVisitor& visitor) {
INTERNAL_OP_SCOPE(SwishNode_visit_attributes);
visitor.on_attribute("alpha", m_alpha);
return true;
}
void ov::intel_cpu::SwishNode::validate_and_infer_types() {
INTERNAL_OP_SCOPE(SwishNode_validate_and_infer_types);
set_output_type(0, get_input_element_type(0), get_input_partial_shape(0));
}

View File

@ -10,7 +10,10 @@
#include <ngraph/pattern/op/wrap_type.hpp>
#include <ngraph/pattern/op/or.hpp>
#include "itt.hpp"
ov::intel_cpu::ReshapeFullyConnectedFusion::ReshapeFullyConnectedFusion() {
MATCHER_SCOPE(ReshapeFullyConnectedFusion);
auto m_reshape = ngraph::pattern::wrap_type<ngraph::opset1::Reshape>({ngraph::pattern::any_input(ov::pass::pattern::has_static_shape()),
ngraph::pattern::any_input()},
ngraph::pattern::has_static_shape());
@ -81,6 +84,6 @@ ov::intel_cpu::ReshapeFullyConnectedFusion::ReshapeFullyConnectedFusion() {
return true;
};
auto m = std::make_shared<ngraph::pattern::Matcher>(fcTwoOrThreeInputs, "ReshapeFullyConnectedFusion");
auto m = std::make_shared<ngraph::pattern::Matcher>(fcTwoOrThreeInputs, matcher_name);
register_matcher(m, callback);
}

View File

@ -9,7 +9,10 @@
#include <ngraph/pattern/op/wrap_type.hpp>
#include "transformations/utils/utils.hpp"
#include "itt.hpp"
ov::intel_cpu::ReshapePRelu::ReshapePRelu() {
MATCHER_SCOPE(ReshapeFullyConnectedFusion);
auto input_m = ngraph::pattern::any_input(ngraph::pattern::has_static_rank());
auto slope_m = ngraph::pattern::any_input(ngraph::pattern::has_static_rank());
auto prelu_m = ngraph::pattern::wrap_type<ngraph::opset1::PRelu>({ input_m, slope_m });
@ -49,6 +52,6 @@ ov::intel_cpu::ReshapePRelu::ReshapePRelu() {
return true;
};
auto m = std::make_shared<ngraph::pattern::Matcher>(prelu_m, "ReshapePRelu");
auto m = std::make_shared<ngraph::pattern::Matcher>(prelu_m, matcher_name);
this->register_matcher(m, callback);
}

View File

@ -11,6 +11,8 @@
#include <transformations/utils/utils.hpp>
#include <ngraph/variant.hpp>
#include "itt.hpp"
namespace {
int64_t getSeqAxis(const std::shared_ptr<ngraph::Node>& sequenceOp) {
// Optimization.
@ -82,6 +84,7 @@ namespace {
} // namespace
ov::intel_cpu::OptimizeGRUSequenceTransposes::OptimizeGRUSequenceTransposes() {
MATCHER_SCOPE(OptimizeGRUSequenceTransposes);
auto gruSequenceNgraph = ngraph::pattern::wrap_type<ngraph::opset5::GRUSequence>();
ngraph::matcher_pass_callback callback = [](ngraph::pattern::Matcher &m) {
@ -96,11 +99,12 @@ ov::intel_cpu::OptimizeGRUSequenceTransposes::OptimizeGRUSequenceTransposes() {
return transform(gruSequence);
};
auto m = std::make_shared<ngraph::pattern::Matcher>(gruSequenceNgraph, "OptimizeGRUSequenceTransposes");
auto m = std::make_shared<ngraph::pattern::Matcher>(gruSequenceNgraph, matcher_name);
this->register_matcher(m, callback);
}
ov::intel_cpu::OptimizeRNNSequenceTransposes::OptimizeRNNSequenceTransposes() {
MATCHER_SCOPE(OptimizeRNNSequenceTransposes);
auto rnnSequenceNgraph = ngraph::pattern::wrap_type<ngraph::opset5::RNNSequence>();
ngraph::matcher_pass_callback callback = [](ngraph::pattern::Matcher &m) {
@ -115,11 +119,12 @@ ov::intel_cpu::OptimizeRNNSequenceTransposes::OptimizeRNNSequenceTransposes() {
return transform(rnnSequence);
};
auto m = std::make_shared<ngraph::pattern::Matcher>(rnnSequenceNgraph, "OptimizeRNNSequenceTransposes");
auto m = std::make_shared<ngraph::pattern::Matcher>(rnnSequenceNgraph, matcher_name);
this->register_matcher(m, callback);
}
ov::intel_cpu::OptimizeLSTMSequenceTransposes::OptimizeLSTMSequenceTransposes() {
MATCHER_SCOPE(OptimizeLSTMSequenceTransposes);
auto lstmSequenceNgraph = ngraph::pattern::wrap_type<ngraph::opset1::LSTMSequence, ngraph::opset5::LSTMSequence>();
ngraph::matcher_pass_callback callback = [](ngraph::pattern::Matcher &m) {
@ -137,7 +142,7 @@ ov::intel_cpu::OptimizeLSTMSequenceTransposes::OptimizeLSTMSequenceTransposes()
return checkSequence(lstmSequence) ? transform(lstmSequence) : false;
};
auto m = std::make_shared<ngraph::pattern::Matcher>(lstmSequenceNgraph, "OptimizeLSTMSequenceTransposes");
auto m = std::make_shared<ngraph::pattern::Matcher>(lstmSequenceNgraph, matcher_name);
this->register_matcher(m, callback);
}

View File

@ -7,6 +7,8 @@
#include <utils/general_utils.h>
#include <utils/cpu_utils.hpp>
#include "itt.hpp"
using namespace ngraph;
namespace ov {
@ -297,6 +299,7 @@ void MarkSubgraphOpAsSkipped(const std::shared_ptr<Node> &node) {
} // namespace
bool SnippetsMarkSkipped::run_on_model(const std::shared_ptr<ov::Model> &m) {
RUN_ON_MODEL_SCOPE(SnippetsMarkSkipped);
for (auto &node : m->get_ordered_ops()) {
if (ngraph::op::is_constant(node))
continue;

View File

@ -8,9 +8,12 @@
#include <ngraph/rt_info.hpp>
#include <ngraph/pattern/op/wrap_type.hpp>
#include "itt.hpp"
NGRAPH_RTTI_DEFINITION(ov::intel_cpu::SwapConvertTranspose, "SwapConvertTranspose", 0);
ov::intel_cpu::SwapConvertTranspose::SwapConvertTranspose() {
MATCHER_SCOPE(SwapConvertTranspose);
ngraph::element::TypeVector param_precisions{ ngraph::element::i8, ngraph::element::u8 };
auto input_m = ngraph::pattern::wrap_type<ngraph::op::v0::Parameter>(ngraph::pattern::type_matches_any(param_precisions));
auto convert_m = ngraph::pattern::wrap_type<ngraph::op::v0::Convert>({input_m}, ngraph::pattern::type_matches(ngraph::element::f32));
@ -38,6 +41,6 @@ ov::intel_cpu::SwapConvertTranspose::SwapConvertTranspose() {
return true;
};
auto m = std::make_shared<ngraph::pattern::Matcher>(transpose_m, "SwapConvertTranspose");
auto m = std::make_shared<ngraph::pattern::Matcher>(transpose_m, matcher_name);
this->register_matcher(m, callback);
}