From ed702910bdb22a5c2fa4fda962a2675adbbccbbe Mon Sep 17 00:00:00 2001 From: Ilya Churaev Date: Fri, 4 Mar 2022 13:38:42 +0300 Subject: [PATCH] Enable clang for transformations (#10778) * Enable clang for transformations * Fixed code style * Fixed build * Fixed macOS --- src/common/transformations/CMakeLists.txt | 2 +- .../include/ngraph_ops/nms_ie_internal.hpp | 3 +- .../ngraph_ops/nms_static_shape_ie.hpp | 37 +- .../include/ngraph_ops/type_relaxed.hpp | 90 +-- .../add_fake_quantize_fusion.hpp | 8 +- .../align_eltwise_input_ranks.hpp | 4 +- .../batch_to_space_fusion.hpp | 8 +- .../common_optimizations/binarize_weights.hpp | 8 +- .../broadcast_elementwise_fusion.hpp | 6 +- .../common_optimizations/clamp_fusion.hpp | 8 +- .../common_optimizations.hpp | 9 +- .../compress_float_constants.hpp | 2 +- .../concat_reduce_fusion.hpp | 6 +- .../common_optimizations/conv_mul_fusion.hpp | 14 +- .../conv_to_binary_conv.hpp | 6 +- .../convert_nms_gather_path_to_unsigned.hpp | 4 +- .../convert_quantize_dequantize.hpp | 8 +- .../depth_to_space_fusion.hpp | 10 +- .../dilated_convolution_converter.hpp | 8 +- .../dimension_tracking.hpp | 40 +- ...isable_random_uniform_constant_folding.hpp | 4 +- .../disable_shapeof_constant_folding.hpp | 7 +- .../division_by_zero_fp16_resolver.hpp | 14 +- .../eliminate_unsqueeze_gather.hpp | 4 +- .../common_optimizations/fq_mul_fusion.hpp | 14 +- .../fq_reshape_fusion.hpp | 10 +- .../common_optimizations/hsigmoid_fusion.hpp | 17 +- .../common_optimizations/hswish_fusion.hpp | 17 +- .../interpolate_sequence_fusion.hpp | 7 +- .../leaky_relu_fusion.hpp | 8 +- .../lin_op_sequence_fusion.hpp | 13 +- .../matmul_const_transposes_extraction.hpp | 7 +- .../matmul_multiply_fusion.hpp | 5 +- .../common_optimizations/mish_fusion.hpp | 9 +- .../moc_transformations.hpp | 9 +- .../common_optimizations/mul_conv_fusion.hpp | 22 +- .../mul_fake_quantize_fusion.hpp | 8 +- .../common_optimizations/mvn_fusion.hpp | 12 +- .../nearest_neighbor_upsampling_fusion.hpp | 6 +- .../common_optimizations/nop_elimination.hpp | 22 +- .../normalize_l2_fusion.hpp | 8 +- .../optimize_strided_slice.hpp | 15 +- .../common_optimizations/pad_fusion.hpp | 15 +- .../pull_transpose_through_fq.hpp | 8 +- .../relu_fake_quantize_fusion.hpp | 5 +- .../remove_concat_zero_dim_input.hpp | 7 +- .../remove_filtering_boxes_by_size.hpp | 10 +- ...move_multi_subgraph_op_dangling_params.hpp | 7 +- .../reshape_sequence_fusion.hpp | 8 +- .../common_optimizations/ric_fusion.hpp | 11 +- .../shuffle_channels_fusion.hpp | 8 +- .../simplify_shape_of_sub_graph.hpp | 17 +- ...ip_gather_before_transpose_and_reshape.hpp | 2 +- .../common_optimizations/softmax_fusion.hpp | 5 +- .../common_optimizations/softplus_fusion.hpp | 7 +- .../softplus_to_mish_fusion.hpp | 9 +- .../space_to_batch_fusion.hpp | 8 +- ...plit_concat_pair_to_interpolate_fusion.hpp | 7 +- .../split_squeeze_concat_fusion.hpp | 7 +- .../strides_optimization.hpp | 22 +- .../common_optimizations/swish_fusion.hpp | 15 +- ...anspose_reshape_elimination_for_matmul.hpp | 7 +- .../transpose_sinking.hpp | 16 +- .../transpose_to_reshape.hpp | 7 +- .../weights_dequantize_to_fake_quantize.hpp | 7 +- .../wrap_interpolate_into_transposes.hpp | 7 +- .../control_flow/unroll_if.hpp | 2 + .../control_flow/unroll_tensor_iterator.hpp | 8 +- .../transformations/convert_precision.hpp | 36 +- ...decompression_convert_constant_folding.hpp | 2 +- .../include/transformations/fix_rt_info.hpp | 5 +- .../transformations/init_node_info.hpp | 7 +- ...convert_constant_folding_on_const_path.hpp | 8 +- .../batch_norm_decomposition.hpp | 9 +- .../bidirectional_sequences_decomposition.hpp | 8 +- .../op_conversions/convert_batch_to_space.hpp | 8 +- .../op_conversions/convert_broadcast3.hpp | 8 +- .../convert_broadcast_to_tiles.hpp | 8 +- .../convert_deformable_conv_v8_to_v1.hpp | 3 +- .../op_conversions/convert_depth_to_space.hpp | 8 +- .../op_conversions/convert_divide.hpp | 10 +- .../op_conversions/convert_gather_0d.hpp | 10 +- .../convert_gather_downgrade.hpp | 3 +- .../op_conversions/convert_gather_upgrade.hpp | 3 +- .../op_conversions/convert_gelu.hpp | 8 +- .../convert_interpolate1_to_interpolate4.hpp | 10 +- .../convert_matrix_nms_to_matrix_nms_ie.hpp | 9 +- .../convert_maxpool_downgrade.hpp | 2 +- .../convert_maxpool_upgrade.hpp | 2 +- .../convert_minimum_to_power_and_max.hpp | 8 +- .../op_conversions/convert_mod.hpp | 8 +- ...rt_multiclass_nms_to_multiclass_nms_ie.hpp | 9 +- .../op_conversions/convert_mvn1_to_mvn6.hpp | 3 +- .../op_conversions/convert_negative.hpp | 8 +- .../convert_nms_to_nms_ie_internal.hpp | 9 +- .../convert_pad_to_group_conv.hpp | 8 +- .../convert_previous_nms_to_nms_5.hpp | 12 +- .../convert_reduce_to_pooling.hpp | 72 ++- .../convert_scatter_elements_to_scatter.hpp | 8 +- .../convert_sequences_to_tensor_iterator.hpp | 12 +- .../op_conversions/convert_shapeof3.hpp | 8 +- .../convert_shuffle_channels3.hpp | 8 +- .../convert_slice_to_strided_slice.hpp | 5 +- .../convert_softmax_downgrade.hpp | 3 +- .../convert_softmax_upgrade.hpp | 3 +- .../op_conversions/convert_space_to_batch.hpp | 8 +- .../op_conversions/convert_space_to_depth.hpp | 8 +- .../op_conversions/convert_subtract.hpp | 8 +- .../convert_ti_to_sequences.hpp | 15 +- .../op_conversions/convert_topk3.hpp | 8 +- .../op_conversions/fq_decomposition.hpp | 10 +- .../gather_normalize_negative_indices.hpp | 4 +- .../op_conversions/gelu7_downgrade.hpp | 4 +- .../op_conversions/gru_cell_decomposition.hpp | 8 +- .../op_conversions/hsigmoid_decomposition.hpp | 4 +- .../op_conversions/hswish_decomposition.hpp | 4 +- .../log_softmax_decomposition.hpp | 4 +- .../lstm_cell_decomposition.hpp | 8 +- .../op_conversions/mvn6_decomposition.hpp | 7 +- .../normalize_l2_decomposition.hpp | 9 +- .../reduce_l1_decomposition.hpp | 9 +- .../reduce_l2_decomposition.hpp | 9 +- .../op_conversions/rnn_cell_decomposition.hpp | 8 +- .../simplify_ctc_greedy_decoder_seq_len.hpp | 6 +- .../op_conversions/softmax_decomposition.hpp | 6 +- .../op_conversions/softplus_decomposition.hpp | 7 +- .../convert_opset2_to_opset1.hpp | 4 +- .../convert_opset3_to_opset2.hpp | 4 +- .../resolve_names_collisions.hpp | 3 +- .../transformations/rt_info/attributes.hpp | 8 +- .../transformations/rt_info/decompression.hpp | 12 +- .../rt_info/disable_constant_folding.hpp | 11 +- .../rt_info/disable_fp16_compression.hpp | 5 +- .../rt_info/fused_names_attribute.hpp | 18 +- .../rt_info/nms_selected_indices.hpp | 15 +- .../rt_info/nonconvertible_divide.hpp | 5 +- .../rt_info/preprocessing_attribute.hpp | 6 +- .../rt_info/primitives_priority_attribute.hpp | 14 +- .../rt_info/strides_property.hpp | 5 +- .../broadcast_const_range_replacement.hpp | 8 +- .../smart_reshape/matmul_sr.hpp | 9 +- .../smart_reshape/mimic_set_batch_size.hpp | 3 +- .../proposal_scales_stridedslice.hpp | 3 +- .../smart_reshape/reshape_to_1D.hpp | 3 +- .../smart_reshape/set_batch_size.hpp | 5 +- .../smart_reshape/smart_reshape.hpp | 5 +- .../smart_reshape/strided_slice_squeeze.hpp | 12 +- .../include/transformations/utils/utils.hpp | 94 +-- .../src/ngraph_ops/nms_ie_internal.cpp | 52 +- .../src/ngraph_ops/nms_static_shape_ie.cpp | 6 +- .../add_fake_quantize_fusion.cpp | 58 +- .../align_eltwise_input_ranks.cpp | 5 +- .../batch_to_space_fusion.cpp | 78 ++- .../common_optimizations/binarize_weights.cpp | 125 ++-- .../broadcast_elementwise_fusion.cpp | 43 +- .../common_optimizations/clamp_fusion.cpp | 22 +- .../common_optimizations.cpp | 185 +++--- .../compress_float_constants.cpp | 11 +- .../concat_reduce_fusion.cpp | 27 +- .../common_optimizations/conv_mul_fusion.cpp | 145 +++-- .../conv_to_binary_conv.cpp | 101 +-- .../convert_nms_gather_path_to_unsigned.cpp | 158 ++--- .../convert_quantize_dequantize.cpp | 52 +- .../depth_to_space_fusion.cpp | 56 +- .../dilated_convolution_converter.cpp | 58 +- .../dimension_tracking.cpp | 7 +- .../disable_shapeof_constant_folding.cpp | 10 +- .../common_optimizations/divide_fusion.cpp | 14 +- .../division_by_zero_fp16_resolver.cpp | 10 +- .../eliminate_unsqueeze_gather.cpp | 23 +- .../common_optimizations/fq_mul_fusion.cpp | 57 +- .../fq_reshape_fusion.cpp | 68 +- .../common_optimizations/gelu_fusion.cpp | 123 ++-- .../common_optimizations/hsigmoid_fusion.cpp | 150 +++-- .../common_optimizations/hswish_fusion.cpp | 108 ++-- .../interpolate_sequence_fusion.cpp | 85 ++- .../leaky_relu_fusion.cpp | 24 +- .../lin_op_sequence_fusion.cpp | 35 +- .../mark_precision_sensitive_divides.cpp | 7 +- .../mark_precision_sensitive_subgraphs.cpp | 8 +- .../matmul_const_transposes_extraction.cpp | 23 +- .../matmul_multiply_fusion.cpp | 35 +- .../common_optimizations/mish_fusion.cpp | 13 +- .../moc_transformations.cpp | 104 ++-- .../common_optimizations/mul_conv_fusion.cpp | 76 ++- .../mul_fake_quantize_fusion.cpp | 43 +- .../common_optimizations/mvn_fusion.cpp | 130 ++-- .../nearest_neighbor_upsampling_fusion.cpp | 229 ++++--- .../common_optimizations/nop_elimination.cpp | 92 ++- .../normalize_l2_fusion.cpp | 26 +- .../optimize_strided_slice.cpp | 78 ++- .../common_optimizations/pad_fusion.cpp | 203 +++--- .../pull_transpose_through_fq.cpp | 27 +- .../random_uniform_fusion.cpp | 10 +- .../relu_fake_quantize_fusion.cpp | 18 +- .../remove_concat_zero_dim_input.cpp | 40 +- .../remove_filtering_boxes_by_size.cpp | 50 +- ...move_multi_subgraph_op_dangling_params.cpp | 45 +- .../reshape_sequence_fusion.cpp | 64 +- .../common_optimizations/ric_fusion.cpp | 264 ++++---- .../shuffle_channels_fusion.cpp | 78 ++- .../simplify_shape_of_sub_graph.cpp | 51 +- ...ip_gather_before_transpose_and_reshape.cpp | 17 +- .../common_optimizations/softmax_fusion.cpp | 36 +- .../common_optimizations/softplus_fusion.cpp | 25 +- .../softplus_to_mish_fusion.cpp | 13 +- .../space_to_batch_fusion.cpp | 86 +-- ...plit_concat_pair_to_interpolate_fusion.cpp | 91 ++- .../split_squeeze_concat_fusion.cpp | 56 +- .../strides_optimization.cpp | 83 ++- .../common_optimizations/subtract_fusion.cpp | 13 +- .../common_optimizations/swish_fusion.cpp | 46 +- ...anspose_reshape_elimination_for_matmul.cpp | 82 ++- .../transpose_sinking.cpp | 127 ++-- .../transpose_to_reshape.cpp | 32 +- .../weights_dequantize_to_fake_quantize.cpp | 45 +- .../wrap_interpolate_into_transposes.cpp | 46 +- .../control_flow/unroll_if.cpp | 9 +- .../control_flow/unroll_tensor_iterator.cpp | 86 +-- ...decompression_convert_constant_folding.cpp | 4 +- ...convert_constant_folding_on_const_path.cpp | 17 +- .../batch_norm_decomposition.cpp | 57 +- .../bidirectional_sequences_decomposition.cpp | 238 +++---- .../op_conversions/convert_batch_to_space.cpp | 57 +- .../op_conversions/convert_broadcast3.cpp | 50 +- .../convert_broadcast_to_tiles.cpp | 21 +- .../convert_deformable_conv_v8_to_v1.cpp | 29 +- .../op_conversions/convert_depth_to_space.cpp | 55 +- .../op_conversions/convert_divide.cpp | 30 +- .../op_conversions/convert_gather_0d.cpp | 20 +- .../convert_gather_downgrade.cpp | 5 +- .../op_conversions/convert_gather_upgrade.cpp | 5 +- .../op_conversions/convert_gelu.cpp | 17 +- .../convert_interpolate1_to_interpolate4.cpp | 43 +- .../convert_matrix_nms_to_matrix_nms_ie.cpp | 20 +- .../convert_maxpool_downgrade.cpp | 17 +- .../convert_maxpool_upgrade.cpp | 4 +- .../convert_minimum_to_power_and_max.cpp | 26 +- .../op_conversions/convert_mod.cpp | 14 +- ...rt_multiclass_nms_to_multiclass_nms_ie.cpp | 20 +- .../op_conversions/convert_mvn1_to_mvn6.cpp | 16 +- .../op_conversions/convert_negative.cpp | 15 +- .../convert_nms_to_nms_ie_internal.cpp | 82 +-- .../convert_pad_to_group_conv.cpp | 38 +- .../convert_previous_nms_to_nms_5.cpp | 232 ++++--- .../convert_prior_box_v8_to_v0.cpp | 4 +- .../convert_reduce_to_pooling.cpp | 25 +- .../convert_scatter_elements_to_scatter.cpp | 62 +- .../convert_sequences_to_tensor_iterator.cpp | 588 +++++++++--------- .../op_conversions/convert_shapeof3.cpp | 10 +- .../convert_shuffle_channels3.cpp | 43 +- .../convert_slice_to_strided_slice.cpp | 51 +- .../convert_softmax_downgrade.cpp | 4 +- .../convert_softmax_upgrade.cpp | 4 +- .../op_conversions/convert_space_to_batch.cpp | 41 +- .../op_conversions/convert_space_to_depth.cpp | 27 +- .../op_conversions/convert_subtract.cpp | 26 +- .../convert_ti_to_sequences.cpp | 225 +++---- .../op_conversions/convert_topk3.cpp | 19 +- .../detection_output_upgrade.cpp | 22 +- .../op_conversions/einsum_decomposition.cpp | 192 ++++-- .../op_conversions/fq_decomposition.cpp | 39 +- .../gather_normalize_negative_indices.cpp | 18 +- .../op_conversions/gelu7_downgrade.cpp | 7 +- .../op_conversions/gru_cell_decomposition.cpp | 34 +- .../op_conversions/hsigmoid_decomposition.cpp | 15 +- .../op_conversions/hswish_decomposition.cpp | 12 +- .../log_softmax_decomposition.cpp | 17 +- .../lstm_cell_decomposition.cpp | 21 +- .../op_conversions/mvn6_decomposition.cpp | 12 +- .../normalize_l2_decomposition.cpp | 33 +- .../reduce_l1_decomposition.cpp | 21 +- .../reduce_l2_decomposition.cpp | 24 +- .../op_conversions/rnn_cell_decomposition.cpp | 12 +- .../simplify_ctc_greedy_decoder_seq_len.cpp | 78 ++- .../op_conversions/softmax_decomposition.cpp | 15 +- .../op_conversions/softplus_decomposition.cpp | 13 +- .../convert_opset2_to_opset1.cpp | 9 +- .../convert_opset3_to_opset2.cpp | 11 +- .../resolve_names_collisions.cpp | 9 +- .../rt_info/nms_selected_indices.cpp | 5 +- .../broadcast_const_range_replacement.cpp | 46 +- .../proposal_scales_stridedslice.cpp | 8 +- .../smart_reshape/strided_slice_squeeze.cpp | 9 +- .../src/transformations/utils/utils.cpp | 137 ++-- 285 files changed, 4899 insertions(+), 4192 deletions(-) diff --git a/src/common/transformations/CMakeLists.txt b/src/common/transformations/CMakeLists.txt index b676441e892..5e2c2b339d1 100644 --- a/src/common/transformations/CMakeLists.txt +++ b/src/common/transformations/CMakeLists.txt @@ -30,7 +30,7 @@ target_link_libraries(${TARGET_NAME}_obj PRIVATE ngraph_reference openvino::itt target_include_directories(${TARGET_NAME}_obj PRIVATE $ "${CMAKE_CURRENT_SOURCE_DIR}/src") -add_cpplint_target(${TARGET_NAME}_cpplint FOR_TARGETS ${TARGET_NAME}_obj) +add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME}_obj) ie_mark_target_as_cc(${TARGET_NAME}_obj) diff --git a/src/common/transformations/include/ngraph_ops/nms_ie_internal.hpp b/src/common/transformations/include/ngraph_ops/nms_ie_internal.hpp index 34a5b6ec7ab..edd3b0f0e03 100644 --- a/src/common/transformations/include/ngraph_ops/nms_ie_internal.hpp +++ b/src/common/transformations/include/ngraph_ops/nms_ie_internal.hpp @@ -6,7 +6,6 @@ #include #include - #include #include "ngraph/coordinate_diff.hpp" @@ -48,7 +47,7 @@ public: bool visit_attributes(AttributeVisitor& visitor) override; - std::shared_ptr clone_with_new_inputs(const OutputVector & new_args) const override; + std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; int m_center_point_box; bool m_sort_result_descending = true; diff --git a/src/common/transformations/include/ngraph_ops/nms_static_shape_ie.hpp b/src/common/transformations/include/ngraph_ops/nms_static_shape_ie.hpp index cb7ee61fdb5..573cba61849 100644 --- a/src/common/transformations/include/ngraph_ops/nms_static_shape_ie.hpp +++ b/src/common/transformations/include/ngraph_ops/nms_static_shape_ie.hpp @@ -4,15 +4,25 @@ #pragma once -#include -#include #include +#include #include - #include +#include #include "ngraph/op/op.hpp" +namespace ov { +namespace op { +namespace v8 { + +class MulticlassNms; +class MatrixNms; + +} // namespace v8 +} // namespace op +} // namespace ov + namespace ngraph { namespace op { namespace internal { @@ -31,9 +41,8 @@ public: /// \param boxes Node producing the box coordinates /// \param scores Node producing the box scores /// \param attrs Attributes of the operation - NmsStaticShapeIE(const Output& boxes, - const Output& scores, - const Attributes& attrs) : BaseNmsOp(boxes, scores, attrs) { + NmsStaticShapeIE(const Output& boxes, const Output& scores, const Attributes& attrs) + : BaseNmsOp(boxes, scores, attrs) { this->constructor_validate_and_infer_types(); } void validate_and_infer_types() override; @@ -42,7 +51,8 @@ public: } private: - typedef struct {} init_rt_result; + typedef struct { + } init_rt_result; init_rt_result init_rt_info() { BaseNmsOp::get_rt_info()["opset"] = "ie_internal_opset"; @@ -98,7 +108,9 @@ void NmsStaticShapeIE::validate_and_infer_types() { } template -const ::ngraph::Node::type_info_t& NmsStaticShapeIE::get_type_info() const { return get_type_info_static(); } +const ::ngraph::Node::type_info_t& NmsStaticShapeIE::get_type_info() const { + return get_type_info_static(); +} template const ::ngraph::Node::type_info_t& NmsStaticShapeIE::get_type_info_static() { @@ -108,14 +120,17 @@ const ::ngraph::Node::type_info_t& NmsStaticShapeIE::get_type_info_st // but currently it will not pass conversion ot Legacy Opset correctly static const std::string name = BaseNmsOpTypeInfoPtr->name; - static const ::ngraph::Node::type_info_t type_info_static{ - name.c_str(), BaseNmsOpTypeInfoPtr->version, "ie_internal_opset", BaseNmsOpTypeInfoPtr}; + static const ::ngraph::Node::type_info_t type_info_static{name.c_str(), + BaseNmsOpTypeInfoPtr->version, + "ie_internal_opset", + BaseNmsOpTypeInfoPtr}; return type_info_static; } #ifndef OPENVINO_STATIC_LIBRARY template -const ::ngraph::Node::type_info_t NmsStaticShapeIE::type_info = NmsStaticShapeIE::get_type_info_static(); +const ::ngraph::Node::type_info_t NmsStaticShapeIE::type_info = + NmsStaticShapeIE::get_type_info_static(); #endif #ifdef __clang__ diff --git a/src/common/transformations/include/ngraph_ops/type_relaxed.hpp b/src/common/transformations/include/ngraph_ops/type_relaxed.hpp index 0b0c6735643..d7de519a8fc 100644 --- a/src/common/transformations/include/ngraph_ops/type_relaxed.hpp +++ b/src/common/transformations/include/ngraph_ops/type_relaxed.hpp @@ -4,15 +4,14 @@ #pragma once -#include -#include #include -#include +#include #include - -#include - #include +#include +#include +#include + #include "ngraph/op/op.hpp" #include "ngraph/variant.hpp" @@ -24,12 +23,10 @@ class NGRAPH_API TypeRelaxedBase { public: virtual ~TypeRelaxedBase(); - explicit TypeRelaxedBase( - const element::TypeVector& _input_data_types = {}, - const element::TypeVector& _output_data_types = {}) : - m_input_data_types(_input_data_types), - m_output_data_types(_output_data_types) { - } + explicit TypeRelaxedBase(const element::TypeVector& _input_data_types = {}, + const element::TypeVector& _output_data_types = {}) + : m_input_data_types(_input_data_types), + m_output_data_types(_output_data_types) {} /// \return Data type that will be set for output with a given index outputIndex. /// If output with a specified index outputIndex hasn't been set before, element::undefined will returned. @@ -83,7 +80,7 @@ public: } protected: - void remember_input_data_types(Node &node, element::TypeVector &old_input_types) { + void remember_input_data_types(Node& node, element::TypeVector& old_input_types) { // Remember all input data types for (size_t i = 0; i < node.get_input_size(); ++i) { old_input_types.push_back(node.get_input_element_type(i)); @@ -100,7 +97,7 @@ protected: } } - void restore_input_data_types(Node &node, const element::TypeVector &old_input_types) { + void restore_input_data_types(Node& node, const element::TypeVector& old_input_types) { // Restore original input data types for (size_t i = 0; i < node.get_input_size(); ++i) { OPENVINO_SUPPRESS_DEPRECATED_START @@ -133,9 +130,10 @@ protected: visitor.on_attribute("output_data_types", m_output_data_types); } - typedef struct {} init_rt_result; + typedef struct { + } init_rt_result; - init_rt_result init_rt_info(Node &node) const { + init_rt_result init_rt_info(Node& node) const { node.get_rt_info()["opset"] = "type_relaxed_opset"; return {}; } @@ -200,29 +198,26 @@ public: TypeRelaxed() = default; - TypeRelaxed( - const BaseOp& base_op, - element::Type overridden_type) : - TypeRelaxed(base_op, - element::TypeVector(base_op.get_input_size(), overridden_type), - element::TypeVector(base_op.get_output_size(), overridden_type)) { - } + TypeRelaxed(const BaseOp& base_op, element::Type overridden_type) + : TypeRelaxed(base_op, + element::TypeVector(base_op.get_input_size(), overridden_type), + element::TypeVector(base_op.get_output_size(), overridden_type)) {} - explicit TypeRelaxed( - const BaseOp& base_op, - const element::TypeVector& _input_data_types = {}, - const element::TypeVector& _output_data_types = {}) : - BaseOp(base_op), TypeRelaxedBase(_input_data_types, _output_data_types) { + explicit TypeRelaxed(const BaseOp& base_op, + const element::TypeVector& _input_data_types = {}, + const element::TypeVector& _output_data_types = {}) + : BaseOp(base_op), + TypeRelaxedBase(_input_data_types, _output_data_types) { init(); } /// Creating a new TypeRelaxed operation by calling one of the original op ctors forwarding arguments directly. - template - TypeRelaxed( - const element::TypeVector& _input_data_types, - const element::TypeVector& _output_data_types, - Args&& ... args) : - BaseOp(std::forward(args)...), TypeRelaxedBase(_input_data_types, _output_data_types) { + template + TypeRelaxed(const element::TypeVector& _input_data_types, + const element::TypeVector& _output_data_types, + Args&&... args) + : BaseOp(std::forward(args)...), + TypeRelaxedBase(_input_data_types, _output_data_types) { init(); } @@ -261,7 +256,7 @@ bool TypeRelaxed::evaluate(const HostTensorVector& outputs, const HostTe convert->set_destination_type(expected_input_type); casted_inputs[i] = std::make_shared(expected_input_type, inputs[i]->get_shape()); - if (!convert->evaluate({ casted_inputs[i] }, { inputs[i] })) { + if (!convert->evaluate({casted_inputs[i]}, {inputs[i]})) { return false; } } @@ -273,7 +268,8 @@ bool TypeRelaxed::evaluate(const HostTensorVector& outputs, const HostTe if (expected_output_type == element::undefined || expected_output_type == m_original_output_data_types[i]) { original_outputs[i] = outputs[i]; } else { - original_outputs[i] = std::make_shared(m_original_output_data_types[i], BaseOp::get_output_partial_shape(i)); + original_outputs[i] = + std::make_shared(m_original_output_data_types[i], BaseOp::get_output_partial_shape(i)); } } @@ -284,14 +280,16 @@ bool TypeRelaxed::evaluate(const HostTensorVector& outputs, const HostTe for (size_t i = 0; i < BaseOp::get_output_size(); ++i) { const auto expected_output_type = get_overridden_output_type(i); - if (expected_output_type != element::undefined && original_outputs[i]->get_element_type() != expected_output_type) { + if (expected_output_type != element::undefined && + original_outputs[i]->get_element_type() != expected_output_type) { if (convert == nullptr) { convert = std::make_shared(); } convert->set_destination_type(expected_output_type); - const auto casted_output = std::make_shared(expected_output_type, original_outputs[i]->get_shape()); - if (!convert->evaluate({ outputs[i] }, { original_outputs[i] })) { + const auto casted_output = + std::make_shared(expected_output_type, original_outputs[i]->get_shape()); + if (!convert->evaluate({outputs[i]}, {original_outputs[i]})) { return false; } } @@ -314,12 +312,12 @@ void TypeRelaxed::validate_and_infer_types() { restore_input_data_types(*this, old_input_types); } - template std::shared_ptr TypeRelaxed::clone_with_new_inputs(const OutputVector& new_args) const { std::lock_guard lock(type_relax_mutex); // copy then modify inputs - std::shared_ptr new_node = std::make_shared>((BaseOp&)(*this), m_input_data_types, m_output_data_types); + std::shared_ptr new_node = + std::make_shared>((BaseOp&)(*this), m_input_data_types, m_output_data_types); for (size_t i = 0; i < new_node->get_input_size(); ++i) { new_node->input(i).replace_source_output(new_args[i]); } @@ -336,13 +334,17 @@ bool TypeRelaxed::visit_attributes(AttributeVisitor& visitor) { } template -const ::ngraph::Node::type_info_t& TypeRelaxed::get_type_info() const { return get_type_info_static(); } +const ::ngraph::Node::type_info_t& TypeRelaxed::get_type_info() const { + return get_type_info_static(); +} template const ::ngraph::Node::type_info_t& TypeRelaxed::get_type_info_static() { auto baseOpTypeInfoPtr = &BaseOp::get_type_info_static(); - static const ::ngraph::Node::type_info_t type_info_static{ - baseOpTypeInfoPtr->name, baseOpTypeInfoPtr->version, baseOpTypeInfoPtr->version_id, baseOpTypeInfoPtr}; + static const ::ngraph::Node::type_info_t type_info_static{baseOpTypeInfoPtr->name, + baseOpTypeInfoPtr->version, + baseOpTypeInfoPtr->version_id, + baseOpTypeInfoPtr}; return type_info_static; } diff --git a/src/common/transformations/include/transformations/common_optimizations/add_fake_quantize_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/add_fake_quantize_fusion.hpp index 8aac9a9c497..5453aba6676 100644 --- a/src/common/transformations/include/transformations/common_optimizations/add_fake_quantize_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/add_fake_quantize_fusion.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - #include +#include +#include namespace ngraph { namespace pass { @@ -26,7 +24,7 @@ class TRANSFORMATIONS_API AddFakeQuantizeFusion; * Restrictions: * - second input to Add is a Constant */ -class ngraph::pass::AddFakeQuantizeFusion: public ngraph::pass::MatcherPass { +class ngraph::pass::AddFakeQuantizeFusion : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; AddFakeQuantizeFusion(); diff --git a/src/common/transformations/include/transformations/common_optimizations/align_eltwise_input_ranks.hpp b/src/common/transformations/include/transformations/common_optimizations/align_eltwise_input_ranks.hpp index 16469f1fb95..ba93c0ca3b8 100644 --- a/src/common/transformations/include/transformations/common_optimizations/align_eltwise_input_ranks.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/align_eltwise_input_ranks.hpp @@ -4,8 +4,8 @@ #pragma once -#include #include +#include /** * @ingroup ie_transformation_common_api @@ -15,7 +15,7 @@ namespace ngraph { namespace pass { -class TRANSFORMATIONS_API AlignEltwiseInputRanks: public MatcherPass { +class TRANSFORMATIONS_API AlignEltwiseInputRanks : public MatcherPass { public: NGRAPH_RTTI_DECLARATION; AlignEltwiseInputRanks(); diff --git a/src/common/transformations/include/transformations/common_optimizations/batch_to_space_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/batch_to_space_fusion.hpp index c9b03a3e6a6..fae7826198b 100644 --- a/src/common/transformations/include/transformations/common_optimizations/batch_to_space_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/batch_to_space_fusion.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - #include +#include +#include namespace ngraph { namespace pass { @@ -30,7 +28,7 @@ class TRANSFORMATIONS_API BatchToSpaceFusion; * - DepthToSpaceMode must be BLOCKS_FIRST */ -class ngraph::pass::BatchToSpaceFusion: public ngraph::pass::MatcherPass { +class ngraph::pass::BatchToSpaceFusion : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; BatchToSpaceFusion(); diff --git a/src/common/transformations/include/transformations/common_optimizations/binarize_weights.hpp b/src/common/transformations/include/transformations/common_optimizations/binarize_weights.hpp index cff18174b78..6a1e857f2ef 100644 --- a/src/common/transformations/include/transformations/common_optimizations/binarize_weights.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/binarize_weights.hpp @@ -4,17 +4,18 @@ #pragma once -#include #include +#include namespace ngraph { namespace pass { class TRANSFORMATIONS_API BinarizeWeights; -} // namespace pass -} // namespace ngraph +} // namespace pass +} // namespace ngraph +// clang-format off /** * @ingroup ie_transformation_common_api * @brief This transformation converts weights to -1/+1 form @@ -71,6 +72,7 @@ class TRANSFORMATIONS_API BinarizeWeights; * Normalization factors are chosen based output_high value. * If it's zero - norm factor is equal to output_low and output_high otherwise */ +// clang-format on class ngraph::pass::BinarizeWeights : public ngraph::pass::MatcherPass { public: diff --git a/src/common/transformations/include/transformations/common_optimizations/broadcast_elementwise_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/broadcast_elementwise_fusion.hpp index 20d2784686c..a7f87a97b63 100644 --- a/src/common/transformations/include/transformations/common_optimizations/broadcast_elementwise_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/broadcast_elementwise_fusion.hpp @@ -4,10 +4,10 @@ #pragma once -#include - #include #include +#include + #include "ngraph/pattern/matcher.hpp" namespace ngraph { @@ -24,7 +24,7 @@ class TRANSFORMATIONS_API BroadcastElementwiseFusion; * are equal neighboring input shape of ElementWise. */ -class ngraph::pass::BroadcastElementwiseFusion: public ngraph::pass::MatcherPass { +class ngraph::pass::BroadcastElementwiseFusion : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; BroadcastElementwiseFusion(); diff --git a/src/common/transformations/include/transformations/common_optimizations/clamp_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/clamp_fusion.hpp index 00e19979d3d..5e555279a2d 100644 --- a/src/common/transformations/include/transformations/common_optimizations/clamp_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/clamp_fusion.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - #include +#include +#include namespace ngraph { namespace pass { @@ -28,7 +26,7 @@ class TRANSFORMATIONS_API ClampFusion; * - one of the parameters to Minimum is a scalar constant */ -class ngraph::pass::ClampFusion: public ngraph::pass::MatcherPass { +class ngraph::pass::ClampFusion : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ClampFusion(); diff --git a/src/common/transformations/include/transformations/common_optimizations/common_optimizations.hpp b/src/common/transformations/include/transformations/common_optimizations/common_optimizations.hpp index c7d23ef2682..a7b6cd8f092 100644 --- a/src/common/transformations/include/transformations/common_optimizations/common_optimizations.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/common_optimizations.hpp @@ -4,13 +4,10 @@ #pragma once -#include #include - -#include - #include - +#include +#include namespace ngraph { namespace pass { @@ -20,7 +17,7 @@ class TRANSFORMATIONS_API CommonOptimizations; } // namespace pass } // namespace ngraph -class ngraph::pass::CommonOptimizations: public ngraph::pass::FunctionPass { +class ngraph::pass::CommonOptimizations : public ngraph::pass::FunctionPass { public: NGRAPH_RTTI_DECLARATION; bool run_on_model(const std::shared_ptr& f) override; diff --git a/src/common/transformations/include/transformations/common_optimizations/compress_float_constants.hpp b/src/common/transformations/include/transformations/common_optimizations/compress_float_constants.hpp index 7fcfcd12509..0ece6dc9e35 100644 --- a/src/common/transformations/include/transformations/common_optimizations/compress_float_constants.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/compress_float_constants.hpp @@ -4,8 +4,8 @@ #pragma once -#include "transformations_visibility.hpp" #include "openvino/pass/graph_rewrite.hpp" +#include "transformations_visibility.hpp" namespace ov { namespace pass { diff --git a/src/common/transformations/include/transformations/common_optimizations/concat_reduce_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/concat_reduce_fusion.hpp index e6f4f7b3716..da8c7a225de 100644 --- a/src/common/transformations/include/transformations/common_optimizations/concat_reduce_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/concat_reduce_fusion.hpp @@ -4,8 +4,8 @@ #pragma once -#include #include +#include namespace ngraph { namespace pass { @@ -32,7 +32,7 @@ public: * @ingroup ie_transformation_common_api * @brief PullSqueezeThroughEltwise transformation propagates Squeeze up through binary elementwise operations: */ -class ngraph::pass::PullSqueezeThroughEltwise: public ngraph::pass::MatcherPass { +class ngraph::pass::PullSqueezeThroughEltwise : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; PullSqueezeThroughEltwise(); @@ -74,7 +74,7 @@ public: * by a single Minimum/Maximum with 2 inputs and tries to eliminate Squeeze/Unsqueeze layers before and after Min/Max. */ -class ngraph::pass::ConcatReduceFusion: public ngraph::pass::GraphRewrite { +class ngraph::pass::ConcatReduceFusion : public ngraph::pass::GraphRewrite { public: NGRAPH_RTTI_DECLARATION; ConcatReduceFusion(); diff --git a/src/common/transformations/include/transformations/common_optimizations/conv_mul_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/conv_mul_fusion.hpp index 38095b08b33..bc56afa8d59 100644 --- a/src/common/transformations/include/transformations/common_optimizations/conv_mul_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/conv_mul_fusion.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - +#include #include +#include namespace ngraph { namespace pass { @@ -22,25 +20,25 @@ class TRANSFORMATIONS_API GroupConvolutionBackpropDataMultiplyFusion; } // namespace pass } // namespace ngraph -class ngraph::pass::ConvolutionMultiplyFusion: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvolutionMultiplyFusion : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvolutionMultiplyFusion(); }; -class ngraph::pass::GroupConvolutionMultiplyFusion: public ngraph::pass::MatcherPass { +class ngraph::pass::GroupConvolutionMultiplyFusion : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; GroupConvolutionMultiplyFusion(); }; -class ngraph::pass::ConvolutionBackpropDataMultiplyFusion: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvolutionBackpropDataMultiplyFusion : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvolutionBackpropDataMultiplyFusion(); }; -class ngraph::pass::GroupConvolutionBackpropDataMultiplyFusion: public ngraph::pass::MatcherPass { +class ngraph::pass::GroupConvolutionBackpropDataMultiplyFusion : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; GroupConvolutionBackpropDataMultiplyFusion(); diff --git a/src/common/transformations/include/transformations/common_optimizations/conv_to_binary_conv.hpp b/src/common/transformations/include/transformations/common_optimizations/conv_to_binary_conv.hpp index fa58a06a4a5..f995f09ce1b 100644 --- a/src/common/transformations/include/transformations/common_optimizations/conv_to_binary_conv.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/conv_to_binary_conv.hpp @@ -4,16 +4,16 @@ #pragma once -#include #include +#include namespace ngraph { namespace pass { class TRANSFORMATIONS_API ConvToBinaryConv; -} // namespace pass -} // namespace ngraph +} // namespace pass +} // namespace ngraph /** * @ingroup ie_transformation_common_api diff --git a/src/common/transformations/include/transformations/common_optimizations/convert_nms_gather_path_to_unsigned.hpp b/src/common/transformations/include/transformations/common_optimizations/convert_nms_gather_path_to_unsigned.hpp index 2e48c5a81e0..6bae6beee9e 100644 --- a/src/common/transformations/include/transformations/common_optimizations/convert_nms_gather_path_to_unsigned.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/convert_nms_gather_path_to_unsigned.hpp @@ -4,8 +4,8 @@ #pragma once -#include #include +#include namespace ngraph { namespace pass { @@ -25,7 +25,7 @@ class TRANSFORMATIONS_API ConvertNmsGatherPathToUnsigned; * Gather-8 will accept UINT32_MAX which is always outside of the bounds * and corresponding output for such indices in gather always will be filled with zeros. */ -class ngraph::pass::ConvertNmsGatherPathToUnsigned: public ngraph::pass::GraphRewrite { +class ngraph::pass::ConvertNmsGatherPathToUnsigned : public ngraph::pass::GraphRewrite { public: NGRAPH_RTTI_DECLARATION; ConvertNmsGatherPathToUnsigned(); diff --git a/src/common/transformations/include/transformations/common_optimizations/convert_quantize_dequantize.hpp b/src/common/transformations/include/transformations/common_optimizations/convert_quantize_dequantize.hpp index 18f976f8b56..8f268e190f6 100644 --- a/src/common/transformations/include/transformations/common_optimizations/convert_quantize_dequantize.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/convert_quantize_dequantize.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - #include +#include +#include namespace ngraph { namespace pass { @@ -30,7 +28,7 @@ class TRANSFORMATIONS_API ConvertQuantizeDequantize; * - 'zero_point' and 'scale' must be broadcastable to FakeQuantize's output */ -class ngraph::pass::ConvertQuantizeDequantize: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvertQuantizeDequantize : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvertQuantizeDequantize(); diff --git a/src/common/transformations/include/transformations/common_optimizations/depth_to_space_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/depth_to_space_fusion.hpp index eaaf76dd733..0bc433a65f6 100644 --- a/src/common/transformations/include/transformations/common_optimizations/depth_to_space_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/depth_to_space_fusion.hpp @@ -4,17 +4,15 @@ #pragma once -#include #include - -#include - #include +#include +#include namespace ngraph { namespace pass { - class TRANSFORMATIONS_API DepthToSpaceFusion; +class TRANSFORMATIONS_API DepthToSpaceFusion; } // namespace pass } // namespace ngraph @@ -41,7 +39,7 @@ namespace pass { * */ -class ngraph::pass::DepthToSpaceFusion: public ngraph::pass::MatcherPass { +class ngraph::pass::DepthToSpaceFusion : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; DepthToSpaceFusion(); diff --git a/src/common/transformations/include/transformations/common_optimizations/dilated_convolution_converter.hpp b/src/common/transformations/include/transformations/common_optimizations/dilated_convolution_converter.hpp index 480aee9cd4b..c9994063674 100644 --- a/src/common/transformations/include/transformations/common_optimizations/dilated_convolution_converter.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/dilated_convolution_converter.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - #include +#include +#include namespace ngraph { namespace pass { @@ -28,7 +26,7 @@ class TRANSFORMATIONS_API DilatedConvolutionConverter; * - pads in SpaceToBatch must have 0 on first and second position */ -class ngraph::pass::DilatedConvolutionConverter: public ngraph::pass::MatcherPass { +class ngraph::pass::DilatedConvolutionConverter : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; DilatedConvolutionConverter(); diff --git a/src/common/transformations/include/transformations/common_optimizations/dimension_tracking.hpp b/src/common/transformations/include/transformations/common_optimizations/dimension_tracking.hpp index a1137a70233..f6ad7c8656b 100644 --- a/src/common/transformations/include/transformations/common_optimizations/dimension_tracking.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/dimension_tracking.hpp @@ -5,11 +5,9 @@ #pragma once #include - -#include - -#include #include +#include +#include using P2Btype = std::unordered_map, std::unordered_set>; @@ -21,11 +19,14 @@ class TRANSFORMATIONS_API FindBatch; } // namespace pass } // namespace ov -class ov::pass::FindBatch: public ov::pass::ModelPass { +class ov::pass::FindBatch : public ov::pass::ModelPass { public: OPENVINO_RTTI("FindBatch"); - FindBatch(bool detach_detection_output = false, bool track = true) : track(track), detach_do(detach_detection_output) {} + FindBatch(bool detach_detection_output = false, bool track = true) + : track(track), + detach_do(detach_detection_output) {} bool run_on_model(const std::shared_ptr& m) override; + protected: bool track = true, detach_do = false; }; @@ -34,14 +35,19 @@ namespace ov { class DimensionTracker; namespace batch_util { - void mark_batch(const std::shared_ptr ¶meter, P2Btype &map, const std::unordered_set &batches); - void mark_no_batch(const std::shared_ptr ¶meter, P2Btype &map); - void mark_layout_independent_batch(const std::shared_ptr ¶meter, const std::shared_ptr & result, P2Btype &map); - void mark_with_unique_dimension_labels(const std::shared_ptr &m, const ov::DimensionTracker &dt); - void restore_original_dimensions( - const std::map, ov::PartialShape>& parameter_to_shape, bool leave_batch_dynamic = true); - bool check_batch_tracks_through_all_the_nodes(const std::shared_ptr& m); - P2Btype find_batch(const std::shared_ptr &m); - bool detach_detection_output(const std::shared_ptr& f); -} // namespace batch_util -} // namespace ov +void mark_batch(const std::shared_ptr& parameter, + P2Btype& map, + const std::unordered_set& batches); +void mark_no_batch(const std::shared_ptr& parameter, P2Btype& map); +void mark_layout_independent_batch(const std::shared_ptr& parameter, + const std::shared_ptr& result, + P2Btype& map); +void mark_with_unique_dimension_labels(const std::shared_ptr& m, const ov::DimensionTracker& dt); +void restore_original_dimensions( + const std::map, ov::PartialShape>& parameter_to_shape, + bool leave_batch_dynamic = true); +bool check_batch_tracks_through_all_the_nodes(const std::shared_ptr& m); +P2Btype find_batch(const std::shared_ptr& m); +bool detach_detection_output(const std::shared_ptr& f); +} // namespace batch_util +} // namespace ov diff --git a/src/common/transformations/include/transformations/common_optimizations/disable_random_uniform_constant_folding.hpp b/src/common/transformations/include/transformations/common_optimizations/disable_random_uniform_constant_folding.hpp index 32b9792098c..2da8555d6c9 100644 --- a/src/common/transformations/include/transformations/common_optimizations/disable_random_uniform_constant_folding.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/disable_random_uniform_constant_folding.hpp @@ -5,10 +5,8 @@ #pragma once #include - -#include - #include +#include namespace ngraph { namespace pass { diff --git a/src/common/transformations/include/transformations/common_optimizations/disable_shapeof_constant_folding.hpp b/src/common/transformations/include/transformations/common_optimizations/disable_shapeof_constant_folding.hpp index 14b4909e259..1e729ecff1a 100644 --- a/src/common/transformations/include/transformations/common_optimizations/disable_shapeof_constant_folding.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/disable_shapeof_constant_folding.hpp @@ -5,10 +5,8 @@ #pragma once #include - -#include - #include +#include namespace ngraph { namespace pass { @@ -18,8 +16,7 @@ class TRANSFORMATIONS_API DisableShapeOfConstantFolding; } // namespace pass } // namespace ngraph - -class ngraph::pass::DisableShapeOfConstantFolding: public ngraph::pass::MatcherPass { +class ngraph::pass::DisableShapeOfConstantFolding : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; DisableShapeOfConstantFolding(); diff --git a/src/common/transformations/include/transformations/common_optimizations/division_by_zero_fp16_resolver.hpp b/src/common/transformations/include/transformations/common_optimizations/division_by_zero_fp16_resolver.hpp index 45b0fba0061..ee85b1e2f15 100644 --- a/src/common/transformations/include/transformations/common_optimizations/division_by_zero_fp16_resolver.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/division_by_zero_fp16_resolver.hpp @@ -4,11 +4,11 @@ #pragma once -#include #include - -#include #include +#include +#include + #include "ngraph/pattern/matcher.hpp" namespace ov { @@ -24,11 +24,11 @@ class TRANSFORMATIONS_API DivisionByZeroFP16Resolver; * @brief: clamps eps into fp16 minimal normalized value in input_1/Maximum(input_2, eps); input_1/Add(input_2, eps); * and input_1*Pow(Maximum[Add](input_2, eps), -z) patterns to prevent division by zero. * - * eps must be always nonzero to prevent from NaNs in such expressions if input_1 and input_2 simultaneously happened to be zero. - * We should keep in such patterns eps >= fp16 minimal normalized value so that - * CompressFloatConstants should not cast them into zero during compression into f16. + * eps must be always nonzero to prevent from NaNs in such expressions if input_1 and input_2 simultaneously happened to + * be zero. We should keep in such patterns eps >= fp16 minimal normalized value so that CompressFloatConstants should + * not cast them into zero during compression into f16. */ -class ov::pass::DivisionByZeroFP16Resolver: public ngraph::pass::MatcherPass { +class ov::pass::DivisionByZeroFP16Resolver : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; DivisionByZeroFP16Resolver(); diff --git a/src/common/transformations/include/transformations/common_optimizations/eliminate_unsqueeze_gather.hpp b/src/common/transformations/include/transformations/common_optimizations/eliminate_unsqueeze_gather.hpp index 45824181755..45467edf817 100644 --- a/src/common/transformations/include/transformations/common_optimizations/eliminate_unsqueeze_gather.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/eliminate_unsqueeze_gather.hpp @@ -4,10 +4,10 @@ #pragma once -#include - #include #include +#include + #include "ngraph/pattern/matcher.hpp" namespace ngraph { diff --git a/src/common/transformations/include/transformations/common_optimizations/fq_mul_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/fq_mul_fusion.hpp index b2ee0c823dd..afc8b7c1278 100644 --- a/src/common/transformations/include/transformations/common_optimizations/fq_mul_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/fq_mul_fusion.hpp @@ -5,19 +5,17 @@ #pragma once #include -#include - -#include - #include +#include +#include namespace ngraph { namespace pass { class TRANSFORMATIONS_API FakeQuantizeMulFusion; -} // namespace pass -} // namespace ngraph +} // namespace pass +} // namespace ngraph /** * @ingroup ie_transformation_common_api @@ -28,6 +26,6 @@ class TRANSFORMATIONS_API FakeQuantizeMulFusion; class ngraph::pass::FakeQuantizeMulFusion : public ngraph::pass::MatcherPass { public: - NGRAPH_RTTI_DECLARATION; - FakeQuantizeMulFusion(); + NGRAPH_RTTI_DECLARATION; + FakeQuantizeMulFusion(); }; diff --git a/src/common/transformations/include/transformations/common_optimizations/fq_reshape_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/fq_reshape_fusion.hpp index b96a185a4ca..05bb7733e0e 100644 --- a/src/common/transformations/include/transformations/common_optimizations/fq_reshape_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/fq_reshape_fusion.hpp @@ -5,19 +5,17 @@ #pragma once #include -#include - -#include - #include +#include +#include namespace ngraph { namespace pass { class TRANSFORMATIONS_API FakeQuantizeReshapeFusion; -} // namespace pass -} // namespace ngraph +} // namespace pass +} // namespace ngraph /** * @ingroup ie_transformation_common_api diff --git a/src/common/transformations/include/transformations/common_optimizations/hsigmoid_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/hsigmoid_fusion.hpp index 7a200d36160..a6d97f6b01f 100644 --- a/src/common/transformations/include/transformations/common_optimizations/hsigmoid_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/hsigmoid_fusion.hpp @@ -5,10 +5,9 @@ #pragma once #include -#include - -#include #include +#include +#include namespace ngraph { namespace pass { @@ -27,7 +26,7 @@ class TRANSFORMATIONS_API HSigmoidFusionWithClampDiv; * @ingroup ie_transformation_common_api * @brief HSigmoidFusion transformation replaces a sub-graph ((min(Relu(x + 3), 6)) / 6) with a HSigmoid op. */ -class ngraph::pass::HSigmoidFusionWithReluDiv: public ngraph::pass::MatcherPass { +class ngraph::pass::HSigmoidFusionWithReluDiv : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; HSigmoidFusionWithReluDiv(); @@ -37,7 +36,7 @@ public: * @ingroup ie_transformation_common_api * @brief HSigmoidFusion transformation replaces a sub-graph ((min(Relu(x + 3), 6)) * const(1/6)) with a HSigmoid op. */ -class ngraph::pass::HSigmoidFusionWithReluMul: public ngraph::pass::MatcherPass { +class ngraph::pass::HSigmoidFusionWithReluMul : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; HSigmoidFusionWithReluMul(); @@ -47,7 +46,7 @@ public: * @ingroup ie_transformation_common_api * @brief HSigmoidFusion transformation replaces a sub-graph (min(max(x + 3, 0), 6) / 6) with a HSigmoid op. */ -class ngraph::pass::HSigmoidFusionWithoutRelu: public ngraph::pass::MatcherPass { +class ngraph::pass::HSigmoidFusionWithoutRelu : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; HSigmoidFusionWithoutRelu(); @@ -57,7 +56,7 @@ public: * @ingroup ie_transformation_common_api * @brief HSigmoidFusion transformation replaces a sub-graph (Clamp(x + 3, 0, 6) * const(1/6)) with a HSigmoid op. */ -class ngraph::pass::HSigmoidFusionWithClampMul: public ngraph::pass::MatcherPass { +class ngraph::pass::HSigmoidFusionWithClampMul : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; HSigmoidFusionWithClampMul(); @@ -67,7 +66,7 @@ public: * @ingroup ie_transformation_common_api * @brief HSigmoidFusion transformation replaces a sub-graph (Clamp(x + 3, 0, 6) * / 6) with a HSigmoid op. */ -class ngraph::pass::HSigmoidFusionWithClampDiv: public ngraph::pass::MatcherPass { +class ngraph::pass::HSigmoidFusionWithClampDiv : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; HSigmoidFusionWithClampDiv(); @@ -77,7 +76,7 @@ public: * @ingroup ie_transformation_common_api * @brief HSigmoidFusion transformation replaces various sub-graphs with a HSigmoid op. */ -class ngraph::pass::HSigmoidFusion: public ngraph::pass::GraphRewrite { +class ngraph::pass::HSigmoidFusion : public ngraph::pass::GraphRewrite { public: NGRAPH_RTTI_DECLARATION; HSigmoidFusion() { diff --git a/src/common/transformations/include/transformations/common_optimizations/hswish_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/hswish_fusion.hpp index 769725abca1..68427f19bb0 100644 --- a/src/common/transformations/include/transformations/common_optimizations/hswish_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/hswish_fusion.hpp @@ -5,10 +5,9 @@ #pragma once #include -#include - -#include #include +#include +#include namespace ngraph { namespace pass { @@ -22,12 +21,11 @@ class TRANSFORMATIONS_API HSwishFusionWithClamp; } // namespace pass } // namespace ngraph - /** * @ingroup ie_transformation_common_api * @brief HSwishFusion transformation replaces a sub-graph (x * (min(Relu(x + 3), 6))) / 6 with a HSwish op. */ -class ngraph::pass::HSwishFusionWithReluDiv: public ngraph::pass::MatcherPass { +class ngraph::pass::HSwishFusionWithReluDiv : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; HSwishFusionWithReluDiv(); @@ -37,7 +35,7 @@ public: * @ingroup ie_transformation_common_api * @brief HSwishFusion transformation replaces a sub-graph (x * (min(Relu(x + 3), 6)) * const(1/6) with a HSwish op. */ -class ngraph::pass::HSwishFusionWithReluMul: public ngraph::pass::MatcherPass { +class ngraph::pass::HSwishFusionWithReluMul : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; HSwishFusionWithReluMul(); @@ -47,18 +45,17 @@ public: * @ingroup ie_transformation_common_api * @brief HSwishFusion transformation replaces a sub-graph x * HSigmoid(x) with a HSwish op. */ -class ngraph::pass::HSwishFusionWithHSigmoid: public ngraph::pass::MatcherPass { +class ngraph::pass::HSwishFusionWithHSigmoid : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; HSwishFusionWithHSigmoid(); }; - /** * @ingroup ie_transformation_common_api * @brief HSwishFusion transformation replaces a sub-graph (Clamp(x + 3, 0, 6) * x) with a HSwish * 6. */ -class ngraph::pass::HSwishFusionWithClamp: public ngraph::pass::MatcherPass { +class ngraph::pass::HSwishFusionWithClamp : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; HSwishFusionWithClamp(); @@ -68,7 +65,7 @@ public: * @ingroup ie_transformation_common_api * @brief HSwishFusion transformation replaces various sub-graphs with a HSwish op. */ -class ngraph::pass::HSwishFusion: public ngraph::pass::GraphRewrite { +class ngraph::pass::HSwishFusion : public ngraph::pass::GraphRewrite { public: NGRAPH_RTTI_DECLARATION; HSwishFusion() { diff --git a/src/common/transformations/include/transformations/common_optimizations/interpolate_sequence_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/interpolate_sequence_fusion.hpp index 83268a143d8..7440b4bc2c8 100644 --- a/src/common/transformations/include/transformations/common_optimizations/interpolate_sequence_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/interpolate_sequence_fusion.hpp @@ -4,13 +4,12 @@ #pragma once -#include #include - -#include - #include #include +#include +#include + #include "ngraph/pattern/matcher.hpp" namespace ngraph { diff --git a/src/common/transformations/include/transformations/common_optimizations/leaky_relu_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/leaky_relu_fusion.hpp index 3988166826a..9808cfac046 100644 --- a/src/common/transformations/include/transformations/common_optimizations/leaky_relu_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/leaky_relu_fusion.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - #include +#include +#include namespace ngraph { namespace pass { @@ -25,7 +23,7 @@ class TRANSFORMATIONS_API LeakyReluFusion; * Multiply->Maximum to LeakyRelu */ -class ngraph::pass::LeakyReluFusion: public ngraph::pass::MatcherPass { +class ngraph::pass::LeakyReluFusion : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; LeakyReluFusion(); diff --git a/src/common/transformations/include/transformations/common_optimizations/lin_op_sequence_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/lin_op_sequence_fusion.hpp index 341d84d138f..a7a09a05894 100644 --- a/src/common/transformations/include/transformations/common_optimizations/lin_op_sequence_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/lin_op_sequence_fusion.hpp @@ -5,10 +5,9 @@ #pragma once #include -#include - -#include #include +#include +#include namespace ngraph { namespace pass { @@ -21,19 +20,19 @@ class TRANSFORMATIONS_API MultiplyMultiplyFusion; } // namespace pass } // namespace ngraph -class ngraph::pass::AddMultiplyFusion: public ngraph::pass::MatcherPass { +class ngraph::pass::AddMultiplyFusion : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; AddMultiplyFusion(); }; -class ngraph::pass::AddAddFusion: public ngraph::pass::MatcherPass { +class ngraph::pass::AddAddFusion : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; AddAddFusion(); }; -class ngraph::pass::MultiplyMultiplyFusion: public ngraph::pass::MatcherPass { +class ngraph::pass::MultiplyMultiplyFusion : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; MultiplyMultiplyFusion(); @@ -43,7 +42,7 @@ public: * @ingroup ie_transformation_common_api * @brief LinOpSequenceFusion transformation fuses linear operation sequence. */ -class ngraph::pass::LinOpSequenceFusion: public ngraph::pass::GraphRewrite { +class ngraph::pass::LinOpSequenceFusion : public ngraph::pass::GraphRewrite { public: NGRAPH_RTTI_DECLARATION; LinOpSequenceFusion() { diff --git a/src/common/transformations/include/transformations/common_optimizations/matmul_const_transposes_extraction.hpp b/src/common/transformations/include/transformations/common_optimizations/matmul_const_transposes_extraction.hpp index f528c666e3f..2a451f18a5a 100644 --- a/src/common/transformations/include/transformations/common_optimizations/matmul_const_transposes_extraction.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/matmul_const_transposes_extraction.hpp @@ -4,18 +4,19 @@ #pragma once -#include #include +#include /** * @ingroup ie_transformation_common_api - * @brief Resolves transpose_b key from MatMul operation if corresponding input is constant or FakeQuantize by inserting Transpose + * @brief Resolves transpose_b key from MatMul operation if corresponding input is constant or FakeQuantize by inserting + * Transpose */ namespace ngraph { namespace pass { -class TRANSFORMATIONS_API MatMulConstTransposesExtraction: public MatcherPass { +class TRANSFORMATIONS_API MatMulConstTransposesExtraction : public MatcherPass { public: NGRAPH_RTTI_DECLARATION; MatMulConstTransposesExtraction(); diff --git a/src/common/transformations/include/transformations/common_optimizations/matmul_multiply_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/matmul_multiply_fusion.hpp index 120d7805ba9..921fe8ffbb4 100644 --- a/src/common/transformations/include/transformations/common_optimizations/matmul_multiply_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/matmul_multiply_fusion.hpp @@ -4,9 +4,8 @@ #pragma once -#include - #include +#include namespace ngraph { namespace pass { @@ -57,7 +56,7 @@ class TRANSFORMATIONS_API MatMulMultiplyFusion; * | MatMul | * +--------+ */ -class ngraph::pass::MatMulMultiplyFusion: public ngraph::pass::MatcherPass { +class ngraph::pass::MatMulMultiplyFusion : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; MatMulMultiplyFusion(); diff --git a/src/common/transformations/include/transformations/common_optimizations/mish_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/mish_fusion.hpp index f91581d7714..546cde5a366 100644 --- a/src/common/transformations/include/transformations/common_optimizations/mish_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/mish_fusion.hpp @@ -4,13 +4,12 @@ #pragma once -#include #include - -#include - #include #include +#include +#include + #include "ngraph/pattern/matcher.hpp" namespace ngraph { @@ -26,7 +25,7 @@ class TRANSFORMATIONS_API MishFusion; * @brief MishFusion transformation replaces group of * operations: x * tanh(log(exp(x) + 1)) to Mish op. */ -class ngraph::pass::MishFusion: public ngraph::pass::MatcherPass { +class ngraph::pass::MishFusion : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; MishFusion(); diff --git a/src/common/transformations/include/transformations/common_optimizations/moc_transformations.hpp b/src/common/transformations/include/transformations/common_optimizations/moc_transformations.hpp index 19504b77988..57c3dbcdbb7 100644 --- a/src/common/transformations/include/transformations/common_optimizations/moc_transformations.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/moc_transformations.hpp @@ -5,10 +5,8 @@ #pragma once #include - -#include - #include +#include namespace ngraph { namespace pass { @@ -24,7 +22,7 @@ class TRANSFORMATIONS_API MOCTransformations; * with transformations pipeline but now it remains empty. */ -class ngraph::pass::MOCTransformations: public ngraph::pass::FunctionPass { +class ngraph::pass::MOCTransformations : public ngraph::pass::FunctionPass { bool m_use_shapes; bool m_low_precision_enabled; @@ -38,7 +36,8 @@ public: * low_precision sub-graphs as is. */ explicit MOCTransformations(bool use_shapes, bool low_precision_enabled = true) - : m_use_shapes(use_shapes), m_low_precision_enabled(low_precision_enabled) {} + : m_use_shapes(use_shapes), + m_low_precision_enabled(low_precision_enabled) {} bool run_on_model(const std::shared_ptr& m) override; }; diff --git a/src/common/transformations/include/transformations/common_optimizations/mul_conv_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/mul_conv_fusion.hpp index 14ddb53a782..ca48dd5665a 100644 --- a/src/common/transformations/include/transformations/common_optimizations/mul_conv_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/mul_conv_fusion.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - +#include #include +#include namespace ngraph { namespace pass { @@ -73,31 +71,31 @@ class TRANSFORMATIONS_API MultiplyGroupConvolutionBackpropDataFusion; * Restrictions: * - weights' shape is static * - if the constant input to Multiply has the same rank as 'input', the constant first dimension has to be 1 - * - constant input to Multiply has to be broadcastable to weights when 'Convolution Op' is either Convolution or GroupConvolution - * - shape of a constant input to Multiply has to be in one of following forms: (1), (1, 1, ..., 1), (C, 1, ..., 1), (1, C, 1, ..., 1) - * when 'Convolution Op' is either ConvolutionBackpropData or GroupConvolutionBackpropData + * - constant input to Multiply has to be broadcastable to weights when 'Convolution Op' is either Convolution or + * GroupConvolution + * - shape of a constant input to Multiply has to be in one of following forms: (1), (1, 1, ..., 1), (C, 1, ..., 1), (1, + * C, 1, ..., 1) when 'Convolution Op' is either ConvolutionBackpropData or GroupConvolutionBackpropData */ - -class ngraph::pass::MultiplyConvolutionFusion: public ngraph::pass::MatcherPass { +class ngraph::pass::MultiplyConvolutionFusion : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; MultiplyConvolutionFusion(); }; -class ngraph::pass::MultiplyGroupConvolutionFusion: public ngraph::pass::MatcherPass { +class ngraph::pass::MultiplyGroupConvolutionFusion : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; MultiplyGroupConvolutionFusion(); }; -class ngraph::pass::MultiplyConvolutionBackpropDataFusion: public ngraph::pass::MatcherPass { +class ngraph::pass::MultiplyConvolutionBackpropDataFusion : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; MultiplyConvolutionBackpropDataFusion(); }; -class ngraph::pass::MultiplyGroupConvolutionBackpropDataFusion: public ngraph::pass::MatcherPass { +class ngraph::pass::MultiplyGroupConvolutionBackpropDataFusion : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; MultiplyGroupConvolutionBackpropDataFusion(); diff --git a/src/common/transformations/include/transformations/common_optimizations/mul_fake_quantize_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/mul_fake_quantize_fusion.hpp index d1325633720..e4c5b4fb02c 100644 --- a/src/common/transformations/include/transformations/common_optimizations/mul_fake_quantize_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/mul_fake_quantize_fusion.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - #include +#include +#include namespace ngraph { namespace pass { @@ -26,7 +24,7 @@ class TRANSFORMATIONS_API MulFakeQuantizeFusion; * Restrictions: * - second input to Mul is a Constant */ -class ngraph::pass::MulFakeQuantizeFusion: public ngraph::pass::MatcherPass { +class ngraph::pass::MulFakeQuantizeFusion : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; MulFakeQuantizeFusion(); diff --git a/src/common/transformations/include/transformations/common_optimizations/mvn_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/mvn_fusion.hpp index 82d4c81b43e..07a96f4c1dc 100644 --- a/src/common/transformations/include/transformations/common_optimizations/mvn_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/mvn_fusion.hpp @@ -4,13 +4,12 @@ #pragma once -#include #include - -#include - #include #include +#include +#include + #include "ngraph/pattern/matcher.hpp" namespace ngraph { @@ -37,7 +36,8 @@ public: /** * @ingroup ie_transformation_common_api * @brief MVNFusion transformation replaces group of - * operations: gamma * (x - ReduceMean(x, axes)) / (Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2)) + eps) + beta to MVN op. + * operations: gamma * (x - ReduceMean(x, axes)) / (Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2)) + eps) + beta to MVN + * op. */ class ngraph::pass::MVNFusionWithConstantsInside : public ngraph::pass::MatcherPass { public: @@ -49,7 +49,7 @@ public: * @ingroup ie_transformation_common_api * @brief MVNFusion transformation replaces various sub-graphs with a MVN op. */ -class ngraph::pass::MVNFusion: public ngraph::pass::GraphRewrite { +class ngraph::pass::MVNFusion : public ngraph::pass::GraphRewrite { public: NGRAPH_RTTI_DECLARATION; MVNFusion() { diff --git a/src/common/transformations/include/transformations/common_optimizations/nearest_neighbor_upsampling_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/nearest_neighbor_upsampling_fusion.hpp index c7b5e2ca5b9..a3aa43cec8a 100644 --- a/src/common/transformations/include/transformations/common_optimizations/nearest_neighbor_upsampling_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/nearest_neighbor_upsampling_fusion.hpp @@ -4,13 +4,11 @@ #pragma once -#include #include - -#include - #include #include +#include +#include namespace ngraph { namespace pass { diff --git a/src/common/transformations/include/transformations/common_optimizations/nop_elimination.hpp b/src/common/transformations/include/transformations/common_optimizations/nop_elimination.hpp index fc6350e21e2..280c71d6c75 100644 --- a/src/common/transformations/include/transformations/common_optimizations/nop_elimination.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/nop_elimination.hpp @@ -4,13 +4,11 @@ #pragma once -#include #include - -#include - #include #include +#include +#include namespace ngraph { namespace pass { @@ -32,7 +30,7 @@ class TRANSFORMATIONS_API NopElimination; * @ingroup ie_transformation_common_api * @brief EliminatePad eliminates pad that does nothing */ -class ngraph::pass::EliminatePad: public ngraph::pass::MatcherPass { +class ngraph::pass::EliminatePad : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; EliminatePad(); @@ -42,7 +40,7 @@ public: * @ingroup ie_transformation_common_api * @brief EliminateConvert eliminates convert that does nothing */ -class ngraph::pass::EliminateConvert: public ngraph::pass::MatcherPass { +class ngraph::pass::EliminateConvert : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; EliminateConvert(); @@ -52,7 +50,7 @@ public: * @ingroup ie_transformation_common_api * @brief EliminateConvertNonZero eliminates convert before NonZero */ -class ngraph::pass::EliminateConvertNonZero: public ngraph::pass::MatcherPass { +class ngraph::pass::EliminateConvertNonZero : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; EliminateConvertNonZero(); @@ -62,7 +60,7 @@ public: * @ingroup ie_transformation_common_api * @brief EliminateConcat eliminates concat that does nothing */ -class ngraph::pass::EliminateConcat: public ngraph::pass::MatcherPass { +class ngraph::pass::EliminateConcat : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; EliminateConcat(); @@ -72,7 +70,7 @@ public: * @ingroup ie_transformation_common_api * @brief EliminateSplit eliminates split that does nothing */ -class ngraph::pass::EliminateSplit: public ngraph::pass::MatcherPass { +class ngraph::pass::EliminateSplit : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; EliminateSplit(); @@ -92,7 +90,7 @@ public: * @ingroup ie_transformation_common_api * @brief EliminateTranspose eliminates transpose that does nothing */ -class ngraph::pass::EliminateTranspose: public ngraph::pass::MatcherPass { +class ngraph::pass::EliminateTranspose : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; EliminateTranspose(); @@ -102,13 +100,13 @@ public: * @ingroup ie_transformation_common_api * @brief EliminateEltwise eliminates eltwise ops that do nothing */ -class ngraph::pass::EliminateEltwise: public ngraph::pass::MatcherPass { +class ngraph::pass::EliminateEltwise : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; EliminateEltwise(); }; -class ngraph::pass::NopElimination: public GraphRewrite { +class ngraph::pass::NopElimination : public GraphRewrite { public: NGRAPH_RTTI_DECLARATION; NopElimination(bool use_shape_for_elimination = true); diff --git a/src/common/transformations/include/transformations/common_optimizations/normalize_l2_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/normalize_l2_fusion.hpp index 981cbff71bf..1c1ae3bca11 100644 --- a/src/common/transformations/include/transformations/common_optimizations/normalize_l2_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/normalize_l2_fusion.hpp @@ -4,11 +4,11 @@ #pragma once -#include #include - -#include #include +#include +#include + #include "ngraph/pattern/matcher.hpp" namespace ngraph { @@ -25,7 +25,7 @@ class TRANSFORMATIONS_API NormalizeL2Fusion; * x/(max(sqrt(sum(x[j0, ..., jN]**2), eps)) with a NormalizeL2 op. * x/(add(sqrt(sum(x[j0, ..., jN]**2), eps)) with a NormalizeL2 op. */ -class ngraph::pass::NormalizeL2Fusion: public ngraph::pass::MatcherPass { +class ngraph::pass::NormalizeL2Fusion : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; NormalizeL2Fusion(); diff --git a/src/common/transformations/include/transformations/common_optimizations/optimize_strided_slice.hpp b/src/common/transformations/include/transformations/common_optimizations/optimize_strided_slice.hpp index 5c8c075c407..2d249da957a 100644 --- a/src/common/transformations/include/transformations/common_optimizations/optimize_strided_slice.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/optimize_strided_slice.hpp @@ -4,15 +4,13 @@ #pragma once -#include #include - -#include - #include #include #include #include +#include +#include namespace ngraph { namespace pass { @@ -25,13 +23,12 @@ class TRANSFORMATIONS_API GroupedStridedSliceOptimizer; } // namespace pass } // namespace ngraph - /** * @ingroup ie_transformation_common_api * @brief UselessStridedSliceEraser transformation removes StridedSlice operations * with equal input and output shapes. */ -class ngraph::pass::UselessStridedSliceEraser: public ngraph::pass::FunctionPass { +class ngraph::pass::UselessStridedSliceEraser : public ngraph::pass::FunctionPass { public: NGRAPH_RTTI_DECLARATION; bool run_on_model(const std::shared_ptr& m) override; @@ -43,7 +40,7 @@ public: * operations with first StridedSlice in this group. All SrtideSlices in this group * must be equal and consume the same output port. */ -class ngraph::pass::SharedStridedSliceEraser: public ngraph::pass::FunctionPass { +class ngraph::pass::SharedStridedSliceEraser : public ngraph::pass::FunctionPass { public: NGRAPH_RTTI_DECLARATION; bool run_on_model(const std::shared_ptr& m) override; @@ -55,7 +52,7 @@ public: * operations with VariadicSplit. All StridedSlice operations must slice data * with the same axis and stride = 1. */ -class ngraph::pass::GroupedStridedSliceOptimizer: public ngraph::pass::FunctionPass { +class ngraph::pass::GroupedStridedSliceOptimizer : public ngraph::pass::FunctionPass { public: NGRAPH_RTTI_DECLARATION; bool run_on_model(const std::shared_ptr& m) override; @@ -66,7 +63,7 @@ public: * @brief StridedSliceOptimization transformation executes all transformations * related to StridedSlice optimizations. */ -class ngraph::pass::StridedSliceOptimization: public ngraph::pass::FunctionPass { +class ngraph::pass::StridedSliceOptimization : public ngraph::pass::FunctionPass { public: StridedSliceOptimization(bool use_shapes = true); diff --git a/src/common/transformations/include/transformations/common_optimizations/pad_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/pad_fusion.hpp index ac93ae23cfe..82c1a09ec4e 100644 --- a/src/common/transformations/include/transformations/common_optimizations/pad_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/pad_fusion.hpp @@ -4,9 +4,8 @@ #pragma once -#include - #include +#include namespace ngraph { namespace pass { @@ -29,7 +28,7 @@ class TRANSFORMATIONS_API PadFusionGroupConvolutionBackpropData; * - pad value is 0 * - exclude_pad in AvgPool is set to false or pads_begin, pads_end are set to zero */ -class ngraph::pass::PadFusionAvgPool: public ngraph::pass::MatcherPass { +class ngraph::pass::PadFusionAvgPool : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; PadFusionAvgPool(); @@ -42,7 +41,7 @@ public: * - pad mode is op::PadMode::CONSTANT * - pad value is 0 */ -class ngraph::pass::PadFusionConvolution: public ngraph::pass::MatcherPass { +class ngraph::pass::PadFusionConvolution : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; PadFusionConvolution(); @@ -56,7 +55,7 @@ public: * - pad value is 0 * - pads in ConvolutionBackpropData are greater than pads in Pad node */ -class ngraph::pass::PadFusionConvolutionBackpropData: public ngraph::pass::MatcherPass { +class ngraph::pass::PadFusionConvolutionBackpropData : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; PadFusionConvolutionBackpropData(); @@ -69,7 +68,7 @@ public: * - pad mode is op::PadMode::CONSTANT * - pad value is 0 */ -class ngraph::pass::PadFusionGroupConvolution: public ngraph::pass::MatcherPass { +class ngraph::pass::PadFusionGroupConvolution : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; PadFusionGroupConvolution(); @@ -83,13 +82,13 @@ public: * - pad value is 0 * - pads in GroupConvolutionBackpropData are greater than pads in Pad node */ -class ngraph::pass::PadFusionGroupConvolutionBackpropData: public ngraph::pass::MatcherPass { +class ngraph::pass::PadFusionGroupConvolutionBackpropData : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; PadFusionGroupConvolutionBackpropData(); }; -class ngraph::pass::PadFusion: public ngraph::pass::GraphRewrite { +class ngraph::pass::PadFusion : public ngraph::pass::GraphRewrite { public: NGRAPH_RTTI_DECLARATION; PadFusion() { diff --git a/src/common/transformations/include/transformations/common_optimizations/pull_transpose_through_fq.hpp b/src/common/transformations/include/transformations/common_optimizations/pull_transpose_through_fq.hpp index ca06de1c1d3..529cdeeaebd 100644 --- a/src/common/transformations/include/transformations/common_optimizations/pull_transpose_through_fq.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/pull_transpose_through_fq.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - #include +#include +#include namespace ngraph { namespace pass { @@ -19,7 +17,7 @@ class TRANSFORMATIONS_API PullTransposeThroughFQUp; } // namespace pass } // namespace ngraph -class ngraph::pass::PullTransposeThroughFQUp: public ngraph::pass::MatcherPass { +class ngraph::pass::PullTransposeThroughFQUp : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; PullTransposeThroughFQUp(); diff --git a/src/common/transformations/include/transformations/common_optimizations/relu_fake_quantize_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/relu_fake_quantize_fusion.hpp index 5d7261ce00c..64044be125b 100644 --- a/src/common/transformations/include/transformations/common_optimizations/relu_fake_quantize_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/relu_fake_quantize_fusion.hpp @@ -4,9 +4,8 @@ #pragma once -#include - #include +#include namespace ngraph { namespace pass { @@ -24,7 +23,7 @@ class TRANSFORMATIONS_API ReluFakeQuantizeFusion; * - 'input_low' has non negative values */ -class ngraph::pass::ReluFakeQuantizeFusion: public ngraph::pass::MatcherPass { +class ngraph::pass::ReluFakeQuantizeFusion : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ReluFakeQuantizeFusion(); diff --git a/src/common/transformations/include/transformations/common_optimizations/remove_concat_zero_dim_input.hpp b/src/common/transformations/include/transformations/common_optimizations/remove_concat_zero_dim_input.hpp index c323dad169b..8c66d608034 100644 --- a/src/common/transformations/include/transformations/common_optimizations/remove_concat_zero_dim_input.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/remove_concat_zero_dim_input.hpp @@ -4,11 +4,10 @@ #pragma once -#include #include - -#include #include +#include +#include namespace ov { namespace pass { @@ -24,7 +23,7 @@ class TRANSFORMATIONS_API RemoveConcatZeroDimInput; * removes input of Concat if the tensor size is equal to 0 */ -class ov::pass::RemoveConcatZeroDimInput: public ov::pass::MatcherPass { +class ov::pass::RemoveConcatZeroDimInput : public ov::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; RemoveConcatZeroDimInput(); diff --git a/src/common/transformations/include/transformations/common_optimizations/remove_filtering_boxes_by_size.hpp b/src/common/transformations/include/transformations/common_optimizations/remove_filtering_boxes_by_size.hpp index 0de47638899..7372684ca73 100644 --- a/src/common/transformations/include/transformations/common_optimizations/remove_filtering_boxes_by_size.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/remove_filtering_boxes_by_size.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - #include +#include +#include namespace ngraph { namespace pass { @@ -20,13 +18,13 @@ class TRANSFORMATIONS_API RemoveFilteringBoxesBySize; } // namespace pass } // namespace ngraph -class ngraph::pass::FuseFilteringBoxesBySize: public ngraph::pass::GraphRewrite { +class ngraph::pass::FuseFilteringBoxesBySize : public ngraph::pass::GraphRewrite { public: NGRAPH_RTTI_DECLARATION; FuseFilteringBoxesBySize(); }; -class ngraph::pass::RemoveFilteringBoxesBySize: public ngraph::pass::MatcherPass { +class ngraph::pass::RemoveFilteringBoxesBySize : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; RemoveFilteringBoxesBySize(); diff --git a/src/common/transformations/include/transformations/common_optimizations/remove_multi_subgraph_op_dangling_params.hpp b/src/common/transformations/include/transformations/common_optimizations/remove_multi_subgraph_op_dangling_params.hpp index 0be7ef92b16..a0154cad5ee 100644 --- a/src/common/transformations/include/transformations/common_optimizations/remove_multi_subgraph_op_dangling_params.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/remove_multi_subgraph_op_dangling_params.hpp @@ -4,11 +4,10 @@ #pragma once -#include #include - -#include #include +#include +#include namespace ov { namespace pass { @@ -25,7 +24,7 @@ class TRANSFORMATIONS_API RemoveMultiSubGraphOpDanglingParams; * in the bodies of a MultiSubGraphOp */ -class ov::pass::RemoveMultiSubGraphOpDanglingParams: public ov::pass::MatcherPass { +class ov::pass::RemoveMultiSubGraphOpDanglingParams : public ov::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; RemoveMultiSubGraphOpDanglingParams(); diff --git a/src/common/transformations/include/transformations/common_optimizations/reshape_sequence_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/reshape_sequence_fusion.hpp index 4d54950fed4..cc9aaf7d096 100644 --- a/src/common/transformations/include/transformations/common_optimizations/reshape_sequence_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/reshape_sequence_fusion.hpp @@ -4,9 +4,8 @@ #pragma once -#include - #include +#include namespace ngraph { namespace pass { @@ -18,10 +17,11 @@ class TRANSFORMATIONS_API ReshapeSequenceFusion; /** * @ingroup ie_transformation_common_api - * @brief ReshapeSequenceFusion fuses sequence of Reshape operation into single Reshape or eliminates full redundant sequence + * @brief ReshapeSequenceFusion fuses sequence of Reshape operation into single Reshape or eliminates full redundant + * sequence */ -class ngraph::pass::ReshapeSequenceFusion: public ngraph::pass::MatcherPass { +class ngraph::pass::ReshapeSequenceFusion : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ReshapeSequenceFusion(bool use_shape_for_elimination = true); diff --git a/src/common/transformations/include/transformations/common_optimizations/ric_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/ric_fusion.hpp index 3f30fde5301..2d5f38c6a0f 100644 --- a/src/common/transformations/include/transformations/common_optimizations/ric_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/ric_fusion.hpp @@ -4,11 +4,10 @@ #pragma once -#include - -#include -#include #include +#include +#include +#include namespace ngraph { namespace pass { @@ -23,8 +22,8 @@ class TRANSFORMATIONS_API ReverseInputChannelsFusion; * @brief ReverseInputChannelsFusion */ -class ngraph::pass::ReverseInputChannelsFusion: public ov::pass::ModelPass { +class ngraph::pass::ReverseInputChannelsFusion : public ov::pass::ModelPass { public: NGRAPH_RTTI_DECLARATION; - bool run_on_model(const std::shared_ptr &) override; + bool run_on_model(const std::shared_ptr&) override; }; diff --git a/src/common/transformations/include/transformations/common_optimizations/shuffle_channels_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/shuffle_channels_fusion.hpp index 153a2a48c5d..ae89107a676 100644 --- a/src/common/transformations/include/transformations/common_optimizations/shuffle_channels_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/shuffle_channels_fusion.hpp @@ -4,17 +4,15 @@ #pragma once -#include #include - -#include - #include +#include +#include namespace ngraph { namespace pass { - class TRANSFORMATIONS_API ShuffleChannelsFusion; +class TRANSFORMATIONS_API ShuffleChannelsFusion; } // namespace pass } // namespace ngraph diff --git a/src/common/transformations/include/transformations/common_optimizations/simplify_shape_of_sub_graph.hpp b/src/common/transformations/include/transformations/common_optimizations/simplify_shape_of_sub_graph.hpp index 72c2925fffb..8ee4432499d 100644 --- a/src/common/transformations/include/transformations/common_optimizations/simplify_shape_of_sub_graph.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/simplify_shape_of_sub_graph.hpp @@ -4,15 +4,13 @@ #pragma once -#include #include - -#include - #include #include #include #include +#include +#include namespace ngraph { namespace pass { @@ -27,14 +25,13 @@ class TRANSFORMATIONS_API SimplifySecondInputOfReshape; } // namespace pass } // namespace ngraph - /** * @ingroup ie_transformation_common_api * @brief SharedShapeOf transformation replaces group of ShapeOf * operations with the first ShapeOf in this group. All ShapeOfs in this group * must be equal and consume the same output port. */ -class ngraph::pass::SharedShapeOf: public ngraph::pass::FunctionPass { +class ngraph::pass::SharedShapeOf : public ngraph::pass::FunctionPass { public: NGRAPH_RTTI_DECLARATION; bool run_on_model(const std::shared_ptr& m) override; @@ -46,7 +43,7 @@ public: * operations with the first Gather in this group and updated indices input * in case all Gathers in the group are consumed by the same Concat in incremental order. */ -class ngraph::pass::GroupedGatherElimination: public ngraph::pass::MatcherPass { +class ngraph::pass::GroupedGatherElimination : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; GroupedGatherElimination(); @@ -56,7 +53,7 @@ public: * @ingroup ie_transformation_common_api * @brief SimplifyShapeOfSubGraph transformation runs specific optimizations of shape sub-graphs */ -class ngraph::pass::SimplifyShapeOfSubGraph: public ngraph::pass::FunctionPass { +class ngraph::pass::SimplifyShapeOfSubGraph : public ngraph::pass::FunctionPass { public: NGRAPH_RTTI_DECLARATION; bool run_on_model(const std::shared_ptr& m) override; @@ -66,7 +63,7 @@ public: * @ingroup ie_transformation_common_api * @brief GatherNopElimination transformation optimizes out useless Gather operations */ -class ngraph::pass::GatherNopElimination: public ngraph::pass::MatcherPass { +class ngraph::pass::GatherNopElimination : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; GatherNopElimination(); @@ -78,7 +75,7 @@ public: * Other cases into Concat of shapeof/gather(data) + shapeof(indices) transformation optimizes out * useless Gather operations */ -class ngraph::pass::SimplifyGatherShapeOf: public ngraph::pass::MatcherPass { +class ngraph::pass::SimplifyGatherShapeOf : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; SimplifyGatherShapeOf(); diff --git a/src/common/transformations/include/transformations/common_optimizations/skip_gather_before_transpose_and_reshape.hpp b/src/common/transformations/include/transformations/common_optimizations/skip_gather_before_transpose_and_reshape.hpp index 1259f96def6..5de5c88fba7 100644 --- a/src/common/transformations/include/transformations/common_optimizations/skip_gather_before_transpose_and_reshape.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/skip_gather_before_transpose_and_reshape.hpp @@ -19,7 +19,7 @@ class TRANSFORMATIONS_API SkipGatherBeforeTransposeAndReshape; /** * @ingroup ie_transformation_common_api - * @brief SkipGatherBeforeTransposeAndReshape transformation removes Gather from the Gather->Transpose->Reshape sequence + * @brief SkipGatherBeforeTransposeAndReshape transformation removes Gather from the Gather->Transpose->Reshape sequence * in case when input has batch=1 and gather has axis=0 and indices={0}. * Also, this transformation corrects a transpose constant to save semantic. */ diff --git a/src/common/transformations/include/transformations/common_optimizations/softmax_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/softmax_fusion.hpp index a9b9bcddc96..01e2741b598 100644 --- a/src/common/transformations/include/transformations/common_optimizations/softmax_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/softmax_fusion.hpp @@ -4,9 +4,8 @@ #pragma once -#include - #include +#include namespace ngraph { namespace pass { @@ -70,7 +69,7 @@ class TRANSFORMATIONS_API SoftmaxFusion; * - ReduceMax and ReduceSum axes must be scalar constants and they have to point to the same axis */ -class ngraph::pass::SoftmaxFusion: public ngraph::pass::MatcherPass { +class ngraph::pass::SoftmaxFusion : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; SoftmaxFusion(); diff --git a/src/common/transformations/include/transformations/common_optimizations/softplus_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/softplus_fusion.hpp index 8a2e42815eb..bd3fe1ed1e5 100644 --- a/src/common/transformations/include/transformations/common_optimizations/softplus_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/softplus_fusion.hpp @@ -4,11 +4,10 @@ #pragma once -#include #include - -#include #include +#include +#include namespace ngraph { namespace pass { @@ -23,7 +22,7 @@ class TRANSFORMATIONS_API SoftPlusFusion; * @brief SoftPlusFusion transformation replaces group of * operations: log(exp(x) + 1) to SoftPlus op. */ -class ngraph::pass::SoftPlusFusion: public ngraph::pass::MatcherPass { +class ngraph::pass::SoftPlusFusion : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; SoftPlusFusion(); diff --git a/src/common/transformations/include/transformations/common_optimizations/softplus_to_mish_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/softplus_to_mish_fusion.hpp index 400ab8d3335..2884df168e1 100644 --- a/src/common/transformations/include/transformations/common_optimizations/softplus_to_mish_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/softplus_to_mish_fusion.hpp @@ -4,13 +4,12 @@ #pragma once -#include #include - -#include - #include #include +#include +#include + #include "ngraph/pattern/matcher.hpp" namespace ngraph { @@ -26,7 +25,7 @@ class TRANSFORMATIONS_API SoftPlusToMishFusion; * @brief SoftPlusToMishFusion transformation replaces group of * operations: x * tanh(softplus(x)) to Mish op. */ -class ngraph::pass::SoftPlusToMishFusion: public ngraph::pass::MatcherPass { +class ngraph::pass::SoftPlusToMishFusion : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; SoftPlusToMishFusion(); diff --git a/src/common/transformations/include/transformations/common_optimizations/space_to_batch_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/space_to_batch_fusion.hpp index eff278cd737..a784f68cc50 100644 --- a/src/common/transformations/include/transformations/common_optimizations/space_to_batch_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/space_to_batch_fusion.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - #include +#include +#include namespace ngraph { namespace pass { @@ -31,7 +29,7 @@ class TRANSFORMATIONS_API SpaceToBatchFusion; * - SpaceToDepthMode must be BLOCKS_FIRST */ -class ngraph::pass::SpaceToBatchFusion: public ngraph::pass::MatcherPass { +class ngraph::pass::SpaceToBatchFusion : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; SpaceToBatchFusion(); diff --git a/src/common/transformations/include/transformations/common_optimizations/split_concat_pair_to_interpolate_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/split_concat_pair_to_interpolate_fusion.hpp index 09b15ceb2fc..b49e1e5485c 100644 --- a/src/common/transformations/include/transformations/common_optimizations/split_concat_pair_to_interpolate_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/split_concat_pair_to_interpolate_fusion.hpp @@ -4,13 +4,12 @@ #pragma once -#include #include - -#include - #include #include +#include +#include + #include "ngraph/pattern/matcher.hpp" namespace ngraph { diff --git a/src/common/transformations/include/transformations/common_optimizations/split_squeeze_concat_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/split_squeeze_concat_fusion.hpp index a140df729a2..91ade68c8d7 100644 --- a/src/common/transformations/include/transformations/common_optimizations/split_squeeze_concat_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/split_squeeze_concat_fusion.hpp @@ -4,13 +4,12 @@ #pragma once -#include #include - -#include - #include #include +#include +#include + #include "ngraph/pattern/matcher.hpp" namespace ngraph { diff --git a/src/common/transformations/include/transformations/common_optimizations/strides_optimization.hpp b/src/common/transformations/include/transformations/common_optimizations/strides_optimization.hpp index 6ccdaff3510..9aa7ec677f6 100644 --- a/src/common/transformations/include/transformations/common_optimizations/strides_optimization.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/strides_optimization.hpp @@ -5,10 +5,10 @@ #pragma once #include -#include -#include -#include #include +#include +#include +#include namespace ngraph { namespace pass { @@ -27,7 +27,7 @@ class TRANSFORMATIONS_API StridesOptimization; * or inserts pooling between current node and its consumers if the consumers have different StridesProp attributes. * Strides can be propagated if Convolution kernel is {1, 1, ...} */ -class ngraph::pass::ConvStridesPropagation: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvStridesPropagation : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvStridesPropagation(); @@ -35,10 +35,11 @@ public: /** * @ingroup ie_transformation_common_api - * @brief SupportedNodesStridesPropagation either propagates stride (greater than 1) from current node up through the graph - * or inserts pooling between current node and its consumers if the consumers have different StridesProp attributes. + * @brief SupportedNodesStridesPropagation either propagates stride (greater than 1) from current node up through the + * graph or inserts pooling between current node and its consumers if the consumers have different StridesProp + * attributes. */ -class ngraph::pass::SupportedNodesStridesPropagation: public ngraph::pass::MatcherPass { +class ngraph::pass::SupportedNodesStridesPropagation : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; SupportedNodesStridesPropagation(); @@ -49,7 +50,7 @@ public: * @brief UnsupportedNodesStridesPropagation inserts pooling between current node and its consumers * if the consumers have different StridesProp attributes. */ -class ngraph::pass::UnsupportedNodesStridesPropagation: public ngraph::pass::MatcherPass { +class ngraph::pass::UnsupportedNodesStridesPropagation : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; UnsupportedNodesStridesPropagation(); @@ -57,9 +58,10 @@ public: /** * @ingroup ie_transformation_common_api - * @brief StridesOptimization transformation works backward on function and propagates strides up through the graph if possible + * @brief StridesOptimization transformation works backward on function and propagates strides up through the graph if + * possible */ -class ngraph::pass::StridesOptimization: public ngraph::pass::BackwardGraphRewrite { +class ngraph::pass::StridesOptimization : public ngraph::pass::BackwardGraphRewrite { public: NGRAPH_RTTI_DECLARATION; StridesOptimization() { diff --git a/src/common/transformations/include/transformations/common_optimizations/swish_fusion.hpp b/src/common/transformations/include/transformations/common_optimizations/swish_fusion.hpp index 8506ce9ed84..5feaff7e376 100644 --- a/src/common/transformations/include/transformations/common_optimizations/swish_fusion.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/swish_fusion.hpp @@ -5,10 +5,9 @@ #pragma once #include -#include - -#include #include +#include +#include namespace ngraph { namespace pass { @@ -26,7 +25,7 @@ class TRANSFORMATIONS_API SwishFusionWithoutBeta; * @ingroup ie_transformation_common_api * @brief SwishFusionWithSigmoid replaces a sub-graphs x * Sigmoid(x) with a Swish op. */ -class ngraph::pass::SwishFusionWithSigmoid: public ngraph::pass::MatcherPass { +class ngraph::pass::SwishFusionWithSigmoid : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; SwishFusionWithSigmoid(); @@ -36,7 +35,7 @@ public: * @ingroup ie_transformation_common_api * @brief SwishFusionWithSigmoid replaces a sub-graphs x * Sigmoid(x * beta) with a Swish op. */ -class ngraph::pass::SwishFusionWithSigmoidWithBeta: public ngraph::pass::MatcherPass { +class ngraph::pass::SwishFusionWithSigmoidWithBeta : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; SwishFusionWithSigmoidWithBeta(); @@ -46,7 +45,7 @@ public: * @ingroup ie_transformation_common_api * @brief SwishFusionWithSigmoid replaces a sub-graphs x / (1.0 + exp(-x * beta)) with a Swish op. */ -class ngraph::pass::SwishFusionWithBeta: public ngraph::pass::MatcherPass { +class ngraph::pass::SwishFusionWithBeta : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; SwishFusionWithBeta(); @@ -56,7 +55,7 @@ public: * @ingroup ie_transformation_common_api * @brief SwishFusionWithSigmoid replaces a sub-graphs x / (1.0 + exp(-x)) with a Swish op. */ -class ngraph::pass::SwishFusionWithoutBeta: public ngraph::pass::MatcherPass { +class ngraph::pass::SwishFusionWithoutBeta : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; SwishFusionWithoutBeta(); @@ -66,7 +65,7 @@ public: * @ingroup ie_transformation_common_api * @brief SwishFusion transformation replaces various sub-graphs with a Swish op. */ -class ngraph::pass::SwishFusion: public ngraph::pass::GraphRewrite { +class ngraph::pass::SwishFusion : public ngraph::pass::GraphRewrite { public: NGRAPH_RTTI_DECLARATION; SwishFusion() { diff --git a/src/common/transformations/include/transformations/common_optimizations/transpose_reshape_elimination_for_matmul.hpp b/src/common/transformations/include/transformations/common_optimizations/transpose_reshape_elimination_for_matmul.hpp index abf0fb89ac9..5f63b7f1fa3 100644 --- a/src/common/transformations/include/transformations/common_optimizations/transpose_reshape_elimination_for_matmul.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/transpose_reshape_elimination_for_matmul.hpp @@ -4,12 +4,11 @@ #pragma once -#include #include - -#include "transformations_visibility.hpp" +#include #include "ngraph/pass/graph_rewrite.hpp" +#include "transformations_visibility.hpp" namespace ngraph { namespace pass { @@ -25,7 +24,7 @@ class TRANSFORMATIONS_API TransposeReshapeEliminationForMatmul; * align input and output dimension ranks before second MatMul input and after MatMul output * (for example, after Einsum Decomposition inside TensorFlow 1 and nGraph EinsumDecomposition transformation) */ -class ngraph::pass::TransposeReshapeEliminationForMatmul: public ngraph::pass::MatcherPass { +class ngraph::pass::TransposeReshapeEliminationForMatmul : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; TransposeReshapeEliminationForMatmul(); diff --git a/src/common/transformations/include/transformations/common_optimizations/transpose_sinking.hpp b/src/common/transformations/include/transformations/common_optimizations/transpose_sinking.hpp index f0aeabbc01f..2ccc8a06ddd 100644 --- a/src/common/transformations/include/transformations/common_optimizations/transpose_sinking.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/transpose_sinking.hpp @@ -4,13 +4,12 @@ #pragma once -#include #include - -#include - #include #include +#include +#include + #include "ngraph/pattern/matcher.hpp" namespace ngraph { @@ -38,7 +37,8 @@ public: /** * @ingroup ie_transformation_common_api - * @brief TransposeFQReduction transformation sinks Transpose through FakeQuantize in case it is followed by reduction or squeeze + * @brief TransposeFQReduction transformation sinks Transpose through FakeQuantize in case it is followed by reduction + * or squeeze */ class ngraph::pass::TransposeFQReduction : public ngraph::pass::MatcherPass { public: @@ -68,8 +68,8 @@ public: /** * @ingroup ie_transformation_common_api - * @brief TransposeFuse transformation eliminates 2 consequtive Transposes if they result in no changes to input or fuses them - * to single Transpose if input gets changed + * @brief TransposeFuse transformation eliminates 2 consequtive Transposes if they result in no changes to input or + * fuses them to single Transpose if input gets changed */ class ngraph::pass::TransposeFuse : public ngraph::pass::MatcherPass { public: @@ -81,7 +81,7 @@ public: * @ingroup ie_transformation_common_api * @brief TransposeSinking transformation sinks Transposes through known operations */ -class ngraph::pass::TransposeSinking: public ngraph::pass::GraphRewrite { +class ngraph::pass::TransposeSinking : public ngraph::pass::GraphRewrite { public: NGRAPH_RTTI_DECLARATION; TransposeSinking() { diff --git a/src/common/transformations/include/transformations/common_optimizations/transpose_to_reshape.hpp b/src/common/transformations/include/transformations/common_optimizations/transpose_to_reshape.hpp index c71b8269321..db2fc8bda6d 100644 --- a/src/common/transformations/include/transformations/common_optimizations/transpose_to_reshape.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/transpose_to_reshape.hpp @@ -4,13 +4,12 @@ #pragma once -#include #include - -#include - #include #include +#include +#include + #include "ngraph/pattern/matcher.hpp" namespace ngraph { diff --git a/src/common/transformations/include/transformations/common_optimizations/weights_dequantize_to_fake_quantize.hpp b/src/common/transformations/include/transformations/common_optimizations/weights_dequantize_to_fake_quantize.hpp index 68913c46355..37970157474 100644 --- a/src/common/transformations/include/transformations/common_optimizations/weights_dequantize_to_fake_quantize.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/weights_dequantize_to_fake_quantize.hpp @@ -4,11 +4,10 @@ #pragma once -#include #include - -#include #include +#include +#include namespace ngraph { namespace pass { @@ -26,7 +25,7 @@ class TRANSFORMATIONS_API WeightsDequantizeToFakeQuantize; * Constant (i8) -> Convert (to fp) -> FakeQuantize -> * deducing levels and FakeQuantize limits according to actual values in the weights Constant */ -class ngraph::pass::WeightsDequantizeToFakeQuantize: public ngraph::pass::MatcherPass { +class ngraph::pass::WeightsDequantizeToFakeQuantize : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; WeightsDequantizeToFakeQuantize(); diff --git a/src/common/transformations/include/transformations/common_optimizations/wrap_interpolate_into_transposes.hpp b/src/common/transformations/include/transformations/common_optimizations/wrap_interpolate_into_transposes.hpp index 5b6e5da2555..445aa745baa 100644 --- a/src/common/transformations/include/transformations/common_optimizations/wrap_interpolate_into_transposes.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/wrap_interpolate_into_transposes.hpp @@ -4,11 +4,10 @@ #pragma once -#include #include - -#include #include +#include +#include namespace ngraph { namespace pass { @@ -33,7 +32,7 @@ class TRANSFORMATIONS_API WrapInterpolateIntoTransposes; * with respect to spatial dimensions, but TensorFlow frontend gives Interpolate with * axes {1, 2} for 4D tensors. */ -class ngraph::pass::WrapInterpolateIntoTransposes: public ngraph::pass::MatcherPass { +class ngraph::pass::WrapInterpolateIntoTransposes : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; WrapInterpolateIntoTransposes(); diff --git a/src/common/transformations/include/transformations/control_flow/unroll_if.hpp b/src/common/transformations/include/transformations/control_flow/unroll_if.hpp index 7fb5840dc29..fbc5ddbe405 100644 --- a/src/common/transformations/include/transformations/control_flow/unroll_if.hpp +++ b/src/common/transformations/include/transformations/control_flow/unroll_if.hpp @@ -15,12 +15,14 @@ class TRANSFORMATIONS_API UnrollIf; } // namespace pass } // namespace ngraph +// clang-format off /** * @ingroup ie_transformation_common_api * @brief The transformation replaces 'If' operations with one of the internal functions (bodies) if the provided condition is constant. * The condition is true: 'If' op is replaced with then_body * The condition is false 'If' op is replaced with else_body */ +// clang-format on class ngraph::pass::UnrollIf : public ngraph::pass::FunctionPass { public: diff --git a/src/common/transformations/include/transformations/control_flow/unroll_tensor_iterator.hpp b/src/common/transformations/include/transformations/control_flow/unroll_tensor_iterator.hpp index 7b80cb145f2..055c41cf805 100644 --- a/src/common/transformations/include/transformations/control_flow/unroll_tensor_iterator.hpp +++ b/src/common/transformations/include/transformations/control_flow/unroll_tensor_iterator.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - #include +#include +#include namespace ngraph { namespace pass { @@ -27,7 +25,7 @@ class TRANSFORMATIONS_API UnrollTensorIterator; * are added to the network. */ -class ngraph::pass::UnrollTensorIterator: public ngraph::pass::FunctionPass { +class ngraph::pass::UnrollTensorIterator : public ngraph::pass::FunctionPass { public: NGRAPH_RTTI_DECLARATION; bool run_on_model(const std::shared_ptr& m) override; diff --git a/src/common/transformations/include/transformations/convert_precision.hpp b/src/common/transformations/include/transformations/convert_precision.hpp index 595b5eb6850..f4634e0143c 100644 --- a/src/common/transformations/include/transformations/convert_precision.hpp +++ b/src/common/transformations/include/transformations/convert_precision.hpp @@ -4,19 +4,16 @@ #pragma once -#include -#include #include -#include - -#include - -#include +#include #include -#include -#include #include - +#include +#include +#include +#include +#include +#include namespace ngraph { namespace pass { @@ -71,23 +68,28 @@ class NGRAPH_API ConvertPrecision; * LessEqual */ -using type_to_fuse_map = std::unordered_map&, ngraph::element::Type, size_t idx)>>; +using type_to_fuse_map = + std::unordered_map&, ngraph::element::Type, size_t idx)>>; using precisions_array = std::vector>; class ngraph::pass::ConvertPrecision : public ngraph::pass::FunctionPass { public: NGRAPH_RTTI_DECLARATION; - ConvertPrecision(ngraph::element::Type_t from, ngraph::element::Type_t to, type_to_fuse_map additional_type_to_fuse_map = {}) + ConvertPrecision(ngraph::element::Type_t from, + ngraph::element::Type_t to, + type_to_fuse_map additional_type_to_fuse_map = {}) : FunctionPass(), - m_precisions(precisions_array {{ from, to }}), - m_additional_type_to_fuse_map(additional_type_to_fuse_map) {} + m_precisions(precisions_array{{from, to}}), + m_additional_type_to_fuse_map(additional_type_to_fuse_map) {} - ConvertPrecision(const precisions_array& precisions, const type_to_fuse_map & additional_type_to_fuse_map = {}) + ConvertPrecision(const precisions_array& precisions, const type_to_fuse_map& additional_type_to_fuse_map = {}) : FunctionPass(), - m_precisions(precisions), - m_additional_type_to_fuse_map(additional_type_to_fuse_map) {} + m_precisions(precisions), + m_additional_type_to_fuse_map(additional_type_to_fuse_map) {} bool run_on_model(const std::shared_ptr& m) override; + private: precisions_array m_precisions; type_to_fuse_map m_additional_type_to_fuse_map; diff --git a/src/common/transformations/include/transformations/disable_decompression_convert_constant_folding.hpp b/src/common/transformations/include/transformations/disable_decompression_convert_constant_folding.hpp index e30e2859421..46698e60ab7 100644 --- a/src/common/transformations/include/transformations/disable_decompression_convert_constant_folding.hpp +++ b/src/common/transformations/include/transformations/disable_decompression_convert_constant_folding.hpp @@ -4,8 +4,8 @@ #pragma once -#include "transformations_visibility.hpp" #include "openvino/pass/graph_rewrite.hpp" +#include "transformations_visibility.hpp" namespace ov { namespace pass { diff --git a/src/common/transformations/include/transformations/fix_rt_info.hpp b/src/common/transformations/include/transformations/fix_rt_info.hpp index 4b5a2a4d1b5..fcc1a82ae83 100644 --- a/src/common/transformations/include/transformations/fix_rt_info.hpp +++ b/src/common/transformations/include/transformations/fix_rt_info.hpp @@ -9,10 +9,9 @@ * @file init_node_info.hpp */ -#include #include - #include +#include /** * @brief ngraph namespace @@ -37,7 +36,7 @@ class NGRAPH_API FixRtInfo; * * Used to extract runtime attributes from shared pointer to `ov::RuntimeAttributeWrapper` to standard or trivial types */ -class ngraph::pass::FixRtInfo: public ngraph::pass::FunctionPass { +class ngraph::pass::FixRtInfo : public ngraph::pass::FunctionPass { public: NGRAPH_RTTI_DECLARATION; bool run_on_model(const std::shared_ptr& m) override; diff --git a/src/common/transformations/include/transformations/init_node_info.hpp b/src/common/transformations/include/transformations/init_node_info.hpp index 26ad8ef93e0..0ed26da0b49 100644 --- a/src/common/transformations/include/transformations/init_node_info.hpp +++ b/src/common/transformations/include/transformations/init_node_info.hpp @@ -9,10 +9,9 @@ * @file init_node_info.hpp */ -#include #include - #include +#include /** * @brief ngraph namespace @@ -32,14 +31,14 @@ class NGRAPH_API InitNodeInfo; /** * @ingroup ie_transformation_common_api * @brief InitNodeInfo transformation helps to set runtime info attributes in a single place. - * + * * Every runtime info attribute that needs to be initialized should be registered * in run_on_function method. Also do not forget to override init methods for registered * attribute. * This transformations should be called first in transformation pipeline. If attribute was * already set initialization will be skipped for this node. */ -class ngraph::pass::InitNodeInfo: public ngraph::pass::FunctionPass { +class ngraph::pass::InitNodeInfo : public ngraph::pass::FunctionPass { public: NGRAPH_RTTI_DECLARATION; bool run_on_model(const std::shared_ptr& m) override; diff --git a/src/common/transformations/include/transformations/low_precision/disable_convert_constant_folding_on_const_path.hpp b/src/common/transformations/include/transformations/low_precision/disable_convert_constant_folding_on_const_path.hpp index e81152ee1a3..9cf348e605c 100644 --- a/src/common/transformations/include/transformations/low_precision/disable_convert_constant_folding_on_const_path.hpp +++ b/src/common/transformations/include/transformations/low_precision/disable_convert_constant_folding_on_const_path.hpp @@ -5,10 +5,9 @@ #pragma once #include -#include - -#include #include +#include +#include namespace ngraph { namespace pass { @@ -21,6 +20,5 @@ class TRANSFORMATIONS_API DisableConvertConstantFoldingOnConstPath; class ngraph::pass::DisableConvertConstantFoldingOnConstPath : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; - DisableConvertConstantFoldingOnConstPath( - const element::TypeVector & inputPrecisions = {}); + DisableConvertConstantFoldingOnConstPath(const element::TypeVector& inputPrecisions = {}); }; diff --git a/src/common/transformations/include/transformations/op_conversions/batch_norm_decomposition.hpp b/src/common/transformations/include/transformations/op_conversions/batch_norm_decomposition.hpp index 4b8514136db..4eb17023cdd 100644 --- a/src/common/transformations/include/transformations/op_conversions/batch_norm_decomposition.hpp +++ b/src/common/transformations/include/transformations/op_conversions/batch_norm_decomposition.hpp @@ -5,13 +5,10 @@ #pragma once #include - -#include - #include - -#include #include +#include +#include using namespace std; @@ -23,7 +20,7 @@ class TRANSFORMATIONS_API BatchNormDecomposition; } // namespace pass } // namespace ngraph -class ngraph::pass::BatchNormDecomposition: public ngraph::pass::MatcherPass { +class ngraph::pass::BatchNormDecomposition : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; BatchNormDecomposition(); diff --git a/src/common/transformations/include/transformations/op_conversions/bidirectional_sequences_decomposition.hpp b/src/common/transformations/include/transformations/op_conversions/bidirectional_sequences_decomposition.hpp index b1c453901e1..711589da3e8 100644 --- a/src/common/transformations/include/transformations/op_conversions/bidirectional_sequences_decomposition.hpp +++ b/src/common/transformations/include/transformations/op_conversions/bidirectional_sequences_decomposition.hpp @@ -4,13 +4,11 @@ #pragma once -#include #include -#include - -#include - #include +#include +#include +#include namespace ngraph { namespace pass { diff --git a/src/common/transformations/include/transformations/op_conversions/convert_batch_to_space.hpp b/src/common/transformations/include/transformations/op_conversions/convert_batch_to_space.hpp index 94fc6fb2ff4..087ba8004f2 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_batch_to_space.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_batch_to_space.hpp @@ -4,13 +4,11 @@ #pragma once -#include #include - -#include - #include #include +#include +#include namespace ngraph { namespace pass { @@ -33,7 +31,7 @@ class TRANSFORMATIONS_API ConvertBatchToSpace; * */ -class ngraph::pass::ConvertBatchToSpace: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvertBatchToSpace : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; explicit ConvertBatchToSpace(bool convert_by_elements = true) : MatcherPass() { diff --git a/src/common/transformations/include/transformations/op_conversions/convert_broadcast3.hpp b/src/common/transformations/include/transformations/op_conversions/convert_broadcast3.hpp index 76be1fa6278..6f42c62924e 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_broadcast3.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_broadcast3.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - #include +#include +#include namespace ngraph { namespace pass { @@ -19,7 +17,7 @@ class TRANSFORMATIONS_API ConvertBroadcast3; } // namespace pass } // namespace ngraph -class ngraph::pass::ConvertBroadcast3: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvertBroadcast3 : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvertBroadcast3(); diff --git a/src/common/transformations/include/transformations/op_conversions/convert_broadcast_to_tiles.hpp b/src/common/transformations/include/transformations/op_conversions/convert_broadcast_to_tiles.hpp index 8b0524c53f6..56a9462302b 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_broadcast_to_tiles.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_broadcast_to_tiles.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - #include +#include +#include namespace ngraph { namespace pass { @@ -19,7 +17,7 @@ class TRANSFORMATIONS_API ConvertBroadcastToTiles; } // namespace pass } // namespace ngraph -class ngraph::pass::ConvertBroadcastToTiles: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvertBroadcastToTiles : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvertBroadcastToTiles(); diff --git a/src/common/transformations/include/transformations/op_conversions/convert_deformable_conv_v8_to_v1.hpp b/src/common/transformations/include/transformations/op_conversions/convert_deformable_conv_v8_to_v1.hpp index 1d6be40e04e..4b8bb451ec2 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_deformable_conv_v8_to_v1.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_deformable_conv_v8_to_v1.hpp @@ -4,9 +4,8 @@ #pragma once -#include - #include +#include namespace ngraph { namespace pass { diff --git a/src/common/transformations/include/transformations/op_conversions/convert_depth_to_space.hpp b/src/common/transformations/include/transformations/op_conversions/convert_depth_to_space.hpp index 92c53785002..1f8953cb257 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_depth_to_space.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_depth_to_space.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - #include +#include +#include namespace ngraph { namespace pass { @@ -19,7 +17,7 @@ class TRANSFORMATIONS_API ConvertDepthToSpace; } // namespace pass } // namespace ngraph -class ngraph::pass::ConvertDepthToSpace: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvertDepthToSpace : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvertDepthToSpace(); diff --git a/src/common/transformations/include/transformations/op_conversions/convert_divide.hpp b/src/common/transformations/include/transformations/op_conversions/convert_divide.hpp index 9052e0ac4e6..e8a59d95a18 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_divide.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_divide.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - #include +#include +#include namespace ngraph { namespace pass { @@ -20,13 +18,13 @@ class TRANSFORMATIONS_API ConvertDivideWithConstant; } // namespace pass } // namespace ngraph -class ngraph::pass::ConvertDivide: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvertDivide : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvertDivide(); }; -class ngraph::pass::ConvertDivideWithConstant: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvertDivideWithConstant : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvertDivideWithConstant(); diff --git a/src/common/transformations/include/transformations/op_conversions/convert_gather_0d.hpp b/src/common/transformations/include/transformations/op_conversions/convert_gather_0d.hpp index d28613d6313..ca74418e731 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_gather_0d.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_gather_0d.hpp @@ -4,13 +4,10 @@ #pragma once -#include #include - -#include - #include - +#include +#include namespace ngraph { namespace pass { @@ -22,7 +19,8 @@ class TRANSFORMATIONS_API ConvertGather0D; /** * @ingroup ie_transformation_common_api - * @brief ConvertGather0D decomposes v1::Gather operation into v0::Unsqueeze + v1::Gather + v0::Squeeze pattern when gather indices is scalar + * @brief ConvertGather0D decomposes v1::Gather operation into v0::Unsqueeze + v1::Gather + v0::Squeeze pattern when + * gather indices is scalar */ class ngraph::pass::ConvertGather0D : public ngraph::pass::MatcherPass { public: diff --git a/src/common/transformations/include/transformations/op_conversions/convert_gather_downgrade.hpp b/src/common/transformations/include/transformations/op_conversions/convert_gather_downgrade.hpp index 9688d88ff27..1b44f809711 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_gather_downgrade.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_gather_downgrade.hpp @@ -4,9 +4,8 @@ #pragma once -#include - #include +#include namespace ngraph { namespace pass { diff --git a/src/common/transformations/include/transformations/op_conversions/convert_gather_upgrade.hpp b/src/common/transformations/include/transformations/op_conversions/convert_gather_upgrade.hpp index d96dc7cd217..effb5649a7f 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_gather_upgrade.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_gather_upgrade.hpp @@ -4,9 +4,8 @@ #pragma once -#include - #include +#include namespace ngraph { namespace pass { diff --git a/src/common/transformations/include/transformations/op_conversions/convert_gelu.hpp b/src/common/transformations/include/transformations/op_conversions/convert_gelu.hpp index 9357aa06c23..8d247aa595e 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_gelu.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_gelu.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - #include +#include +#include #include "ngraph/op/gelu.hpp" @@ -21,7 +19,7 @@ class TRANSFORMATIONS_API ConvertGELU; } // namespace pass } // namespace ngraph -class ngraph::pass::ConvertGELU: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvertGELU : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvertGELU(); diff --git a/src/common/transformations/include/transformations/op_conversions/convert_interpolate1_to_interpolate4.hpp b/src/common/transformations/include/transformations/op_conversions/convert_interpolate1_to_interpolate4.hpp index b4ae689e96b..6ad05c2e9f7 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_interpolate1_to_interpolate4.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_interpolate1_to_interpolate4.hpp @@ -4,13 +4,11 @@ #pragma once -#include -#include #include - -#include - #include +#include +#include +#include namespace ngraph { namespace pass { @@ -24,7 +22,7 @@ class TRANSFORMATIONS_API ConvertInterpolate1ToInterpolate4; * @ingroup ie_transformation_common_api * @brief ConvertInterpolate1ToInterpolate4 covert v0:interpolate into v4::Interpolate. */ -class ngraph::pass::ConvertInterpolate1ToInterpolate4: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvertInterpolate1ToInterpolate4 : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvertInterpolate1ToInterpolate4(); diff --git a/src/common/transformations/include/transformations/op_conversions/convert_matrix_nms_to_matrix_nms_ie.hpp b/src/common/transformations/include/transformations/op_conversions/convert_matrix_nms_to_matrix_nms_ie.hpp index e1970e17a1b..21a04ef16f1 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_matrix_nms_to_matrix_nms_ie.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_matrix_nms_to_matrix_nms_ie.hpp @@ -4,12 +4,11 @@ #pragma once -#include -#include #include - -#include #include +#include +#include +#include namespace ngraph { namespace pass { @@ -19,7 +18,7 @@ class TRANSFORMATIONS_API ConvertMatrixNmsToMatrixNmsIE; } // namespace pass } // namespace ngraph -class ngraph::pass::ConvertMatrixNmsToMatrixNmsIE: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvertMatrixNmsToMatrixNmsIE : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvertMatrixNmsToMatrixNmsIE(bool force_i32_output_type = true); diff --git a/src/common/transformations/include/transformations/op_conversions/convert_maxpool_downgrade.hpp b/src/common/transformations/include/transformations/op_conversions/convert_maxpool_downgrade.hpp index 6a5dad82169..7d7e10aca2c 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_maxpool_downgrade.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_maxpool_downgrade.hpp @@ -4,8 +4,8 @@ #pragma once -#include #include +#include namespace ngraph { namespace pass { diff --git a/src/common/transformations/include/transformations/op_conversions/convert_maxpool_upgrade.hpp b/src/common/transformations/include/transformations/op_conversions/convert_maxpool_upgrade.hpp index 9a38a8189f1..919bf917423 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_maxpool_upgrade.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_maxpool_upgrade.hpp @@ -4,8 +4,8 @@ #pragma once -#include #include +#include namespace ngraph { namespace pass { diff --git a/src/common/transformations/include/transformations/op_conversions/convert_minimum_to_power_and_max.hpp b/src/common/transformations/include/transformations/op_conversions/convert_minimum_to_power_and_max.hpp index 79cc81d9648..e1025e1ef79 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_minimum_to_power_and_max.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_minimum_to_power_and_max.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - #include +#include +#include namespace ngraph { namespace pass { @@ -19,7 +17,7 @@ class TRANSFORMATIONS_API ConvertMinimum; } // namespace pass } // namespace ngraph -class ngraph::pass::ConvertMinimum: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvertMinimum : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvertMinimum(); diff --git a/src/common/transformations/include/transformations/op_conversions/convert_mod.hpp b/src/common/transformations/include/transformations/op_conversions/convert_mod.hpp index 78c3ac9bf5c..69b18636f42 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_mod.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_mod.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - #include +#include +#include namespace ngraph { namespace pass { @@ -19,7 +17,7 @@ class TRANSFORMATIONS_API ConvertMod; } // namespace pass } // namespace ngraph -class ngraph::pass::ConvertMod: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvertMod : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvertMod(); diff --git a/src/common/transformations/include/transformations/op_conversions/convert_multiclass_nms_to_multiclass_nms_ie.hpp b/src/common/transformations/include/transformations/op_conversions/convert_multiclass_nms_to_multiclass_nms_ie.hpp index 14fce022787..90c7da24daf 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_multiclass_nms_to_multiclass_nms_ie.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_multiclass_nms_to_multiclass_nms_ie.hpp @@ -4,12 +4,11 @@ #pragma once -#include -#include #include - -#include #include +#include +#include +#include namespace ngraph { namespace pass { @@ -19,7 +18,7 @@ class TRANSFORMATIONS_API ConvertMulticlassNmsToMulticlassNmsIE; } // namespace pass } // namespace ngraph -class ngraph::pass::ConvertMulticlassNmsToMulticlassNmsIE: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvertMulticlassNmsToMulticlassNmsIE : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvertMulticlassNmsToMulticlassNmsIE(bool force_i32_output_type = true); diff --git a/src/common/transformations/include/transformations/op_conversions/convert_mvn1_to_mvn6.hpp b/src/common/transformations/include/transformations/op_conversions/convert_mvn1_to_mvn6.hpp index cdb03a83173..aaece983f6b 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_mvn1_to_mvn6.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_mvn1_to_mvn6.hpp @@ -4,9 +4,8 @@ #pragma once -#include - #include +#include namespace ngraph { namespace pass { diff --git a/src/common/transformations/include/transformations/op_conversions/convert_negative.hpp b/src/common/transformations/include/transformations/op_conversions/convert_negative.hpp index 6e762fc2b71..9a542bca8bf 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_negative.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_negative.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - #include +#include +#include namespace ngraph { namespace pass { @@ -19,7 +17,7 @@ class TRANSFORMATIONS_API ConvertNegative; } // namespace pass } // namespace ngraph -class ngraph::pass::ConvertNegative: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvertNegative : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvertNegative(); diff --git a/src/common/transformations/include/transformations/op_conversions/convert_nms_to_nms_ie_internal.hpp b/src/common/transformations/include/transformations/op_conversions/convert_nms_to_nms_ie_internal.hpp index 1e22735bab4..4f40940c82e 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_nms_to_nms_ie_internal.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_nms_to_nms_ie_internal.hpp @@ -4,12 +4,11 @@ #pragma once -#include -#include #include - -#include #include +#include +#include +#include namespace ngraph { namespace pass { @@ -19,7 +18,7 @@ class TRANSFORMATIONS_API ConvertNMSToNMSIEInternal; } // namespace pass } // namespace ngraph -class ngraph::pass::ConvertNMSToNMSIEInternal: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvertNMSToNMSIEInternal : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvertNMSToNMSIEInternal(); diff --git a/src/common/transformations/include/transformations/op_conversions/convert_pad_to_group_conv.hpp b/src/common/transformations/include/transformations/op_conversions/convert_pad_to_group_conv.hpp index 140f820d2ec..583c875b1b9 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_pad_to_group_conv.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_pad_to_group_conv.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - #include +#include +#include namespace ngraph { namespace pass { @@ -28,7 +26,7 @@ class TRANSFORMATIONS_API ConvertPadToGroupConvolution; * 3. Input shape rank must be static and greater than 3 */ -class ngraph::pass::ConvertPadToGroupConvolution: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvertPadToGroupConvolution : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvertPadToGroupConvolution(); diff --git a/src/common/transformations/include/transformations/op_conversions/convert_previous_nms_to_nms_5.hpp b/src/common/transformations/include/transformations/op_conversions/convert_previous_nms_to_nms_5.hpp index c72efba58f2..1a98a5b1c62 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_previous_nms_to_nms_5.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_previous_nms_to_nms_5.hpp @@ -5,10 +5,9 @@ #pragma once #include -#include - -#include #include +#include +#include namespace ngraph { namespace pass { @@ -20,21 +19,20 @@ class TRANSFORMATIONS_API ConvertNMS4ToNMS5; } // namespace pass } // namespace ngraph -class ngraph::pass::ConvertNMS1ToNMS5: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvertNMS1ToNMS5 : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvertNMS1ToNMS5(); }; -class ngraph::pass::ConvertNMS3ToNMS5: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvertNMS3ToNMS5 : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvertNMS3ToNMS5(); }; -class ngraph::pass::ConvertNMS4ToNMS5: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvertNMS4ToNMS5 : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvertNMS4ToNMS5(); }; - diff --git a/src/common/transformations/include/transformations/op_conversions/convert_reduce_to_pooling.hpp b/src/common/transformations/include/transformations/op_conversions/convert_reduce_to_pooling.hpp index 525ced51d88..cca24e57133 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_reduce_to_pooling.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_reduce_to_pooling.hpp @@ -4,19 +4,16 @@ #pragma once -#include -#include #include - -#include - +#include #include -#include #include -#include -#include +#include #include - +#include +#include +#include +#include namespace ngraph { namespace pass { @@ -35,25 +32,25 @@ public: ngraph::matcher_pass_callback convert_reduce_to_pooling(); }; -class ngraph::pass::ConvertReduceMeanToPooling: public ConvertReduceBase { +class ngraph::pass::ConvertReduceMeanToPooling : public ConvertReduceBase { public: NGRAPH_RTTI_DECLARATION; ConvertReduceMeanToPooling(); }; -class ngraph::pass::ConvertReduceMaxToPooling: public ConvertReduceBase { +class ngraph::pass::ConvertReduceMaxToPooling : public ConvertReduceBase { public: NGRAPH_RTTI_DECLARATION; ConvertReduceMaxToPooling(); }; -class ngraph::pass::ConvertReduceSumToPooling: public ConvertReduceBase { +class ngraph::pass::ConvertReduceSumToPooling : public ConvertReduceBase { public: NGRAPH_RTTI_DECLARATION; ConvertReduceSumToPooling(); }; -class ngraph::pass::ConvertReduceToPooling: public ngraph::pass::GraphRewrite { +class ngraph::pass::ConvertReduceToPooling : public ngraph::pass::GraphRewrite { public: NGRAPH_RTTI_DECLARATION; ConvertReduceToPooling() { @@ -74,7 +71,8 @@ ngraph::matcher_pass_callback ConvertReduceBase::convert_reduce_to_pooling() { auto input = reduce->input_value(0); - auto axes_node = std::dynamic_pointer_cast(reduce->input_value(1).get_node_shared_ptr()); + auto axes_node = + std::dynamic_pointer_cast(reduce->input_value(1).get_node_shared_ptr()); if (!axes_node) { return false; } @@ -97,11 +95,16 @@ ngraph::matcher_pass_callback ConvertReduceBase::convert_reduce_to_pooling() { auto input_shape = input.get_shape(); // If Reduce op reduces only 1 dims we replace it with Reshape - if (std::all_of(axes_vector.begin(), axes_vector.end(), - [&input_shape](const int64_t & axis) { return input_shape[axis] == 1; })) { + if (std::all_of(axes_vector.begin(), axes_vector.end(), [&input_shape](const int64_t& axis) { + return input_shape[axis] == 1; + })) { const auto reshape_shape = reduce->output(0).get_shape(); - auto reshape = std::make_shared(input, - ngraph::opset1::Constant::create(ngraph::element::i64, ngraph::Shape{reshape_shape.size()}, reshape_shape), true); + auto reshape = std::make_shared( + input, + ngraph::opset1::Constant::create(ngraph::element::i64, + ngraph::Shape{reshape_shape.size()}, + reshape_shape), + true); reshape->set_friendly_name(reduce->get_friendly_name()); copy_runtime_info(reduce, reshape); @@ -111,7 +114,7 @@ ngraph::matcher_pass_callback ConvertReduceBase::convert_reduce_to_pooling() { // Check that axes are consecutive otherwise this transformation is not applicable for (size_t i = 1; i < axes_vector.size(); ++i) { - if (axes_vector[i] - axes_vector[i-1] != 1) { + if (axes_vector[i] - axes_vector[i - 1] != 1) { return false; } } @@ -169,7 +172,7 @@ ngraph::matcher_pass_callback ConvertReduceBase::convert_reduce_to_pooling() { kernel.push_back(1); } for (auto& axis : axes_vector) { - kernel[axis-2] = input_shape[axis]; + kernel[axis - 2] = input_shape[axis]; } shape_end = reduce->output(0).get_shape(); } @@ -192,8 +195,10 @@ ngraph::matcher_pass_callback ConvertReduceBase::convert_reduce_to_pooling() { ngraph::NodeVector new_ops; if (!shape_begin.empty() && shape_begin != input.get_shape()) { - input = std::make_shared(input, - ngraph::opset1::Constant::create(ngraph::element::i64, ngraph::Shape{shape_begin.size()}, shape_begin), true); + input = std::make_shared( + input, + ngraph::opset1::Constant::create(ngraph::element::i64, ngraph::Shape{shape_begin.size()}, shape_begin), + true); input.get_node_shared_ptr()->set_friendly_name(reduce->get_friendly_name() + "/reshape_begin"); new_ops.push_back(input.get_node_shared_ptr()); } @@ -229,18 +234,19 @@ ngraph::matcher_pass_callback ConvertReduceBase::convert_reduce_to_pooling() { } input = std::make_shared(input, - strides, - pads_begin, - pads_end, - kernel, - true, - ngraph::op::RoundingType::FLOOR); + strides, + pads_begin, + pads_end, + kernel, + true, + ngraph::op::RoundingType::FLOOR); input.get_node_shared_ptr()->set_friendly_name(reduce->get_friendly_name() + "/pool"); new_ops.push_back(input.get_node_shared_ptr()); - input = std::make_shared(input, - ngraph::opset1::Constant::create(input.get_element_type(), ngraph::Shape{1}, {reduction_dims_count})); + input = std::make_shared( + input, + ngraph::opset1::Constant::create(input.get_element_type(), ngraph::Shape{1}, {reduction_dims_count})); input.get_node_shared_ptr()->set_friendly_name(reduce->get_friendly_name() + "/mul"); new_ops.push_back(input.get_node_shared_ptr()); @@ -253,8 +259,10 @@ ngraph::matcher_pass_callback ConvertReduceBase::convert_reduce_to_pooling() { } if (shape_end != input.get_shape()) { - input = std::make_shared(input, - ngraph::opset1::Constant::create(ngraph::element::i64, ngraph::Shape{shape_end.size()}, shape_end), true); + input = std::make_shared( + input, + ngraph::opset1::Constant::create(ngraph::element::i64, ngraph::Shape{shape_end.size()}, shape_end), + true); new_ops.push_back(input.get_node_shared_ptr()); } input.get_node_shared_ptr()->set_friendly_name(reduce->get_friendly_name()); diff --git a/src/common/transformations/include/transformations/op_conversions/convert_scatter_elements_to_scatter.hpp b/src/common/transformations/include/transformations/op_conversions/convert_scatter_elements_to_scatter.hpp index 5d4a819fd6f..7e4a5e76ec5 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_scatter_elements_to_scatter.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_scatter_elements_to_scatter.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - #include +#include +#include namespace ngraph { namespace pass { @@ -23,7 +21,7 @@ class TRANSFORMATIONS_API ConvertScatterElementsToScatter; * @ingroup ie_transformation_common_api * @brief ConvertScatterElementsToScatter convert opset3::ScatterElementsUpdate to opset3::ScatterUpdate. */ -class ngraph::pass::ConvertScatterElementsToScatter: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvertScatterElementsToScatter : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvertScatterElementsToScatter(); diff --git a/src/common/transformations/include/transformations/op_conversions/convert_sequences_to_tensor_iterator.hpp b/src/common/transformations/include/transformations/op_conversions/convert_sequences_to_tensor_iterator.hpp index 13cfaad76ee..e3cc75b5f57 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_sequences_to_tensor_iterator.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_sequences_to_tensor_iterator.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - #include +#include +#include namespace ngraph { namespace pass { @@ -28,7 +26,7 @@ class TRANSFORMATIONS_API ConvertSequenceToTensorIterator; * * */ -class ngraph::pass::ConvertRNNSequenceToTensorIterator: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvertRNNSequenceToTensorIterator : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvertRNNSequenceToTensorIterator(); @@ -40,7 +38,7 @@ public: * * */ -class ngraph::pass::ConvertGRUSequenceToTensorIterator: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvertGRUSequenceToTensorIterator : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvertGRUSequenceToTensorIterator(); @@ -52,7 +50,7 @@ public: * * */ -class ngraph::pass::ConvertLSTMSequenceToTensorIterator: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvertLSTMSequenceToTensorIterator : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvertLSTMSequenceToTensorIterator(); diff --git a/src/common/transformations/include/transformations/op_conversions/convert_shapeof3.hpp b/src/common/transformations/include/transformations/op_conversions/convert_shapeof3.hpp index 108d2a8cb8d..bd46611853a 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_shapeof3.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_shapeof3.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - #include +#include +#include namespace ngraph { namespace pass { @@ -19,7 +17,7 @@ class TRANSFORMATIONS_API ConvertShapeOf3; } // namespace pass } // namespace ngraph -class ngraph::pass::ConvertShapeOf3: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvertShapeOf3 : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvertShapeOf3(); diff --git a/src/common/transformations/include/transformations/op_conversions/convert_shuffle_channels3.hpp b/src/common/transformations/include/transformations/op_conversions/convert_shuffle_channels3.hpp index 8080c20cf37..fe76ccc3ffc 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_shuffle_channels3.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_shuffle_channels3.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - #include +#include +#include namespace ngraph { namespace pass { @@ -19,7 +17,7 @@ class TRANSFORMATIONS_API ConvertShuffleChannels3; } // namespace pass } // namespace ngraph -class ngraph::pass::ConvertShuffleChannels3: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvertShuffleChannels3 : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvertShuffleChannels3(); diff --git a/src/common/transformations/include/transformations/op_conversions/convert_slice_to_strided_slice.hpp b/src/common/transformations/include/transformations/op_conversions/convert_slice_to_strided_slice.hpp index 0e6e00d42dd..1cc2521e66b 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_slice_to_strided_slice.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_slice_to_strided_slice.hpp @@ -4,8 +4,8 @@ #pragma once -#include #include +#include namespace ngraph { namespace pass { @@ -15,12 +15,11 @@ class TRANSFORMATIONS_API SliceToStridedSlice; } // namespace pass } // namespace ngraph - /** * @ingroup ie_transformation_common_api * @brief SliceToStridedSlice transformation convert v8::Slice to v1::StridedSlice */ -class ngraph::pass::SliceToStridedSlice: public ngraph::pass::MatcherPass { +class ngraph::pass::SliceToStridedSlice : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; SliceToStridedSlice(bool use_shapes); diff --git a/src/common/transformations/include/transformations/op_conversions/convert_softmax_downgrade.hpp b/src/common/transformations/include/transformations/op_conversions/convert_softmax_downgrade.hpp index 380e44a3cfd..907576d7b92 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_softmax_downgrade.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_softmax_downgrade.hpp @@ -4,9 +4,8 @@ #pragma once -#include - #include +#include namespace ngraph { namespace pass { diff --git a/src/common/transformations/include/transformations/op_conversions/convert_softmax_upgrade.hpp b/src/common/transformations/include/transformations/op_conversions/convert_softmax_upgrade.hpp index 00c42ffeee6..603a036d3e1 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_softmax_upgrade.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_softmax_upgrade.hpp @@ -4,9 +4,8 @@ #pragma once -#include - #include +#include namespace ngraph { namespace pass { diff --git a/src/common/transformations/include/transformations/op_conversions/convert_space_to_batch.hpp b/src/common/transformations/include/transformations/op_conversions/convert_space_to_batch.hpp index 7a1109526e4..574e93baa88 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_space_to_batch.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_space_to_batch.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - #include +#include +#include namespace ngraph { namespace pass { @@ -32,7 +30,7 @@ class TRANSFORMATIONS_API ConvertSpaceToBatch; * */ -class ngraph::pass::ConvertSpaceToBatch: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvertSpaceToBatch : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; explicit ConvertSpaceToBatch(bool convert_by_elements = true) : MatcherPass() { diff --git a/src/common/transformations/include/transformations/op_conversions/convert_space_to_depth.hpp b/src/common/transformations/include/transformations/op_conversions/convert_space_to_depth.hpp index 2ab8be9350e..572f49ba92e 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_space_to_depth.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_space_to_depth.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - #include +#include +#include namespace ngraph { namespace pass { @@ -19,7 +17,7 @@ class TRANSFORMATIONS_API ConvertSpaceToDepth; } // namespace pass } // namespace ngraph -class ngraph::pass::ConvertSpaceToDepth: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvertSpaceToDepth : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvertSpaceToDepth(); diff --git a/src/common/transformations/include/transformations/op_conversions/convert_subtract.hpp b/src/common/transformations/include/transformations/op_conversions/convert_subtract.hpp index cb2cd33bc6a..cd18c4c279f 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_subtract.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_subtract.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - #include +#include +#include namespace ngraph { namespace pass { @@ -19,7 +17,7 @@ class TRANSFORMATIONS_API ConvertSubtract; } // namespace pass } // namespace ngraph -class ngraph::pass::ConvertSubtract: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvertSubtract : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvertSubtract(); diff --git a/src/common/transformations/include/transformations/op_conversions/convert_ti_to_sequences.hpp b/src/common/transformations/include/transformations/op_conversions/convert_ti_to_sequences.hpp index 5aff6ed4276..8e13bc21997 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_ti_to_sequences.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_ti_to_sequences.hpp @@ -4,15 +4,10 @@ #pragma once -#include #include - -#include -#include - -#include - #include +#include +#include namespace ngraph { namespace pass { @@ -31,7 +26,7 @@ class TRANSFORMATIONS_API ConvertTensorIteratorToSequence; * converts this pattern to LSTMSequence layer and replaces them TensorIterator. */ -class ngraph::pass::ConvertTensorIteratorToLSTMSequence: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvertTensorIteratorToLSTMSequence : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvertTensorIteratorToLSTMSequence(); @@ -43,7 +38,7 @@ public: * converts this pattern to RNNSequence layer and replaces them TensorIterator. */ -class ngraph::pass::ConvertTensorIteratorToRNNSequence: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvertTensorIteratorToRNNSequence : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvertTensorIteratorToRNNSequence(); @@ -55,7 +50,7 @@ public: * converts this pattern to GRUSequence layer and replaces them TensorIterator. */ -class ngraph::pass::ConvertTensorIteratorToGRUSequence: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvertTensorIteratorToGRUSequence : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvertTensorIteratorToGRUSequence(); diff --git a/src/common/transformations/include/transformations/op_conversions/convert_topk3.hpp b/src/common/transformations/include/transformations/op_conversions/convert_topk3.hpp index 0de713b0456..c2575583f35 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_topk3.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_topk3.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - #include +#include +#include namespace ngraph { namespace pass { @@ -19,7 +17,7 @@ class TRANSFORMATIONS_API ConvertTopK3; } // namespace pass } // namespace ngraph -class ngraph::pass::ConvertTopK3: public ngraph::pass::MatcherPass { +class ngraph::pass::ConvertTopK3 : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ConvertTopK3(); diff --git a/src/common/transformations/include/transformations/op_conversions/fq_decomposition.hpp b/src/common/transformations/include/transformations/op_conversions/fq_decomposition.hpp index 1f827a7de3f..ae0df4c61ec 100644 --- a/src/common/transformations/include/transformations/op_conversions/fq_decomposition.hpp +++ b/src/common/transformations/include/transformations/op_conversions/fq_decomposition.hpp @@ -4,8 +4,8 @@ #pragma once -#include #include +#include namespace ngraph { namespace pass { @@ -25,14 +25,16 @@ class TRANSFORMATIONS_API FakeQuantizeDecomposition; * elif x > max(input_low, input_high): * output = output_high * else: - * output = round((x - input_low) / (input_high - input_low) * (levels-1)) / (levels-1) * (output_high - output_low) + output_low + * output = round((x - input_low) / (input_high - input_low) * (levels-1)) / (levels-1) * (output_high - output_low) + + * output_low * * expand brackets into round: * round(x * (levels-1) / (input_high - input_low) - input_low * (levels-1) / (input_high - input_low)) * div on (levels-1) and mult on (output_high - output_low) => mult on (output_high - output_low) / (levels-1) * * => - * round(x * (levels-1) / (input_high - input_low) - input_low * (levels-1) / (input_high - input_low)) * (output_high - output_low) / (levels-1) + output_low + * round(x * (levels-1) / (input_high - input_low) - input_low * (levels-1) / (input_high - input_low)) * (output_high - + * output_low) / (levels-1) + output_low * * This transformation doesn't support following cases: * 1. At least one 'range' input is not Constant @@ -40,7 +42,7 @@ class TRANSFORMATIONS_API FakeQuantizeDecomposition; * */ -class ngraph::pass::FakeQuantizeDecomposition: public ngraph::pass::MatcherPass { +class ngraph::pass::FakeQuantizeDecomposition : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; FakeQuantizeDecomposition(); diff --git a/src/common/transformations/include/transformations/op_conversions/gather_normalize_negative_indices.hpp b/src/common/transformations/include/transformations/op_conversions/gather_normalize_negative_indices.hpp index 7b14086df32..cb63d082103 100644 --- a/src/common/transformations/include/transformations/op_conversions/gather_normalize_negative_indices.hpp +++ b/src/common/transformations/include/transformations/op_conversions/gather_normalize_negative_indices.hpp @@ -4,13 +4,13 @@ #pragma once -#include #include +#include namespace ngraph { namespace pass { - class TRANSFORMATIONS_API GatherNegativeConstIndicesNormalize; +class TRANSFORMATIONS_API GatherNegativeConstIndicesNormalize; } // namespace pass } // namespace ngraph diff --git a/src/common/transformations/include/transformations/op_conversions/gelu7_downgrade.hpp b/src/common/transformations/include/transformations/op_conversions/gelu7_downgrade.hpp index 7d122f0d937..9380426e505 100644 --- a/src/common/transformations/include/transformations/op_conversions/gelu7_downgrade.hpp +++ b/src/common/transformations/include/transformations/op_conversions/gelu7_downgrade.hpp @@ -4,13 +4,13 @@ #pragma once -#include #include +#include namespace ngraph { namespace pass { - class TRANSFORMATIONS_API Gelu7Downgrade; +class TRANSFORMATIONS_API Gelu7Downgrade; } // namespace pass } // namespace ngraph diff --git a/src/common/transformations/include/transformations/op_conversions/gru_cell_decomposition.hpp b/src/common/transformations/include/transformations/op_conversions/gru_cell_decomposition.hpp index f52b4de7e15..58508d22eb5 100644 --- a/src/common/transformations/include/transformations/op_conversions/gru_cell_decomposition.hpp +++ b/src/common/transformations/include/transformations/op_conversions/gru_cell_decomposition.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - #include +#include +#include namespace ngraph { namespace pass { @@ -35,7 +33,7 @@ class TRANSFORMATIONS_API GRUCellDecomposition; * * */ -class ngraph::pass::GRUCellDecomposition: public ngraph::pass::MatcherPass { +class ngraph::pass::GRUCellDecomposition : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; GRUCellDecomposition(); diff --git a/src/common/transformations/include/transformations/op_conversions/hsigmoid_decomposition.hpp b/src/common/transformations/include/transformations/op_conversions/hsigmoid_decomposition.hpp index b4f559f1e86..194d224ca58 100644 --- a/src/common/transformations/include/transformations/op_conversions/hsigmoid_decomposition.hpp +++ b/src/common/transformations/include/transformations/op_conversions/hsigmoid_decomposition.hpp @@ -4,8 +4,8 @@ #pragma once -#include #include +#include namespace ngraph { namespace pass { @@ -19,7 +19,7 @@ class TRANSFORMATIONS_API HSigmoidDecomposition; * @ingroup ie_transformation_common_api * @brief HSigmoidDecomposition transformation into sub-graph (min(Relu(x + 3), 6) * const(1/6). */ -class ngraph::pass::HSigmoidDecomposition: public ngraph::pass::MatcherPass { +class ngraph::pass::HSigmoidDecomposition : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; HSigmoidDecomposition(); diff --git a/src/common/transformations/include/transformations/op_conversions/hswish_decomposition.hpp b/src/common/transformations/include/transformations/op_conversions/hswish_decomposition.hpp index 7019ab371f5..f3a37120b07 100644 --- a/src/common/transformations/include/transformations/op_conversions/hswish_decomposition.hpp +++ b/src/common/transformations/include/transformations/op_conversions/hswish_decomposition.hpp @@ -4,8 +4,8 @@ #pragma once -#include #include +#include namespace ngraph { namespace pass { @@ -19,7 +19,7 @@ class TRANSFORMATIONS_API HSwishDecomposition; * @ingroup ie_transformation_common_api * @brief HSwishDecomposition transformation into sub-graph x * (min(Relu(x + 3), 6) * const(1/6). */ -class ngraph::pass::HSwishDecomposition: public ngraph::pass::MatcherPass { +class ngraph::pass::HSwishDecomposition : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; HSwishDecomposition(); diff --git a/src/common/transformations/include/transformations/op_conversions/log_softmax_decomposition.hpp b/src/common/transformations/include/transformations/op_conversions/log_softmax_decomposition.hpp index 6963bc70830..b71278227a2 100644 --- a/src/common/transformations/include/transformations/op_conversions/log_softmax_decomposition.hpp +++ b/src/common/transformations/include/transformations/op_conversions/log_softmax_decomposition.hpp @@ -4,13 +4,13 @@ #pragma once -#include #include +#include namespace ngraph { namespace pass { - class TRANSFORMATIONS_API LogSoftmaxDecomposition; +class TRANSFORMATIONS_API LogSoftmaxDecomposition; } // namespace pass } // namespace ngraph diff --git a/src/common/transformations/include/transformations/op_conversions/lstm_cell_decomposition.hpp b/src/common/transformations/include/transformations/op_conversions/lstm_cell_decomposition.hpp index 1ae74025b31..78d103abf8c 100644 --- a/src/common/transformations/include/transformations/op_conversions/lstm_cell_decomposition.hpp +++ b/src/common/transformations/include/transformations/op_conversions/lstm_cell_decomposition.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - #include +#include +#include namespace ngraph { namespace pass { @@ -36,7 +34,7 @@ class TRANSFORMATIONS_API LSTMCellDecomposition; * * */ -class ngraph::pass::LSTMCellDecomposition: public ngraph::pass::MatcherPass { +class ngraph::pass::LSTMCellDecomposition : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; LSTMCellDecomposition(); diff --git a/src/common/transformations/include/transformations/op_conversions/mvn6_decomposition.hpp b/src/common/transformations/include/transformations/op_conversions/mvn6_decomposition.hpp index 26a63b11399..287856f90a1 100644 --- a/src/common/transformations/include/transformations/op_conversions/mvn6_decomposition.hpp +++ b/src/common/transformations/include/transformations/op_conversions/mvn6_decomposition.hpp @@ -4,13 +4,13 @@ #pragma once -#include #include +#include namespace ngraph { namespace pass { - class TRANSFORMATIONS_API MVN6Decomposition; +class TRANSFORMATIONS_API MVN6Decomposition; } // namespace pass } // namespace ngraph @@ -18,7 +18,8 @@ namespace pass { /** * @ingroup ie_transformation_common_api * @brief MVN6Decomposition transformation into sub-graph x - ReduceMean(x, axes) if normalize_variance is false and - * into sub-graph (x - ReduceMean(x, axes)) / Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2)) if normalize_variance is true. + * into sub-graph (x - ReduceMean(x, axes)) / Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2)) if normalize_variance is + * true. */ class ngraph::pass::MVN6Decomposition : public ngraph::pass::MatcherPass { public: diff --git a/src/common/transformations/include/transformations/op_conversions/normalize_l2_decomposition.hpp b/src/common/transformations/include/transformations/op_conversions/normalize_l2_decomposition.hpp index b62b4844f49..39dcf457e61 100644 --- a/src/common/transformations/include/transformations/op_conversions/normalize_l2_decomposition.hpp +++ b/src/common/transformations/include/transformations/op_conversions/normalize_l2_decomposition.hpp @@ -4,13 +4,12 @@ #pragma once -#include #include - -#include - #include #include +#include +#include + #include "ngraph/pattern/matcher.hpp" namespace ngraph { @@ -25,7 +24,7 @@ class TRANSFORMATIONS_API NormalizeL2Decomposition; * @ingroup ie_transformation_common_api * @brief Decomposes NormalizeL2 into subgraph */ -class ngraph::pass::NormalizeL2Decomposition: public ngraph::pass::MatcherPass { +class ngraph::pass::NormalizeL2Decomposition : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; NormalizeL2Decomposition(); diff --git a/src/common/transformations/include/transformations/op_conversions/reduce_l1_decomposition.hpp b/src/common/transformations/include/transformations/op_conversions/reduce_l1_decomposition.hpp index cde3b793c4f..79d151c2830 100644 --- a/src/common/transformations/include/transformations/op_conversions/reduce_l1_decomposition.hpp +++ b/src/common/transformations/include/transformations/op_conversions/reduce_l1_decomposition.hpp @@ -4,13 +4,12 @@ #pragma once -#include #include - -#include - #include #include +#include +#include + #include "ngraph/pattern/matcher.hpp" namespace ngraph { @@ -25,7 +24,7 @@ class TRANSFORMATIONS_API ReduceL1Decomposition; * @ingroup ie_transformation_common_api * @brief Decomposes ReduceL1 into ReduceSum(abs(x)). */ -class ngraph::pass::ReduceL1Decomposition: public ngraph::pass::MatcherPass { +class ngraph::pass::ReduceL1Decomposition : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ReduceL1Decomposition(); diff --git a/src/common/transformations/include/transformations/op_conversions/reduce_l2_decomposition.hpp b/src/common/transformations/include/transformations/op_conversions/reduce_l2_decomposition.hpp index a8abc08e88a..d1a5d784583 100644 --- a/src/common/transformations/include/transformations/op_conversions/reduce_l2_decomposition.hpp +++ b/src/common/transformations/include/transformations/op_conversions/reduce_l2_decomposition.hpp @@ -4,13 +4,12 @@ #pragma once -#include #include - -#include - #include #include +#include +#include + #include "ngraph/pattern/matcher.hpp" namespace ngraph { @@ -25,7 +24,7 @@ class TRANSFORMATIONS_API ReduceL2Decomposition; * @ingroup ie_transformation_common_api * @brief Decomposes ReduceL2 into sqrt(ReduceSum(x * x)). */ -class ngraph::pass::ReduceL2Decomposition: public ngraph::pass::MatcherPass { +class ngraph::pass::ReduceL2Decomposition : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ReduceL2Decomposition(); diff --git a/src/common/transformations/include/transformations/op_conversions/rnn_cell_decomposition.hpp b/src/common/transformations/include/transformations/op_conversions/rnn_cell_decomposition.hpp index 1c01942b5a7..ecda79e3e4a 100644 --- a/src/common/transformations/include/transformations/op_conversions/rnn_cell_decomposition.hpp +++ b/src/common/transformations/include/transformations/op_conversions/rnn_cell_decomposition.hpp @@ -4,12 +4,10 @@ #pragma once -#include #include - -#include - #include +#include +#include namespace ngraph { namespace pass { @@ -30,7 +28,7 @@ class TRANSFORMATIONS_API RNNCellDecomposition; * * */ -class ngraph::pass::RNNCellDecomposition: public ngraph::pass::MatcherPass { +class ngraph::pass::RNNCellDecomposition : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; RNNCellDecomposition(); diff --git a/src/common/transformations/include/transformations/op_conversions/simplify_ctc_greedy_decoder_seq_len.hpp b/src/common/transformations/include/transformations/op_conversions/simplify_ctc_greedy_decoder_seq_len.hpp index 00d95cbc85f..17d91ab33c2 100644 --- a/src/common/transformations/include/transformations/op_conversions/simplify_ctc_greedy_decoder_seq_len.hpp +++ b/src/common/transformations/include/transformations/op_conversions/simplify_ctc_greedy_decoder_seq_len.hpp @@ -5,10 +5,8 @@ #pragma once #include - -#include - #include +#include namespace ngraph { namespace pass { @@ -36,7 +34,7 @@ class TRANSFORMATIONS_API SimplifyCTCGreedyDecoderSeqLen; * * The transformation works only for case when the blank_index input == C-1, where C is the number of classes. */ -class ngraph::pass::SimplifyCTCGreedyDecoderSeqLen: public ngraph::pass::MatcherPass { +class ngraph::pass::SimplifyCTCGreedyDecoderSeqLen : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; SimplifyCTCGreedyDecoderSeqLen(); diff --git a/src/common/transformations/include/transformations/op_conversions/softmax_decomposition.hpp b/src/common/transformations/include/transformations/op_conversions/softmax_decomposition.hpp index cce4b3f5a1b..c097a19d29c 100644 --- a/src/common/transformations/include/transformations/op_conversions/softmax_decomposition.hpp +++ b/src/common/transformations/include/transformations/op_conversions/softmax_decomposition.hpp @@ -5,10 +5,8 @@ #pragma once #include - -#include - #include +#include namespace ngraph { namespace pass { @@ -68,7 +66,7 @@ class TRANSFORMATIONS_API SoftmaxDecomposition; * */ -class ngraph::pass::SoftmaxDecomposition: public ngraph::pass::MatcherPass { +class ngraph::pass::SoftmaxDecomposition : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; SoftmaxDecomposition(); diff --git a/src/common/transformations/include/transformations/op_conversions/softplus_decomposition.hpp b/src/common/transformations/include/transformations/op_conversions/softplus_decomposition.hpp index 1f8a70ec3ca..8274a7da19c 100644 --- a/src/common/transformations/include/transformations/op_conversions/softplus_decomposition.hpp +++ b/src/common/transformations/include/transformations/op_conversions/softplus_decomposition.hpp @@ -4,11 +4,10 @@ #pragma once -#include #include - -#include #include +#include +#include namespace ngraph { namespace pass { @@ -23,7 +22,7 @@ class TRANSFORMATIONS_API SoftPlusDecomposition; * @brief SoftPlusDecomposition transformation replaces SoftPlus op to * group of operations: log(exp(x) + 1). */ -class ngraph::pass::SoftPlusDecomposition: public ngraph::pass::MatcherPass { +class ngraph::pass::SoftPlusDecomposition : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; SoftPlusDecomposition(); diff --git a/src/common/transformations/include/transformations/opset_conversions/convert_opset2_to_opset1.hpp b/src/common/transformations/include/transformations/opset_conversions/convert_opset2_to_opset1.hpp index d20b1364b98..7852fdc106c 100644 --- a/src/common/transformations/include/transformations/opset_conversions/convert_opset2_to_opset1.hpp +++ b/src/common/transformations/include/transformations/opset_conversions/convert_opset2_to_opset1.hpp @@ -5,8 +5,8 @@ #pragma once #include -#include #include +#include namespace ngraph { namespace pass { @@ -16,7 +16,7 @@ class TRANSFORMATIONS_API ConvertOpSet2ToOpSet1; } // namespace pass } // namespace ngraph -class ngraph::pass::ConvertOpSet2ToOpSet1: public ngraph::pass::FunctionPass { +class ngraph::pass::ConvertOpSet2ToOpSet1 : public ngraph::pass::FunctionPass { public: NGRAPH_RTTI_DECLARATION; bool run_on_model(const std::shared_ptr& m) override; diff --git a/src/common/transformations/include/transformations/opset_conversions/convert_opset3_to_opset2.hpp b/src/common/transformations/include/transformations/opset_conversions/convert_opset3_to_opset2.hpp index 7cbc7c1db91..80313a4ee9d 100644 --- a/src/common/transformations/include/transformations/opset_conversions/convert_opset3_to_opset2.hpp +++ b/src/common/transformations/include/transformations/opset_conversions/convert_opset3_to_opset2.hpp @@ -5,8 +5,8 @@ #pragma once #include -#include #include +#include namespace ngraph { namespace pass { @@ -16,7 +16,7 @@ class TRANSFORMATIONS_API ConvertOpSet3ToOpSet2; } // namespace pass } // namespace ngraph -class ngraph::pass::ConvertOpSet3ToOpSet2: public ngraph::pass::FunctionPass { +class ngraph::pass::ConvertOpSet3ToOpSet2 : public ngraph::pass::FunctionPass { public: NGRAPH_RTTI_DECLARATION; bool run_on_model(const std::shared_ptr& m) override; diff --git a/src/common/transformations/include/transformations/resolve_names_collisions.hpp b/src/common/transformations/include/transformations/resolve_names_collisions.hpp index 795efb59ff6..f87f74b7a5b 100644 --- a/src/common/transformations/include/transformations/resolve_names_collisions.hpp +++ b/src/common/transformations/include/transformations/resolve_names_collisions.hpp @@ -14,7 +14,7 @@ namespace pass { * @ingroup ie_transformation_common_api * @brief ResolveNameCollisions transformation helps to fix names collisions * if some internal nodes or nodes with autogenerated names have conflicts with other nodes from the original graph - * + * * Every transformation call can change the graph structure and create some additional operations, * autogenerated name is used if new operation doesn't have friendly name. * This transformations should be called after the transformation pipeline in order to fix names collisions. @@ -27,4 +27,3 @@ public: } // namespace pass } // namespace ov - diff --git a/src/common/transformations/include/transformations/rt_info/attributes.hpp b/src/common/transformations/include/transformations/rt_info/attributes.hpp index b52038f4138..8f500d956a8 100644 --- a/src/common/transformations/include/transformations/rt_info/attributes.hpp +++ b/src/common/transformations/include/transformations/rt_info/attributes.hpp @@ -9,19 +9,19 @@ #include #include #include -#include #include +#include #include +#include #include #include #include #include #include #include +#include #include #include -#include -#include #include #include @@ -36,7 +36,7 @@ public: private: template void register_factory() { - m_factory_registry.emplace(T::get_type_info_static(), [] () -> Any { + m_factory_registry.emplace(T::get_type_info_static(), []() -> Any { return T{}; }); } diff --git a/src/common/transformations/include/transformations/rt_info/decompression.hpp b/src/common/transformations/include/transformations/rt_info/decompression.hpp index 57753e81736..a7d9c0d106d 100644 --- a/src/common/transformations/include/transformations/rt_info/decompression.hpp +++ b/src/common/transformations/include/transformations/rt_info/decompression.hpp @@ -5,16 +5,16 @@ #pragma once #include + #include #include -#include #include +#include #include "openvino/core/node.hpp" #include "openvino/core/runtime_attribute.hpp" #include "transformations_visibility.hpp" - namespace ov { TRANSFORMATIONS_API void mark_as_decompression(const std::shared_ptr& node); @@ -34,9 +34,13 @@ public: Decompression() = default; - bool visit_attributes(AttributeVisitor& visitor) override { return true; } + bool visit_attributes(AttributeVisitor& visitor) override { + return true; + } - bool is_copyable() const override { return false; } + bool is_copyable() const override { + return false; + } }; } // namespace ov diff --git a/src/common/transformations/include/transformations/rt_info/disable_constant_folding.hpp b/src/common/transformations/include/transformations/rt_info/disable_constant_folding.hpp index e4e4bb8b526..50017e69048 100644 --- a/src/common/transformations/include/transformations/rt_info/disable_constant_folding.hpp +++ b/src/common/transformations/include/transformations/rt_info/disable_constant_folding.hpp @@ -5,21 +5,22 @@ #pragma once #include + #include #include -#include -#include - #include #include +#include +#include #include + #include "openvino/pass/constant_folding.hpp" namespace ov { -using pass::disable_constant_folding; -using pass::enable_constant_folding; using pass::constant_folding_is_disabled; +using pass::disable_constant_folding; using pass::DisableConstantFolding; +using pass::enable_constant_folding; } // namespace ov diff --git a/src/common/transformations/include/transformations/rt_info/disable_fp16_compression.hpp b/src/common/transformations/include/transformations/rt_info/disable_fp16_compression.hpp index cfcfda69363..d245ce23d0c 100644 --- a/src/common/transformations/include/transformations/rt_info/disable_fp16_compression.hpp +++ b/src/common/transformations/include/transformations/rt_info/disable_fp16_compression.hpp @@ -8,7 +8,6 @@ #include "openvino/core/runtime_attribute.hpp" #include "transformations_visibility.hpp" - namespace ov { TRANSFORMATIONS_API void disable_fp16_compression(const std::shared_ptr& node); @@ -28,7 +27,9 @@ public: DisableFP16Compression() = default; - bool is_copyable() const override { return false; } + bool is_copyable() const override { + return false; + } }; } // namespace ov diff --git a/src/common/transformations/include/transformations/rt_info/fused_names_attribute.hpp b/src/common/transformations/include/transformations/rt_info/fused_names_attribute.hpp index 8e7d9a54629..38d17031e83 100644 --- a/src/common/transformations/include/transformations/rt_info/fused_names_attribute.hpp +++ b/src/common/transformations/include/transformations/rt_info/fused_names_attribute.hpp @@ -10,17 +10,17 @@ #pragma once #include + #include #include -#include -#include - +#include #include #include #include -#include -#include "openvino/core/runtime_attribute.hpp" +#include +#include +#include "openvino/core/runtime_attribute.hpp" namespace ngraph { @@ -44,7 +44,7 @@ public: * @brief Constructs a new object consisting of a single name * * @param[in] name The name */ - explicit FusedNames(const std::string &name) { + explicit FusedNames(const std::string& name) { fused_names.insert(name); } @@ -52,7 +52,7 @@ public: * @brief Unites current set of already fused names with another FusedNames object * @param[in] names Another object to fuse with */ - void fuseWith(const FusedNames &names); + void fuseWith(const FusedNames& names); /** * @brief return string with operation names separated by coma in alphabetical order @@ -79,7 +79,7 @@ public: * @brief getFusedNames return string with operation names separated by coma in alphabetical order * @param[in] node The node will be used to get FusedNames attribute */ -NGRAPH_API std::string getFusedNames(const std::shared_ptr & node); +NGRAPH_API std::string getFusedNames(const std::shared_ptr& node); /** * @ingroup ie_runtime_attr_api @@ -87,6 +87,6 @@ NGRAPH_API std::string getFusedNames(const std::shared_ptr & node) * @param[in] node The node will be used to get FusedNames attribute * @return vector of strings */ -NGRAPH_API std::vector getFusedNamesVector(const std::shared_ptr & node); +NGRAPH_API std::vector getFusedNamesVector(const std::shared_ptr& node); } // namespace ngraph diff --git a/src/common/transformations/include/transformations/rt_info/nms_selected_indices.hpp b/src/common/transformations/include/transformations/rt_info/nms_selected_indices.hpp index 9928eaad0dd..2cad2935b5e 100644 --- a/src/common/transformations/include/transformations/rt_info/nms_selected_indices.hpp +++ b/src/common/transformations/include/transformations/rt_info/nms_selected_indices.hpp @@ -5,27 +5,30 @@ #pragma once #include + #include #include -#include -#include - #include #include +#include +#include #include + #include "openvino/core/runtime_attribute.hpp" namespace ov { -TRANSFORMATIONS_API bool has_nms_selected_indices(const Node * node); +TRANSFORMATIONS_API bool has_nms_selected_indices(const Node* node); -TRANSFORMATIONS_API void set_nms_selected_indices(Node * node); +TRANSFORMATIONS_API void set_nms_selected_indices(Node* node); class TRANSFORMATIONS_API NmsSelectedIndices : ov::RuntimeAttribute { public: OPENVINO_RTTI("nms_selected_indices", "0"); NmsSelectedIndices() = default; - bool is_copyable() const override { return false; } + bool is_copyable() const override { + return false; + } }; } // namespace ov diff --git a/src/common/transformations/include/transformations/rt_info/nonconvertible_divide.hpp b/src/common/transformations/include/transformations/rt_info/nonconvertible_divide.hpp index 4c29ee2ccc4..b1f78f7e0e7 100644 --- a/src/common/transformations/include/transformations/rt_info/nonconvertible_divide.hpp +++ b/src/common/transformations/include/transformations/rt_info/nonconvertible_divide.hpp @@ -8,7 +8,6 @@ #include "openvino/core/runtime_attribute.hpp" #include "transformations_visibility.hpp" - namespace ov { TRANSFORMATIONS_API void disable_divide_conversion(const std::shared_ptr& node); @@ -28,7 +27,9 @@ public: NonconvertibleDivide() = default; - bool is_copyable() const override { return false; } + bool is_copyable() const override { + return false; + } }; } // namespace ov diff --git a/src/common/transformations/include/transformations/rt_info/preprocessing_attribute.hpp b/src/common/transformations/include/transformations/rt_info/preprocessing_attribute.hpp index 9d45c93bd76..91752f275cd 100644 --- a/src/common/transformations/include/transformations/rt_info/preprocessing_attribute.hpp +++ b/src/common/transformations/include/transformations/rt_info/preprocessing_attribute.hpp @@ -23,6 +23,8 @@ class NGRAPH_API PreprocessingAttribute : public ov::RuntimeAttribute { public: OPENVINO_RTTI("preprocessing", "0"); PreprocessingAttribute() = default; - bool visit_attributes(AttributeVisitor& visitor) override { return true; }; + bool visit_attributes(AttributeVisitor& visitor) override { + return true; + }; }; -} // namespace ov +} // namespace ov diff --git a/src/common/transformations/include/transformations/rt_info/primitives_priority_attribute.hpp b/src/common/transformations/include/transformations/rt_info/primitives_priority_attribute.hpp index d5b4f984849..9042ad540e6 100644 --- a/src/common/transformations/include/transformations/rt_info/primitives_priority_attribute.hpp +++ b/src/common/transformations/include/transformations/rt_info/primitives_priority_attribute.hpp @@ -10,13 +10,13 @@ #pragma once #include + #include #include -#include -#include - #include #include +#include +#include #include "openvino/core/runtime_attribute.hpp" @@ -26,7 +26,7 @@ namespace ov { * @brief getPrimitivesPriority return string with primitive priorities value * @param[in] node The node will be used to get PrimitivesPriority attribute */ -NGRAPH_API std::string getPrimitivesPriority(const std::shared_ptr & node); +NGRAPH_API std::string getPrimitivesPriority(const std::shared_ptr& node); class NGRAPH_API PrimitivesPriority : public ov::RuntimeAttribute { public: @@ -34,11 +34,11 @@ public: PrimitivesPriority() = default; - PrimitivesPriority(const std::string &value) : value(value) {} + PrimitivesPriority(const std::string& value) : value(value) {} - Any merge(const ngraph::NodeVector & nodes) const override; + Any merge(const ngraph::NodeVector& nodes) const override; - bool visit_attributes(AttributeVisitor & visitor) override; + bool visit_attributes(AttributeVisitor& visitor) override; std::string to_string() const override; diff --git a/src/common/transformations/include/transformations/rt_info/strides_property.hpp b/src/common/transformations/include/transformations/rt_info/strides_property.hpp index 682d1150a11..5204543687a 100644 --- a/src/common/transformations/include/transformations/rt_info/strides_property.hpp +++ b/src/common/transformations/include/transformations/rt_info/strides_property.hpp @@ -4,10 +4,11 @@ #pragma once -#include #include +#include #include #include + #include "openvino/core/runtime_attribute.hpp" namespace ov { @@ -21,4 +22,4 @@ public: StridesPropagation(const ngraph::Strides& value) : value{value} {} ngraph::Strides value; }; -} // namespace ov +} // namespace ov diff --git a/src/common/transformations/include/transformations/smart_reshape/broadcast_const_range_replacement.hpp b/src/common/transformations/include/transformations/smart_reshape/broadcast_const_range_replacement.hpp index 6c0f449f9ea..8826269fc05 100644 --- a/src/common/transformations/include/transformations/smart_reshape/broadcast_const_range_replacement.hpp +++ b/src/common/transformations/include/transformations/smart_reshape/broadcast_const_range_replacement.hpp @@ -4,9 +4,8 @@ #pragma once -#include - #include +#include namespace ngraph { namespace pass { @@ -18,10 +17,11 @@ class TRANSFORMATIONS_API BroadcastConstRangeReplacement; /** * @ingroup ie_transformation_common_api - * @brief BroadcastConstRangeReplacement replaces Constant filled with range values starting from 0 and replaces it with Range op + * @brief BroadcastConstRangeReplacement replaces Constant filled with range values starting from 0 and replaces it with + * Range op */ -class ngraph::pass::BroadcastConstRangeReplacement: public ngraph::pass::MatcherPass { +class ngraph::pass::BroadcastConstRangeReplacement : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; BroadcastConstRangeReplacement(); diff --git a/src/common/transformations/include/transformations/smart_reshape/matmul_sr.hpp b/src/common/transformations/include/transformations/smart_reshape/matmul_sr.hpp index f949e8aa52c..6491f1a7f98 100644 --- a/src/common/transformations/include/transformations/smart_reshape/matmul_sr.hpp +++ b/src/common/transformations/include/transformations/smart_reshape/matmul_sr.hpp @@ -4,9 +4,8 @@ #pragma once -#include #include - +#include #include namespace ngraph { @@ -27,17 +26,17 @@ class NGRAPH_API TransposeMatMul; * - MatMul(any_input, Reshape(any_input, any_input)) */ -class ngraph::pass::ReshapeAMatMul: public ngraph::pass::MatcherPass { +class ngraph::pass::ReshapeAMatMul : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ReshapeAMatMul(); }; -class ngraph::pass::ReshapeBMatMul: public ngraph::pass::MatcherPass { +class ngraph::pass::ReshapeBMatMul : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; ReshapeBMatMul(); }; -class ngraph::pass::TransposeMatMul: public ngraph::pass::MatcherPass { +class ngraph::pass::TransposeMatMul : public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; TransposeMatMul(); diff --git a/src/common/transformations/include/transformations/smart_reshape/mimic_set_batch_size.hpp b/src/common/transformations/include/transformations/smart_reshape/mimic_set_batch_size.hpp index 050016f8880..6c326a5b39d 100644 --- a/src/common/transformations/include/transformations/smart_reshape/mimic_set_batch_size.hpp +++ b/src/common/transformations/include/transformations/smart_reshape/mimic_set_batch_size.hpp @@ -6,9 +6,8 @@ #include #include -#include - #include +#include namespace ngraph { namespace pass { diff --git a/src/common/transformations/include/transformations/smart_reshape/proposal_scales_stridedslice.hpp b/src/common/transformations/include/transformations/smart_reshape/proposal_scales_stridedslice.hpp index df9d2c467fa..876312acf64 100644 --- a/src/common/transformations/include/transformations/smart_reshape/proposal_scales_stridedslice.hpp +++ b/src/common/transformations/include/transformations/smart_reshape/proposal_scales_stridedslice.hpp @@ -4,10 +4,9 @@ #pragma once -#include #include - #include +#include namespace ngraph { namespace pass { diff --git a/src/common/transformations/include/transformations/smart_reshape/reshape_to_1D.hpp b/src/common/transformations/include/transformations/smart_reshape/reshape_to_1D.hpp index e7608b55a33..dda1f18d654 100644 --- a/src/common/transformations/include/transformations/smart_reshape/reshape_to_1D.hpp +++ b/src/common/transformations/include/transformations/smart_reshape/reshape_to_1D.hpp @@ -4,10 +4,9 @@ #pragma once -#include #include - #include +#include namespace ngraph { namespace pass { diff --git a/src/common/transformations/include/transformations/smart_reshape/set_batch_size.hpp b/src/common/transformations/include/transformations/smart_reshape/set_batch_size.hpp index b306ce479c4..c4f7fb79fce 100644 --- a/src/common/transformations/include/transformations/smart_reshape/set_batch_size.hpp +++ b/src/common/transformations/include/transformations/smart_reshape/set_batch_size.hpp @@ -4,10 +4,9 @@ #pragma once -#include #include - #include +#include namespace ngraph { namespace pass { @@ -22,7 +21,7 @@ class NGRAPH_API SetBatchSize; * @brief Generic caller for all the transformations responsible to make model reshape-able by batch dimension */ -class ngraph::pass::SetBatchSize: public ngraph::pass::FunctionPass { +class ngraph::pass::SetBatchSize : public ngraph::pass::FunctionPass { public: NGRAPH_RTTI_DECLARATION; bool run_on_model(const std::shared_ptr& m) override; diff --git a/src/common/transformations/include/transformations/smart_reshape/smart_reshape.hpp b/src/common/transformations/include/transformations/smart_reshape/smart_reshape.hpp index 45c1ff1bcc7..7893fe065f8 100644 --- a/src/common/transformations/include/transformations/smart_reshape/smart_reshape.hpp +++ b/src/common/transformations/include/transformations/smart_reshape/smart_reshape.hpp @@ -4,10 +4,9 @@ #pragma once -#include #include - #include +#include namespace ngraph { namespace pass { @@ -17,7 +16,7 @@ class NGRAPH_API SmartReshape; } // namespace pass } // namespace ngraph -class ngraph::pass::SmartReshape: public ngraph::pass::FunctionPass { +class ngraph::pass::SmartReshape : public ngraph::pass::FunctionPass { public: NGRAPH_RTTI_DECLARATION; bool run_on_model(const std::shared_ptr& m) override; diff --git a/src/common/transformations/include/transformations/smart_reshape/strided_slice_squeeze.hpp b/src/common/transformations/include/transformations/smart_reshape/strided_slice_squeeze.hpp index b8985cad652..b6d3fa907a5 100644 --- a/src/common/transformations/include/transformations/smart_reshape/strided_slice_squeeze.hpp +++ b/src/common/transformations/include/transformations/smart_reshape/strided_slice_squeeze.hpp @@ -4,10 +4,9 @@ #pragma once -#include #include - #include +#include namespace ngraph { namespace pass { @@ -21,7 +20,8 @@ class NGRAPH_API SharedSqueeze; /** * @ingroup ie_transformation_common_api - * @brief StridedSliceSqueeze transformation looks for SS -> Squeeze and corrects SS inputs and attributes for SS output to be squeeze-able + * @brief StridedSliceSqueeze transformation looks for SS -> Squeeze and corrects SS inputs and attributes for SS output + * to be squeeze-able */ class ngraph::pass::StridedSliceSqueeze : public ngraph::pass::MatcherPass { @@ -32,7 +32,8 @@ public: /** * @ingroup ie_transformation_common_api - * @brief StridedSliceSqueeze transformation looks for Squeeze -> SSe and corrects SS inputs and attributes for SS output to be squeeze-able + * @brief StridedSliceSqueeze transformation looks for Squeeze -> SSe and corrects SS inputs and attributes for SS + * output to be squeeze-able */ class ngraph::pass::SqueezeStridedSlice : public ngraph::pass::MatcherPass { @@ -43,7 +44,8 @@ public: /** * @ingroup ie_transformation_common_api - * @brief SharedSqueeze transformation looks for shared Squeezes and leaves only one Squeeze reconnecting all the outputs to it + * @brief SharedSqueeze transformation looks for shared Squeezes and leaves only one Squeeze reconnecting all the + * outputs to it */ class ngraph::pass::SharedSqueeze : public ngraph::pass::FunctionPass { diff --git a/src/common/transformations/include/transformations/utils/utils.hpp b/src/common/transformations/include/transformations/utils/utils.hpp index a6c017e1e30..f62b7e51f43 100644 --- a/src/common/transformations/include/transformations/utils/utils.hpp +++ b/src/common/transformations/include/transformations/utils/utils.hpp @@ -4,32 +4,32 @@ #pragma once -#include -#include #include -#include -#include -#include -#include +#include +#include +#include #include +#include #include #include #include - -#include -#include #include +#include +#include #include +#include +#include namespace ngraph { namespace op { namespace util { template -bool normalize_single_value(std::vector vec, float & value) { - for (const auto & val : vec) { - if (val != *vec.begin()) return false; +bool normalize_single_value(std::vector vec, float& value) { + for (const auto& val : vec) { + if (val != *vec.begin()) + return false; } float ref_val = static_cast(*vec.begin()); @@ -43,8 +43,8 @@ bool normalize_single_value(std::vector vec, float & value) { } template -bool has_op_with_type(const std::shared_ptr &function) { - for (const auto & op : function->get_ops()) { +bool has_op_with_type(const std::shared_ptr& function) { + for (const auto& op : function->get_ops()) { if (std::dynamic_pointer_cast(op)) { return true; } @@ -104,21 +104,18 @@ bool has_constant_value(const std::shared_ptr& node, return false; } - const bool is_scalar_or_single_elem = is_scalar(constant->get_shape()) || - shape_size(constant->get_shape()) == 1; + const bool is_scalar_or_single_elem = is_scalar(constant->get_shape()) || shape_size(constant->get_shape()) == 1; if (!is_scalar_or_single_elem) { return false; } - if (constant->get_element_type() == ngraph::element::f16 || - constant->get_element_type() == ngraph::element::f32 || - constant->get_element_type() == ngraph::element::f64 || - constant->get_element_type() == ngraph::element::bf16) { - const auto data = constant->cast_vector(); - if (std::fabs(data[0] - value) > epsilon) { - return false; - } - } else { + if (constant->get_element_type() == ngraph::element::f16 || constant->get_element_type() == ngraph::element::f32 || + constant->get_element_type() == ngraph::element::f64 || constant->get_element_type() == ngraph::element::bf16) { + const auto data = constant->cast_vector(); + if (std::fabs(data[0] - value) > epsilon) { + return false; + } + } else { const auto data = constant->cast_vector(); if (data[0] != value) { return false; @@ -143,44 +140,47 @@ bool has_constant_value(const std::shared_ptr& node, const auto const_values = constant->cast_vector(); - if (constant->get_element_type() == ngraph::element::f16 || - constant->get_element_type() == ngraph::element::f32 || - constant->get_element_type() == ngraph::element::f64 || - constant->get_element_type() == ngraph::element::bf16) { - return std::equal(const_values.cbegin(), const_values.cend(), values.cbegin(), - [&] (T lhs, T rhs) { return std::fabs(lhs - rhs) < epsilon; }); + if (constant->get_element_type() == ngraph::element::f16 || constant->get_element_type() == ngraph::element::f32 || + constant->get_element_type() == ngraph::element::f64 || constant->get_element_type() == ngraph::element::bf16) { + return std::equal(const_values.cbegin(), const_values.cend(), values.cbegin(), [&](T lhs, T rhs) { + return std::fabs(lhs - rhs) < epsilon; + }); } return const_values == values; } -TRANSFORMATIONS_API bool get_single_value(const std::shared_ptr & const_node, float & value); +TRANSFORMATIONS_API bool get_single_value(const std::shared_ptr& const_node, float& value); -TRANSFORMATIONS_API std::shared_ptr normalize_constant(const std::shared_ptr & constant, - const PartialShape & shape); +TRANSFORMATIONS_API std::shared_ptr normalize_constant(const std::shared_ptr& constant, + const PartialShape& shape); TRANSFORMATIONS_API std::shared_ptr broadcastTo(const Output& input, const Shape& shape); -TRANSFORMATIONS_API std::shared_ptr reshapeTo(const Output & input, const Shape& shape); +TRANSFORMATIONS_API std::shared_ptr reshapeTo(const Output& input, const Shape& shape); -TRANSFORMATIONS_API bool constantIsEqualTo(const std::shared_ptr& const_node, float value, float eps = 1e-5); +TRANSFORMATIONS_API bool constantIsEqualTo(const std::shared_ptr& const_node, + float value, + float eps = 1e-5); -TRANSFORMATIONS_API bool has_f16_constants(const std::shared_ptr &function); +TRANSFORMATIONS_API bool has_f16_constants(const std::shared_ptr& function); -TRANSFORMATIONS_API bool check_for_broadcast(const ngraph::PartialShape &ref_shape, const ngraph::PartialShape &other_shape); +TRANSFORMATIONS_API bool check_for_broadcast(const ngraph::PartialShape& ref_shape, + const ngraph::PartialShape& other_shape); TRANSFORMATIONS_API std::shared_ptr activation(const std::string& activation_name, const ngraph::Output& apply_to); -TRANSFORMATIONS_API bool is_seq_len_provided(const std::shared_ptr &seq_len_input, int64_t max_seq_len); +TRANSFORMATIONS_API bool is_seq_len_provided(const std::shared_ptr& seq_len_input, int64_t max_seq_len); TRANSFORMATIONS_API std::shared_ptr try_fold_unary_output(const std::shared_ptr& node); TRANSFORMATIONS_API std::shared_ptr clone_try_fold(const std::shared_ptr& node, const OutputVector& inputs); -TRANSFORMATIONS_API bool shapes_equal_except_dynamic_expected_batch(const ngraph::PartialShape& expected, const ngraph::PartialShape& actual); +TRANSFORMATIONS_API bool shapes_equal_except_dynamic_expected_batch(const ngraph::PartialShape& expected, + const ngraph::PartialShape& actual); -TRANSFORMATIONS_API void visit_shape_path(ov::Node * node, +TRANSFORMATIONS_API void visit_shape_path(ov::Node* node, std::unordered_set& visited, std::function func); @@ -191,7 +191,7 @@ std::shared_ptr make_try_fold(Args&&... args) { } template -Output eltwise_fold(const Output & input0, const Output & input1) { +Output eltwise_fold(const Output& input0, const Output& input1) { auto eltwise = std::make_shared(input0, input1); OutputVector output(eltwise->get_output_size()); if (!eltwise->constant_fold(output, {input0, input1})) { @@ -206,14 +206,18 @@ Output eltwise_fold(const Output & input0, const Output & inpu TRANSFORMATIONS_API std::vector> get_node_target_inputs(const std::shared_ptr& node); TRANSFORMATIONS_API std::shared_ptr node_to_get_shape_value_of_indices_from_shape_node( - const std::shared_ptr& shape_node, const std::vector& indices); + const std::shared_ptr& shape_node, + const std::vector& indices); TRANSFORMATIONS_API std::shared_ptr node_to_get_shape_value_of_indices_from_shape_source( - const ngraph::Output& shape_source, const std::vector& indices); + const ngraph::Output& shape_source, + const std::vector& indices); TRANSFORMATIONS_API bool is_dequantization_subgraph(const Output& node); -TRANSFORMATIONS_API bool can_eliminate_eltwise_node(const std::shared_ptr& eltwise, const Output& constant, const Output& non_constant_input); +TRANSFORMATIONS_API bool can_eliminate_eltwise_node(const std::shared_ptr& eltwise, + const Output& constant, + const Output& non_constant_input); } // namespace util } // namespace op } // namespace ngraph diff --git a/src/common/transformations/src/ngraph_ops/nms_ie_internal.cpp b/src/common/transformations/src/ngraph_ops/nms_ie_internal.cpp index 12dcbea44c5..8af20ba8a86 100644 --- a/src/common/transformations/src/ngraph_ops/nms_ie_internal.cpp +++ b/src/common/transformations/src/ngraph_ops/nms_ie_internal.cpp @@ -2,10 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 // -#include - -#include #include "ngraph_ops/nms_ie_internal.hpp" + +#include +#include + #include "itt.hpp" using namespace std; @@ -22,9 +23,11 @@ op::internal::NonMaxSuppressionIEInternal::NonMaxSuppressionIEInternal(const Out bool sort_result_descending, const ngraph::element::Type& output_type, const ngraph::element::Type& score_output_type) - : Op({boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold}), - m_center_point_box(center_point_box), m_sort_result_descending(sort_result_descending), m_output_type(output_type), - m_scores_output_type(score_output_type) { + : Op({boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold}), + m_center_point_box(center_point_box), + m_sort_result_descending(sort_result_descending), + m_output_type(output_type), + m_scores_output_type(score_output_type) { constructor_validate_and_infer_types(); } @@ -38,22 +41,36 @@ op::internal::NonMaxSuppressionIEInternal::NonMaxSuppressionIEInternal(const Out bool sort_result_descending, const ngraph::element::Type& output_type, const ngraph::element::Type& score_output_type) - : Op({boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold, soft_nms_sigma}), - m_center_point_box(center_point_box), m_sort_result_descending(sort_result_descending), m_output_type(output_type), - m_scores_output_type(score_output_type) { + : Op({boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold, soft_nms_sigma}), + m_center_point_box(center_point_box), + m_sort_result_descending(sort_result_descending), + m_output_type(output_type), + m_scores_output_type(score_output_type) { constructor_validate_and_infer_types(); } -std::shared_ptr op::internal::NonMaxSuppressionIEInternal::clone_with_new_inputs(const ngraph::OutputVector &new_args) const { +std::shared_ptr op::internal::NonMaxSuppressionIEInternal::clone_with_new_inputs( + const ngraph::OutputVector& new_args) const { INTERNAL_OP_SCOPE(internal_NonMaxSuppressionIEInternal_clone_with_new_inputs); if (new_args.size() == 6) { - return make_shared(new_args.at(0), new_args.at(1), new_args.at(2), new_args.at(3), - new_args.at(4), new_args.at(5), m_center_point_box, m_sort_result_descending, - m_output_type); + return make_shared(new_args.at(0), + new_args.at(1), + new_args.at(2), + new_args.at(3), + new_args.at(4), + new_args.at(5), + m_center_point_box, + m_sort_result_descending, + m_output_type); } else if (new_args.size() == 5) { - return make_shared(new_args.at(0), new_args.at(1), new_args.at(2), new_args.at(3), - new_args.at(4), m_center_point_box, m_sort_result_descending, - m_output_type); + return make_shared(new_args.at(0), + new_args.at(1), + new_args.at(2), + new_args.at(3), + new_args.at(4), + m_center_point_box, + m_sort_result_descending, + m_output_type); } throw ngraph::ngraph_error("Unsupported number of inputs: " + std::to_string(new_args.size())); } @@ -104,8 +121,7 @@ void op::internal::NonMaxSuppressionIEInternal::validate_and_infer_types() { const auto num_classes = scores_ps[1].get_length(); const auto max_output_boxes_per_class = max_boxes_output_from_input(); - out_shape[0] = std::min(num_boxes, max_output_boxes_per_class) * num_classes * - scores_ps[0].get_length(); + out_shape[0] = std::min(num_boxes, max_output_boxes_per_class) * num_classes * scores_ps[0].get_length(); } } diff --git a/src/common/transformations/src/ngraph_ops/nms_static_shape_ie.cpp b/src/common/transformations/src/ngraph_ops/nms_static_shape_ie.cpp index de4b2609eeb..db1669e186d 100644 --- a/src/common/transformations/src/ngraph_ops/nms_static_shape_ie.cpp +++ b/src/common/transformations/src/ngraph_ops/nms_static_shape_ie.cpp @@ -2,10 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 // -#include - +// clang-format off #include "ngraph/ops.hpp" #include "ngraph_ops/nms_static_shape_ie.hpp" +// clang-format on + +#include namespace ngraph { namespace op { diff --git a/src/common/transformations/src/transformations/common_optimizations/add_fake_quantize_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/add_fake_quantize_fusion.cpp index 427993670d1..9811947e555 100644 --- a/src/common/transformations/src/transformations/common_optimizations/add_fake_quantize_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/add_fake_quantize_fusion.cpp @@ -3,17 +3,16 @@ // #include "transformations/common_optimizations/add_fake_quantize_fusion.hpp" -#include "transformations/utils/utils.hpp" #include +#include +#include +#include +#include #include -#include -#include -#include -#include #include "itt.hpp" - +#include "transformations/utils/utils.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::AddFakeQuantizeFusion, "AddFakeQuantizeFusion", 0); @@ -21,8 +20,8 @@ ngraph::pass::AddFakeQuantizeFusion::AddFakeQuantizeFusion() { MATCHER_SCOPE(AddFakeQuantizeFusion); auto input_pattern = ngraph::pattern::any_input(); auto const_pattern = ngraph::pattern::wrap_type(); - auto add_pattern = ngraph::pattern::wrap_type({input_pattern, const_pattern}, - pattern::consumers_count(1)); + auto add_pattern = + ngraph::pattern::wrap_type({input_pattern, const_pattern}, pattern::consumers_count(1)); auto fq_pattern = ngraph::pattern::wrap_type({add_pattern, ngraph::pattern::any_input(), ngraph::pattern::any_input(), @@ -34,11 +33,13 @@ ngraph::pass::AddFakeQuantizeFusion::AddFakeQuantizeFusion() { const auto& type = input.get_element_type(); if (type.bitwidth() < element::f32.bitwidth()) return false; - auto fq = std::dynamic_pointer_cast(pattern_value_map.at(fq_pattern).get_node_shared_ptr()); + auto fq = + std::dynamic_pointer_cast(pattern_value_map.at(fq_pattern).get_node_shared_ptr()); if (!fq) return false; const auto& add_node = pattern_value_map.at(add_pattern).get_node_shared_ptr(); - auto add_const = std::dynamic_pointer_cast(pattern_value_map.at(const_pattern).get_node_shared_ptr()); + auto add_const = + std::dynamic_pointer_cast(pattern_value_map.at(const_pattern).get_node_shared_ptr()); if (!add_const) return false; @@ -71,8 +72,10 @@ ngraph::pass::AddFakeQuantizeFusion::AddFakeQuantizeFusion() { if (diff > 0) { // Reshape constants like (C, 1, 1) to (1, C, 1, 1) const_shape.insert(const_shape.begin(), diff, 1); - new_const = std::make_shared(new_const, - op::Constant::create(element::u64, Shape{const_shape.size()}, const_shape), false); + new_const = std::make_shared( + new_const, + op::Constant::create(element::u64, Shape{const_shape.size()}, const_shape), + false); } // disallow constant shapes other than (N, 1, 1, ..., 1) or (1, C, 1, ..., 1) @@ -84,23 +87,21 @@ ngraph::pass::AddFakeQuantizeFusion::AddFakeQuantizeFusion() { // Convolution+Add or MatMul+Add can be fused later // so don't fuse Add+FQ in that situation const auto& add_inputs = add_node->input_values(); - bool add_parent_is_conv_or_mm = std::any_of(add_inputs.begin(), add_inputs.end(), - [] (const Output& node) -> bool { - auto node_ptr = node.get_node(); - return is_type(node_ptr) || - is_type(node_ptr) || - is_type(node_ptr) || - is_type(node_ptr) || - is_type(node_ptr); - }); + bool add_parent_is_conv_or_mm = + std::any_of(add_inputs.begin(), add_inputs.end(), [](const Output& node) -> bool { + auto node_ptr = node.get_node(); + return is_type(node_ptr) || is_type(node_ptr) || + is_type(node_ptr) || + is_type(node_ptr) || is_type(node_ptr); + }); if (add_parent_is_conv_or_mm) return false; auto fq_users = fq->get_users(); // Concat LPT transformation supports per tensor quantization only - bool fq_user_is_concat = std::any_of(fq_users.begin(), fq_users.end(), - [] (const std::shared_ptr node_ptr) -> bool { - return is_type(node_ptr); - }); + bool fq_user_is_concat = + std::any_of(fq_users.begin(), fq_users.end(), [](const std::shared_ptr node_ptr) -> bool { + return is_type(node_ptr); + }); if (fq_user_is_concat) return false; } @@ -113,11 +114,8 @@ ngraph::pass::AddFakeQuantizeFusion::AddFakeQuantizeFusion() { std::shared_ptr new_input_high = get_constant_from_source(input_high_sub); if (!new_input_high) new_input_high = input_high_sub; - auto new_fq = fq->clone_with_new_inputs({input, - new_input_low, - new_input_high, - fq->input_value(3), - fq->input_value(4)}); + auto new_fq = + fq->clone_with_new_inputs({input, new_input_low, new_input_high, fq->input_value(3), fq->input_value(4)}); if (transformation_callback(new_fq)) return false; register_new_node(new_fq); diff --git a/src/common/transformations/src/transformations/common_optimizations/align_eltwise_input_ranks.cpp b/src/common/transformations/src/transformations/common_optimizations/align_eltwise_input_ranks.cpp index cc3ad56fc6c..7dc91d29333 100644 --- a/src/common/transformations/src/transformations/common_optimizations/align_eltwise_input_ranks.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/align_eltwise_input_ranks.cpp @@ -34,8 +34,9 @@ ngraph::pass::AlignEltwiseInputRanks::AlignEltwiseInputRanks() { // So we skip extending Multiply's constant input rank here. if (ov::is_type(node)) { auto inputs = node->input_values(); - if (std::any_of(inputs.begin(), inputs.end(), - [] (const Output& input) -> bool { return ov::is_type(input.get_node()); })) + if (std::any_of(inputs.begin(), inputs.end(), [](const Output& input) -> bool { + return ov::is_type(input.get_node()); + })) return false; } diff --git a/src/common/transformations/src/transformations/common_optimizations/batch_to_space_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/batch_to_space_fusion.cpp index f1ed56be0f8..ae1e21371e2 100644 --- a/src/common/transformations/src/transformations/common_optimizations/batch_to_space_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/batch_to_space_fusion.cpp @@ -3,68 +3,79 @@ // #include "transformations/common_optimizations/batch_to_space_fusion.hpp" -#include "transformations/utils/utils.hpp" #include +#include +#include +#include +#include #include -#include -#include -#include -#include #include "itt.hpp" - +#include "transformations/utils/utils.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::BatchToSpaceFusion, "BatchToSpaceFusion", 0); ngraph::pass::BatchToSpaceFusion::BatchToSpaceFusion() { MATCHER_SCOPE(BatchToSpaceFusion); auto data_pattern = pattern::any_input(pattern::has_static_shape()); - auto reshape_before_pattern = pattern::wrap_type({data_pattern, pattern::wrap_type()}, pattern::rank_equals(4)); - auto trans_before_pattern = pattern::wrap_type({data_pattern, pattern::wrap_type()}, pattern::rank_equals(4)); - auto reshape_or_transpose_before_pattern = std::make_shared(OutputVector{reshape_before_pattern, trans_before_pattern}); + auto reshape_before_pattern = + pattern::wrap_type({data_pattern, pattern::wrap_type()}, + pattern::rank_equals(4)); + auto trans_before_pattern = + pattern::wrap_type({data_pattern, pattern::wrap_type()}, + pattern::rank_equals(4)); + auto reshape_or_transpose_before_pattern = + std::make_shared(OutputVector{reshape_before_pattern, trans_before_pattern}); auto depth_to_space_pattern = pattern::wrap_type({reshape_or_transpose_before_pattern}); auto starts_pattern = pattern::wrap_type(); auto ends_pattern = pattern::wrap_type(); - auto slice_pattern = pattern::wrap_type({depth_to_space_pattern, starts_pattern, ends_pattern, - pattern::wrap_type()}); - auto reshape_after_pattern = pattern::wrap_type({slice_pattern, pattern::wrap_type()}, pattern::rank_equals(4)); - auto trans_after_pattern = pattern::wrap_type({slice_pattern, pattern::wrap_type()}, pattern::rank_equals(4)); - auto reshape_or_transpose_after_pattern = std::make_shared(OutputVector{reshape_after_pattern, trans_after_pattern}); + auto slice_pattern = pattern::wrap_type( + {depth_to_space_pattern, starts_pattern, ends_pattern, pattern::wrap_type()}); + auto reshape_after_pattern = + pattern::wrap_type({slice_pattern, pattern::wrap_type()}, + pattern::rank_equals(4)); + auto trans_after_pattern = + pattern::wrap_type({slice_pattern, pattern::wrap_type()}, + pattern::rank_equals(4)); + auto reshape_or_transpose_after_pattern = + std::make_shared(OutputVector{reshape_after_pattern, trans_after_pattern}); ngraph::matcher_pass_callback callback = [=](pattern::Matcher& m) { const auto& pattern_map = m.get_pattern_value_map(); - auto get_reshape_or_transpose = [&pattern_map] (const std::shared_ptr& reshape_pattern, - const std::shared_ptr& trans_pattern) -> std::shared_ptr { + auto get_reshape_or_transpose = [&pattern_map]( + const std::shared_ptr& reshape_pattern, + const std::shared_ptr& trans_pattern) -> std::shared_ptr { if (pattern_map.count(reshape_pattern)) return pattern_map.at(reshape_pattern).get_node_shared_ptr(); if (pattern_map.count(trans_pattern)) return pattern_map.at(trans_pattern).get_node_shared_ptr(); return nullptr; }; - auto check_input_output_shape = [] (const std::shared_ptr& node) -> bool { + auto check_input_output_shape = [](const std::shared_ptr& node) -> bool { const auto& input_shape = node->get_input_shape(0); const auto& output_shape = node->get_output_shape(0); // Transpose permutation has to be [1, 0, 2, 3] - return input_shape[0] == output_shape[1] && - input_shape[1] == output_shape[0] && - input_shape[2] == output_shape[2] && - input_shape[3] == output_shape[3]; + return input_shape[0] == output_shape[1] && input_shape[1] == output_shape[0] && + input_shape[2] == output_shape[2] && input_shape[3] == output_shape[3]; }; - std::shared_ptr reshape_or_trans_before = get_reshape_or_transpose(reshape_before_pattern, trans_before_pattern); + std::shared_ptr reshape_or_trans_before = + get_reshape_or_transpose(reshape_before_pattern, trans_before_pattern); if (!reshape_or_trans_before) return false; if (!check_input_output_shape(reshape_or_trans_before)) return false; - std::shared_ptr reshape_or_trans_after = get_reshape_or_transpose(reshape_after_pattern, trans_after_pattern); + std::shared_ptr reshape_or_trans_after = + get_reshape_or_transpose(reshape_after_pattern, trans_after_pattern); if (!reshape_or_trans_after) return false; if (!check_input_output_shape(reshape_or_trans_after)) return false; - auto depth_to_space = std::dynamic_pointer_cast(pattern_map.at(depth_to_space_pattern).get_node_shared_ptr()); + auto depth_to_space = std::dynamic_pointer_cast( + pattern_map.at(depth_to_space_pattern).get_node_shared_ptr()); if (!depth_to_space) return false; if (depth_to_space->get_mode() != opset6::DepthToSpace::DepthToSpaceMode::BLOCKS_FIRST) @@ -73,8 +84,8 @@ ngraph::pass::BatchToSpaceFusion::BatchToSpaceFusion() { if (dts_shape.size() != 4) return false; auto block_size = static_cast(depth_to_space->get_block_size()); - auto block_shape = op::Constant::create(element::i64, Shape{4}, - std::vector{1, 1, block_size, block_size}); + auto block_shape = + op::Constant::create(element::i64, Shape{4}, std::vector{1, 1, block_size, block_size}); auto starts = std::dynamic_pointer_cast(pattern_map.at(starts_pattern).get_node_shared_ptr()); if (!starts) return false; @@ -99,15 +110,16 @@ ngraph::pass::BatchToSpaceFusion::BatchToSpaceFusion() { } auto crops_begin = op::Constant::create(element::i64, Shape{4}, starts_value); auto crops_end = op::Constant::create(element::i64, Shape{4}, ends_value); - auto batch_to_space = register_new_node(pattern_map.at(data_pattern), block_shape, crops_begin, crops_end); + auto batch_to_space = register_new_node(pattern_map.at(data_pattern), + block_shape, + crops_begin, + crops_end); batch_to_space->set_friendly_name(reshape_or_trans_after->get_friendly_name()); - copy_runtime_info({ - reshape_or_trans_before, - depth_to_space, - pattern_map.at(slice_pattern).get_node_shared_ptr(), - reshape_or_trans_after - }, + copy_runtime_info({reshape_or_trans_before, + depth_to_space, + pattern_map.at(slice_pattern).get_node_shared_ptr(), + reshape_or_trans_after}, batch_to_space); replace_node(reshape_or_trans_after, batch_to_space); diff --git a/src/common/transformations/src/transformations/common_optimizations/binarize_weights.cpp b/src/common/transformations/src/transformations/common_optimizations/binarize_weights.cpp index 3a5d88b7368..69c0fd0802e 100644 --- a/src/common/transformations/src/transformations/common_optimizations/binarize_weights.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/binarize_weights.cpp @@ -3,20 +3,19 @@ // #include "transformations/common_optimizations/binarize_weights.hpp" -#include "itt.hpp" #include -#include - #include #include #include +#include + +#include "itt.hpp" using namespace ngraph; NGRAPH_RTTI_DEFINITION(pass::BinarizeWeights, "BinarizeWeights", 0); - static float quantize(float f, float input_low, float input_high, float output_low, float output_high) { if (f <= input_low) return output_low; @@ -25,10 +24,14 @@ static float quantize(float f, float input_low, float input_high, float output_l return std::round((f - input_low) / (input_high - input_low)) * (output_high - output_low) + output_low; } - -static std::vector quantize_weights(const Shape& weights_shape, std::vector& weights, - Shape input_low_high_shape, const std::vector& input_low, const std::vector& input_high, - Shape output_low_high_shape, const std::vector& output_low, const std::vector& output_high) { +static std::vector quantize_weights(const Shape& weights_shape, + std::vector& weights, + Shape input_low_high_shape, + const std::vector& input_low, + const std::vector& input_high, + Shape output_low_high_shape, + const std::vector& output_low, + const std::vector& output_high) { NGRAPH_CHECK(shape_size(input_low_high_shape) == 1 || shape_size(input_low_high_shape) == weights_shape[0]); NGRAPH_CHECK(shape_size(output_low_high_shape) == 1 || shape_size(output_low_high_shape) == weights_shape[0]); size_t out_feat_off = 1; @@ -38,54 +41,54 @@ static std::vector quantize_weights(const Shape& weights_shape, std::vect std::vector out; out.reserve(shape_size(weights_shape)); - auto get_idx = [out_feat_off] (size_t i, const Shape& shape) -> size_t { + auto get_idx = [out_feat_off](size_t i, const Shape& shape) -> size_t { return (i / out_feat_off) % shape[0]; }; for (size_t i = 0; i < shape_size(weights_shape); i++) { size_t in_idx = get_idx(i, input_low_high_shape); size_t out_idx = get_idx(i, output_low_high_shape); - out.push_back(quantize(weights[i], input_low[in_idx], input_high[in_idx], output_low[out_idx], output_high[out_idx])); + out.push_back( + quantize(weights[i], input_low[in_idx], input_high[in_idx], output_low[out_idx], output_high[out_idx])); } return out; } - pass::BinarizeWeights::BinarizeWeights() { MATCHER_SCOPE(BinarizeWeights); - auto activations_fq_pattern = pattern::wrap_type( - {pattern::any_input(), - pattern::wrap_type(), - pattern::wrap_type(), - pattern::wrap_type(), - pattern::wrap_type()}, - pattern::consumers_count(1)); - auto weights_fq_pattern = pattern::wrap_type( - {pattern::wrap_type(), - pattern::wrap_type(), - pattern::wrap_type(), - pattern::wrap_type(), - pattern::wrap_type()}, - pattern::consumers_count(1)); + auto activations_fq_pattern = pattern::wrap_type({pattern::any_input(), + pattern::wrap_type(), + pattern::wrap_type(), + pattern::wrap_type(), + pattern::wrap_type()}, + pattern::consumers_count(1)); + auto weights_fq_pattern = pattern::wrap_type({pattern::wrap_type(), + pattern::wrap_type(), + pattern::wrap_type(), + pattern::wrap_type(), + pattern::wrap_type()}, + pattern::consumers_count(1)); auto conv_pattern = pattern::wrap_type({activations_fq_pattern, weights_fq_pattern}); - matcher_pass_callback callback = [=](pattern::Matcher &m) { + matcher_pass_callback callback = [=](pattern::Matcher& m) { auto conv = std::dynamic_pointer_cast(m.get_match_root()); if (!conv) return false; - auto activations_fq = std::dynamic_pointer_cast(conv->input_value(0).get_node_shared_ptr()); + auto activations_fq = + std::dynamic_pointer_cast(conv->input_value(0).get_node_shared_ptr()); if (!activations_fq || activations_fq->get_levels() != 2) return false; auto weights_fq = std::dynamic_pointer_cast(conv->input_value(1).get_node_shared_ptr()); if (!weights_fq || weights_fq->get_levels() != 2) return false; - auto weights_const = std::dynamic_pointer_cast(weights_fq->input_value(0).get_node_shared_ptr()); + auto weights_const = + std::dynamic_pointer_cast(weights_fq->input_value(0).get_node_shared_ptr()); if (!weights_const) return false; - auto check_output_low_high = [] (const std::vector& output_low, - const std::vector& output_high) -> std::tuple { + auto check_output_low_high = [](const std::vector& output_low, + const std::vector& output_high) -> std::tuple { bool output_low_is_zero = true; bool output_low_high_are_opposite = true; for (size_t i = 0; i < output_low.size(); i++) { @@ -95,8 +98,10 @@ pass::BinarizeWeights::BinarizeWeights() { return std::tuple{output_low_is_zero, output_low_high_are_opposite}; }; - auto activations_output_low_const = std::dynamic_pointer_cast(activations_fq->input_value(3).get_node_shared_ptr()); - auto activations_output_high_const = std::dynamic_pointer_cast(activations_fq->input_value(4).get_node_shared_ptr()); + auto activations_output_low_const = + std::dynamic_pointer_cast(activations_fq->input_value(3).get_node_shared_ptr()); + auto activations_output_high_const = + std::dynamic_pointer_cast(activations_fq->input_value(4).get_node_shared_ptr()); if (!activations_output_low_const || !activations_output_high_const) return false; @@ -105,17 +110,21 @@ pass::BinarizeWeights::BinarizeWeights() { bool act_out_low_high_are_opposite = false; auto activations_output_low = activations_output_low_const->cast_vector(); auto activations_output_high = activations_output_high_const->cast_vector(); - std::tie(act_out_low_is_zero, act_out_low_high_are_opposite) = check_output_low_high(activations_output_low, - activations_output_high); + std::tie(act_out_low_is_zero, act_out_low_high_are_opposite) = + check_output_low_high(activations_output_low, activations_output_high); if (!(act_out_low_high_are_opposite || act_out_low_is_zero)) return false; - auto weights_input_low_const = std::dynamic_pointer_cast(weights_fq->input_value(1).get_node_shared_ptr()); - auto weights_input_high_const = std::dynamic_pointer_cast(weights_fq->input_value(2).get_node_shared_ptr()); + auto weights_input_low_const = + std::dynamic_pointer_cast(weights_fq->input_value(1).get_node_shared_ptr()); + auto weights_input_high_const = + std::dynamic_pointer_cast(weights_fq->input_value(2).get_node_shared_ptr()); if (!weights_input_low_const || !weights_input_high_const) return false; - auto weights_output_low_const = std::dynamic_pointer_cast(weights_fq->input_value(3).get_node_shared_ptr()); - auto weights_output_high_const = std::dynamic_pointer_cast(weights_fq->input_value(4).get_node_shared_ptr()); + auto weights_output_low_const = + std::dynamic_pointer_cast(weights_fq->input_value(3).get_node_shared_ptr()); + auto weights_output_high_const = + std::dynamic_pointer_cast(weights_fq->input_value(4).get_node_shared_ptr()); if (!weights_output_low_const || !weights_output_high_const) return false; @@ -123,13 +132,13 @@ pass::BinarizeWeights::BinarizeWeights() { bool weights_out_low_high_are_opposite = false; auto weights_output_low = weights_output_low_const->cast_vector(); auto weights_output_high = weights_output_high_const->cast_vector(); - std::tie(std::ignore, weights_out_low_high_are_opposite) = check_output_low_high(weights_output_low, - weights_output_high); + std::tie(std::ignore, weights_out_low_high_are_opposite) = + check_output_low_high(weights_output_low, weights_output_high); if (!weights_out_low_high_are_opposite) return false; // Normalize output low and high to either (0, 1) or (-1, 1) - auto normalize_output_low_high = [] (std::vector& output_low, std::vector& output_high) { + auto normalize_output_low_high = [](std::vector& output_low, std::vector& output_high) { for (size_t i = 0; i < output_low.size(); i++) { output_low[i] /= output_high[i]; output_high[i] = 1.0f; @@ -144,9 +153,11 @@ pass::BinarizeWeights::BinarizeWeights() { const std::shared_ptr& weights_norm_factor = weights_output_high_const; // Create new FQ on activations with new output low/high - auto output_low_normalized = op::Constant::create(element::f32, activations_output_low_const->get_shape(), activations_output_low); + auto output_low_normalized = + op::Constant::create(element::f32, activations_output_low_const->get_shape(), activations_output_low); output_low_normalized->set_friendly_name(activations_output_low_const->get_friendly_name()); - auto output_high_normalized = op::Constant::create(element::f32, activations_output_high_const->get_shape(), activations_output_high); + auto output_high_normalized = + op::Constant::create(element::f32, activations_output_high_const->get_shape(), activations_output_high); output_high_normalized->set_friendly_name(activations_output_high_const->get_friendly_name()); auto new_activations_fq = activations_fq->clone_with_new_inputs({activations_fq->input_value(0), activations_fq->input_value(1), @@ -159,25 +170,35 @@ pass::BinarizeWeights::BinarizeWeights() { auto weights = weights_const->cast_vector(); auto weights_input_low = weights_input_low_const->cast_vector(); auto weights_input_high = weights_input_high_const->cast_vector(); - auto quantized_weights = quantize_weights(weights_const->get_shape(), weights, - weights_input_low_const->get_shape(), weights_input_low, weights_input_high, - weights_output_low_const->get_shape(), weights_output_low, weights_output_high); - auto quantized_weights_const = op::Constant::create(element::f32, weights_const->get_shape(), quantized_weights); + auto quantized_weights = quantize_weights(weights_const->get_shape(), + weights, + weights_input_low_const->get_shape(), + weights_input_low, + weights_input_high, + weights_output_low_const->get_shape(), + weights_output_low, + weights_output_high); + auto quantized_weights_const = + op::Constant::create(element::f32, weights_const->get_shape(), quantized_weights); quantized_weights_const->set_friendly_name(weights_const->get_friendly_name()); auto new_conv = conv->clone_with_new_inputs({new_activations_fq, quantized_weights_const}); std::vector norm_factor_shape = {-1}; for (size_t i = 2; i < weights_const->get_shape().size(); i++) norm_factor_shape.push_back(1); - auto norm_factor_shape_const = opset5::Constant::create(element::i64, Shape{norm_factor_shape.size()}, norm_factor_shape); + auto norm_factor_shape_const = + opset5::Constant::create(element::i64, Shape{norm_factor_shape.size()}, norm_factor_shape); - auto activations_norm_factor_reshaped = std::make_shared(activations_norm_factor, norm_factor_shape_const, false); + auto activations_norm_factor_reshaped = + std::make_shared(activations_norm_factor, norm_factor_shape_const, false); auto mul = std::make_shared(new_conv, activations_norm_factor_reshaped); - auto weights_norm_factor_reshaped = std::make_shared(weights_norm_factor, norm_factor_shape_const, false); + auto weights_norm_factor_reshaped = + std::make_shared(weights_norm_factor, norm_factor_shape_const, false); auto mul2 = std::make_shared(mul, weights_norm_factor_reshaped); - copy_runtime_info({activations_fq, weights_fq, conv}, - {new_activations_fq, new_conv, activations_norm_factor_reshaped, mul, weights_norm_factor_reshaped, mul2}); + copy_runtime_info( + {activations_fq, weights_fq, conv}, + {new_activations_fq, new_conv, activations_norm_factor_reshaped, mul, weights_norm_factor_reshaped, mul2}); mul2->set_friendly_name(conv->get_friendly_name()); replace_node(conv, mul2); return true; diff --git a/src/common/transformations/src/transformations/common_optimizations/broadcast_elementwise_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/broadcast_elementwise_fusion.cpp index 4107dfa8eb8..e6fcba2ab90 100644 --- a/src/common/transformations/src/transformations/common_optimizations/broadcast_elementwise_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/broadcast_elementwise_fusion.cpp @@ -2,13 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/common_optimizations/broadcast_elementwise_fusion.hpp" #include #include #include +#include "itt.hpp" + NGRAPH_RTTI_DEFINITION(ngraph::pass::BroadcastElementwiseFusion, "BroadcastElementwiseFusion", 0); namespace { @@ -26,32 +27,33 @@ bool can_eliminate_broadcast(const ngraph::Output& eltwise, // Broadcast since eltwise_input will broadcast another eltwise input automatically. auto broadcast_input = broadcast.get_node()->get_input_node_shared_ptr(1); if ((ov::is_type(broadcast_input) || - ov::is_type(broadcast_input)) && + ov::is_type(broadcast_input)) && broadcast_input->input_value(0) == eltwise_input) { return true; } - const auto & input_shape = eltwise_input.get_partial_shape(); - const auto & broadcast_shape = broadcast.get_partial_shape(); + const auto& input_shape = eltwise_input.get_partial_shape(); + const auto& broadcast_shape = broadcast.get_partial_shape(); if (input_shape.rank().is_dynamic() || broadcast_shape.rank().is_dynamic()) { return false; } - const int64_t & input_shape_rank = input_shape.rank().get_length(); - const int64_t & broadcast_shape_rank = broadcast_shape.rank().get_length(); + const int64_t& input_shape_rank = input_shape.rank().get_length(); + const int64_t& broadcast_shape_rank = broadcast_shape.rank().get_length(); if (broadcast_shape_rank > input_shape_rank) { - //We can not eliminate broadcast op because - //in the case input_shape will be broadcasted + // We can not eliminate broadcast op because + // in the case input_shape will be broadcasted return false; } - for (int64_t i_dim = input_shape_rank - 1, b_dim = broadcast_shape_rank - 1; i_dim >= 0 && b_dim >=0; --i_dim, --b_dim) { + for (int64_t i_dim = input_shape_rank - 1, b_dim = broadcast_shape_rank - 1; i_dim >= 0 && b_dim >= 0; + --i_dim, --b_dim) { if (input_shape[i_dim].is_static() && broadcast_shape[b_dim].is_static()) { - const auto &input_shape_dim = input_shape[i_dim].get_length(); - const auto &broadcast_shape_dim = broadcast_shape[b_dim].get_length(); + const auto& input_shape_dim = input_shape[i_dim].get_length(); + const auto& broadcast_shape_dim = broadcast_shape[b_dim].get_length(); if (input_shape_dim != broadcast_shape_dim && broadcast_shape_dim != 1) { - //We can not eliminate broadcast op because - //input_shape will be broadcast + // We can not eliminate broadcast op because + // input_shape will be broadcast return false; } } else if (input_shape[i_dim].is_dynamic() && broadcast_shape[i_dim].is_static() && @@ -67,23 +69,24 @@ bool can_eliminate_broadcast(const ngraph::Output& eltwise, return true; } -} // namespace +} // namespace ngraph::pass::BroadcastElementwiseFusion::BroadcastElementwiseFusion() { MATCHER_SCOPE(BroadcastElementwiseFusion); auto broadcast_input = pattern::any_input(); - auto broadcast = pattern::wrap_type({broadcast_input, pattern::any_input()}, pattern::consumers_count(1)); + auto broadcast = pattern::wrap_type({broadcast_input, pattern::any_input()}, + pattern::consumers_count(1)); auto eltwise_input = pattern::any_input(); auto eltwise = pattern::wrap_type({eltwise_input, broadcast}); ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { - auto & pattern_value = m.get_pattern_value_map(); + auto& pattern_value = m.get_pattern_value_map(); - const auto & m_eltwise_input = pattern_value.at(eltwise_input); - const auto & m_eltwise = pattern_value.at(eltwise); + const auto& m_eltwise_input = pattern_value.at(eltwise_input); + const auto& m_eltwise = pattern_value.at(eltwise); - const auto & m_broadcast_input = pattern_value.at(broadcast_input); - auto & m_broadcast = pattern_value.at(broadcast); + const auto& m_broadcast_input = pattern_value.at(broadcast_input); + auto& m_broadcast = pattern_value.at(broadcast); if (!can_eliminate_broadcast(m_eltwise, m_eltwise_input, m_broadcast)) { return false; diff --git a/src/common/transformations/src/transformations/common_optimizations/clamp_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/clamp_fusion.cpp index 6521150788b..af19f56319e 100644 --- a/src/common/transformations/src/transformations/common_optimizations/clamp_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/clamp_fusion.cpp @@ -3,16 +3,16 @@ // #include "transformations/common_optimizations/clamp_fusion.hpp" -#include "transformations/utils/utils.hpp" #include +#include +#include +#include +#include #include -#include -#include -#include -#include #include "itt.hpp" +#include "transformations/utils/utils.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ClampFusion, "ClampFusion", 0); @@ -21,21 +21,25 @@ ngraph::pass::ClampFusion::ClampFusion() { auto data_pattern = ngraph::pattern::any_input(); auto min_const_pattern = ngraph::pattern::wrap_type(); auto max_const_pattern = ngraph::pattern::wrap_type(); - auto max_pattern1 = ngraph::pattern::wrap_type({data_pattern, min_const_pattern}, pattern::consumers_count(1)); + auto max_pattern1 = + ngraph::pattern::wrap_type({data_pattern, min_const_pattern}, pattern::consumers_count(1)); auto min_pattern1 = ngraph::pattern::wrap_type({max_pattern1, max_const_pattern}); auto min_pattern2 = ngraph::pattern::wrap_type({data_pattern, max_const_pattern}); - auto max_pattern2 = ngraph::pattern::wrap_type({min_pattern2, min_const_pattern}, pattern::consumers_count(1)); + auto max_pattern2 = + ngraph::pattern::wrap_type({min_pattern2, min_const_pattern}, pattern::consumers_count(1)); auto root = std::make_shared(ngraph::OutputVector{min_pattern1, max_pattern2}); ngraph::matcher_pass_callback callback = [=](pattern::Matcher& m) { auto pattern_map = m.get_pattern_value_map(); auto data = pattern_map.at(data_pattern); - auto min_const = std::dynamic_pointer_cast(pattern_map.at(min_const_pattern).get_node_shared_ptr()); + auto min_const = + std::dynamic_pointer_cast(pattern_map.at(min_const_pattern).get_node_shared_ptr()); if (!min_const) return false; if (shape_size(min_const->get_shape()) != 1) return false; - auto max_const = std::dynamic_pointer_cast(pattern_map.at(max_const_pattern).get_node_shared_ptr()); + auto max_const = + std::dynamic_pointer_cast(pattern_map.at(max_const_pattern).get_node_shared_ptr()); if (!max_const) return false; if (shape_size(max_const->get_shape()) != 1) diff --git a/src/common/transformations/src/transformations/common_optimizations/common_optimizations.cpp b/src/common/transformations/src/transformations/common_optimizations/common_optimizations.cpp index 2e4d2edca4c..69147c85af5 100644 --- a/src/common/transformations/src/transformations/common_optimizations/common_optimizations.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/common_optimizations.cpp @@ -2,106 +2,105 @@ // SPDX-License-Identifier: Apache-2.0 // -#include - -#include "transformations/init_node_info.hpp" -#include "itt.hpp" -#include "transformations/common_optimizations/broadcast_elementwise_fusion.hpp" -#include "transformations/common_optimizations/nop_elimination.hpp" #include "transformations/common_optimizations/common_optimizations.hpp" -#include "transformations/common_optimizations/conv_mul_fusion.hpp" -#include "transformations/common_optimizations/fq_mul_fusion.hpp" -#include "transformations/common_optimizations/fq_reshape_fusion.hpp" -#include "transformations/common_optimizations/gelu_fusion.hpp" -#include "transformations/common_optimizations/depth_to_space_fusion.hpp" -#include "transformations/common_optimizations/dropout_with_random_uniform_replacer.hpp" -#include "transformations/common_optimizations/optimize_strided_slice.hpp" -#include "transformations/common_optimizations/softplus_fusion.hpp" -#include "transformations/common_optimizations/softplus_to_mish_fusion.hpp" -#include "transformations/common_optimizations/swish_fusion.hpp" -#include "transformations/common_optimizations/normalize_l2_fusion.hpp" -#include "transformations/common_optimizations/pull_transpose_through_fq.hpp" -#include "transformations/common_optimizations/leaky_relu_fusion.hpp" -#include "transformations/common_optimizations/lin_op_sequence_fusion.hpp" -#include "transformations/common_optimizations/remove_filtering_boxes_by_size.hpp" -#include "transformations/common_optimizations/hsigmoid_fusion.hpp" -#include "transformations/common_optimizations/hswish_fusion.hpp" -#include "transformations/common_optimizations/convert_quantize_dequantize.hpp" -#include "transformations/common_optimizations/relu_fake_quantize_fusion.hpp" -#include "transformations/common_optimizations/disable_random_uniform_constant_folding.hpp" -#include "transformations/common_optimizations/random_uniform_fusion.hpp" -#include "transformations/common_optimizations/add_fake_quantize_fusion.hpp" -#include "transformations/common_optimizations/mul_fake_quantize_fusion.hpp" -#include "transformations/common_optimizations/clamp_fusion.hpp" -#include "transformations/common_optimizations/pad_fusion.hpp" -#include "transformations/common_optimizations/eliminate_unsqueeze_gather.hpp" -#include "transformations/common_optimizations/shuffle_channels_fusion.hpp" -#include "transformations/common_optimizations/softmax_fusion.hpp" -#include "transformations/common_optimizations/mvn_fusion.hpp" -#include "transformations/common_optimizations/binarize_weights.hpp" -#include "transformations/common_optimizations/conv_to_binary_conv.hpp" -#include "transformations/common_optimizations/space_to_batch_fusion.hpp" -#include "transformations/common_optimizations/batch_to_space_fusion.hpp" -#include "transformations/common_optimizations/dilated_convolution_converter.hpp" -#include "transformations/common_optimizations/transpose_sinking.hpp" -#include "transformations/common_optimizations/split_squeeze_concat_fusion.hpp" -#include "transformations/common_optimizations/skip_gather_before_transpose_and_reshape.hpp" -#include "transformations/common_optimizations/transpose_to_reshape.hpp" -#include "transformations/common_optimizations/strides_optimization.hpp" -#include "transformations/common_optimizations/convert_nms_gather_path_to_unsigned.hpp" -#include "transformations/common_optimizations/mul_conv_fusion.hpp" -#include "transformations/common_optimizations/interpolate_sequence_fusion.hpp" -#include "transformations/common_optimizations/convert_compression_only_to_legacy.hpp" -#include -#include "transformations/common_optimizations/matmul_multiply_fusion.hpp" -#include "transformations/common_optimizations/mark_precision_sensitive_divides.hpp" -#include "transformations/op_conversions/bidirectional_sequences_decomposition.hpp" -#include "transformations/common_optimizations/concat_reduce_fusion.hpp" -#include "transformations/op_conversions/convert_pad_to_group_conv.hpp" -#include "transformations/op_conversions/convert_divide.hpp" -#include "transformations/op_conversions/convert_gather_downgrade.hpp" -#include "transformations/op_conversions/convert_gather_upgrade.hpp" -#include "transformations/op_conversions/convert_mod.hpp" -#include "transformations/op_conversions/convert_minimum_to_power_and_max.hpp" -#include "transformations/op_conversions/convert_negative.hpp" -#include "transformations/op_conversions/convert_scatter_elements_to_scatter.hpp" -#include "transformations/op_conversions/convert_reduce_to_pooling.hpp" -#include "transformations/op_conversions/convert_subtract.hpp" -#include "transformations/op_conversions/convert_softmax_downgrade.hpp" -#include "transformations/op_conversions/convert_softmax_upgrade.hpp" -#include "transformations/op_conversions/convert_depth_to_space.hpp" -#include "transformations/op_conversions/convert_space_to_depth.hpp" -#include "transformations/op_conversions/convert_broadcast_to_tiles.hpp" -#include "transformations/op_conversions/convert_gelu.hpp" -#include "transformations/op_conversions/convert_interpolate1_to_interpolate4.hpp" -#include "transformations/op_conversions/detection_output_downgrade.hpp" -#include "transformations/op_conversions/detection_output_upgrade.hpp" -#include "transformations/op_conversions/batch_norm_decomposition.hpp" -#include "transformations/op_conversions/einsum_decomposition.hpp" -#include "transformations/op_conversions/gelu7_downgrade.hpp" -#include "transformations/op_conversions/reduce_l1_decomposition.hpp" -#include "transformations/op_conversions/reduce_l2_decomposition.hpp" -#include "transformations/op_conversions/hswish_decomposition.hpp" -#include "transformations/op_conversions/hsigmoid_decomposition.hpp" -#include "transformations/op_conversions/log_softmax_decomposition.hpp" -#include "transformations/op_conversions/mvn6_decomposition.hpp" -#include "transformations/op_conversions/simplify_ctc_greedy_decoder_seq_len.hpp" -#include "transformations/op_conversions/gather_normalize_negative_indices.hpp" -#include "transformations/op_conversions/convert_deformable_conv_v8_to_v1.hpp" -#include "transformations/op_conversions/convert_maxpool_downgrade.hpp" -#include "transformations/op_conversions/convert_maxpool_upgrade.hpp" -#include "transformations/disable_decompression_convert_constant_folding.hpp" -#include "transformations/op_conversions/convert_prior_box_v8_to_v0.hpp" -#include +#include #include -#include +#include +#include #include - +#include +#include #include #include #include -#include + +#include "itt.hpp" +#include "transformations/common_optimizations/add_fake_quantize_fusion.hpp" +#include "transformations/common_optimizations/batch_to_space_fusion.hpp" +#include "transformations/common_optimizations/binarize_weights.hpp" +#include "transformations/common_optimizations/broadcast_elementwise_fusion.hpp" +#include "transformations/common_optimizations/clamp_fusion.hpp" +#include "transformations/common_optimizations/concat_reduce_fusion.hpp" +#include "transformations/common_optimizations/conv_mul_fusion.hpp" +#include "transformations/common_optimizations/conv_to_binary_conv.hpp" +#include "transformations/common_optimizations/convert_compression_only_to_legacy.hpp" +#include "transformations/common_optimizations/convert_nms_gather_path_to_unsigned.hpp" +#include "transformations/common_optimizations/convert_quantize_dequantize.hpp" +#include "transformations/common_optimizations/depth_to_space_fusion.hpp" +#include "transformations/common_optimizations/dilated_convolution_converter.hpp" +#include "transformations/common_optimizations/disable_random_uniform_constant_folding.hpp" +#include "transformations/common_optimizations/dropout_with_random_uniform_replacer.hpp" +#include "transformations/common_optimizations/eliminate_unsqueeze_gather.hpp" +#include "transformations/common_optimizations/fq_mul_fusion.hpp" +#include "transformations/common_optimizations/fq_reshape_fusion.hpp" +#include "transformations/common_optimizations/gelu_fusion.hpp" +#include "transformations/common_optimizations/hsigmoid_fusion.hpp" +#include "transformations/common_optimizations/hswish_fusion.hpp" +#include "transformations/common_optimizations/interpolate_sequence_fusion.hpp" +#include "transformations/common_optimizations/leaky_relu_fusion.hpp" +#include "transformations/common_optimizations/lin_op_sequence_fusion.hpp" +#include "transformations/common_optimizations/mark_precision_sensitive_divides.hpp" +#include "transformations/common_optimizations/matmul_multiply_fusion.hpp" +#include "transformations/common_optimizations/mul_conv_fusion.hpp" +#include "transformations/common_optimizations/mul_fake_quantize_fusion.hpp" +#include "transformations/common_optimizations/mvn_fusion.hpp" +#include "transformations/common_optimizations/nop_elimination.hpp" +#include "transformations/common_optimizations/normalize_l2_fusion.hpp" +#include "transformations/common_optimizations/optimize_strided_slice.hpp" +#include "transformations/common_optimizations/pad_fusion.hpp" +#include "transformations/common_optimizations/pull_transpose_through_fq.hpp" +#include "transformations/common_optimizations/random_uniform_fusion.hpp" +#include "transformations/common_optimizations/relu_fake_quantize_fusion.hpp" +#include "transformations/common_optimizations/remove_filtering_boxes_by_size.hpp" +#include "transformations/common_optimizations/shuffle_channels_fusion.hpp" +#include "transformations/common_optimizations/skip_gather_before_transpose_and_reshape.hpp" +#include "transformations/common_optimizations/softmax_fusion.hpp" +#include "transformations/common_optimizations/softplus_fusion.hpp" +#include "transformations/common_optimizations/softplus_to_mish_fusion.hpp" +#include "transformations/common_optimizations/space_to_batch_fusion.hpp" +#include "transformations/common_optimizations/split_squeeze_concat_fusion.hpp" +#include "transformations/common_optimizations/strides_optimization.hpp" +#include "transformations/common_optimizations/swish_fusion.hpp" +#include "transformations/common_optimizations/transpose_sinking.hpp" +#include "transformations/common_optimizations/transpose_to_reshape.hpp" +#include "transformations/disable_decompression_convert_constant_folding.hpp" +#include "transformations/init_node_info.hpp" +#include "transformations/op_conversions/batch_norm_decomposition.hpp" +#include "transformations/op_conversions/bidirectional_sequences_decomposition.hpp" +#include "transformations/op_conversions/convert_broadcast_to_tiles.hpp" +#include "transformations/op_conversions/convert_deformable_conv_v8_to_v1.hpp" +#include "transformations/op_conversions/convert_depth_to_space.hpp" +#include "transformations/op_conversions/convert_divide.hpp" +#include "transformations/op_conversions/convert_gather_downgrade.hpp" +#include "transformations/op_conversions/convert_gather_upgrade.hpp" +#include "transformations/op_conversions/convert_gelu.hpp" +#include "transformations/op_conversions/convert_interpolate1_to_interpolate4.hpp" +#include "transformations/op_conversions/convert_maxpool_downgrade.hpp" +#include "transformations/op_conversions/convert_maxpool_upgrade.hpp" +#include "transformations/op_conversions/convert_minimum_to_power_and_max.hpp" +#include "transformations/op_conversions/convert_mod.hpp" +#include "transformations/op_conversions/convert_negative.hpp" +#include "transformations/op_conversions/convert_pad_to_group_conv.hpp" +#include "transformations/op_conversions/convert_prior_box_v8_to_v0.hpp" +#include "transformations/op_conversions/convert_reduce_to_pooling.hpp" +#include "transformations/op_conversions/convert_scatter_elements_to_scatter.hpp" +#include "transformations/op_conversions/convert_softmax_downgrade.hpp" +#include "transformations/op_conversions/convert_softmax_upgrade.hpp" +#include "transformations/op_conversions/convert_space_to_depth.hpp" +#include "transformations/op_conversions/convert_subtract.hpp" +#include "transformations/op_conversions/detection_output_downgrade.hpp" +#include "transformations/op_conversions/detection_output_upgrade.hpp" +#include "transformations/op_conversions/einsum_decomposition.hpp" +#include "transformations/op_conversions/gather_normalize_negative_indices.hpp" +#include "transformations/op_conversions/gelu7_downgrade.hpp" +#include "transformations/op_conversions/hsigmoid_decomposition.hpp" +#include "transformations/op_conversions/hswish_decomposition.hpp" +#include "transformations/op_conversions/log_softmax_decomposition.hpp" +#include "transformations/op_conversions/mvn6_decomposition.hpp" +#include "transformations/op_conversions/reduce_l1_decomposition.hpp" +#include "transformations/op_conversions/reduce_l2_decomposition.hpp" +#include "transformations/op_conversions/simplify_ctc_greedy_decoder_seq_len.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::CommonOptimizations, "CommonOptimizations", 0); diff --git a/src/common/transformations/src/transformations/common_optimizations/compress_float_constants.cpp b/src/common/transformations/src/transformations/common_optimizations/compress_float_constants.cpp index 4df6241a92c..f576115556f 100644 --- a/src/common/transformations/src/transformations/common_optimizations/compress_float_constants.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/compress_float_constants.cpp @@ -4,14 +4,13 @@ #include "transformations/common_optimizations/compress_float_constants.hpp" -#include "openvino/opsets/opset8.hpp" +#include "itt.hpp" #include "ngraph/rt_info.hpp" +#include "openvino/opsets/opset8.hpp" #include "openvino/pass/pattern/op/wrap_type.hpp" #include "transformations/rt_info/decompression.hpp" #include "transformations/rt_info/disable_fp16_compression.hpp" #include "transformations/rt_info/old_api_map_element_type_attribute.hpp" -#include "itt.hpp" - namespace { template @@ -40,7 +39,8 @@ std::shared_ptr change_constant_precision_to_fp16(std::shared_ptr( - const_node_pattern.get_node_shared_ptr()); + auto const_node = std::dynamic_pointer_cast(const_node_pattern.get_node_shared_ptr()); if (!const_node) return false; diff --git a/src/common/transformations/src/transformations/common_optimizations/concat_reduce_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/concat_reduce_fusion.cpp index d4b6ff35387..a3b3c18ef60 100644 --- a/src/common/transformations/src/transformations/common_optimizations/concat_reduce_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/concat_reduce_fusion.cpp @@ -3,27 +3,25 @@ // #include "transformations/common_optimizations/concat_reduce_fusion.hpp" -#include "transformations/common_optimizations/nop_elimination.hpp" -#include "transformations/utils/utils.hpp" #include -#include - #include -#include -#include #include #include -#include "itt.hpp" +#include +#include +#include +#include "itt.hpp" +#include "transformations/common_optimizations/nop_elimination.hpp" +#include "transformations/utils/utils.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ReplaceConcatReduceByMinOrMax, "ReplaceConcatReduceByMinOrMax", 0); NGRAPH_RTTI_DEFINITION(ngraph::pass::PullSqueezeThroughEltwise, "PullSqueezeThroughEltwise", 0); NGRAPH_RTTI_DEFINITION(ngraph::pass::ConcatReduceFusion, "ConcatReduceFusion", 0); - namespace { -enum class ReduceType {NONE, MAX, MIN}; +enum class ReduceType { NONE, MAX, MIN }; ReduceType get_reduce_type(const std::shared_ptr& reduce_node) { if (ov::is_type(reduce_node)) { @@ -34,7 +32,7 @@ ReduceType get_reduce_type(const std::shared_ptr& reduce_node) { return ReduceType::NONE; } } -} // namespace +} // namespace ngraph::pass::PullSqueezeThroughEltwise::PullSqueezeThroughEltwise() { MATCHER_SCOPE(PullSqueezeThroughEltwise); @@ -87,13 +85,15 @@ ngraph::pass::ReplaceConcatReduceByMinOrMax::ReplaceConcatReduceByMinOrMax() { auto concat_pattern = ngraph::pattern::wrap_type({pattern::any_input(), pattern::any_input()}); auto reduce_axes_pattern = ngraph::pattern::wrap_type(); - auto reduce_pattern = ngraph::pattern::wrap_type({concat_pattern, reduce_axes_pattern}); + auto reduce_pattern = + ngraph::pattern::wrap_type({concat_pattern, reduce_axes_pattern}); ngraph::matcher_pass_callback callback = [=](pattern::Matcher& m) { const auto& pattern_map = m.get_pattern_value_map(); auto concat = as_type_ptr(pattern_map.at(concat_pattern).get_node_shared_ptr()); - auto reduce = as_type_ptr(pattern_map.at(reduce_pattern).get_node_shared_ptr()); + auto reduce = + as_type_ptr(pattern_map.at(reduce_pattern).get_node_shared_ptr()); if (!reduce || !concat) return false; @@ -118,7 +118,8 @@ ngraph::pass::ReplaceConcatReduceByMinOrMax::ReplaceConcatReduceByMinOrMax() { copy_runtime_info({concat, reduce}, result_node); if (!reduce->get_keep_dims()) { - const auto squeeze_axis_node = ngraph::opset8::Constant::create(ngraph::element::i64, {}, {*reduction_axes.begin()}); + const auto squeeze_axis_node = + ngraph::opset8::Constant::create(ngraph::element::i64, {}, {*reduction_axes.begin()}); result_node = register_new_node(result_node, squeeze_axis_node); copy_runtime_info({concat, reduce}, result_node); } diff --git a/src/common/transformations/src/transformations/common_optimizations/conv_mul_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/conv_mul_fusion.cpp index b737d34d06b..bbe836325de 100644 --- a/src/common/transformations/src/transformations/common_optimizations/conv_mul_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/conv_mul_fusion.cpp @@ -3,18 +3,17 @@ // #include "transformations/common_optimizations/conv_mul_fusion.hpp" -#include "itt.hpp" #include +#include +#include +#include +#include +#include +#include #include -#include -#include -#include -#include -#include - -#include +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvolutionMultiplyFusion, "ConvolutionMultiplyFusion", 0); @@ -26,18 +25,18 @@ ngraph::pass::ConvolutionMultiplyFusion::ConvolutionMultiplyFusion() { auto mul_const = ngraph::pattern::wrap_type(pattern::has_static_shape()); auto mul = ngraph::pattern::wrap_type({conv, mul_const}); - matcher_pass_callback callback = [conv, input, weights, mul, mul_const](pattern::Matcher & m) -> bool { - const auto & pattern_to_output = m.get_pattern_value_map(); + matcher_pass_callback callback = [conv, input, weights, mul, mul_const](pattern::Matcher& m) -> bool { + const auto& pattern_to_output = m.get_pattern_value_map(); - const auto & m_weights = pattern_to_output.at(weights); - const auto & m_const = pattern_to_output.at(mul_const); - const auto & m_input = pattern_to_output.at(input); - const auto & m_conv = pattern_to_output.at(conv).get_node_shared_ptr(); - const auto & m_mul = pattern_to_output.at(mul).get_node_shared_ptr(); + const auto& m_weights = pattern_to_output.at(weights); + const auto& m_const = pattern_to_output.at(mul_const); + const auto& m_input = pattern_to_output.at(input); + const auto& m_conv = pattern_to_output.at(conv).get_node_shared_ptr(); + const auto& m_mul = pattern_to_output.at(mul).get_node_shared_ptr(); - const auto & channel_dim = m_weights.get_partial_shape()[0].get_length(); - const auto & weights_rank = m_weights.get_partial_shape().rank().get_length(); - const auto & const_shape = m_const.get_shape(); + const auto& channel_dim = m_weights.get_partial_shape()[0].get_length(); + const auto& weights_rank = m_weights.get_partial_shape().rank().get_length(); + const auto& const_shape = m_const.get_shape(); bool is_scalar_multiplier(shape_size(const_shape) == 1); @@ -60,9 +59,12 @@ ngraph::pass::ConvolutionMultiplyFusion::ConvolutionMultiplyFusion() { if (!is_scalar_multiplier) { auto final_const_shape = Shape(weights_rank, 1); final_const_shape[0] = channel_dim; - final_const = std::make_shared(m_const, - opset4::Constant::create(ngraph::element::i64, ngraph::Shape{final_const_shape.size()}, - final_const_shape), true); + final_const = + std::make_shared(m_const, + opset4::Constant::create(ngraph::element::i64, + ngraph::Shape{final_const_shape.size()}, + final_const_shape), + true); } // Multiply convolution weights with aligned Constant values @@ -87,22 +89,22 @@ ngraph::pass::GroupConvolutionMultiplyFusion::GroupConvolutionMultiplyFusion() { auto input = pattern::any_input(); auto weights = ngraph::pattern::any_input(pattern::has_static_dims({0, 1}) /* has GOIYX layout */); auto conv = ngraph::pattern::wrap_type({input, weights}, pattern::consumers_count(1)); - auto mul_const = ngraph::pattern::wrap_type();//pattern::has_static_shape()); + auto mul_const = ngraph::pattern::wrap_type(); // pattern::has_static_shape()); auto mul = ngraph::pattern::wrap_type({conv, mul_const}); - matcher_pass_callback callback = [conv, input, weights, mul, mul_const](pattern::Matcher & m) -> bool { - const auto & pattern_to_output = m.get_pattern_value_map(); + matcher_pass_callback callback = [conv, input, weights, mul, mul_const](pattern::Matcher& m) -> bool { + const auto& pattern_to_output = m.get_pattern_value_map(); auto m_weights = pattern_to_output.at(weights); - const auto & m_const = pattern_to_output.at(mul_const); - const auto & m_conv = pattern_to_output.at(conv).get_node_shared_ptr(); - const auto & m_mul = pattern_to_output.at(mul).get_node_shared_ptr(); + const auto& m_const = pattern_to_output.at(mul_const); + const auto& m_conv = pattern_to_output.at(conv).get_node_shared_ptr(); + const auto& m_mul = pattern_to_output.at(mul).get_node_shared_ptr(); - const auto & weights_shape = m_weights.get_partial_shape(); - const auto & G = weights_shape[0].get_length(); - const auto & O = weights_shape[1].get_length(); - const auto & weights_rank = weights_shape.rank().get_length(); - const auto & const_shape = m_const.get_shape(); + const auto& weights_shape = m_weights.get_partial_shape(); + const auto& G = weights_shape[0].get_length(); + const auto& O = weights_shape[1].get_length(); + const auto& weights_rank = weights_shape.rank().get_length(); + const auto& const_shape = m_const.get_shape(); bool is_scalar_multiplier(shape_size(const_shape) == 1); @@ -144,9 +146,12 @@ ngraph::pass::GroupConvolutionMultiplyFusion::GroupConvolutionMultiplyFusion() { final_const_shape[0] = G; final_const_shape[1] = O; } - final_const = std::make_shared(m_const, - opset4::Constant::create(ngraph::element::i64, ngraph::Shape{final_const_shape.size()}, - final_const_shape), true); + final_const = + std::make_shared(m_const, + opset4::Constant::create(ngraph::element::i64, + ngraph::Shape{final_const_shape.size()}, + final_const_shape), + true); } // Multiply convolution weights with aligned Constant values @@ -173,22 +178,23 @@ ngraph::pass::ConvolutionBackpropDataMultiplyFusion::ConvolutionBackpropDataMult MATCHER_SCOPE(ConvolutionBackpropDataMultiplyFusion); auto input = pattern::any_input(); auto weights = ngraph::pattern::any_input(pattern::has_static_dim(1) /* has IOYX layout */); - auto conv = ngraph::pattern::wrap_type({input, weights}, pattern::consumers_count(1)); + auto conv = + ngraph::pattern::wrap_type({input, weights}, pattern::consumers_count(1)); auto mul_const = ngraph::pattern::wrap_type(pattern::has_static_shape()); auto mul = ngraph::pattern::wrap_type({conv, mul_const}); - matcher_pass_callback callback = [conv, input, weights, mul, mul_const](pattern::Matcher & m) -> bool { - const auto & pattern_to_output = m.get_pattern_value_map(); + matcher_pass_callback callback = [conv, input, weights, mul, mul_const](pattern::Matcher& m) -> bool { + const auto& pattern_to_output = m.get_pattern_value_map(); - const auto & m_weights = pattern_to_output.at(weights); - const auto & m_const = pattern_to_output.at(mul_const); - const auto & m_input = pattern_to_output.at(input); - const auto & m_conv = pattern_to_output.at(conv).get_node_shared_ptr(); - const auto & m_mul = pattern_to_output.at(mul).get_node_shared_ptr(); + const auto& m_weights = pattern_to_output.at(weights); + const auto& m_const = pattern_to_output.at(mul_const); + const auto& m_input = pattern_to_output.at(input); + const auto& m_conv = pattern_to_output.at(conv).get_node_shared_ptr(); + const auto& m_mul = pattern_to_output.at(mul).get_node_shared_ptr(); - const auto & channel_dim = m_weights.get_partial_shape()[1].get_length(); - const auto & weights_rank = m_weights.get_partial_shape().rank().get_length(); - const auto & const_shape = m_const.get_shape(); + const auto& channel_dim = m_weights.get_partial_shape()[1].get_length(); + const auto& weights_rank = m_weights.get_partial_shape().rank().get_length(); + const auto& const_shape = m_const.get_shape(); bool is_scalar_multiplier(shape_size(const_shape) == 1); @@ -211,9 +217,12 @@ ngraph::pass::ConvolutionBackpropDataMultiplyFusion::ConvolutionBackpropDataMult if (!is_scalar_multiplier) { auto final_const_shape = Shape(weights_rank - 1, 1); final_const_shape[0] = channel_dim; - final_const = std::make_shared(m_const, - opset4::Constant::create(ngraph::element::i64, ngraph::Shape{final_const_shape.size()}, - final_const_shape), true); + final_const = + std::make_shared(m_const, + opset4::Constant::create(ngraph::element::i64, + ngraph::Shape{final_const_shape.size()}, + final_const_shape), + true); } // Multiply convolution weights with aligned Constant values @@ -231,29 +240,32 @@ ngraph::pass::ConvolutionBackpropDataMultiplyFusion::ConvolutionBackpropDataMult register_matcher(m, callback); } -NGRAPH_RTTI_DEFINITION(ngraph::pass::GroupConvolutionBackpropDataMultiplyFusion, "GroupConvolutionBackpropDataMultiplyFusion", 0); +NGRAPH_RTTI_DEFINITION(ngraph::pass::GroupConvolutionBackpropDataMultiplyFusion, + "GroupConvolutionBackpropDataMultiplyFusion", + 0); ngraph::pass::GroupConvolutionBackpropDataMultiplyFusion::GroupConvolutionBackpropDataMultiplyFusion() { MATCHER_SCOPE(GroupConvolutionBackpropDataMultiplyFusion); auto input = pattern::any_input(); auto weights = ngraph::pattern::any_input(pattern::has_static_dims({0, 2}) /* has GIOYX layout */); - auto conv = ngraph::pattern::wrap_type({input, weights}, pattern::consumers_count(1)); + auto conv = + ngraph::pattern::wrap_type({input, weights}, pattern::consumers_count(1)); auto mul_const = ngraph::pattern::wrap_type(pattern::has_static_shape()); auto mul = ngraph::pattern::wrap_type({conv, mul_const}); - matcher_pass_callback callback = [conv, input, weights, mul, mul_const](pattern::Matcher & m) -> bool { - const auto & pattern_to_output = m.get_pattern_value_map(); + matcher_pass_callback callback = [conv, input, weights, mul, mul_const](pattern::Matcher& m) -> bool { + const auto& pattern_to_output = m.get_pattern_value_map(); - const auto & m_weights = pattern_to_output.at(weights); - const auto & m_const = pattern_to_output.at(mul_const); - const auto & m_input = pattern_to_output.at(input); - const auto & m_conv = pattern_to_output.at(conv).get_node_shared_ptr(); - const auto & m_mul = pattern_to_output.at(mul).get_node_shared_ptr(); + const auto& m_weights = pattern_to_output.at(weights); + const auto& m_const = pattern_to_output.at(mul_const); + const auto& m_input = pattern_to_output.at(input); + const auto& m_conv = pattern_to_output.at(conv).get_node_shared_ptr(); + const auto& m_mul = pattern_to_output.at(mul).get_node_shared_ptr(); - const auto & G = m_weights.get_partial_shape()[0].get_length(); - const auto & O = m_weights.get_partial_shape()[2].get_length(); - const auto & weights_rank = m_weights.get_partial_shape().rank().get_length(); - const auto & const_shape = m_const.get_shape(); + const auto& G = m_weights.get_partial_shape()[0].get_length(); + const auto& O = m_weights.get_partial_shape()[2].get_length(); + const auto& weights_rank = m_weights.get_partial_shape().rank().get_length(); + const auto& const_shape = m_const.get_shape(); bool is_scalar_multiplier(shape_size(const_shape) == 1); @@ -277,9 +289,12 @@ ngraph::pass::GroupConvolutionBackpropDataMultiplyFusion::GroupConvolutionBackpr auto final_const_shape = Shape(weights_rank, 1); final_const_shape[0] = G; final_const_shape[2] = O; - final_const = std::make_shared(m_const, - opset4::Constant::create(ngraph::element::i64, ngraph::Shape{final_const_shape.size()}, - final_const_shape), true); + final_const = + std::make_shared(m_const, + opset4::Constant::create(ngraph::element::i64, + ngraph::Shape{final_const_shape.size()}, + final_const_shape), + true); } // Multiply convolution weights with aligned Constant values diff --git a/src/common/transformations/src/transformations/common_optimizations/conv_to_binary_conv.cpp b/src/common/transformations/src/transformations/common_optimizations/conv_to_binary_conv.cpp index 965d245779f..a31062bcee1 100644 --- a/src/common/transformations/src/transformations/common_optimizations/conv_to_binary_conv.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/conv_to_binary_conv.cpp @@ -3,15 +3,15 @@ // #include "transformations/common_optimizations/conv_to_binary_conv.hpp" -#include "itt.hpp" #include -#include - #include #include #include #include +#include + +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvToBinaryConv, "ConvToBinaryConv", 0); @@ -32,16 +32,16 @@ static std::vector binarize_weights(const std::vector& weights) ngraph::pass::ConvToBinaryConv::ConvToBinaryConv() { MATCHER_SCOPE(ConvToBinaryConv); - auto fq_pattern = ngraph::pattern::wrap_type( - {ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type()}, - pattern::consumers_count(1)); - auto conv_pattern = ngraph::pattern::wrap_type({fq_pattern, ngraph::pattern::wrap_type()}); + auto fq_pattern = ngraph::pattern::wrap_type({ngraph::pattern::any_input(), + ngraph::pattern::any_input(), + ngraph::pattern::any_input(), + ngraph::pattern::wrap_type(), + ngraph::pattern::wrap_type()}, + pattern::consumers_count(1)); + auto conv_pattern = + ngraph::pattern::wrap_type({fq_pattern, ngraph::pattern::wrap_type()}); - ngraph::matcher_pass_callback callback = [=](pattern::Matcher &m) { + ngraph::matcher_pass_callback callback = [=](pattern::Matcher& m) { auto conv = std::dynamic_pointer_cast(m.get_match_root()); if (!conv) return false; @@ -49,41 +49,54 @@ ngraph::pass::ConvToBinaryConv::ConvToBinaryConv() { if (!fq || fq->get_levels() != 2) return false; - auto output_low_constant = std::dynamic_pointer_cast(fq->input_value(3).get_node_shared_ptr()); + auto output_low_constant = + std::dynamic_pointer_cast(fq->input_value(3).get_node_shared_ptr()); if (!output_low_constant) return false; auto output_low = output_low_constant->cast_vector(); - bool output_low_is_zero = std::all_of(output_low.begin(), output_low.end(), [] (float f) -> bool { return f == 0.0f; }); - bool output_low_is_minus_one = std::all_of(output_low.begin(), output_low.end(), [] (float f) -> bool { return f == -1.0f; }); - auto output_high_constant = std::dynamic_pointer_cast(fq->input_value(4).get_node_shared_ptr()); + bool output_low_is_zero = std::all_of(output_low.begin(), output_low.end(), [](float f) -> bool { + return f == 0.0f; + }); + bool output_low_is_minus_one = std::all_of(output_low.begin(), output_low.end(), [](float f) -> bool { + return f == -1.0f; + }); + auto output_high_constant = + std::dynamic_pointer_cast(fq->input_value(4).get_node_shared_ptr()); if (!output_high_constant) return false; auto output_high = output_high_constant->cast_vector(); - bool output_high_is_one = std::all_of(output_high.begin(), output_high.end(), [] (float f) -> bool { return f == 1.0f; }); + bool output_high_is_one = std::all_of(output_high.begin(), output_high.end(), [](float f) -> bool { + return f == 1.0f; + }); if (!(output_high_is_one && (output_low_is_zero || output_low_is_minus_one))) - return false; + return false; auto weights_constant = std::dynamic_pointer_cast(conv->input_value(1).get_node_shared_ptr()); if (!weights_constant) return false; auto weights = weights_constant->cast_vector(); - if (!std::all_of(weights.begin(), weights.end(), [] (float f) -> bool { return f == -1.0f || f == 1.0f; })) + if (!std::all_of(weights.begin(), weights.end(), [](float f) -> bool { + return f == -1.0f || f == 1.0f; + })) return false; auto bin_weights = binarize_weights(weights); - auto bin_weights_constant = std::make_shared(element::u1, weights_constant->get_shape(), bin_weights.data()); + auto bin_weights_constant = + std::make_shared(element::u1, weights_constant->get_shape(), bin_weights.data()); if (output_low_is_zero && output_high_is_one) { - auto new_conv = std::make_shared(conv->input_value(0), bin_weights_constant, - conv->get_strides(), - conv->get_pads_begin(), - conv->get_pads_end(), - conv->get_dilations(), - opset5::BinaryConvolution::BinaryConvolutionMode::XNOR_POPCOUNT, - -1, - conv->get_auto_pad()); + auto new_conv = std::make_shared( + conv->input_value(0), + bin_weights_constant, + conv->get_strides(), + conv->get_pads_begin(), + conv->get_pads_end(), + conv->get_dilations(), + opset5::BinaryConvolution::BinaryConvolutionMode::XNOR_POPCOUNT, + -1, + conv->get_auto_pad()); new_conv->set_friendly_name(conv->get_friendly_name()); std::vector axes; std::vector weights_reduced_shape = {-1}; @@ -94,13 +107,13 @@ ngraph::pass::ConvToBinaryConv::ConvToBinaryConv() { weights_reduced_shape.push_back(1); } auto weights_reduced = std::make_shared( - op::Constant::create(element::f32, weights_constant->get_shape(), weights), - op::Constant::create(element::i64, Shape{axes.size()}, axes), false); - std::shared_ptr weights_reduced_reshaped = std::make_shared(weights_reduced, - op::Constant::create(element::i64, - Shape{weights_reduced_shape.size()}, - weights_reduced_shape), - false); + op::Constant::create(element::f32, weights_constant->get_shape(), weights), + op::Constant::create(element::i64, Shape{axes.size()}, axes), + false); + std::shared_ptr weights_reduced_reshaped = std::make_shared( + weights_reduced, + op::Constant::create(element::i64, Shape{weights_reduced_shape.size()}, weights_reduced_shape), + false); weights_reduced_reshaped = ngraph::get_constant_from_source(weights_reduced_reshaped); auto add = std::make_shared(new_conv, weights_reduced_reshaped); auto mul = std::make_shared(add, op::Constant::create(element::f32, Shape{}, {0.5})); @@ -110,14 +123,16 @@ ngraph::pass::ConvToBinaryConv::ConvToBinaryConv() { return true; } - auto new_conv = std::make_shared(conv->input_value(0), bin_weights_constant, - conv->get_strides(), - conv->get_pads_begin(), - conv->get_pads_end(), - conv->get_dilations(), - opset5::BinaryConvolution::BinaryConvolutionMode::XNOR_POPCOUNT, - 0, - conv->get_auto_pad()); + auto new_conv = + std::make_shared(conv->input_value(0), + bin_weights_constant, + conv->get_strides(), + conv->get_pads_begin(), + conv->get_pads_end(), + conv->get_dilations(), + opset5::BinaryConvolution::BinaryConvolutionMode::XNOR_POPCOUNT, + 0, + conv->get_auto_pad()); new_conv->set_friendly_name(conv->get_friendly_name()); copy_runtime_info(conv, new_conv); replace_node(conv, new_conv); diff --git a/src/common/transformations/src/transformations/common_optimizations/convert_nms_gather_path_to_unsigned.cpp b/src/common/transformations/src/transformations/common_optimizations/convert_nms_gather_path_to_unsigned.cpp index 33809fe27c0..55caec13138 100644 --- a/src/common/transformations/src/transformations/common_optimizations/convert_nms_gather_path_to_unsigned.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/convert_nms_gather_path_to_unsigned.cpp @@ -2,16 +2,18 @@ // SPDX-License-Identifier: Apache-2.0 // #include "transformations/common_optimizations/convert_nms_gather_path_to_unsigned.hpp" -#include + +#include +#include +#include #include #include #include #include -#include -#include +#include #include -#include #include + #include "itt.hpp" #include "ngraph/node.hpp" @@ -20,84 +22,82 @@ using namespace std; namespace ngraph { namespace pass { class InitNMSPath : public pass::MatcherPass { - public: - NGRAPH_RTTI_DECLARATION; - InitNMSPath() { - MATCHER_SCOPE(InitNMSPath); - auto nms_pattern = pattern::wrap_type(); - matcher_pass_callback callback = [=](pattern::Matcher &m) { - const auto &out_nodes = m.get_match_root()->output(0).get_target_inputs(); - for (const auto & out_node : out_nodes) { - ov::set_nms_selected_indices(out_node.get_node()); - } - return true; - }; - auto m = make_shared(nms_pattern, matcher_name); - register_matcher(m, callback); - } - }; -class PropagateNMSPath: public pass::MatcherPass { - public: - NGRAPH_RTTI_DECLARATION; - PropagateNMSPath(){ - MATCHER_SCOPE(PropagateNMSPath); - auto node_pattern = pattern::wrap_type< - opset8::Squeeze, - opset8::Unsqueeze, - opset8::Reshape, - op::util::BroadcastBase, - opset8::StridedSlice, - opset8::Slice, - opset8::VariadicSplit, - op::util::GatherBase, - opset8::Concat, - opset8::Convert>(); - matcher_pass_callback callback = [=](pattern::Matcher &m) { - auto node = m.get_match_root(); - const auto & inputs = node->input_values(); - if (any_of(inputs.begin(), inputs.end(), [](const Output & output) { +public: + NGRAPH_RTTI_DECLARATION; + InitNMSPath() { + MATCHER_SCOPE(InitNMSPath); + auto nms_pattern = + pattern::wrap_type(); + matcher_pass_callback callback = [=](pattern::Matcher& m) { + const auto& out_nodes = m.get_match_root()->output(0).get_target_inputs(); + for (const auto& out_node : out_nodes) { + ov::set_nms_selected_indices(out_node.get_node()); + } + return true; + }; + auto m = make_shared(nms_pattern, matcher_name); + register_matcher(m, callback); + } +}; +class PropagateNMSPath : public pass::MatcherPass { +public: + NGRAPH_RTTI_DECLARATION; + PropagateNMSPath() { + MATCHER_SCOPE(PropagateNMSPath); + auto node_pattern = pattern::wrap_type(); + matcher_pass_callback callback = [=](pattern::Matcher& m) { + auto node = m.get_match_root(); + const auto& inputs = node->input_values(); + if (any_of(inputs.begin(), inputs.end(), [](const Output& output) { return ov::has_nms_selected_indices(output.get_node()); })) { - ov::set_nms_selected_indices(node.get()); - } + ov::set_nms_selected_indices(node.get()); + } + return false; + }; + auto m = make_shared(node_pattern, matcher_name); + register_matcher(m, callback); + } +}; +class UpdateConvertGather : public pass::MatcherPass { +public: + NGRAPH_RTTI_DECLARATION; + UpdateConvertGather() { + MATCHER_SCOPE(UpdateConvertGather); + auto node_pattern = pattern::wrap_type(); + matcher_pass_callback callback = [=](pattern::Matcher& m) { + auto gather = m.get_match_root(); + auto indices = gather->input_value(1); + if (!ov::has_nms_selected_indices(indices.get_node())) return false; - }; - auto m = make_shared(node_pattern, matcher_name); - register_matcher(m, callback); - } - }; -class UpdateConvertGather: public pass::MatcherPass { - public: - NGRAPH_RTTI_DECLARATION; - UpdateConvertGather(){ - MATCHER_SCOPE(UpdateConvertGather); - auto node_pattern = pattern::wrap_type(); - matcher_pass_callback callback = [=](pattern::Matcher &m) { - auto gather = m.get_match_root(); - auto indices = gather->input_value(1); - if (!ov::has_nms_selected_indices(indices.get_node())) - return false; - gather->get_rt_info()["dontReverseIndices"] = true; - auto out_type = (indices.get_element_type() == element::i64 ? element::u64 : element::u32); - auto existing_convert = dynamic_pointer_cast(indices.get_node_shared_ptr()); - if (existing_convert && indices.get_target_inputs().size() == 1) { - existing_convert->set_convert_element_type(out_type); - existing_convert->validate_and_infer_types(); - } else { - auto new_convert_to_unsigned = make_shared(indices, out_type); - gather->input(1).replace_source_output(new_convert_to_unsigned); - copy_runtime_info(gather, new_convert_to_unsigned); - } - return true; - }; - auto m = make_shared(node_pattern, matcher_name); - register_matcher(m, callback); - } - }; -}// namespace pass -}// namespace ngraph + gather->get_rt_info()["dontReverseIndices"] = true; + auto out_type = (indices.get_element_type() == element::i64 ? element::u64 : element::u32); + auto existing_convert = dynamic_pointer_cast(indices.get_node_shared_ptr()); + if (existing_convert && indices.get_target_inputs().size() == 1) { + existing_convert->set_convert_element_type(out_type); + existing_convert->validate_and_infer_types(); + } else { + auto new_convert_to_unsigned = make_shared(indices, out_type); + gather->input(1).replace_source_output(new_convert_to_unsigned); + copy_runtime_info(gather, new_convert_to_unsigned); + } + return true; + }; + auto m = make_shared(node_pattern, matcher_name); + register_matcher(m, callback); + } +}; +} // namespace pass +} // namespace ngraph NGRAPH_RTTI_DEFINITION(ngraph::pass::InitNMSPath, "InitNMSPath", 0); NGRAPH_RTTI_DEFINITION(ngraph::pass::PropagateNMSPath, "PropagateNMSPath", 0); diff --git a/src/common/transformations/src/transformations/common_optimizations/convert_quantize_dequantize.cpp b/src/common/transformations/src/transformations/common_optimizations/convert_quantize_dequantize.cpp index ae4d10eea4a..ee15d1458cd 100644 --- a/src/common/transformations/src/transformations/common_optimizations/convert_quantize_dequantize.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/convert_quantize_dequantize.cpp @@ -3,25 +3,25 @@ // #include "transformations/common_optimizations/convert_quantize_dequantize.hpp" -#include "transformations/utils/utils.hpp" -#include "itt.hpp" #include +#include +#include +#include +#include #include -#include -#include -#include -#include - +#include "itt.hpp" +#include "transformations/utils/utils.hpp" // ConvertQuantizeDequantize converts Quantize/Dequantize pair to a single FakeQuantize. // Since Quantize is decomposed to FakeQuantize and Dequantize is decomposed to Subtract->Multiply, // the full pattern to match is presented on the left hand side of the graph below. // On the right hand side is the graph after transformation. // Currently transformation supports only i8 and u8 quantized data type. -// That implies 'levels' attribute to be 256, as well as (output_low, output_high) be (-128, 127) or (0, 255) (depends on sign of the quantized data type). -// Another limitation is that 'zero_point' and 'scale' have to be broadcastable to the output of FakeQuantize. +// That implies 'levels' attribute to be 256, as well as (output_low, output_high) be (-128, 127) or (0, 255) (depends +// on sign of the quantized data type). Another limitation is that 'zero_point' and 'scale' have to be broadcastable to +// the output of FakeQuantize. // // // | | | | | @@ -65,13 +65,16 @@ ngraph::pass::ConvertQuantizeDequantize::ConvertQuantizeDequantize() { auto input_high_pattern = ngraph::pattern::any_input(); auto output_low_pattern = ngraph::pattern::wrap_type(); auto output_high_pattern = ngraph::pattern::wrap_type(); - auto fq_pattern = ngraph::pattern::wrap_type({data_pattern, input_low_pattern, - input_high_pattern, output_low_pattern, - output_high_pattern}); - auto convert1_pattern = ngraph::pattern::wrap_type({fq_pattern}, pattern::type_matches_any({element::i8, element::u8})); - auto convert2_pattern = ngraph::pattern::wrap_type({convert1_pattern}, pattern::type_matches(element::f32)); + auto fq_pattern = ngraph::pattern::wrap_type( + {data_pattern, input_low_pattern, input_high_pattern, output_low_pattern, output_high_pattern}); + auto convert1_pattern = + ngraph::pattern::wrap_type({fq_pattern}, + pattern::type_matches_any({element::i8, element::u8})); + auto convert2_pattern = + ngraph::pattern::wrap_type({convert1_pattern}, pattern::type_matches(element::f32)); auto zero_point_pattern = ngraph::pattern::any_input(); - auto sub_pattern = ngraph::pattern::wrap_type({convert2_pattern, zero_point_pattern}, pattern::consumers_count(1)); + auto sub_pattern = ngraph::pattern::wrap_type({convert2_pattern, zero_point_pattern}, + pattern::consumers_count(1)); auto scale_pattern = ngraph::pattern::any_input(); auto mul_pattern = ngraph::pattern::wrap_type({sub_pattern, scale_pattern}); @@ -85,10 +88,12 @@ ngraph::pass::ConvertQuantizeDequantize::ConvertQuantizeDequantize() { auto data = pattern_map[data_pattern]; auto input_low = pattern_map[input_low_pattern]; auto input_high = pattern_map[input_high_pattern]; - auto output_low = std::dynamic_pointer_cast(pattern_map[output_low_pattern].get_node_shared_ptr()); + auto output_low = + std::dynamic_pointer_cast(pattern_map[output_low_pattern].get_node_shared_ptr()); if (!output_low) return false; - auto output_high = std::dynamic_pointer_cast(pattern_map[output_high_pattern].get_node_shared_ptr()); + auto output_high = + std::dynamic_pointer_cast(pattern_map[output_high_pattern].get_node_shared_ptr()); if (!output_high) return false; auto fq = std::dynamic_pointer_cast(pattern_map[fq_pattern].get_node_shared_ptr()); @@ -133,9 +138,11 @@ ngraph::pass::ConvertQuantizeDequantize::ConvertQuantizeDequantize() { } std::shared_ptr new_out_low = std::make_shared( - std::make_shared(output_low, zero_point), scale); + std::make_shared(output_low, zero_point), + scale); std::shared_ptr new_out_high = std::make_shared( - std::make_shared(output_high, zero_point), scale); + std::make_shared(output_high, zero_point), + scale); // check if new_out_low/high shapes are broadcastable to FQ's input auto data_shape = data.get_partial_shape(); @@ -155,7 +162,12 @@ ngraph::pass::ConvertQuantizeDequantize::ConvertQuantizeDequantize() { if (const_out_high) new_out_high = const_out_high; - auto new_fq = std::make_shared(data, input_low, input_high, new_out_low, new_out_high, levels); + auto new_fq = std::make_shared(data, + input_low, + input_high, + new_out_low, + new_out_high, + levels); new_fq->set_friendly_name(mul->get_friendly_name()); copy_runtime_info({fq, convert1.get_node_shared_ptr(), convert2.get_node_shared_ptr()}, new_fq); diff --git a/src/common/transformations/src/transformations/common_optimizations/depth_to_space_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/depth_to_space_fusion.cpp index 3ca49a88926..b95c4428949 100644 --- a/src/common/transformations/src/transformations/common_optimizations/depth_to_space_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/depth_to_space_fusion.cpp @@ -3,20 +3,21 @@ // #include "transformations/common_optimizations/depth_to_space_fusion.hpp" -#include "itt.hpp" #include +#include +#include +#include #include -#include -#include -#include - +#include "itt.hpp" #include "transformations/utils/utils.hpp" namespace { -bool check_block_first(const ngraph::PartialShape& shape_input, const ngraph::PartialShape& shape_reshape_before, - const ngraph::AxisVector& permutation, const ngraph::PartialShape& shape_reshape_after, +bool check_block_first(const ngraph::PartialShape& shape_input, + const ngraph::PartialShape& shape_reshape_before, + const ngraph::AxisVector& permutation, + const ngraph::PartialShape& shape_reshape_after, size_t& possible_block_size) { const auto input_rank = shape_input.rank(); auto spatial_dims = input_rank.get_length() - 2; @@ -50,7 +51,8 @@ bool check_block_first(const ngraph::PartialShape& shape_input, const ngraph::Pa return false; } - // y = reshape(x'', [N, C / (block_size ^ K), D1 * block_size, D2 * block_size, D3 * block_size, ..., DK * block_size]) + // y = reshape(x'', [N, C / (block_size ^ K), D1 * block_size, D2 * block_size, D3 * block_size, ..., DK * + // block_size]) expected_shape = {shape_input[0], c_dim}; for (int i = 2; i < input_rank.get_length(); ++i) expected_shape.push_back(shape_input[i] * possible_block_size); @@ -62,8 +64,10 @@ bool check_block_first(const ngraph::PartialShape& shape_input, const ngraph::Pa return true; } -bool check_depth_first(const ngraph::PartialShape& shape_input, const ngraph::PartialShape& shape_reshape_before, - const ngraph::AxisVector& permutation, const ngraph::PartialShape& shape_reshape_after, +bool check_depth_first(const ngraph::PartialShape& shape_input, + const ngraph::PartialShape& shape_reshape_before, + const ngraph::AxisVector& permutation, + const ngraph::PartialShape& shape_reshape_after, size_t& possible_block_size) { const auto input_rank = shape_input.rank(); auto spatial_dims = input_rank.get_length() - 2; @@ -95,7 +99,8 @@ bool check_depth_first(const ngraph::PartialShape& shape_input, const ngraph::Pa return false; } - // y = reshape(x'', [N, C / (block_size ^ K), D1 * block_size, D2 * block_size, D3 * block_size, ..., DK * block_size]) + // y = reshape(x'', [N, C / (block_size ^ K), D1 * block_size, D2 * block_size, D3 * block_size, ..., DK * + // block_size]) expected_shape = {shape_input[0], c_dim}; for (int i = 2; i < input_rank.get_length(); ++i) expected_shape.push_back(shape_input[i] * possible_block_size); @@ -107,7 +112,7 @@ bool check_depth_first(const ngraph::PartialShape& shape_input, const ngraph::Pa return true; } -} // namespace +} // namespace NGRAPH_RTTI_DEFINITION(ngraph::pass::DepthToSpaceFusion, "DepthToSpaceFusion", 0); @@ -117,9 +122,11 @@ ngraph::pass::DepthToSpaceFusion::DepthToSpaceFusion() { auto input1 = ngraph::pattern::any_input(); auto input2 = ngraph::pattern::any_input(); auto input3 = ngraph::pattern::any_input(); - auto reshape_before = ngraph::pattern::wrap_type({ input0, input1 }, pattern::consumers_count(1)); - auto permute = ngraph::pattern::wrap_type({ reshape_before, input2 }, pattern::consumers_count(1)); - auto reshape_after = ngraph::pattern::wrap_type({ permute, input3 }); + auto reshape_before = + ngraph::pattern::wrap_type({input0, input1}, pattern::consumers_count(1)); + auto permute = + ngraph::pattern::wrap_type({reshape_before, input2}, pattern::consumers_count(1)); + auto reshape_after = ngraph::pattern::wrap_type({permute, input3}); ngraph::matcher_pass_callback callback = [this](pattern::Matcher& m) { auto reshape_after = std::dynamic_pointer_cast(m.get_match_root()); @@ -127,7 +134,8 @@ ngraph::pass::DepthToSpaceFusion::DepthToSpaceFusion() { return false; } - auto permute = std::dynamic_pointer_cast(reshape_after->get_input_node_shared_ptr(0)); + auto permute = + std::dynamic_pointer_cast(reshape_after->get_input_node_shared_ptr(0)); if (!permute) { return false; } @@ -148,13 +156,16 @@ ngraph::pass::DepthToSpaceFusion::DepthToSpaceFusion() { } // check that all dimensions except batch are static - if (std::any_of(p_shape_input.begin() + 1, p_shape_input.end(), [](const ngraph::Dimension& x) { return x.is_dynamic(); })) { + if (std::any_of(p_shape_input.begin() + 1, p_shape_input.end(), [](const ngraph::Dimension& x) { + return x.is_dynamic(); + })) { return false; } // input shape: [ batch, C, spatial_dims], expected_shape = spatial_dims.size() * 2 + 2 auto expected_shape_size = (input_rank.get_length() - 2) * 2 + 2; - if (input_rank != p_shape_reshape_after.rank().get_length() || p_shape_reshape_before.rank().get_length() != expected_shape_size || + if (input_rank != p_shape_reshape_after.rank().get_length() || + p_shape_reshape_before.rank().get_length() != expected_shape_size || p_shape_permute.rank().get_length() != expected_shape_size) { return false; } @@ -170,13 +181,18 @@ ngraph::pass::DepthToSpaceFusion::DepthToSpaceFusion() { size_t block_size; if (check_depth_first(p_shape_input, p_shape_reshape_before, permutation, p_shape_reshape_after, block_size)) { mode = ngraph::opset3::DepthToSpace::DepthToSpaceMode::DEPTH_FIRST; - } else if (check_block_first(p_shape_input, p_shape_reshape_before, permutation, p_shape_reshape_after, block_size)) { + } else if (check_block_first(p_shape_input, + p_shape_reshape_before, + permutation, + p_shape_reshape_after, + block_size)) { mode = ngraph::opset3::DepthToSpace::DepthToSpaceMode::BLOCKS_FIRST; } else { return false; } - auto depth_to_space = std::make_shared(reshape_before->input_value(0), mode, block_size); + auto depth_to_space = + std::make_shared(reshape_before->input_value(0), mode, block_size); depth_to_space->set_friendly_name(reshape_after->get_friendly_name()); ngraph::copy_runtime_info({reshape_before, permute, reshape_after}, depth_to_space); ngraph::replace_node(reshape_after, depth_to_space); diff --git a/src/common/transformations/src/transformations/common_optimizations/dilated_convolution_converter.cpp b/src/common/transformations/src/transformations/common_optimizations/dilated_convolution_converter.cpp index 846d007a953..f23cfa6d4a4 100644 --- a/src/common/transformations/src/transformations/common_optimizations/dilated_convolution_converter.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/dilated_convolution_converter.cpp @@ -3,16 +3,15 @@ // #include "transformations/common_optimizations/dilated_convolution_converter.hpp" -#include "transformations/utils/utils.hpp" #include +#include +#include +#include #include -#include -#include -#include #include "itt.hpp" - +#include "transformations/utils/utils.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::DilatedConvolutionConverter, "DilatedConvolutionConverter", 0); @@ -22,28 +21,34 @@ ngraph::pass::DilatedConvolutionConverter::DilatedConvolutionConverter() { auto block_shape_pattern = pattern::wrap_type(); auto pads_begin_pattern = pattern::wrap_type(); auto pads_end_pattern = pattern::wrap_type(); - auto space_to_batch_pattern = pattern::wrap_type({data_pattern, block_shape_pattern, pads_begin_pattern, pads_end_pattern}); + auto space_to_batch_pattern = pattern::wrap_type( + {data_pattern, block_shape_pattern, pads_begin_pattern, pads_end_pattern}); auto conv_pattern = pattern::wrap_type({space_to_batch_pattern, pattern::any_input()}); auto crops_begin_pattern = pattern::wrap_type(); auto crops_end_pattern = pattern::wrap_type(); - auto batch_to_space_pattern = pattern::wrap_type({conv_pattern, pattern::any_input(), - crops_begin_pattern, crops_end_pattern}); + auto batch_to_space_pattern = pattern::wrap_type( + {conv_pattern, pattern::any_input(), crops_begin_pattern, crops_end_pattern}); matcher_pass_callback callback = [=](pattern::Matcher& m) { const auto& pattern_map = m.get_pattern_value_map(); - auto block_shape = std::dynamic_pointer_cast(pattern_map.at(block_shape_pattern).get_node_shared_ptr()); + auto block_shape = + std::dynamic_pointer_cast(pattern_map.at(block_shape_pattern).get_node_shared_ptr()); if (!block_shape) return false; - auto pads_begin = std::dynamic_pointer_cast(pattern_map.at(pads_begin_pattern).get_node_shared_ptr()); + auto pads_begin = + std::dynamic_pointer_cast(pattern_map.at(pads_begin_pattern).get_node_shared_ptr()); if (!pads_begin) return false; - auto pads_end = std::dynamic_pointer_cast(pattern_map.at(pads_end_pattern).get_node_shared_ptr()); + auto pads_end = + std::dynamic_pointer_cast(pattern_map.at(pads_end_pattern).get_node_shared_ptr()); if (!pads_end) return false; - auto crops_begin = std::dynamic_pointer_cast(pattern_map.at(crops_begin_pattern).get_node_shared_ptr()); + auto crops_begin = + std::dynamic_pointer_cast(pattern_map.at(crops_begin_pattern).get_node_shared_ptr()); if (!crops_begin) return false; - auto crops_end = std::dynamic_pointer_cast(pattern_map.at(crops_end_pattern).get_node_shared_ptr()); + auto crops_end = + std::dynamic_pointer_cast(pattern_map.at(crops_end_pattern).get_node_shared_ptr()); if (!crops_end) return false; auto conv = std::dynamic_pointer_cast(pattern_map.at(conv_pattern).get_node_shared_ptr()); @@ -57,10 +62,7 @@ ngraph::pass::DilatedConvolutionConverter::DilatedConvolutionConverter() { dilations[i] = block_shape_val[i + 2]; auto pads_begin_val = pads_begin->cast_vector(); auto pads_end_val = pads_end->cast_vector(); - if (!(pads_begin_val[0] == 0 && - pads_begin_val[1] == 0 && - pads_end_val[0] == 0 && - pads_end_val[1] == 0)) + if (!(pads_begin_val[0] == 0 && pads_begin_val[1] == 0 && pads_end_val[0] == 0 && pads_end_val[1] == 0)) return false; auto crops_begin_val = crops_begin->cast_vector(); auto crops_end_val = crops_end->cast_vector(); @@ -70,18 +72,24 @@ ngraph::pass::DilatedConvolutionConverter::DilatedConvolutionConverter() { std::vector new_pads_end; for (size_t i = 2; i < pads_end_val.size(); i++) new_pads_end.push_back(pads_end_val[i] - crops_end_val[i]); - auto new_conv = register_new_node(pattern_map.at(data_pattern), conv->input_value(1), - conv->get_strides(), new_pads_begin, new_pads_end, dilations, op::PadType::EXPLICIT); + auto new_conv = register_new_node(pattern_map.at(data_pattern), + conv->input_value(1), + conv->get_strides(), + new_pads_begin, + new_pads_end, + dilations, + op::PadType::EXPLICIT); auto batch_to_space = pattern_map.at(batch_to_space_pattern).get_node_shared_ptr(); new_conv->set_friendly_name(batch_to_space->get_friendly_name()); - copy_runtime_info({ - pattern_map.at(space_to_batch_pattern).get_node_shared_ptr(), - pattern_map.at(conv_pattern).get_node_shared_ptr(), - batch_to_space, - }, - new_conv); + copy_runtime_info( + { + pattern_map.at(space_to_batch_pattern).get_node_shared_ptr(), + pattern_map.at(conv_pattern).get_node_shared_ptr(), + batch_to_space, + }, + new_conv); replace_node(batch_to_space, new_conv); return true; diff --git a/src/common/transformations/src/transformations/common_optimizations/dimension_tracking.cpp b/src/common/transformations/src/transformations/common_optimizations/dimension_tracking.cpp index 547ea7e5b42..baa521905ea 100644 --- a/src/common/transformations/src/transformations/common_optimizations/dimension_tracking.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/dimension_tracking.cpp @@ -161,7 +161,8 @@ P2Btype ov::batch_util::find_batch(const std::shared_ptr& f) { } void ov::batch_util::restore_original_dimensions( - const std::map, ov::PartialShape>& parameter_to_shape, bool leave_batch_dynamic) { + const std::map, ov::PartialShape>& parameter_to_shape, + bool leave_batch_dynamic) { for (const auto& item : parameter_to_shape) { const auto& batch_marked_shape = item.first->get_partial_shape(); auto original_shape = item.second; @@ -227,7 +228,7 @@ bool ov::batch_util::detach_detection_output(const std::shared_ptr& f ResultVector new_outputs, outputs_to_delete; for (auto& result_node : f->get_results()) { auto do_node = result_node->input_value(0).get_node_shared_ptr(); - if (ov::is_type(do_node)) // cases with do->convert->result + if (ov::is_type(do_node)) // cases with do->convert->result do_node = do_node->get_input_node_shared_ptr(0); if (ov::is_type(do_node) || ov::is_type(do_node)) { for (auto& new_result_src : do_node->input_values()) { @@ -278,7 +279,7 @@ bool ov::pass::FindBatch::run_on_model(const std::shared_ptr& m) { bool failed_to_propagate_batch = ov::batch_util::check_batch_tracks_through_all_the_nodes(m); - if (failed_to_propagate_batch) { // restore original input shape with labels + if (failed_to_propagate_batch) { // restore original input shape with labels for (const auto& item : parameter_to_shape) item.first->set_partial_shape(item.second); } else { // restore original input shape with batch labels diff --git a/src/common/transformations/src/transformations/common_optimizations/disable_shapeof_constant_folding.cpp b/src/common/transformations/src/transformations/common_optimizations/disable_shapeof_constant_folding.cpp index 7f766c0daf4..74cef221073 100644 --- a/src/common/transformations/src/transformations/common_optimizations/disable_shapeof_constant_folding.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/disable_shapeof_constant_folding.cpp @@ -3,19 +3,17 @@ // #include - -#include #include #include -#include - +#include #include +#include NGRAPH_RTTI_DEFINITION(ngraph::pass::DisableShapeOfConstantFolding, "DisableShapeOfConstantFolding", 0); ngraph::pass::DisableShapeOfConstantFolding::DisableShapeOfConstantFolding() { - auto shape_of = pattern::wrap_type([=](const Output & output) { - const auto & shape = output.get_partial_shape(); + auto shape_of = pattern::wrap_type([=](const Output& output) { + const auto& shape = output.get_partial_shape(); return shape.is_dynamic() || shape_size(shape.get_shape()) != 1; }); diff --git a/src/common/transformations/src/transformations/common_optimizations/divide_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/divide_fusion.cpp index 0f5738b1f81..40135a5dd3e 100644 --- a/src/common/transformations/src/transformations/common_optimizations/divide_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/divide_fusion.cpp @@ -22,13 +22,13 @@ ngraph::pass::DivideFusion::DivideFusion() { auto p_mul_input = pattern::any_input(); auto p_mul = ngraph::pattern::wrap_type({p_mul_input, p_pow}); - matcher_pass_callback callback = [=](pattern::Matcher &m) { - const auto & pattern_to_output = m.get_pattern_value_map(); - const auto & minuend_input = pattern_to_output.at(p_mul_input); - const auto & subtrahend_input = pattern_to_output.at(p_pow_input); - const auto & mul = pattern_to_output.at(p_mul).get_node_shared_ptr(); - const auto & pow = pattern_to_output.at(p_pow).get_node_shared_ptr(); - const auto & minus_one = pattern_to_output.at(p_pow_const).get_node_shared_ptr(); + matcher_pass_callback callback = [=](pattern::Matcher& m) { + const auto& pattern_to_output = m.get_pattern_value_map(); + const auto& minuend_input = pattern_to_output.at(p_mul_input); + const auto& subtrahend_input = pattern_to_output.at(p_pow_input); + const auto& mul = pattern_to_output.at(p_mul).get_node_shared_ptr(); + const auto& pow = pattern_to_output.at(p_pow).get_node_shared_ptr(); + const auto& minus_one = pattern_to_output.at(p_pow_const).get_node_shared_ptr(); auto minus_one_const = std::dynamic_pointer_cast(minus_one); if (!minus_one_const || !op::util::has_constant_value(minus_one_const, -1.)) { diff --git a/src/common/transformations/src/transformations/common_optimizations/division_by_zero_fp16_resolver.cpp b/src/common/transformations/src/transformations/common_optimizations/division_by_zero_fp16_resolver.cpp index 3d970ee5f1e..c7a327d3b07 100644 --- a/src/common/transformations/src/transformations/common_optimizations/division_by_zero_fp16_resolver.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/division_by_zero_fp16_resolver.cpp @@ -2,17 +2,17 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/common_optimizations/division_by_zero_fp16_resolver.hpp" -#include "transformations/utils/utils.hpp" #include +#include +#include +#include #include -#include +#include "itt.hpp" #include "ngraph/rt_info.hpp" -#include -#include +#include "transformations/utils/utils.hpp" NGRAPH_RTTI_DEFINITION(ov::pass::DivisionByZeroFP16Resolver, "DivisionByZeroFP16Resolver", 0); diff --git a/src/common/transformations/src/transformations/common_optimizations/eliminate_unsqueeze_gather.cpp b/src/common/transformations/src/transformations/common_optimizations/eliminate_unsqueeze_gather.cpp index 0e03abe7272..833e6b99d0b 100644 --- a/src/common/transformations/src/transformations/common_optimizations/eliminate_unsqueeze_gather.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/eliminate_unsqueeze_gather.cpp @@ -8,6 +8,7 @@ #include #include #include + #include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::EliminateUnsqueezeGather, "EliminateUnsqueezeGather", 0); @@ -17,10 +18,12 @@ ngraph::pass::EliminateUnsqueezeGather::EliminateUnsqueezeGather() { // Remove Unsqueeze + Gather pair, if Gather gathers data by `1` dimension that was previously added by Unsqueeze const auto unsqueezeAxis = ngraph::pattern::any_input(); const auto unsqueezeInput = ngraph::pattern::any_input(); - const auto unsqueeze = ngraph::pattern::wrap_type({unsqueezeInput, unsqueezeAxis}, pattern::consumers_count(1)); + const auto unsqueeze = ngraph::pattern::wrap_type({unsqueezeInput, unsqueezeAxis}, + pattern::consumers_count(1)); const auto gatherIndices = ngraph::opset6::Constant::create(ngraph::element::i64, ngraph::Shape{}, {0}); const auto gatherAxis = ngraph::pattern::any_input(); - const auto gather = ngraph::pattern::wrap_type({unsqueeze, gatherIndices, gatherAxis}); + const auto gather = + ngraph::pattern::wrap_type({unsqueeze, gatherIndices, gatherAxis}); ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { auto& patternValue = m.get_pattern_value_map(); @@ -28,7 +31,8 @@ ngraph::pass::EliminateUnsqueezeGather::EliminateUnsqueezeGather() { const auto& m_unsqueezeAxis = patternValue.at(unsqueezeAxis); const auto& m_gatherAxis = patternValue.at(gatherAxis); - const auto& unsqueezeAxisNode = ngraph::as_type_ptr(m_unsqueezeAxis.get_node_shared_ptr()); + const auto& unsqueezeAxisNode = + ngraph::as_type_ptr(m_unsqueezeAxis.get_node_shared_ptr()); const auto& gatherAxisNode = ngraph::as_type_ptr(m_gatherAxis.get_node_shared_ptr()); if (!unsqueezeAxisNode || !gatherAxisNode) { @@ -68,10 +72,12 @@ ngraph::pass::EliminateGatherUnsqueeze::EliminateGatherUnsqueeze() { const auto gather_indices_label = ngraph::pattern::wrap_type(pattern::rank_equals(0)); const auto gather_axis_label = ngraph::pattern::wrap_type(); const auto gather_label = ngraph::pattern::wrap_type( - {ngraph::pattern::any_input(), gather_indices_label, gather_axis_label}, pattern::rank_equals(0)); + {ngraph::pattern::any_input(), gather_indices_label, gather_axis_label}, + pattern::rank_equals(0)); - const auto unsqueeze_label = ngraph::pattern::wrap_type( - {gather_label, ngraph::pattern::any_input()}, pattern::rank_equals(1)); + const auto unsqueeze_label = + ngraph::pattern::wrap_type({gather_label, ngraph::pattern::any_input()}, + pattern::rank_equals(1)); ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { auto pattern_nodes = m.get_pattern_map(); @@ -80,7 +86,10 @@ ngraph::pass::EliminateGatherUnsqueeze::EliminateGatherUnsqueeze() { auto& gather = pattern_nodes.at(gather_label); auto& unsqueeze = pattern_nodes.at(unsqueeze_label); - auto new_indices = ngraph::op::util::make_try_fold(gather_indices, opset6::Constant::create(element::i32, {1}, {1}), false); + auto new_indices = + ngraph::op::util::make_try_fold(gather_indices, + opset6::Constant::create(element::i32, {1}, {1}), + false); auto new_gather = gather->clone_with_new_inputs({gather->input_value(0), new_indices, gather->input_value(2)}); new_gather->set_friendly_name(gather->get_friendly_name()); diff --git a/src/common/transformations/src/transformations/common_optimizations/fq_mul_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/fq_mul_fusion.cpp index 2bfaf08f42c..2b8af6c28e8 100644 --- a/src/common/transformations/src/transformations/common_optimizations/fq_mul_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/fq_mul_fusion.cpp @@ -2,17 +2,17 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/common_optimizations/fq_mul_fusion.hpp" -#include "transformations/utils/utils.hpp" #include -#include - #include #include #include #include +#include + +#include "itt.hpp" +#include "transformations/utils/utils.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::FakeQuantizeMulFusion, "FakeQuantizeMulFusion", 0); @@ -43,25 +43,22 @@ ngraph::pass::FakeQuantizeMulFusion::FakeQuantizeMulFusion() { const auto fq_output_low_p = ngraph::pattern::any_input(); const auto fq_output_high_p = ngraph::pattern::any_input(); - const auto fq_node_p = ngraph::pattern::wrap_type({data_p, - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - fq_output_low_p, - fq_output_high_p}, - pattern::consumers_count(1)); + const auto fq_node_p = ngraph::pattern::wrap_type( + {data_p, ngraph::pattern::any_input(), ngraph::pattern::any_input(), fq_output_low_p, fq_output_high_p}, + pattern::consumers_count(1)); const auto mul_constant_p = ngraph::pattern::wrap_type(); - const auto mul_node_p = ngraph::pattern::wrap_type( - {fq_node_p, mul_constant_p}, pattern::consumers_count(1)); + const auto mul_node_p = + ngraph::pattern::wrap_type({fq_node_p, mul_constant_p}, pattern::consumers_count(1)); - ngraph::matcher_pass_callback callback = [=](pattern::Matcher &m) { + ngraph::matcher_pass_callback callback = [=](pattern::Matcher& m) { const auto& pattern_map = m.get_pattern_value_map(); const auto& data = pattern_map.at(data_p); const auto fq_node = pattern_map.at(fq_node_p).get_node_shared_ptr(); - const auto & original_output_low = pattern_map.at(fq_output_low_p); - const auto & original_output_high = pattern_map.at(fq_output_high_p); + const auto& original_output_low = pattern_map.at(fq_output_low_p); + const auto& original_output_high = pattern_map.at(fq_output_high_p); auto mul_constant = pattern_map.at(mul_constant_p).get_node_shared_ptr(); auto mul_constant_shape = mul_constant->get_shape(); bool is_single_value = shape_size(mul_constant_shape) == 1; @@ -73,7 +70,8 @@ ngraph::pass::FakeQuantizeMulFusion::FakeQuantizeMulFusion() { is_single_value = op::util::get_single_value(constant, v); if (is_single_value) { mul_constant_shape = Shape{1}; - mul_constant = std::make_shared(mul_constant->get_element_type(), mul_constant_shape, v); + mul_constant = + std::make_shared(mul_constant->get_element_type(), mul_constant_shape, v); } } } @@ -81,15 +79,14 @@ ngraph::pass::FakeQuantizeMulFusion::FakeQuantizeMulFusion() { if (!is_single_value) { auto fq_outputs = fq_node->get_users(); // Convolution and GroupConvolution LP transformations require output low/high to have the same values - bool fq_output_is_conv = std::any_of(fq_outputs.begin(), fq_outputs.end(), - [] (const std::shared_ptr& node) -> bool { - return is_type(node) || - is_type(node); - }); + bool fq_output_is_conv = + std::any_of(fq_outputs.begin(), fq_outputs.end(), [](const std::shared_ptr& node) -> bool { + return is_type(node) || is_type(node); + }); if (fq_output_is_conv) { return false; } - const auto & data_rank = data.get_partial_shape().rank(); + const auto& data_rank = data.get_partial_shape().rank(); if (data_rank.is_dynamic()) { return false; } @@ -97,12 +94,14 @@ ngraph::pass::FakeQuantizeMulFusion::FakeQuantizeMulFusion() { auto diff = rank - mul_constant_shape.size(); if (diff > 0) { mul_constant_shape.insert(mul_constant_shape.begin(), diff, 1); - mul_constant = std::make_shared(mul_constant, - op::Constant::create(element::i64, Shape{mul_constant_shape.size()}, mul_constant_shape), false); + mul_constant = std::make_shared( + mul_constant, + op::Constant::create(element::i64, Shape{mul_constant_shape.size()}, mul_constant_shape), + false); } } - auto get_adjusted_output_range = [&] (const Output& node) -> std::shared_ptr { + auto get_adjusted_output_range = [&](const Output& node) -> std::shared_ptr { auto ret = std::make_shared(node, mul_constant); copy_runtime_info(node.get_node_shared_ptr(), ret); auto constant = get_constant_from_source(ret); @@ -112,10 +111,10 @@ ngraph::pass::FakeQuantizeMulFusion::FakeQuantizeMulFusion() { }; const auto new_fq_node = fq_node->clone_with_new_inputs({fq_node->input_value(0), - fq_node->input_value(1), - fq_node->input_value(2), - get_adjusted_output_range(original_output_low), - get_adjusted_output_range(original_output_high)}); + fq_node->input_value(1), + fq_node->input_value(2), + get_adjusted_output_range(original_output_low), + get_adjusted_output_range(original_output_high)}); bool fq_on_weights = is_type(data.get_node()); if (!fq_on_weights && transformation_callback(new_fq_node)) return false; diff --git a/src/common/transformations/src/transformations/common_optimizations/fq_reshape_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/fq_reshape_fusion.cpp index aed87c1627e..0194639bfff 100644 --- a/src/common/transformations/src/transformations/common_optimizations/fq_reshape_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/fq_reshape_fusion.cpp @@ -2,72 +2,78 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/common_optimizations/fq_reshape_fusion.hpp" #include -#include - #include #include #include +#include + +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::FakeQuantizeReshapeFusion, "FakeQuantizeReshapeFusion", 0); ngraph::pass::FakeQuantizeReshapeFusion::FakeQuantizeReshapeFusion() { MATCHER_SCOPE(FakeQuantizeReshapeFusion); const auto fq_node_p = ngraph::pattern::wrap_type( - {ngraph::pattern::wrap_type(), // for weights only - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input(), - ngraph::pattern::any_input()}, - pattern::consumers_count(1)); + {ngraph::pattern::wrap_type(), // for weights only + ngraph::pattern::any_input(), + ngraph::pattern::any_input(), + ngraph::pattern::any_input(), + ngraph::pattern::any_input()}, + pattern::consumers_count(1)); const auto reshape_node_p = ngraph::pattern::wrap_type( - {fq_node_p, ngraph::pattern::any_input()}, [](const Output & output) { - // WA: check that all Reshape node consumers are not GroupConvolution operations - const auto & target_inputs = output.get_target_inputs(); - return std::all_of(target_inputs.begin(), target_inputs.end(), - [](const Input & input){ - return input.get_node()->get_type_info() != opset4::GroupConvolution::get_type_info_static(); - }); + {fq_node_p, ngraph::pattern::any_input()}, + [](const Output& output) { + // WA: check that all Reshape node consumers are not GroupConvolution operations + const auto& target_inputs = output.get_target_inputs(); + return std::all_of(target_inputs.begin(), target_inputs.end(), [](const Input& input) { + return input.get_node()->get_type_info() != opset4::GroupConvolution::get_type_info_static(); }); + }); - ngraph::matcher_pass_callback callback = [=](pattern::Matcher &m) { - const auto &pattern_map = m.get_pattern_value_map(); + ngraph::matcher_pass_callback callback = [=](pattern::Matcher& m) { + const auto& pattern_map = m.get_pattern_value_map(); const auto fq_node = pattern_map.at(fq_node_p).get_node_shared_ptr(); if (fq_node->is_dynamic()) return false; - const auto &reshape_node = pattern_map.at(reshape_node_p).get_node_shared_ptr(); - const auto &original_data_rank = fq_node->get_input_shape(0).size(); - OutputVector renewed_inputs = {reshape_node->clone_with_new_inputs({fq_node->input_value(0), reshape_node->input_value(1)})}; + const auto& reshape_node = pattern_map.at(reshape_node_p).get_node_shared_ptr(); + const auto& original_data_rank = fq_node->get_input_shape(0).size(); + OutputVector renewed_inputs = { + reshape_node->clone_with_new_inputs({fq_node->input_value(0), reshape_node->input_value(1)})}; for (auto i = 1; i < 5; ++i) { Output limit_input = fq_node->input_value(i); auto limit_shape = limit_input.get_shape(); NGRAPH_CHECK(limit_shape.size() <= original_data_rank, "FakeQuantize limit input has unexpected rank"); - if (limit_shape.size() < original_data_rank) // aligning limit rank with data rank + if (limit_shape.size() < original_data_rank) // aligning limit rank with data rank limit_shape.insert(limit_shape.begin(), original_data_rank - limit_shape.size(), uint64_t(1)); NGRAPH_CHECK(limit_shape.size() == original_data_rank, "FakeQuantize limit input has unexpected rank"); - const auto &limit_size = shape_size(limit_shape); - const auto &max_element = *std::max_element(limit_shape.begin(), limit_shape.end()); - if (max_element == limit_size) { // per-tensor / per-channel limit + const auto& limit_size = shape_size(limit_shape); + const auto& max_element = *std::max_element(limit_shape.begin(), limit_shape.end()); + if (max_element == limit_size) { // per-tensor / per-channel limit auto new_limit_shape = reshape_node->get_output_shape(0); - std::transform(new_limit_shape.begin(), new_limit_shape.end(), new_limit_shape.begin(), - [max_element](size_t &dim) { return dim == max_element ? max_element : 1; }); - const auto &new_limit_size = shape_size(new_limit_shape); - if (new_limit_size == limit_size) { // we tracked future channel placement + std::transform(new_limit_shape.begin(), + new_limit_shape.end(), + new_limit_shape.begin(), + [max_element](size_t& dim) { + return dim == max_element ? max_element : 1; + }); + const auto& new_limit_size = shape_size(new_limit_shape); + if (new_limit_size == limit_size) { // we tracked future channel placement if (new_limit_shape == limit_input.get_shape()) renewed_inputs.push_back(limit_input); else renewed_inputs.push_back(reshape_node->clone_with_new_inputs( - {limit_input, opset4::Constant::create(element::i64, {new_limit_shape.size()}, new_limit_shape)})); + {limit_input, + opset4::Constant::create(element::i64, {new_limit_shape.size()}, new_limit_shape)})); continue; } } // resulting FQ will become or already is more than per-tensor / per-channel return false; } - for (auto &new_input : renewed_inputs) + for (auto& new_input : renewed_inputs) copy_runtime_info({reshape_node, fq_node}, new_input.get_node_shared_ptr()); const auto new_fq_node = fq_node->clone_with_new_inputs(renewed_inputs); replace_node(reshape_node, new_fq_node); diff --git a/src/common/transformations/src/transformations/common_optimizations/gelu_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/gelu_fusion.cpp index 7b92e3dafeb..14adcb372f2 100644 --- a/src/common/transformations/src/transformations/common_optimizations/gelu_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/gelu_fusion.cpp @@ -18,8 +18,7 @@ NGRAPH_RTTI_DEFINITION(ngraph::pass::GeluFusion, "GeluFusion", 0); -NGRAPH_RTTI_DEFINITION(ngraph::pass::GeluFusionWithErfOne, - "GeluFusionWithErfOne", 0); +NGRAPH_RTTI_DEFINITION(ngraph::pass::GeluFusionWithErfOne, "GeluFusionWithErfOne", 0); ngraph::pass::GeluFusionWithErfOne::GeluFusionWithErfOne() { MATCHER_SCOPE(GeluFusionWithErfOne); @@ -27,42 +26,34 @@ ngraph::pass::GeluFusionWithErfOne::GeluFusionWithErfOne() { // Shared by every pattern: (1 + erf(x / sqrt(2))) auto input = ngraph::pattern::any_input(); auto div_constant = ngraph::pattern::wrap_type(); - auto div = ngraph::pattern::wrap_type( - {input, div_constant}); + auto div = ngraph::pattern::wrap_type({input, div_constant}); auto erf = ngraph::pattern::wrap_type({div}); auto add_constant = ngraph::pattern::wrap_type(); - auto add = - ngraph::pattern::wrap_type({add_constant, erf}); + auto add = ngraph::pattern::wrap_type({add_constant, erf}); auto mul_constant = ngraph::pattern::wrap_type(); // (0.5 * x) * (1 + erf(x / sqrt(2)) - auto mul_first = ngraph::pattern::wrap_type( - {input, mul_constant}); - auto mul = - ngraph::pattern::wrap_type({mul_first, add}); + auto mul_first = ngraph::pattern::wrap_type({input, mul_constant}); + auto mul = ngraph::pattern::wrap_type({mul_first, add}); - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { - auto &pattern_to_output = m.get_pattern_value_map(); + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { + auto& pattern_to_output = m.get_pattern_value_map(); auto x_output = pattern_to_output.at(input); - auto div_const_value = - std::dynamic_pointer_cast( - pattern_to_output.at(div_constant).get_node_shared_ptr()); - auto add_const_value = - std::dynamic_pointer_cast( - pattern_to_output.at(add_constant).get_node_shared_ptr()); - auto mul_const_value = - std::dynamic_pointer_cast( - pattern_to_output.at(mul_constant).get_node_shared_ptr()); + auto div_const_value = std::dynamic_pointer_cast( + pattern_to_output.at(div_constant).get_node_shared_ptr()); + auto add_const_value = std::dynamic_pointer_cast( + pattern_to_output.at(add_constant).get_node_shared_ptr()); + auto mul_const_value = std::dynamic_pointer_cast( + pattern_to_output.at(mul_constant).get_node_shared_ptr()); if (!div_const_value || !add_const_value || !mul_const_value) { return false; } - bool valid_constant_values = - op::util::has_constant_value(div_const_value, M_SQRT2) && - op::util::has_constant_value(add_const_value, 1.0f) && - op::util::has_constant_value(mul_const_value, 0.5f); + bool valid_constant_values = op::util::has_constant_value(div_const_value, M_SQRT2) && + op::util::has_constant_value(add_const_value, 1.0f) && + op::util::has_constant_value(mul_const_value, 0.5f); if (!valid_constant_values) { return false; @@ -88,8 +79,7 @@ ngraph::pass::GeluFusionWithErfOne::GeluFusionWithErfOne() { register_matcher(m, callback); } -NGRAPH_RTTI_DEFINITION(ngraph::pass::GeluFusionWithErfTwo, - "GeluFusionWithErfTwo", 0); +NGRAPH_RTTI_DEFINITION(ngraph::pass::GeluFusionWithErfTwo, "GeluFusionWithErfTwo", 0); ngraph::pass::GeluFusionWithErfTwo::GeluFusionWithErfTwo() { MATCHER_SCOPE(GeluFusionWithErfTwo); @@ -97,42 +87,34 @@ ngraph::pass::GeluFusionWithErfTwo::GeluFusionWithErfTwo() { // Shared by every pattern: (1 + erf(x / sqrt(2))) auto input = ngraph::pattern::any_input(); auto div_constant = ngraph::pattern::wrap_type(); - auto div = ngraph::pattern::wrap_type( - {input, div_constant}); + auto div = ngraph::pattern::wrap_type({input, div_constant}); auto erf = ngraph::pattern::wrap_type({div}); auto add_constant = ngraph::pattern::wrap_type(); - auto add = - ngraph::pattern::wrap_type({add_constant, erf}); + auto add = ngraph::pattern::wrap_type({add_constant, erf}); auto mul_constant = ngraph::pattern::wrap_type(); // 0.5 * (x * (1 + erf(x / sqrt(2))) - auto mul_first = - ngraph::pattern::wrap_type({input, add}); - auto mul = ngraph::pattern::wrap_type( - {mul_constant, mul_first}); + auto mul_first = ngraph::pattern::wrap_type({input, add}); + auto mul = ngraph::pattern::wrap_type({mul_constant, mul_first}); - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { - auto &pattern_to_output = m.get_pattern_value_map(); + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { + auto& pattern_to_output = m.get_pattern_value_map(); auto x_output = pattern_to_output.at(input); - auto div_const_value = - std::dynamic_pointer_cast( - pattern_to_output.at(div_constant).get_node_shared_ptr()); - auto add_const_value = - std::dynamic_pointer_cast( - pattern_to_output.at(add_constant).get_node_shared_ptr()); - auto mul_const_value = - std::dynamic_pointer_cast( - pattern_to_output.at(mul_constant).get_node_shared_ptr()); + auto div_const_value = std::dynamic_pointer_cast( + pattern_to_output.at(div_constant).get_node_shared_ptr()); + auto add_const_value = std::dynamic_pointer_cast( + pattern_to_output.at(add_constant).get_node_shared_ptr()); + auto mul_const_value = std::dynamic_pointer_cast( + pattern_to_output.at(mul_constant).get_node_shared_ptr()); if (!div_const_value || !add_const_value || !mul_const_value) { return false; } - bool valid_constant_values = - op::util::has_constant_value(div_const_value, M_SQRT2) && - op::util::has_constant_value(add_const_value, 1.0f) && - op::util::has_constant_value(mul_const_value, 0.5f); + bool valid_constant_values = op::util::has_constant_value(div_const_value, M_SQRT2) && + op::util::has_constant_value(add_const_value, 1.0f) && + op::util::has_constant_value(mul_const_value, 0.5f); if (!valid_constant_values) { return false; @@ -158,8 +140,7 @@ ngraph::pass::GeluFusionWithErfTwo::GeluFusionWithErfTwo() { register_matcher(m, callback); } -NGRAPH_RTTI_DEFINITION(ngraph::pass::GeluFusionWithErfThree, - "GeluFusionWithErfThree", 0); +NGRAPH_RTTI_DEFINITION(ngraph::pass::GeluFusionWithErfThree, "GeluFusionWithErfThree", 0); ngraph::pass::GeluFusionWithErfThree::GeluFusionWithErfThree() { MATCHER_SCOPE(GeluFusionWithErfThree); @@ -167,42 +148,34 @@ ngraph::pass::GeluFusionWithErfThree::GeluFusionWithErfThree() { // Shared by every pattern: (1 + erf(x / sqrt(2))) auto input = ngraph::pattern::any_input(); auto div_constant = ngraph::pattern::wrap_type(); - auto div = ngraph::pattern::wrap_type( - {input, div_constant}); + auto div = ngraph::pattern::wrap_type({input, div_constant}); auto erf = ngraph::pattern::wrap_type({div}); auto add_constant = ngraph::pattern::wrap_type(); - auto add = - ngraph::pattern::wrap_type({add_constant, erf}); + auto add = ngraph::pattern::wrap_type({add_constant, erf}); auto mul_constant = ngraph::pattern::wrap_type(); // x * (0.5 * (1 + erf(x / sqrt(2))) - auto mul_first = ngraph::pattern::wrap_type( - {add, mul_constant}); - auto mul = ngraph::pattern::wrap_type( - {input, mul_first}); + auto mul_first = ngraph::pattern::wrap_type({add, mul_constant}); + auto mul = ngraph::pattern::wrap_type({input, mul_first}); - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { - auto &pattern_to_output = m.get_pattern_value_map(); + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { + auto& pattern_to_output = m.get_pattern_value_map(); auto x_output = pattern_to_output.at(input); - auto div_const_value = - std::dynamic_pointer_cast( - pattern_to_output.at(div_constant).get_node_shared_ptr()); - auto add_const_value = - std::dynamic_pointer_cast( - pattern_to_output.at(add_constant).get_node_shared_ptr()); - auto mul_const_value = - std::dynamic_pointer_cast( - pattern_to_output.at(mul_constant).get_node_shared_ptr()); + auto div_const_value = std::dynamic_pointer_cast( + pattern_to_output.at(div_constant).get_node_shared_ptr()); + auto add_const_value = std::dynamic_pointer_cast( + pattern_to_output.at(add_constant).get_node_shared_ptr()); + auto mul_const_value = std::dynamic_pointer_cast( + pattern_to_output.at(mul_constant).get_node_shared_ptr()); if (!div_const_value || !add_const_value || !mul_const_value) { return false; } - bool valid_constant_values = - op::util::has_constant_value(div_const_value, M_SQRT2) && - op::util::has_constant_value(add_const_value, 1.0f) && - op::util::has_constant_value(mul_const_value, 0.5f); + bool valid_constant_values = op::util::has_constant_value(div_const_value, M_SQRT2) && + op::util::has_constant_value(add_const_value, 1.0f) && + op::util::has_constant_value(mul_const_value, 0.5f); if (!valid_constant_values) { return false; diff --git a/src/common/transformations/src/transformations/common_optimizations/hsigmoid_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/hsigmoid_fusion.cpp index cca1c8ecda0..81025a071b0 100644 --- a/src/common/transformations/src/transformations/common_optimizations/hsigmoid_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/hsigmoid_fusion.cpp @@ -2,15 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/common_optimizations/hsigmoid_fusion.hpp" -#include "transformations/utils/utils.hpp" #include - #include -#include #include +#include + +#include "itt.hpp" +#include "transformations/utils/utils.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::HSigmoidFusion, "HSigmoidFusion", 0); @@ -28,17 +28,20 @@ ngraph::pass::HSigmoidFusionWithReluDiv::HSigmoidFusionWithReluDiv() { auto div_constant = ngraph::pattern::wrap_type(); auto div = ngraph::pattern::wrap_type({min, div_constant}); - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { - auto &pattern_to_output = m.get_pattern_value_map(); + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { + auto& pattern_to_output = m.get_pattern_value_map(); auto x_output = pattern_to_output.at(input); - auto add_const_value = std::dynamic_pointer_cast(pattern_to_output.at(add_constant).get_node_shared_ptr()); - auto min_const_value = std::dynamic_pointer_cast(pattern_to_output.at(min_constant).get_node_shared_ptr()); - auto div_const_value = std::dynamic_pointer_cast(pattern_to_output.at(div_constant).get_node_shared_ptr()); + auto add_const_value = std::dynamic_pointer_cast( + pattern_to_output.at(add_constant).get_node_shared_ptr()); + auto min_const_value = std::dynamic_pointer_cast( + pattern_to_output.at(min_constant).get_node_shared_ptr()); + auto div_const_value = std::dynamic_pointer_cast( + pattern_to_output.at(div_constant).get_node_shared_ptr()); - bool valid_constant_values = op::util::has_constant_value(add_const_value, 3.0) - && op::util::has_constant_value(min_const_value, 6.0) - && op::util::has_constant_value(div_const_value, 6.0); + bool valid_constant_values = op::util::has_constant_value(add_const_value, 3.0) && + op::util::has_constant_value(min_const_value, 6.0) && + op::util::has_constant_value(div_const_value, 6.0); if (!valid_constant_values) { return false; @@ -47,12 +50,14 @@ ngraph::pass::HSigmoidFusionWithReluDiv::HSigmoidFusionWithReluDiv() { auto hsigmoid = register_new_node(x_output); hsigmoid->set_friendly_name(m.get_match_root()->get_friendly_name()); - ngraph::copy_runtime_info({ pattern_to_output.at(add).get_node_shared_ptr(), - pattern_to_output.at(relu).get_node_shared_ptr(), - pattern_to_output.at(min).get_node_shared_ptr(), - pattern_to_output.at(div).get_node_shared_ptr(), - }, - hsigmoid); + ngraph::copy_runtime_info( + { + pattern_to_output.at(add).get_node_shared_ptr(), + pattern_to_output.at(relu).get_node_shared_ptr(), + pattern_to_output.at(min).get_node_shared_ptr(), + pattern_to_output.at(div).get_node_shared_ptr(), + }, + hsigmoid); ngraph::replace_node(m.get_match_root(), hsigmoid); return true; }; @@ -75,17 +80,20 @@ ngraph::pass::HSigmoidFusionWithReluMul::HSigmoidFusionWithReluMul() { auto mul_constant = ngraph::pattern::wrap_type(); auto mul_second = ngraph::pattern::wrap_type({min, mul_constant}); - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { - auto &pattern_to_output = m.get_pattern_value_map(); + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { + auto& pattern_to_output = m.get_pattern_value_map(); auto x_output = pattern_to_output.at(input); - auto add_const_value = std::dynamic_pointer_cast(pattern_to_output.at(add_constant).get_node_shared_ptr()); - auto min_const_value = std::dynamic_pointer_cast(pattern_to_output.at(min_constant).get_node_shared_ptr()); - auto mul_const_value = std::dynamic_pointer_cast(pattern_to_output.at(mul_constant).get_node_shared_ptr()); + auto add_const_value = std::dynamic_pointer_cast( + pattern_to_output.at(add_constant).get_node_shared_ptr()); + auto min_const_value = std::dynamic_pointer_cast( + pattern_to_output.at(min_constant).get_node_shared_ptr()); + auto mul_const_value = std::dynamic_pointer_cast( + pattern_to_output.at(mul_constant).get_node_shared_ptr()); - bool valid_constant_values = op::util::has_constant_value(add_const_value, 3.0f) - && op::util::has_constant_value(min_const_value, 6.0f) - && op::util::has_constant_value(mul_const_value, (1.0f/6.0f), 0.0001f); + bool valid_constant_values = op::util::has_constant_value(add_const_value, 3.0f) && + op::util::has_constant_value(min_const_value, 6.0f) && + op::util::has_constant_value(mul_const_value, (1.0f / 6.0f), 0.0001f); if (!valid_constant_values) { return false; @@ -94,11 +102,10 @@ ngraph::pass::HSigmoidFusionWithReluMul::HSigmoidFusionWithReluMul() { auto hsigmoid = register_new_node(x_output); hsigmoid->set_friendly_name(m.get_match_root()->get_friendly_name()); - ngraph::copy_runtime_info({ pattern_to_output.at(add).get_node_shared_ptr(), - pattern_to_output.at(relu).get_node_shared_ptr(), - pattern_to_output.at(min).get_node_shared_ptr(), - pattern_to_output.at(mul_second).get_node_shared_ptr() - }, + ngraph::copy_runtime_info({pattern_to_output.at(add).get_node_shared_ptr(), + pattern_to_output.at(relu).get_node_shared_ptr(), + pattern_to_output.at(min).get_node_shared_ptr(), + pattern_to_output.at(mul_second).get_node_shared_ptr()}, hsigmoid); ngraph::replace_node(m.get_match_root(), hsigmoid); return true; @@ -124,19 +131,23 @@ ngraph::pass::HSigmoidFusionWithoutRelu::HSigmoidFusionWithoutRelu() { auto div = ngraph::pattern::wrap_type({min, div_constant}); auto mul = ngraph::pattern::wrap_type({input, div}); - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { - auto &pattern_to_output = m.get_pattern_value_map(); + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { + auto& pattern_to_output = m.get_pattern_value_map(); auto x_output = pattern_to_output.at(input); - auto add_const_value = std::dynamic_pointer_cast(pattern_to_output.at(add_constant).get_node_shared_ptr()); - auto max_const_value = std::dynamic_pointer_cast(pattern_to_output.at(max_constant).get_node_shared_ptr()); - auto min_const_value = std::dynamic_pointer_cast(pattern_to_output.at(min_constant).get_node_shared_ptr()); - auto div_const_value = std::dynamic_pointer_cast(pattern_to_output.at(div_constant).get_node_shared_ptr()); + auto add_const_value = std::dynamic_pointer_cast( + pattern_to_output.at(add_constant).get_node_shared_ptr()); + auto max_const_value = std::dynamic_pointer_cast( + pattern_to_output.at(max_constant).get_node_shared_ptr()); + auto min_const_value = std::dynamic_pointer_cast( + pattern_to_output.at(min_constant).get_node_shared_ptr()); + auto div_const_value = std::dynamic_pointer_cast( + pattern_to_output.at(div_constant).get_node_shared_ptr()); - bool valid_constant_values = op::util::has_constant_value(add_const_value, 3.0f) - && op::util::has_constant_value(max_const_value, 0.0f) - && op::util::has_constant_value(min_const_value, 6.0f) - && op::util::has_constant_value(div_const_value, 6.0f); + bool valid_constant_values = op::util::has_constant_value(add_const_value, 3.0f) && + op::util::has_constant_value(max_const_value, 0.0f) && + op::util::has_constant_value(min_const_value, 6.0f) && + op::util::has_constant_value(div_const_value, 6.0f); if (!valid_constant_values) { return false; @@ -145,11 +156,10 @@ ngraph::pass::HSigmoidFusionWithoutRelu::HSigmoidFusionWithoutRelu() { auto hsigmoid = register_new_node(x_output); hsigmoid->set_friendly_name(m.get_match_root()->get_friendly_name()); - ngraph::copy_runtime_info({ pattern_to_output.at(add).get_node_shared_ptr(), - pattern_to_output.at(max).get_node_shared_ptr(), - pattern_to_output.at(min).get_node_shared_ptr(), - pattern_to_output.at(div).get_node_shared_ptr() - }, + ngraph::copy_runtime_info({pattern_to_output.at(add).get_node_shared_ptr(), + pattern_to_output.at(max).get_node_shared_ptr(), + pattern_to_output.at(min).get_node_shared_ptr(), + pattern_to_output.at(div).get_node_shared_ptr()}, hsigmoid); ngraph::replace_node(m.get_match_root(), hsigmoid); return true; @@ -171,31 +181,33 @@ ngraph::pass::HSigmoidFusionWithClampMul::HSigmoidFusionWithClampMul() { auto mul_constant = ngraph::pattern::wrap_type(); auto mul_first = ngraph::pattern::wrap_type({clamp, mul_constant}); - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { - auto &pattern_to_output = m.get_pattern_value_map(); + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { + auto& pattern_to_output = m.get_pattern_value_map(); auto x_output = pattern_to_output.at(input); - auto add_const_value = std::dynamic_pointer_cast(pattern_to_output.at(add_constant).get_node_shared_ptr()); - auto mul_const_value = std::dynamic_pointer_cast(pattern_to_output.at(mul_constant).get_node_shared_ptr()); + auto add_const_value = std::dynamic_pointer_cast( + pattern_to_output.at(add_constant).get_node_shared_ptr()); + auto mul_const_value = std::dynamic_pointer_cast( + pattern_to_output.at(mul_constant).get_node_shared_ptr()); - bool valid_constant_values = op::util::has_constant_value(add_const_value, 3.0) - && op::util::has_constant_value(mul_const_value, (1.0/6.0), 0.0001); + bool valid_constant_values = op::util::has_constant_value(add_const_value, 3.0) && + op::util::has_constant_value(mul_const_value, (1.0 / 6.0), 0.0001); if (!valid_constant_values) { return false; } - auto clamp_node = std::dynamic_pointer_cast(pattern_to_output.at(clamp).get_node_shared_ptr()); + auto clamp_node = + std::dynamic_pointer_cast(pattern_to_output.at(clamp).get_node_shared_ptr()); if (!clamp_node || clamp_node->get_min() != 0 || clamp_node->get_max() != 6) return false; auto hsigmoid = register_new_node(x_output); hsigmoid->set_friendly_name(m.get_match_root()->get_friendly_name()); - ngraph::copy_runtime_info({ pattern_to_output.at(add).get_node_shared_ptr(), - pattern_to_output.at(clamp).get_node_shared_ptr(), - pattern_to_output.at(mul_first).get_node_shared_ptr() - }, + ngraph::copy_runtime_info({pattern_to_output.at(add).get_node_shared_ptr(), + pattern_to_output.at(clamp).get_node_shared_ptr(), + pattern_to_output.at(mul_first).get_node_shared_ptr()}, hsigmoid); ngraph::replace_node(m.get_match_root(), hsigmoid); return true; @@ -217,31 +229,33 @@ ngraph::pass::HSigmoidFusionWithClampDiv::HSigmoidFusionWithClampDiv() { auto div_constant = ngraph::pattern::wrap_type(); auto div = ngraph::pattern::wrap_type({clamp, div_constant}); - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { - auto &pattern_to_output = m.get_pattern_value_map(); + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { + auto& pattern_to_output = m.get_pattern_value_map(); auto x_output = pattern_to_output.at(input); - auto add_const_value = std::dynamic_pointer_cast(pattern_to_output.at(add_constant).get_node_shared_ptr()); - auto div_const_value = std::dynamic_pointer_cast(pattern_to_output.at(div_constant).get_node_shared_ptr()); + auto add_const_value = std::dynamic_pointer_cast( + pattern_to_output.at(add_constant).get_node_shared_ptr()); + auto div_const_value = std::dynamic_pointer_cast( + pattern_to_output.at(div_constant).get_node_shared_ptr()); - bool valid_constant_values = op::util::has_constant_value(add_const_value, 3.0) - && op::util::has_constant_value(div_const_value, 6.0); + bool valid_constant_values = + op::util::has_constant_value(add_const_value, 3.0) && op::util::has_constant_value(div_const_value, 6.0); if (!valid_constant_values) { return false; } - auto clamp_node = std::dynamic_pointer_cast(pattern_to_output.at(clamp).get_node_shared_ptr()); + auto clamp_node = + std::dynamic_pointer_cast(pattern_to_output.at(clamp).get_node_shared_ptr()); if (!clamp_node || clamp_node->get_min() != 0 || clamp_node->get_max() != 6) return false; auto hsigmoid = register_new_node(x_output); hsigmoid->set_friendly_name(m.get_match_root()->get_friendly_name()); - ngraph::copy_runtime_info({ pattern_to_output.at(add).get_node_shared_ptr(), - pattern_to_output.at(clamp).get_node_shared_ptr(), - pattern_to_output.at(div).get_node_shared_ptr() - }, + ngraph::copy_runtime_info({pattern_to_output.at(add).get_node_shared_ptr(), + pattern_to_output.at(clamp).get_node_shared_ptr(), + pattern_to_output.at(div).get_node_shared_ptr()}, hsigmoid); ngraph::replace_node(m.get_match_root(), hsigmoid); return true; diff --git a/src/common/transformations/src/transformations/common_optimizations/hswish_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/hswish_fusion.cpp index bedaf649c44..e233f10a334 100644 --- a/src/common/transformations/src/transformations/common_optimizations/hswish_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/hswish_fusion.cpp @@ -2,15 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/common_optimizations/hswish_fusion.hpp" -#include "transformations/utils/utils.hpp" #include - #include -#include #include +#include + +#include "itt.hpp" +#include "transformations/utils/utils.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::HSwishFusion, "HSwishFusion", 0); @@ -29,17 +29,20 @@ ngraph::pass::HSwishFusionWithReluDiv::HSwishFusionWithReluDiv() { auto div_constant = ngraph::pattern::wrap_type(); auto div = std::make_shared(mul, div_constant); - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { - auto &pattern_to_output = m.get_pattern_value_map(); + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { + auto& pattern_to_output = m.get_pattern_value_map(); auto x_output = pattern_to_output.at(input); - auto add_const_value = std::dynamic_pointer_cast(pattern_to_output.at(add_constant).get_node_shared_ptr()); - auto min_const_value = std::dynamic_pointer_cast(pattern_to_output.at(min_constant).get_node_shared_ptr()); - auto div_const_value = std::dynamic_pointer_cast(pattern_to_output.at(div_constant).get_node_shared_ptr()); + auto add_const_value = std::dynamic_pointer_cast( + pattern_to_output.at(add_constant).get_node_shared_ptr()); + auto min_const_value = std::dynamic_pointer_cast( + pattern_to_output.at(min_constant).get_node_shared_ptr()); + auto div_const_value = std::dynamic_pointer_cast( + pattern_to_output.at(div_constant).get_node_shared_ptr()); - bool valid_constant_values = op::util::has_constant_value(add_const_value, 3.0) - && op::util::has_constant_value(min_const_value, 6.0) - && op::util::has_constant_value(div_const_value, 6.0); + bool valid_constant_values = op::util::has_constant_value(add_const_value, 3.0) && + op::util::has_constant_value(min_const_value, 6.0) && + op::util::has_constant_value(div_const_value, 6.0); if (!valid_constant_values) { return false; @@ -48,16 +51,18 @@ ngraph::pass::HSwishFusionWithReluDiv::HSwishFusionWithReluDiv() { auto hswish = std::make_shared(x_output); hswish->set_friendly_name(m.get_match_root()->get_friendly_name()); - ngraph::copy_runtime_info({ pattern_to_output.at(add_constant).get_node_shared_ptr(), - pattern_to_output.at(add).get_node_shared_ptr(), - pattern_to_output.at(relu).get_node_shared_ptr(), - pattern_to_output.at(min_constant).get_node_shared_ptr(), - pattern_to_output.at(min).get_node_shared_ptr(), - pattern_to_output.at(mul).get_node_shared_ptr(), - pattern_to_output.at(div_constant).get_node_shared_ptr(), - pattern_to_output.at(div).get_node_shared_ptr(), - }, - hswish); + ngraph::copy_runtime_info( + { + pattern_to_output.at(add_constant).get_node_shared_ptr(), + pattern_to_output.at(add).get_node_shared_ptr(), + pattern_to_output.at(relu).get_node_shared_ptr(), + pattern_to_output.at(min_constant).get_node_shared_ptr(), + pattern_to_output.at(min).get_node_shared_ptr(), + pattern_to_output.at(mul).get_node_shared_ptr(), + pattern_to_output.at(div_constant).get_node_shared_ptr(), + pattern_to_output.at(div).get_node_shared_ptr(), + }, + hswish); ngraph::replace_node(m.get_match_root(), hswish); return true; }; @@ -81,17 +86,20 @@ ngraph::pass::HSwishFusionWithReluMul::HSwishFusionWithReluMul() { auto mul_constant = ngraph::pattern::wrap_type(); auto mul_second = std::make_shared(mul_first, mul_constant); - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { - auto &pattern_to_output = m.get_pattern_value_map(); + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { + auto& pattern_to_output = m.get_pattern_value_map(); auto x_output = pattern_to_output.at(input); - auto add_const_value = std::dynamic_pointer_cast(pattern_to_output.at(add_constant).get_node_shared_ptr()); - auto min_const_value = std::dynamic_pointer_cast(pattern_to_output.at(min_constant).get_node_shared_ptr()); - auto mul_const_value = std::dynamic_pointer_cast(pattern_to_output.at(mul_constant).get_node_shared_ptr()); + auto add_const_value = std::dynamic_pointer_cast( + pattern_to_output.at(add_constant).get_node_shared_ptr()); + auto min_const_value = std::dynamic_pointer_cast( + pattern_to_output.at(min_constant).get_node_shared_ptr()); + auto mul_const_value = std::dynamic_pointer_cast( + pattern_to_output.at(mul_constant).get_node_shared_ptr()); - bool valid_constant_values = op::util::has_constant_value(add_const_value, 3.0f) - && op::util::has_constant_value(min_const_value, 6.0f) - && op::util::has_constant_value(mul_const_value, (1.0f/6.0f), 0.0001f); + bool valid_constant_values = op::util::has_constant_value(add_const_value, 3.0f) && + op::util::has_constant_value(min_const_value, 6.0f) && + op::util::has_constant_value(mul_const_value, (1.0f / 6.0f), 0.0001f); if (!valid_constant_values) { return false; @@ -100,15 +108,14 @@ ngraph::pass::HSwishFusionWithReluMul::HSwishFusionWithReluMul() { auto hswish = std::make_shared(x_output); hswish->set_friendly_name(m.get_match_root()->get_friendly_name()); - ngraph::copy_runtime_info({ pattern_to_output.at(add_constant).get_node_shared_ptr(), - pattern_to_output.at(add).get_node_shared_ptr(), - pattern_to_output.at(relu).get_node_shared_ptr(), - pattern_to_output.at(min_constant).get_node_shared_ptr(), - pattern_to_output.at(min).get_node_shared_ptr(), - pattern_to_output.at(mul_first).get_node_shared_ptr(), - pattern_to_output.at(mul_constant).get_node_shared_ptr(), - pattern_to_output.at(mul_second).get_node_shared_ptr() - }, + ngraph::copy_runtime_info({pattern_to_output.at(add_constant).get_node_shared_ptr(), + pattern_to_output.at(add).get_node_shared_ptr(), + pattern_to_output.at(relu).get_node_shared_ptr(), + pattern_to_output.at(min_constant).get_node_shared_ptr(), + pattern_to_output.at(min).get_node_shared_ptr(), + pattern_to_output.at(mul_first).get_node_shared_ptr(), + pattern_to_output.at(mul_constant).get_node_shared_ptr(), + pattern_to_output.at(mul_second).get_node_shared_ptr()}, hswish); ngraph::replace_node(m.get_match_root(), hswish); return true; @@ -127,7 +134,7 @@ ngraph::pass::HSwishFusionWithHSigmoid::HSwishFusionWithHSigmoid() { auto hsigmoid_pattern = pattern::wrap_type({input}, pattern::consumers_count(1)); auto mul_pattern = pattern::wrap_type({input, hsigmoid_pattern}); - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { const auto& pattern_to_output = m.get_pattern_value_map(); auto hsigmoid = pattern_to_output.at(hsigmoid_pattern).get_node_shared_ptr(); auto mul = pattern_to_output.at(mul_pattern).get_node_shared_ptr(); @@ -154,27 +161,30 @@ ngraph::pass::HSwishFusionWithClamp::HSwishFusionWithClamp() { const auto clamp = ngraph::pattern::wrap_type({add}); const auto mul = ngraph::pattern::wrap_type({clamp, input}); - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { - const auto &pattern_to_output = m.get_pattern_value_map(); + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { + const auto& pattern_to_output = m.get_pattern_value_map(); const auto x_output = pattern_to_output.at(input); - const auto add_const_value = std::dynamic_pointer_cast(pattern_to_output.at(add_constant).get_node_shared_ptr()); + const auto add_const_value = std::dynamic_pointer_cast( + pattern_to_output.at(add_constant).get_node_shared_ptr()); if (!op::util::has_constant_value(add_const_value, 3.0)) { return false; } - const auto clamp_node = std::dynamic_pointer_cast(pattern_to_output.at(clamp).get_node_shared_ptr()); + const auto clamp_node = + std::dynamic_pointer_cast(pattern_to_output.at(clamp).get_node_shared_ptr()); if (!clamp_node || clamp_node->get_min() != 0 || clamp_node->get_max() != 6) return false; auto hswish = std::make_shared(x_output); - auto new_mul_const = std::make_shared(add_const_value->get_element_type(), Shape{}, std::vector{6.0}); + auto new_mul_const = std::make_shared(add_const_value->get_element_type(), + Shape{}, + std::vector{6.0}); auto new_mul = std::make_shared(hswish, new_mul_const); new_mul->set_friendly_name(m.get_match_root()->get_friendly_name()); - ngraph::copy_runtime_info({ pattern_to_output.at(add).get_node_shared_ptr(), - pattern_to_output.at(clamp).get_node_shared_ptr(), - pattern_to_output.at(mul).get_node_shared_ptr() - }, + ngraph::copy_runtime_info({pattern_to_output.at(add).get_node_shared_ptr(), + pattern_to_output.at(clamp).get_node_shared_ptr(), + pattern_to_output.at(mul).get_node_shared_ptr()}, {hswish, new_mul_const, new_mul}); ngraph::replace_node(m.get_match_root(), new_mul); return true; diff --git a/src/common/transformations/src/transformations/common_optimizations/interpolate_sequence_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/interpolate_sequence_fusion.cpp index 5157d56aa5d..ba4bd4674b1 100644 --- a/src/common/transformations/src/transformations/common_optimizations/interpolate_sequence_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/interpolate_sequence_fusion.cpp @@ -2,20 +2,20 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/common_optimizations/interpolate_sequence_fusion.hpp" #include #include +#include #include #include #include #include -#include +#include "itt.hpp" // #include -#include #include +#include namespace { using namespace ngraph; @@ -23,7 +23,8 @@ using namespace ngraph; bool compatible_axes(const std::vector& fst_axes_vector, const std::vector& snd_axes_vector) { std::set fst_axes_set(fst_axes_vector.begin(), fst_axes_vector.end()); for (const auto& a : snd_axes_vector) { - if (fst_axes_set.count(a) != 0) return false; + if (fst_axes_set.count(a) != 0) + return false; } return true; } @@ -31,14 +32,16 @@ bool compatible_axes(const std::vector& fst_axes_vector, const std::vec bool shape_calculation_mode_can_use_constant_inputs(const std::shared_ptr& interpolate) { const auto& attrs = interpolate->get_attrs(); if (attrs.shape_calculation_mode == ngraph::opset8::Interpolate::ShapeCalcMode::SIZES) { - return std::dynamic_pointer_cast(interpolate->input_value(1).get_node_shared_ptr()) != nullptr; + return std::dynamic_pointer_cast(interpolate->input_value(1).get_node_shared_ptr()) != + nullptr; } return std::dynamic_pointer_cast(interpolate->input_value(2).get_node_shared_ptr()) != nullptr; } bool is_candidate_for_fusion(const std::shared_ptr& interpolate) { return (interpolate->get_input_partial_shape(0).rank().is_static()) && - (interpolate->inputs().size() != 4 || std::dynamic_pointer_cast(interpolate->input_value(3).get_node_shared_ptr())) && + (interpolate->inputs().size() != 4 || + std::dynamic_pointer_cast(interpolate->input_value(3).get_node_shared_ptr())) && shape_calculation_mode_can_use_constant_inputs(interpolate); } @@ -51,31 +54,36 @@ std::vector get_interpolated_axes(const std::shared_ptr(interpolate->input_value(3).get_node_shared_ptr())->cast_vector(); + return std::dynamic_pointer_cast(interpolate->input_value(3).get_node_shared_ptr()) + ->cast_vector(); } bool can_be_fused(const std::shared_ptr& fst, const std::shared_ptr& snd) { // The first Interpolate (fst) must have only one consumer. for (const auto& output : fst->outputs()) { for (const auto& consumer : output.get_target_inputs()) { - if (consumer.get_node() != snd.get()) return false; + if (consumer.get_node() != snd.get()) + return false; } } - if (fst->get_attrs() != snd->get_attrs() || !is_candidate_for_fusion(fst) || !is_candidate_for_fusion(snd)) return false; + if (fst->get_attrs() != snd->get_attrs() || !is_candidate_for_fusion(fst) || !is_candidate_for_fusion(snd)) + return false; const auto fst_axes = get_interpolated_axes(fst); const auto snd_axes = get_interpolated_axes(snd); return compatible_axes(fst_axes, snd_axes); } -ngraph::NodeVector subgraph_for_sizes_calculation_mode(const std::shared_ptr& fst, const std::shared_ptr& snd, +ngraph::NodeVector subgraph_for_sizes_calculation_mode(const std::shared_ptr& fst, + const std::shared_ptr& snd, pass::MatcherPass* matcherPass) { const auto fst_axes = get_interpolated_axes(fst); const auto snd_axes = get_interpolated_axes(snd); const auto fst_sizes_node = std::dynamic_pointer_cast(fst->input_value(1).get_node_shared_ptr()); const auto snd_sizes_node = std::dynamic_pointer_cast(snd->input_value(1).get_node_shared_ptr()); - if (!fst_sizes_node || !snd_sizes_node) return {}; + if (!fst_sizes_node || !snd_sizes_node) + return {}; const auto fst_sizes = fst_sizes_node->cast_vector(); const auto snd_sizes = snd_sizes_node->cast_vector(); @@ -109,20 +117,30 @@ ngraph::NodeVector subgraph_for_sizes_calculation_mode(const std::shared_ptr(new_sizes_cast, cast_shape_to_float); - const auto new_interpolate = ov::as_type_ptr(fst->clone_with_new_inputs({fst->input_value(0), new_sizes_node, div_node, - new_axes_node})); + const auto new_interpolate = ov::as_type_ptr( + fst->clone_with_new_inputs({fst->input_value(0), new_sizes_node, div_node, new_axes_node})); matcherPass->register_new_node(new_interpolate); - return {new_sizes_node, new_axes_node, new_sizes_cast, shape_node, gather_axis_node, gather_node, cast_shape_to_float, div_node, new_interpolate}; + return {new_sizes_node, + new_axes_node, + new_sizes_cast, + shape_node, + gather_axis_node, + gather_node, + cast_shape_to_float, + div_node, + new_interpolate}; } -ngraph::NodeVector subgraph_for_scales_calculation_mode(const std::shared_ptr& fst, const std::shared_ptr& snd, +ngraph::NodeVector subgraph_for_scales_calculation_mode(const std::shared_ptr& fst, + const std::shared_ptr& snd, pass::MatcherPass* matcherPass) { const auto fst_axes = get_interpolated_axes(fst); const auto snd_axes = get_interpolated_axes(snd); const auto fst_scales_node = std::dynamic_pointer_cast(fst->input_value(2).get_node_shared_ptr()); const auto snd_scales_node = std::dynamic_pointer_cast(snd->input_value(2).get_node_shared_ptr()); - if (!fst_scales_node || !snd_scales_node) return {}; + if (!fst_scales_node || !snd_scales_node) + return {}; const auto fst_scales = fst_scales_node->cast_vector(); const auto snd_scales = snd_scales_node->cast_vector(); @@ -159,14 +177,24 @@ ngraph::NodeVector subgraph_for_scales_calculation_mode(const std::shared_ptr(add_node); auto cast_mul_result_to_int = std::make_shared(floor_node, element::i64); - const auto new_interpolate = ov::as_type_ptr(fst->clone_with_new_inputs({fst->input_value(0), cast_mul_result_to_int, - new_scales_node, new_axes_node})); + const auto new_interpolate = ov::as_type_ptr( + fst->clone_with_new_inputs({fst->input_value(0), cast_mul_result_to_int, new_scales_node, new_axes_node})); matcherPass->register_new_node(new_interpolate); - return {new_scales_node, new_axes_node, shape_node, gather_axis_node, gather_node, cast_shape_to_float, mul_node, eps_node, - add_node, floor_node, cast_mul_result_to_int, new_interpolate}; + return {new_scales_node, + new_axes_node, + shape_node, + gather_axis_node, + gather_node, + cast_shape_to_float, + mul_node, + eps_node, + add_node, + floor_node, + cast_mul_result_to_int, + new_interpolate}; } -} // namespace +} // namespace NGRAPH_RTTI_DEFINITION(ngraph::pass::InterpolateSequenceFusion, "InterpolateSequenceFusion", 0); @@ -175,12 +203,16 @@ ngraph::pass::InterpolateSequenceFusion::InterpolateSequenceFusion() { auto interpolate_pattern = ngraph::pattern::wrap_type(); ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { auto snd_interpolate = std::dynamic_pointer_cast(m.get_match_root()); - if (!snd_interpolate) return false; + if (!snd_interpolate) + return false; - auto fst_interpolate = std::dynamic_pointer_cast(snd_interpolate->input_value(0).get_node_shared_ptr()); - if (!fst_interpolate) return false; + auto fst_interpolate = + std::dynamic_pointer_cast(snd_interpolate->input_value(0).get_node_shared_ptr()); + if (!fst_interpolate) + return false; - if (!can_be_fused(fst_interpolate, snd_interpolate)) return false; + if (!can_be_fused(fst_interpolate, snd_interpolate)) + return false; NodeVector new_subgraph; if (fst_interpolate->get_attrs().shape_calculation_mode == ngraph::opset8::Interpolate::ShapeCalcMode::SIZES) { @@ -188,7 +220,8 @@ ngraph::pass::InterpolateSequenceFusion::InterpolateSequenceFusion() { } else { new_subgraph = subgraph_for_scales_calculation_mode(fst_interpolate, snd_interpolate, this); } - if (new_subgraph.empty()) return false; + if (new_subgraph.empty()) + return false; auto& new_interpolate = new_subgraph.back(); new_interpolate->set_friendly_name(snd_interpolate->get_friendly_name()); diff --git a/src/common/transformations/src/transformations/common_optimizations/leaky_relu_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/leaky_relu_fusion.cpp index 9b98c8e7124..74af8fe6b7c 100644 --- a/src/common/transformations/src/transformations/common_optimizations/leaky_relu_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/leaky_relu_fusion.cpp @@ -3,16 +3,15 @@ // #include "transformations/common_optimizations/leaky_relu_fusion.hpp" -#include "transformations/utils/utils.hpp" #include +#include +#include +#include #include -#include -#include -#include #include "itt.hpp" - +#include "transformations/utils/utils.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::LeakyReluFusion, "LeakyReluFusion", 0); @@ -20,24 +19,23 @@ ngraph::pass::LeakyReluFusion::LeakyReluFusion() { MATCHER_SCOPE(LeakyReluFusion); auto data_pattern = ngraph::pattern::any_input(); auto alpha_pattern = ngraph::pattern::any_input(pattern::has_static_shape()); - auto multiply_pattern = ngraph::pattern::wrap_type({data_pattern, alpha_pattern}, pattern::consumers_count(1)); + auto multiply_pattern = + ngraph::pattern::wrap_type({data_pattern, alpha_pattern}, pattern::consumers_count(1)); auto max_pattern = ngraph::pattern::wrap_type({data_pattern, multiply_pattern}); ngraph::matcher_pass_callback callback = [=](pattern::Matcher& m) { - const auto & pattern_map = m.get_pattern_value_map(); - const auto & original_alpha_pattern = pattern_map.at(alpha_pattern); + const auto& pattern_map = m.get_pattern_value_map(); + const auto& original_alpha_pattern = pattern_map.at(alpha_pattern); if (shape_size(original_alpha_pattern.get_shape()) != 1) return false; - auto leaky_relu = register_new_node(pattern_map.at(data_pattern), original_alpha_pattern); + auto leaky_relu = + register_new_node(pattern_map.at(data_pattern), original_alpha_pattern); auto maximum = pattern_map.at(max_pattern); leaky_relu->set_friendly_name(maximum.get_node()->get_friendly_name()); - copy_runtime_info({ - pattern_map.at(multiply_pattern).get_node_shared_ptr(), - maximum.get_node_shared_ptr() - }, + copy_runtime_info({pattern_map.at(multiply_pattern).get_node_shared_ptr(), maximum.get_node_shared_ptr()}, leaky_relu); replace_node(maximum.get_node_shared_ptr(), leaky_relu); diff --git a/src/common/transformations/src/transformations/common_optimizations/lin_op_sequence_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/lin_op_sequence_fusion.cpp index 2d4bce6b417..7d1ff2c7b28 100644 --- a/src/common/transformations/src/transformations/common_optimizations/lin_op_sequence_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/lin_op_sequence_fusion.cpp @@ -2,16 +2,16 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/common_optimizations/lin_op_sequence_fusion.hpp" #include +#include +#include +#include +#include #include -#include -#include -#include -#include +#include "itt.hpp" using namespace ngraph; @@ -28,8 +28,8 @@ ngraph::pass::AddMultiplyFusion::AddMultiplyFusion() { auto m_mul_constant = ngraph::pattern::wrap_type(); auto m_mul = ngraph::pattern::wrap_type({m_add, m_mul_constant}); - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher & m) -> bool { - auto & label_to_output = m.get_pattern_value_map(); + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) -> bool { + auto& label_to_output = m.get_pattern_value_map(); auto mul = label_to_output[m_mul].get_node_shared_ptr(); auto add = label_to_output[m_add].get_node_shared_ptr(); @@ -42,7 +42,8 @@ ngraph::pass::AddMultiplyFusion::AddMultiplyFusion() { Output mul_const = label_to_output[m_mul_constant]; Output add_const = label_to_output[m_add_constant]; - if ((input.get_element_type() != mul_const.get_element_type()) || (add_const.get_element_type() != mul_const.get_element_type())) { + if ((input.get_element_type() != mul_const.get_element_type()) || + (add_const.get_element_type() != mul_const.get_element_type())) { return false; } @@ -52,7 +53,8 @@ ngraph::pass::AddMultiplyFusion::AddMultiplyFusion() { auto new_mul = register_new_node(input, mul_const); // Add two constants using opset3::Add constant folding and create new Add operation - auto new_add = std::make_shared(new_mul, op::util::eltwise_fold(add_const, mul_const)); + auto new_add = + std::make_shared(new_mul, op::util::eltwise_fold(add_const, mul_const)); copy_runtime_info({add, mul}, {new_mul, new_add}); new_add->set_friendly_name(mul->get_friendly_name()); @@ -75,8 +77,8 @@ ngraph::pass::AddAddFusion::AddAddFusion() { auto m_add2_constant = ngraph::pattern::wrap_type(); auto m_add2 = ngraph::pattern::wrap_type({m_add1, m_add2_constant}); - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher & m) -> bool { - auto & label_to_output = m.get_pattern_value_map(); + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) -> bool { + auto& label_to_output = m.get_pattern_value_map(); auto add1 = label_to_output[m_add1].get_node_shared_ptr(); auto add2 = label_to_output[m_add2].get_node_shared_ptr(); @@ -87,7 +89,8 @@ ngraph::pass::AddAddFusion::AddAddFusion() { // Replace Add->Add with single Add // Add operation will be added to the list of ops requested for pattern matching - auto new_add = register_new_node(input, op::util::eltwise_fold(add1_const, add2_const)); + auto new_add = + register_new_node(input, op::util::eltwise_fold(add1_const, add2_const)); copy_runtime_info({add1, add2}, new_add); new_add->set_friendly_name(add2->get_friendly_name()); @@ -110,8 +113,8 @@ ngraph::pass::MultiplyMultiplyFusion::MultiplyMultiplyFusion() { auto m_mul2_constant = ngraph::pattern::wrap_type(); auto m_mul2 = ngraph::pattern::wrap_type({m_mul1, m_mul2_constant}); - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher & m) -> bool { - auto & label_to_output = m.get_pattern_value_map(); + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) -> bool { + auto& label_to_output = m.get_pattern_value_map(); auto mul1 = label_to_output[m_mul1].get_node_shared_ptr(); auto mul2 = label_to_output[m_mul2].get_node_shared_ptr(); @@ -122,7 +125,9 @@ ngraph::pass::MultiplyMultiplyFusion::MultiplyMultiplyFusion() { // Replace Multiply->Multiply with single Multiply // Multiply operation will be added to the list of ops requested for pattern matching - auto new_mul = register_new_node(input, op::util::eltwise_fold(mul1_const, mul2_const)); + auto new_mul = + register_new_node(input, + op::util::eltwise_fold(mul1_const, mul2_const)); copy_runtime_info({mul1, mul2}, new_mul); new_mul->set_friendly_name(mul2->get_friendly_name()); diff --git a/src/common/transformations/src/transformations/common_optimizations/mark_precision_sensitive_divides.cpp b/src/common/transformations/src/transformations/common_optimizations/mark_precision_sensitive_divides.cpp index afddeeec062..c57fd4db283 100644 --- a/src/common/transformations/src/transformations/common_optimizations/mark_precision_sensitive_divides.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/mark_precision_sensitive_divides.cpp @@ -13,8 +13,8 @@ #include "transformations/utils/utils.hpp" bool ov::pass::MarkPrecisionSensitiveDivides::run_on_model(const std::shared_ptr& m) { - std::deque nodes; - std::unordered_set visited, precision_sensitive_visited; + std::deque nodes; + std::unordered_set visited, precision_sensitive_visited; for (auto& r : m->get_results()) { nodes.push_back(r.get()); visited.insert(r.get()); @@ -48,7 +48,8 @@ bool ov::pass::MarkPrecisionSensitiveDivides::run_on_model(const std::shared_ptr for (auto& input_value : curr_node->input_values()) { // continue searching const auto& input_node = input_value.get_node(); - if (visited.count(input_node)) continue; + if (visited.count(input_node)) + continue; nodes.push_front(input_node); visited.insert(input_node); } diff --git a/src/common/transformations/src/transformations/common_optimizations/mark_precision_sensitive_subgraphs.cpp b/src/common/transformations/src/transformations/common_optimizations/mark_precision_sensitive_subgraphs.cpp index dd1775bd951..4c218c9c75d 100644 --- a/src/common/transformations/src/transformations/common_optimizations/mark_precision_sensitive_subgraphs.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/mark_precision_sensitive_subgraphs.cpp @@ -29,7 +29,7 @@ bool ov::pass::MarkPrecisionSensitiveSubgraphs::run_on_model(const std::shared_p visited.insert(r.get()); } - auto markup_func = [](Node * node) { + auto markup_func = [](Node* node) { if (ov::is_type(node)) { ov::disable_fp16_compression(node->shared_from_this()); } @@ -42,14 +42,16 @@ bool ov::pass::MarkPrecisionSensitiveSubgraphs::run_on_model(const std::shared_p if (ov::is_precision_sensitive(input)) { visited.insert(input.get_source_output().get_node()); ngraph::op::util::visit_shape_path(input.get_source_output().get_node(), - precision_sensitive_visited, markup_func); + precision_sensitive_visited, + markup_func); } } for (auto& input_value : curr_node->input_values()) { // continue searching const auto& input_node = input_value.get_node(); - if (visited.count(input_node)) continue; + if (visited.count(input_node)) + continue; nodes.push_front(input_node); visited.insert(input_node); } diff --git a/src/common/transformations/src/transformations/common_optimizations/matmul_const_transposes_extraction.cpp b/src/common/transformations/src/transformations/common_optimizations/matmul_const_transposes_extraction.cpp index 07cb1bf115f..3558be6499f 100644 --- a/src/common/transformations/src/transformations/common_optimizations/matmul_const_transposes_extraction.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/matmul_const_transposes_extraction.cpp @@ -13,13 +13,12 @@ NGRAPH_RTTI_DEFINITION(ngraph::pass::MatMulConstTransposesExtraction, "MatMulCon ngraph::pass::MatMulConstTransposesExtraction::MatMulConstTransposesExtraction() { auto data_pattern = pattern::any_input(); - auto weights_pattern = pattern::wrap_type([](Output node) -> bool { - const auto& pshape = node.get_partial_shape(); - const auto& rank = pshape.rank(); - return rank.is_static() && rank.get_length() >= 2 && - std::count(pshape.begin(), pshape.end(), 1) >= rank.get_length() - 2; - }); + auto weights_pattern = pattern::wrap_type([](Output node) -> bool { + const auto& pshape = node.get_partial_shape(); + const auto& rank = pshape.rank(); + return rank.is_static() && rank.get_length() >= 2 && + std::count(pshape.begin(), pshape.end(), 1) >= rank.get_length() - 2; + }); auto matmul_pattern = pattern::wrap_type({data_pattern, weights_pattern}); matcher_pass_callback callback = [=](pattern::Matcher& m) { auto node = m.get_match_root(); @@ -33,13 +32,17 @@ ngraph::pass::MatMulConstTransposesExtraction::MatMulConstTransposesExtraction() std::vector transpose_order(weights.get_partial_shape().size()); std::iota(transpose_order.begin(), transpose_order.end(), 0); std::reverse(transpose_order.end() - 2, transpose_order.end()); - std::shared_ptr transpose = std::make_shared(weights, - op::Constant::create(element::i32, {transpose_order.size()}, transpose_order)); + std::shared_ptr transpose = std::make_shared( + weights, + op::Constant::create(element::i32, {transpose_order.size()}, transpose_order)); if (ov::is_type(weights.get_node())) { if (auto constant = get_constant_from_source(transpose)) transpose = constant; } - auto new_matmul = std::make_shared(pattern_value_map.at(data_pattern), transpose, matmul->get_transpose_a(), true); + auto new_matmul = std::make_shared(pattern_value_map.at(data_pattern), + transpose, + matmul->get_transpose_a(), + true); new_matmul->set_friendly_name(matmul->get_friendly_name()); copy_runtime_info(node, {transpose, new_matmul}); replace_node(node, new_matmul); diff --git a/src/common/transformations/src/transformations/common_optimizations/matmul_multiply_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/matmul_multiply_fusion.cpp index 0dc61b235a4..c86bfad7a80 100644 --- a/src/common/transformations/src/transformations/common_optimizations/matmul_multiply_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/matmul_multiply_fusion.cpp @@ -3,12 +3,13 @@ // #include "transformations/common_optimizations/matmul_multiply_fusion.hpp" -#include "transformations/utils/utils.hpp" #include #include #include + #include "itt.hpp" +#include "transformations/utils/utils.hpp" using namespace ngraph; @@ -61,7 +62,8 @@ static std::shared_ptr fuse_const_to_weights(const std::shared_ptr& // Check if const's last dimension matches last weights dimension if (matmul_casted->get_transpose_b()) { if (weights_shape[weights_rank - 2].is_dynamic() || - (weights_rank > 1 && const_shape.back() != static_cast(weights_shape[weights_rank - 2].get_length()))) { + (weights_rank > 1 && + const_shape.back() != static_cast(weights_shape[weights_rank - 2].get_length()))) { return nullptr; } } else if (weights_shape[weights_rank - 1].is_dynamic() || @@ -83,8 +85,9 @@ static std::shared_ptr fuse_const_to_weights(const std::shared_ptr& bool const_broadcasts_weights = weights_rank < const_rank; for (int64_t i = 3; i <= const_rank; i++) { if (const_shape[const_rank - i] != 1) { - const_broadcasts_weights = const_broadcasts_weights || - ((weights_rank - i >= 0) && (weights_shape[weights_rank - i] != const_shape[const_rank - i])); + const_broadcasts_weights = + const_broadcasts_weights || + ((weights_rank - i >= 0) && (weights_shape[weights_rank - i] != const_shape[const_rank - i])); } } bool const_broadcasts_input = true; @@ -94,8 +97,9 @@ static std::shared_ptr fuse_const_to_weights(const std::shared_ptr& const_broadcasts_input = input_rank < const_rank; for (int64_t i = 3; i <= const_rank; i++) { if (const_shape[const_rank - i] != 1) { - const_broadcasts_input = const_broadcasts_input || - ((input_rank - i >= 0) && (input_shape[input_rank - i] != const_shape[const_rank - i])); + const_broadcasts_input = + const_broadcasts_input || + ((input_rank - i >= 0) && (input_shape[input_rank - i] != const_shape[const_rank - i])); } } } @@ -105,10 +109,11 @@ static std::shared_ptr fuse_const_to_weights(const std::shared_ptr& } } - auto transpose_const = [] (const std::shared_ptr& mul_const) -> std::shared_ptr { + auto transpose_const = [](const std::shared_ptr& mul_const) -> std::shared_ptr { auto const_shape = mul_const->get_shape(); auto const_rank = const_shape.size(); - if (shape_size(const_shape) == 1 || (const_rank > 1 && const_shape[const_rank - 2] == 1 && const_shape[const_rank - 1] == 1)) { + if (shape_size(const_shape) == 1 || + (const_rank > 1 && const_shape[const_rank - 2] == 1 && const_shape[const_rank - 1] == 1)) { // Nothing to transpose - constant has shape (..., 1, 1) return mul_const; } @@ -116,14 +121,17 @@ static std::shared_ptr fuse_const_to_weights(const std::shared_ptr& // Scalars were fused before, it suffices to check for 1D shape here if (const_rank == 1) { const_shape.insert(const_shape.begin(), 1); - new_const = std::make_shared(mul_const, - opset8::Constant::create(element::u64, Shape{const_shape.size()}, const_shape), false); + new_const = std::make_shared( + mul_const, + opset8::Constant::create(element::u64, Shape{const_shape.size()}, const_shape), + false); } std::vector perm(const_shape.size()); std::iota(perm.begin(), perm.end(), 0); std::swap(*(perm.end() - 1), *(perm.end() - 2)); - auto transpose = std::make_shared(new_const, - opset8::Constant::create(element::i64, Shape{perm.size()}, perm)); + auto transpose = + std::make_shared(new_const, + opset8::Constant::create(element::i64, Shape{perm.size()}, perm)); return get_constant_from_source(transpose); }; @@ -149,7 +157,8 @@ pass::MatMulMultiplyFusion::MatMulMultiplyFusion() { const auto& pattern_map = m.get_pattern_value_map(); const auto& weights = pattern_map.at(weights_pattern); auto mul = pattern_map.at(mul_pattern).get_node_shared_ptr(); - auto mul_const = std::dynamic_pointer_cast(pattern_map.at(mul_const_pattern).get_node_shared_ptr()); + auto mul_const = + std::dynamic_pointer_cast(pattern_map.at(mul_const_pattern).get_node_shared_ptr()); if (!mul_const) return false; auto matmul = pattern_map.at(matmul_pattern).get_node_shared_ptr(); diff --git a/src/common/transformations/src/transformations/common_optimizations/mish_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/mish_fusion.cpp index 5037c16fc5d..0567bce6cdb 100644 --- a/src/common/transformations/src/transformations/common_optimizations/mish_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/mish_fusion.cpp @@ -2,15 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/common_optimizations/mish_fusion.hpp" #include +#include +#include +#include #include -#include -#include -#include +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::MishFusion, "MishFusion", 0); @@ -24,7 +24,7 @@ ngraph::pass::MishFusion::MishFusion() { auto mul = std::make_shared(input, tanh); ngraph::matcher_pass_callback matcher_pass_callback = [=](ngraph::pattern::Matcher& m) { - auto & pattern_to_output = m.get_pattern_value_map(); + auto& pattern_to_output = m.get_pattern_value_map(); auto exp_input = pattern_to_output.at(input); auto mish = std::make_shared(exp_input); @@ -34,7 +34,8 @@ ngraph::pass::MishFusion::MishFusion() { pattern_to_output.at(tanh).get_node_shared_ptr(), pattern_to_output.at(log).get_node_shared_ptr(), pattern_to_output.at(add).get_node_shared_ptr(), - pattern_to_output.at(exp).get_node_shared_ptr()}, mish); + pattern_to_output.at(exp).get_node_shared_ptr()}, + mish); ngraph::replace_node(m.get_match_root(), mish); return true; }; diff --git a/src/common/transformations/src/transformations/common_optimizations/moc_transformations.cpp b/src/common/transformations/src/transformations/common_optimizations/moc_transformations.cpp index e75372e89d4..a77601e3821 100644 --- a/src/common/transformations/src/transformations/common_optimizations/moc_transformations.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/moc_transformations.cpp @@ -3,63 +3,61 @@ // #include - -#include -#include - -#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include #include +#include +#include +#include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include NGRAPH_RTTI_DEFINITION(ngraph::pass::MOCTransformations, "MOCTransformations", 0); @@ -68,7 +66,7 @@ bool ngraph::pass::MOCTransformations::run_on_model(const std::shared_ptr input_shapes; if (!m_use_shapes) { - for (auto &¶m : f->get_parameters()) { + for (auto&& param : f->get_parameters()) { input_shapes[param.get()] = param->get_partial_shape(); param->set_partial_shape(PartialShape::dynamic(param->get_partial_shape().rank())); } @@ -81,7 +79,7 @@ bool ngraph::pass::MOCTransformations::run_on_model(const std::shared_ptr(); if (m_low_precision_enabled) { manager.register_pass( - element::TypeVector{ ngraph::element::i8, ngraph::element::u8, ngraph::element::i4, ngraph::element::u4 }); + element::TypeVector{ngraph::element::i8, ngraph::element::u8, ngraph::element::i4, ngraph::element::u4}); } if (!m_use_shapes) { manager.register_pass(); @@ -191,7 +189,7 @@ bool ngraph::pass::MOCTransformations::run_on_model(const std::shared_ptrget_parameters()) { + for (auto&& param : f->get_parameters()) { param->set_partial_shape(input_shapes.at(param.get())); } f->validate_nodes_and_infer_types(); diff --git a/src/common/transformations/src/transformations/common_optimizations/mul_conv_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/mul_conv_fusion.cpp index e5a74bdca70..28a0196dba2 100644 --- a/src/common/transformations/src/transformations/common_optimizations/mul_conv_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/mul_conv_fusion.cpp @@ -3,18 +3,17 @@ // #include "transformations/common_optimizations/mul_conv_fusion.hpp" -#include "itt.hpp" #include +#include +#include +#include +#include +#include +#include #include -#include -#include -#include -#include -#include - -#include +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::MultiplyConvolutionFusion, "MultiplyConvolutionFusion", 0); @@ -22,11 +21,12 @@ ngraph::pass::MultiplyConvolutionFusion::MultiplyConvolutionFusion() { MATCHER_SCOPE(MultiplyConvolutionFusion); auto input_pattern = pattern::any_input(); auto mul_const_pattern = ngraph::pattern::wrap_type(); - auto mul_pattern = ngraph::pattern::wrap_type({input_pattern, mul_const_pattern}, pattern::consumers_count(1)); + auto mul_pattern = + ngraph::pattern::wrap_type({input_pattern, mul_const_pattern}, pattern::consumers_count(1)); auto weights_pattern = ngraph::pattern::any_input(pattern::has_static_shape()); auto conv_pattern = ngraph::pattern::wrap_type({mul_pattern, weights_pattern}); - matcher_pass_callback callback = [=](pattern::Matcher & m) -> bool { + matcher_pass_callback callback = [=](pattern::Matcher& m) -> bool { const auto& pattern_to_output = m.get_pattern_value_map(); // Can't fuse Multiply to Convolution if that Multiply is part of dequantization subgraph @@ -58,8 +58,7 @@ ngraph::pass::MultiplyConvolutionFusion::MultiplyConvolutionFusion() { auto new_conv = conv->clone_with_new_inputs({input, new_weights}); new_conv->set_friendly_name(conv->get_friendly_name()); - copy_runtime_info({conv, pattern_to_output.at(mul_pattern).get_node_shared_ptr()}, - {new_weights, new_conv}); + copy_runtime_info({conv, pattern_to_output.at(mul_pattern).get_node_shared_ptr()}, {new_weights, new_conv}); replace_node(conv, new_conv); return true; @@ -75,11 +74,12 @@ ngraph::pass::MultiplyGroupConvolutionFusion::MultiplyGroupConvolutionFusion() { MATCHER_SCOPE(MultiplyGroupConvolutionFusion); auto input_pattern = pattern::any_input(); auto mul_const_pattern = ngraph::pattern::wrap_type(); - auto mul_pattern = ngraph::pattern::wrap_type({input_pattern, mul_const_pattern}, pattern::consumers_count(1)); + auto mul_pattern = + ngraph::pattern::wrap_type({input_pattern, mul_const_pattern}, pattern::consumers_count(1)); auto weights_pattern = ngraph::pattern::any_input(pattern::has_static_shape()); auto conv_pattern = ngraph::pattern::wrap_type({mul_pattern, weights_pattern}); - matcher_pass_callback callback = [=](pattern::Matcher & m) -> bool { + matcher_pass_callback callback = [=](pattern::Matcher& m) -> bool { const auto& pattern_to_output = m.get_pattern_value_map(); // Can't fuse Multiply to Convolution if that Multiply is part of dequantization subgraph @@ -109,7 +109,10 @@ ngraph::pass::MultiplyGroupConvolutionFusion::MultiplyGroupConvolutionFusion() { if (op::util::check_for_broadcast(weights_shape, new_shape)) { return false; } - mul_const = std::make_shared(mul_const, op::Constant::create(element::u64, Shape{new_shape.size()}, new_shape), false); + mul_const = std::make_shared( + mul_const, + op::Constant::create(element::u64, Shape{new_shape.size()}, new_shape), + false); } auto weights_multiply = std::make_shared(weights, mul_const); @@ -122,8 +125,7 @@ ngraph::pass::MultiplyGroupConvolutionFusion::MultiplyGroupConvolutionFusion() { auto new_conv = conv->clone_with_new_inputs({input, new_weights}); new_conv->set_friendly_name(conv->get_friendly_name()); - copy_runtime_info({conv, pattern_to_output.at(mul_pattern).get_node_shared_ptr()}, - {new_weights, new_conv}); + copy_runtime_info({conv, pattern_to_output.at(mul_pattern).get_node_shared_ptr()}, {new_weights, new_conv}); replace_node(conv, new_conv); return true; @@ -139,11 +141,12 @@ ngraph::pass::MultiplyConvolutionBackpropDataFusion::MultiplyConvolutionBackprop MATCHER_SCOPE(MultiplyConvolutionBackpropDataFusion); auto input_pattern = pattern::any_input(); auto mul_const_pattern = ngraph::pattern::wrap_type(); - auto mul_pattern = ngraph::pattern::wrap_type({input_pattern, mul_const_pattern}, pattern::consumers_count(1)); + auto mul_pattern = + ngraph::pattern::wrap_type({input_pattern, mul_const_pattern}, pattern::consumers_count(1)); auto weights_pattern = ngraph::pattern::any_input(pattern::has_static_shape()); auto conv_pattern = ngraph::pattern::wrap_type({mul_pattern, weights_pattern}); - matcher_pass_callback callback = [=](pattern::Matcher & m) -> bool { + matcher_pass_callback callback = [=](pattern::Matcher& m) -> bool { const auto& pattern_to_output = m.get_pattern_value_map(); // Can't fuse Multiply to Convolution if that Multiply is part of dequantization subgraph @@ -165,7 +168,7 @@ ngraph::pass::MultiplyConvolutionBackpropDataFusion::MultiplyConvolutionBackprop // In backprop, weights pixels are applied to input differently than in fprop convolution for (size_t i = 0; i < mul_const_shape.size(); i++) { if (i == 1) - continue; + continue; if (mul_const_shape[i] != 1) return false; } @@ -175,7 +178,10 @@ ngraph::pass::MultiplyConvolutionBackpropDataFusion::MultiplyConvolutionBackprop if (op::util::check_for_broadcast(weights_shape, new_shape)) { return false; } - mul_const = std::make_shared(mul_const, op::Constant::create(element::u64, Shape{new_shape.size()}, new_shape), false); + mul_const = std::make_shared( + mul_const, + op::Constant::create(element::u64, Shape{new_shape.size()}, new_shape), + false); } auto weights_multiply = std::make_shared(weights, mul_const); @@ -188,8 +194,7 @@ ngraph::pass::MultiplyConvolutionBackpropDataFusion::MultiplyConvolutionBackprop auto new_conv = conv->clone_with_new_inputs({input, new_weights}); new_conv->set_friendly_name(conv->get_friendly_name()); - copy_runtime_info({conv, pattern_to_output.at(mul_pattern).get_node_shared_ptr()}, - {new_weights, new_conv}); + copy_runtime_info({conv, pattern_to_output.at(mul_pattern).get_node_shared_ptr()}, {new_weights, new_conv}); replace_node(conv, new_conv); return true; @@ -199,17 +204,21 @@ ngraph::pass::MultiplyConvolutionBackpropDataFusion::MultiplyConvolutionBackprop register_matcher(m, callback); } -NGRAPH_RTTI_DEFINITION(ngraph::pass::MultiplyGroupConvolutionBackpropDataFusion, "MultiplyGroupConvolutionBackpropDataFusion", 0); +NGRAPH_RTTI_DEFINITION(ngraph::pass::MultiplyGroupConvolutionBackpropDataFusion, + "MultiplyGroupConvolutionBackpropDataFusion", + 0); ngraph::pass::MultiplyGroupConvolutionBackpropDataFusion::MultiplyGroupConvolutionBackpropDataFusion() { MATCHER_SCOPE(MultiplyGroupConvolutionBackpropDataFusion); auto input_pattern = pattern::any_input(); auto mul_const_pattern = ngraph::pattern::wrap_type(); - auto mul_pattern = ngraph::pattern::wrap_type({input_pattern, mul_const_pattern}, pattern::consumers_count(1)); + auto mul_pattern = + ngraph::pattern::wrap_type({input_pattern, mul_const_pattern}, pattern::consumers_count(1)); auto weights_pattern = ngraph::pattern::any_input(pattern::has_static_shape()); - auto conv_pattern = ngraph::pattern::wrap_type({mul_pattern, weights_pattern}); + auto conv_pattern = + ngraph::pattern::wrap_type({mul_pattern, weights_pattern}); - matcher_pass_callback callback = [=](pattern::Matcher & m) -> bool { + matcher_pass_callback callback = [=](pattern::Matcher& m) -> bool { const auto& pattern_to_output = m.get_pattern_value_map(); // Can't fuse Multiply to Convolution if that Multiply is part of dequantization subgraph @@ -230,11 +239,12 @@ ngraph::pass::MultiplyGroupConvolutionBackpropDataFusion::MultiplyGroupConvoluti // In backprop, weights pixels are applied to input differently than in fprop convolution for (size_t i = 0; i < mul_const_shape.size(); i++) { if (i == 1) - continue; + continue; if (mul_const_shape[i] != 1) return false; } - // Reshape mul_const from shape (1, C, 1, 1) to (G, C / G, 1, 1, 1) to match GroupConvolutionBackpropData weights format + // Reshape mul_const from shape (1, C, 1, 1) to (G, C / G, 1, 1, 1) to match GroupConvolutionBackpropData + // weights format auto G = mul_const_shape[1] > 1 ? weights_shape[0] : 1; auto C = mul_const_shape[1] / G; Shape new_shape{G, C, 1}; @@ -242,7 +252,10 @@ ngraph::pass::MultiplyGroupConvolutionBackpropDataFusion::MultiplyGroupConvoluti if (op::util::check_for_broadcast(weights_shape, new_shape)) { return false; } - mul_const = std::make_shared(mul_const, op::Constant::create(element::u64, Shape{new_shape.size()}, new_shape), false); + mul_const = std::make_shared( + mul_const, + op::Constant::create(element::u64, Shape{new_shape.size()}, new_shape), + false); } auto weights_multiply = std::make_shared(weights, mul_const); @@ -255,8 +268,7 @@ ngraph::pass::MultiplyGroupConvolutionBackpropDataFusion::MultiplyGroupConvoluti auto new_conv = conv->clone_with_new_inputs({input, new_weights}); new_conv->set_friendly_name(conv->get_friendly_name()); - copy_runtime_info({conv, pattern_to_output.at(mul_pattern).get_node_shared_ptr()}, - {new_weights, new_conv}); + copy_runtime_info({conv, pattern_to_output.at(mul_pattern).get_node_shared_ptr()}, {new_weights, new_conv}); replace_node(conv, new_conv); return true; diff --git a/src/common/transformations/src/transformations/common_optimizations/mul_fake_quantize_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/mul_fake_quantize_fusion.cpp index f2702cc3649..9dc9a72c76f 100644 --- a/src/common/transformations/src/transformations/common_optimizations/mul_fake_quantize_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/mul_fake_quantize_fusion.cpp @@ -3,17 +3,16 @@ // #include "transformations/common_optimizations/mul_fake_quantize_fusion.hpp" -#include "transformations/utils/utils.hpp" #include +#include +#include +#include +#include #include -#include -#include -#include -#include #include "itt.hpp" - +#include "transformations/utils/utils.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::MulFakeQuantizeFusion, "MulFakeQuantizeFusion", 0); @@ -21,8 +20,8 @@ ngraph::pass::MulFakeQuantizeFusion::MulFakeQuantizeFusion() { MATCHER_SCOPE(MulFakeQuantizeFusion); auto input_pattern = ngraph::pattern::any_input(); auto const_pattern = ngraph::pattern::wrap_type(); - auto mul_pattern = ngraph::pattern::wrap_type({input_pattern, const_pattern}, - pattern::consumers_count(1)); + auto mul_pattern = + ngraph::pattern::wrap_type({input_pattern, const_pattern}, pattern::consumers_count(1)); auto fq_pattern = ngraph::pattern::wrap_type({mul_pattern, ngraph::pattern::any_input(), ngraph::pattern::any_input(), @@ -34,10 +33,12 @@ ngraph::pass::MulFakeQuantizeFusion::MulFakeQuantizeFusion() { const auto& type = input.get_element_type(); if (type.bitwidth() < element::f32.bitwidth()) return false; - auto fq = std::dynamic_pointer_cast(pattern_value_map.at(fq_pattern).get_node_shared_ptr()); + auto fq = + std::dynamic_pointer_cast(pattern_value_map.at(fq_pattern).get_node_shared_ptr()); if (!fq) return false; - auto mul_const = std::dynamic_pointer_cast(pattern_value_map.at(const_pattern).get_node_shared_ptr()); + auto mul_const = + std::dynamic_pointer_cast(pattern_value_map.at(const_pattern).get_node_shared_ptr()); if (!mul_const) return false; @@ -50,7 +51,9 @@ ngraph::pass::MulFakeQuantizeFusion::MulFakeQuantizeFusion() { } auto mul_const_value = mul_const->cast_vector(); - if (std::any_of(mul_const_value.begin(), mul_const_value.end(), [] (float f) -> bool { return f <= 0.0f; })) + if (std::any_of(mul_const_value.begin(), mul_const_value.end(), [](float f) -> bool { + return f <= 0.0f; + })) return false; std::shared_ptr new_const = mul_const; @@ -75,8 +78,10 @@ ngraph::pass::MulFakeQuantizeFusion::MulFakeQuantizeFusion() { if (diff > 0) { // Reshape constants like (C, 1, 1) to (1, C, 1, 1) const_shape.insert(const_shape.begin(), diff, 1); - new_const = std::make_shared(new_const, - op::Constant::create(element::u64, Shape{const_shape.size()}, const_shape), false); + new_const = std::make_shared( + new_const, + op::Constant::create(element::u64, Shape{const_shape.size()}, const_shape), + false); } // disallow constant shapes other than (N, 1, 1, ..., 1) or (1, C, 1, ..., 1) @@ -87,10 +92,10 @@ ngraph::pass::MulFakeQuantizeFusion::MulFakeQuantizeFusion() { auto fq_users = fq->get_users(); // Concat LPT transformation supports per tensor quantization only - bool fq_user_is_concat = std::any_of(fq_users.begin(), fq_users.end(), - [] (const std::shared_ptr node_ptr) -> bool { - return is_type(node_ptr); - }); + bool fq_user_is_concat = + std::any_of(fq_users.begin(), fq_users.end(), [](const std::shared_ptr node_ptr) -> bool { + return is_type(node_ptr); + }); if (fq_user_is_concat) return false; } @@ -104,8 +109,8 @@ ngraph::pass::MulFakeQuantizeFusion::MulFakeQuantizeFusion() { if (!new_input_high) new_input_high = input_high_div; - auto new_fq = fq->clone_with_new_inputs({input, new_input_low, new_input_high, - fq->input_value(3), fq->input_value(4)}); + auto new_fq = + fq->clone_with_new_inputs({input, new_input_low, new_input_high, fq->input_value(3), fq->input_value(4)}); if (transformation_callback(new_fq)) return false; register_new_node(new_fq); diff --git a/src/common/transformations/src/transformations/common_optimizations/mvn_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/mvn_fusion.cpp index 3cac385c0aa..55f39d5f46c 100644 --- a/src/common/transformations/src/transformations/common_optimizations/mvn_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/mvn_fusion.cpp @@ -2,17 +2,17 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/common_optimizations/mvn_fusion.hpp" -#include "transformations/utils/utils.hpp" #include +#include +#include +#include +#include #include -#include -#include -#include -#include +#include "itt.hpp" +#include "transformations/utils/utils.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::MVNFusion, "MVNFusion", 0); @@ -38,35 +38,35 @@ ngraph::pass::MVNFusionWithoutConstants::MVNFusionWithoutConstants() { // (x - ReduceMean(x, axes)) // `------mean1-------' auto mean1_axes = pattern::wrap_type(); - auto mean1 = pattern::wrap_type({ x, mean1_axes }); + auto mean1 = pattern::wrap_type({x, mean1_axes}); // (x - ReduceMean(x, axes)) // `-sub1------------------' - auto sub1 = pattern::wrap_type({ x, mean1 }); + auto sub1 = pattern::wrap_type({x, mean1}); // Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2)) // `---mean2----------' auto mean2_axes = pattern::wrap_type(); - auto mean2 = pattern::wrap_type({ x, mean2_axes }); + auto mean2 = pattern::wrap_type({x, mean2_axes}); // Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2)) // `-sub2------------------' - auto sub2 = pattern::wrap_type({ x, mean2 }); + auto sub2 = pattern::wrap_type({x, mean2}); - const auto reuseSub1OrNot = std::make_shared(OutputVector{ sub1, sub2 }); + const auto reuseSub1OrNot = std::make_shared(OutputVector{sub1, sub2}); - auto cast = pattern::wrap_type({ reuseSub1OrNot }); - const auto hasConvertOrNot = std::make_shared(OutputVector{ cast, reuseSub1OrNot }); + auto cast = pattern::wrap_type({reuseSub1OrNot}); + const auto hasConvertOrNot = std::make_shared(OutputVector{cast, reuseSub1OrNot}); // Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2)) // `---------------------power--' - auto const_2 = pattern::wrap_type(value_is_equal_to({ 2.0 })); - auto power = pattern::wrap_type({ hasConvertOrNot, const_2 }); + auto const_2 = pattern::wrap_type(value_is_equal_to({2.0})); + auto power = pattern::wrap_type({hasConvertOrNot, const_2}); // Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2)) // `---mean3--------------------------------' auto mean3_axes = pattern::wrap_type(); - auto mean3 = pattern::wrap_type({ power, mean3_axes }); + auto mean3 = pattern::wrap_type({power, mean3_axes}); auto const_0_5 = pattern::wrap_type(value_is_equal_to({0.5})); auto eps = pattern::wrap_type(); @@ -74,48 +74,51 @@ ngraph::pass::MVNFusionWithoutConstants::MVNFusionWithoutConstants() { // Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2)) // `--Power--------------------------------------' - auto power_sqrt_os = pattern::wrap_type({ mean3, const_0_5 }); - auto sqrt_os = pattern::wrap_type({ mean3 }); - const auto powerOrSqrt_os = std::make_shared(OutputVector{ power_sqrt_os, sqrt_os }); + auto power_sqrt_os = pattern::wrap_type({mean3, const_0_5}); + auto sqrt_os = pattern::wrap_type({mean3}); + const auto powerOrSqrt_os = std::make_shared(OutputVector{power_sqrt_os, sqrt_os}); // Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2)) + eps // `----------------------------------------------Add---' - auto add_eps_os = pattern::wrap_type({ powerOrSqrt_os, eps }); + auto add_eps_os = pattern::wrap_type({powerOrSqrt_os, eps}); // ------------------- INSIDE_SQRT ---------------------- // (Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2) + eps)) // `-----------------------------------------------Add---' - auto add_eps_is = pattern::wrap_type({ mean3, eps }); + auto add_eps_is = pattern::wrap_type({mean3, eps}); // Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2)) // `--Power--------------------------------------' - auto power_sqrt_is = pattern::wrap_type({ add_eps_is, const_0_5 }); - auto sqrt_is = pattern::wrap_type({ add_eps_is }); - const auto powerOrSqrt_is = std::make_shared(OutputVector{ power_sqrt_is, sqrt_is }); + auto power_sqrt_is = pattern::wrap_type({add_eps_is, const_0_5}); + auto sqrt_is = pattern::wrap_type({add_eps_is}); + const auto powerOrSqrt_is = std::make_shared(OutputVector{power_sqrt_is, sqrt_is}); - auto outsideOrInside = std::make_shared(OutputVector{ add_eps_os, powerOrSqrt_is }); + auto outsideOrInside = std::make_shared(OutputVector{add_eps_os, powerOrSqrt_is}); // Final Divide - auto const_neg_1 = pattern::wrap_type(value_is_equal_to({ -1 })); - auto power_div = pattern::wrap_type({ outsideOrInside, const_neg_1 }); - auto div = pattern::wrap_type({ sub1, power_div }); + auto const_neg_1 = pattern::wrap_type(value_is_equal_to({-1})); + auto power_div = pattern::wrap_type({outsideOrInside, const_neg_1}); + auto div = pattern::wrap_type({sub1, power_div}); - auto div_alt = pattern::wrap_type({ sub1, outsideOrInside }); - const auto powerMulOrDiv = std::make_shared(OutputVector{ div, div_alt }); + auto div_alt = pattern::wrap_type({sub1, outsideOrInside}); + const auto powerMulOrDiv = std::make_shared(OutputVector{div, div_alt}); ngraph::matcher_pass_callback matcher_pass_callback = [=](ngraph::pattern::Matcher& m) { auto& pattern_to_output = m.get_pattern_value_map(); auto exp_input = pattern_to_output.at(x); - auto const_eps_node = std::dynamic_pointer_cast(pattern_to_output.at(eps).get_node_shared_ptr()); + auto const_eps_node = + std::dynamic_pointer_cast(pattern_to_output.at(eps).get_node_shared_ptr()); float eps_value; if (!op::util::get_single_value(const_eps_node, eps_value)) { return false; } - auto axes_1_node = std::dynamic_pointer_cast(pattern_to_output.at(mean1_axes).get_node_shared_ptr()); - auto axes_3_node = std::dynamic_pointer_cast(pattern_to_output.at(mean3_axes).get_node_shared_ptr()); + auto axes_1_node = + std::dynamic_pointer_cast(pattern_to_output.at(mean1_axes).get_node_shared_ptr()); + auto axes_3_node = + std::dynamic_pointer_cast(pattern_to_output.at(mean3_axes).get_node_shared_ptr()); if (!axes_1_node || !axes_3_node) { return false; @@ -128,7 +131,8 @@ ngraph::pass::MVNFusionWithoutConstants::MVNFusionWithoutConstants() { return false; } if (pattern_to_output.count(mean2_axes)) { - auto axes_2_node = std::dynamic_pointer_cast(pattern_to_output.at(mean2_axes).get_node_shared_ptr()); + auto axes_2_node = std::dynamic_pointer_cast( + pattern_to_output.at(mean2_axes).get_node_shared_ptr()); if (!axes_2_node) { return false; } @@ -138,10 +142,10 @@ ngraph::pass::MVNFusionWithoutConstants::MVNFusionWithoutConstants() { } } - ngraph::NodeVector nodes_to_copy_info({ pattern_to_output.at(mean1).get_node_shared_ptr(), - pattern_to_output.at(sub1).get_node_shared_ptr(), - pattern_to_output.at(power).get_node_shared_ptr(), - pattern_to_output.at(mean3).get_node_shared_ptr() }); + ngraph::NodeVector nodes_to_copy_info({pattern_to_output.at(mean1).get_node_shared_ptr(), + pattern_to_output.at(sub1).get_node_shared_ptr(), + pattern_to_output.at(power).get_node_shared_ptr(), + pattern_to_output.at(mean3).get_node_shared_ptr()}); op::MVNEpsMode mode; if (pattern_to_output.count(add_eps_os)) { @@ -202,71 +206,78 @@ ngraph::pass::MVNFusionWithConstantsInside::MVNFusionWithConstantsInside() { // (x - ReduceMean(x, axes))^2 // `------mean1-------' auto mean1_axes = pattern::wrap_type(); - auto mean1 = pattern::wrap_type({ x, mean1_axes }); + auto mean1 = pattern::wrap_type({x, mean1_axes}); // (x - ReduceMean(x, axes))^2 // `-squared_difference------' - auto squared_difference = pattern::wrap_type({ x, mean1 }); + auto squared_difference = pattern::wrap_type({x, mean1}); // 1 / Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2) + eps) // `---mean2--------------------------------' auto mean2_axes = pattern::wrap_type(); - auto mean2 = pattern::wrap_type({ squared_difference, mean2_axes }); + auto mean2 = pattern::wrap_type({squared_difference, mean2_axes}); // 1 / Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2) + eps) // `------------------------------------------add--' auto eps = pattern::wrap_type(); - auto add_eps = pattern::wrap_type({ mean2, eps }); + auto add_eps = pattern::wrap_type({mean2, eps}); // 1 / Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2) + eps) // `-power-------------------------------------------------' auto const_0_5 = pattern::wrap_type(value_is_equal_to({-0.5})); - auto power = pattern::wrap_type({ add_eps, const_0_5 }); + auto power = pattern::wrap_type({add_eps, const_0_5}); // gamma / Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2) + eps) // `---mul1----------------------------------------------------' auto gamma = pattern::wrap_type(); - auto mul1 = pattern::wrap_type({ power, gamma }); + auto mul1 = pattern::wrap_type({power, gamma}); // x * gamma / Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2) + eps) // `---mul2--------------------------------------------------------' - auto mul2 = pattern::wrap_type({ x, mul1 }); + auto mul2 = pattern::wrap_type({x, mul1}); // ReduceMean(x, axes) * gamma / Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2) + eps) - beta // `-------------------mul3----------------------------------------------------------' - auto mul3 = pattern::wrap_type({ mul1, mean1 }); + auto mul3 = pattern::wrap_type({mul1, mean1}); // beta - ReduceMean(x, axes) * gamma / Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2) + eps) // `---sub-----------------------------------------------------------------------------------' auto beta = pattern::wrap_type(); - auto sub = pattern::wrap_type({ beta, mul3 }); + auto sub = pattern::wrap_type({beta, mul3}); // Final Add // x * gamma / Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2) + eps) + // beta - ReduceMean(x, axes) * gamma / Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2) + eps) = // gamma * (x - ReduceMean(x, axes)) / Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2) + eps) + beta - auto add = pattern::wrap_type({ mul2, sub }); + auto add = pattern::wrap_type({mul2, sub}); ngraph::matcher_pass_callback matcher_pass_callback = [=](ngraph::pattern::Matcher& m) { auto& pattern_to_output = m.get_pattern_value_map(); auto x_output = pattern_to_output.at(x); - auto const_0_5_node = std::dynamic_pointer_cast(pattern_to_output.at(const_0_5).get_node_shared_ptr()); - auto const_gamma_node = std::dynamic_pointer_cast(pattern_to_output.at(gamma).get_node_shared_ptr()); - auto const_beta_node = std::dynamic_pointer_cast(pattern_to_output.at(beta).get_node_shared_ptr()); - auto const_eps_node = std::dynamic_pointer_cast(pattern_to_output.at(eps).get_node_shared_ptr()); + auto const_0_5_node = + std::dynamic_pointer_cast(pattern_to_output.at(const_0_5).get_node_shared_ptr()); + auto const_gamma_node = + std::dynamic_pointer_cast(pattern_to_output.at(gamma).get_node_shared_ptr()); + auto const_beta_node = + std::dynamic_pointer_cast(pattern_to_output.at(beta).get_node_shared_ptr()); + auto const_eps_node = + std::dynamic_pointer_cast(pattern_to_output.at(eps).get_node_shared_ptr()); if (!const_0_5_node || !const_beta_node || !const_gamma_node || !const_eps_node) { return false; } float eps_value; - bool valid_constant_values = op::util::has_constant_value(const_0_5_node, -0.5) && op::util::get_single_value(const_eps_node, eps_value); + bool valid_constant_values = op::util::has_constant_value(const_0_5_node, -0.5) && + op::util::get_single_value(const_eps_node, eps_value); if (!valid_constant_values) { return false; } - auto axes_1_node = std::dynamic_pointer_cast(pattern_to_output.at(mean1_axes).get_node_shared_ptr()); - auto axes_2_node = std::dynamic_pointer_cast(pattern_to_output.at(mean2_axes).get_node_shared_ptr()); + auto axes_1_node = + std::dynamic_pointer_cast(pattern_to_output.at(mean1_axes).get_node_shared_ptr()); + auto axes_2_node = + std::dynamic_pointer_cast(pattern_to_output.at(mean2_axes).get_node_shared_ptr()); if (!axes_1_node || !axes_2_node) { return false; } @@ -277,11 +288,12 @@ ngraph::pass::MVNFusionWithConstantsInside::MVNFusionWithConstantsInside() { return false; } - auto mvn = std::make_shared(x_output, axes_1_node, true, eps_value, op::MVNEpsMode::INSIDE_SQRT); + auto mvn = + std::make_shared(x_output, axes_1_node, true, eps_value, op::MVNEpsMode::INSIDE_SQRT); auto mul_gamma = std::make_shared(mvn, const_gamma_node); auto add_beta = std::make_shared(mul_gamma, const_beta_node); - ngraph::copy_runtime_info({ pattern_to_output.at(mean1).get_node_shared_ptr(), + ngraph::copy_runtime_info({pattern_to_output.at(mean1).get_node_shared_ptr(), pattern_to_output.at(squared_difference).get_node_shared_ptr(), pattern_to_output.at(add_eps).get_node_shared_ptr(), pattern_to_output.at(power).get_node_shared_ptr(), @@ -289,8 +301,8 @@ ngraph::pass::MVNFusionWithConstantsInside::MVNFusionWithConstantsInside() { pattern_to_output.at(mul2).get_node_shared_ptr(), pattern_to_output.at(mul3).get_node_shared_ptr(), pattern_to_output.at(sub).get_node_shared_ptr(), - pattern_to_output.at(add).get_node_shared_ptr() }, - { mvn, const_gamma_node, mul_gamma, const_beta_node, add_beta }); + pattern_to_output.at(add).get_node_shared_ptr()}, + {mvn, const_gamma_node, mul_gamma, const_beta_node, add_beta}); add_beta->set_friendly_name(m.get_match_root()->get_friendly_name()); ngraph::replace_node(m.get_match_root(), add_beta); return true; diff --git a/src/common/transformations/src/transformations/common_optimizations/nearest_neighbor_upsampling_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/nearest_neighbor_upsampling_fusion.cpp index 4478bfb56ed..47187c18ab5 100644 --- a/src/common/transformations/src/transformations/common_optimizations/nearest_neighbor_upsampling_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/nearest_neighbor_upsampling_fusion.cpp @@ -2,21 +2,21 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/common_optimizations/nearest_neighbor_upsampling_fusion.hpp" -#include "transformations/utils/utils.hpp" #include #include +#include +#include +#include +#include +#include #include #include #include -#include -#include -#include -#include -#include +#include "itt.hpp" +#include "transformations/utils/utils.hpp" namespace { using namespace ngraph; @@ -28,7 +28,8 @@ using namespace ngraph; // [S_1, S_2, ..., S_i, ..., S_{r - 2}], // when the shape, 's', has the form (1), and the empty vector otherwise. std::vector get_scales_from_mul_const_shape(const Shape& s, uint64_t input_rank) { - if (input_rank < 4 || s.size() != 2 * input_rank - 2) return {}; + if (input_rank < 4 || s.size() != 2 * input_rank - 2) + return {}; ngraph::Shape expected_shape(2 * input_rank - 2, 1); std::vector scales(input_rank - 2); @@ -37,7 +38,8 @@ std::vector get_scales_from_mul_const_shape(const Shape& s, uint64_t inpu scales[i - 1] = static_cast(s[2 * i]); } - if (s != expected_shape) return {}; + if (s != expected_shape) + return {}; return scales; } @@ -48,21 +50,28 @@ bool check_concat_1(const std::shared_ptr& concat, const Shape& const auto inputs = concat->input_values(); size_t num_of_input_values = inputs.size(); - if (num_of_input_values != 2 * rank - 2) return false; + if (num_of_input_values != 2 * rank - 2) + return false; std::vector input_constants(num_of_input_values, 1); for (size_t i = 1; i < num_of_input_values; ++i) { const auto& current_input = std::dynamic_pointer_cast(inputs[i].get_node_shared_ptr()); - if (!current_input) return false; + if (!current_input) + return false; - const auto current_input_axis = std::dynamic_pointer_cast(current_input->input_value(1).get_node_shared_ptr()); - if (!current_input_axis || current_input_axis->cast_vector() != std::vector{0}) return false; + const auto current_input_axis = + std::dynamic_pointer_cast(current_input->input_value(1).get_node_shared_ptr()); + if (!current_input_axis || current_input_axis->cast_vector() != std::vector{0}) + return false; - const auto unsqueezed_const = std::dynamic_pointer_cast(current_input->input_value(0).get_node_shared_ptr()); - if (!unsqueezed_const) return false; + const auto unsqueezed_const = + std::dynamic_pointer_cast(current_input->input_value(0).get_node_shared_ptr()); + if (!unsqueezed_const) + return false; const auto unsqueezed_const_value = unsqueezed_const->cast_vector(); - if (unsqueezed_const_value.size() != 1) return false; + if (unsqueezed_const_value.size() != 1) + return false; input_constants[i] = unsqueezed_const_value[0]; } @@ -73,59 +82,69 @@ bool check_concat_1(const std::shared_ptr& concat, const Shape& } expected_input_constants.back() = static_cast(shape.back()); - if (input_constants != expected_input_constants) return false; + if (input_constants != expected_input_constants) + return false; return true; } -// In this transformation 'concat_2' must have r inputs (where r is an output rank of the root of the transformation pattern). -// And (r - 1) inputs must be unsqueezed constants, and the list of these constants is +// In this transformation 'concat_2' must have r inputs (where r is an output rank of the root of the transformation +// pattern). And (r - 1) inputs must be unsqueezed constants, and the list of these constants is // [newD_1, newD_2, ..., newD_{r - 2}, C], // where C is number of channels in the output shape of the root of the transformation pattern. // // This function gets a new spatial shape from unsqueezed constants of 'concat_2', that is, the vector with elements // [newD_1, newD_2, ..., newD_{r - 2}]. -std::vector get_new_spatial_shape_from_concat_2(const std::shared_ptr& concat, const Shape& input_shape) { +std::vector get_new_spatial_shape_from_concat_2(const std::shared_ptr& concat, + const Shape& input_shape) { size_t rank = input_shape.size(); const auto inputs = concat->input_values(); size_t num_of_input_values = inputs.size(); - if (num_of_input_values != rank) return {}; + if (num_of_input_values != rank) + return {}; std::vector input_constants(num_of_input_values - 1, 0); for (size_t i = 1; i < num_of_input_values; ++i) { const auto& current_input = std::dynamic_pointer_cast(inputs[i].get_node_shared_ptr()); - if (!current_input) return {}; + if (!current_input) + return {}; - const auto current_input_axis = std::dynamic_pointer_cast(current_input->input_value(1).get_node_shared_ptr()); - if (!current_input_axis || current_input_axis->cast_vector() != std::vector{0}) return {}; + const auto current_input_axis = + std::dynamic_pointer_cast(current_input->input_value(1).get_node_shared_ptr()); + if (!current_input_axis || current_input_axis->cast_vector() != std::vector{0}) + return {}; - const auto unsqueezed_const = std::dynamic_pointer_cast(current_input->input_value(0).get_node_shared_ptr()); - if (!unsqueezed_const) return {}; + const auto unsqueezed_const = + std::dynamic_pointer_cast(current_input->input_value(0).get_node_shared_ptr()); + if (!unsqueezed_const) + return {}; const auto unsqueezed_const_value = unsqueezed_const->cast_vector(); - if (unsqueezed_const_value.size() != 1) return {}; + if (unsqueezed_const_value.size() != 1) + return {}; input_constants[i - 1] = unsqueezed_const_value[0]; } - if (input_constants.back() != static_cast(input_shape.back())) return {}; + if (input_constants.back() != static_cast(input_shape.back())) + return {}; input_constants.pop_back(); return input_constants; } -} // namespace +} // namespace NGRAPH_RTTI_DEFINITION(ngraph::pass::NearestNeighborUpsamplingFusion, "NearestNeighborUpsamplingFusion", 0); ngraph::pass::NearestNeighborUpsamplingFusion::NearestNeighborUpsamplingFusion() { MATCHER_SCOPE(NearestNeighborUpsamplingFusion); - // This transformation looks for Interpolate layer implemented using simple operations, namely ShapeOf, StridedSlice, Concat, - // Reshape, Mul, and replaces found pattern with a sequence of Shape, StridedSlice, Const, Mul, Interpolate. - // Found pattern (for 4D case, in a general case the pattern is similar): + // This transformation looks for Interpolate layer implemented using simple operations, namely ShapeOf, + // StridedSlice, Concat, Reshape, Mul, and replaces found pattern with a sequence of Shape, StridedSlice, Const, + // Mul, Interpolate. Found pattern (for 4D case, in a general case the pattern is similar): // // |---------| // | op | @@ -147,36 +166,35 @@ ngraph::pass::NearestNeighborUpsamplingFusion::NearestNeighborUpsamplingFusion() // | | 0|<-----------------------| | 0|<----------| // | | | | | // | | | | | - // | | | |-------------| |------------| | | |-------------| |--------------| - // | | | | | | Constant | | | | | | Constant | - // | | | | 0|<--| value: H | | | | 0|<--| value: new_H | - // | | | | | |------------| | | | | |--------------| - // | | | | | | | | | - // | | | | Unsqueeze | |------------| | | | Unsqueeze | |------------| - // | | | | | | Constant | | | | | | Constant | - // | | 1|<-----| 1|<--| value: 0 | | 1|<-----| 1|<--| value: 0 | - // | | | |-------------| |------------| | | |-------------| |------------| - // | | | | | - // | | | |-------------| |------------| | | |-------------| |--------------| - // | | | | | | Constant | | | | | | Constant | - // | | | | 0|<--| value: 1 | | | | 0|<--| value: new_W | - // | | | | | |------------| | | | | |--------------| - // | | | | | | | | | - // | | | | Unsqueeze | |------------| | | | Unsqueeze | |------------| - // | | | | | | Constant | | | | | | Constant | - // | | 2|<-----| 1|<--| value: 0 | | 2|<-----| 1|<--| value: 0 | - // | | | |-------------| |------------| | | |-------------| |------------| - // | | | | | - // | | | |-------------| |------------| | | |-------------| |------------| - // | | | | | | Constant | | | | | | Constant | - // | | | | 0|<--| value: W | | | | 0|<--| value: C | - // | | | | | |------------| | | | | |------------| - // | | | | | | | | | - // | | | | Unsqueeze | |------------| | | | Unsqueeze | |------------| - // | | | | | | Constant | | | | | | Constant | - // | | 3|<-----| 1|<--| value: 0 | | 3|<-----| 1|<--| value: 0 | - // | | | |-------------| |------------| |------|--------| |-------------| |------------| - // | | | | + // | | | |-------------| |------------| | | |-------------| + // |--------------| | | | | | | Constant | | | | + // | | Constant | | | | | 0|<--| value: H | | | | + // 0|<--| value: new_H | | | | | | |------------| | | + // | | |--------------| | | | | | | | | + // | | | | | Unsqueeze | |------------| | | | Unsqueeze | + // |------------| | | | | | | Constant | | | | + // | | Constant | | | 1|<-----| 1|<--| value: 0 | | 1|<-----| 1|<--| + // value: 0 | | | | |-------------| |------------| | | + // |-------------| |------------| | | | | | | | + // | |-------------| |------------| | | |-------------| |--------------| | | | + // | | | Constant | | | | | | Constant | | | | | + // 0|<--| value: 1 | | | | 0|<--| value: new_W | | | | + // | | |------------| | | | | |--------------| | | | | + // | | | | | | | | | Unsqueeze | + // |------------| | | | Unsqueeze | |------------| | | | | + // | | Constant | | | | | | Constant | | | 2|<-----| 1|<--| + // value: 0 | | 2|<-----| 1|<--| value: 0 | | | | + // |-------------| |------------| | | |-------------| |------------| | | | | | + // | | | |-------------| |------------| | | |-------------| + // |------------| | | | | | | Constant | | | | + // | | Constant | | | | | 0|<--| value: W | | | | + // 0|<--| value: C | | | | | | |------------| | | | + // | |------------| | | | | | | | | | + // | | | | Unsqueeze | |------------| | | | Unsqueeze | + // |------------| | | | | | | Constant | | | | + // | | Constant | | | 3|<-----| 1|<--| value: 0 | | 3|<-----| 1|<--| + // value: 0 | | | | |-------------| |------------| |------|--------| + // |-------------| |------------| | | | | // | | | |-------------| |------------| | // | | | | | | Constant | | // | | | | 0|<--| value: 1 | | @@ -230,8 +248,8 @@ ngraph::pass::NearestNeighborUpsamplingFusion::NearestNeighborUpsamplingFusion() // ... // D_i for the input port 2 * (i - 1) + 1 of 'concat_1' and 1 for the input port 2 * i of 'concat_1'; // ... - // D_{r - 2} for the input port 2 * ((r - 2) - 1) + 1 of 'concat_1' and 1 for the input port 2 * (r - 2) of 'concat_1'; - // C for the input port 2 * (r - 2) + 1 of 'concat_1'; + // D_{r - 2} for the input port 2 * ((r - 2) - 1) + 1 of 'concat_1' and 1 for the input port 2 * (r - 2) of + // 'concat_1'; C for the input port 2 * (r - 2) + 1 of 'concat_1'; // 4) unsqueezed constants for 'concat_2' are // newD_1 for the input port 1 of 'concat_1'; // newD_2 for the input port 2 of 'concat_1'; @@ -240,8 +258,8 @@ ngraph::pass::NearestNeighborUpsamplingFusion::NearestNeighborUpsamplingFusion() // ... // newD_{r - 2} for the input port (r - 2) of 'concat_1'; // C for the input port (r - 2) + 1 of 'concat_1'; - // 5) the shape of 'mul_const' is [1, 1, S_1, 1, S_2, ..., 1, S_i, ..., 1, S_{r - 2}, 1] where S_i is a scale for the axis i; - // 6) all elements of 'mul_const' are equal to 1.0. + // 5) the shape of 'mul_const' is [1, 1, S_1, 1, S_2, ..., 1, S_i, ..., 1, S_{r - 2}, 1] where S_i is a scale + // for the axis i; 6) all elements of 'mul_const' are equal to 1.0. // // Such subgraph can be replaced by the Interpolate node with // 1) mode='nearest' and shape_calculation_mode='scales'; @@ -259,48 +277,75 @@ ngraph::pass::NearestNeighborUpsamplingFusion::NearestNeighborUpsamplingFusion() auto reshape_2 = pattern::wrap_type({mul, concat_2}); ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { - const auto &pattern_to_output = m.get_pattern_value_map(); + const auto& pattern_to_output = m.get_pattern_value_map(); - const auto reshape_2_node = std::dynamic_pointer_cast(pattern_to_output.at(reshape_2).get_node_shared_ptr()); - const auto mul_node = std::dynamic_pointer_cast(pattern_to_output.at(mul).get_node_shared_ptr()); - if (!reshape_2_node || !mul_node) return false; + const auto reshape_2_node = + std::dynamic_pointer_cast(pattern_to_output.at(reshape_2).get_node_shared_ptr()); + const auto mul_node = + std::dynamic_pointer_cast(pattern_to_output.at(mul).get_node_shared_ptr()); + if (!reshape_2_node || !mul_node) + return false; - const auto mul_const_node = std::dynamic_pointer_cast(pattern_to_output.at(mul_const).get_node_shared_ptr()); - if (!mul_const_node) return false; + const auto mul_const_node = + std::dynamic_pointer_cast(pattern_to_output.at(mul_const).get_node_shared_ptr()); + if (!mul_const_node) + return false; - const auto reshape_1_node = std::dynamic_pointer_cast(pattern_to_output.at(reshape_1).get_node_shared_ptr()); - if (!reshape_1_node) return false; + const auto reshape_1_node = + std::dynamic_pointer_cast(pattern_to_output.at(reshape_1).get_node_shared_ptr()); + if (!reshape_1_node) + return false; uint64_t input_rank = static_cast(reshape_1_node->get_input_partial_shape(0).rank().get_length()); const auto mul_const_shape = mul_const_node->get_output_shape(0); const auto scales = get_scales_from_mul_const_shape(mul_const_shape, input_rank); - if (scales.empty() || std::all_of(scales.begin(), scales.end(), [](float s) { return s == 1.0f;})) { return false; } + if (scales.empty() || std::all_of(scales.begin(), scales.end(), [](float s) { + return s == 1.0f; + })) { + return false; + } const auto mul_const_value = mul_const_node->cast_vector(); - if (std::any_of(mul_const_value.begin(), mul_const_value.end(), [](float x){ return x != 1.0f; })) { return false; } + if (std::any_of(mul_const_value.begin(), mul_const_value.end(), [](float x) { + return x != 1.0f; + })) { + return false; + } - const auto concat_1_node = std::dynamic_pointer_cast(pattern_to_output.at(concat_1).get_node_shared_ptr()); - if (!concat_1_node) return false; + const auto concat_1_node = + std::dynamic_pointer_cast(pattern_to_output.at(concat_1).get_node_shared_ptr()); + if (!concat_1_node) + return false; const auto input_shape = reshape_1_node->get_input_shape(0); - if (!check_concat_1(concat_1_node, input_shape)) return false; + if (!check_concat_1(concat_1_node, input_shape)) + return false; - const auto concat_2_node = std::dynamic_pointer_cast(pattern_to_output.at(concat_2).get_node_shared_ptr()); - if (!concat_2_node) return false; + const auto concat_2_node = + std::dynamic_pointer_cast(pattern_to_output.at(concat_2).get_node_shared_ptr()); + if (!concat_2_node) + return false; const auto new_spatial_shape = get_new_spatial_shape_from_concat_2(concat_2_node, input_shape); - if (new_spatial_shape.empty()) return false; + if (new_spatial_shape.empty()) + return false; - const auto ss_before_concat_1 = std::dynamic_pointer_cast(concat_1_node->input_value(0).get_node_shared_ptr()); - const auto ss_before_concat_2 = std::dynamic_pointer_cast(concat_2_node->input_value(0).get_node_shared_ptr()); - if (!ss_before_concat_1 || !ss_before_concat_2 || ss_before_concat_1.get() != ss_before_concat_2.get()) return false; + const auto ss_before_concat_1 = + std::dynamic_pointer_cast(concat_1_node->input_value(0).get_node_shared_ptr()); + const auto ss_before_concat_2 = + std::dynamic_pointer_cast(concat_2_node->input_value(0).get_node_shared_ptr()); + if (!ss_before_concat_1 || !ss_before_concat_2 || ss_before_concat_1.get() != ss_before_concat_2.get()) + return false; - const auto shapeof_node = std::dynamic_pointer_cast(ss_before_concat_1->input_value(0).get_node_shared_ptr()); - if (!shapeof_node) return false; + const auto shapeof_node = + std::dynamic_pointer_cast(ss_before_concat_1->input_value(0).get_node_shared_ptr()); + if (!shapeof_node) + return false; const auto before_shapeof = shapeof_node->input_value(0); const auto before_reshape_1 = reshape_1_node->input_value(0); - if (before_shapeof.get_node() != before_reshape_1.get_node()) return false; + if (before_shapeof.get_node() != before_reshape_1.get_node()) + return false; opset8::Interpolate::InterpolateAttrs attrs; attrs.mode = opset8::Interpolate::InterpolateMode::NEAREST; @@ -321,11 +366,13 @@ ngraph::pass::NearestNeighborUpsamplingFusion::NearestNeighborUpsamplingFusion() std::iota(axes.begin(), axes.end(), static_cast(1)); const auto axes_node = opset8::Constant::create(element::i64, {axes.size()}, axes); - auto interpolate = register_new_node(before_shapeof, sizes_node, scales_node, axes_node, attrs); + auto interpolate = + register_new_node(before_shapeof, sizes_node, scales_node, axes_node, attrs); interpolate->set_friendly_name(reshape_2_node->get_friendly_name()); - copy_runtime_info({reshape_2_node, mul_node, mul_const_node, concat_1_node, concat_2_node, ss_before_concat_1, shapeof_node}, - {scales_node, sizes_node, axes_node, interpolate}); + copy_runtime_info( + {reshape_2_node, mul_node, mul_const_node, concat_1_node, concat_2_node, ss_before_concat_1, shapeof_node}, + {scales_node, sizes_node, axes_node, interpolate}); replace_node(reshape_2_node, interpolate); return true; diff --git a/src/common/transformations/src/transformations/common_optimizations/nop_elimination.cpp b/src/common/transformations/src/transformations/common_optimizations/nop_elimination.cpp index 22fb21b074a..fb508dbba33 100644 --- a/src/common/transformations/src/transformations/common_optimizations/nop_elimination.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/nop_elimination.cpp @@ -2,18 +2,18 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include #include -#include - +#include #include #include +#include #include -#include +#include #include #include -#include + +#include "itt.hpp" using namespace std; using namespace ngraph; @@ -56,8 +56,7 @@ static bool simplify_gather(std::shared_ptr node) { // op has Nop // check if the indices is constant - auto constant_indices = - ov::as_type_ptr(gather->input_value(1).get_node_shared_ptr()); + auto constant_indices = ov::as_type_ptr(gather->input_value(1).get_node_shared_ptr()); if (!constant_indices) { return false; } else { @@ -75,8 +74,7 @@ static bool simplify_gather(std::shared_ptr node) { static bool eliminate_nop(const std::shared_ptr& node) { // skip if shapes are dynamic - if (node->get_input_partial_shape(0).is_dynamic() || - node->get_output_partial_shape(0).is_dynamic()) { + if (node->get_input_partial_shape(0).is_dynamic() || node->get_output_partial_shape(0).is_dynamic()) { return false; } @@ -99,8 +97,7 @@ static bool eliminate_reshape_v1(const std::shared_ptr& node) { } // eliminate redundant reshape, squeeze, or unsqueeze auto input_node = input.get_node_shared_ptr(); - if (ov::as_type_ptr(input_node) || - ov::as_type_ptr(input_node) || + if (ov::as_type_ptr(input_node) || ov::as_type_ptr(input_node) || ov::as_type_ptr(input_node)) { if (input_node->get_output_target_inputs(0).size() != 1) return false; @@ -114,8 +111,7 @@ static bool eliminate_reshape_v1(const std::shared_ptr& node) { std::vector vi; vi.assign(shape.begin(), shape.end()); auto pat = opset3::Constant::create(element::i64, Shape{vi.size()}, vi); - auto new_reshape = - make_shared(input.get_node()->input_value(0), pat, false); + auto new_reshape = make_shared(input.get_node()->input_value(0), pat, false); new_reshape->set_friendly_name(node->get_friendly_name()); copy_runtime_info({input_node, node}, new_reshape); replace_node(node, new_reshape); @@ -176,8 +172,7 @@ static bool replace_squeeze_unsqueeze(const std::shared_ptr& node) { } } -static std::vector get_unsqueeze_axes(const PartialShape& data_shape, - const PartialShape& out_shape) { +static std::vector get_unsqueeze_axes(const PartialShape& data_shape, const PartialShape& out_shape) { std::vector axes; int64_t i = 0; for (auto o = 0; o < out_shape.rank().get_length(); o++) { @@ -192,8 +187,7 @@ static std::vector get_unsqueeze_axes(const PartialShape& data_shape, return axes; } -static std::vector get_squeeze_axes(const PartialShape& data_shape, - const PartialShape& out_shape) { +static std::vector get_squeeze_axes(const PartialShape& data_shape, const PartialShape& out_shape) { std::vector axes; int64_t out_i = 0; for (auto i = 0; i < data_shape.rank().get_length(); i++) { @@ -223,8 +217,7 @@ static bool eliminate_unsqueeze(const std::shared_ptr& node) { auto replace_unsqueeze_only = [&](const vector& axes) { auto axes_const = opset3::Constant::create(element::i64, Shape{axes.size()}, axes); auto new_unsq = make_shared(input->input_value(0), axes_const); - if (unsqueeze->get_output_partial_shape(0).same_scheme( - new_unsq->get_output_partial_shape(0))) { + if (unsqueeze->get_output_partial_shape(0).same_scheme(new_unsq->get_output_partial_shape(0))) { return replace_node_update_name(unsqueeze, new_unsq); } return false; @@ -250,11 +243,9 @@ static bool eliminate_unsqueeze(const std::shared_ptr& node) { // check if single squeeze can handle this auto axes = get_squeeze_axes(data_shape, out_shape); if (data_shape.rank().get_length() - static_cast(axes.size()) == out_shape.rank().get_length()) { - auto axes_const = - opset3::Constant::create(element::i64, Shape{axes.size()}, axes); + auto axes_const = opset3::Constant::create(element::i64, Shape{axes.size()}, axes); auto new_sq = make_shared(input->input_value(0), axes_const); - if (unsqueeze->get_output_partial_shape(0).same_scheme( - new_sq->get_output_partial_shape(0))) { + if (unsqueeze->get_output_partial_shape(0).same_scheme(new_sq->get_output_partial_shape(0))) { return replace_node_update_name(unsqueeze, new_sq); } return false; @@ -277,29 +268,28 @@ static bool eliminate_unsqueeze(const std::shared_ptr& node) { } #define ECHO(NAME) #NAME -#define STR(NAME) ECHO(NAME) -#define SIMPLE_MATCHER_PASS_DEFINITION(NAME, OP, FUNC) \ -class NAME : public ngraph::pass::MatcherPass { \ -public: \ -NGRAPH_RTTI_DECLARATION; \ -NAME() { \ - MATCHER_SCOPE(NAME); \ - auto match_node = ngraph::pattern::wrap_type(); \ - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { \ - return FUNC(m.get_match_root()); \ - }; \ - auto m = std::make_shared(match_node, matcher_name); \ - register_matcher(m, callback); \ -} \ -}; \ -NGRAPH_RTTI_DEFINITION(NAME, STR(NAME), 0); +#define STR(NAME) ECHO(NAME) +#define SIMPLE_MATCHER_PASS_DEFINITION(NAME, OP, FUNC) \ + class NAME : public ngraph::pass::MatcherPass { \ + public: \ + NGRAPH_RTTI_DECLARATION; \ + NAME() { \ + MATCHER_SCOPE(NAME); \ + auto match_node = ngraph::pattern::wrap_type(); \ + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { \ + return FUNC(m.get_match_root()); \ + }; \ + auto m = std::make_shared(match_node, matcher_name); \ + register_matcher(m, callback); \ + } \ + }; \ + NGRAPH_RTTI_DEFINITION(NAME, STR(NAME), 0); SIMPLE_MATCHER_PASS_DEFINITION(EliminateReshape, opset3::Reshape, eliminate_reshape_v1); SIMPLE_MATCHER_PASS_DEFINITION(EliminateUnsqueeze, opset3::Unsqueeze, eliminate_unsqueeze); SIMPLE_MATCHER_PASS_DEFINITION(EliminateBroadcast, op::v1::Broadcast, eliminate_nop); SIMPLE_MATCHER_PASS_DEFINITION(EliminateGather, opset3::Gather, simplify_gather); - NGRAPH_RTTI_DEFINITION(pass::EliminatePad, "EliminatePad", 0); pass::EliminatePad::EliminatePad() { @@ -319,8 +309,14 @@ pass::EliminatePad::EliminatePad() { const auto pad_begin_value = pad_begin_const->cast_vector(); const auto pad_end_value = pad_end_const->cast_vector(); - if (std::any_of(pad_begin_value.begin(), pad_begin_value.end(), [](int64_t value) { return value != 0; }) || - std::any_of(pad_end_value.begin(), pad_end_value.end(), [](int64_t value) { return value != 0; })) { + if (std::any_of(pad_begin_value.begin(), + pad_begin_value.end(), + [](int64_t value) { + return value != 0; + }) || + std::any_of(pad_end_value.begin(), pad_end_value.end(), [](int64_t value) { + return value != 0; + })) { return false; } @@ -360,7 +356,7 @@ pass::EliminateConvertNonZero::EliminateConvertNonZero() { auto non_zero = pattern::wrap_type({convert_pattern}); matcher_pass_callback callback = [=](pattern::Matcher& m) { - const auto & pattern_map = m.get_pattern_map(); + const auto& pattern_map = m.get_pattern_map(); auto convert = pattern_map.at(convert_pattern); // remove convert convert->output(0).replace(convert->input_value(0)); @@ -502,13 +498,13 @@ pass::EliminateTranspose::EliminateTranspose() { auto transpose_pattern = pattern::wrap_type({pattern::any_input(), order}); matcher_pass_callback callback = [=](pattern::Matcher& m) { - const auto & pattern_map = m.get_pattern_map(); + const auto& pattern_map = m.get_pattern_map(); auto order_const = std::dynamic_pointer_cast(pattern_map.at(order)); if (!order_const) { return false; } - const auto & order_values = order_const->cast_vector(); + const auto& order_values = order_const->cast_vector(); vector ref_values(order_values.size()); std::iota(ref_values.begin(), ref_values.end(), 0); if (order_values != ref_values) { @@ -529,10 +525,8 @@ pass::EliminateEltwise::EliminateEltwise() { MATCHER_SCOPE(EliminateEltwise); auto input = pattern::any_input(); auto constant_pattern = pattern::wrap_type(); - auto eltwise_pattern = pattern::wrap_type({input, constant_pattern}); + auto eltwise_pattern = + pattern::wrap_type({input, constant_pattern}); matcher_pass_callback callback = [=](pattern::Matcher& m) { const auto& pattern_map = m.get_pattern_value_map(); diff --git a/src/common/transformations/src/transformations/common_optimizations/normalize_l2_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/normalize_l2_fusion.cpp index cc9dcebab48..4b2ca7bdd7e 100644 --- a/src/common/transformations/src/transformations/common_optimizations/normalize_l2_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/normalize_l2_fusion.cpp @@ -2,17 +2,17 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/common_optimizations/normalize_l2_fusion.hpp" -#include "transformations/utils/utils.hpp" #include +#include +#include +#include +#include #include -#include -#include -#include -#include +#include "itt.hpp" +#include "transformations/utils/utils.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::NormalizeL2Fusion, "NormalizeL2Fusion", 0); @@ -37,9 +37,12 @@ ngraph::pass::NormalizeL2Fusion::NormalizeL2Fusion() { const auto& pattern_to_output = m.get_pattern_value_map(); const auto data_input = pattern_to_output.at(input); - const auto exp_input = std::dynamic_pointer_cast(pattern_to_output.at(exp).get_node_shared_ptr()); - const auto axes_input = std::dynamic_pointer_cast(pattern_to_output.at(axes).get_node_shared_ptr()); - const auto eps_attr = std::dynamic_pointer_cast(pattern_to_output.at(eps_const).get_node_shared_ptr()); + const auto exp_input = + std::dynamic_pointer_cast(pattern_to_output.at(exp).get_node_shared_ptr()); + const auto axes_input = + std::dynamic_pointer_cast(pattern_to_output.at(axes).get_node_shared_ptr()); + const auto eps_attr = + std::dynamic_pointer_cast(pattern_to_output.at(eps_const).get_node_shared_ptr()); if (!exp_input || !axes_input || !eps_attr) { return false; @@ -75,9 +78,8 @@ ngraph::pass::NormalizeL2Fusion::NormalizeL2Fusion() { pattern_to_output.at(reduce_sum).get_node_shared_ptr(), pattern_to_output.at(sqrt).get_node_shared_ptr(), pattern_to_output.at(divide).get_node_shared_ptr(), - eps_node.get_node_shared_ptr() - }, - normalize_l2); + eps_node.get_node_shared_ptr()}, + normalize_l2); ngraph::replace_node(m.get_match_root(), normalize_l2); return true; }; diff --git a/src/common/transformations/src/transformations/common_optimizations/optimize_strided_slice.cpp b/src/common/transformations/src/transformations/common_optimizations/optimize_strided_slice.cpp index 32e01e0b4e1..96a5073a41d 100644 --- a/src/common/transformations/src/transformations/common_optimizations/optimize_strided_slice.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/optimize_strided_slice.cpp @@ -3,17 +3,15 @@ // #include -#include - -#include "itt.hpp" -#include "transformations/op_conversions/convert_slice_to_strided_slice.hpp" - -#include #include #include #include #include +#include +#include +#include "itt.hpp" +#include "transformations/op_conversions/convert_slice_to_strided_slice.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::StridedSliceOptimization, "StridedSliceOptimization", 0); @@ -22,7 +20,7 @@ NGRAPH_RTTI_DEFINITION(ngraph::pass::UselessStridedSliceEraser, "UselessStridedS bool ngraph::pass::UselessStridedSliceEraser::run_on_model(const std::shared_ptr& f) { RUN_ON_FUNCTION_SCOPE(UselessStridedSliceEraser); bool rewritten = false; - for (auto & node : f->get_ordered_ops()) { + for (auto& node : f->get_ordered_ops()) { // Recursively apply transformation for sub-graph based operations if (auto sub_graph_node = std::dynamic_pointer_cast(node)) { if (auto sub_graph = sub_graph_node->get_function()) { @@ -35,10 +33,13 @@ bool ngraph::pass::UselessStridedSliceEraser::run_on_model(const std::shared_ptr if (ss->input(0).get_shape() != ss->output(0).get_shape()) continue; - auto stridesNode = std::dynamic_pointer_cast(ss->input_value(3).get_node_shared_ptr()); + auto stridesNode = + std::dynamic_pointer_cast(ss->input_value(3).get_node_shared_ptr()); if (stridesNode) { auto strides = stridesNode->cast_vector(); - if (!std::any_of(strides.begin(), strides.end(), [](int64_t strd) { return strd < 0;})) + if (!std::any_of(strides.begin(), strides.end(), [](int64_t strd) { + return strd < 0; + })) rewritten |= replace_output_update_name(ss->output(0), ss->input_value(0)); } } @@ -93,7 +94,7 @@ bool strided_slices_perform_the_same(std::shared_ptr, std::vector>> source_to_ss; - for (const auto & node : f->get_ordered_ops()) { + for (const auto& node : f->get_ordered_ops()) { // Recursively apply transformation for sub-graph based operations if (auto sub_graph_node = std::dynamic_pointer_cast(node)) { if (auto sub_graph = sub_graph_node->get_function()) { @@ -119,7 +120,8 @@ bool ngraph::pass::SharedStridedSliceEraser::run_on_model(const std::shared_ptr< continue; auto root_ss = pair.second[0]; for (auto& child_ss : pair.second) { - if (root_ss->get_instance_id() != child_ss->get_instance_id() && strided_slices_perform_the_same(root_ss, child_ss)) { + if (root_ss->get_instance_id() != child_ss->get_instance_id() && + strided_slices_perform_the_same(root_ss, child_ss)) { graph_rewritten |= replace_output_update_name(child_ss->output(0), root_ss->output(0)); } } @@ -135,7 +137,7 @@ bool ngraph::pass::GroupedStridedSliceOptimizer::run_on_model(const std::shared_ using planned_slice = std::pair, ngraph::SlicePlan>; std::map, std::vector> source_to_ss_with_plan; - for (const auto & node : f->get_ordered_ops()) { + for (const auto& node : f->get_ordered_ops()) { // Recursively apply transformation for sub-graph based operations if (auto sub_graph_node = std::dynamic_pointer_cast(node)) { if (auto sub_graph = sub_graph_node->get_function()) { @@ -157,14 +159,15 @@ bool ngraph::pass::GroupedStridedSliceOptimizer::run_on_model(const std::shared_ bool valid_for_replacement = true; auto root_plan = pair.second[0].second; - for (const auto & ss_plan : pair.second) { + for (const auto& ss_plan : pair.second) { valid_for_replacement &= (ss_plan.second.begins.size() == root_plan.begins.size()); - valid_for_replacement &= (ss_plan.first->get_ellipsis_mask().empty() && - ss_plan.first->get_new_axis_mask().empty() && - ss_plan.first->get_shrink_axis_mask().empty()); + valid_for_replacement &= + (ss_plan.first->get_ellipsis_mask().empty() && ss_plan.first->get_new_axis_mask().empty() && + ss_plan.first->get_shrink_axis_mask().empty()); } - if (!valid_for_replacement) continue; + if (!valid_for_replacement) + continue; auto input_shape = pair.first.get_shape(); auto axis = -1; @@ -177,7 +180,7 @@ bool ngraph::pass::GroupedStridedSliceOptimizer::run_on_model(const std::shared_ std::vector output_to_partition; for (size_t i = 0; i < input_shape.size(); ++i) { - for (const auto & ss_plan : pair.second) { + for (const auto& ss_plan : pair.second) { if (ss_plan.second.begins[i] != 0 || ss_plan.second.ends[i] != static_cast(input_shape[i])) { if (axis == -1 || axis == static_cast(i)) axis = static_cast(i); @@ -192,31 +195,38 @@ bool ngraph::pass::GroupedStridedSliceOptimizer::run_on_model(const std::shared_ break; } } - output_to_partition.push_back({ss_plan.first->output(0), ss_plan.second.begins[i], ss_plan.second.ends[i]}); + output_to_partition.push_back( + {ss_plan.first->output(0), ss_plan.second.begins[i], ss_plan.second.ends[i]}); } - if (!valid_for_replacement) break; + if (!valid_for_replacement) + break; } - if (!valid_for_replacement) break; + if (!valid_for_replacement) + break; } - if (!valid_for_replacement || output_to_partition.size() < 2 || axis == -1) continue; + if (!valid_for_replacement || output_to_partition.size() < 2 || axis == -1) + continue; - std::sort(output_to_partition.begin(), output_to_partition.end(), - [](OutputToPatrition lhs, OutputToPatrition rhs) - {return lhs.begin < rhs.begin;}); + std::sort(output_to_partition.begin(), + output_to_partition.end(), + [](OutputToPatrition lhs, OutputToPatrition rhs) { + return lhs.begin < rhs.begin; + }); std::vector, uint64_t>> output_to_size; int64_t prev_r = 0; - for (auto & record : output_to_partition) { + for (auto& record : output_to_partition) { valid_for_replacement &= (record.begin >= prev_r); prev_r = record.end; } valid_for_replacement &= (static_cast(prev_r) <= input_shape[axis]); - if (!valid_for_replacement) continue; + if (!valid_for_replacement) + continue; prev_r = 0; Output fake_output; - for (auto & record : output_to_partition) { + for (auto& record : output_to_partition) { if (record.begin > prev_r) output_to_size.emplace_back(fake_output, record.begin - prev_r); prev_r = record.end; @@ -229,14 +239,16 @@ bool ngraph::pass::GroupedStridedSliceOptimizer::run_on_model(const std::shared_ auto axis_const = ngraph::opset1::Constant::create(ngraph::element::i64, ngraph::Shape{}, {axis}); std::vector size_splits; - for (const auto & item : output_to_size) + for (const auto& item : output_to_size) size_splits.push_back(item.second); - auto size_splits_const = ngraph::opset1::Constant::create(ngraph::element::i64, ngraph::Shape{size_splits.size()}, size_splits); - auto variadic_split = std::make_shared(pair.first, axis_const, size_splits_const); + auto size_splits_const = + ngraph::opset1::Constant::create(ngraph::element::i64, ngraph::Shape{size_splits.size()}, size_splits); + auto variadic_split = + std::make_shared(pair.first, axis_const, size_splits_const); auto i = 0; NodeVector ops_to_replace; - for (auto & record : output_to_size) { + for (auto& record : output_to_size) { if (record.first != fake_output) { record.first.replace(variadic_split->output(i)); ops_to_replace.push_back(record.first.get_node_shared_ptr()); diff --git a/src/common/transformations/src/transformations/common_optimizations/pad_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/pad_fusion.cpp index 0030e9cc6bf..e1cde82025e 100644 --- a/src/common/transformations/src/transformations/common_optimizations/pad_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/pad_fusion.cpp @@ -3,23 +3,24 @@ // #include "transformations/common_optimizations/pad_fusion.hpp" -#include "transformations/utils/utils.hpp" -#include "itt.hpp" #include +#include +#include +#include +#include #include -#include -#include -#include -#include +#include "itt.hpp" +#include "transformations/utils/utils.hpp" using namespace ngraph; NGRAPH_RTTI_DEFINITION(pass::PadFusion, "PadFusion", 0); template -static bool can_be_fused(const std::shared_ptr& pad, const std::shared_ptr& node, +static bool can_be_fused(const std::shared_ptr& pad, + const std::shared_ptr& node, const std::shared_ptr& pad_value_node, const std::shared_ptr& pads_begin, const std::shared_ptr& pads_end) { @@ -63,12 +64,20 @@ static std::tuple new_pooling_pad_values(const std::shared_ptrcast_vector(); auto pads_end_val = pads_end->cast_vector(); - std::transform(node_pads_begin.begin(), node_pads_begin.end(), - pads_begin_val.begin() + 2, node_pads_begin.begin(), - [] (size_t a, size_t b) -> size_t { return a + b; }); - std::transform(node_pads_end.begin(), node_pads_end.end(), - pads_end_val.begin() + 2, node_pads_end.begin(), - [] (size_t a, size_t b) -> size_t { return a + b; }); + std::transform(node_pads_begin.begin(), + node_pads_begin.end(), + pads_begin_val.begin() + 2, + node_pads_begin.begin(), + [](size_t a, size_t b) -> size_t { + return a + b; + }); + std::transform(node_pads_end.begin(), + node_pads_end.end(), + pads_end_val.begin() + 2, + node_pads_end.begin(), + [](size_t a, size_t b) -> size_t { + return a + b; + }); return std::make_tuple(node_pads_begin, node_pads_end); } @@ -81,9 +90,9 @@ pass::PadFusionAvgPool::PadFusionAvgPool() { auto pads_begin_pattern = pattern::wrap_type(); auto pads_end_pattern = pattern::wrap_type(); auto pad_value_pattern = pattern::any_input(); - auto pad_node_pattern = pattern::wrap_type({data_pattern, pads_begin_pattern, - pads_end_pattern, pad_value_pattern}, - pattern::consumers_count(1)); + auto pad_node_pattern = + pattern::wrap_type({data_pattern, pads_begin_pattern, pads_end_pattern, pad_value_pattern}, + pattern::consumers_count(1)); auto avg_pool_pattern = pattern::wrap_type({pad_node_pattern}); matcher_pass_callback callback = [=](pattern::Matcher& m) { @@ -91,8 +100,10 @@ pass::PadFusionAvgPool::PadFusionAvgPool() { auto data = pattern_map[data_pattern]; auto pad = std::dynamic_pointer_cast(pattern_map[pad_node_pattern].get_node_shared_ptr()); auto pad_value = pattern_map[pad_value_pattern].get_node_shared_ptr(); - auto pads_begin = std::dynamic_pointer_cast(pattern_map[pads_begin_pattern].get_node_shared_ptr()); - auto pads_end = std::dynamic_pointer_cast(pattern_map[pads_end_pattern].get_node_shared_ptr()); + auto pads_begin = + std::dynamic_pointer_cast(pattern_map[pads_begin_pattern].get_node_shared_ptr()); + auto pads_end = + std::dynamic_pointer_cast(pattern_map[pads_end_pattern].get_node_shared_ptr()); auto avg_pool = std::dynamic_pointer_cast(pattern_map[avg_pool_pattern].get_node_shared_ptr()); if (!can_be_fused(pad, avg_pool, pad_value, pads_begin, pads_end)) return false; @@ -101,24 +112,34 @@ pass::PadFusionAvgPool::PadFusionAvgPool() { if (avg_pool->get_exclude_pad()) { const auto& avg_pads_begin = avg_pool->get_pads_begin(); const auto& avg_pads_end = avg_pool->get_pads_end(); - bool avg_pads_begin_are_zeros = std::all_of(avg_pads_begin.begin(), avg_pads_begin.end(), [] (size_t p) -> bool { return p == 0; }); - bool avg_pads_end_are_zeros = std::all_of(avg_pads_end.begin(), avg_pads_end.end(), [] (size_t p) -> bool { return p == 0; }); + bool avg_pads_begin_are_zeros = + std::all_of(avg_pads_begin.begin(), avg_pads_begin.end(), [](size_t p) -> bool { + return p == 0; + }); + bool avg_pads_end_are_zeros = std::all_of(avg_pads_end.begin(), avg_pads_end.end(), [](size_t p) -> bool { + return p == 0; + }); if (!avg_pads_begin_are_zeros || !avg_pads_end_are_zeros) return false; auto pads_begin_val = pads_begin->cast_vector(); auto pads_end_val = pads_end->cast_vector(); - new_avg_pool = std::make_shared(data, avg_pool->get_strides(), + new_avg_pool = std::make_shared(data, + avg_pool->get_strides(), Shape{pads_begin_val.begin() + 2, pads_begin_val.end()}, Shape{pads_end_val.begin() + 2, pads_end_val.end()}, - avg_pool->get_kernel(), false, + avg_pool->get_kernel(), + false, avg_pool->get_rounding_type(), op::PadType::EXPLICIT); } else { Shape new_pads_begin, new_pads_end; std::tie(new_pads_begin, new_pads_end) = new_pooling_pad_values(pads_begin, pads_end, avg_pool); - new_avg_pool = std::make_shared(data, avg_pool->get_strides(), - new_pads_begin, new_pads_end, - avg_pool->get_kernel(), false, + new_avg_pool = std::make_shared(data, + avg_pool->get_strides(), + new_pads_begin, + new_pads_end, + avg_pool->get_kernel(), + false, avg_pool->get_rounding_type(), op::PadType::EXPLICIT); } @@ -135,20 +156,29 @@ pass::PadFusionAvgPool::PadFusionAvgPool() { } template -static std::tuple new_conv_pad_values(const std::shared_ptr& pads_begin, - const std::shared_ptr& pads_end, - const std::shared_ptr& node) { +static std::tuple new_conv_pad_values( + const std::shared_ptr& pads_begin, + const std::shared_ptr& pads_end, + const std::shared_ptr& node) { auto node_pads_begin = node->get_pads_begin(); auto node_pads_end = node->get_pads_end(); auto pads_begin_val = pads_begin->cast_vector(); auto pads_end_val = pads_end->cast_vector(); - std::transform(node_pads_begin.begin(), node_pads_begin.end(), - pads_begin_val.begin() + 2, node_pads_begin.begin(), - [] (std::ptrdiff_t a, size_t b) -> std::ptrdiff_t { return a + b; }); - std::transform(node_pads_end.begin(), node_pads_end.end(), - pads_end_val.begin() + 2, node_pads_end.begin(), - [] (std::ptrdiff_t a, size_t b) -> std::ptrdiff_t { return a + b; }); + std::transform(node_pads_begin.begin(), + node_pads_begin.end(), + pads_begin_val.begin() + 2, + node_pads_begin.begin(), + [](std::ptrdiff_t a, size_t b) -> std::ptrdiff_t { + return a + b; + }); + std::transform(node_pads_end.begin(), + node_pads_end.end(), + pads_end_val.begin() + 2, + node_pads_end.begin(), + [](std::ptrdiff_t a, size_t b) -> std::ptrdiff_t { + return a + b; + }); return std::make_tuple(node_pads_begin, node_pads_end); } @@ -162,9 +192,9 @@ pass::PadFusionConvolution::PadFusionConvolution() { auto pads_begin_pattern = pattern::wrap_type(); auto pads_end_pattern = pattern::wrap_type(); auto pad_value_pattern = pattern::any_input(); - auto pad_node_pattern = pattern::wrap_type({data_pattern, pads_begin_pattern, - pads_end_pattern, pad_value_pattern}, - pattern::consumers_count(1)); + auto pad_node_pattern = + pattern::wrap_type({data_pattern, pads_begin_pattern, pads_end_pattern, pad_value_pattern}, + pattern::consumers_count(1)); auto conv_pattern = pattern::wrap_type({pad_node_pattern, filter_pattern}); matcher_pass_callback callback = [=](pattern::Matcher& m) { @@ -173,17 +203,23 @@ pass::PadFusionConvolution::PadFusionConvolution() { auto filter = pattern_map[filter_pattern]; auto pad = std::dynamic_pointer_cast(pattern_map[pad_node_pattern].get_node_shared_ptr()); auto pad_value = pattern_map[pad_value_pattern].get_node_shared_ptr(); - auto pads_begin = std::dynamic_pointer_cast(pattern_map[pads_begin_pattern].get_node_shared_ptr()); - auto pads_end = std::dynamic_pointer_cast(pattern_map[pads_end_pattern].get_node_shared_ptr()); + auto pads_begin = + std::dynamic_pointer_cast(pattern_map[pads_begin_pattern].get_node_shared_ptr()); + auto pads_end = + std::dynamic_pointer_cast(pattern_map[pads_end_pattern].get_node_shared_ptr()); auto conv = std::dynamic_pointer_cast(pattern_map[conv_pattern].get_node_shared_ptr()); if (!can_be_fused(pad, conv, pad_value, pads_begin, pads_end)) return false; CoordinateDiff new_pads_begin, new_pads_end; std::tie(new_pads_begin, new_pads_end) = new_conv_pad_values(pads_begin, pads_end, conv); - auto new_conv = std::make_shared(data, filter, conv->get_strides(), - new_pads_begin, new_pads_end, - conv->get_dilations(), op::PadType::EXPLICIT); + auto new_conv = std::make_shared(data, + filter, + conv->get_strides(), + new_pads_begin, + new_pads_end, + conv->get_dilations(), + op::PadType::EXPLICIT); new_conv->set_friendly_name(conv->get_friendly_name()); copy_runtime_info({pad, conv}, new_conv); @@ -205,9 +241,9 @@ pass::PadFusionConvolutionBackpropData::PadFusionConvolutionBackpropData() { auto pads_begin_pattern = pattern::wrap_type(); auto pads_end_pattern = pattern::wrap_type(); auto pad_value_pattern = pattern::any_input(); - auto pad_node_pattern = pattern::wrap_type({data_pattern, pads_begin_pattern, - pads_end_pattern, pad_value_pattern}, - pattern::consumers_count(1)); + auto pad_node_pattern = + pattern::wrap_type({data_pattern, pads_begin_pattern, pads_end_pattern, pad_value_pattern}, + pattern::consumers_count(1)); auto conv_pattern = pattern::wrap_type({pad_node_pattern, filter_pattern}); matcher_pass_callback callback = [=](pattern::Matcher& m) { @@ -216,9 +252,12 @@ pass::PadFusionConvolutionBackpropData::PadFusionConvolutionBackpropData() { auto filter = pattern_map[filter_pattern]; auto pad = std::dynamic_pointer_cast(pattern_map[pad_node_pattern].get_node_shared_ptr()); auto pad_value = pattern_map[pad_value_pattern].get_node_shared_ptr(); - auto pads_begin = std::dynamic_pointer_cast(pattern_map[pads_begin_pattern].get_node_shared_ptr()); - auto pads_end = std::dynamic_pointer_cast(pattern_map[pads_end_pattern].get_node_shared_ptr()); - auto conv = std::dynamic_pointer_cast(pattern_map[conv_pattern].get_node_shared_ptr()); + auto pads_begin = + std::dynamic_pointer_cast(pattern_map[pads_begin_pattern].get_node_shared_ptr()); + auto pads_end = + std::dynamic_pointer_cast(pattern_map[pads_end_pattern].get_node_shared_ptr()); + auto conv = + std::dynamic_pointer_cast(pattern_map[conv_pattern].get_node_shared_ptr()); if (!can_be_fused(pad, conv, pad_value, pads_begin, pads_end)) return false; @@ -227,16 +266,19 @@ pass::PadFusionConvolutionBackpropData::PadFusionConvolutionBackpropData() { auto pads_begin_val = pads_begin->cast_vector(); auto pads_end_val = pads_end->cast_vector(); for (size_t i = 0; i < conv_pads_begin.size(); i++) { - if (conv_pads_begin[i] < pads_begin_val[i + 2] || - conv_pads_end[i] < pads_end_val[i + 2]) + if (conv_pads_begin[i] < pads_begin_val[i + 2] || conv_pads_end[i] < pads_end_val[i + 2]) return false; conv_pads_begin[i] -= pads_begin_val[i + 2]; conv_pads_end[i] -= pads_end_val[i + 2]; } - auto new_conv = std::make_shared(data, filter, conv->get_strides(), - conv_pads_begin, conv_pads_end, - conv->get_dilations(), op::PadType::EXPLICIT, + auto new_conv = std::make_shared(data, + filter, + conv->get_strides(), + conv_pads_begin, + conv_pads_end, + conv->get_dilations(), + op::PadType::EXPLICIT, conv->get_output_padding()); new_conv->set_friendly_name(conv->get_friendly_name()); @@ -259,9 +301,9 @@ pass::PadFusionGroupConvolution::PadFusionGroupConvolution() { auto pads_begin_pattern = pattern::wrap_type(); auto pads_end_pattern = pattern::wrap_type(); auto pad_value_pattern = pattern::any_input(); - auto pad_node_pattern = pattern::wrap_type({data_pattern, pads_begin_pattern, - pads_end_pattern, pad_value_pattern}, - pattern::consumers_count(1)); + auto pad_node_pattern = + pattern::wrap_type({data_pattern, pads_begin_pattern, pads_end_pattern, pad_value_pattern}, + pattern::consumers_count(1)); auto conv_pattern = pattern::wrap_type({pad_node_pattern, filter_pattern}); matcher_pass_callback callback = [=](pattern::Matcher& m) { @@ -270,17 +312,24 @@ pass::PadFusionGroupConvolution::PadFusionGroupConvolution() { auto filter = pattern_map[filter_pattern]; auto pad = std::dynamic_pointer_cast(pattern_map[pad_node_pattern].get_node_shared_ptr()); auto pad_value = pattern_map[pad_value_pattern].get_node_shared_ptr(); - auto pads_begin = std::dynamic_pointer_cast(pattern_map[pads_begin_pattern].get_node_shared_ptr()); - auto pads_end = std::dynamic_pointer_cast(pattern_map[pads_end_pattern].get_node_shared_ptr()); - auto conv = std::dynamic_pointer_cast(pattern_map[conv_pattern].get_node_shared_ptr()); + auto pads_begin = + std::dynamic_pointer_cast(pattern_map[pads_begin_pattern].get_node_shared_ptr()); + auto pads_end = + std::dynamic_pointer_cast(pattern_map[pads_end_pattern].get_node_shared_ptr()); + auto conv = + std::dynamic_pointer_cast(pattern_map[conv_pattern].get_node_shared_ptr()); if (!can_be_fused(pad, conv, pad_value, pads_begin, pads_end)) return false; CoordinateDiff new_pads_begin, new_pads_end; std::tie(new_pads_begin, new_pads_end) = new_conv_pad_values(pads_begin, pads_end, conv); - auto new_conv = std::make_shared(data, filter, conv->get_strides(), - new_pads_begin, new_pads_end, - conv->get_dilations(), op::PadType::EXPLICIT); + auto new_conv = std::make_shared(data, + filter, + conv->get_strides(), + new_pads_begin, + new_pads_end, + conv->get_dilations(), + op::PadType::EXPLICIT); new_conv->set_friendly_name(conv->get_friendly_name()); copy_runtime_info({pad, conv}, new_conv); @@ -302,9 +351,9 @@ pass::PadFusionGroupConvolutionBackpropData::PadFusionGroupConvolutionBackpropDa auto pads_begin_pattern = pattern::wrap_type(); auto pads_end_pattern = pattern::wrap_type(); auto pad_value_pattern = pattern::any_input(); - auto pad_node_pattern = pattern::wrap_type({data_pattern, pads_begin_pattern, - pads_end_pattern, pad_value_pattern}, - pattern::consumers_count(1)); + auto pad_node_pattern = + pattern::wrap_type({data_pattern, pads_begin_pattern, pads_end_pattern, pad_value_pattern}, + pattern::consumers_count(1)); auto conv_pattern = pattern::wrap_type({pad_node_pattern, filter_pattern}); matcher_pass_callback callback = [=](pattern::Matcher& m) { @@ -313,9 +362,12 @@ pass::PadFusionGroupConvolutionBackpropData::PadFusionGroupConvolutionBackpropDa auto filter = pattern_map[filter_pattern]; auto pad = std::dynamic_pointer_cast(pattern_map[pad_node_pattern].get_node_shared_ptr()); auto pad_value = pattern_map[pad_value_pattern].get_node_shared_ptr(); - auto pads_begin = std::dynamic_pointer_cast(pattern_map[pads_begin_pattern].get_node_shared_ptr()); - auto pads_end = std::dynamic_pointer_cast(pattern_map[pads_end_pattern].get_node_shared_ptr()); - auto conv = std::dynamic_pointer_cast(pattern_map[conv_pattern].get_node_shared_ptr()); + auto pads_begin = + std::dynamic_pointer_cast(pattern_map[pads_begin_pattern].get_node_shared_ptr()); + auto pads_end = + std::dynamic_pointer_cast(pattern_map[pads_end_pattern].get_node_shared_ptr()); + auto conv = std::dynamic_pointer_cast( + pattern_map[conv_pattern].get_node_shared_ptr()); if (!can_be_fused(pad, conv, pad_value, pads_begin, pads_end)) return false; @@ -324,17 +376,20 @@ pass::PadFusionGroupConvolutionBackpropData::PadFusionGroupConvolutionBackpropDa auto pads_begin_val = pads_begin->cast_vector(); auto pads_end_val = pads_end->cast_vector(); for (size_t i = 0; i < conv_pads_begin.size(); i++) { - if (conv_pads_begin[i] < pads_begin_val[i + 2] || - conv_pads_end[i] < pads_end_val[i + 2]) + if (conv_pads_begin[i] < pads_begin_val[i + 2] || conv_pads_end[i] < pads_end_val[i + 2]) return false; conv_pads_begin[i] -= pads_begin_val[i + 2]; conv_pads_end[i] -= pads_end_val[i + 2]; } - auto new_conv = std::make_shared(data, filter, conv->get_strides(), - conv_pads_begin, conv_pads_end, - conv->get_dilations(), op::PadType::EXPLICIT, - conv->get_output_padding()); + auto new_conv = std::make_shared(data, + filter, + conv->get_strides(), + conv_pads_begin, + conv_pads_end, + conv->get_dilations(), + op::PadType::EXPLICIT, + conv->get_output_padding()); new_conv->set_friendly_name(conv->get_friendly_name()); copy_runtime_info({pad, conv}, new_conv); diff --git a/src/common/transformations/src/transformations/common_optimizations/pull_transpose_through_fq.cpp b/src/common/transformations/src/transformations/common_optimizations/pull_transpose_through_fq.cpp index 4c6298e3012..e3609ad5dbb 100644 --- a/src/common/transformations/src/transformations/common_optimizations/pull_transpose_through_fq.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/pull_transpose_through_fq.cpp @@ -2,17 +2,17 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/common_optimizations/pull_transpose_through_fq.hpp" #include -#include - #include -#include #include +#include #include #include +#include + +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::PullTransposeThroughFQUp, "PullTransposeThroughFQUp", 0); @@ -24,21 +24,21 @@ ngraph::pass::PullTransposeThroughFQUp::PullTransposeThroughFQUp() { pattern::any_input(pattern::has_static_shape()), pattern::any_input(pattern::has_static_shape()), pattern::any_input(pattern::has_static_shape())}, - pattern::consumers_count(1)); + pattern::consumers_count(1)); auto m_transpose_perm = pattern::wrap_type(); auto m_transpose = pattern::wrap_type({m_fq, m_transpose_perm}); ngraph::matcher_pass_callback callback = [=](pattern::Matcher& m) { - auto & pattern_map = m.get_pattern_value_map(); + auto& pattern_map = m.get_pattern_value_map(); auto transpose = pattern_map[m_transpose].get_node_shared_ptr(); auto fq = pattern_map[m_fq].get_node_shared_ptr(); - auto are_inputs_scalars = shape_size(fq->input_value(1).get_shape()) == 1 && - shape_size(fq->input_value(2).get_shape()) == 1 && - shape_size(fq->input_value(3).get_shape()) == 1 && - shape_size(fq->input_value(4).get_shape()) == 1; + auto are_inputs_scalars = + shape_size(fq->input_value(1).get_shape()) == 1 && shape_size(fq->input_value(2).get_shape()) == 1 && + shape_size(fq->input_value(3).get_shape()) == 1 && shape_size(fq->input_value(4).get_shape()) == 1; if (!are_inputs_scalars) { - auto perm = std::dynamic_pointer_cast(pattern_map[m_transpose_perm].get_node_shared_ptr()); + auto perm = + std::dynamic_pointer_cast(pattern_map[m_transpose_perm].get_node_shared_ptr()); if (!perm) return false; auto perm_val = perm->cast_vector(); @@ -58,8 +58,9 @@ ngraph::pass::PullTransposeThroughFQUp::PullTransposeThroughFQUp() { unsqueeze_axes.push_back(j); } if (!unsqueeze_axes.empty()) { - fq_input = std::make_shared(fq_input, - opset1::Constant::create(element::i64, Shape{unsqueeze_axes.size()}, unsqueeze_axes)); + fq_input = std::make_shared( + fq_input, + opset1::Constant::create(element::i64, Shape{unsqueeze_axes.size()}, unsqueeze_axes)); new_ops.push_back(fq_input.get_node_shared_ptr()); } fq_input = std::make_shared(fq_input, transpose->input_value(1)); diff --git a/src/common/transformations/src/transformations/common_optimizations/random_uniform_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/random_uniform_fusion.cpp index 2e5017f7cc4..9cc68dbcaf7 100644 --- a/src/common/transformations/src/transformations/common_optimizations/random_uniform_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/random_uniform_fusion.cpp @@ -5,11 +5,11 @@ #include "transformations/common_optimizations/random_uniform_fusion.hpp" #include +#include #include #include #include #include -#include #include "itt.hpp" @@ -64,9 +64,8 @@ ngraph::pass::RandomUniformFusion::RandomUniformFusion() { const auto& folded_const1 = ngraph::get_constant_from_source(new_mul_add1); const auto& folded_const2 = ngraph::get_constant_from_source(new_mul_add2); - const auto new_ru = ru->clone_with_new_inputs({data, - folded_const1 ? folded_const1 : new_mul_add1, - folded_const2 ? folded_const2 : new_mul_add2}); + const auto new_ru = ru->clone_with_new_inputs( + {data, folded_const1 ? folded_const1 : new_mul_add1, folded_const2 ? folded_const2 : new_mul_add2}); if (pattern_map.count(convert_pattern)) { const auto& convert = pattern_map.at(convert_pattern); @@ -76,7 +75,8 @@ ngraph::pass::RandomUniformFusion::RandomUniformFusion() { if (!cvt->get_element_type().is_real()) return false; const auto new_ru_conv = cvt->clone_with_new_inputs({new_ru}); - copy_runtime_info({ru, cvt, mul_add.get_node_shared_ptr()}, {new_mul_add1, new_mul_add2, new_ru, new_ru_conv}); + copy_runtime_info({ru, cvt, mul_add.get_node_shared_ptr()}, + {new_mul_add1, new_mul_add2, new_ru, new_ru_conv}); new_ru_conv->set_friendly_name(m.get_match_root()->get_friendly_name()); ngraph::replace_node(m.get_match_root(), new_ru_conv); } else { diff --git a/src/common/transformations/src/transformations/common_optimizations/relu_fake_quantize_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/relu_fake_quantize_fusion.cpp index 96600f8e649..4d05cbee47b 100644 --- a/src/common/transformations/src/transformations/common_optimizations/relu_fake_quantize_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/relu_fake_quantize_fusion.cpp @@ -3,16 +3,15 @@ // #include "transformations/common_optimizations/relu_fake_quantize_fusion.hpp" -#include "transformations/utils/utils.hpp" -#include "itt.hpp" #include +#include +#include +#include #include -#include -#include -#include - +#include "itt.hpp" +#include "transformations/utils/utils.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ReluFakeQuantizeFusion, "ReluFakeQuantizeFusion", 0); @@ -21,7 +20,8 @@ ngraph::pass::ReluFakeQuantizeFusion::ReluFakeQuantizeFusion() { auto data_pattern = ngraph::pattern::any_input(); auto relu_pattern = ngraph::pattern::wrap_type({data_pattern}, pattern::consumers_count(1)); auto input_low_pattern = ngraph::pattern::wrap_type(); - auto fq_pattern = ngraph::pattern::wrap_type({relu_pattern, input_low_pattern, + auto fq_pattern = ngraph::pattern::wrap_type({relu_pattern, + input_low_pattern, ngraph::pattern::any_input(), ngraph::pattern::any_input(), ngraph::pattern::any_input()}); @@ -35,7 +35,9 @@ ngraph::pass::ReluFakeQuantizeFusion::ReluFakeQuantizeFusion() { if (!input_low_const) return false; auto input_low_values = input_low_const->cast_vector(); - if (std::any_of(input_low_values.begin(), input_low_values.end(), [] (float f) -> bool { return f < 0; })) + if (std::any_of(input_low_values.begin(), input_low_values.end(), [](float f) -> bool { + return f < 0; + })) return false; auto fq = std::dynamic_pointer_cast(pattern_map[fq_pattern].get_node_shared_ptr()); if (!fq) diff --git a/src/common/transformations/src/transformations/common_optimizations/remove_concat_zero_dim_input.cpp b/src/common/transformations/src/transformations/common_optimizations/remove_concat_zero_dim_input.cpp index d7faaaf2a28..9ced2a787ce 100644 --- a/src/common/transformations/src/transformations/common_optimizations/remove_concat_zero_dim_input.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/remove_concat_zero_dim_input.cpp @@ -3,17 +3,16 @@ // #include "transformations/common_optimizations/remove_concat_zero_dim_input.hpp" -#include "transformations/utils/utils.hpp" -#include -#include #include - -#include -#include "openvino/pass/pattern/op/wrap_type.hpp" +#include #include -#include "itt.hpp" +#include +#include +#include "itt.hpp" +#include "openvino/pass/pattern/op/wrap_type.hpp" +#include "transformations/utils/utils.hpp" NGRAPH_RTTI_DEFINITION(ov::pass::RemoveConcatZeroDimInput, "RemoveConcatZeroDimInput", 0); @@ -23,18 +22,23 @@ ov::pass::RemoveConcatZeroDimInput::RemoveConcatZeroDimInput() { ngraph::matcher_pass_callback callback = [=](pattern::Matcher& m) { auto concat = m.get_match_root(); auto concat_inputs = concat->input_values(); - concat_inputs.erase(std::remove_if(concat_inputs.begin(), concat_inputs.end(), - [](const Output& input) { - const auto& in_shape = input.get_partial_shape(); - if (in_shape.rank().is_static()) { - return std::any_of(std::begin(in_shape), std::end(in_shape), [](const ov::Dimension& dim) { - if (dim.is_static() && dim.get_length() == 0) { - return true; - } - return false; - });} + concat_inputs.erase( + std::remove_if( + concat_inputs.begin(), + concat_inputs.end(), + [](const Output& input) { + const auto& in_shape = input.get_partial_shape(); + if (in_shape.rank().is_static()) { + return std::any_of(std::begin(in_shape), std::end(in_shape), [](const ov::Dimension& dim) { + if (dim.is_static() && dim.get_length() == 0) { + return true; + } + return false; + }); + } return false; - }), concat_inputs.end()); + }), + concat_inputs.end()); bool inputs_removed = concat->get_input_size() > concat_inputs.size(); if (inputs_removed) { diff --git a/src/common/transformations/src/transformations/common_optimizations/remove_filtering_boxes_by_size.cpp b/src/common/transformations/src/transformations/common_optimizations/remove_filtering_boxes_by_size.cpp index 6c1fc703056..00b308b6095 100644 --- a/src/common/transformations/src/transformations/common_optimizations/remove_filtering_boxes_by_size.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/remove_filtering_boxes_by_size.cpp @@ -2,15 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" +#include "transformations/common_optimizations/remove_filtering_boxes_by_size.hpp" + #include +#include +#include +#include #include -#include -#include -#include - -#include "transformations/common_optimizations/remove_filtering_boxes_by_size.hpp" +#include "itt.hpp" #include "transformations/common_optimizations/subtract_fusion.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::FuseFilteringBoxesBySize, "FuseFilteringBoxesBySize", 0); @@ -25,39 +25,41 @@ ngraph::pass::RemoveFilteringBoxesBySize::RemoveFilteringBoxesBySize() { MATCHER_SCOPE(RemoveFilteringBoxesBySize); // variadic split auto data = std::make_shared(element::f32, Shape{1000, 4}); - auto sizes = opset3::Constant::create(element::i64, Shape{4}, std::vector({1, 1, 1, 1})); - auto axis = opset3::Constant::create(element::i64, Shape{1}, std::vector({1})); + auto sizes = opset3::Constant::create(element::i64, Shape{4}, std::vector({1, 1, 1, 1})); + auto axis = opset3::Constant::create(element::i64, Shape{1}, std::vector({1})); auto split = std::make_shared(data, axis, sizes); // sub -> add - auto sub_2_0 = std::make_shared(split->output(2), split->output(0)); + auto sub_2_0 = std::make_shared(split->output(2), split->output(0)); auto term_1 = std::make_shared(element::f32, Shape{1}); auto add_1 = std::make_shared(sub_2_0, term_1); - auto sub_3_1 = std::make_shared(split->output(3), split->output(1)); + auto sub_3_1 = std::make_shared(split->output(3), split->output(1)); auto term_2 = std::make_shared(element::f32, Shape{1}); auto add_2 = std::make_shared(sub_3_1, term_2); // concat - auto concat = std::make_shared(ngraph::OutputVector({split->output(0), split->output(1), add_1->output(0), add_2->output(0)}), 1); + auto concat = std::make_shared( + ngraph::OutputVector({split->output(0), split->output(1), add_1->output(0), add_2->output(0)}), + 1); // second variadic split - auto sizes_1 = opset3::Constant::create(element::i64, Shape{4}, std::vector({1, 1, 1, 1})); - auto axis_1 = opset3::Constant::create(element::i64, Shape{1}, std::vector({1})); + auto sizes_1 = opset3::Constant::create(element::i64, Shape{4}, std::vector({1, 1, 1, 1})); + auto axis_1 = opset3::Constant::create(element::i64, Shape{1}, std::vector({1})); auto split_1 = std::make_shared(concat, axis_1, sizes_1); // squeeze - auto squeeze_1_axis = opset3::Constant::create(element::i64, Shape{1}, std::vector({1})); + auto squeeze_1_axis = opset3::Constant::create(element::i64, Shape{1}, std::vector({1})); auto squeeze_1 = std::make_shared(split_1->output(2), squeeze_1_axis); - auto squeeze_2_axis = opset3::Constant::create(element::i64, Shape{1}, std::vector({1})); + auto squeeze_2_axis = opset3::Constant::create(element::i64, Shape{1}, std::vector({1})); auto squeeze_2 = std::make_shared(split_1->output(3), squeeze_2_axis); // less - auto less_1_constant = opset3::Constant::create(element::f32, Shape{1}, std::vector({0})); + auto less_1_constant = opset3::Constant::create(element::f32, Shape{1}, std::vector({0})); auto less_1 = std::make_shared(squeeze_1, less_1_constant); - auto less_2_constant = opset3::Constant::create(element::f32, Shape{1}, std::vector({0})); + auto less_2_constant = opset3::Constant::create(element::f32, Shape{1}, std::vector({0})); auto less_2 = std::make_shared(squeeze_2, less_2_constant); // Logical Not @@ -81,27 +83,27 @@ ngraph::pass::RemoveFilteringBoxesBySize::RemoveFilteringBoxesBySize() { // nonzero auto non_zero = std::make_shared(cast_32); - auto order = opset3::Constant::create(element::i64, Shape{2}, std::vector({1, 0})); + auto order = opset3::Constant::create(element::i64, Shape{2}, std::vector({1, 0})); auto transpose = std::make_shared(non_zero, order); - auto squeeze_3_axis = opset3::Constant::create(element::i64, Shape{1}, std::vector({1})); + auto squeeze_3_axis = opset3::Constant::create(element::i64, Shape{1}, std::vector({1})); auto squeeze_3 = std::make_shared(transpose, squeeze_3_axis); auto cast = std::make_shared(squeeze_3, ngraph::element::i64); ngraph::matcher_pass_callback callback = [data](pattern::Matcher& m) { - auto start = opset3::Constant::create(element::i64, Shape{}, std::vector({0})); - auto step = opset3::Constant::create(element::i64, Shape{}, std::vector({1})); + auto start = opset3::Constant::create(element::i64, Shape{}, std::vector({0})); + auto step = opset3::Constant::create(element::i64, Shape{}, std::vector({1})); - const auto & pattern_map = m.get_pattern_map(); + const auto& pattern_map = m.get_pattern_map(); auto input = pattern_map.at(data); auto output = m.get_match_root(); auto input_shape = std::make_shared(input); - auto axis = opset3::Constant::create(element::i64, Shape{}, std::vector({0})); - auto index = opset3::Constant::create(element::i64, Shape{}, std::vector({0})); + auto axis = opset3::Constant::create(element::i64, Shape{}, std::vector({0})); + auto index = opset3::Constant::create(element::i64, Shape{}, std::vector({0})); auto stop = std::make_shared(input_shape, index, axis); auto range = std::make_shared(start, stop, step); diff --git a/src/common/transformations/src/transformations/common_optimizations/remove_multi_subgraph_op_dangling_params.cpp b/src/common/transformations/src/transformations/common_optimizations/remove_multi_subgraph_op_dangling_params.cpp index 08c4ea78092..4fa80f62761 100644 --- a/src/common/transformations/src/transformations/common_optimizations/remove_multi_subgraph_op_dangling_params.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/remove_multi_subgraph_op_dangling_params.cpp @@ -3,17 +3,16 @@ // #include "transformations/common_optimizations/remove_multi_subgraph_op_dangling_params.hpp" -#include "transformations/utils/utils.hpp" #include +#include +#include +#include #include -#include -#include -#include "openvino/pass/pattern/op/wrap_type.hpp" -#include #include "itt.hpp" - +#include "openvino/pass/pattern/op/wrap_type.hpp" +#include "transformations/utils/utils.hpp" NGRAPH_RTTI_DEFINITION(ov::pass::RemoveMultiSubGraphOpDanglingParams, "RemoveMultiSubGraphOpDanglingParams", 0); @@ -31,7 +30,7 @@ ov::pass::RemoveMultiSubGraphOpDanglingParams::RemoveMultiSubGraphOpDanglingPara std::vector> to_remove_descriptors_indexes; const auto subgraphs_size = multi_subgraph_op->get_internal_subgraphs_size(); to_remove_descriptors_indexes.resize(subgraphs_size); - for (size_t body_idx=0; body_idx < subgraphs_size; ++body_idx) { + for (size_t body_idx = 0; body_idx < subgraphs_size; ++body_idx) { auto& body_func = multi_subgraph_op->get_function(body_idx); auto& body_params = body_func->get_parameters(); auto& body_in_descriptors = multi_subgraph_op->get_input_descriptions(body_idx); @@ -44,46 +43,52 @@ ov::pass::RemoveMultiSubGraphOpDanglingParams::RemoveMultiSubGraphOpDanglingPara } else { // collecting required inputs is needed to detect cases where the input // is not needed in a one body, but the other one uses it (for example If case) - required_inputs.insert(op_inputs[body_in_descriptors[i]->m_input_index]); // only unique + required_inputs.insert(op_inputs[body_in_descriptors[i]->m_input_index]); // only unique } } } if (pass_required) { using DescType = op::util::MultiSubGraphOp::MultiSubgraphInputDescriptionVector; - auto update_body_param_desc = [](DescType& descriptors, uint64_t removed_body_idx){ + auto update_body_param_desc = [](DescType& descriptors, uint64_t removed_body_idx) { for (auto& desc : descriptors) { if (desc->m_body_parameter_index > removed_body_idx) { desc->m_body_parameter_index--; } - }}; - auto update_op_inputs_desc = [&subgraphs_size](const std::shared_ptr& op, uint64_t removed_loop_idx){ - for (size_t body_idx=0; body_idx < subgraphs_size; ++body_idx) { + } + }; + auto update_op_inputs_desc = [&subgraphs_size](const std::shared_ptr& op, + uint64_t removed_loop_idx) { + for (size_t body_idx = 0; body_idx < subgraphs_size; ++body_idx) { auto& descriptors = op->get_input_descriptions(body_idx); for (auto& desc : descriptors) { if (desc->m_input_index > removed_loop_idx) { desc->m_input_index--; } } - }}; + } + }; // Remove dangling body params and input and update input descriptors - for (size_t body_idx=0; body_idx < subgraphs_size; ++body_idx) { + for (size_t body_idx = 0; body_idx < subgraphs_size; ++body_idx) { auto& body_in_descriptors = multi_subgraph_op->get_input_descriptions(body_idx); auto& body_func = multi_subgraph_op->get_function(body_idx); auto& body_params = body_func->get_parameters(); op::util::MultiSubGraphOp::MultiSubgraphInputDescriptionVector updated_body_in_descriptors; for (size_t desc_idx = 0; desc_idx < body_in_descriptors.size(); ++desc_idx) { - if (std::count(std::begin(to_remove_descriptors_indexes[body_idx]), std::end(to_remove_descriptors_indexes[body_idx]), desc_idx) > 0) { + if (std::count(std::begin(to_remove_descriptors_indexes[body_idx]), + std::end(to_remove_descriptors_indexes[body_idx]), + desc_idx) > 0) { auto& body_param = body_params[body_in_descriptors[desc_idx]->m_body_parameter_index]; body_func->remove_parameter(body_param); // Move all body indexes which are after these indicated by to_remove_descriptors_indexes - update_body_param_desc(body_in_descriptors, body_in_descriptors[desc_idx]->m_body_parameter_index); + update_body_param_desc(body_in_descriptors, + body_in_descriptors[desc_idx]->m_body_parameter_index); // remove dangling input of MultiSubGraphOp which was not removed earlier auto& current_input = op_inputs[body_in_descriptors[desc_idx]->m_input_index]; - if (std::count(std::begin(required_inputs), std::end(required_inputs), current_input) == 0 - && std::count(std::begin(op_inputs), std::end(op_inputs), current_input) > 0) { + if (std::count(std::begin(required_inputs), std::end(required_inputs), current_input) == 0 && + std::count(std::begin(op_inputs), std::end(op_inputs), current_input) > 0) { op_inputs.erase(std::next(op_inputs.begin(), body_in_descriptors[desc_idx]->m_input_index)); - // Move all input indexes (in all bodies) which are after these indicated by to_remove_descriptors_indexes - // and are not used in any body + // Move all input indexes (in all bodies) which are after these indicated by + // to_remove_descriptors_indexes and are not used in any body update_op_inputs_desc(multi_subgraph_op, body_in_descriptors[desc_idx]->m_input_index); } } else { diff --git a/src/common/transformations/src/transformations/common_optimizations/reshape_sequence_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/reshape_sequence_fusion.cpp index 847d0a196d4..f3ca206f315 100644 --- a/src/common/transformations/src/transformations/common_optimizations/reshape_sequence_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/reshape_sequence_fusion.cpp @@ -3,17 +3,16 @@ // #include "transformations/common_optimizations/reshape_sequence_fusion.hpp" -#include "transformations/utils/utils.hpp" #include +#include +#include +#include +#include #include -#include -#include -#include -#include #include "itt.hpp" - +#include "transformations/utils/utils.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ReshapeSequenceFusion, "ReshapeSequenceFusion", 0); @@ -23,45 +22,59 @@ bool has_valid_pattern(const ov::Output& node_out) { if (!const_node) { // Lower bound of the value auto lb = ngraph::evaluate_lower_bound(node_out); - if (!lb) return false; + if (!lb) + return false; const auto lb_const_node = std::make_shared(lb); - const auto & lb_values = lb_const_node->cast_vector(); + const auto& lb_values = lb_const_node->cast_vector(); // The pattern is valid if all lower bound values are higher than zero (not a special number) // or if the lower and upper bounds values are a sign of full dynamism - const bool lb_has_special_val = std::any_of(lb_values.cbegin(), lb_values.cend(), [](int64_t value) { return value < 1;}); - if (!lb_has_special_val) return true; + const bool lb_has_special_val = std::any_of(lb_values.cbegin(), lb_values.cend(), [](int64_t value) { + return value < 1; + }); + if (!lb_has_special_val) + return true; // Upper bound of the value auto ub = ngraph::evaluate_upper_bound(node_out); - if (!ub) return false; + if (!ub) + return false; const auto ub_const_node = std::make_shared(ub); - const auto & ub_values = ub_const_node->cast_vector(); - if (lb_values.size() != ub_values.size()) return false; + const auto& ub_values = ub_const_node->cast_vector(); + if (lb_values.size() != ub_values.size()) + return false; // Check if zero values are paired with max value as a sign of full dynamism - const int64_t ub_max = node_out.get_element_type() == ov::element::i32 ? std::numeric_limits::max() : std::numeric_limits::max(); - const auto mismatch_iters = std::mismatch(lb_values.cbegin(), lb_values.cend(), ub_values.cbegin(), - [ub_max](int64_t lb_val, int64_t ub_val){ return lb_val > 0 || (lb_val == 0 && ub_val == ub_max);}); + const int64_t ub_max = node_out.get_element_type() == ov::element::i32 ? std::numeric_limits::max() + : std::numeric_limits::max(); + const auto mismatch_iters = std::mismatch(lb_values.cbegin(), + lb_values.cend(), + ub_values.cbegin(), + [ub_max](int64_t lb_val, int64_t ub_val) { + return lb_val > 0 || (lb_val == 0 && ub_val == ub_max); + }); return mismatch_iters.first == lb_values.cend(); } - const auto & values = const_node->cast_vector(); + const auto& values = const_node->cast_vector(); // We can not fuse Reshapes if their pattern values have special numbers like -1 and 0 - return std::all_of(values.cbegin(), values.cend(), [](int64_t value) { return value > 0;}); + return std::all_of(values.cbegin(), values.cend(), [](int64_t value) { + return value > 0; + }); } -} // namespace +} // namespace ngraph::pass::ReshapeSequenceFusion::ReshapeSequenceFusion(bool use_shape_for_elimination) { MATCHER_SCOPE(ReshapeSequenceFusion); auto reshape_input = pattern::any_input(); auto reshape_a_pattern = pattern::wrap_type(); - auto reshape_a = pattern::wrap_type({reshape_input, reshape_a_pattern}, pattern::consumers_count(1)); + auto reshape_a = + pattern::wrap_type({reshape_input, reshape_a_pattern}, pattern::consumers_count(1)); auto reshape_b_pattern = pattern::any_input(); auto reshape_b = pattern::wrap_type({reshape_a, reshape_b_pattern}); matcher_pass_callback callback = [=](pattern::Matcher& m) { - const auto & pattern_map = m.get_pattern_value_map(); + const auto& pattern_map = m.get_pattern_value_map(); auto input = pattern_map.at(reshape_input); auto reshape = m.get_match_root(); @@ -76,8 +89,7 @@ ngraph::pass::ReshapeSequenceFusion::ReshapeSequenceFusion(bool use_shape_for_el NodeVector nodes{pattern_map.at(reshape_a).get_node_shared_ptr(), reshape}; while (std::dynamic_pointer_cast(input.get_node_shared_ptr())) { auto node = input.get_node_shared_ptr(); - if (!has_valid_pattern(node->get_input_node_shared_ptr(1)) || - input.get_target_inputs().size() != 1) { + if (!has_valid_pattern(node->get_input_node_shared_ptr(1)) || input.get_target_inputs().size() != 1) { break; } nodes.push_back(node); @@ -86,8 +98,8 @@ ngraph::pass::ReshapeSequenceFusion::ReshapeSequenceFusion(bool use_shape_for_el // remove redundant reshapes bool replaced = false; - if (use_shape_for_elimination && input.get_partial_shape().is_static() && reshape->get_output_partial_shape(0).is_static() && - input.get_shape() == reshape->get_output_shape(0)) { + if (use_shape_for_elimination && input.get_partial_shape().is_static() && + reshape->get_output_partial_shape(0).is_static() && input.get_shape() == reshape->get_output_shape(0)) { // in case if elimination is not allowed we still can eliminate all transposes except last one replaced = replace_output_update_name(reshape->output(0), input); } @@ -95,7 +107,7 @@ ngraph::pass::ReshapeSequenceFusion::ReshapeSequenceFusion(bool use_shape_for_el if (!replaced) { reshape->input(0).replace_source_output(input); copy_runtime_info(nodes, reshape); - return false; // because root node wasn't replaced + return false; // because root node wasn't replaced } return true; diff --git a/src/common/transformations/src/transformations/common_optimizations/ric_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/ric_fusion.cpp index d25065328a2..e1eb4d5e815 100644 --- a/src/common/transformations/src/transformations/common_optimizations/ric_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/ric_fusion.cpp @@ -3,23 +3,22 @@ // #include "transformations/common_optimizations/ric_fusion.hpp" -#include "transformations/utils/utils.hpp" #include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include "itt.hpp" - +#include "transformations/utils/utils.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ReverseInputChannelsFusion, "ReverseInputChannelsFusion", 0); @@ -32,10 +31,13 @@ namespace ric_attr { // In addition, attribute has some functionality and properties for propagation. class Attribute { public: - using callback_t = std::function, const Attribute &)>; + using callback_t = std::function, const Attribute&)>; Attribute(std::vector order, int64_t axis, bool is_final = false, bool is_initial = false) - : m_order(std::move(order)), m_axis(axis), m_is_final(is_final), m_is_initial(is_initial) { + : m_order(std::move(order)), + m_axis(axis), + m_is_final(is_final), + m_is_initial(is_initial) { m_can_be_fused.emplace_back(std::make_shared(true)); } @@ -48,13 +50,16 @@ public: return attr; } - void set_is_final(bool is_final) { m_is_final = is_final; } + void set_is_final(bool is_final) { + m_is_final = is_final; + } void set_can_be_fused(bool can_be_fused) { - std::for_each(m_can_be_fused.cbegin(), m_can_be_fused.cend(), - [can_be_fused](const std::shared_ptr & state) { - *state = can_be_fused; - }); + std::for_each(m_can_be_fused.cbegin(), + m_can_be_fused.cend(), + [can_be_fused](const std::shared_ptr& state) { + *state = can_be_fused; + }); } void set_callback(callback_t callback) { @@ -62,13 +67,12 @@ public: } // Apply callback to materialize RIC inside graph - void operator() (Input input) const { + void operator()(Input input) const { m_callback(input, *this); } bool can_be_fused() const { - return std::all_of(m_can_be_fused.cbegin(), m_can_be_fused.cend(), - [](const std::shared_ptr & state) { + return std::all_of(m_can_be_fused.cbegin(), m_can_be_fused.cend(), [](const std::shared_ptr& state) { return *state; }); } @@ -76,29 +80,39 @@ public: // For cases when we propagate through operation with multiple inputs like Eltwise // we have to merge RIC attrs from all inputs. To check that given attr be merged with // current we check the order and axis which must be the same. - bool can_be_merged_with(const Attribute & other) { + bool can_be_merged_with(const Attribute& other) { return (m_order.empty() || other.m_order.empty() || m_order == other.m_order) && m_axis == other.m_axis; } // When merging two and more attrs for further propagation we have to keep can_be_fused references // for cases when fusion is not possible, so we can update all related attrs. - void merge_with(const Attribute & other) { - m_can_be_fused.insert(m_can_be_fused.end(), - other.m_can_be_fused.begin(), - other.m_can_be_fused.end()); + void merge_with(const Attribute& other) { + m_can_be_fused.insert(m_can_be_fused.end(), other.m_can_be_fused.begin(), other.m_can_be_fused.end()); } - const std::vector & get_order() const { return m_order; } + const std::vector& get_order() const { + return m_order; + } - void set_order(const std::vector & order) { m_order = order; } + void set_order(const std::vector& order) { + m_order = order; + } - int64_t get_axis() const { return m_axis; } + int64_t get_axis() const { + return m_axis; + } - void set_axis(int64_t axis) { m_axis = axis; } + void set_axis(int64_t axis) { + m_axis = axis; + } - bool is_final() const { return m_is_final; } + bool is_final() const { + return m_is_final; + } - bool is_initial() const { return m_is_initial; } + bool is_initial() const { + return m_is_initial; + } private: // empty order means that the order is default and must be n, n-1, ..., 0 @@ -120,8 +134,7 @@ private: // Callback specifies the action for RIC materialization for given input port. // In most cases it should insert Gather operation for the input. - std::function, const Attribute &)> m_callback = - [](Input, const Attribute &) {}; + std::function, const Attribute&)> m_callback = [](Input, const Attribute&) {}; }; namespace { @@ -130,8 +143,8 @@ template using is_port = typename std::enable_if>::value>::type; template > -void set(T port, const Attribute & ric_attr) { - auto & attrs = port.get_rt_info(); +void set(T port, const Attribute& ric_attr) { + auto& attrs = port.get_rt_info(); attrs["reverse_input_channel_index"] = ric_attr; } @@ -141,14 +154,14 @@ void init(Output output, std::vector order, int64_t axis) { } template > -bool has(const T & port) { - const auto & attrs = port.get_rt_info(); +bool has(const T& port) { + const auto& attrs = port.get_rt_info(); return attrs.count("reverse_input_channel_index"); } template > -Attribute get(const T & port) { - const auto & attrs = port.get_rt_info(); +Attribute get(const T& port) { + const auto& attrs = port.get_rt_info(); auto res = attrs.find("reverse_input_channel_index"); if (res != attrs.end()) { return res->second.template as(); @@ -158,11 +171,11 @@ Attribute get(const T & port) { template > void erase(T port) { - auto & rt_info = port.get_rt_info(); + auto& rt_info = port.get_rt_info(); rt_info.erase("reverse_input_channel_index"); } -}// namespace -}// namespace ric_attr +} // namespace +} // namespace ric_attr namespace init { class SplitConcat : public ngraph::pass::MatcherPass { @@ -173,10 +186,11 @@ public: auto pattern_root = pattern::wrap_type({split_p, split_p, split_p}); auto callback = [=](pattern::Matcher& m) { - const auto & pattern_map = m.get_pattern_value_map(); + const auto& pattern_map = m.get_pattern_value_map(); auto concat = ov::as_type_ptr(pattern_map.at(pattern_root).get_node_shared_ptr()); auto split = ov::as_type_ptr(pattern_map.at(split_p).get_node_shared_ptr()); - if (!concat || !split) return false; + if (!concat || !split) + return false; // Avoid cases with two consecutive Split->Concat if (ric_attr::has(split->input_value(0))) { @@ -186,13 +200,14 @@ public: std::vector order; order.reserve(split->get_num_splits()); - for (const auto & input : concat->inputs()) { + for (const auto& input : concat->inputs()) { auto split_output = input.get_source_output(); - if (split_output.get_node() != split.get()) return false; + if (split_output.get_node() != split.get()) + return false; // Check that Concat is the only Split consumer and order of Split outputs // satisfies expected order for reverse input channel case. - for (const auto & target_input : split_output.get_target_inputs()) { + for (const auto& target_input : split_output.get_target_inputs()) { if (target_input.get_node() != concat.get()) { return false; } @@ -226,11 +241,12 @@ public: auto pattern_root = pattern::wrap_type({input_p, indices_p, axis_p}); auto callback = [=](pattern::Matcher& m) { - const auto & pattern_map = m.get_pattern_value_map(); - const auto & output = pattern_map.at(pattern_root); + const auto& pattern_map = m.get_pattern_value_map(); + const auto& output = pattern_map.at(pattern_root); auto axis = ov::get_constant_from_source(pattern_map.at(axis_p)); - if (!axis) return false; + if (!axis) + return false; const auto axis_value = axis->cast_vector().at(0); @@ -240,7 +256,8 @@ public: } auto order = ov::get_constant_from_source(pattern_map.at(indices_p)); - if (!order) return false; + if (!order) + return false; // Avoid cases with two consecutive Gathers if (ric_attr::has(pattern_map.at(input_p))) { @@ -248,17 +265,15 @@ public: } // This constraint helps to avoid detection of other Gathers that do not perform RIC - const auto & data_shape = m.get_match_root()->input(0).get_partial_shape(); - if (shape_size(order->get_shape()) == 1 || - axis_value < 0 || - axis_value >= data_shape.rank().get_length() || + const auto& data_shape = m.get_match_root()->input(0).get_partial_shape(); + if (shape_size(order->get_shape()) == 1 || axis_value < 0 || axis_value >= data_shape.rank().get_length() || data_shape[axis_value].is_dynamic() || shape_size(order->get_shape()) != static_cast(data_shape[axis_value].get_length())) { return false; } // Check that all order values are unique, otherwise it is not RIC - const auto & order_values = order->cast_vector(); + const auto& order_values = order->cast_vector(); std::set unique_values(order_values.cbegin(), order_values.cend()); if (unique_values.size() != order_values.size()) { return false; @@ -271,14 +286,14 @@ public: register_matcher(m, callback); } }; -}// namespace init +} // namespace init namespace prop { namespace { -std::shared_ptr create_const(const std::vector & values) { +std::shared_ptr create_const(const std::vector& values) { return opset8::Constant::create(ov::element::i64, ov::Shape{values.size()}, values); } -}// namespace +} // namespace class Binary : public ngraph::pass::MatcherPass { public: @@ -287,11 +302,11 @@ public: auto pattern_root = pattern::wrap_type(); auto callback = [=](pattern::Matcher& m) { - const auto & root = m.get_match_root(); - const auto & inputs = root->inputs(); + const auto& root = m.get_match_root(); + const auto& inputs = root->inputs(); std::map attrs; - for (const auto & input : inputs) { + for (const auto& input : inputs) { auto output = input.get_source_output(); if (ric_attr::has(output)) { attrs.insert({input.get_index(), ric_attr::get(output).propagate()}); @@ -302,32 +317,34 @@ public: } } - if (attrs.empty()) return false; + if (attrs.empty()) + return false; // Check that all RIC attrs can be merged and then merge them auto ric = attrs.begin()->second; auto rank = root->get_input_partial_shape(attrs.begin()->first).rank(); - if (rank.is_dynamic()) return false; + if (rank.is_dynamic()) + return false; auto data_rank = rank.get_length(); - for (const auto & item : attrs) { - const auto & input_rank = root->get_input_partial_shape(item.first).rank(); - if (input_rank.is_static() && - input_rank.get_length() == data_rank && - ric.can_be_merged_with(item.second) ) { + for (const auto& item : attrs) { + const auto& input_rank = root->get_input_partial_shape(item.first).rank(); + if (input_rank.is_static() && input_rank.get_length() == data_rank && + ric.can_be_merged_with(item.second)) { ric.merge_with(item.second); } else { return false; } } - for (const auto & input : inputs) { + for (const auto& input : inputs) { // Skip input that have RIC attribute - if (attrs.count(input.get_index())) continue; + if (attrs.count(input.get_index())) + continue; auto const_output = input.get_source_output(); - const auto & shape = const_output.get_shape(); - const int64_t & shape_rank = static_cast(shape.size()); + const auto& shape = const_output.get_shape(); + const int64_t& shape_rank = static_cast(shape.size()); if (shape_rank > data_rank) { // TODO: handle case when constant input broadcast another one return false; @@ -339,8 +356,8 @@ public: continue; } - const int64_t & new_axis = ric.get_axis() - (data_rank - shape_rank); - const auto & axis_dim = shape[new_axis]; + const int64_t& new_axis = ric.get_axis() - (data_rank - shape_rank); + const auto& axis_dim = shape[new_axis]; if (axis_dim == 1) { // we don't have to insert RIC for constant, so we keep propagating ric_attr::set(m.get_match_value(), ric); @@ -351,7 +368,7 @@ public: auto ric_const = ric; ric_const.set_axis(new_axis); ric_const.set_is_final(true); - ric_const.set_callback([axis_dim](Input input, const ric_attr::Attribute & attr) { + ric_const.set_callback([axis_dim](Input input, const ric_attr::Attribute& attr) { auto output = input.get_source_output(); // Handle case when the RIC order is default auto order = attr.get_order(); @@ -359,8 +376,8 @@ public: order.resize(axis_dim); std::iota(order.rbegin(), order.rend(), 0); } - auto gather = std::make_shared(output, create_const(order), - create_const({attr.get_axis()})); + auto gather = + std::make_shared(output, create_const(order), create_const({attr.get_axis()})); input.replace_source_output(gather); // TODO: copy runtime info from RIC sub-graph }); @@ -384,16 +401,18 @@ public: // a terminal node, so we do not propagate RIC attribute further and insert // final RIC attribute to the weights input. auto input_p = pattern::any_input(ric_attr::has>); - auto pattern_root = pattern::wrap_type({input_p, - pattern::wrap_type(pattern::has_static_dim(1/*output channel*/))}); + auto pattern_root = + pattern::wrap_type({input_p, + pattern::wrap_type( + pattern::has_static_dim(1 /*output channel*/))}); auto callback = [=](pattern::Matcher& m) { auto conv = m.get_match_root(); auto ric = ric_attr::get(conv->input_value(0)).propagate(); - if (ric.get_axis() != 1) return false; + if (ric.get_axis() != 1) + return false; ric.set_is_final(true); - ric.set_callback([](Input input, const ric_attr::Attribute & attr) { + ric.set_callback([](Input input, const ric_attr::Attribute& attr) { const auto output_channel_index = 1; auto order = attr.get_order(); // Handle case when the RIC order is default @@ -402,7 +421,8 @@ public: std::iota(order.rbegin(), order.rend(), 0); } auto weights = input.get_source_output(); - auto gather = std::make_shared(weights, create_const(order), + auto gather = std::make_shared(weights, + create_const(order), create_const({output_channel_index})); input.replace_source_output(gather); // TODO: copy runtime info from RIC sub-graph @@ -414,7 +434,7 @@ public: // Apply Binary transformation for FQ to handle 1..5 inputs ric.set_is_final(false); - ric_attr::set(fq->input_value(0), ric); // set ric attr to simulate propagation flow + ric_attr::set(fq->input_value(0), ric); // set ric attr to simulate propagation flow Binary().apply(fq); } else { ric_attr::set(conv->input(1), ric); @@ -432,15 +452,15 @@ public: GroupConvolution() { MATCHER_SCOPE(GroupConvolution); auto input_p = pattern::any_input(ric_attr::has>); - auto pattern_root = pattern::wrap_type({input_p, pattern::wrap_type(pattern::has_static_shape())}); + auto pattern_root = pattern::wrap_type( + {input_p, pattern::wrap_type(pattern::has_static_shape())}); auto callback = [=](pattern::Matcher& m) { auto conv = m.get_match_root(); - const auto & weights_shape = conv->input_value(1).get_shape(); - const int64_t & group = static_cast(weights_shape.at(0)); - const int64_t & channels = static_cast(weights_shape.at(1)); - const int64_t & in_channels = static_cast(weights_shape.at(2)); + const auto& weights_shape = conv->input_value(1).get_shape(); + const int64_t& group = static_cast(weights_shape.at(0)); + const int64_t& channels = static_cast(weights_shape.at(1)); + const int64_t& in_channels = static_cast(weights_shape.at(2)); auto ric = ric_attr::get(conv->input_value(0)).propagate(); auto order = ric.get_order(); @@ -460,9 +480,10 @@ public: auto ric_weights = ric; ric_weights.set_is_final(true); ric_weights.set_axis(0); - ric_weights.set_callback([](Input input, const ric_attr::Attribute & attr) { + ric_weights.set_callback([](Input input, const ric_attr::Attribute& attr) { auto weights = input.get_source_output(); - auto gather = std::make_shared(weights, create_const(attr.get_order()), + auto gather = std::make_shared(weights, + create_const(attr.get_order()), create_const({0} /* output channel */)); input.replace_source_output(gather); // TODO: copy runtime info from RIC sub-graph @@ -474,7 +495,7 @@ public: // Apply Binary transformation for FQ to handle 1..5 inputs ric_weights.set_is_final(false); - ric_attr::set(fq->input_value(0), ric_weights); // set ric attr to simulate propagation flow + ric_attr::set(fq->input_value(0), ric_weights); // set ric attr to simulate propagation flow Binary().apply(fq); } else { ric_attr::set(conv->input(1), ric_weights); @@ -484,7 +505,7 @@ public: const int64_t output_channels = group * channels; std::vector new_order; new_order.reserve(output_channels); - for (const auto & index : ric.get_order()) { + for (const auto& index : ric.get_order()) { for (int64_t pos = index * channels, i = 0; i < channels; ++i, ++pos) { new_order.emplace_back(pos); } @@ -521,12 +542,13 @@ class PassThrough : public ngraph::pass::MatcherPass { public: PassThrough() { MATCHER_SCOPE(PassThrough); - auto pattern_root = pattern::wrap_type(); + auto pattern_root = + pattern::wrap_type(); auto callback = [=](pattern::Matcher& m) { auto root = m.get_match_root(); - if (!ric_attr::has(root->input_value(0))) return false; + if (!ric_attr::has(root->input_value(0))) + return false; ric_attr::set(root->output(0), ric_attr::get(root->input_value(0)).propagate()); return true; }; @@ -545,11 +567,12 @@ public: auto pattern_root = pattern::wrap_type({input_p, order_p}); auto callback = [=](pattern::Matcher& m) { - const auto & pattern_map = m.get_pattern_value_map(); + const auto& pattern_map = m.get_pattern_value_map(); auto input = pattern_map.at(input_p); auto ric = ric_attr::get(input).propagate(); - auto order_node = std::dynamic_pointer_cast(pattern_map.at(order_p).get_node_shared_ptr()); + auto order_node = + std::dynamic_pointer_cast(pattern_map.at(order_p).get_node_shared_ptr()); auto order = order_node->cast_vector(); int64_t new_axis = std::find(order.begin(), order.end(), ric.get_axis()) - order.begin(); @@ -570,7 +593,7 @@ public: MATCHER_SCOPE(Unsupported); auto pattern_root = pattern::any_input(); auto callback = [=](pattern::Matcher& m) { - for (const auto & input : m.get_match_root()->input_values()) { + for (const auto& input : m.get_match_root()->input_values()) { if (ric_attr::has(input)) { auto ric = ric_attr::get(input); ric.set_can_be_fused(false); @@ -584,16 +607,17 @@ public: register_matcher(m, callback); } }; -}// namespace prop +} // namespace prop namespace fuse { namespace { -bool need_to_erase_ric(const Output & output) { - if (!ric_attr::has(output)) return false; - const auto & ric = ric_attr::get(output); +bool need_to_erase_ric(const Output& output) { + if (!ric_attr::has(output)) + return false; + const auto& ric = ric_attr::get(output); return ric.can_be_fused() && ric.is_initial(); } -}// namespace +} // namespace class InsertReverseInputChannel : public ngraph::pass::MatcherPass { public: @@ -601,10 +625,11 @@ public: MATCHER_SCOPE(InsertReverseInputChannel); auto pattern_root = pattern::any_input(); auto callback = [](pattern::Matcher& m) { - const auto & node = m.get_match_root(); - for (const auto & input : node->inputs()) { - if (!ric_attr::has(input)) continue; - const auto & ric = ric_attr::get(input); + const auto& node = m.get_match_root(); + for (const auto& input : node->inputs()) { + if (!ric_attr::has(input)) + continue; + const auto& ric = ric_attr::get(input); if (ric.can_be_fused() && ric.is_final()) { ric(input); } @@ -626,7 +651,7 @@ public: auto pattern_root = pattern::wrap_type({split_p, split_p, split_p}, need_to_erase_ric); auto callback = [=](pattern::Matcher& m) { - const auto & pattern_map = m.get_pattern_value_map(); + const auto& pattern_map = m.get_pattern_value_map(); auto output = pattern_map.at(pattern_root); auto input = pattern_map.at(input_p); output.replace(input); @@ -643,11 +668,10 @@ public: EraseGather() { MATCHER_SCOPE(EraseGather); auto input_p = pattern::any_input(); - auto pattern_root = pattern::wrap_type({input_p, pattern::any_input(), - pattern::any_input()}, - need_to_erase_ric); + auto pattern_root = pattern::wrap_type({input_p, pattern::any_input(), pattern::any_input()}, + need_to_erase_ric); auto callback = [=](pattern::Matcher& m) { - const auto & pattern_map = m.get_pattern_value_map(); + const auto& pattern_map = m.get_pattern_value_map(); auto output = pattern_map.at(pattern_root); auto input = pattern_map.at(input_p); output.replace(input); @@ -658,9 +682,9 @@ public: register_matcher(m, callback); } }; -}// namespace fuse +} // namespace fuse -bool ngraph::pass::ReverseInputChannelsFusion::run_on_model(const std::shared_ptr & model) { +bool ngraph::pass::ReverseInputChannelsFusion::run_on_model(const std::shared_ptr& model) { Manager m; m.set_per_pass_validation(false); @@ -687,5 +711,5 @@ bool ngraph::pass::ReverseInputChannelsFusion::run_on_model(const std::shared_pt m.run_passes(model); return false; } -}// namespace pass -}// namespace ngraph \ No newline at end of file +} // namespace pass +} // namespace ngraph \ No newline at end of file diff --git a/src/common/transformations/src/transformations/common_optimizations/shuffle_channels_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/shuffle_channels_fusion.cpp index 9bd38afdcc9..9bfa4d74b95 100644 --- a/src/common/transformations/src/transformations/common_optimizations/shuffle_channels_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/shuffle_channels_fusion.cpp @@ -3,20 +3,21 @@ // #include "transformations/common_optimizations/shuffle_channels_fusion.hpp" -#include "itt.hpp" #include -#include - #include #include #include +#include +#include "itt.hpp" #include "transformations/utils/utils.hpp" namespace { -bool check_shapes(const ngraph::PartialShape& pshape_input, const ngraph::PartialShape& pshape_reshape_before, - const ngraph::AxisVector& transpose_constant_values, const ngraph::PartialShape& pshape_reshape_after) { +bool check_shapes(const ngraph::PartialShape& pshape_input, + const ngraph::PartialShape& pshape_reshape_before, + const ngraph::AxisVector& transpose_constant_values, + const ngraph::PartialShape& pshape_reshape_after) { // x: [N, C, H, W] const auto rank = pshape_input.rank(); if (rank.is_dynamic() || rank.get_length() != 4) { @@ -24,7 +25,9 @@ bool check_shapes(const ngraph::PartialShape& pshape_input, const ngraph::Partia } // check that all dimensions except batch are static - if (std::any_of(pshape_input.begin() + 1, pshape_input.end(), [](const ngraph::Dimension& x) { return x.is_dynamic(); })) { + if (std::any_of(pshape_input.begin() + 1, pshape_input.end(), [](const ngraph::Dimension& x) { + return x.is_dynamic(); + })) { return false; } @@ -36,20 +39,16 @@ bool check_shapes(const ngraph::PartialShape& pshape_input, const ngraph::Partia const auto group = pshape_reshape_before[1].get_length(); ngraph::PartialShape expected_reshape_before; if (pshape_reshape_before.rank().get_length() == 4) { - expected_reshape_before = { - pshape_input[0], - group, - pshape_input[1].get_length() / group, - pshape_input[2].get_length() * pshape_input[3].get_length() - }; + expected_reshape_before = {pshape_input[0], + group, + pshape_input[1].get_length() / group, + pshape_input[2].get_length() * pshape_input[3].get_length()}; } else { - expected_reshape_before = { - pshape_input[0], - group, - pshape_input[1].get_length() / group, - pshape_input[2], - pshape_input[3] - }; + expected_reshape_before = {pshape_input[0], + group, + pshape_input[1].get_length() / group, + pshape_input[2], + pshape_input[3]}; } if (!ngraph::op::util::shapes_equal_except_dynamic_expected_batch(expected_reshape_before, pshape_reshape_before)) { @@ -61,7 +60,7 @@ bool check_shapes(const ngraph::PartialShape& pshape_input, const ngraph::Partia return false; } - ngraph::AxisVector expected_transpose_values{ 0, 2, 1, 3 }; + ngraph::AxisVector expected_transpose_values{0, 2, 1, 3}; if (transpose_constant_values.size() == 5) { expected_transpose_values.push_back(4); } @@ -78,7 +77,7 @@ bool check_shapes(const ngraph::PartialShape& pshape_input, const ngraph::Partia return true; } -} // namespace +} // namespace NGRAPH_RTTI_DEFINITION(ngraph::pass::ShuffleChannelsFusion, "ShuffleChannelsFusion", 0); @@ -89,19 +88,25 @@ ngraph::pass::ShuffleChannelsFusion::ShuffleChannelsFusion(const bool reshape_co auto transpose_const_pattern = ngraph::pattern::wrap_type(); auto reshape_after_const_pattern = ngraph::pattern::wrap_type(); - auto reshape_before_pattern = ngraph::pattern::wrap_type({input, reshape_before_const_pattern}, - pattern::consumers_count(1)); - auto transpose_pattern = ngraph::pattern::wrap_type({reshape_before_pattern, transpose_const_pattern}, - pattern::consumers_count(1)); - auto reshape_after_pattern = ngraph::pattern::wrap_type({transpose_pattern, reshape_after_const_pattern}); + auto reshape_before_pattern = + ngraph::pattern::wrap_type({input, reshape_before_const_pattern}, + pattern::consumers_count(1)); + auto transpose_pattern = + ngraph::pattern::wrap_type({reshape_before_pattern, transpose_const_pattern}, + pattern::consumers_count(1)); + auto reshape_after_pattern = + ngraph::pattern::wrap_type({transpose_pattern, reshape_after_const_pattern}); ngraph::matcher_pass_callback callback = [=](pattern::Matcher& m) { const auto& pattern_map = m.get_pattern_value_map(); auto data = pattern_map.at(input); - auto reshape_before = std::dynamic_pointer_cast(pattern_map.at(reshape_before_pattern).get_node_shared_ptr()); - auto transpose = std::dynamic_pointer_cast(pattern_map.at(transpose_pattern).get_node_shared_ptr()); - auto reshape_after = std::dynamic_pointer_cast(pattern_map.at(reshape_after_pattern).get_node_shared_ptr()); + auto reshape_before = std::dynamic_pointer_cast( + pattern_map.at(reshape_before_pattern).get_node_shared_ptr()); + auto transpose = std::dynamic_pointer_cast( + pattern_map.at(transpose_pattern).get_node_shared_ptr()); + auto reshape_after = std::dynamic_pointer_cast( + pattern_map.at(reshape_after_pattern).get_node_shared_ptr()); if (!reshape_after || !transpose || !reshape_after) { return false; } @@ -118,8 +123,14 @@ ngraph::pass::ShuffleChannelsFusion::ShuffleChannelsFusion(const bool reshape_co const auto& reshape_before_values = reshape_before_constant->cast_vector(); const auto& reshape_after_values = reshape_after_constant->cast_vector(); - if (std::any_of(reshape_before_values.cbegin(), reshape_before_values.cend(), [](const int64_t& value) { return value == -1; }) || - std::any_of(reshape_after_values.cbegin(), reshape_after_values.cend(), [](const int64_t& value) { return value == -1; })) { + if (std::any_of(reshape_before_values.cbegin(), + reshape_before_values.cend(), + [](const int64_t& value) { + return value == -1; + }) || + std::any_of(reshape_after_values.cbegin(), reshape_after_values.cend(), [](const int64_t& value) { + return value == -1; + })) { return false; } } @@ -128,7 +139,8 @@ ngraph::pass::ShuffleChannelsFusion::ShuffleChannelsFusion(const bool reshape_co auto pshape_reshape_before = reshape_before->get_output_partial_shape(0); auto pshape_reshape_after = reshape_after->get_output_partial_shape(0); - auto transpose_constant = std::dynamic_pointer_cast(pattern_map.at(transpose_const_pattern).get_node_shared_ptr()); + auto transpose_constant = std::dynamic_pointer_cast( + pattern_map.at(transpose_const_pattern).get_node_shared_ptr()); auto transpose_constant_values = transpose_constant->get_axis_vector_val(); if (!check_shapes(pshape_input, pshape_reshape_before, transpose_constant_values, pshape_reshape_after)) { return false; @@ -139,7 +151,7 @@ ngraph::pass::ShuffleChannelsFusion::ShuffleChannelsFusion(const bool reshape_co auto shuffle_shannels = std::make_shared(data, axis, group); shuffle_shannels->set_friendly_name(reshape_after->get_friendly_name()); - ngraph::copy_runtime_info({ reshape_before, transpose, reshape_after }, shuffle_shannels); + ngraph::copy_runtime_info({reshape_before, transpose, reshape_after}, shuffle_shannels); ngraph::replace_node(reshape_after, shuffle_shannels); return true; }; diff --git a/src/common/transformations/src/transformations/common_optimizations/simplify_shape_of_sub_graph.cpp b/src/common/transformations/src/transformations/common_optimizations/simplify_shape_of_sub_graph.cpp index 4caa1311136..3d4a089686f 100644 --- a/src/common/transformations/src/transformations/common_optimizations/simplify_shape_of_sub_graph.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/simplify_shape_of_sub_graph.cpp @@ -3,20 +3,20 @@ // #include -#include - -#include "itt.hpp" #include #include #include #include #include -#include #include -#include -#include -#include +#include #include +#include +#include +#include +#include + +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::SharedShapeOf, "SharedShapeOf", 0); @@ -28,7 +28,7 @@ bool ngraph::pass::SharedShapeOf::run_on_model(const std::shared_ptr, std::vector>> source_to_shape_of; - for (const auto & node : f->get_ordered_ops()) { + for (const auto& node : f->get_ordered_ops()) { // Recursively apply transformation for sub-graph based operations if (auto sub_graph_node = std::dynamic_pointer_cast(node)) if (auto sub_graph = sub_graph_node->get_function()) @@ -74,12 +74,15 @@ ngraph::pass::GroupedGatherElimination::GroupedGatherElimination() { while (inputs.size() > i + 1) { auto curr = inputs[i].get_node_shared_ptr(), next = inputs[i + 1].get_node_shared_ptr(); if (curr->get_type_info() != next->get_type_info() || - (!ov::is_type(curr) && !ov::is_type(curr) && !ov::is_type(curr)) || + (!ov::is_type(curr) && !ov::is_type(curr) && + !ov::is_type(curr)) || (curr->input_value(0) != next->input_value(0))) { ++i; continue; - } // curr and next are the same type of gather which takes data from the same source - auto joint_indices = ngraph::op::util::make_try_fold(OutputVector{curr->input_value(1), next->input_value(1)}, 0); + } // curr and next are the same type of gather which takes data from the same source + auto joint_indices = ngraph::op::util::make_try_fold( + OutputVector{curr->input_value(1), next->input_value(1)}, + 0); std::shared_ptr new_gather; if (ov::is_type(curr)) { new_gather = register_new_node( @@ -105,7 +108,7 @@ ngraph::pass::GroupedGatherElimination::GroupedGatherElimination() { inputs[i] = new_gather->output(0); } ngraph::copy_runtime_info(concat, new_ops); - if (inputs.size() == 1) // we can optimize out concat + if (inputs.size() == 1) // we can optimize out concat return replace_output_update_name(concat->output(0), inputs[0]); if (original_inputs_size > inputs.size()) { auto new_concat = std::make_shared(inputs, 0); @@ -126,14 +129,15 @@ NGRAPH_RTTI_DEFINITION(ngraph::pass::GatherNopElimination, "GatherNopElimination ngraph::pass::GatherNopElimination::GatherNopElimination() { MATCHER_SCOPE(GatherNopElimination); const auto gather_label = ngraph::pattern::wrap_type( - {ngraph::pattern::any_input(pattern::has_static_shape()), - ngraph::pattern::wrap_type(), - ngraph::pattern::wrap_type()}); + {ngraph::pattern::any_input(pattern::has_static_shape()), + ngraph::pattern::wrap_type(), + ngraph::pattern::wrap_type()}); ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { auto gather = m.get_match_root(); const auto& number_of_indices = shape_size(gather->get_input_shape(1)); - if (gather->get_input_shape(0) != gather->get_output_shape(0) || shape_size(gather->get_input_shape(2)) != 1 || number_of_indices > 10) + if (gather->get_input_shape(0) != gather->get_output_shape(0) || shape_size(gather->get_input_shape(2)) != 1 || + number_of_indices > 10) return false; std::vector expected_vector(number_of_indices); std::iota(expected_vector.begin(), expected_vector.end(), 0); @@ -164,8 +168,7 @@ ngraph::pass::SimplifyGatherShapeOf::SimplifyGatherShapeOf() { auto gather_in_rank = gather->get_input_partial_shape(0).rank(); auto indices_rank = gather->get_input_partial_shape(1).rank(); auto axis = gather->get_axis(); - if (gather_in_rank.is_dynamic() || indices_rank.is_dynamic() || - axis == opset3::Gather::AXIS_NOT_SET_VALUE) { + if (gather_in_rank.is_dynamic() || indices_rank.is_dynamic() || axis == opset3::Gather::AXIS_NOT_SET_VALUE) { return false; } @@ -191,7 +194,8 @@ ngraph::pass::SimplifyGatherShapeOf::SimplifyGatherShapeOf() { new_ops.push_back(new_gather); concat_inputs.push_back(new_gather); } - auto shapeof_indices = std::make_shared(gather->input_value(1), node->get_output_element_type(0)); + auto shapeof_indices = + std::make_shared(gather->input_value(1), node->get_output_element_type(0)); new_ops.push_back(shapeof_indices); concat_inputs.push_back(shapeof_indices); @@ -226,7 +230,7 @@ ngraph::pass::SimplifySecondInputOfReshape::SimplifySecondInputOfReshape() { return pattern::has_static_shape()(output) && pattern::rank_equals(1)(output); }; const auto concat = pattern::wrap_type(has_static_1d_shape); - const auto reshape_pattern = pattern::wrap_type({ input, concat }); + const auto reshape_pattern = pattern::wrap_type({input, concat}); ngraph::matcher_pass_callback callback = [=](pattern::Matcher& m) { auto node = m.get_match_root(); @@ -283,12 +287,13 @@ ngraph::pass::SimplifySecondInputOfReshape::SimplifySecondInputOfReshape() { if (gather_can_be_fused) { const size_t num_of_unchanged_dimensions = indices.size(); const auto subgraph_et = gather->get_input_element_type(0); - input = opset8::Constant::create(subgraph_et, Shape{ num_of_unchanged_dimensions }, { 0 }); + input = opset8::Constant::create(subgraph_et, Shape{num_of_unchanged_dimensions}, {0}); gather_folded = true; } } else { const auto concat_input_shape = input.get_shape(); - OPENVINO_ASSERT(concat_input_shape.size() == 1, "concat input rank is not valid for matched Concat with 1D output"); + OPENVINO_ASSERT(concat_input_shape.size() == 1, + "concat input rank is not valid for matched Concat with 1D output"); gather_dims_expected_location += concat_input_shape[0]; } } @@ -301,7 +306,7 @@ ngraph::pass::SimplifySecondInputOfReshape::SimplifySecondInputOfReshape() { new_concat->set_friendly_name(concat->get_friendly_name()); copy_runtime_info(concat, new_concat); - const auto new_reshape = reshape->clone_with_new_inputs({ reshape->input_value(0), new_concat }); + const auto new_reshape = reshape->clone_with_new_inputs({reshape->input_value(0), new_concat}); new_reshape->set_friendly_name(reshape->get_friendly_name()); copy_runtime_info(reshape, new_reshape); diff --git a/src/common/transformations/src/transformations/common_optimizations/skip_gather_before_transpose_and_reshape.cpp b/src/common/transformations/src/transformations/common_optimizations/skip_gather_before_transpose_and_reshape.cpp index 530e4537fe6..7a499b165b4 100644 --- a/src/common/transformations/src/transformations/common_optimizations/skip_gather_before_transpose_and_reshape.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/skip_gather_before_transpose_and_reshape.cpp @@ -3,15 +3,14 @@ // #include "transformations/common_optimizations/skip_gather_before_transpose_and_reshape.hpp" -#include "itt.hpp" #include -#include - -#include #include #include +#include +#include +#include "itt.hpp" #include "transformations/utils/utils.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::SkipGatherBeforeTransposeAndReshape, "SkipGatherBeforeTransposeAndReshape", 0); @@ -52,18 +51,22 @@ ngraph::pass::SkipGatherBeforeTransposeAndReshape::SkipGatherBeforeTransposeAndR } const auto transpose = pattern_map.at(transpose_m).get_node_shared_ptr(); - const auto transpose_const = as_type_ptr(pattern_map.at(transpose_const_m).get_node_shared_ptr()); + const auto transpose_const = + as_type_ptr(pattern_map.at(transpose_const_m).get_node_shared_ptr()); if (!transpose_const) { return false; } - const auto reshape_const = as_type_ptr(pattern_map.at(reshape_const_m).get_node_shared_ptr()); + const auto reshape_const = + as_type_ptr(pattern_map.at(reshape_const_m).get_node_shared_ptr()); if (!reshape_const) { return false; } const auto reshape_vals = reshape_const->cast_vector(); - if (std::any_of(reshape_vals.begin(), reshape_vals.end(), [](const std::int64_t x) { return x == 0; })) { + if (std::any_of(reshape_vals.begin(), reshape_vals.end(), [](const std::int64_t x) { + return x == 0; + })) { return false; } diff --git a/src/common/transformations/src/transformations/common_optimizations/softmax_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/softmax_fusion.cpp index dc5406dd24a..0c94a6af141 100644 --- a/src/common/transformations/src/transformations/common_optimizations/softmax_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/softmax_fusion.cpp @@ -3,16 +3,15 @@ // #include "transformations/common_optimizations/softmax_fusion.hpp" -#include "transformations/utils/utils.hpp" #include +#include +#include +#include #include -#include -#include -#include #include "itt.hpp" - +#include "transformations/utils/utils.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::SoftmaxFusion, "SoftmaxFusion", 0); @@ -33,10 +32,12 @@ ngraph::pass::SoftmaxFusion::SoftmaxFusion() { const auto& pattern_map = m.get_pattern_value_map(); - auto reduce_max_axes = std::dynamic_pointer_cast(pattern_map.at(reduce_max_axes_pattern).get_node_shared_ptr()); + auto reduce_max_axes = + std::dynamic_pointer_cast(pattern_map.at(reduce_max_axes_pattern).get_node_shared_ptr()); if (!reduce_max_axes || shape_size(reduce_max_axes->get_shape()) != 1) return false; - auto reduce_sum_axes = std::dynamic_pointer_cast(pattern_map.at(reduce_sum_axes_pattern).get_node_shared_ptr()); + auto reduce_sum_axes = + std::dynamic_pointer_cast(pattern_map.at(reduce_sum_axes_pattern).get_node_shared_ptr()); if (!reduce_sum_axes || shape_size(reduce_sum_axes->get_shape()) != 1) return false; @@ -46,9 +47,9 @@ ngraph::pass::SoftmaxFusion::SoftmaxFusion() { const auto& pshape = pattern_map.at(data_pattern).get_partial_shape(); auto rank = pshape.rank().get_length(); if (reduce_max_axis < 0) - reduce_max_axis += rank; + reduce_max_axis += rank; if (reduce_sum_axis < 0) - reduce_sum_axis += rank; + reduce_sum_axis += rank; } if (reduce_max_axis != reduce_sum_axis) return false; @@ -57,14 +58,15 @@ ngraph::pass::SoftmaxFusion::SoftmaxFusion() { auto div = pattern_map.at(div_pattern).get_node_shared_ptr(); softmax->set_friendly_name(div->get_friendly_name()); - copy_runtime_info({ - pattern_map.at(reduce_max_pattern).get_node_shared_ptr(), - pattern_map.at(sub_pattern).get_node_shared_ptr(), - pattern_map.at(exp_pattern).get_node_shared_ptr(), - pattern_map.at(reduce_sum_pattern).get_node_shared_ptr(), - div, - }, - softmax); + copy_runtime_info( + { + pattern_map.at(reduce_max_pattern).get_node_shared_ptr(), + pattern_map.at(sub_pattern).get_node_shared_ptr(), + pattern_map.at(exp_pattern).get_node_shared_ptr(), + pattern_map.at(reduce_sum_pattern).get_node_shared_ptr(), + div, + }, + softmax); replace_node(div, softmax); return true; diff --git a/src/common/transformations/src/transformations/common_optimizations/softplus_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/softplus_fusion.cpp index 3749de60332..84e44e5dff7 100644 --- a/src/common/transformations/src/transformations/common_optimizations/softplus_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/softplus_fusion.cpp @@ -2,15 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/common_optimizations/softplus_fusion.hpp" #include +#include +#include +#include #include -#include -#include -#include +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::SoftPlusFusion, "SoftPlusFusion", 0); @@ -19,17 +19,19 @@ ngraph::pass::SoftPlusFusion::SoftPlusFusion() { // fuses ln(exp(x) + 1.0) operations into SoftPlus(x) auto input = ngraph::pattern::any_input(); auto exp = std::make_shared(input); - auto add_constant = ngraph::pattern::wrap_type( - pattern::type_matches_any({element::f32, element::f16})); + auto add_constant = + ngraph::pattern::wrap_type(pattern::type_matches_any({element::f32, element::f16})); auto add = std::make_shared(exp, add_constant); auto log = std::make_shared(add); - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { - const auto &pattern_to_output = m.get_pattern_value_map(); + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { + const auto& pattern_to_output = m.get_pattern_value_map(); auto exp_input = pattern_to_output.at(input); - auto constant = std::dynamic_pointer_cast(pattern_to_output.at(add_constant).get_node_shared_ptr()); - if (!constant) return false; + auto constant = std::dynamic_pointer_cast( + pattern_to_output.at(add_constant).get_node_shared_ptr()); + if (!constant) + return false; auto data = constant->cast_vector(); if (data.size() != 1 || data[0] != 1.0) { @@ -41,7 +43,8 @@ ngraph::pass::SoftPlusFusion::SoftPlusFusion() { softplus->set_friendly_name(m.get_match_root()->get_friendly_name()); ngraph::copy_runtime_info({pattern_to_output.at(log).get_node_shared_ptr(), pattern_to_output.at(add).get_node_shared_ptr(), - pattern_to_output.at(exp).get_node_shared_ptr()}, softplus); + pattern_to_output.at(exp).get_node_shared_ptr()}, + softplus); ngraph::replace_node(m.get_match_root(), softplus); return true; }; diff --git a/src/common/transformations/src/transformations/common_optimizations/softplus_to_mish_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/softplus_to_mish_fusion.cpp index 6b6c45efbd2..56ed85b040e 100644 --- a/src/common/transformations/src/transformations/common_optimizations/softplus_to_mish_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/softplus_to_mish_fusion.cpp @@ -2,15 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/common_optimizations/softplus_to_mish_fusion.hpp" #include +#include +#include +#include #include -#include -#include -#include +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::SoftPlusToMishFusion, "SoftPlusToMishFusion", 0); @@ -22,7 +22,7 @@ ngraph::pass::SoftPlusToMishFusion::SoftPlusToMishFusion() { auto mul = std::make_shared(input, tanh); ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { - auto & pattern_to_output = m.get_pattern_value_map(); + auto& pattern_to_output = m.get_pattern_value_map(); auto exp_input = pattern_to_output.at(input); auto mish = std::make_shared(exp_input); @@ -30,7 +30,8 @@ ngraph::pass::SoftPlusToMishFusion::SoftPlusToMishFusion() { mish->set_friendly_name(m.get_match_root()->get_friendly_name()); ngraph::copy_runtime_info({pattern_to_output.at(mul).get_node_shared_ptr(), pattern_to_output.at(tanh).get_node_shared_ptr(), - pattern_to_output.at(softplus).get_node_shared_ptr()}, mish); + pattern_to_output.at(softplus).get_node_shared_ptr()}, + mish); ngraph::replace_node(m.get_match_root(), mish); return true; }; diff --git a/src/common/transformations/src/transformations/common_optimizations/space_to_batch_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/space_to_batch_fusion.cpp index 1928a48219a..f15b890377b 100644 --- a/src/common/transformations/src/transformations/common_optimizations/space_to_batch_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/space_to_batch_fusion.cpp @@ -3,60 +3,71 @@ // #include "transformations/common_optimizations/space_to_batch_fusion.hpp" -#include "transformations/utils/utils.hpp" #include +#include +#include +#include +#include #include -#include -#include -#include -#include #include "itt.hpp" - +#include "transformations/utils/utils.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::SpaceToBatchFusion, "SpaceToBatchFusion", 0); ngraph::pass::SpaceToBatchFusion::SpaceToBatchFusion() { MATCHER_SCOPE(SpaceToBatchFusion); auto data_pattern = pattern::any_input(); - auto reshape_before_pattern = pattern::wrap_type({data_pattern, pattern::wrap_type()}, pattern::rank_equals(4)); - auto trans_before_pattern = pattern::wrap_type({data_pattern, pattern::wrap_type()}, pattern::rank_equals(4)); - auto reshape_or_transpose_before_pattern = std::make_shared(OutputVector{reshape_before_pattern, trans_before_pattern}); + auto reshape_before_pattern = + pattern::wrap_type({data_pattern, pattern::wrap_type()}, + pattern::rank_equals(4)); + auto trans_before_pattern = + pattern::wrap_type({data_pattern, pattern::wrap_type()}, + pattern::rank_equals(4)); + auto reshape_or_transpose_before_pattern = + std::make_shared(OutputVector{reshape_before_pattern, trans_before_pattern}); auto pads_begin_pattern = pattern::wrap_type(); auto pads_end_pattern = pattern::wrap_type(); auto pad_value = pattern::wrap_type(); - auto pad_pattern = pattern::wrap_type({reshape_or_transpose_before_pattern, pads_begin_pattern, pads_end_pattern, pad_value}); + auto pad_pattern = pattern::wrap_type( + {reshape_or_transpose_before_pattern, pads_begin_pattern, pads_end_pattern, pad_value}); auto space_to_depth_pattern = pattern::wrap_type({pad_pattern}, pattern::has_static_shape()); - auto reshape_after_pattern = pattern::wrap_type({space_to_depth_pattern, pattern::wrap_type()}, pattern::rank_equals(4)); - auto trans_after_pattern = pattern::wrap_type({space_to_depth_pattern, pattern::wrap_type()}, pattern::rank_equals(4)); - auto reshape_or_transpose_after_pattern = std::make_shared(OutputVector{reshape_after_pattern, trans_after_pattern}); + auto reshape_after_pattern = + pattern::wrap_type({space_to_depth_pattern, pattern::wrap_type()}, + pattern::rank_equals(4)); + auto trans_after_pattern = + pattern::wrap_type({space_to_depth_pattern, pattern::wrap_type()}, + pattern::rank_equals(4)); + auto reshape_or_transpose_after_pattern = + std::make_shared(OutputVector{reshape_after_pattern, trans_after_pattern}); matcher_pass_callback callback = [=](pattern::Matcher& m) { const auto& pattern_map = m.get_pattern_value_map(); - auto get_reshape_or_transpose = [&pattern_map] (const std::shared_ptr& reshape_pattern, - const std::shared_ptr& trans_pattern) -> std::shared_ptr { + auto get_reshape_or_transpose = [&pattern_map]( + const std::shared_ptr& reshape_pattern, + const std::shared_ptr& trans_pattern) -> std::shared_ptr { if (pattern_map.count(reshape_pattern)) return pattern_map.at(reshape_pattern).get_node_shared_ptr(); if (pattern_map.count(trans_pattern)) return pattern_map.at(trans_pattern).get_node_shared_ptr(); return nullptr; }; - auto check_input_output_shape = [] (const std::shared_ptr& node) -> bool { + auto check_input_output_shape = [](const std::shared_ptr& node) -> bool { const auto& input_shape = node->get_input_shape(0); const auto& output_shape = node->get_output_shape(0); // Transpose permutation has to be [1, 0, 2, 3] - return input_shape[0] == output_shape[1] && - input_shape[1] == output_shape[0] && - input_shape[2] == output_shape[2] && - input_shape[3] == output_shape[3]; + return input_shape[0] == output_shape[1] && input_shape[1] == output_shape[0] && + input_shape[2] == output_shape[2] && input_shape[3] == output_shape[3]; }; - std::shared_ptr reshape_or_trans_before = get_reshape_or_transpose(reshape_before_pattern, trans_before_pattern); + std::shared_ptr reshape_or_trans_before = + get_reshape_or_transpose(reshape_before_pattern, trans_before_pattern); if (!reshape_or_trans_before) return false; - std::shared_ptr reshape_or_trans_after = get_reshape_or_transpose(reshape_after_pattern, trans_after_pattern); + std::shared_ptr reshape_or_trans_after = + get_reshape_or_transpose(reshape_after_pattern, trans_after_pattern); if (!reshape_or_trans_after) return false; if (!check_input_output_shape(reshape_or_trans_before)) @@ -67,32 +78,37 @@ ngraph::pass::SpaceToBatchFusion::SpaceToBatchFusion() { auto pad = std::dynamic_pointer_cast(pattern_map.at(pad_pattern).get_node_shared_ptr()); if (!pad || pad->get_pad_mode() != op::PadMode::CONSTANT) return false; - auto pad_value_const = std::dynamic_pointer_cast(pattern_map.at(pad_value).get_node_shared_ptr()); + auto pad_value_const = + std::dynamic_pointer_cast(pattern_map.at(pad_value).get_node_shared_ptr()); if (!pad_value_const) return false; auto pad_value = pad_value_const->cast_vector(); if (pad_value.size() != 1 || pad_value[0] != 0.0f) return false; - auto space_to_depth = std::dynamic_pointer_cast(pattern_map.at(space_to_depth_pattern).get_node_shared_ptr()); + auto space_to_depth = std::dynamic_pointer_cast( + pattern_map.at(space_to_depth_pattern).get_node_shared_ptr()); if (!space_to_depth) return false; if (space_to_depth->get_mode() != opset6::SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST) return false; auto block_size = static_cast(space_to_depth->get_block_size()); - auto block_shape = op::Constant::create(element::i64, Shape{4}, - std::vector{1, 1, block_size, block_size}); - auto space_to_batch = register_new_node(pattern_map.at(data_pattern), block_shape, - pattern_map.at(pads_begin_pattern), pattern_map.at(pads_end_pattern)); + auto block_shape = + op::Constant::create(element::i64, Shape{4}, std::vector{1, 1, block_size, block_size}); + auto space_to_batch = register_new_node(pattern_map.at(data_pattern), + block_shape, + pattern_map.at(pads_begin_pattern), + pattern_map.at(pads_end_pattern)); space_to_batch->set_friendly_name(reshape_or_trans_after->get_friendly_name()); - copy_runtime_info({ - reshape_or_trans_before, - pad, - space_to_depth, - reshape_or_trans_after, - }, - space_to_batch); + copy_runtime_info( + { + reshape_or_trans_before, + pad, + space_to_depth, + reshape_or_trans_after, + }, + space_to_batch); replace_node(reshape_or_trans_after, space_to_batch); return true; diff --git a/src/common/transformations/src/transformations/common_optimizations/split_concat_pair_to_interpolate_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/split_concat_pair_to_interpolate_fusion.cpp index 7c797796b4f..bf1710619bd 100644 --- a/src/common/transformations/src/transformations/common_optimizations/split_concat_pair_to_interpolate_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/split_concat_pair_to_interpolate_fusion.cpp @@ -2,21 +2,21 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/common_optimizations/split_concat_pair_to_interpolate_fusion.hpp" #include #include +#include +#include +#include #include +#include #include #include #include #include -#include -#include -#include -#include +#include "itt.hpp" namespace { // This function creates a partition of its argument into groups consisting of adjacent identical elements. @@ -25,7 +25,8 @@ namespace { std::vector> grouped_vector(const std::vector& v) { std::vector> result; - if (v.empty()) return result; + if (v.empty()) + return result; uint64_t prev = v[0]; std::vector group; @@ -42,7 +43,8 @@ std::vector> grouped_vector(const std::vector& v return result; } -std::pair, uint64_t> get_split_before_concat(const std::shared_ptr& concat) { +std::pair, uint64_t> get_split_before_concat( + const std::shared_ptr& concat) { // This function gets producers of the 'concat' node, checks that the following conditions are fulfilled: // 1) all producers for 'concat' are Split nodes; // 2) 'concat' has only one unique producer ('split'); @@ -50,8 +52,8 @@ std::pair, uint64_t> get_split_before_con // 4) for any output port of 'split', number of corresponding input ports of the consumer is the same; // 5) for any output port 'i' of the 'split', corresponding input ports of the consumer are // [i * m, ..., i * m + (m - 1)], where 'm' is the same for all 'i'; - // and, if all these conditions are fulfilled, returns the above mentioned 'Concat' node. Otherwise, if some of these - // conditions is false, this functions returns nullptr. + // and, if all these conditions are fulfilled, returns the above mentioned 'Concat' node. Otherwise, if some of + // these conditions is false, this functions returns nullptr. std::vector idx; std::shared_ptr split; @@ -60,24 +62,28 @@ std::pair, uint64_t> get_split_before_con auto split_op = std::dynamic_pointer_cast(input.get_node_shared_ptr()); if (!split) split = split_op; - if (!split_op || split != split_op) return {}; + if (!split_op || split != split_op) + return {}; idx.emplace_back(static_cast(input.get_index())); } // If 'split' node has more than one consumer, then the transformation is not applicable. for (const auto& output : split->outputs()) { for (const auto& consumer : output.get_target_inputs()) { - if (consumer.get_node() != concat.get()) return {}; + if (consumer.get_node() != concat.get()) + return {}; } } - // If numbers of consumer ports are various for various output ports of 'split', then the transformation is not applicable. + // If numbers of consumer ports are various for various output ports of 'split', then the transformation is not + // applicable. auto grouped_idx = grouped_vector(idx); std::unordered_set sizes_of_groups; for (const auto& group : grouped_idx) { sizes_of_groups.insert(static_cast(group.size())); } - if (sizes_of_groups.size() != 1) return {}; + if (sizes_of_groups.size() != 1) + return {}; uint64_t size_of_group = *(sizes_of_groups.begin()); // The transformation is applicable if output port 0 of 'split' goes to ports [0, ..., m-1] of next node, @@ -85,12 +91,16 @@ std::pair, uint64_t> get_split_before_con // goes to ports [i * m, ..., i * m + (m - 1)], and so on. for (uint64_t i = 0; i < static_cast(grouped_idx.size()); ++i) { const auto& current_group = grouped_idx[i]; - if (std::any_of(current_group.begin(), current_group.end(), [i](uint64_t j){ return j != i; })) { return {}; } + if (std::any_of(current_group.begin(), current_group.end(), [i](uint64_t j) { + return j != i; + })) { + return {}; + } } return {split, size_of_group}; } -} // namespace +} // namespace NGRAPH_RTTI_DEFINITION(ngraph::pass::SplitConcatPairToInterpolateFusion, "SplitConcatPairToInterpolateFusion", 0); @@ -107,8 +117,8 @@ ngraph::pass::SplitConcatPairToInterpolateFusion::SplitConcatPairToInterpolateFu // 4) 'concat' takes inputs only from 'split'; // 5) split_dim of 'split' is equal to axis of 'concat'; // 6) output port 0 of 'split' goes to ports [0, ..., m-1] of next node, output port 1 of 'split' goes to ports - // [m, ..., m + (m-1)] of next node, ..., output port i of 'split' goes to ports [i * m, ..., i * m + (m - 1)], - // and so on; + // [m, ..., m + (m-1)] of next node, ..., output port i of 'split' goes to ports [i * m, ..., i * m + (m - + // 1)], and so on; // 7) number of outputs of 'split' is equal to the length of the split axis. // Such subgraph // Split -> Concat @@ -128,24 +138,30 @@ ngraph::pass::SplitConcatPairToInterpolateFusion::SplitConcatPairToInterpolateFu auto concat_pattern = ngraph::pattern::wrap_type(); ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { auto concat = std::dynamic_pointer_cast(m.get_match_root()); - if (!concat) return false; + if (!concat) + return false; uint64_t scale_factor; std::shared_ptr split; std::tie(split, scale_factor) = get_split_before_concat(concat); // If scale_factor == 1, then output data of Interpolate are equal to input data. Hence, we should not replace // Split->Concat pair with Interpolate. - if (!split || !scale_factor || scale_factor == 1) return false; + if (!split || !scale_factor || scale_factor == 1) + return false; - if (split->get_input_partial_shape(0).rank().is_dynamic()) return false; + if (split->get_input_partial_shape(0).rank().is_dynamic()) + return false; int64_t split_input_rank = split->get_input_partial_shape(0).rank().get_length(); - // If this transformation is applied in the case of the the rank is less than 4, we have a performance degradation. - // And, at this time, we have no models with Split->Concat pattern when this transformation is applicable and - // input rank of Split is greater than 5. - if (split_input_rank != 4 && split_input_rank != 5) return false; + // If this transformation is applied in the case of the the rank is less than 4, we have a performance + // degradation. And, at this time, we have no models with Split->Concat pattern when this transformation is + // applicable and input rank of Split is greater than 5. + if (split_input_rank != 4 && split_input_rank != 5) + return false; - auto split_axis_const = std::dynamic_pointer_cast(split->input_value(1).get_node_shared_ptr()); - if (!split_axis_const) return false; + auto split_axis_const = + std::dynamic_pointer_cast(split->input_value(1).get_node_shared_ptr()); + if (!split_axis_const) + return false; int64_t axis = split_axis_const->cast_vector()[0]; @@ -164,7 +180,8 @@ ngraph::pass::SplitConcatPairToInterpolateFusion::SplitConcatPairToInterpolateFu attrs.coordinate_transformation_mode = opset8::Interpolate::CoordinateTransformMode::HALF_PIXEL; attrs.cube_coeff = -0.75f; - auto scales_node = opset8::Constant::create(element::f32, {1}, std::vector{static_cast(scale_factor)}); + auto scales_node = + opset8::Constant::create(element::f32, {1}, std::vector{static_cast(scale_factor)}); auto axis_node = opset8::Constant::create(element::i64, {1}, std::vector{axis}); auto shape_node = std::make_shared(split->input_value(0)); @@ -172,7 +189,8 @@ ngraph::pass::SplitConcatPairToInterpolateFusion::SplitConcatPairToInterpolateFu auto sslice_end = opset8::Constant::create(element::i64, {1}, std::vector{axis + 1}); std::vector begin_mask = {0}; std::vector end_mask = {0}; - auto strided_slice_node = std::make_shared(shape_node, sslice_begin, sslice_end, begin_mask, end_mask); + auto strided_slice_node = + std::make_shared(shape_node, sslice_begin, sslice_end, begin_mask, end_mask); auto cast_shape_to_float = std::make_shared(strided_slice_node, element::f32); auto mul_node = std::make_shared(cast_shape_to_float, scales_node); @@ -190,11 +208,22 @@ ngraph::pass::SplitConcatPairToInterpolateFusion::SplitConcatPairToInterpolateFu if (!sizes_node) sizes_node = cast_mul_result_to_int; - auto interpolate = register_new_node(split->input_value(0), sizes_node, scales_node, axis_node, attrs); + auto interpolate = + register_new_node(split->input_value(0), sizes_node, scales_node, axis_node, attrs); interpolate->set_friendly_name(concat->get_friendly_name()); - copy_runtime_info({split, concat}, {scales_node, axis_node, shape_node, sslice_begin, sslice_end, strided_slice_node, cast_shape_to_float, mul_node, - floor_node, sizes_node, interpolate}); + copy_runtime_info({split, concat}, + {scales_node, + axis_node, + shape_node, + sslice_begin, + sslice_end, + strided_slice_node, + cast_shape_to_float, + mul_node, + floor_node, + sizes_node, + interpolate}); replace_node(concat, interpolate); return true; diff --git a/src/common/transformations/src/transformations/common_optimizations/split_squeeze_concat_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/split_squeeze_concat_fusion.cpp index 32fe8d9850e..88c84405678 100644 --- a/src/common/transformations/src/transformations/common_optimizations/split_squeeze_concat_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/split_squeeze_concat_fusion.cpp @@ -2,16 +2,16 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/common_optimizations/split_squeeze_concat_fusion.hpp" #include -#include -#include - #include -#include #include +#include +#include +#include + +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::SplitSqueezeConcatFusion, "SplitSqueezeConcatFusion", 0); @@ -22,28 +22,36 @@ ngraph::pass::SplitSqueezeConcatFusion::SplitSqueezeConcatFusion() { ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { const auto& pattern_to_output = m.get_pattern_value_map(); - auto concat = std::dynamic_pointer_cast(pattern_to_output.at(concat_pattern).get_node_shared_ptr()); - if (!concat) return false; + auto concat = std::dynamic_pointer_cast( + pattern_to_output.at(concat_pattern).get_node_shared_ptr()); + if (!concat) + return false; - NodeVector nodes_to_delete{ concat }; + NodeVector nodes_to_delete{concat}; int64_t axis_value = 0; std::shared_ptr split; const auto& concat_inputs = concat->input_values(); - if (concat_inputs.empty()) return false; + if (concat_inputs.empty()) + return false; for (size_t i = 0; i < concat_inputs.size(); i++) { auto squeeze = std::dynamic_pointer_cast(concat_inputs[i].get_node_shared_ptr()); - if (!squeeze) return false; + if (!squeeze) + return false; nodes_to_delete.push_back(squeeze); - auto split_to_check = std::dynamic_pointer_cast(squeeze->input_value(0).get_node_shared_ptr()); - auto squeeze_axes = std::dynamic_pointer_cast(squeeze->input_value(1).get_node_shared_ptr()); - if (!squeeze_axes || !split_to_check) return false; + auto split_to_check = + std::dynamic_pointer_cast(squeeze->input_value(0).get_node_shared_ptr()); + auto squeeze_axes = + std::dynamic_pointer_cast(squeeze->input_value(1).get_node_shared_ptr()); + if (!squeeze_axes || !split_to_check) + return false; auto squeeze_axes_vec = squeeze_axes->cast_vector(); - if (squeeze_axes_vec.size() != 1) return false; + if (squeeze_axes_vec.size() != 1) + return false; if (i == 0) { axis_value = squeeze_axes_vec[0]; @@ -54,15 +62,17 @@ ngraph::pass::SplitSqueezeConcatFusion::SplitSqueezeConcatFusion() { } auto split_output = squeeze->input_value(0); - if (split_output.get_target_inputs().size() != 1 || - split_output.get_index() != i) + if (split_output.get_target_inputs().size() != 1 || split_output.get_index() != i) return false; } - if (split->get_num_splits() != concat_inputs.size()) return false; + if (split->get_num_splits() != concat_inputs.size()) + return false; - auto split_axis = std::dynamic_pointer_cast(split->input_value(1).get_node_shared_ptr()); - if (!split_axis) return false; + auto split_axis = + std::dynamic_pointer_cast(split->input_value(1).get_node_shared_ptr()); + if (!split_axis) + return false; auto axis_vec = split_axis->cast_vector(); if (axis_vec.size() != 1 || axis_value != axis_vec[0]) @@ -79,13 +89,15 @@ ngraph::pass::SplitSqueezeConcatFusion::SplitSqueezeConcatFusion() { order.erase(order.begin() + axis_value); order.insert(order.begin() + concat_axis, axis_value); - auto transpose_order = ngraph::opset7::Constant::create(element::i64, { (size_t)rank.get_length() }, order); + auto transpose_order = ngraph::opset7::Constant::create(element::i64, {(size_t)rank.get_length()}, order); auto transpose = register_new_node(input, transpose_order); - auto shape_after = ngraph::opset7::Constant::create(element::i64, { (size_t)rank.get_length() - 1 }, concat->get_output_shape(0)); + auto shape_after = ngraph::opset7::Constant::create(element::i64, + {(size_t)rank.get_length() - 1}, + concat->get_output_shape(0)); auto reshape = std::make_shared(transpose, shape_after, false); reshape->set_friendly_name(m.get_match_root()->get_friendly_name()); - ngraph::copy_runtime_info(nodes_to_delete, { transpose, reshape }); + ngraph::copy_runtime_info(nodes_to_delete, {transpose, reshape}); ngraph::replace_node(m.get_match_root(), reshape); return true; }; diff --git a/src/common/transformations/src/transformations/common_optimizations/strides_optimization.cpp b/src/common/transformations/src/transformations/common_optimizations/strides_optimization.cpp index 0675d84a82c..f335e7d48fc 100644 --- a/src/common/transformations/src/transformations/common_optimizations/strides_optimization.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/strides_optimization.cpp @@ -2,18 +2,17 @@ // SPDX-License-Identifier: Apache-2.0 // +#include +#include +#include +#include +#include #include - -#include "itt.hpp" #include #include #include -#include -#include -#include -#include -#include +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::StridesOptimization, "StridesOptimization", 0); @@ -21,7 +20,9 @@ NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvStridesPropagation, "ConvStridesPropaga static bool can_propagate_conv_stride(const std::shared_ptr& conv) { const auto& kernel_shape = conv->input_value(1).get_shape(); - return std::all_of(kernel_shape.begin() + 2, kernel_shape.end(), [] (size_t s) -> bool { return s == 1; }); + return std::all_of(kernel_shape.begin() + 2, kernel_shape.end(), [](size_t s) -> bool { + return s == 1; + }); } static std::tuple check_next_ops(const std::vector>& next_ops) { @@ -32,37 +33,47 @@ static std::tuple check_next_ops(const std::vector bool { - bool all_ones = std::all_of(s.begin(), s.end(), [] (size_t i) -> bool { return i == 1; }); - return s == strides[0] && !all_ones; - }); + bool all_ops_are_valid = std::all_of(strides.begin(), strides.end(), [&strides](const ngraph::Strides& s) -> bool { + bool all_ones = std::all_of(s.begin(), s.end(), [](size_t i) -> bool { + return i == 1; + }); + return s == strides[0] && !all_ones; + }); return std::make_tuple(strides[0], all_ops_are_valid); } -static void insert_pooling(const ngraph::Output& first, ngraph::Input& second, const ngraph::Strides& strides) { +static void insert_pooling(const ngraph::Output& first, + ngraph::Input& second, + const ngraph::Strides& strides) { auto first_node = first.get_node_shared_ptr(); auto rank = first.get_partial_shape().rank(); bool do_reshape = rank.is_static() && static_cast(rank.get_length()) < strides.size() + 2; if (do_reshape) { size_t diff = strides.size() + 2 - static_cast(rank.get_length()); - auto ones = ngraph::opset7::Constant::create(ngraph::element::i64, ngraph::Shape{diff}, std::vector(diff, 1)); + auto ones = + ngraph::opset7::Constant::create(ngraph::element::i64, ngraph::Shape{diff}, std::vector(diff, 1)); auto current_shape = std::make_shared(first); - std::shared_ptr new_shape = std::make_shared(ngraph::OutputVector{ones, current_shape}, 0); + std::shared_ptr new_shape = + std::make_shared(ngraph::OutputVector{ones, current_shape}, 0); std::shared_ptr constant_new_shape = get_constant_from_source(new_shape); if (constant_new_shape) new_shape = constant_new_shape; first_node = std::make_shared(first_node, new_shape, false); } - std::shared_ptr new_node = std::make_shared(first_node, strides, ngraph::Shape{}, - ngraph::Shape{}, ngraph::Shape(strides.size(), 1)); + std::shared_ptr new_node = + std::make_shared(first_node, + strides, + ngraph::Shape{}, + ngraph::Shape{}, + ngraph::Shape(strides.size(), 1)); if (do_reshape) { // squeeze dimensions back size_t diff = strides.size() + 2 - static_cast(rank.get_length()); std::vector axes(diff); std::iota(axes.begin(), axes.end(), 0); - new_node = std::make_shared(new_node, - ngraph::opset7::Constant::create(ngraph::element::u64, ngraph::Shape{diff}, axes)); + new_node = std::make_shared( + new_node, + ngraph::opset7::Constant::create(ngraph::element::u64, ngraph::Shape{diff}, axes)); } std::shared_ptr constant_new_node = get_constant_from_source(new_node); if (constant_new_node) @@ -75,8 +86,9 @@ static void handle_not_equal_stride_props(std::vector bool { return s == 1; }); + bool are_strides_ones = std::all_of(strides.begin(), strides.end(), [](size_t s) -> bool { + return s == 1; + }); if (!are_strides_ones) { auto conv = dynamic_cast(op.get_node()); if (conv) { @@ -90,15 +102,15 @@ static void handle_not_equal_stride_props(std::vector& node) -> bool { - const auto& shape = node.get_partial_shape(); - const auto& rank = shape.rank(); - if (rank.is_dynamic()) - return false; - return std::all_of(shape.begin() + 2, shape.end(), [] (const Dimension& dim) -> bool { - return dim.is_static(); - }); - }); + auto data = pattern::any_input([](const Output& node) -> bool { + const auto& shape = node.get_partial_shape(); + const auto& rank = shape.rank(); + if (rank.is_dynamic()) + return false; + return std::all_of(shape.begin() + 2, shape.end(), [](const Dimension& dim) -> bool { + return dim.is_static(); + }); + }); auto weights = pattern::any_input(pattern::has_static_shape()); auto conv_pattern = pattern::wrap_type({data, weights}); @@ -117,8 +129,13 @@ ngraph::pass::ConvStridesPropagation::ConvStridesPropagation() { if (!all_ops_are_valid) { handle_not_equal_stride_props(std::move(next_ops)); } else { - std::transform(conv_strides.begin(), conv_strides.end(), strides.begin(), conv_strides.begin(), - [] (size_t s1, size_t s2) -> size_t { return s1 * s2; }); + std::transform(conv_strides.begin(), + conv_strides.end(), + strides.begin(), + conv_strides.begin(), + [](size_t s1, size_t s2) -> size_t { + return s1 * s2; + }); } if (can_propagate_conv_stride(conv)) { diff --git a/src/common/transformations/src/transformations/common_optimizations/subtract_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/subtract_fusion.cpp index b6a0d983a4e..2f7ad6625d4 100644 --- a/src/common/transformations/src/transformations/common_optimizations/subtract_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/subtract_fusion.cpp @@ -29,17 +29,18 @@ ngraph::pass::SubtractFusion::SubtractFusion() { auto p_add_input = pattern::any_input(); auto p_add = ngraph::pattern::wrap_type({p_add_input, p_mul_or_neg}); - matcher_pass_callback callback = [=](pattern::Matcher &m) { - const auto & pattern_to_output = m.get_pattern_value_map(); - const auto & minuend_input = pattern_to_output.at(p_add_input); - const auto & subtrahend_input = pattern_to_output.at(p_input); + matcher_pass_callback callback = [=](pattern::Matcher& m) { + const auto& pattern_to_output = m.get_pattern_value_map(); + const auto& minuend_input = pattern_to_output.at(p_add_input); + const auto& subtrahend_input = pattern_to_output.at(p_input); - const auto & add = pattern_to_output.at(p_add).get_node_shared_ptr(); + const auto& add = pattern_to_output.at(p_add).get_node_shared_ptr(); NodeVector nodes_to_replace{add}; if (pattern_to_output.count(p_mul_const)) { - auto minus_one_const = std::dynamic_pointer_cast(pattern_to_output.at(p_mul_const).get_node_shared_ptr()); + auto minus_one_const = + std::dynamic_pointer_cast(pattern_to_output.at(p_mul_const).get_node_shared_ptr()); if (!op::util::has_constant_value(minus_one_const, -1.)) { return false; } diff --git a/src/common/transformations/src/transformations/common_optimizations/swish_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/swish_fusion.cpp index adbeeaf026a..918416c801b 100644 --- a/src/common/transformations/src/transformations/common_optimizations/swish_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/swish_fusion.cpp @@ -2,14 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/common_optimizations/swish_fusion.hpp" #include - #include -#include #include +#include + +#include "itt.hpp" #include "transformations/utils/utils.hpp" namespace { @@ -30,7 +30,7 @@ bool check_beta_value(const std::shared_ptr& constant) return true; } -} // namespace +} // namespace NGRAPH_RTTI_DEFINITION(ngraph::pass::SwishFusion, "SwishFusion", 0); @@ -43,16 +43,16 @@ ngraph::pass::SwishFusionWithSigmoid::SwishFusionWithSigmoid() { auto sigmoid = std::make_shared(input); auto mul = std::make_shared(input, sigmoid); - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { - auto &pattern_to_output = m.get_pattern_value_map(); + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { + auto& pattern_to_output = m.get_pattern_value_map(); auto exp_input = pattern_to_output.at(input); auto swish = std::make_shared(exp_input); swish->set_friendly_name(m.get_match_root()->get_friendly_name()); - ngraph::copy_runtime_info({pattern_to_output.at(sigmoid).get_node_shared_ptr(), - pattern_to_output.at(mul).get_node_shared_ptr()}, - swish); + ngraph::copy_runtime_info( + {pattern_to_output.at(sigmoid).get_node_shared_ptr(), pattern_to_output.at(mul).get_node_shared_ptr()}, + swish); ngraph::replace_node(m.get_match_root(), swish); return true; }; @@ -72,8 +72,8 @@ ngraph::pass::SwishFusionWithSigmoidWithBeta::SwishFusionWithSigmoidWithBeta() { auto sigmoid = std::make_shared(mul_beta); auto mul = std::make_shared(input, sigmoid); - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { - auto &pattern_to_output = m.get_pattern_value_map(); + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { + auto& pattern_to_output = m.get_pattern_value_map(); auto exp_input = pattern_to_output.at(input); auto beta_input = pattern_to_output.at(beta); @@ -81,7 +81,9 @@ ngraph::pass::SwishFusionWithSigmoidWithBeta::SwishFusionWithSigmoidWithBeta() { Output new_beta; if (beta_constant) { if (check_beta_value(beta_constant)) { - new_beta = opset4::Constant::create(beta_input.get_element_type(), Shape{}, {beta_constant->cast_vector()[0]}); + new_beta = opset4::Constant::create(beta_input.get_element_type(), + Shape{}, + {beta_constant->cast_vector()[0]}); } else { return false; } @@ -96,9 +98,9 @@ ngraph::pass::SwishFusionWithSigmoidWithBeta::SwishFusionWithSigmoidWithBeta() { auto swish = std::make_shared(exp_input, new_beta); swish->set_friendly_name(m.get_match_root()->get_friendly_name()); - ngraph::copy_runtime_info({pattern_to_output.at(sigmoid).get_node_shared_ptr(), - pattern_to_output.at(mul).get_node_shared_ptr()}, - swish); + ngraph::copy_runtime_info( + {pattern_to_output.at(sigmoid).get_node_shared_ptr(), pattern_to_output.at(mul).get_node_shared_ptr()}, + swish); ngraph::replace_node(m.get_match_root(), swish); return true; }; @@ -121,11 +123,12 @@ ngraph::pass::SwishFusionWithBeta::SwishFusionWithBeta() { auto add = std::make_shared(exp, add_constant); auto div = std::make_shared(input, add); - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { - auto &pattern_to_output = m.get_pattern_value_map(); + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { + auto& pattern_to_output = m.get_pattern_value_map(); auto exp_input = pattern_to_output.at(input); - auto constant = std::dynamic_pointer_cast(pattern_to_output.at(add_constant).get_node_shared_ptr()); + auto constant = std::dynamic_pointer_cast( + pattern_to_output.at(add_constant).get_node_shared_ptr()); if (!op::util::has_constant_value(constant, 1.0f)) { return false; } @@ -162,10 +165,11 @@ ngraph::pass::SwishFusionWithoutBeta::SwishFusionWithoutBeta() { auto div = std::make_shared(input, add); ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { - auto & pattern_to_output = m.get_pattern_value_map(); + auto& pattern_to_output = m.get_pattern_value_map(); auto exp_input = pattern_to_output.at(input); - auto constant = std::dynamic_pointer_cast(pattern_to_output.at(add_constant).get_node_shared_ptr()); + auto constant = std::dynamic_pointer_cast( + pattern_to_output.at(add_constant).get_node_shared_ptr()); if (!op::util::has_constant_value(constant, 1.0f)) { return false; } @@ -178,7 +182,7 @@ ngraph::pass::SwishFusionWithoutBeta::SwishFusionWithoutBeta() { pattern_to_output.at(add_constant).get_node_shared_ptr(), pattern_to_output.at(add).get_node_shared_ptr(), pattern_to_output.at(div).get_node_shared_ptr()}, - swish); + swish); ngraph::replace_node(m.get_match_root(), swish); return true; }; diff --git a/src/common/transformations/src/transformations/common_optimizations/transpose_reshape_elimination_for_matmul.cpp b/src/common/transformations/src/transformations/common_optimizations/transpose_reshape_elimination_for_matmul.cpp index 1ac962c7abf..47865bb1dd2 100644 --- a/src/common/transformations/src/transformations/common_optimizations/transpose_reshape_elimination_for_matmul.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/transpose_reshape_elimination_for_matmul.cpp @@ -7,11 +7,11 @@ #include #include -#include "ngraph/opsets/opset1.hpp" -#include "ngraph/rt_info.hpp" -#include "ngraph/pattern/op/wrap_type.hpp" -#include "ngraph/validation_util.hpp" #include "itt.hpp" +#include "ngraph/opsets/opset1.hpp" +#include "ngraph/pattern/op/wrap_type.hpp" +#include "ngraph/rt_info.hpp" +#include "ngraph/validation_util.hpp" namespace { /// \brief Check for correct Transpose orders which are before and after MatMul. Second Transpose must be back for @@ -23,7 +23,9 @@ namespace { /// /// \return True - Transposes have right orders, otherwise, Transposes have incorrect order for transformation /// -bool check_transposes(const std::vector& before_order, const std::vector& after_order, const bool transposed_b) { +bool check_transposes(const std::vector& before_order, + const std::vector& after_order, + const bool transposed_b) { const size_t rank = before_order.size(); if (rank < 3) return false; @@ -77,10 +79,12 @@ bool check_transposes(const std::vector& before_order, const std::vecto /// \param new_shape New shape for Reshape /// \param transposed_b true - second MatMul input is transposed, otherwise, it's not transposed /// -/// \return True - Reshape has right new shape for reshaping, otherwise, Reshape has incorrect new shape for transformation +/// \return True - Reshape has right new shape for reshaping, otherwise, Reshape has incorrect new shape for +/// transformation /// bool check_input_reshape(const std::shared_ptr& reshape, - const std::vector& new_shape, const bool transposed_b) { + const std::vector& new_shape, + const bool transposed_b) { const auto input_shape = reshape->get_input_shape(0); const size_t input_rank = input_shape.size(); const size_t output_rank = reshape->get_output_shape(0).size(); @@ -89,12 +93,12 @@ bool check_input_reshape(const std::shared_ptr& reshape if (transposed_b) { const int64_t k = input_shape.back(); - const int64_t new_n = ov::shape_size(input_shape) / k; + const int64_t new_n = ov::shape_size(input_shape) / k; if (new_shape != std::vector{new_n, k}) return false; } else { const int64_t k = input_shape.front(); - const int64_t new_n = ov::shape_size(input_shape) / k; + const int64_t new_n = ov::shape_size(input_shape) / k; if (new_shape != std::vector{k, -1} && new_shape != std::vector{k, new_n}) return false; } @@ -107,61 +111,75 @@ NGRAPH_RTTI_DEFINITION(ngraph::pass::TransposeReshapeEliminationForMatmul, "Tran ngraph::pass::TransposeReshapeEliminationForMatmul::TransposeReshapeEliminationForMatmul() { MATCHER_SCOPE(TransposeReshapeEliminationForMatmul); - auto input_1_pattern = ngraph::pattern::any_input([] (const Output& node) -> bool { - const auto& shape = node.get_partial_shape(); - const auto& rank = shape.rank(); - return rank.is_static() && rank.get_length() == 2 && shape.is_static(); - }); - auto input_2_pattern = ngraph::pattern::any_input([] (const Output& node) -> bool { - return node.get_partial_shape().is_static(); - }); + auto input_1_pattern = ngraph::pattern::any_input([](const Output& node) -> bool { + const auto& shape = node.get_partial_shape(); + const auto& rank = shape.rank(); + return rank.is_static() && rank.get_length() == 2 && shape.is_static(); + }); + auto input_2_pattern = ngraph::pattern::any_input([](const Output& node) -> bool { + return node.get_partial_shape().is_static(); + }); auto const_transpose_before_pattern = ngraph::pattern::wrap_type(); - auto transpose_before_pattern = ngraph::pattern::wrap_type({input_2_pattern, const_transpose_before_pattern}); + auto transpose_before_pattern = + ngraph::pattern::wrap_type({input_2_pattern, const_transpose_before_pattern}); auto const_reshape_before_pattern = ngraph::pattern::wrap_type(); - auto reshape_before_pattern = ngraph::pattern::wrap_type({transpose_before_pattern, const_reshape_before_pattern}); + auto reshape_before_pattern = + ngraph::pattern::wrap_type({transpose_before_pattern, const_reshape_before_pattern}); auto matmul_pattern = ngraph::pattern::wrap_type({input_1_pattern, reshape_before_pattern}); auto const_reshape_after_pattern = ngraph::pattern::wrap_type(); - auto reshape_after_pattern = ngraph::pattern::wrap_type({matmul_pattern, const_reshape_after_pattern}); + auto reshape_after_pattern = + ngraph::pattern::wrap_type({matmul_pattern, const_reshape_after_pattern}); auto const_transpose_after_pattern = ngraph::pattern::wrap_type(); - auto transpose_after_pattern = ngraph::pattern::wrap_type({reshape_after_pattern, const_transpose_after_pattern}); + auto transpose_after_pattern = + ngraph::pattern::wrap_type({reshape_after_pattern, const_transpose_after_pattern}); ngraph::matcher_pass_callback callback = [=](pattern::Matcher& m) { const auto& pattern_value_map = m.get_pattern_value_map(); const auto& input_1 = pattern_value_map.at(input_1_pattern); const auto& input_2 = pattern_value_map.at(input_2_pattern); - auto matmul = std::dynamic_pointer_cast(pattern_value_map.at(matmul_pattern).get_node_shared_ptr()); + auto matmul = + std::dynamic_pointer_cast(pattern_value_map.at(matmul_pattern).get_node_shared_ptr()); if (!matmul) return false; const bool transposed_a = matmul->get_transpose_a(); const bool transposed_b = matmul->get_transpose_b(); - auto reshape_before = std::dynamic_pointer_cast(pattern_value_map.at(reshape_before_pattern).get_node_shared_ptr()); - auto reshape_after = std::dynamic_pointer_cast(pattern_value_map.at(reshape_after_pattern).get_node_shared_ptr()); + auto reshape_before = std::dynamic_pointer_cast( + pattern_value_map.at(reshape_before_pattern).get_node_shared_ptr()); + auto reshape_after = std::dynamic_pointer_cast( + pattern_value_map.at(reshape_after_pattern).get_node_shared_ptr()); auto reshape_before_constant = std::dynamic_pointer_cast( - pattern_value_map.at(const_reshape_before_pattern).get_node_shared_ptr()); + pattern_value_map.at(const_reshape_before_pattern).get_node_shared_ptr()); if (!reshape_before || !reshape_after || !reshape_before_constant) return false; if (!check_input_reshape(reshape_before, reshape_before_constant->cast_vector(), transposed_b)) return false; // check transpose order before and after matmul - auto transpose_before = std::dynamic_pointer_cast(pattern_value_map.at(transpose_before_pattern).get_node_shared_ptr()); - auto transpose_after = std::dynamic_pointer_cast(pattern_value_map.at(transpose_after_pattern).get_node_shared_ptr()); - if (!transpose_before || !transpose_after) return false; + auto transpose_before = std::dynamic_pointer_cast( + pattern_value_map.at(transpose_before_pattern).get_node_shared_ptr()); + auto transpose_after = std::dynamic_pointer_cast( + pattern_value_map.at(transpose_after_pattern).get_node_shared_ptr()); + if (!transpose_before || !transpose_after) + return false; - auto transpose_before_constant = std::dynamic_pointer_cast(transpose_before->get_input_node_shared_ptr(1)); - auto transpose_after_constant = std::dynamic_pointer_cast(transpose_after->get_input_node_shared_ptr(1)); - if (!transpose_before_constant || !transpose_after_constant) return false; + auto transpose_before_constant = + std::dynamic_pointer_cast(transpose_before->get_input_node_shared_ptr(1)); + auto transpose_after_constant = + std::dynamic_pointer_cast(transpose_after->get_input_node_shared_ptr(1)); + if (!transpose_before_constant || !transpose_after_constant) + return false; auto transpose_before_order = transpose_before_constant->cast_vector(); auto transpose_after_order = transpose_after_constant->cast_vector(); - // need to check that input shape is correctly contracted and output shape is correctly unpacked using transposes + // need to check that input shape is correctly contracted and output shape is correctly unpacked using + // transposes if (!check_transposes(transpose_before_order, transpose_after_order, transposed_b)) return false; diff --git a/src/common/transformations/src/transformations/common_optimizations/transpose_sinking.cpp b/src/common/transformations/src/transformations/common_optimizations/transpose_sinking.cpp index 4d0e1bab44b..a9127811eb9 100644 --- a/src/common/transformations/src/transformations/common_optimizations/transpose_sinking.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/transpose_sinking.cpp @@ -2,18 +2,18 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/common_optimizations/transpose_sinking.hpp" -#include "transformations/utils/utils.hpp" #include -#include - #include #include -#include #include +#include #include +#include + +#include "itt.hpp" +#include "transformations/utils/utils.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::TransposeSinking, "TransposeSinking", 0); NGRAPH_RTTI_DEFINITION(ngraph::pass::TransposeConvert, "TransposeConvert", 0); @@ -26,8 +26,9 @@ using namespace ngraph; namespace { -std::shared_ptr get_reduced_order_constant(const std::shared_ptr& axes_const, - const std::shared_ptr& order_const) { +std::shared_ptr get_reduced_order_constant( + const std::shared_ptr& axes_const, + const std::shared_ptr& order_const) { auto order = order_const->cast_vector(); auto axes = axes_const->cast_vector(); @@ -44,11 +45,11 @@ std::shared_ptr get_reduced_order_constant(const std:: std::replace(order.begin(), order.end(), *lowest_greater_eq_i, i); std::replace(order_sorted.begin(), order_sorted.end(), *lowest_greater_eq_i, i); } - return std::make_shared( - ngraph::element::i64, ngraph::Shape{order.size()}, order); + return std::make_shared(ngraph::element::i64, ngraph::Shape{order.size()}, order); } -std::shared_ptr get_reversed_order_constant(const std::shared_ptr& order_const) { +std::shared_ptr get_reversed_order_constant( + const std::shared_ptr& order_const) { const auto& order = order_const->cast_vector(); const auto& rank = order.size(); const auto& default_order = ngraph::get_default_order(rank); @@ -56,34 +57,35 @@ std::shared_ptr get_reversed_order_constant(const std: for (size_t i = 0; i < rank; ++i) reverse_order[order[i]] = default_order[i]; - return std::make_shared( - ngraph::element::i64, ngraph::Shape{reverse_order.size()}, reverse_order); + return std::make_shared(ngraph::element::i64, + ngraph::Shape{reverse_order.size()}, + reverse_order); } -} // namespace +} // namespace ngraph::pass::TransposeEltwise::TransposeEltwise() { MATCHER_SCOPE(TransposeEltwise); auto eltwise_data_input_p = pattern::any_input(); auto eltwise_const_input_p = pattern::wrap_type(); - auto eltwise_p = pattern::wrap_type({eltwise_data_input_p, eltwise_const_input_p}, - [](const Output & output) { + auto eltwise_p = pattern::wrap_type( + {eltwise_data_input_p, eltwise_const_input_p}, + [](const Output& output) { return ov::is_preprocesing_node(output.get_node_shared_ptr()); - }); - auto transpose_p = pattern::wrap_type({eltwise_p, - pattern::wrap_type()}, - pattern::consumers_count(1)); + }); + auto transpose_p = pattern::wrap_type({eltwise_p, pattern::wrap_type()}, + pattern::consumers_count(1)); - auto callback = [=](ngraph::pattern::Matcher &m) { - const auto &pattern_to_output = m.get_pattern_value_map(); + auto callback = [=](ngraph::pattern::Matcher& m) { + const auto& pattern_to_output = m.get_pattern_value_map(); auto eltwise = pattern_to_output.at(eltwise_p).get_node_shared_ptr(); auto eltwise_const_input = pattern_to_output.at(eltwise_const_input_p); auto eltwise_data_input = pattern_to_output.at(eltwise_data_input_p); auto transpose = pattern_to_output.at(transpose_p).get_node_shared_ptr(); - const auto & order_size = transpose->get_input_shape(1).at(0); - const auto & shape = eltwise_const_input.get_shape(); + const auto& order_size = transpose->get_input_shape(1).at(0); + const auto& shape = eltwise_const_input.get_shape(); if (shape.size() != order_size && ov::shape_size(shape) != 1) { // TODO: temporary restrictions return false; @@ -113,13 +115,13 @@ ngraph::pass::TransposeEltwise::TransposeEltwise() { ngraph::pass::TransposeConvert::TransposeConvert() { MATCHER_SCOPE(TransposeConvert); - auto transpose_label = pattern::wrap_type({pattern::any_input(), - pattern::wrap_type()}, - pattern::consumers_count(1)); + auto transpose_label = + pattern::wrap_type({pattern::any_input(), pattern::wrap_type()}, + pattern::consumers_count(1)); auto convert_label = pattern::wrap_type({transpose_label}); - matcher_pass_callback matcher_pass_callback = [=](ngraph::pattern::Matcher &m) { - const auto &pattern_to_output = m.get_pattern_value_map(); + matcher_pass_callback matcher_pass_callback = [=](ngraph::pattern::Matcher& m) { + const auto& pattern_to_output = m.get_pattern_value_map(); auto transpose = pattern_to_output.at(transpose_label).get_node_shared_ptr(); auto convert = pattern_to_output.at(convert_label).get_node_shared_ptr(); @@ -140,12 +142,15 @@ ngraph::pass::TransposeConvert::TransposeConvert() { ngraph::pass::TransposeReduction::TransposeReduction() { MATCHER_SCOPE(TransposeReduction); - auto transpose_label = pattern::wrap_type({pattern::any_input(), pattern::wrap_type()}, pattern::consumers_count(1)); - auto reduce_or_squeeze_label = pattern::wrap_type( + auto transpose_label = + pattern::wrap_type({pattern::any_input(), pattern::wrap_type()}, + pattern::consumers_count(1)); + auto reduce_or_squeeze_label = + pattern::wrap_type( {transpose_label, pattern::wrap_type()}); - ngraph::matcher_pass_callback matcher_pass_callback = [=](ngraph::pattern::Matcher &m) { - const auto &pattern_to_output = m.get_pattern_value_map(); + ngraph::matcher_pass_callback matcher_pass_callback = [=](ngraph::pattern::Matcher& m) { + const auto& pattern_to_output = m.get_pattern_value_map(); auto transpose = pattern_to_output.at(transpose_label).get_node_shared_ptr(); auto reduction = pattern_to_output.at(reduce_or_squeeze_label).get_node_shared_ptr(); @@ -155,24 +160,30 @@ ngraph::pass::TransposeReduction::TransposeReduction() { if (!transpose || !(arithmetic_reduce || logical_reduce || squeeze)) return false; - bool keep_dims = false; // squeeze always reduces number of output dimensions + bool keep_dims = false; // squeeze always reduces number of output dimensions if (logical_reduce) keep_dims = logical_reduce->get_keep_dims(); else if (arithmetic_reduce) keep_dims = arithmetic_reduce->get_keep_dims(); - auto transpose_order = std::dynamic_pointer_cast(transpose->get_input_node_shared_ptr(1)); - auto reduction_axes = std::dynamic_pointer_cast(reduction->get_input_node_shared_ptr(1)); + auto transpose_order = + std::dynamic_pointer_cast(transpose->get_input_node_shared_ptr(1)); + auto reduction_axes = + std::dynamic_pointer_cast(reduction->get_input_node_shared_ptr(1)); if (!transpose_order || !reduction_axes) return false; - const auto& non_negative_axes = ngraph::normalize_axes( - reduction->get_friendly_name(), reduction_axes->cast_vector(), reduction->get_input_partial_shape(0).rank()); - reduction_axes = ngraph::opset6::Constant::create(ngraph::element::i64, {non_negative_axes.size()}, non_negative_axes); + const auto& non_negative_axes = ngraph::normalize_axes(reduction->get_friendly_name(), + reduction_axes->cast_vector(), + reduction->get_input_partial_shape(0).rank()); + reduction_axes = + ngraph::opset6::Constant::create(ngraph::element::i64, {non_negative_axes.size()}, non_negative_axes); ngraph::NodeVector new_ops; auto new_axes = ngraph::op::util::make_try_fold( - transpose_order, reduction_axes, ngraph::opset6::Constant::create(ngraph::element::i64, {}, {0})); + transpose_order, + reduction_axes, + ngraph::opset6::Constant::create(ngraph::element::i64, {}, {0})); new_ops.push_back(new_axes); auto new_reduce = reduction->clone_with_new_inputs({transpose->input_value(0), new_axes}); new_ops.push_back(new_reduce); @@ -199,22 +210,28 @@ ngraph::pass::TransposeReduction::TransposeReduction() { ngraph::pass::TransposeFQReduction::TransposeFQReduction() { MATCHER_SCOPE(TransposeFQReduction); - auto transpose_label = pattern::wrap_type({pattern::any_input(), pattern::wrap_type()}); - auto fq_label = pattern::wrap_type( - {transpose_label, pattern::any_input(pattern::has_static_rank()), pattern::any_input(pattern::has_static_rank()), - pattern::any_input(pattern::has_static_rank()), pattern::any_input(pattern::has_static_rank())}); - auto reduce_or_squeeze_label = pattern::wrap_type( + auto transpose_label = + pattern::wrap_type({pattern::any_input(), pattern::wrap_type()}); + auto fq_label = pattern::wrap_type({transpose_label, + pattern::any_input(pattern::has_static_rank()), + pattern::any_input(pattern::has_static_rank()), + pattern::any_input(pattern::has_static_rank()), + pattern::any_input(pattern::has_static_rank())}); + auto reduce_or_squeeze_label = + pattern::wrap_type( {fq_label, pattern::wrap_type()}); - ngraph::matcher_pass_callback matcher_pass_callback = [=](ngraph::pattern::Matcher &m) { - auto &pattern_to_output = m.get_pattern_value_map(); + ngraph::matcher_pass_callback matcher_pass_callback = [=](ngraph::pattern::Matcher& m) { + auto& pattern_to_output = m.get_pattern_value_map(); auto transpose = pattern_to_output.at(transpose_label).get_node_shared_ptr(); - if (!transpose) return false; + if (!transpose) + return false; auto transpose_order = std::dynamic_pointer_cast(transpose->get_input_node_shared_ptr(1)); auto fq = pattern_to_output.at(fq_label).get_node_shared_ptr(); - if (!transpose_order || !fq) return false; + if (!transpose_order || !fq) + return false; ngraph::NodeVector new_ops; @@ -261,8 +278,10 @@ ngraph::pass::TransposeFQReduction::TransposeFQReduction() { ngraph::pass::TransposeFuse::TransposeFuse() { MATCHER_SCOPE(TransposeFuse); - auto transpose_1 = pattern::wrap_type({ pattern::any_input(), pattern::wrap_type() }, pattern::consumers_count(1)); - auto transpose_2 = pattern::wrap_type({ transpose_1, pattern::wrap_type() }); + auto transpose_1 = + pattern::wrap_type({pattern::any_input(), pattern::wrap_type()}, + pattern::consumers_count(1)); + auto transpose_2 = pattern::wrap_type({transpose_1, pattern::wrap_type()}); ngraph::matcher_pass_callback matcher_pass_callback = [=](ngraph::pattern::Matcher& m) { const auto& pattern_to_output = m.get_pattern_value_map(); @@ -271,8 +290,10 @@ ngraph::pass::TransposeFuse::TransposeFuse() { auto transpose2 = pattern_to_output.at(transpose_2).get_node_shared_ptr(); auto input = transpose1->input_value(0); - auto transpose1_order = std::dynamic_pointer_cast(transpose1->get_input_node_shared_ptr(1)); - auto transpose2_order = std::dynamic_pointer_cast(transpose2->get_input_node_shared_ptr(1)); + auto transpose1_order = + std::dynamic_pointer_cast(transpose1->get_input_node_shared_ptr(1)); + auto transpose2_order = + std::dynamic_pointer_cast(transpose2->get_input_node_shared_ptr(1)); if (!transpose1_order || !transpose2_order) return false; @@ -295,7 +316,7 @@ ngraph::pass::TransposeFuse::TransposeFuse() { auto new_transpose = register_new_node(input, new_order); new_transpose->set_friendly_name(m.get_match_root()->get_friendly_name()); - ngraph::copy_runtime_info({ transpose1, transpose2 }, new_transpose); + ngraph::copy_runtime_info({transpose1, transpose2}, new_transpose); ngraph::replace_node(m.get_match_root(), new_transpose); } diff --git a/src/common/transformations/src/transformations/common_optimizations/transpose_to_reshape.cpp b/src/common/transformations/src/transformations/common_optimizations/transpose_to_reshape.cpp index 94e2a5129ca..06a54f6e657 100644 --- a/src/common/transformations/src/transformations/common_optimizations/transpose_to_reshape.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/transpose_to_reshape.cpp @@ -2,17 +2,17 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/common_optimizations/transpose_to_reshape.hpp" -#include "transformations/utils/utils.hpp" #include +#include +#include +#include +#include #include -#include -#include -#include -#include +#include "itt.hpp" +#include "transformations/utils/utils.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::TransposeToReshape, "TransposeToReshape", 0); @@ -22,7 +22,7 @@ ngraph::pass::TransposeToReshape::TransposeToReshape() { MATCHER_SCOPE(TransposeToReshape); auto transpose_label = pattern::wrap_type( - { pattern::any_input(pattern::has_static_rank()), pattern::wrap_type() }); + {pattern::any_input(pattern::has_static_rank()), pattern::wrap_type()}); ngraph::matcher_pass_callback matcher_pass_callback = [=](ngraph::pattern::Matcher& m) { auto transpose = m.get_match_root(); auto data = transpose->input_value(0); @@ -57,14 +57,14 @@ ngraph::pass::TransposeToReshape::TransposeToReshape() { std::vector dims; for (size_t i = 0; i < input_shape_rank; ++i) { if (order_value[i] != static_cast(i)) { - dims.push_back({ input_shape[order_value[i]], i }); + dims.push_back({input_shape[order_value[i]], i}); } } // If number of dimensions != 1 to move equal to 0 we can remove this Transpose if (count_if(dims.begin(), dims.end(), [](const DimensionToPosition& item) { - return !(item.dim.is_static() && item.dim.get_length() == 1); - }) == 0) { + return !(item.dim.is_static() && item.dim.get_length() == 1); + }) == 0) { return replace_output_update_name(transpose->output(0), transpose->input_value(0)); } @@ -82,19 +82,19 @@ ngraph::pass::TransposeToReshape::TransposeToReshape() { NodeVector new_ops; if (count_if(dims.begin(), dims.end(), [](const DimensionToPosition& item) { - return item.dim.is_dynamic(); - }) < 2) { + return item.dim.is_dynamic(); + }) < 2) { std::vector reshape_value(input_shape_rank, 0); for (const auto& item : dims) { reshape_value[item.pos] = item.dim.is_dynamic() ? -1 : item.dim.get_length(); } - reshape_dim = - opset3::Constant::create(element::i64, Shape{ reshape_value.size() }, reshape_value); + reshape_dim = opset3::Constant::create(element::i64, Shape{reshape_value.size()}, reshape_value); } else { auto shape_of = std::make_shared(data); new_ops.push_back(shape_of); - reshape_dim = std::make_shared( - shape_of, order, opset3::Constant::create(element::i64, Shape{ 1 }, { 0 })); + reshape_dim = std::make_shared(shape_of, + order, + opset3::Constant::create(element::i64, Shape{1}, {0})); new_ops.push_back(reshape_dim.get_node_shared_ptr()); } diff --git a/src/common/transformations/src/transformations/common_optimizations/weights_dequantize_to_fake_quantize.cpp b/src/common/transformations/src/transformations/common_optimizations/weights_dequantize_to_fake_quantize.cpp index e85e3d7c1e1..b30fd3f89f5 100644 --- a/src/common/transformations/src/transformations/common_optimizations/weights_dequantize_to_fake_quantize.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/weights_dequantize_to_fake_quantize.cpp @@ -3,12 +3,13 @@ // #include -#include #include +#include #include -#include #include #include +#include + #include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::WeightsDequantizeToFakeQuantize, "WeightsDequantizeToFakeQuantize", 0); @@ -27,34 +28,42 @@ ngraph::pass::WeightsDequantizeToFakeQuantize::WeightsDequantizeToFakeQuantize() const auto mul = ngraph::pattern::wrap_type({sub_or_convert, mul_c}); ngraph::matcher_pass_callback callback; - callback = [=](ngraph::pattern::Matcher &m) { - const auto &pattern_map = m.get_pattern_map(); + callback = [=](ngraph::pattern::Matcher& m) { + const auto& pattern_map = m.get_pattern_map(); - const auto &weights_node = ov::as_type_ptr(pattern_map.at(weights)); - const auto &convert_node = pattern_map.at(convert); - const auto &multiply_node = pattern_map.at(mul); - const auto &scale_node = pattern_map.at(mul_c); + const auto& weights_node = ov::as_type_ptr(pattern_map.at(weights)); + const auto& convert_node = pattern_map.at(convert); + const auto& multiply_node = pattern_map.at(mul); + const auto& scale_node = pattern_map.at(mul_c); if (!weights_node || !convert_node || !multiply_node || !scale_node) { return false; } - const auto *data = weights_node->get_data_ptr(); + const auto* data = weights_node->get_data_ptr(); const int8_t weights_minimum = *std::min_element(data, data + shape_size(weights_node->get_shape())); int64_t levels = (weights_minimum == static_cast(-128)) ? 256 : 255; int64_t in_low = -(levels / 2), in_high = levels + in_low - 1; - const auto &input_low = opset6::Constant::create(convert_node->get_element_type(), {}, {in_low}); - const auto &input_high = opset6::Constant::create(convert_node->get_element_type(), {}, {in_high}); + const auto& input_low = opset6::Constant::create(convert_node->get_element_type(), {}, {in_low}); + const auto& input_high = opset6::Constant::create(convert_node->get_element_type(), {}, {in_high}); - auto &zero_point = pattern_map.count(sub_c) ? pattern_map.at(sub_c) : opset6::Constant::create(convert_node->get_element_type(), {}, {0}); + auto& zero_point = pattern_map.count(sub_c) + ? pattern_map.at(sub_c) + : opset6::Constant::create(convert_node->get_element_type(), {}, {0}); - const auto &output_low = op::util::eltwise_fold( - op::util::eltwise_fold(input_low, zero_point), scale_node); - const auto &output_high = op::util::eltwise_fold( - op::util::eltwise_fold(input_high, zero_point), scale_node); + const auto& output_low = + op::util::eltwise_fold(op::util::eltwise_fold(input_low, zero_point), + scale_node); + const auto& output_high = + op::util::eltwise_fold(op::util::eltwise_fold(input_high, zero_point), + scale_node); - auto fq = std::make_shared( - convert_node, input_low, input_high, output_low, output_high, levels); + auto fq = std::make_shared(convert_node, + input_low, + input_high, + output_low, + output_high, + levels); NodeVector nodes_to_copy_RT_info_from{multiply_node, scale_node, zero_point}; if (pattern_map.count(sub)) diff --git a/src/common/transformations/src/transformations/common_optimizations/wrap_interpolate_into_transposes.cpp b/src/common/transformations/src/transformations/common_optimizations/wrap_interpolate_into_transposes.cpp index e57078c7aab..0f07340841d 100644 --- a/src/common/transformations/src/transformations/common_optimizations/wrap_interpolate_into_transposes.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/wrap_interpolate_into_transposes.cpp @@ -2,24 +2,25 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/common_optimizations/wrap_interpolate_into_transposes.hpp" #include #include +#include #include -#include +#include +#include #include +#include #include #include -#include -#include -#include +#include "itt.hpp" namespace { std::vector reverse_permutation(const std::vector& perm) { - if (perm.empty()) return {}; + if (perm.empty()) + return {}; std::vector result(perm.size()); for (int64_t i = 0; i < static_cast(perm.size()); ++i) { @@ -48,7 +49,7 @@ std::vector build_new_axes(size_t num_of_axes, size_t rank) { std::iota(result.begin(), result.end(), static_cast(rank - num_of_axes)); return result; } -} // namespace +} // namespace NGRAPH_RTTI_DEFINITION(ngraph::pass::WrapInterpolateIntoTransposes, "WrapInterpolateIntoTransposes", 0); @@ -57,18 +58,25 @@ ngraph::pass::WrapInterpolateIntoTransposes::WrapInterpolateIntoTransposes() { auto interpolate_pattern = ov::pass::pattern::wrap_type(); ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { auto interpolate = std::dynamic_pointer_cast(m.get_match_root()); - if (!interpolate || interpolate->get_input_partial_shape(0).rank().is_dynamic() || interpolate->inputs().size() != 4) return false; + if (!interpolate || interpolate->get_input_partial_shape(0).rank().is_dynamic() || + interpolate->inputs().size() != 4) + return false; int64_t input_rank = interpolate->get_input_partial_shape(0).rank().get_length(); // If the input rank is equal to 1 or 2, then such Interpolate is supported by MKLDNN. - if (input_rank < 3) return false; + if (input_rank < 3) + return false; - auto axes_node = std::dynamic_pointer_cast(interpolate->input_value(3).get_node_shared_ptr()); - if (!axes_node) return false; + auto axes_node = + std::dynamic_pointer_cast(interpolate->input_value(3).get_node_shared_ptr()); + if (!axes_node) + return false; const auto axes = axes_node->cast_vector(); if (static_cast(axes.size()) > input_rank - 2 || - std::all_of(axes.begin(), axes.end(), [](int64_t axis){ return axis != 0 && axis != 1; })) { + std::all_of(axes.begin(), axes.end(), [](int64_t axis) { + return axis != 0 && axis != 1; + })) { return false; } @@ -76,15 +84,23 @@ ngraph::pass::WrapInterpolateIntoTransposes::WrapInterpolateIntoTransposes() { const auto last_perm = reverse_permutation(first_perm); auto first_transpose_perm = ov::opset8::Constant::create(element::i64, {first_perm.size()}, first_perm); - auto first_transpose = std::make_shared(interpolate->input_value(0), first_transpose_perm); + auto first_transpose = + std::make_shared(interpolate->input_value(0), first_transpose_perm); auto new_axes = build_new_axes(axes.size(), input_rank); auto new_axes_node = ov::opset8::Constant::create(element::i64, {new_axes.size()}, new_axes); - auto new_interpolate = interpolate->clone_with_new_inputs({first_transpose, interpolate->input_value(1), interpolate->input_value(2), new_axes_node}); + auto new_interpolate = interpolate->clone_with_new_inputs( + {first_transpose, interpolate->input_value(1), interpolate->input_value(2), new_axes_node}); auto last_transpose_perm = ov::opset8::Constant::create(element::i64, {last_perm.size()}, last_perm); auto last_transpose = std::make_shared(new_interpolate, last_transpose_perm); last_transpose->set_friendly_name(interpolate->get_friendly_name()); - copy_runtime_info(interpolate, {first_transpose_perm, first_transpose, new_axes_node, new_interpolate, last_transpose_perm, last_transpose}); + copy_runtime_info(interpolate, + {first_transpose_perm, + first_transpose, + new_axes_node, + new_interpolate, + last_transpose_perm, + last_transpose}); replace_node(interpolate, last_transpose); return true; diff --git a/src/common/transformations/src/transformations/control_flow/unroll_if.cpp b/src/common/transformations/src/transformations/control_flow/unroll_if.cpp index 7ee8fe2ab82..5e75607e71f 100644 --- a/src/common/transformations/src/transformations/control_flow/unroll_if.cpp +++ b/src/common/transformations/src/transformations/control_flow/unroll_if.cpp @@ -47,11 +47,12 @@ bool ngraph::pass::UnrollIf::run_on_model(const std::shared_ptroutput(output_desc->m_output_index))); + in_value.get_tensor().set_name( + op::util::create_ie_output_name(if_node->output(output_desc->m_output_index))); NGRAPH_SUPPRESS_DEPRECATED_END - for (const auto& input : if_node->output(output_desc->m_output_index).get_target_inputs()) { - input.replace_source_output(result->get_input_source_output(0)); - } + for (const auto& input : if_node->output(output_desc->m_output_index).get_target_inputs()) { + input.replace_source_output(result->get_input_source_output(0)); + } } is_applicable = true; f->add_sinks(body->get_sinks()); diff --git a/src/common/transformations/src/transformations/control_flow/unroll_tensor_iterator.cpp b/src/common/transformations/src/transformations/control_flow/unroll_tensor_iterator.cpp index f25db972d67..8176f544a2b 100644 --- a/src/common/transformations/src/transformations/control_flow/unroll_tensor_iterator.cpp +++ b/src/common/transformations/src/transformations/control_flow/unroll_tensor_iterator.cpp @@ -2,17 +2,17 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/control_flow/unroll_tensor_iterator.hpp" -#include "transformations/utils/utils.hpp" #include -#include - #include #include #include #include +#include + +#include "itt.hpp" +#include "transformations/utils/utils.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::UnrollTensorIterator, "UnrollTensorIterator", 0); @@ -24,7 +24,7 @@ bool ngraph::pass::UnrollTensorIterator::run_on_model(const std::shared_ptrget_function(); + const auto& function = sub_graph_op->get_function(); int64_t num_iter = sub_graph_op->get_num_iterations(); // negative value means inconsistent TI @@ -37,7 +37,7 @@ bool ngraph::pass::UnrollTensorIterator::run_on_model(const std::shared_ptr> body_functions(num_iter); for (int64_t idx = 0; idx < num_iter; ++idx) { body_functions[idx] = clone_function(*function); - for (auto &node : body_functions[idx]->get_ops()) { + for (auto& node : body_functions[idx]->get_ops()) { node->set_friendly_name(sub_graph_op->get_friendly_name() + "/" + std::to_string(idx + 1) + "/" + node->get_friendly_name()); copy_runtime_info(sub_graph_op, node); @@ -45,9 +45,9 @@ bool ngraph::pass::UnrollTensorIterator::run_on_model(const std::shared_ptrget_input_descriptions()) { - if (const auto &input_desc = std::dynamic_pointer_cast( - desc)) { + for (const auto& desc : sub_graph_op->get_input_descriptions()) { + if (const auto& input_desc = + std::dynamic_pointer_cast(desc)) { // Connect the sliced input (layer before the input) to the Split layer and connect // the corresponding Split output to the corresponding copy of the body. // If the number of iterations is 1, then the Split is not needed. @@ -63,23 +63,23 @@ bool ngraph::pass::UnrollTensorIterator::run_on_model(const std::shared_ptr 0 ? j : num_iter - j - 1; const auto& param = body_functions[j]->get_parameters()[input_desc->m_body_parameter_index]; - for (auto &output : param->outputs()) { + for (auto& output : param->outputs()) { output.replace(split->output(idx)); } } } else { // connect to the body const auto& param = body_functions[0]->get_parameters()[input_desc->m_body_parameter_index]; - for (auto &output : param->outputs()) { + for (auto& output : param->outputs()) { output.replace(in_data); } } - } else if (const auto &merged_desc = std::dynamic_pointer_cast( - desc)) { + } else if (const auto& merged_desc = + std::dynamic_pointer_cast(desc)) { // Connect the input to the corresponding copy of the body. auto in_data = sub_graph_op->input_values()[merged_desc->m_input_index]; const auto& param = body_functions[0]->get_parameters()[merged_desc->m_body_parameter_index]; - for (auto &output : param->outputs()) { + for (auto& output : param->outputs()) { output.replace(in_data); } @@ -87,17 +87,17 @@ bool ngraph::pass::UnrollTensorIterator::run_on_model(const std::shared_ptrget_parameters()[merged_desc->m_body_parameter_index]; const auto& prev_val = body_functions[j - 1]->get_results()[merged_desc->m_body_value_index]; - for (auto &output : cur_param->outputs()) { + for (auto& output : cur_param->outputs()) { output.replace(prev_val->get_input_source_output(0)); } } - } else if (const auto &invariant_desc = std::dynamic_pointer_cast( - desc)) { + } else if (const auto& invariant_desc = + std::dynamic_pointer_cast(desc)) { // Connect the input to the corresponding copy of the body. auto in_data = sub_graph_op->input_values()[invariant_desc->m_input_index]; for (int64_t j = 0; j < num_iter; j++) { auto param = body_functions[j]->get_parameters()[invariant_desc->m_body_parameter_index]; - for (auto &output : param->outputs()) { + for (auto& output : param->outputs()) { output.replace(in_data); } } @@ -108,9 +108,9 @@ bool ngraph::pass::UnrollTensorIterator::run_on_model(const std::shared_ptrget_output_descriptions()) { - if (const auto &concat_desc = std::dynamic_pointer_cast( - desc)) { + for (const auto& desc : sub_graph_op->get_output_descriptions()) { + if (const auto& concat_desc = + std::dynamic_pointer_cast(desc)) { if (!concat_desc) { return false; } @@ -126,7 +126,8 @@ bool ngraph::pass::UnrollTensorIterator::run_on_model(const std::shared_ptr 0 ? j : num_iter - j - 1; - std::shared_ptr result = body_functions[idx]->get_results()[concat_desc->m_body_value_index]; + std::shared_ptr result = + body_functions[idx]->get_results()[concat_desc->m_body_value_index]; auto input_to_res = result->get_input_source_output(0); to_concat[j] = input_to_res; } @@ -136,40 +137,41 @@ bool ngraph::pass::UnrollTensorIterator::run_on_model(const std::shared_ptroutput(0).get_tensor().set_name( - op::util::create_ie_output_name(sub_graph_op->output(concat_desc->m_output_index))); + op::util::create_ie_output_name(sub_graph_op->output(concat_desc->m_output_index))); NGRAPH_SUPPRESS_DEPRECATED_END // connect the Concat layer to the corresponding TI outputs - for (auto &input : sub_graph_op->output(concat_desc->m_output_index).get_target_inputs()) { + for (auto& input : sub_graph_op->output(concat_desc->m_output_index).get_target_inputs()) { input.replace_source_output(concat); } } else { // Connect outputs of the bodies to the corresponding TI outputs - std::shared_ptr result = body_functions[0]->get_results().at( - concat_desc->m_body_value_index); + std::shared_ptr result = + body_functions[0]->get_results().at(concat_desc->m_body_value_index); const auto& input_to_res = result->get_input_source_output(0); // set output name to Tensor to store it for ngraph to cnn conversion NGRAPH_SUPPRESS_DEPRECATED_START input_to_res.get_tensor().set_name( - op::util::create_ie_output_name(sub_graph_op->output(concat_desc->m_output_index))); + op::util::create_ie_output_name(sub_graph_op->output(concat_desc->m_output_index))); NGRAPH_SUPPRESS_DEPRECATED_END - for (auto &input : sub_graph_op->output(concat_desc->m_output_index).get_target_inputs()) { + for (auto& input : sub_graph_op->output(concat_desc->m_output_index).get_target_inputs()) { input.replace_source_output(input_to_res); } } - } else if (const auto &output_desc = std::dynamic_pointer_cast( - desc)) { + } else if (const auto& output_desc = + std::dynamic_pointer_cast(desc)) { // Connect outputs of the bodies to the corresponding TI outputs auto iter = output_desc->m_iteration; - iter = iter >= 0? iter: num_iter - 1; - std::shared_ptr result = body_functions[iter]->get_results()[output_desc->m_body_value_index]; + iter = iter >= 0 ? iter : num_iter - 1; + std::shared_ptr result = + body_functions[iter]->get_results()[output_desc->m_body_value_index]; const auto& in_value = result->input_value(0); // set output name to Tensor to store it for ngraph to cnn conversion NGRAPH_SUPPRESS_DEPRECATED_START in_value.get_tensor().set_name( - op::util::create_ie_output_name(sub_graph_op->output(output_desc->m_output_index))); + op::util::create_ie_output_name(sub_graph_op->output(output_desc->m_output_index))); NGRAPH_SUPPRESS_DEPRECATED_END - for (const auto &input : sub_graph_op->output(output_desc->m_output_index).get_target_inputs()) { + for (const auto& input : sub_graph_op->output(output_desc->m_output_index).get_target_inputs()) { input.replace_source_output(result->get_input_source_output(0)); } } else { @@ -184,24 +186,26 @@ bool ngraph::pass::UnrollTensorIterator::run_on_model(const std::shared_ptr(sub_graph_op); + const auto& loop = std::dynamic_pointer_cast(sub_graph_op); if (loop) { // 1. Check CurrentIteration Parameter is not connected to outer network bool need_to_remove_iteration_param = false; const auto cur_iter_idx = loop->get_special_body_ports().current_iteration_input_idx; if (cur_iter_idx >= 0) { - const auto &in_descs = loop->get_input_descriptions(); - need_to_remove_iteration_param = std::all_of(in_descs.begin(), in_descs.end(), - [cur_iter_idx](const std::shared_ptr &in_desc) { - return in_desc->m_body_parameter_index != static_cast(cur_iter_idx); - }); + const auto& in_descs = loop->get_input_descriptions(); + need_to_remove_iteration_param = + std::all_of(in_descs.begin(), + in_descs.end(), + [cur_iter_idx](const std::shared_ptr& in_desc) { + return in_desc->m_body_parameter_index != static_cast(cur_iter_idx); + }); } // 2. Replace CurrentIteration Parameter with a Constant for each copy of the body if (need_to_remove_iteration_param) { for (int64_t idx = 0; idx < num_iter; ++idx) { const auto iter_idx = loop->get_special_body_ports().current_iteration_input_idx; - const auto ¶m_to_delete = body_functions[idx]->get_parameters()[iter_idx]; + const auto& param_to_delete = body_functions[idx]->get_parameters()[iter_idx]; auto cur_iter_const = std::make_shared(ngraph::element::i64, Shape{}, idx); replace_node(param_to_delete, cur_iter_const); body_functions[idx]->remove_parameter(param_to_delete); diff --git a/src/common/transformations/src/transformations/disable_decompression_convert_constant_folding.cpp b/src/common/transformations/src/transformations/disable_decompression_convert_constant_folding.cpp index 3d5288f5ad0..3d5d60c5553 100644 --- a/src/common/transformations/src/transformations/disable_decompression_convert_constant_folding.cpp +++ b/src/common/transformations/src/transformations/disable_decompression_convert_constant_folding.cpp @@ -4,11 +4,11 @@ #include "transformations/disable_decompression_convert_constant_folding.hpp" +#include "itt.hpp" #include "openvino/opsets/opset8.hpp" #include "openvino/pass/pattern/op/wrap_type.hpp" -#include "transformations/rt_info/disable_constant_folding.hpp" #include "transformations/rt_info/decompression.hpp" -#include "itt.hpp" +#include "transformations/rt_info/disable_constant_folding.hpp" ov::pass::DisableDecompressionConvertConstantFolding::DisableDecompressionConvertConstantFolding() { MATCHER_SCOPE(DisableDecompressionConvertConstantFolding); diff --git a/src/common/transformations/src/transformations/low_precision/disable_convert_constant_folding_on_const_path.cpp b/src/common/transformations/src/transformations/low_precision/disable_convert_constant_folding_on_const_path.cpp index 7a346be7b51..7db3b639942 100644 --- a/src/common/transformations/src/transformations/low_precision/disable_convert_constant_folding_on_const_path.cpp +++ b/src/common/transformations/src/transformations/low_precision/disable_convert_constant_folding_on_const_path.cpp @@ -5,26 +5,27 @@ #include "transformations/low_precision/disable_convert_constant_folding_on_const_path.hpp" #include -#include -#include - #include #include -#include #include +#include #include +#include #include +#include using namespace ngraph; -NGRAPH_RTTI_DEFINITION(ngraph::pass::DisableConvertConstantFoldingOnConstPath, "DisableConvertConstantFoldingOnConstPath", 0); +NGRAPH_RTTI_DEFINITION(ngraph::pass::DisableConvertConstantFoldingOnConstPath, + "DisableConvertConstantFoldingOnConstPath", + 0); ngraph::pass::DisableConvertConstantFoldingOnConstPath::DisableConvertConstantFoldingOnConstPath( - const element::TypeVector & inputPrecisions) { + const element::TypeVector& inputPrecisions) { auto matcherData = ngraph::pattern::any_input(); - auto matcherConvert = ngraph::pattern::wrap_type({ matcherData }, pattern::consumers_count(1)); + auto matcherConvert = ngraph::pattern::wrap_type({matcherData}, pattern::consumers_count(1)); - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher & m) -> bool { + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) -> bool { const auto& opsMap = m.get_pattern_value_map(); const auto convert = opsMap.at(matcherConvert).get_node_shared_ptr(); diff --git a/src/common/transformations/src/transformations/op_conversions/batch_norm_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/batch_norm_decomposition.cpp index d9b6eab3c7a..22148b0b15b 100644 --- a/src/common/transformations/src/transformations/op_conversions/batch_norm_decomposition.cpp +++ b/src/common/transformations/src/transformations/op_conversions/batch_norm_decomposition.cpp @@ -2,18 +2,18 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/batch_norm_decomposition.hpp" #include -#include - #include #include -#include -#include #include +#include +#include #include +#include + +#include "itt.hpp" using namespace ngraph; @@ -21,23 +21,19 @@ NGRAPH_RTTI_DEFINITION(ngraph::pass::BatchNormDecomposition, "BatchNormDecomposi ngraph::pass::BatchNormDecomposition::BatchNormDecomposition() { MATCHER_SCOPE(BatchNormDecomposition); - auto bn_1 = pattern::wrap_type({ - pattern::any_input(pattern::has_static_shape()), - pattern::any_input(pattern::has_static_shape()), - pattern::any_input(pattern::has_static_rank()), - pattern::any_input(pattern::has_static_shape()), - pattern::any_input(pattern::has_static_shape()) - }); - auto bn_5 = pattern::wrap_type({ - pattern::any_input(pattern::has_static_rank()), - pattern::any_input(pattern::has_static_shape()), - pattern::any_input(pattern::has_static_shape()), - pattern::any_input(pattern::has_static_shape()), - pattern::any_input(pattern::has_static_shape()) - }); + auto bn_1 = pattern::wrap_type({pattern::any_input(pattern::has_static_shape()), + pattern::any_input(pattern::has_static_shape()), + pattern::any_input(pattern::has_static_rank()), + pattern::any_input(pattern::has_static_shape()), + pattern::any_input(pattern::has_static_shape())}); + auto bn_5 = pattern::wrap_type({pattern::any_input(pattern::has_static_rank()), + pattern::any_input(pattern::has_static_shape()), + pattern::any_input(pattern::has_static_shape()), + pattern::any_input(pattern::has_static_shape()), + pattern::any_input(pattern::has_static_shape())}); auto bn = std::make_shared(OutputVector{bn_1, bn_5}); - ngraph::matcher_pass_callback callback = [this](ngraph::pattern::Matcher &m) { + ngraph::matcher_pass_callback callback = [this](ngraph::pattern::Matcher& m) { auto m_bn = m.get_match_root(); Output m_input, m_gamma, m_beta, m_mean, m_var; double eps; @@ -75,19 +71,20 @@ ngraph::pass::BatchNormDecomposition::BatchNormDecomposition() { // create new shape [1, C, 1, 1, ...] const auto new_shape = std::make_shared(OutputVector{one, C_dim, tail_shape}, 0); - std::shared_ptr gamma_div_scale_aligned = std::make_shared(gamma_div_scale, new_shape, true); + std::shared_ptr gamma_div_scale_aligned = + std::make_shared(gamma_div_scale, new_shape, true); std::shared_ptr beta_aligned = std::make_shared(m_beta, new_shape, true); std::shared_ptr mean_aligned = std::make_shared(m_mean, new_shape, true); std::shared_ptr mean_negative = std::make_shared( mean_aligned, opset5::Constant::create(mean_aligned->get_output_element_type(0), Shape{}, {-1})); - if (auto constant = ov::get_constant_from_source(beta_aligned)) - beta_aligned = constant; - if (auto constant = ov::get_constant_from_source(mean_negative)) - mean_negative = constant; - if (auto constant = ov::get_constant_from_source(gamma_div_scale_aligned)) - gamma_div_scale_aligned = constant; + if (auto constant = ov::get_constant_from_source(beta_aligned)) + beta_aligned = constant; + if (auto constant = ov::get_constant_from_source(mean_negative)) + mean_negative = constant; + if (auto constant = ov::get_constant_from_source(gamma_div_scale_aligned)) + gamma_div_scale_aligned = constant; // input_sub_mean = input + mean * -1 auto input_sub_mean = register_new_node(m_input, mean_negative); @@ -98,8 +95,9 @@ ngraph::pass::BatchNormDecomposition::BatchNormDecomposition() { add->set_friendly_name(m_bn->get_friendly_name()); - copy_runtime_info(m_bn, {scale_add, scale, gamma_div_scale, gamma_div_scale_aligned, - beta_aligned, input_sub_mean, mul, add}); + copy_runtime_info( + m_bn, + {scale_add, scale, gamma_div_scale, gamma_div_scale_aligned, beta_aligned, input_sub_mean, mul, add}); replace_node(m_bn, add); @@ -108,4 +106,3 @@ ngraph::pass::BatchNormDecomposition::BatchNormDecomposition() { auto m = std::make_shared(bn, matcher_name); this->register_matcher(m, callback); } - diff --git a/src/common/transformations/src/transformations/op_conversions/bidirectional_sequences_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/bidirectional_sequences_decomposition.cpp index 8fc3b86669d..200a538f70f 100644 --- a/src/common/transformations/src/transformations/op_conversions/bidirectional_sequences_decomposition.cpp +++ b/src/common/transformations/src/transformations/op_conversions/bidirectional_sequences_decomposition.cpp @@ -2,18 +2,20 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/bidirectional_sequences_decomposition.hpp" #include - #include #include -#include #include +#include + +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::BidirectionalSequenceDecomposition, "BidirectionalSequenceDecomposition", 0); -NGRAPH_RTTI_DEFINITION(ngraph::pass::BidirectionalLSTMSequenceDecomposition, "BidirectionalLSTMSequenceDecomposition", 0); +NGRAPH_RTTI_DEFINITION(ngraph::pass::BidirectionalLSTMSequenceDecomposition, + "BidirectionalLSTMSequenceDecomposition", + 0); NGRAPH_RTTI_DEFINITION(ngraph::pass::BidirectionalGRUSequenceDecomposition, "BidirectionalGRUSequenceDecomposition", 0); NGRAPH_RTTI_DEFINITION(ngraph::pass::BidirectionalRNNSequenceDecomposition, "BidirectionalRNNSequenceDecomposition", 0); @@ -21,7 +23,7 @@ ngraph::pass::BidirectionalLSTMSequenceDecomposition::BidirectionalLSTMSequenceD MATCHER_SCOPE(BidirectionalLSTMSequenceDecomposition); auto lstm_sequence_ngraph = ngraph::pattern::wrap_type(); - ngraph::matcher_pass_callback callback = [this](pattern::Matcher &m) { + ngraph::matcher_pass_callback callback = [this](pattern::Matcher& m) { auto lstm_sequence = std::dynamic_pointer_cast(m.get_match_root()); if (!lstm_sequence || transformation_callback(lstm_sequence)) { return false; @@ -37,47 +39,51 @@ ngraph::pass::BidirectionalLSTMSequenceDecomposition::BidirectionalLSTMSequenceD auto W = std::make_shared(lstm_sequence->input_value(4), axis_0, 2); auto R = std::make_shared(lstm_sequence->input_value(5), axis_0, 2); auto B = std::make_shared(lstm_sequence->input_value(6), axis_0, 2); - auto lstm_sequence_forward = std::make_shared( - lstm_sequence->input_value(0), - H->output(0), - C->output(0), - lstm_sequence->input_value(3), - W->output(0), - R->output(0), - B->output(0), - lstm_sequence->get_hidden_size(), - ngraph::op::RecurrentSequenceDirection::FORWARD, - lstm_sequence->get_activations_alpha(), - lstm_sequence->get_activations_beta(), - lstm_sequence->get_activations(), - lstm_sequence->get_clip()); + auto lstm_sequence_forward = + std::make_shared(lstm_sequence->input_value(0), + H->output(0), + C->output(0), + lstm_sequence->input_value(3), + W->output(0), + R->output(0), + B->output(0), + lstm_sequence->get_hidden_size(), + ngraph::op::RecurrentSequenceDirection::FORWARD, + lstm_sequence->get_activations_alpha(), + lstm_sequence->get_activations_beta(), + lstm_sequence->get_activations(), + lstm_sequence->get_clip()); - auto lstm_sequence_reverse = std::make_shared( - lstm_sequence->input_value(0), - H->output(1), - C->output(1), - lstm_sequence->input_value(3), - W->output(1), - R->output(1), - B->output(1), - lstm_sequence->get_hidden_size(), - ngraph::op::RecurrentSequenceDirection::REVERSE, - lstm_sequence->get_activations_alpha(), - lstm_sequence->get_activations_beta(), - lstm_sequence->get_activations(), - lstm_sequence->get_clip()); + auto lstm_sequence_reverse = + std::make_shared(lstm_sequence->input_value(0), + H->output(1), + C->output(1), + lstm_sequence->input_value(3), + W->output(1), + R->output(1), + B->output(1), + lstm_sequence->get_hidden_size(), + ngraph::op::RecurrentSequenceDirection::REVERSE, + lstm_sequence->get_activations_alpha(), + lstm_sequence->get_activations_beta(), + lstm_sequence->get_activations(), + lstm_sequence->get_clip()); - auto concat_0 = std::make_shared(OutputVector{lstm_sequence_forward->output(0), - lstm_sequence_reverse->output(0)}, 1); - auto concat_1 = std::make_shared(OutputVector{lstm_sequence_forward->output(1), - lstm_sequence_reverse->output(1)}, 1); - auto concat_2 = std::make_shared(OutputVector{lstm_sequence_forward->output(2), - lstm_sequence_reverse->output(2)}, 1); - ngraph::copy_runtime_info(lstm_sequence, {H, C, W, R, B, lstm_sequence_forward, lstm_sequence_reverse, - concat_0, concat_1, concat_2}); - concat_0->set_friendly_name(lstm_sequence->get_friendly_name()+".0"); - concat_1->set_friendly_name(lstm_sequence->get_friendly_name()+".1"); - concat_2->set_friendly_name(lstm_sequence->get_friendly_name()+".2"); + auto concat_0 = std::make_shared( + OutputVector{lstm_sequence_forward->output(0), lstm_sequence_reverse->output(0)}, + 1); + auto concat_1 = std::make_shared( + OutputVector{lstm_sequence_forward->output(1), lstm_sequence_reverse->output(1)}, + 1); + auto concat_2 = std::make_shared( + OutputVector{lstm_sequence_forward->output(2), lstm_sequence_reverse->output(2)}, + 1); + ngraph::copy_runtime_info( + lstm_sequence, + {H, C, W, R, B, lstm_sequence_forward, lstm_sequence_reverse, concat_0, concat_1, concat_2}); + concat_0->set_friendly_name(lstm_sequence->get_friendly_name() + ".0"); + concat_1->set_friendly_name(lstm_sequence->get_friendly_name() + ".1"); + concat_2->set_friendly_name(lstm_sequence->get_friendly_name() + ".2"); ngraph::replace_node(lstm_sequence, {concat_0->output(0), concat_1->output(0), concat_2->output(0)}); return true; }; @@ -90,7 +96,7 @@ ngraph::pass::BidirectionalGRUSequenceDecomposition::BidirectionalGRUSequenceDec MATCHER_SCOPE(BidirectionalGRUSequenceDecomposition); auto gru_sequence_ngraph = ngraph::pattern::wrap_type(); - ngraph::matcher_pass_callback callback = [this](pattern::Matcher &m) { + ngraph::matcher_pass_callback callback = [this](pattern::Matcher& m) { auto gru_sequence = std::dynamic_pointer_cast(m.get_match_root()); if (!gru_sequence || transformation_callback(gru_sequence)) { return false; @@ -105,44 +111,46 @@ ngraph::pass::BidirectionalGRUSequenceDecomposition::BidirectionalGRUSequenceDec auto W = std::make_shared(gru_sequence->input_value(3), axis_0, 2); auto R = std::make_shared(gru_sequence->input_value(4), axis_0, 2); auto B = std::make_shared(gru_sequence->input_value(5), axis_0, 2); - auto gru_sequence_forward = std::make_shared( - gru_sequence->input_value(0), - H->output(0), - gru_sequence->input_value(2), - W->output(0), - R->output(0), - B->output(0), - gru_sequence->get_hidden_size(), - ngraph::op::RecurrentSequenceDirection::FORWARD, - gru_sequence->get_activations(), - gru_sequence->get_activations_alpha(), - gru_sequence->get_activations_beta(), - gru_sequence->get_clip(), - gru_sequence->get_linear_before_reset()); + auto gru_sequence_forward = + std::make_shared(gru_sequence->input_value(0), + H->output(0), + gru_sequence->input_value(2), + W->output(0), + R->output(0), + B->output(0), + gru_sequence->get_hidden_size(), + ngraph::op::RecurrentSequenceDirection::FORWARD, + gru_sequence->get_activations(), + gru_sequence->get_activations_alpha(), + gru_sequence->get_activations_beta(), + gru_sequence->get_clip(), + gru_sequence->get_linear_before_reset()); - auto gru_sequence_reverse = std::make_shared( - gru_sequence->input_value(0), - H->output(1), - gru_sequence->input_value(2), - W->output(1), - R->output(1), - B->output(1), - gru_sequence->get_hidden_size(), - ngraph::op::RecurrentSequenceDirection::REVERSE, - gru_sequence->get_activations(), - gru_sequence->get_activations_alpha(), - gru_sequence->get_activations_beta(), - gru_sequence->get_clip(), - gru_sequence->get_linear_before_reset()); + auto gru_sequence_reverse = + std::make_shared(gru_sequence->input_value(0), + H->output(1), + gru_sequence->input_value(2), + W->output(1), + R->output(1), + B->output(1), + gru_sequence->get_hidden_size(), + ngraph::op::RecurrentSequenceDirection::REVERSE, + gru_sequence->get_activations(), + gru_sequence->get_activations_alpha(), + gru_sequence->get_activations_beta(), + gru_sequence->get_clip(), + gru_sequence->get_linear_before_reset()); - auto concat_0 = std::make_shared(OutputVector{gru_sequence_forward->output(0), - gru_sequence_reverse->output(0)}, 1); - auto concat_1 = std::make_shared(OutputVector{gru_sequence_forward->output(1), - gru_sequence_reverse->output(1)}, 1); - ngraph::copy_runtime_info(gru_sequence, {H, W, R, B, gru_sequence_forward, gru_sequence_reverse, - concat_0, concat_1}); - concat_0->set_friendly_name(gru_sequence->get_friendly_name()+".0"); - concat_1->set_friendly_name(gru_sequence->get_friendly_name()+".1"); + auto concat_0 = std::make_shared( + OutputVector{gru_sequence_forward->output(0), gru_sequence_reverse->output(0)}, + 1); + auto concat_1 = std::make_shared( + OutputVector{gru_sequence_forward->output(1), gru_sequence_reverse->output(1)}, + 1); + ngraph::copy_runtime_info(gru_sequence, + {H, W, R, B, gru_sequence_forward, gru_sequence_reverse, concat_0, concat_1}); + concat_0->set_friendly_name(gru_sequence->get_friendly_name() + ".0"); + concat_1->set_friendly_name(gru_sequence->get_friendly_name() + ".1"); ngraph::replace_node(gru_sequence, {concat_0->output(0), concat_1->output(0)}); return true; }; @@ -155,7 +163,7 @@ ngraph::pass::BidirectionalRNNSequenceDecomposition::BidirectionalRNNSequenceDec MATCHER_SCOPE(BidirectionalRNNSequenceDecomposition); auto rnn_sequence_ngraph = ngraph::pattern::wrap_type(); - ngraph::matcher_pass_callback callback = [this](pattern::Matcher &m) { + ngraph::matcher_pass_callback callback = [this](pattern::Matcher& m) { auto rnn_sequence = std::dynamic_pointer_cast(m.get_match_root()); if (!rnn_sequence || transformation_callback(rnn_sequence)) { return false; @@ -170,40 +178,42 @@ ngraph::pass::BidirectionalRNNSequenceDecomposition::BidirectionalRNNSequenceDec auto W = std::make_shared(rnn_sequence->input_value(3), axis_0, 2); auto R = std::make_shared(rnn_sequence->input_value(4), axis_0, 2); auto B = std::make_shared(rnn_sequence->input_value(5), axis_0, 2); - auto rnn_sequence_forward = std::make_shared( - rnn_sequence->input_value(0), - H->output(0), - rnn_sequence->input_value(2), - W->output(0), - R->output(0), - B->output(0), - rnn_sequence->get_hidden_size(), - ngraph::op::RecurrentSequenceDirection::FORWARD, - rnn_sequence->get_activations(), - rnn_sequence->get_activations_alpha(), - rnn_sequence->get_activations_beta(), - rnn_sequence->get_clip()); + auto rnn_sequence_forward = + std::make_shared(rnn_sequence->input_value(0), + H->output(0), + rnn_sequence->input_value(2), + W->output(0), + R->output(0), + B->output(0), + rnn_sequence->get_hidden_size(), + ngraph::op::RecurrentSequenceDirection::FORWARD, + rnn_sequence->get_activations(), + rnn_sequence->get_activations_alpha(), + rnn_sequence->get_activations_beta(), + rnn_sequence->get_clip()); - auto rnn_sequence_reverse = std::make_shared( - rnn_sequence->input_value(0), - H->output(1), - rnn_sequence->input_value(2), - W->output(1), - R->output(1), - B->output(1), - rnn_sequence->get_hidden_size(), - ngraph::op::RecurrentSequenceDirection::REVERSE, - rnn_sequence->get_activations(), - rnn_sequence->get_activations_alpha(), - rnn_sequence->get_activations_beta(), - rnn_sequence->get_clip()); + auto rnn_sequence_reverse = + std::make_shared(rnn_sequence->input_value(0), + H->output(1), + rnn_sequence->input_value(2), + W->output(1), + R->output(1), + B->output(1), + rnn_sequence->get_hidden_size(), + ngraph::op::RecurrentSequenceDirection::REVERSE, + rnn_sequence->get_activations(), + rnn_sequence->get_activations_alpha(), + rnn_sequence->get_activations_beta(), + rnn_sequence->get_clip()); - auto concat_0 = std::make_shared(OutputVector{rnn_sequence_forward->output(0), - rnn_sequence_reverse->output(0)}, 1); - auto concat_1 = std::make_shared(OutputVector{rnn_sequence_forward->output(1), - rnn_sequence_reverse->output(1)}, 1); - ngraph::copy_runtime_info(rnn_sequence, {H, W, R, B, rnn_sequence_forward, rnn_sequence_reverse, - concat_0, concat_1}); + auto concat_0 = std::make_shared( + OutputVector{rnn_sequence_forward->output(0), rnn_sequence_reverse->output(0)}, + 1); + auto concat_1 = std::make_shared( + OutputVector{rnn_sequence_forward->output(1), rnn_sequence_reverse->output(1)}, + 1); + ngraph::copy_runtime_info(rnn_sequence, + {H, W, R, B, rnn_sequence_forward, rnn_sequence_reverse, concat_0, concat_1}); concat_0->set_friendly_name(rnn_sequence->get_friendly_name() + ".0"); concat_1->set_friendly_name(rnn_sequence->get_friendly_name() + ".1"); ngraph::replace_node(rnn_sequence, {concat_0->output(0), concat_1->output(0)}); diff --git a/src/common/transformations/src/transformations/op_conversions/convert_batch_to_space.cpp b/src/common/transformations/src/transformations/op_conversions/convert_batch_to_space.cpp index 819cb1ae5ba..7d387903398 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_batch_to_space.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_batch_to_space.cpp @@ -2,15 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/convert_batch_to_space.hpp" #include -#include - #include #include #include +#include + +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertBatchToSpace, "ConvertBatchToSpace", 0); @@ -18,7 +18,7 @@ void ngraph::pass::ConvertBatchToSpace::convert_batch_to_space() { MATCHER_SCOPE(ConvertBatchToSpace_convert_batch_to_space); auto batch_to_space = ngraph::pattern::wrap_type(); ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto batch_to_space = std::dynamic_pointer_cast (m.get_match_root()); + auto batch_to_space = std::dynamic_pointer_cast(m.get_match_root()); if (!batch_to_space) { return false; } @@ -42,8 +42,8 @@ void ngraph::pass::ConvertBatchToSpace::convert_batch_to_space() { return false; } - const std::vector &block_values = block_const->cast_vector(); - const std::vector &crops_end_values = crops_end_const->cast_vector(); + const std::vector& block_values = block_const->cast_vector(); + const std::vector& crops_end_values = crops_end_const->cast_vector(); // First we have to disperse the data from batch, then rearrange them // so as appropriate chunks of data where close to their destination place. @@ -65,7 +65,7 @@ void ngraph::pass::ConvertBatchToSpace::convert_batch_to_space() { } const auto out_pattern_1 = - opset3::Constant::create(element::i64, Shape{dispersed_shape.size()}, dispersed_shape); + opset3::Constant::create(element::i64, Shape{dispersed_shape.size()}, dispersed_shape); const bool special_zero = false; std::shared_ptr flat_node = std::make_shared(data, out_pattern_1, special_zero); new_ops.push_back(flat_node); @@ -78,9 +78,9 @@ void ngraph::pass::ConvertBatchToSpace::convert_batch_to_space() { } const auto axes_order_const = - opset3::Constant::create(element::i64, - Shape{axes_order.size()}, - std::vector(axes_order.begin(), axes_order.end())); + opset3::Constant::create(element::i64, + Shape{axes_order.size()}, + std::vector(axes_order.begin(), axes_order.end())); flat_node = std::make_shared(flat_node, axes_order_const); new_ops.push_back(flat_node); // x''' = reshape(x'', [batch / (B_1 * ... * B_{N - 1}), D_1 * B_1, D_2 * B_2, ... , D_{N - 1} @@ -91,8 +91,7 @@ void ngraph::pass::ConvertBatchToSpace::convert_batch_to_space() { squeezed_shape.push_back(data_shape.at(i) * block_values.at(i)); } - const auto out_pattern_2 = - opset3::Constant::create(element::i64, Shape{squeezed_shape.size()}, squeezed_shape); + const auto out_pattern_2 = opset3::Constant::create(element::i64, Shape{squeezed_shape.size()}, squeezed_shape); flat_node = std::make_shared(flat_node, out_pattern_2, special_zero); new_ops.push_back(flat_node); @@ -108,13 +107,14 @@ void ngraph::pass::ConvertBatchToSpace::convert_batch_to_space() { upperbounds_values.push_back(flat_node_shape.at(i) - crops_end_values.at(i)); } - const auto upperbounds = opset3::Constant::create( - crops_end.get_element_type(), Shape{upperbounds_values.size()}, upperbounds_values); + const auto upperbounds = opset3::Constant::create(crops_end.get_element_type(), + Shape{upperbounds_values.size()}, + upperbounds_values); std::vector begin_mask(data_shape.size(), 0); std::vector end_mask(data_shape.size(), 0); - flat_node = std::make_shared( - flat_node, crops_begin_const, upperbounds, begin_mask, end_mask); + flat_node = + std::make_shared(flat_node, crops_begin_const, upperbounds, begin_mask, end_mask); new_ops.push_back(flat_node); flat_node->set_friendly_name(batch_to_space->get_friendly_name()); @@ -131,7 +131,7 @@ void ngraph::pass::ConvertBatchToSpace::convert_batch_to_space_by_elements() { MATCHER_SCOPE(ConvertBatchToSpace_convert_batch_to_space_by_elements); auto batch_to_space = ngraph::pattern::wrap_type(); ngraph::matcher_pass_callback callback = [this](pattern::Matcher& m) { - auto batch_to_space = std::dynamic_pointer_cast (m.get_match_root()); + auto batch_to_space = std::dynamic_pointer_cast(m.get_match_root()); if (!batch_to_space) { return false; } @@ -154,8 +154,8 @@ void ngraph::pass::ConvertBatchToSpace::convert_batch_to_space_by_elements() { const auto crops_begin_const = ov::as_type_ptr(crops_begin.get_node_shared_ptr()); const auto crops_end_const = ov::as_type_ptr(crops_end.get_node_shared_ptr()); - const std::vector &block_values = block_const->cast_vector(); - const std::vector &crops_end_values = crops_end_const->cast_vector(); + const std::vector& block_values = block_const->cast_vector(); + const std::vector& crops_end_values = crops_end_const->cast_vector(); std::vector dispersed_shape(1); dispersed_shape.insert(dispersed_shape.end(), data_shape.begin(), data_shape.end()); @@ -172,7 +172,7 @@ void ngraph::pass::ConvertBatchToSpace::convert_batch_to_space_by_elements() { dispersed_shape[0] = block_values[block_idx]; dispersed_shape[1] /= block_values[block_idx]; const auto out_pattern_1 = - opset3::Constant::create(element::i64, Shape{dispersed_shape.size()}, dispersed_shape); + opset3::Constant::create(element::i64, Shape{dispersed_shape.size()}, dispersed_shape); const bool special_zero = false; flat_node = std::make_shared(flat_node, out_pattern_1, special_zero); new_ops.push_back(flat_node); @@ -188,9 +188,9 @@ void ngraph::pass::ConvertBatchToSpace::convert_batch_to_space_by_elements() { } const auto axes_order_const = - ngraph::opset3::Constant::create(element::i64, - Shape{axes_order.size()}, - std::vector(axes_order.begin(), axes_order.end())); + ngraph::opset3::Constant::create(element::i64, + Shape{axes_order.size()}, + std::vector(axes_order.begin(), axes_order.end())); flat_node = std::make_shared(flat_node, axes_order_const); new_ops.push_back(flat_node); @@ -198,7 +198,7 @@ void ngraph::pass::ConvertBatchToSpace::convert_batch_to_space_by_elements() { squeezed_shape[block_idx] *= block_values[block_idx]; dispersed_shape[block_idx + 1] = squeezed_shape[block_idx]; const auto out_pattern_2 = - opset3::Constant::create(element::i64, Shape{squeezed_shape.size()}, squeezed_shape); + opset3::Constant::create(element::i64, Shape{squeezed_shape.size()}, squeezed_shape); flat_node = std::make_shared(flat_node, out_pattern_2, special_zero); new_ops.push_back(flat_node); } @@ -208,13 +208,14 @@ void ngraph::pass::ConvertBatchToSpace::convert_batch_to_space_by_elements() { for (size_t i = 0; i < flat_node_shape.size(); ++i) { upperbounds_values.push_back(flat_node_shape.at(i) - crops_end_values.at(i)); } - const auto upperbounds = opset3::Constant::create( - crops_end.get_element_type(), Shape{upperbounds_values.size()}, upperbounds_values); + const auto upperbounds = opset3::Constant::create(crops_end.get_element_type(), + Shape{upperbounds_values.size()}, + upperbounds_values); std::vector begin_mask(data_shape.size(), 0); std::vector end_mask(data_shape.size(), 0); - flat_node = std::make_shared( - flat_node, crops_begin_const, upperbounds, begin_mask, end_mask); + flat_node = + std::make_shared(flat_node, crops_begin_const, upperbounds, begin_mask, end_mask); new_ops.push_back(flat_node); flat_node->set_friendly_name(batch_to_space->get_friendly_name()); diff --git a/src/common/transformations/src/transformations/op_conversions/convert_broadcast3.cpp b/src/common/transformations/src/transformations/op_conversions/convert_broadcast3.cpp index 515c48b52ed..3a45833d0e2 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_broadcast3.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_broadcast3.cpp @@ -2,31 +2,30 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/convert_broadcast3.hpp" #include -#include - -#include - #include #include #include +#include +#include + +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertBroadcast3, "ConvertBroadcast3", 0); namespace { -bool make_compatible_shape(const ngraph::PartialShape & input_shape, std::vector & target_shape) { +bool make_compatible_shape(const ngraph::PartialShape& input_shape, std::vector& target_shape) { if (input_shape.rank().is_dynamic()) { return false; } - const int64_t & input_shape_rank = input_shape.rank().get_length(); + const int64_t& input_shape_rank = input_shape.rank().get_length(); if (input_shape_rank > static_cast(target_shape.size())) { // target_shape rank must greater or equal to input_shape rank, so in case when it's less we // insert missing input_shape dimensions to the beginning of the target_shape. - const int64_t & dims_to_add_count = input_shape_rank - target_shape.size(); + const int64_t& dims_to_add_count = input_shape_rank - target_shape.size(); std::vector dims_to_add(dims_to_add_count); for (int64_t dim = 0; dim < dims_to_add_count; ++dim) { if (input_shape[dim].is_dynamic()) { @@ -36,9 +35,10 @@ bool make_compatible_shape(const ngraph::PartialShape & input_shape, std::vector } target_shape.insert(target_shape.begin(), dims_to_add.begin(), dims_to_add.end()); } - for (int64_t i_dim = input_shape_rank - 1, t_dim = target_shape.size() - 1; i_dim >= 0 && t_dim >= 0; --i_dim, --t_dim) { + for (int64_t i_dim = input_shape_rank - 1, t_dim = target_shape.size() - 1; i_dim >= 0 && t_dim >= 0; + --i_dim, --t_dim) { if (input_shape[i_dim].is_static()) { - const auto & input_dim = input_shape[i_dim].get_length(); + const auto& input_dim = input_shape[i_dim].get_length(); if (static_cast(input_dim) != target_shape[t_dim] && input_dim != 1 && target_shape[t_dim] != 1) { // this dimensions are not broadcastable return false; @@ -57,7 +57,7 @@ bool make_compatible_shape(const ngraph::PartialShape & input_shape, std::vector return true; } -} // namespace +} // namespace ngraph::pass::ConvertBroadcast3::ConvertBroadcast3() { MATCHER_SCOPE(ConvertBroadcast3); @@ -71,26 +71,34 @@ ngraph::pass::ConvertBroadcast3::ConvertBroadcast3() { auto input = broadcast->input_value(0); auto target_shape_input = broadcast->input_value(1); - const auto & broadcast_type = broadcast->get_broadcast_spec(); - const auto & input_element_type = input.get_element_type(); + const auto& broadcast_type = broadcast->get_broadcast_spec(); + const auto& input_element_type = input.get_element_type(); if (broadcast_type == op::BroadcastType::NUMPY) { input = std::make_shared(input, target_shape_input, op::AutoBroadcastType::NUMPY); } else if (broadcast_type == op::BroadcastType::PDPD) { input = std::make_shared(input, target_shape_input, op::AutoBroadcastType::PDPD); } else if (broadcast_type == op::BroadcastType::NONE) { - input = std::make_shared(input, target_shape_input, broadcast->input_value(2), op::AutoBroadcastType::NONE); + input = std::make_shared(input, + target_shape_input, + broadcast->input_value(2), + op::AutoBroadcastType::NONE); } else if (broadcast_type == op::BroadcastType::BIDIRECTIONAL) { - if (auto const_target_shape = std::dynamic_pointer_cast(target_shape_input.get_node_shared_ptr())) { - const auto & input_shape = input.get_partial_shape(); - const auto & target_shape = const_target_shape->cast_vector(); + if (auto const_target_shape = + std::dynamic_pointer_cast(target_shape_input.get_node_shared_ptr())) { + const auto& input_shape = input.get_partial_shape(); + const auto& target_shape = const_target_shape->cast_vector(); std::vector aligned_target_shape{target_shape}; if (make_compatible_shape(input_shape, aligned_target_shape)) { - input = std::make_shared(input, - opset1::Constant::create(element::i64, Shape({aligned_target_shape.size()}), aligned_target_shape)); + input = std::make_shared( + input, + opset1::Constant::create(element::i64, + Shape({aligned_target_shape.size()}), + aligned_target_shape)); } else { - input = std::make_shared(input, - opset1::Constant::create(input_element_type, target_shape, {1})); + input = std::make_shared( + input, + opset1::Constant::create(input_element_type, target_shape, {1})); } } else { auto constant_one = opset1::Constant::create(input_element_type, {1}, {1}); diff --git a/src/common/transformations/src/transformations/op_conversions/convert_broadcast_to_tiles.cpp b/src/common/transformations/src/transformations/op_conversions/convert_broadcast_to_tiles.cpp index 45a005e6bd4..b7fbaa32ebf 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_broadcast_to_tiles.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_broadcast_to_tiles.cpp @@ -2,15 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/convert_broadcast_to_tiles.hpp" #include +#include +#include +#include #include -#include -#include -#include +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertBroadcastToTiles, "ConvertBroadcastToTiles", 0); @@ -30,9 +30,12 @@ ngraph::pass::ConvertBroadcastToTiles::ConvertBroadcastToTiles() { return false; } - auto shape_node = std::dynamic_pointer_cast(broadcast->input_value(1).get_node_shared_ptr()); - auto axes_node = std::dynamic_pointer_cast(broadcast->input_value(2).get_node_shared_ptr()); - if (!shape_node || !axes_node) return false; + auto shape_node = + std::dynamic_pointer_cast(broadcast->input_value(1).get_node_shared_ptr()); + auto axes_node = + std::dynamic_pointer_cast(broadcast->input_value(2).get_node_shared_ptr()); + if (!shape_node || !axes_node) + return false; auto output_shape = shape_node->cast_vector(); auto input_shape = data_node.get_shape(); @@ -64,7 +67,7 @@ ngraph::pass::ConvertBroadcastToTiles::ConvertBroadcastToTiles() { } else { return false; } - auto shape_const = std::make_shared(element::i64, Shape {shape.size()}, shape); + auto shape_const = std::make_shared(element::i64, Shape{shape.size()}, shape); auto reshape = std::make_shared(data_node, shape_const, true); new_ops.push_back(reshape); last_node = reshape; @@ -88,7 +91,7 @@ ngraph::pass::ConvertBroadcastToTiles::ConvertBroadcastToTiles() { ++input_shape_it; } - auto const_node = std::make_shared(element::i64, Shape {dims_count}, dims); + auto const_node = std::make_shared(element::i64, Shape{dims_count}, dims); auto tile = register_new_node(last_node, const_node); new_ops.push_back(tile); tile->set_friendly_name(broadcast->get_friendly_name()); diff --git a/src/common/transformations/src/transformations/op_conversions/convert_deformable_conv_v8_to_v1.cpp b/src/common/transformations/src/transformations/op_conversions/convert_deformable_conv_v8_to_v1.cpp index 276a1192ca1..e4d1380164d 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_deformable_conv_v8_to_v1.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_deformable_conv_v8_to_v1.cpp @@ -3,10 +3,11 @@ // #include "transformations/op_conversions/convert_deformable_conv_v8_to_v1.hpp" + #include #include -#include #include +#include #include "itt.hpp" @@ -18,12 +19,12 @@ ngraph::pass::ConvertDeformableConv8To1::ConvertDeformableConv8To1() { auto deformable_conv_v8 = pattern::wrap_type(); ngraph::matcher_pass_callback callback = [=](pattern::Matcher& m) { - auto deformable_conv_v8_node = std::dynamic_pointer_cast(m.get_match_root()); + auto deformable_conv_v8_node = + std::dynamic_pointer_cast(m.get_match_root()); if (!deformable_conv_v8_node) return false; - if (deformable_conv_v8_node->get_input_size() != 3 - || deformable_conv_v8_node->get_bilinear_interpolation_pad()) + if (deformable_conv_v8_node->get_input_size() != 3 || deformable_conv_v8_node->get_bilinear_interpolation_pad()) return false; auto arg = deformable_conv_v8_node->input_value(0); @@ -31,16 +32,16 @@ ngraph::pass::ConvertDeformableConv8To1::ConvertDeformableConv8To1() { auto filters = deformable_conv_v8_node->input_value(2); auto deformable_conv_v1 = - std::make_shared(arg, - offsets, - filters, - deformable_conv_v8_node->get_strides(), - deformable_conv_v8_node->get_pads_begin(), - deformable_conv_v8_node->get_pads_end(), - deformable_conv_v8_node->get_dilations(), - deformable_conv_v8_node->get_auto_pad(), - deformable_conv_v8_node->get_group(), - deformable_conv_v8_node->get_deformable_group()); + std::make_shared(arg, + offsets, + filters, + deformable_conv_v8_node->get_strides(), + deformable_conv_v8_node->get_pads_begin(), + deformable_conv_v8_node->get_pads_end(), + deformable_conv_v8_node->get_dilations(), + deformable_conv_v8_node->get_auto_pad(), + deformable_conv_v8_node->get_group(), + deformable_conv_v8_node->get_deformable_group()); deformable_conv_v1->set_friendly_name(deformable_conv_v8_node->get_friendly_name()); ngraph::copy_runtime_info(deformable_conv_v8_node, deformable_conv_v1); ngraph::replace_node(deformable_conv_v8_node, deformable_conv_v1); diff --git a/src/common/transformations/src/transformations/op_conversions/convert_depth_to_space.cpp b/src/common/transformations/src/transformations/op_conversions/convert_depth_to_space.cpp index 90ceae01f0f..e8d2a4d8104 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_depth_to_space.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_depth_to_space.cpp @@ -2,24 +2,25 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/convert_depth_to_space.hpp" #include +#include +#include +#include #include -#include -#include -#include +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertDepthToSpace, "ConvertDepthToSpace", 0); ngraph::pass::ConvertDepthToSpace::ConvertDepthToSpace() { MATCHER_SCOPE(ConvertDepthToSpace); - auto dts_node = ngraph::pattern::wrap_type({pattern::any_input(pattern::has_static_shape())}); + auto dts_node = + ngraph::pattern::wrap_type({pattern::any_input(pattern::has_static_shape())}); ngraph::matcher_pass_callback callback = [this](pattern::Matcher& m) { - auto dts_node = std::dynamic_pointer_cast (m.get_match_root()); + auto dts_node = std::dynamic_pointer_cast(m.get_match_root()); if (!dts_node || transformation_callback(dts_node)) { return false; } @@ -52,12 +53,12 @@ ngraph::pass::ConvertDepthToSpace::ConvertDepthToSpace() { } switch (mode) { - case ngraph::op::DepthToSpace::DepthToSpaceMode::BLOCKS_FIRST: - shape_begin.push_back(C); - break; - case ngraph::op::DepthToSpace::DepthToSpaceMode::DEPTH_FIRST: - shape_begin.insert(shape_begin.begin() + 1, C); - break; + case ngraph::op::DepthToSpace::DepthToSpaceMode::BLOCKS_FIRST: + shape_begin.push_back(C); + break; + case ngraph::op::DepthToSpace::DepthToSpaceMode::DEPTH_FIRST: + shape_begin.insert(shape_begin.begin() + 1, C); + break; } for (size_t i = 0; i < spatial_dims; ++i) { @@ -67,20 +68,20 @@ ngraph::pass::ConvertDepthToSpace::ConvertDepthToSpace() { // Calculate Transpose order std::vector order{0}; switch (mode) { - case ngraph::op::DepthToSpace::DepthToSpaceMode::BLOCKS_FIRST: - order.push_back(spatial_dims + 1); - for (size_t i = 1; i <= spatial_dims; ++i) { - order.push_back(spatial_dims + 1 + i); - order.push_back(i); - } - break; - case ngraph::op::DepthToSpace::DepthToSpaceMode::DEPTH_FIRST: - order.push_back(1); - for (size_t i = 1; i <= spatial_dims; ++i) { - order.push_back(spatial_dims + 1 + i); - order.push_back(i + 1); - } - break; + case ngraph::op::DepthToSpace::DepthToSpaceMode::BLOCKS_FIRST: + order.push_back(spatial_dims + 1); + for (size_t i = 1; i <= spatial_dims; ++i) { + order.push_back(spatial_dims + 1 + i); + order.push_back(i); + } + break; + case ngraph::op::DepthToSpace::DepthToSpaceMode::DEPTH_FIRST: + order.push_back(1); + for (size_t i = 1; i <= spatial_dims; ++i) { + order.push_back(spatial_dims + 1 + i); + order.push_back(i + 1); + } + break; } // Calculate Reshape shape_end @@ -89,7 +90,7 @@ ngraph::pass::ConvertDepthToSpace::ConvertDepthToSpace() { shape_end.push_back(block_size * input_shape[2 + i]); } - auto create_constant = [](std::vector & v) -> std::shared_ptr { + auto create_constant = [](std::vector& v) -> std::shared_ptr { return op::Constant::create(element::i64, Shape{v.size()}, v); }; diff --git a/src/common/transformations/src/transformations/op_conversions/convert_divide.cpp b/src/common/transformations/src/transformations/op_conversions/convert_divide.cpp index e99631a13cb..0f13fbcf681 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_divide.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_divide.cpp @@ -2,21 +2,19 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/convert_divide.hpp" -#include "transformations/utils/utils.hpp" - #include +#include +#include +#include +#include +#include #include -#include -#include -#include -#include -#include - +#include "itt.hpp" #include "transformations/rt_info/nonconvertible_divide.hpp" +#include "transformations/utils/utils.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertDivide, "ConvertDivide", 0); NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertDivideWithConstant, "ConvertDivideWithConstant", 0); @@ -25,13 +23,13 @@ namespace { bool convert_divide(std::shared_ptr node) { auto div = std::dynamic_pointer_cast(node); // We can not apply this transformation in case with integer input data type - if (!div || ov::divide_is_nonconvertible(div) - || div->get_input_element_type(0).is_integral()) { + if (!div || ov::divide_is_nonconvertible(div) || div->get_input_element_type(0).is_integral()) { return false; } - std::shared_ptr pow = std::make_shared(div->input_value(1), - ngraph::op::Constant::create(div->get_input_element_type(1), ngraph::Shape{}, {-1})); + std::shared_ptr pow = std::make_shared( + div->input_value(1), + ngraph::op::Constant::create(div->get_input_element_type(1), ngraph::Shape{}, {-1})); if (std::dynamic_pointer_cast(div->get_input_node_shared_ptr(1))) { if (auto const_pow = ngraph::get_constant_from_source(pow)) { @@ -56,7 +54,7 @@ bool convert_divide(std::shared_ptr node) { } return true; } -} // namespace +} // namespace ngraph::pass::ConvertDivide::ConvertDivide() { MATCHER_SCOPE(ConvertDivide); @@ -72,8 +70,8 @@ ngraph::pass::ConvertDivide::ConvertDivide() { ngraph::pass::ConvertDivideWithConstant::ConvertDivideWithConstant() { MATCHER_SCOPE(ConvertDivideWithConstant); - auto div = ngraph::pattern::wrap_type( - {pattern::any_input(), pattern::wrap_type()}); + auto div = + ngraph::pattern::wrap_type({pattern::any_input(), pattern::wrap_type()}); ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { return convert_divide(m.get_match_root()); diff --git a/src/common/transformations/src/transformations/op_conversions/convert_gather_0d.cpp b/src/common/transformations/src/transformations/op_conversions/convert_gather_0d.cpp index 18a2f6a531b..40c2d7b5bf9 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_gather_0d.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_gather_0d.cpp @@ -4,14 +4,13 @@ #include "transformations/op_conversions/convert_gather_0d.hpp" -#include "itt.hpp" - #include +#include +#include +#include #include -#include -#include -#include +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertGather0D, "ConvertGather0D", 0); @@ -19,13 +18,14 @@ ngraph::pass::ConvertGather0D::ConvertGather0D() { MATCHER_SCOPE(ConvertGather0D); auto gather = ngraph::pattern::wrap_type(); - ngraph::matcher_pass_callback callback = [](pattern::Matcher &m) { + ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { auto gather = std::dynamic_pointer_cast(m.get_match_root()); if (!gather) { return false; } - auto axes_constant = std::dynamic_pointer_cast(gather->input_value(2).get_node_shared_ptr()); + auto axes_constant = + std::dynamic_pointer_cast(gather->input_value(2).get_node_shared_ptr()); if (!axes_constant) { return false; } @@ -39,9 +39,11 @@ ngraph::pass::ConvertGather0D::ConvertGather0D() { } auto axis = axes_constant->cast_vector()[0]; - indices = std::make_shared(indices, opset1::Constant::create(element::i64, Shape{1}, {0})); + indices = + std::make_shared(indices, opset1::Constant::create(element::i64, Shape{1}, {0})); auto gather_new = std::make_shared(gather->input_value(0), indices, axes_constant); - auto sq = std::make_shared(gather_new, opset1::Constant::create(element::i64, Shape{1}, {axis})); + auto sq = std::make_shared(gather_new, + opset1::Constant::create(element::i64, Shape{1}, {axis})); sq->set_friendly_name(gather->get_friendly_name()); ngraph::copy_runtime_info(gather, {indices.get_node_shared_ptr(), gather_new, sq}); diff --git a/src/common/transformations/src/transformations/op_conversions/convert_gather_downgrade.cpp b/src/common/transformations/src/transformations/op_conversions/convert_gather_downgrade.cpp index e573a9a847a..184829a35fb 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_gather_downgrade.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_gather_downgrade.cpp @@ -3,11 +3,13 @@ // #include "transformations/op_conversions/convert_gather_downgrade.hpp" + #include #include #include -#include #include +#include + #include "itt.hpp" using namespace std; @@ -16,7 +18,6 @@ using namespace ngraph; NGRAPH_RTTI_DEFINITION(pass::ConvertGather7ToGather1, "ConvertGather7ToGather1", 0); NGRAPH_RTTI_DEFINITION(pass::ConvertGather8ToGather7, "ConvertGather8ToGather7", 0); - pass::ConvertGather7ToGather1::ConvertGather7ToGather1() { MATCHER_SCOPE(ConvertGather7ToGather1); diff --git a/src/common/transformations/src/transformations/op_conversions/convert_gather_upgrade.cpp b/src/common/transformations/src/transformations/op_conversions/convert_gather_upgrade.cpp index 7c45c39f5ab..207a432012c 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_gather_upgrade.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_gather_upgrade.cpp @@ -3,11 +3,13 @@ // #include "transformations/op_conversions/convert_gather_upgrade.hpp" + #include #include #include -#include #include +#include + #include "itt.hpp" using namespace std; @@ -16,7 +18,6 @@ using namespace ngraph; NGRAPH_RTTI_DEFINITION(pass::ConvertGather1ToGather7, "ConvertGather1ToGather7", 0); NGRAPH_RTTI_DEFINITION(pass::ConvertGather7ToGather8, "ConvertGather7ToGather8", 0); - pass::ConvertGather1ToGather7::ConvertGather1ToGather7() { MATCHER_SCOPE(ConvertGather1ToGather7); diff --git a/src/common/transformations/src/transformations/op_conversions/convert_gelu.cpp b/src/common/transformations/src/transformations/op_conversions/convert_gelu.cpp index e4d043118e8..5c5395fccc0 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_gelu.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_gelu.cpp @@ -2,14 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include +#include #include +#include +#include #include -#include -#include -#include +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertGELU, "ConvertGELU", 0); @@ -25,11 +25,14 @@ ngraph::pass::ConvertGELU::ConvertGELU() { auto input_type = input.get_element_type(); // f(x) = 0.5 * x * (1.0 + erf( x / sqrt(2.0) ) - auto mul = std::make_shared(input, ngraph::opset1::Constant::create(input_type, Shape{}, {0.5})); + auto mul = + std::make_shared(input, + ngraph::opset1::Constant::create(input_type, Shape{}, {0.5})); auto sq2 = std::make_shared(ngraph::opset1::Constant::create(input_type, Shape{}, {2.0})); - auto div = register_new_node(input, sq2); // can be decomposed + auto div = register_new_node(input, sq2); // can be decomposed auto erf = std::make_shared(div); - auto add = std::make_shared(erf, ngraph::opset1::Constant::create(input_type, Shape{}, {1.0})); + auto add = + std::make_shared(erf, ngraph::opset1::Constant::create(input_type, Shape{}, {1.0})); auto res = std::make_shared(mul, add); res->set_friendly_name(gelu->get_friendly_name()); diff --git a/src/common/transformations/src/transformations/op_conversions/convert_interpolate1_to_interpolate4.cpp b/src/common/transformations/src/transformations/op_conversions/convert_interpolate1_to_interpolate4.cpp index de0feeb8dcb..227336e768b 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_interpolate1_to_interpolate4.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_interpolate1_to_interpolate4.cpp @@ -2,25 +2,26 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/convert_interpolate1_to_interpolate4.hpp" #include -#include - #include #include #include -#include #include -#include +#include #include +#include +#include + +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertInterpolate1ToInterpolate4, "ConvertInterpolate1ToInterpolate4", 0); ngraph::pass::ConvertInterpolate1ToInterpolate4::ConvertInterpolate1ToInterpolate4() { MATCHER_SCOPE(ConvertInterpolate1ToInterpolate4); - auto interpolate1 = ngraph::pattern::wrap_type({pattern::any_input(pattern::has_static_rank()), pattern::any_input()}); + auto interpolate1 = ngraph::pattern::wrap_type( + {pattern::any_input(pattern::has_static_rank()), pattern::any_input()}); ngraph::matcher_pass_callback callback = [this](pattern::Matcher& m) { auto interpolationV0 = std::dynamic_pointer_cast(m.get_match_root()); if (!interpolationV0) { @@ -30,8 +31,10 @@ ngraph::pass::ConvertInterpolate1ToInterpolate4::ConvertInterpolate1ToInterpolat auto attrsV0 = interpolationV0->get_attrs(); std::vector axes{attrsV0.axes.begin(), attrsV0.axes.end()}; const auto& out_dims = std::make_shared(interpolationV0->input_value(1), element::f32); - const auto& in_dims = std::make_shared(ngraph::op::util::node_to_get_shape_value_of_indices_from_shape_source( - interpolationV0->input_value(0), axes), element::f32); + const auto& in_dims = std::make_shared( + ngraph::op::util::node_to_get_shape_value_of_indices_from_shape_source(interpolationV0->input_value(0), + axes), + element::f32); std::shared_ptr scales = std::make_shared(out_dims, in_dims); if (const auto& constant = ov::get_constant_from_source(scales)) @@ -72,17 +75,29 @@ ngraph::pass::ConvertInterpolate1ToInterpolate4::ConvertInterpolate1ToInterpolat attrsV4.coordinate_transformation_mode = ngraph::opset4::Interpolate::CoordinateTransformMode::ASYMMETRIC; attrsV4.cube_coeff = -0.75f; if (attrsV0.align_corners) { - attrsV4.coordinate_transformation_mode = ngraph::opset4::Interpolate::CoordinateTransformMode::ALIGN_CORNERS; + attrsV4.coordinate_transformation_mode = + ngraph::opset4::Interpolate::CoordinateTransformMode::ALIGN_CORNERS; } else if ((attrsV4.mode == ngraph::op::v4::Interpolate::InterpolateMode::LINEAR_ONNX || attrsV4.mode == ngraph::op::v4::Interpolate::InterpolateMode::LINEAR) && - std::all_of(attrsV4.pads_begin.begin(), attrsV4.pads_begin.end(), [](size_t i){return i == 0;}) && - std::all_of(attrsV4.pads_end.begin(), attrsV4.pads_end.end(), [](size_t i){return i == 0;}) && - !(input_shape_rank - 2 == 2 && attrsV0.axes == AxisSet{2, 3})) { + std::all_of(attrsV4.pads_begin.begin(), + attrsV4.pads_begin.end(), + [](size_t i) { + return i == 0; + }) && + std::all_of(attrsV4.pads_end.begin(), + attrsV4.pads_end.end(), + [](size_t i) { + return i == 0; + }) && + !(input_shape_rank - 2 == 2 && attrsV0.axes == AxisSet{2, 3})) { attrsV4.coordinate_transformation_mode = ngraph::opset4::Interpolate::CoordinateTransformMode::HALF_PIXEL; } - auto interpolateV4 = std::make_shared(interpolationV0->input_value(0), interpolationV0->input_value(1), - scales, axisConstant, attrsV4); + auto interpolateV4 = std::make_shared(interpolationV0->input_value(0), + interpolationV0->input_value(1), + scales, + axisConstant, + attrsV4); interpolateV4->set_friendly_name(interpolationV0->get_friendly_name()); ngraph::copy_runtime_info(interpolationV0, interpolateV4); diff --git a/src/common/transformations/src/transformations/op_conversions/convert_matrix_nms_to_matrix_nms_ie.cpp b/src/common/transformations/src/transformations/op_conversions/convert_matrix_nms_to_matrix_nms_ie.cpp index e8ebccb356a..20a8139107f 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_matrix_nms_to_matrix_nms_ie.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_matrix_nms_to_matrix_nms_ie.cpp @@ -2,19 +2,18 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" -#include -#include +#include "transformations/op_conversions/convert_matrix_nms_to_matrix_nms_ie.hpp" +#include #include #include #include - -#include #include +#include +#include +#include "itt.hpp" #include "ngraph_ops/nms_static_shape_ie.hpp" -#include "transformations/op_conversions/convert_matrix_nms_to_matrix_nms_ie.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertMatrixNmsToMatrixNmsIE, "ConvertMatrixNmsToMatrixNmsIE", 0); @@ -22,7 +21,7 @@ ngraph::pass::ConvertMatrixNmsToMatrixNmsIE::ConvertMatrixNmsToMatrixNmsIE(bool MATCHER_SCOPE(ConvertMatrixNmsToMatrixNmsIE); auto nms = ngraph::pattern::wrap_type(); - ngraph::matcher_pass_callback callback = [=](pattern::Matcher &m) { + ngraph::matcher_pass_callback callback = [=](pattern::Matcher& m) { auto nms = std::dynamic_pointer_cast(m.get_match_root()); if (!nms || transformation_callback(nms)) { return false; @@ -38,10 +37,9 @@ ngraph::pass::ConvertMatrixNmsToMatrixNmsIE::ConvertMatrixNmsToMatrixNmsIE(bool NodeVector new_ops; auto attrs = nms->get_attrs(); attrs.output_type = force_i32_output_type ? element::i32 : nms->get_output_type(); - auto nms_new = std::make_shared>( - new_args.at(0), - new_args.at(1), - attrs); + auto nms_new = std::make_shared>(new_args.at(0), + new_args.at(1), + attrs); new_ops.emplace_back(nms_new); Output output_0 = nms_new->output(0); diff --git a/src/common/transformations/src/transformations/op_conversions/convert_maxpool_downgrade.cpp b/src/common/transformations/src/transformations/op_conversions/convert_maxpool_downgrade.cpp index 761e9f8d90a..d04a54c4f12 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_maxpool_downgrade.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_maxpool_downgrade.cpp @@ -3,17 +3,18 @@ // #include "transformations/op_conversions/convert_maxpool_downgrade.hpp" + #include #include -#include #include +#include #include + #include "itt.hpp" using namespace std; using namespace ngraph; - pass::ConvertMaxPool8ToMaxPool1::ConvertMaxPool8ToMaxPool1() { MATCHER_SCOPE(ConvertMaxPool8ToMaxPool1); @@ -30,12 +31,12 @@ pass::ConvertMaxPool8ToMaxPool1::ConvertMaxPool8ToMaxPool1() { return false; auto maxpool_v1_node = make_shared(maxpool_v8_node->input_value(0), - maxpool_v8_node->get_strides(), - maxpool_v8_node->get_pads_begin(), - maxpool_v8_node->get_pads_end(), - maxpool_v8_node->get_kernel(), - maxpool_v8_node->get_rounding_type(), - maxpool_v8_node->get_auto_pad()); + maxpool_v8_node->get_strides(), + maxpool_v8_node->get_pads_begin(), + maxpool_v8_node->get_pads_end(), + maxpool_v8_node->get_kernel(), + maxpool_v8_node->get_rounding_type(), + maxpool_v8_node->get_auto_pad()); auto out_name = ngraph::op::util::create_ie_output_name(maxpool_v8_node->output(0)); diff --git a/src/common/transformations/src/transformations/op_conversions/convert_maxpool_upgrade.cpp b/src/common/transformations/src/transformations/op_conversions/convert_maxpool_upgrade.cpp index 463c037cc77..211c6c6611d 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_maxpool_upgrade.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_maxpool_upgrade.cpp @@ -3,11 +3,13 @@ // #include "transformations/op_conversions/convert_maxpool_upgrade.hpp" + #include #include -#include #include +#include #include + #include "itt.hpp" ngraph::pass::ConvertMaxPool1ToMaxPool8::ConvertMaxPool1ToMaxPool8() { diff --git a/src/common/transformations/src/transformations/op_conversions/convert_minimum_to_power_and_max.cpp b/src/common/transformations/src/transformations/op_conversions/convert_minimum_to_power_and_max.cpp index 5d9748925d7..3611b8cb0de 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_minimum_to_power_and_max.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_minimum_to_power_and_max.cpp @@ -2,15 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/convert_minimum_to_power_and_max.hpp" #include +#include +#include +#include #include -#include -#include -#include +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertMinimum, "ConvertMinimum", 0); @@ -19,8 +19,8 @@ ngraph::pass::ConvertMinimum::ConvertMinimum() { auto minimum = ngraph::pattern::wrap_type(); ngraph::matcher_pass_callback callback = [this](pattern::Matcher& m) { - auto minimum = std::dynamic_pointer_cast (m.get_match_root()); - if (!minimum || transformation_callback(minimum) || !minimum->get_output_element_type(0).is_signed()) { + auto minimum = std::dynamic_pointer_cast(m.get_match_root()); + if (!minimum || transformation_callback(minimum) || !minimum->get_output_element_type(0).is_signed()) { return false; } @@ -29,15 +29,19 @@ ngraph::pass::ConvertMinimum::ConvertMinimum() { * Mul(-1)--' */ - auto neg_0 = std::make_shared(minimum->input(0).get_source_output(), - opset1::Constant::create(minimum->get_input_element_type(0), Shape{}, {-1})); + auto neg_0 = std::make_shared( + minimum->input(0).get_source_output(), + opset1::Constant::create(minimum->get_input_element_type(0), Shape{}, {-1})); - auto neg_1 = std::make_shared(minimum->input(1).get_source_output(), - opset1::Constant::create(minimum->get_input_element_type(1), Shape{}, {-1})); + auto neg_1 = std::make_shared( + minimum->input(1).get_source_output(), + opset1::Constant::create(minimum->get_input_element_type(1), Shape{}, {-1})); auto max = std::make_shared(neg_0, neg_1); - auto neg_2 = std::make_shared(max, opset1::Constant::create(max->get_element_type(), Shape{}, {-1})); + auto neg_2 = std::make_shared( + max, + opset1::Constant::create(max->get_element_type(), Shape{}, {-1})); neg_2->set_friendly_name(minimum->get_friendly_name()); ngraph::copy_runtime_info(minimum, {neg_0, neg_1, max, neg_2}); diff --git a/src/common/transformations/src/transformations/op_conversions/convert_mod.cpp b/src/common/transformations/src/transformations/op_conversions/convert_mod.cpp index cbac3d48228..51e93ced9d0 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_mod.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_mod.cpp @@ -2,15 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/convert_mod.hpp" #include +#include +#include +#include #include -#include -#include -#include +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertMod, "ConvertMod", 0); @@ -19,7 +19,7 @@ ngraph::pass::ConvertMod::ConvertMod() { auto mod = ngraph::pattern::wrap_type(); ngraph::matcher_pass_callback callback = [this](pattern::Matcher& m) { - auto mod = std::dynamic_pointer_cast (m.get_match_root()); + auto mod = std::dynamic_pointer_cast(m.get_match_root()); if (!mod) { return false; } @@ -42,7 +42,9 @@ ngraph::pass::ConvertMod::ConvertMod() { auto mul = std::make_shared(dividend_sign, sub); mul->set_friendly_name(mod->get_friendly_name()); - ngraph::copy_runtime_info(mod, {dividend, dividend_sign, divisor, div, convert_to_i64, convert, multiplication, sub, mul}); + ngraph::copy_runtime_info( + mod, + {dividend, dividend_sign, divisor, div, convert_to_i64, convert, multiplication, sub, mul}); ngraph::replace_node(mod, mul); return true; }; diff --git a/src/common/transformations/src/transformations/op_conversions/convert_multiclass_nms_to_multiclass_nms_ie.cpp b/src/common/transformations/src/transformations/op_conversions/convert_multiclass_nms_to_multiclass_nms_ie.cpp index 596fbde42d4..26683c7e135 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_multiclass_nms_to_multiclass_nms_ie.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_multiclass_nms_to_multiclass_nms_ie.cpp @@ -2,19 +2,18 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" -#include -#include +#include "transformations/op_conversions/convert_multiclass_nms_to_multiclass_nms_ie.hpp" +#include #include #include #include - -#include #include +#include +#include +#include "itt.hpp" #include "ngraph_ops/nms_static_shape_ie.hpp" -#include "transformations/op_conversions/convert_multiclass_nms_to_multiclass_nms_ie.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertMulticlassNmsToMulticlassNmsIE, "ConvertMulticlassNmsToMulticlassNmsIE", 0); @@ -22,7 +21,7 @@ ngraph::pass::ConvertMulticlassNmsToMulticlassNmsIE::ConvertMulticlassNmsToMulti MATCHER_SCOPE(ConvertMulticlassNmsToMulticlassNmsIE); auto nms = ngraph::pattern::wrap_type(); - ngraph::matcher_pass_callback callback = [=](pattern::Matcher &m) { + ngraph::matcher_pass_callback callback = [=](pattern::Matcher& m) { auto nms = std::dynamic_pointer_cast(m.get_match_root()); if (!nms || transformation_callback(nms)) { return false; @@ -39,10 +38,9 @@ ngraph::pass::ConvertMulticlassNmsToMulticlassNmsIE::ConvertMulticlassNmsToMulti auto attrs = nms->get_attrs(); attrs.output_type = force_i32_output_type ? element::i32 : nms->get_output_type(); - auto nms_new = std::make_shared>( - new_args.at(0), - new_args.at(1), - attrs); + auto nms_new = std::make_shared>(new_args.at(0), + new_args.at(1), + attrs); new_ops.emplace_back(nms_new); Output output_0 = nms_new->output(0); diff --git a/src/common/transformations/src/transformations/op_conversions/convert_mvn1_to_mvn6.cpp b/src/common/transformations/src/transformations/op_conversions/convert_mvn1_to_mvn6.cpp index 4f42fbc59bc..773f3e63a82 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_mvn1_to_mvn6.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_mvn1_to_mvn6.cpp @@ -4,13 +4,11 @@ #include "transformations/op_conversions/convert_mvn1_to_mvn6.hpp" -#include - -#include - #include #include #include +#include +#include #include "itt.hpp" @@ -37,12 +35,12 @@ ngraph::pass::ConvertMVN1ToMVN6::ConvertMVN1ToMVN6() { } std::vector axes_v(input_rank.get_length() - start_axis); std::iota(axes_v.begin(), axes_v.end(), start_axis); - auto axes = opset6::Constant::create(ngraph::element::i64, { axes_v.size() }, axes_v); + auto axes = opset6::Constant::create(ngraph::element::i64, {axes_v.size()}, axes_v); auto mvn6_node = std::make_shared(input, - axes, - mvn_node->get_normalize_variance(), - mvn_node->get_eps(), - ngraph::op::MVNEpsMode::OUTSIDE_SQRT); + axes, + mvn_node->get_normalize_variance(), + mvn_node->get_eps(), + ngraph::op::MVNEpsMode::OUTSIDE_SQRT); mvn6_node->set_friendly_name(mvn_node->get_friendly_name()); ngraph::copy_runtime_info(mvn_node, mvn6_node); diff --git a/src/common/transformations/src/transformations/op_conversions/convert_negative.cpp b/src/common/transformations/src/transformations/op_conversions/convert_negative.cpp index 0f66711452b..6b852d9fadb 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_negative.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_negative.cpp @@ -2,15 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/convert_negative.hpp" #include +#include +#include +#include #include -#include -#include -#include +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertNegative, "ConvertNegative", 0); @@ -19,13 +19,14 @@ ngraph::pass::ConvertNegative::ConvertNegative() { auto neg = ngraph::pattern::wrap_type(); ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto neg = std::dynamic_pointer_cast (m.get_match_root()); + auto neg = std::dynamic_pointer_cast(m.get_match_root()); if (!neg) { return false; } - auto mul = std::make_shared(neg->input(0).get_source_output(), - opset1::Constant::create(neg->get_element_type(), Shape{}, {-1})); + auto mul = std::make_shared( + neg->input(0).get_source_output(), + opset1::Constant::create(neg->get_element_type(), Shape{}, {-1})); mul->set_friendly_name(neg->get_friendly_name()); ngraph::copy_runtime_info(neg, mul); ngraph::replace_node(neg, mul); diff --git a/src/common/transformations/src/transformations/op_conversions/convert_nms_to_nms_ie_internal.cpp b/src/common/transformations/src/transformations/op_conversions/convert_nms_to_nms_ie_internal.cpp index b1e6d90f775..4445a06008c 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_nms_to_nms_ie_internal.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_nms_to_nms_ie_internal.cpp @@ -2,18 +2,17 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" -#include -#include +#include "transformations/op_conversions/convert_nms_to_nms_ie_internal.hpp" +#include #include #include - -#include #include +#include +#include +#include "itt.hpp" #include "ngraph_ops/nms_ie_internal.hpp" -#include "transformations/op_conversions/convert_nms_to_nms_ie_internal.hpp" #include "transformations/utils/utils.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertNMSToNMSIEInternal, "ConvertNMSToNMSIEInternal", 0); @@ -22,7 +21,7 @@ ngraph::pass::ConvertNMSToNMSIEInternal::ConvertNMSToNMSIEInternal() { MATCHER_SCOPE(ConvertNMSToNMSIEInternal); auto nms = ngraph::pattern::wrap_type(); - ngraph::matcher_pass_callback callback = [=](pattern::Matcher &m) { + ngraph::matcher_pass_callback callback = [=](pattern::Matcher& m) { auto nms_5 = std::dynamic_pointer_cast(m.get_match_root()); if (!nms_5 || transformation_callback(nms_5)) { return false; @@ -31,9 +30,12 @@ ngraph::pass::ConvertNMSToNMSIEInternal::ConvertNMSToNMSIEInternal() { const auto new_args = nms_5->input_values(); const std::size_t num_of_inputs = new_args.size(); - const auto& arg2 = num_of_inputs > 2 ? new_args.at(2) : ngraph::opset5::Constant::create(element::i32, Shape{}, {0}); - const auto& arg3 = num_of_inputs > 3 ? new_args.at(3) : ngraph::opset5::Constant::create(element::f32, Shape{}, {.0f}); - const auto& arg4 = num_of_inputs > 4 ? new_args.at(4) : ngraph::opset5::Constant::create(element::f32, Shape{}, {.0f}); + const auto& arg2 = + num_of_inputs > 2 ? new_args.at(2) : ngraph::opset5::Constant::create(element::i32, Shape{}, {0}); + const auto& arg3 = + num_of_inputs > 3 ? new_args.at(3) : ngraph::opset5::Constant::create(element::f32, Shape{}, {.0f}); + const auto& arg4 = + num_of_inputs > 4 ? new_args.at(4) : ngraph::opset5::Constant::create(element::f32, Shape{}, {.0f}); // vector of new nGraph operations NodeVector new_ops; @@ -61,15 +63,15 @@ ngraph::pass::ConvertNMSToNMSIEInternal::ConvertNMSToNMSIEInternal() { int center_point_box = 0; switch (nms_5->get_box_encoding()) { - case ::ngraph::opset5::NonMaxSuppression::BoxEncodingType::CENTER: - center_point_box = 1; - break; - case ::ngraph::opset5::NonMaxSuppression::BoxEncodingType::CORNER: - center_point_box = 0; - break; - default: - throw ngraph_error("NonMaxSuppression layer " + nms_5->get_friendly_name() + - " has unsupported box encoding"); + case ::ngraph::opset5::NonMaxSuppression::BoxEncodingType::CENTER: + center_point_box = 1; + break; + case ::ngraph::opset5::NonMaxSuppression::BoxEncodingType::CORNER: + center_point_box = 0; + break; + default: + throw ngraph_error("NonMaxSuppression layer " + nms_5->get_friendly_name() + + " has unsupported box encoding"); } std::shared_ptr nms_legacy{nullptr}; @@ -77,29 +79,29 @@ ngraph::pass::ConvertNMSToNMSIEInternal::ConvertNMSToNMSIEInternal() { if (num_of_inputs > 5 && !nms_5->is_soft_nms_sigma_constant_and_default()) { new_soft_nms_sigma = std::make_shared(new_args.at(5), new_shape_for_soft_nms_sigma, true); new_ops.emplace_back(new_soft_nms_sigma.get_node_shared_ptr()); - nms_legacy = std::make_shared( - new_args.at(0), - new_args.at(1), - new_max_per_class, - new_iou_threshold, - new_score_threshold, - new_soft_nms_sigma, - center_point_box, - nms_5->get_sort_result_descending(), - element::i32, - nms_5->get_output_element_type(1)); + nms_legacy = + std::make_shared(new_args.at(0), + new_args.at(1), + new_max_per_class, + new_iou_threshold, + new_score_threshold, + new_soft_nms_sigma, + center_point_box, + nms_5->get_sort_result_descending(), + element::i32, + nms_5->get_output_element_type(1)); new_ops.push_back(nms_legacy); } else { - nms_legacy = std::make_shared( - new_args.at(0), - new_args.at(1), - new_max_per_class, - new_iou_threshold, - new_score_threshold, - center_point_box, - nms_5->get_sort_result_descending(), - element::i32, - nms_5->get_output_element_type(1)); + nms_legacy = + std::make_shared(new_args.at(0), + new_args.at(1), + new_max_per_class, + new_iou_threshold, + new_score_threshold, + center_point_box, + nms_5->get_sort_result_descending(), + element::i32, + nms_5->get_output_element_type(1)); new_ops.push_back(nms_legacy); } diff --git a/src/common/transformations/src/transformations/op_conversions/convert_pad_to_group_conv.cpp b/src/common/transformations/src/transformations/op_conversions/convert_pad_to_group_conv.cpp index c5695b6eb3b..c5291cd88bd 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_pad_to_group_conv.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_pad_to_group_conv.cpp @@ -2,16 +2,16 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/convert_pad_to_group_conv.hpp" #include +#include +#include +#include +#include #include -#include -#include -#include -#include +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertPadToGroupConvolution, "ConvertPadToGroupConvolution", 0); @@ -20,14 +20,14 @@ ngraph::pass::ConvertPadToGroupConvolution::ConvertPadToGroupConvolution() { auto neg = ngraph::pattern::wrap_type(pattern::has_static_dim(1)); ngraph::matcher_pass_callback callback = [this](pattern::Matcher& m) { - auto pad = std::dynamic_pointer_cast (m.get_match_root()); + auto pad = std::dynamic_pointer_cast(m.get_match_root()); if (!pad) { return false; } auto input = pad->input_value(0); - const auto & channel_dim = input.get_partial_shape()[1].get_length(); - const auto & rank = input.get_partial_shape().rank().get_length(); + const auto& channel_dim = input.get_partial_shape()[1].get_length(); + const auto& rank = input.get_partial_shape().rank().get_length(); if (rank < 4) { // We can not create Convolution without spatial dimensions. // Also creating Convolution with single spatial dimension won't be effective as @@ -41,7 +41,8 @@ ngraph::pass::ConvertPadToGroupConvolution::ConvertPadToGroupConvolution() { } if (pad->inputs().size() == 4) { - if (auto pad_value = std::dynamic_pointer_cast(pad->input_value(3).get_node_shared_ptr())) { + if (auto pad_value = + std::dynamic_pointer_cast(pad->input_value(3).get_node_shared_ptr())) { // pad value is a scalar if (pad_value->cast_vector()[0] != 0) { return false; @@ -50,8 +51,8 @@ ngraph::pass::ConvertPadToGroupConvolution::ConvertPadToGroupConvolution() { } // Check that Pad has padding only for spatial dimensions - const auto & pad_begin = pad->get_pads_begin(); - const auto & pad_end = pad->get_pads_end(); + const auto& pad_begin = pad->get_pads_begin(); + const auto& pad_end = pad->get_pads_end(); if (pad_begin.empty() || pad_end.empty()) { // pads will be empty if inputs are not constants @@ -59,14 +60,20 @@ ngraph::pass::ConvertPadToGroupConvolution::ConvertPadToGroupConvolution() { } // Check that not spatial dimension are not padded - if (std::any_of(pad_begin.begin(), pad_begin.begin() + 2, [](ptrdiff_t value) { return value != 0; }) || - std::any_of(pad_end.begin(), pad_end.begin() + 2, [](ptrdiff_t value) { return value != 0; })) { + if (std::any_of(pad_begin.begin(), + pad_begin.begin() + 2, + [](ptrdiff_t value) { + return value != 0; + }) || + std::any_of(pad_end.begin(), pad_end.begin() + 2, [](ptrdiff_t value) { + return value != 0; + })) { return false; } // Create fake weights with ones GOIXY Shape weights_shape(rank + 1, 1); - weights_shape[0] = channel_dim; // G dimension + weights_shape[0] = channel_dim; // G dimension auto weights = opset4::Constant::create(pad->input(0).get_element_type(), weights_shape, {1}); // Create GroupConvolution attributes @@ -74,7 +81,8 @@ ngraph::pass::ConvertPadToGroupConvolution::ConvertPadToGroupConvolution() { CoordinateDiff new_pad_begin{pad_begin.begin() + 2, pad_begin.end()}; CoordinateDiff new_pad_end{pad_end.begin() + 2, pad_end.end()}; - auto conv = std::make_shared(input, weights, stride, new_pad_begin, new_pad_end, stride); + auto conv = + std::make_shared(input, weights, stride, new_pad_begin, new_pad_end, stride); conv->set_friendly_name(pad->get_friendly_name()); ngraph::copy_runtime_info(pad, conv); diff --git a/src/common/transformations/src/transformations/op_conversions/convert_previous_nms_to_nms_5.cpp b/src/common/transformations/src/transformations/op_conversions/convert_previous_nms_to_nms_5.cpp index c81e1e1caeb..10dc4ba635e 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_previous_nms_to_nms_5.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_previous_nms_to_nms_5.cpp @@ -2,19 +2,19 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/convert_previous_nms_to_nms_5.hpp" #include #include -#include - #include #include #include #include -#include #include +#include +#include + +#include "itt.hpp" using namespace ngraph; @@ -26,138 +26,136 @@ struct NMSAttributes { bool is_supported_nms; }; - NMSAttributes get_nms4_attrs(const std::shared_ptr& nms4) { - NMSAttributes attrs; +NMSAttributes get_nms4_attrs(const std::shared_ptr& nms4) { + NMSAttributes attrs; + attrs.box_encoding = ::ngraph::opset5::NonMaxSuppression::BoxEncodingType::CORNER; + attrs.is_supported_nms = true; + attrs.sort_result_descending = true; + attrs.output_type = ::ngraph::element::i64; + + switch (nms4->get_box_encoding()) { + case ::ngraph::opset4::NonMaxSuppression::BoxEncodingType::CENTER: + attrs.box_encoding = ::ngraph::opset5::NonMaxSuppression::BoxEncodingType::CENTER; + break; + case ::ngraph::opset4::NonMaxSuppression::BoxEncodingType::CORNER: attrs.box_encoding = ::ngraph::opset5::NonMaxSuppression::BoxEncodingType::CORNER; - attrs.is_supported_nms = true; - attrs.sort_result_descending = true; - attrs.output_type = ::ngraph::element::i64; - - switch (nms4->get_box_encoding()) { - case ::ngraph::opset4::NonMaxSuppression::BoxEncodingType::CENTER: - attrs.box_encoding = ::ngraph::opset5::NonMaxSuppression::BoxEncodingType::CENTER; - break; - case ::ngraph::opset4::NonMaxSuppression::BoxEncodingType::CORNER: - attrs.box_encoding = ::ngraph::opset5::NonMaxSuppression::BoxEncodingType::CORNER; - break; - default: - throw ngraph_error("NonMaxSuppression layer " + nms4->get_friendly_name() + - " has unsupported box encoding"); - } - - attrs.sort_result_descending = nms4->get_sort_result_descending(); - attrs.output_type = nms4->get_output_type(); - - return attrs; + break; + default: + throw ngraph_error("NonMaxSuppression layer " + nms4->get_friendly_name() + " has unsupported box encoding"); } - NMSAttributes get_nms3_attrs(const std::shared_ptr& nms3) { - NMSAttributes attrs; + attrs.sort_result_descending = nms4->get_sort_result_descending(); + attrs.output_type = nms4->get_output_type(); + return attrs; +} + +NMSAttributes get_nms3_attrs(const std::shared_ptr& nms3) { + NMSAttributes attrs; + + attrs.box_encoding = ::ngraph::opset5::NonMaxSuppression::BoxEncodingType::CORNER; + attrs.is_supported_nms = true; + attrs.sort_result_descending = true; + attrs.output_type = ::ngraph::element::i64; + + switch (nms3->get_box_encoding()) { + case ::ngraph::opset3::NonMaxSuppression::BoxEncodingType::CENTER: + attrs.box_encoding = ::ngraph::opset5::NonMaxSuppression::BoxEncodingType::CENTER; + break; + case ::ngraph::opset3::NonMaxSuppression::BoxEncodingType::CORNER: attrs.box_encoding = ::ngraph::opset5::NonMaxSuppression::BoxEncodingType::CORNER; - attrs.is_supported_nms = true; - attrs.sort_result_descending = true; - attrs.output_type = ::ngraph::element::i64; - - switch (nms3->get_box_encoding()) { - case ::ngraph::opset3::NonMaxSuppression::BoxEncodingType::CENTER: - attrs.box_encoding = ::ngraph::opset5::NonMaxSuppression::BoxEncodingType::CENTER; - break; - case ::ngraph::opset3::NonMaxSuppression::BoxEncodingType::CORNER: - attrs.box_encoding = ::ngraph::opset5::NonMaxSuppression::BoxEncodingType::CORNER; - break; - default: - throw ngraph_error("NonMaxSuppression layer " + nms3->get_friendly_name() + - " has unsupported box encoding"); - } - - attrs.sort_result_descending = nms3->get_sort_result_descending(); - attrs.output_type = nms3->get_output_type(); - - return attrs; + break; + default: + throw ngraph_error("NonMaxSuppression layer " + nms3->get_friendly_name() + " has unsupported box encoding"); } - NMSAttributes get_nms1_attrs(const std::shared_ptr& nms1) { - NMSAttributes attrs; + attrs.sort_result_descending = nms3->get_sort_result_descending(); + attrs.output_type = nms3->get_output_type(); + return attrs; +} + +NMSAttributes get_nms1_attrs(const std::shared_ptr& nms1) { + NMSAttributes attrs; + + attrs.box_encoding = ::ngraph::opset5::NonMaxSuppression::BoxEncodingType::CORNER; + attrs.is_supported_nms = true; + attrs.sort_result_descending = true; + attrs.output_type = ::ngraph::element::i64; + + switch (nms1->get_box_encoding()) { + case ::ngraph::opset1::NonMaxSuppression::BoxEncodingType::CENTER: + attrs.box_encoding = ::ngraph::opset5::NonMaxSuppression::BoxEncodingType::CENTER; + break; + case ::ngraph::opset1::NonMaxSuppression::BoxEncodingType::CORNER: attrs.box_encoding = ::ngraph::opset5::NonMaxSuppression::BoxEncodingType::CORNER; - attrs.is_supported_nms = true; - attrs.sort_result_descending = true; - attrs.output_type = ::ngraph::element::i64; - - switch (nms1->get_box_encoding()) { - case ::ngraph::opset1::NonMaxSuppression::BoxEncodingType::CENTER: - attrs.box_encoding = ::ngraph::opset5::NonMaxSuppression::BoxEncodingType::CENTER; - break; - case ::ngraph::opset1::NonMaxSuppression::BoxEncodingType::CORNER: - attrs.box_encoding = ::ngraph::opset5::NonMaxSuppression::BoxEncodingType::CORNER; - break; - default: - throw ngraph_error("NonMaxSuppression layer " + nms1->get_friendly_name() + - " has unsupported box encoding"); - } - - attrs.sort_result_descending = nms1->get_sort_result_descending(); - - return attrs; + break; + default: + throw ngraph_error("NonMaxSuppression layer " + nms1->get_friendly_name() + " has unsupported box encoding"); } - NMSAttributes get_nms_attrs(const std::shared_ptr& root) { - NMSAttributes attrs; - attrs.output_type = ::ngraph::element::i64; - attrs.box_encoding = ::ngraph::opset5::NonMaxSuppression::BoxEncodingType::CORNER; - attrs.sort_result_descending = false; - attrs.is_supported_nms = false; + attrs.sort_result_descending = nms1->get_sort_result_descending(); - auto nms_4 = std::dynamic_pointer_cast(root); - if (nms_4) { - return get_nms4_attrs(nms_4); - } - auto nms_3 = std::dynamic_pointer_cast(root); - if (nms_3) { - return get_nms3_attrs(nms_3); - } - auto nms_1 = std::dynamic_pointer_cast(root); - if (nms_1) { - return get_nms1_attrs(nms_1); - } + return attrs; +} - return attrs; +NMSAttributes get_nms_attrs(const std::shared_ptr& root) { + NMSAttributes attrs; + attrs.output_type = ::ngraph::element::i64; + attrs.box_encoding = ::ngraph::opset5::NonMaxSuppression::BoxEncodingType::CORNER; + attrs.sort_result_descending = false; + attrs.is_supported_nms = false; + + auto nms_4 = std::dynamic_pointer_cast(root); + if (nms_4) { + return get_nms4_attrs(nms_4); + } + auto nms_3 = std::dynamic_pointer_cast(root); + if (nms_3) { + return get_nms3_attrs(nms_3); + } + auto nms_1 = std::dynamic_pointer_cast(root); + if (nms_1) { + return get_nms1_attrs(nms_1); } - bool callback_func(pattern::Matcher &m, pass::MatcherPass * impl) { - auto root = m.get_match_root(); + return attrs; +} - auto attrs = get_nms_attrs(root); - if (!attrs.is_supported_nms) { - return false; - } +bool callback_func(pattern::Matcher& m, pass::MatcherPass* impl) { + auto root = m.get_match_root(); - const auto new_args = root->input_values(); - - size_t num_of_args = new_args.size(); - - const auto& arg2 = num_of_args > 2 ? new_args.at(2) : ngraph::opset5::Constant::create(element::i64, Shape{}, {0}); - const auto& arg3 = num_of_args > 3 ? new_args.at(3) : ngraph::opset5::Constant::create(element::f32, Shape{}, {.0f}); - const auto& arg4 = num_of_args > 4 ? new_args.at(4) : ngraph::opset5::Constant::create(element::f32, Shape{}, {.0f}); - - const auto nms_5 = impl->register_new_node( - new_args.at(0), - new_args.at(1), - arg2, - arg3, - arg4, - attrs.box_encoding, - attrs.sort_result_descending, - attrs.output_type); - - nms_5->set_friendly_name(root->get_friendly_name()); - ngraph::copy_runtime_info(root, nms_5); - root->output(0).replace(nms_5->output(0)); - return true; + auto attrs = get_nms_attrs(root); + if (!attrs.is_supported_nms) { + return false; } -} // namespace + + const auto new_args = root->input_values(); + + size_t num_of_args = new_args.size(); + + const auto& arg2 = num_of_args > 2 ? new_args.at(2) : ngraph::opset5::Constant::create(element::i64, Shape{}, {0}); + const auto& arg3 = + num_of_args > 3 ? new_args.at(3) : ngraph::opset5::Constant::create(element::f32, Shape{}, {.0f}); + const auto& arg4 = + num_of_args > 4 ? new_args.at(4) : ngraph::opset5::Constant::create(element::f32, Shape{}, {.0f}); + + const auto nms_5 = impl->register_new_node(new_args.at(0), + new_args.at(1), + arg2, + arg3, + arg4, + attrs.box_encoding, + attrs.sort_result_descending, + attrs.output_type); + + nms_5->set_friendly_name(root->get_friendly_name()); + ngraph::copy_runtime_info(root, nms_5); + root->output(0).replace(nms_5->output(0)); + return true; +} +} // namespace NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertNMS4ToNMS5, "ConvertNMS4ToNMS5", 0); diff --git a/src/common/transformations/src/transformations/op_conversions/convert_prior_box_v8_to_v0.cpp b/src/common/transformations/src/transformations/op_conversions/convert_prior_box_v8_to_v0.cpp index c2b8a676484..467ad82f826 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_prior_box_v8_to_v0.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_prior_box_v8_to_v0.cpp @@ -41,7 +41,9 @@ ngraph::pass::ConvertPriorBox8To0::ConvertPriorBox8To0() { attrs_v0.variance = attrs_v8.variance; attrs_v0.scale_all_sizes = attrs_v8.scale_all_sizes; - auto prior_box_v0 = std::make_shared(prior_box_v8_node->input_value(0), prior_box_v8_node->input_value(1), attrs_v0); + auto prior_box_v0 = std::make_shared(prior_box_v8_node->input_value(0), + prior_box_v8_node->input_value(1), + attrs_v0); prior_box_v0->set_friendly_name(prior_box_v8_node->get_friendly_name()); ngraph::copy_runtime_info(prior_box_v8_node, prior_box_v0); ngraph::replace_node(prior_box_v8_node, prior_box_v0); diff --git a/src/common/transformations/src/transformations/op_conversions/convert_reduce_to_pooling.cpp b/src/common/transformations/src/transformations/op_conversions/convert_reduce_to_pooling.cpp index 2010cad4dc6..2bdf5dbe02c 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_reduce_to_pooling.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_reduce_to_pooling.cpp @@ -2,9 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/convert_reduce_to_pooling.hpp" +#include "itt.hpp" + NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertReduceToPooling, "ConvertReduceToPooling", 0); NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertReduceMeanToPooling, "ConvertReduceMeanToPooling", 0); NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertReduceMaxToPooling, "ConvertReduceMaxToPooling", 0); @@ -12,24 +13,28 @@ NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertReduceSumToPooling, "ConvertReduceSu ngraph::pass::ConvertReduceMeanToPooling::ConvertReduceMeanToPooling() { MATCHER_SCOPE(ConvertReduceMeanToPooling); - auto m = std::make_shared(ngraph::pattern::wrap_type({pattern::any_input(pattern::has_static_shape()), - pattern::wrap_type()}, - pattern::has_static_shape()), matcher_name); + auto m = std::make_shared( + ngraph::pattern::wrap_type( + {pattern::any_input(pattern::has_static_shape()), pattern::wrap_type()}, + pattern::has_static_shape()), + matcher_name); register_matcher(m, convert_reduce_to_pooling()); } ngraph::pass::ConvertReduceMaxToPooling::ConvertReduceMaxToPooling() { MATCHER_SCOPE(ConvertReduceMaxToPooling); auto m = std::make_shared( - ngraph::pattern::wrap_type({pattern::any_input(pattern::has_static_shape()), - pattern::wrap_type()}, - pattern::has_static_shape()), matcher_name); + ngraph::pattern::wrap_type( + {pattern::any_input(pattern::has_static_shape()), pattern::wrap_type()}, + pattern::has_static_shape()), + matcher_name); register_matcher(m, convert_reduce_to_pooling()); } ngraph::pass::ConvertReduceSumToPooling::ConvertReduceSumToPooling() { MATCHER_SCOPE(ConvertReduceSumToPooling); auto m = std::make_shared( - ngraph::pattern::wrap_type({pattern::any_input(pattern::has_static_shape()), - pattern::wrap_type()}, - pattern::has_static_shape()), matcher_name); + ngraph::pattern::wrap_type( + {pattern::any_input(pattern::has_static_shape()), pattern::wrap_type()}, + pattern::has_static_shape()), + matcher_name); register_matcher(m, convert_reduce_to_pooling()); } diff --git a/src/common/transformations/src/transformations/op_conversions/convert_scatter_elements_to_scatter.cpp b/src/common/transformations/src/transformations/op_conversions/convert_scatter_elements_to_scatter.cpp index 60ee1a46ab7..5aea4234244 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_scatter_elements_to_scatter.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_scatter_elements_to_scatter.cpp @@ -2,16 +2,16 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/convert_scatter_elements_to_scatter.hpp" #include -#include -#include - #include #include #include +#include +#include + +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertScatterElementsToScatter, "ConvertScatterElementsToScatter", 0); @@ -30,7 +30,8 @@ ngraph::pass::ConvertScatterElementsToScatter::ConvertScatterElementsToScatter() ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { auto scatter = m.get_match_root(); auto broadcast = scatter->input_value(1).get_node_shared_ptr(); - auto axis_const = std::dynamic_pointer_cast(scatter->input_value(3).get_node_shared_ptr()); + auto axis_const = + std::dynamic_pointer_cast(scatter->input_value(3).get_node_shared_ptr()); if (!axis_const) { return false; @@ -43,7 +44,8 @@ ngraph::pass::ConvertScatterElementsToScatter::ConvertScatterElementsToScatter() const auto updates_pshape = scatter->input(2).get_partial_shape(); // Check that ScatterElementsUpdate and Broadcast inputs has static shapes - if (data_pshape.rank().is_dynamic() || indices_pshape.rank().is_dynamic() || updates_pshape.rank().is_dynamic()) { + if (data_pshape.rank().is_dynamic() || indices_pshape.rank().is_dynamic() || + updates_pshape.rank().is_dynamic()) { return false; } @@ -51,45 +53,45 @@ ngraph::pass::ConvertScatterElementsToScatter::ConvertScatterElementsToScatter() const uint64_t updates_rank = updates_pshape.rank().get_length(); const uint64_t indices_rank = indices_pshape.rank().get_length(); - // Check that axis Constant has {} or {1} shape if (shape_size(axis_const->get_shape()) > 1) { return false; } - const size_t axis = ngraph::normalize_axes(scatter->get_friendly_name(), - axis_const->cast_vector(), - data_pshape.rank())[0]; + const size_t axis = ngraph::normalize_axes(scatter->get_friendly_name(), + axis_const->cast_vector(), + data_pshape.rank())[0]; struct Range { uint64_t l, r; - Range(const uint64_t & l, const uint64_t & r) : l(l), r(r) { - if (l > r) throw ngraph_error("Range values are inconsistent"); + Range(const uint64_t& l, const uint64_t& r) : l(l), r(r) { + if (l > r) + throw ngraph_error("Range values are inconsistent"); } uint64_t size() const { return r - l; } - bool operator!= (const Range & rhs) const { + bool operator!=(const Range& rhs) const { return (r - l != rhs.r - rhs.l); } - static - bool is_valid(const int64_t & l, const int64_t & r) { + static bool is_valid(const int64_t& l, const int64_t& r) { return (l >= 0 && l <= r); } - static - bool is_empty(const uint64_t & l, const uint64_t & r) { + static bool is_empty(const uint64_t& l, const uint64_t& r) { return l == r; } }; - auto compare_shapes_ranges = [](const PartialShape & lhsShape, const PartialShape & rhsShape, const Range & lhsRange, const Range & rhsRange) -> bool { + auto compare_shapes_ranges = [](const PartialShape& lhsShape, + const PartialShape& rhsShape, + const Range& lhsRange, + const Range& rhsRange) -> bool { // Check that ranges are equal and suits to Shapes sizes - if (lhsRange != rhsRange || - lhsRange.r > static_cast(lhsShape.rank().get_length()) || + if (lhsRange != rhsRange || lhsRange.r > static_cast(lhsShape.rank().get_length()) || rhsRange.r > static_cast(rhsShape.rank().get_length())) { return false; } @@ -105,7 +107,7 @@ ngraph::pass::ConvertScatterElementsToScatter::ConvertScatterElementsToScatter() return true; }; - auto product = [](const Shape & shape, const Range & range) -> uint64_t { + auto product = [](const Shape& shape, const Range& range) -> uint64_t { uint64_t prod(1); for (size_t dim = range.l; dim < range.r; ++dim) { prod *= shape[dim]; @@ -122,7 +124,8 @@ ngraph::pass::ConvertScatterElementsToScatter::ConvertScatterElementsToScatter() * updates_shape[d_0, d_1, i_0(axis), i_1, ... , i_n, d_axis + 1, ... , d_n] * * EXAMPLE: - * In this example the input shapes are suits the rules above and ScatterElementsUpdate can be replaced with ScatterUpdate + * In this example the input shapes are suits the rules above and ScatterElementsUpdate can be replaced with + * ScatterUpdate * * axis = 1 | (axis) * \/ @@ -172,8 +175,10 @@ ngraph::pass::ConvertScatterElementsToScatter::ConvertScatterElementsToScatter() const auto indices_shape = indices_pshape.get_shape(); Shape indices_new_shape(updates_shape.begin() + axis, updates_shape.begin() + updates_last.l); if (indices_shape != indices_new_shape) { - indices_input = std::make_shared(indices_input, - opset3::Constant::create(element::i64, Shape{indices_new_shape.size()}, indices_new_shape), false); + indices_input = std::make_shared( + indices_input, + opset3::Constant::create(element::i64, Shape{indices_new_shape.size()}, indices_new_shape), + false); new_ops.push_back(indices_input.get_node_shared_ptr()); } } else { @@ -182,7 +187,8 @@ ngraph::pass::ConvertScatterElementsToScatter::ConvertScatterElementsToScatter() // 2. updates_pshape axis interval size = 1 for (size_t dim = 1; dim < indices_rank; ++dim) { - if (indices_pshape[dim] != 1) return false; + if (indices_pshape[dim] != 1) + return false; } if (Range(axis, updates_last.l).size() != 1) { @@ -193,8 +199,9 @@ ngraph::pass::ConvertScatterElementsToScatter::ConvertScatterElementsToScatter() if (indices_rank > 1) { std::vector squeeze_axes(indices_rank - 1ul); std::iota(squeeze_axes.begin(), squeeze_axes.end(), 1); - indices_input = std::make_shared(indices_input, - opset3::Constant::create(element::i64, Shape{squeeze_axes.size()}, squeeze_axes)); + indices_input = std::make_shared( + indices_input, + opset3::Constant::create(element::i64, Shape{squeeze_axes.size()}, squeeze_axes)); new_ops.push_back(indices_input.get_node_shared_ptr()); } } @@ -213,4 +220,3 @@ ngraph::pass::ConvertScatterElementsToScatter::ConvertScatterElementsToScatter() auto m = std::make_shared(scatter, matcher_name); register_matcher(m, callback); } - diff --git a/src/common/transformations/src/transformations/op_conversions/convert_sequences_to_tensor_iterator.cpp b/src/common/transformations/src/transformations/op_conversions/convert_sequences_to_tensor_iterator.cpp index d57dfb1b8e4..38e51cd151d 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_sequences_to_tensor_iterator.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_sequences_to_tensor_iterator.cpp @@ -2,17 +2,17 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" -#include "ngraph/builder/autobroadcast.hpp" #include "transformations/op_conversions/convert_sequences_to_tensor_iterator.hpp" #include +#include +#include +#include +#include #include -#include -#include -#include -#include +#include "itt.hpp" +#include "ngraph/builder/autobroadcast.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertRNNSequenceToTensorIterator, "ConvertRNNSequenceToTensorIterator", 0); NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertGRUSequenceToTensorIterator, "ConvertGRUSequenceToTensorIterator", 0); @@ -20,285 +20,292 @@ NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertLSTMSequenceToTensorIterator, "Conve NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertSequenceToTensorIterator, "ConvertSequenceToTensorIterator", 0); namespace { - ngraph::Output get_current_iter(ngraph::ParameterVector &body_params, - ngraph::ResultVector &body_results, - const ngraph::Output &seq_lengths) { - auto curr_iter_body_param = std::make_shared(seq_lengths.get_element_type(), - ngraph::Shape{1}); - // increment current iteration - auto one = ngraph::opset5::Constant::create(seq_lengths.get_element_type(), ngraph::Shape{1}, {1}); - auto add = std::make_shared(curr_iter_body_param, one); - auto curr_iter_result = std::make_shared(add); - body_params.push_back(curr_iter_body_param); - body_results.push_back(curr_iter_result); - return curr_iter_body_param; +ngraph::Output get_current_iter(ngraph::ParameterVector& body_params, + ngraph::ResultVector& body_results, + const ngraph::Output& seq_lengths) { + auto curr_iter_body_param = + std::make_shared(seq_lengths.get_element_type(), ngraph::Shape{1}); + // increment current iteration + auto one = ngraph::opset5::Constant::create(seq_lengths.get_element_type(), ngraph::Shape{1}, {1}); + auto add = std::make_shared(curr_iter_body_param, one); + auto curr_iter_result = std::make_shared(add); + body_params.push_back(curr_iter_body_param); + body_results.push_back(curr_iter_result); + return curr_iter_body_param; +} + +ngraph::Output get_masked_value(const std::shared_ptr& ti, + ngraph::ParameterVector& body_params, + ngraph::ResultVector& body_results, + const ngraph::Output& current_iter, + const ngraph::Output& data, + const ngraph::Output& seq_lengths) { + // body parameters + auto aggregated_Y_h_body_param = + std::make_shared(data.get_element_type(), data.get_partial_shape()); + + body_params.push_back(aggregated_Y_h_body_param); + + // Create mask node deciding whether or not to mask batch data. + auto batch_seq_length = ngraph::builder::opset1::legacy_broadcast_for_binary_operation(data, seq_lengths, 0); + + auto mask_condition = std::make_shared(current_iter, batch_seq_length); + auto mask_Y_h = std::make_shared(current_iter, batch_seq_length); + + // Select values depending on mask. + // Select(, , ) + auto select_aggregated_H = std::make_shared(mask_Y_h, data, aggregated_Y_h_body_param); + auto aggregated_result = std::make_shared(select_aggregated_H); + body_results.push_back(aggregated_result); + + auto scalar_mask_value = ngraph::opset5::Constant::create(data.get_element_type(), {}, {0.f}); + auto data_shape = ngraph::op::util::make_try_fold(data); + auto mask_value = ngraph::op::util::make_try_fold(scalar_mask_value, data_shape); + return ngraph::op::util::make_try_fold(mask_condition, mask_value, data); +} + +bool convert_sequence_to_ti(const std::shared_ptr& sequence, + const ngraph::Output& X, + const ngraph::Output& H_t, + const ngraph::Output& C_t, + const ngraph::Output& seq_lengths, + const ngraph::Output& W, + const ngraph::Output& R, + const ngraph::Output& B, + const ngraph::op::RecurrentSequenceDirection& direction) { + auto X_pshape = X.get_partial_shape(); + if (X_pshape.size() < 2 || X_pshape[1].is_dynamic()) { + return false; } - ngraph::Output get_masked_value(const std::shared_ptr &ti, - ngraph::ParameterVector &body_params, - ngraph::ResultVector &body_results, - const ngraph::Output ¤t_iter, - const ngraph::Output &data, - const ngraph::Output &seq_lengths) { - // body parameters - auto aggregated_Y_h_body_param = std::make_shared(data.get_element_type(), data.get_partial_shape()); + auto max_seq_len = X_pshape[1].get_length(); + bool enable_mask = ngraph::op::util::is_seq_len_provided(seq_lengths.get_node_shared_ptr(), max_seq_len); - body_params.push_back(aggregated_Y_h_body_param); - - // Create mask node deciding whether or not to mask batch data. - auto batch_seq_length = ngraph::builder::opset1::legacy_broadcast_for_binary_operation(data, seq_lengths, 0); - - auto mask_condition = std::make_shared(current_iter, batch_seq_length); - auto mask_Y_h = std::make_shared(current_iter, batch_seq_length); - - // Select values depending on mask. - // Select(, , ) - auto select_aggregated_H = std::make_shared(mask_Y_h, data, aggregated_Y_h_body_param); - auto aggregated_result = std::make_shared(select_aggregated_H); - body_results.push_back(aggregated_result); - - auto scalar_mask_value = ngraph::opset5::Constant::create(data.get_element_type(), {}, { 0.f }); - auto data_shape = ngraph::op::util::make_try_fold(data); - auto mask_value = ngraph::op::util::make_try_fold(scalar_mask_value, data_shape); - return ngraph::op::util::make_try_fold(mask_condition, mask_value, data); + const bool is_reverse = direction == ngraph::op::RecurrentSequenceDirection::REVERSE; + std::shared_ptr reverse_seq_before; + if (is_reverse && enable_mask) { + reverse_seq_before = std::make_shared(X, seq_lengths, 0, 1); } - bool convert_sequence_to_ti( - const std::shared_ptr& sequence, - const ngraph::Output& X, - const ngraph::Output& H_t, - const ngraph::Output& C_t, - const ngraph::Output& seq_lengths, - const ngraph::Output& W, - const ngraph::Output& R, - const ngraph::Output& B, - const ngraph::op::RecurrentSequenceDirection& direction) { - auto X_pshape = X.get_partial_shape(); - if (X_pshape.size() < 2 || X_pshape[1].is_dynamic()) { - return false; - } + auto axis_0 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); + auto axis_1 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto max_seq_len = X_pshape[1].get_length(); - bool enable_mask = ngraph::op::util::is_seq_len_provided(seq_lengths.get_node_shared_ptr(), max_seq_len); + // TensorIterator Body: begin + auto X_param_pshape = X_pshape; + X_param_pshape[1] = 1; // split by seq_lengths dimension + auto X_body_param = std::make_shared(X.get_element_type(), X_param_pshape); - const bool is_reverse = direction == ngraph::op::RecurrentSequenceDirection::REVERSE; - std::shared_ptr reverse_seq_before; - if (is_reverse && enable_mask) { - reverse_seq_before = std::make_shared(X, seq_lengths, 0, 1); - } + const auto squeezed_h = ngraph::op::util::make_try_fold(H_t, axis_1); + auto H_body_param = std::make_shared(squeezed_h->get_element_type(), + squeezed_h->get_output_partial_shape(0)); + auto seq_body_param = + std::make_shared(seq_lengths.get_element_type(), seq_lengths.get_partial_shape()); - auto axis_0 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{ 1 }, { 0 }); - auto axis_1 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{ 1 }, { 1 }); + // LSTM sequence case + const bool cell_state_defined = C_t.get_node_shared_ptr() != nullptr; + std::shared_ptr C_body_param = nullptr; + std::shared_ptr squeezed_c = nullptr; + if (cell_state_defined) { + squeezed_c = ngraph::op::util::make_try_fold(C_t, axis_1); + C_body_param = std::make_shared(squeezed_c->get_element_type(), + squeezed_c->get_output_partial_shape(0)); + } - // TensorIterator Body: begin - auto X_param_pshape = X_pshape; - X_param_pshape[1] = 1; // split by seq_lengths dimension - auto X_body_param = std::make_shared(X.get_element_type(), X_param_pshape); + const auto squeezed_x = ngraph::op::util::make_try_fold(X_body_param, axis_1); + const auto squeezed_w = ngraph::op::util::make_try_fold(W, axis_0); + const auto squeezed_r = ngraph::op::util::make_try_fold(R, axis_0); + const auto squeezed_b = ngraph::op::util::make_try_fold(B, axis_0); - const auto squeezed_h = ngraph::op::util::make_try_fold(H_t, axis_1); - auto H_body_param = std::make_shared(squeezed_h->get_element_type(), squeezed_h->get_output_partial_shape(0)); - auto seq_body_param = std::make_shared(seq_lengths.get_element_type(), seq_lengths.get_partial_shape()); + std::shared_ptr cell; + if (const auto lstm_sequence = ngraph::as_type_ptr(sequence)) { + cell = std::make_shared(squeezed_x, + H_body_param, + C_body_param, + squeezed_w, + squeezed_r, + squeezed_b, + lstm_sequence->get_hidden_size(), + lstm_sequence->get_activations(), + lstm_sequence->get_activations_alpha(), + lstm_sequence->get_activations_beta(), + lstm_sequence->get_clip()); + } else if (const auto rnn_sequence = ngraph::as_type_ptr(sequence)) { + cell = std::make_shared(squeezed_x, + H_body_param, + squeezed_w, + squeezed_r, + squeezed_b, + rnn_sequence->get_hidden_size(), + rnn_sequence->get_activations(), + rnn_sequence->get_activations_alpha(), + rnn_sequence->get_activations_beta(), + rnn_sequence->get_clip()); + } else if (const auto gnn_sequence = ngraph::as_type_ptr(sequence)) { + cell = std::make_shared(squeezed_x, + H_body_param, + squeezed_w, + squeezed_r, + squeezed_b, + gnn_sequence->get_hidden_size(), + gnn_sequence->get_activations(), + gnn_sequence->get_activations_alpha(), + gnn_sequence->get_activations_beta(), + gnn_sequence->get_clip(), + gnn_sequence->get_linear_before_reset()); + } else { + return false; + } - // LSTM sequence case - const bool cell_state_defined = C_t.get_node_shared_ptr() != nullptr; - std::shared_ptr C_body_param = nullptr; - std::shared_ptr squeezed_c = nullptr; - if (cell_state_defined) { - squeezed_c = ngraph::op::util::make_try_fold(C_t, axis_1); - C_body_param = std::make_shared(squeezed_c->get_element_type(), squeezed_c->get_output_partial_shape(0)); - } + ngraph::ParameterVector body_params; + ngraph::ResultVector body_results; - const auto squeezed_x = ngraph::op::util::make_try_fold(X_body_param, axis_1); - const auto squeezed_w = ngraph::op::util::make_try_fold(W, axis_0); - const auto squeezed_r = ngraph::op::util::make_try_fold(R, axis_0); - const auto squeezed_b = ngraph::op::util::make_try_fold(B, axis_0); + ngraph::Output hidden_state = cell->output(0); + ngraph::Output cell_state; + if (cell_state_defined) + cell_state = cell->output(1); - std::shared_ptr cell; - if (const auto lstm_sequence = ngraph::as_type_ptr(sequence)) { - cell = std::make_shared( - squeezed_x, - H_body_param, - C_body_param, - squeezed_w, - squeezed_r, - squeezed_b, - lstm_sequence->get_hidden_size(), - lstm_sequence->get_activations(), - lstm_sequence->get_activations_alpha(), - lstm_sequence->get_activations_beta(), - lstm_sequence->get_clip()); - } else if (const auto rnn_sequence = ngraph::as_type_ptr(sequence)) { - cell = std::make_shared( - squeezed_x, - H_body_param, - squeezed_w, - squeezed_r, - squeezed_b, - rnn_sequence->get_hidden_size(), - rnn_sequence->get_activations(), - rnn_sequence->get_activations_alpha(), - rnn_sequence->get_activations_beta(), - rnn_sequence->get_clip()); - } else if (const auto gnn_sequence = ngraph::as_type_ptr(sequence)) { - cell = std::make_shared( - squeezed_x, - H_body_param, - squeezed_w, - squeezed_r, - squeezed_b, - gnn_sequence->get_hidden_size(), - gnn_sequence->get_activations(), - gnn_sequence->get_activations_alpha(), - gnn_sequence->get_activations_beta(), - gnn_sequence->get_clip(), - gnn_sequence->get_linear_before_reset()); + auto tensor_iterator = std::make_shared(); + if (enable_mask) { + const auto current_iter = get_current_iter(body_params, body_results, seq_body_param); + hidden_state = + get_masked_value(tensor_iterator, body_params, body_results, current_iter, hidden_state, seq_body_param); + if (cell_state_defined) + cell_state = + get_masked_value(tensor_iterator, body_params, body_results, current_iter, cell_state, seq_body_param); + } + + auto H_res = std::make_shared(hidden_state); + auto C_res = cell_state_defined ? std::make_shared(cell_state) : nullptr; + auto hidden_state_unsqueezed = std::make_shared(hidden_state, axis_1); + auto concat_res = std::make_shared(hidden_state_unsqueezed); + + body_params.push_back(X_body_param); + body_params.push_back(H_body_param); + if (cell_state_defined) + body_params.push_back(C_body_param); + body_params.push_back(seq_body_param); + + body_results.push_back(concat_res); + body_results.push_back(H_res); + if (cell_state_defined) + body_results.push_back(C_res); + + auto body = std::make_shared(body_results, body_params); + tensor_iterator->set_function(body); + // TensorIterator Body: end + if (is_reverse) { + if (!enable_mask) { + // Reversed order, stride -1 + tensor_iterator->set_sliced_input(X_body_param, X, -1, -1, 1, 0, 1); + tensor_iterator->get_concatenated_slices(concat_res, -1, -1, 1, 0, 1); } else { - return false; - } - - ngraph::ParameterVector body_params; - ngraph::ResultVector body_results; - - ngraph::Output hidden_state = cell->output(0); - ngraph::Output cell_state; - if (cell_state_defined) - cell_state = cell->output(1); - - auto tensor_iterator = std::make_shared(); - if (enable_mask) { - const auto current_iter = get_current_iter(body_params, body_results, seq_body_param); - hidden_state = get_masked_value(tensor_iterator, body_params, body_results, current_iter, hidden_state, seq_body_param); - if (cell_state_defined) - cell_state = get_masked_value(tensor_iterator, body_params, body_results, current_iter, cell_state, seq_body_param); - } - - auto H_res = std::make_shared(hidden_state); - auto C_res = cell_state_defined ? std::make_shared(cell_state) : nullptr; - auto hidden_state_unsqueezed = std::make_shared(hidden_state, axis_1); - auto concat_res = std::make_shared(hidden_state_unsqueezed); - - body_params.push_back(X_body_param); - body_params.push_back(H_body_param); - if (cell_state_defined) - body_params.push_back(C_body_param); - body_params.push_back(seq_body_param); - - body_results.push_back(concat_res); - body_results.push_back(H_res); - if (cell_state_defined) - body_results.push_back(C_res); - - auto body = std::make_shared(body_results, body_params); - tensor_iterator->set_function(body); - // TensorIterator Body: end - if (is_reverse) { - if (!enable_mask) { - // Reversed order, stride -1 - tensor_iterator->set_sliced_input(X_body_param, X, -1, -1, 1, 0, 1); - tensor_iterator->get_concatenated_slices(concat_res, -1, -1, 1, 0, 1); - } else { - // use ReverseSequence as initializer - tensor_iterator->set_sliced_input(X_body_param, reverse_seq_before, 0, 1, 1, -1, 1); - tensor_iterator->get_concatenated_slices(concat_res, 0, 1, 1, -1, 1); - } - } else { - // forward order - tensor_iterator->set_sliced_input(X_body_param, X, 0, 1, 1, -1, 1); + // use ReverseSequence as initializer + tensor_iterator->set_sliced_input(X_body_param, reverse_seq_before, 0, 1, 1, -1, 1); tensor_iterator->get_concatenated_slices(concat_res, 0, 1, 1, -1, 1); } - - tensor_iterator->set_merged_input(H_body_param, squeezed_h, H_res); - if (cell_state_defined) - tensor_iterator->set_merged_input(C_body_param, squeezed_c, C_res); - tensor_iterator->set_invariant_input(seq_body_param, seq_lengths); - - ngraph::Output H_out = H_res; - ngraph::Output C_out = C_res; - if (enable_mask) { - // create initial values for body_parameters in outer graph - // aggregated Y_h - concatenation of the last non-zero values for each batch - auto H_body_param_shape = ngraph::op::util::make_try_fold(H_body_param); - auto aggregated_Y_h_scalar = ngraph::opset5::Constant::create(H_body_param->get_element_type(), {}, { 0.f }); - auto aggregated_Y_h = ngraph::op::util::make_try_fold(aggregated_Y_h_scalar, H_body_param_shape); - - auto init_val_curr_iter = ngraph::opset5::Constant::create(seq_lengths.get_element_type(), ngraph::Shape{ 1 }, { 1 }); - ngraph::copy_runtime_info(sequence, { aggregated_Y_h, init_val_curr_iter }); - - // set initial value and back edge for current iteration - tensor_iterator->set_merged_input(body_params.at(0), init_val_curr_iter, body_results.at(0)); - // set initial value and back edge for aggregated H - tensor_iterator->set_merged_input(body_params.at(1), aggregated_Y_h, body_results.at(1)); - - H_out = tensor_iterator->get_function()->get_results()[1]; - - if (cell_state_defined) { - auto C_body_param_shape = ngraph::op::util::make_try_fold(C_body_param); - auto aggregated_Y_c_scalar = ngraph::opset5::Constant::create(C_body_param->get_element_type(), {}, { 0.f }); - auto aggregated_Y_c = ngraph::op::util::make_try_fold(aggregated_Y_c_scalar, C_body_param_shape); - ngraph::copy_runtime_info(sequence, aggregated_Y_c); - - // set initial value and back edge for aggregated C - tensor_iterator->set_merged_input(body_params.at(2), aggregated_Y_c, body_results.at(2)); - C_out = tensor_iterator->get_function()->get_results()[2]; - } - } - - tensor_iterator->get_iter_value(H_out); - if (cell_state_defined) - tensor_iterator->get_iter_value(C_out); - tensor_iterator->set_friendly_name(sequence->get_friendly_name()); - ngraph::NodeVector new_nodes{squeezed_h, tensor_iterator}; - if (cell_state_defined) - new_nodes.push_back(squeezed_c); - ngraph::OutputVector nodes_to_replace; - if (enable_mask && is_reverse) { - auto reverse_seq_after = std::make_shared(tensor_iterator->output(0), seq_lengths, 0, 1); - // Resolve a collision of names data nodes in CNN Network in Reverse case with mask. - /* - * Before transformation (no collisions) - * RNN/LSTM/GRU Sequence [rnn_name] -- (data_node: rnn_name.0) - > Result1 - * -- (data_node: rnn_name.1) - > Result2 - * - * - * After transformation (without identity, there are collisions): - * We need to set rnn_name.0 to RevSequence to store result name. - * TI [rnn_name] -- (DATA_NODE: rnn_name.0) --> RevSequence [rnn_name.0] -- (DATA_NODE: rnn_name.0) -> Result1 - * -- (data_node: rnn_name.1) --> Result2 - * - * - * After transformation (with identity, no collisions): - * TI has other_name, but it doesn't affect result names due TI is not connected to Results directly. - * TI [other_name] -- (data_node: other_name.0) --> RevSequence [rnn_name.0] -- (data_node: rnn_name.0) -> Result1 - * -- (data_node: other_name.1) --> Identity(rnn_name.1) -- (data_node: rnn_name.1) -> Result2 - */ - new_nodes.push_back(reverse_seq_before); - new_nodes.push_back(reverse_seq_after); - nodes_to_replace.push_back(reverse_seq_after); - nodes_to_replace.push_back(tensor_iterator->output(1)); - - if (cell_state_defined) { - auto cell_state = tensor_iterator->output(2); - new_nodes.emplace_back(cell_state.get_node_shared_ptr()); - nodes_to_replace.emplace_back(cell_state); - } - - tensor_iterator->set_friendly_name(sequence->get_friendly_name() + "/tensor_iterator"); - } else { - nodes_to_replace = tensor_iterator->outputs(); - } - - for (size_t i = 0; i < nodes_to_replace.size(); i++) { - auto unsqueeze = std::make_shared(nodes_to_replace[i], axis_1); - unsqueeze->set_friendly_name(sequence->get_friendly_name() + "." + std::to_string(i)); - nodes_to_replace[i] = unsqueeze; - new_nodes.push_back(unsqueeze); - } - ngraph::copy_runtime_info(sequence, new_nodes); - ngraph::replace_node(sequence, nodes_to_replace); - - return true; + } else { + // forward order + tensor_iterator->set_sliced_input(X_body_param, X, 0, 1, 1, -1, 1); + tensor_iterator->get_concatenated_slices(concat_res, 0, 1, 1, -1, 1); } -} // namespace + + tensor_iterator->set_merged_input(H_body_param, squeezed_h, H_res); + if (cell_state_defined) + tensor_iterator->set_merged_input(C_body_param, squeezed_c, C_res); + tensor_iterator->set_invariant_input(seq_body_param, seq_lengths); + + ngraph::Output H_out = H_res; + ngraph::Output C_out = C_res; + if (enable_mask) { + // create initial values for body_parameters in outer graph + // aggregated Y_h - concatenation of the last non-zero values for each batch + auto H_body_param_shape = ngraph::op::util::make_try_fold(H_body_param); + auto aggregated_Y_h_scalar = ngraph::opset5::Constant::create(H_body_param->get_element_type(), {}, {0.f}); + auto aggregated_Y_h = + ngraph::op::util::make_try_fold(aggregated_Y_h_scalar, H_body_param_shape); + + auto init_val_curr_iter = + ngraph::opset5::Constant::create(seq_lengths.get_element_type(), ngraph::Shape{1}, {1}); + ngraph::copy_runtime_info(sequence, {aggregated_Y_h, init_val_curr_iter}); + + // set initial value and back edge for current iteration + tensor_iterator->set_merged_input(body_params.at(0), init_val_curr_iter, body_results.at(0)); + // set initial value and back edge for aggregated H + tensor_iterator->set_merged_input(body_params.at(1), aggregated_Y_h, body_results.at(1)); + + H_out = tensor_iterator->get_function()->get_results()[1]; + + if (cell_state_defined) { + auto C_body_param_shape = ngraph::op::util::make_try_fold(C_body_param); + auto aggregated_Y_c_scalar = ngraph::opset5::Constant::create(C_body_param->get_element_type(), {}, {0.f}); + auto aggregated_Y_c = + ngraph::op::util::make_try_fold(aggregated_Y_c_scalar, C_body_param_shape); + ngraph::copy_runtime_info(sequence, aggregated_Y_c); + + // set initial value and back edge for aggregated C + tensor_iterator->set_merged_input(body_params.at(2), aggregated_Y_c, body_results.at(2)); + C_out = tensor_iterator->get_function()->get_results()[2]; + } + } + + tensor_iterator->get_iter_value(H_out); + if (cell_state_defined) + tensor_iterator->get_iter_value(C_out); + tensor_iterator->set_friendly_name(sequence->get_friendly_name()); + ngraph::NodeVector new_nodes{squeezed_h, tensor_iterator}; + if (cell_state_defined) + new_nodes.push_back(squeezed_c); + ngraph::OutputVector nodes_to_replace; + if (enable_mask && is_reverse) { + auto reverse_seq_after = + std::make_shared(tensor_iterator->output(0), seq_lengths, 0, 1); + // Resolve a collision of names data nodes in CNN Network in Reverse case with mask. + /* + * Before transformation (no collisions) + * RNN/LSTM/GRU Sequence [rnn_name] -- (data_node: rnn_name.0) - > Result1 + * -- (data_node: rnn_name.1) - > Result2 + * + * + * After transformation (without identity, there are collisions): + * We need to set rnn_name.0 to RevSequence to store result name. + * TI [rnn_name] -- (DATA_NODE: rnn_name.0) --> RevSequence [rnn_name.0] -- (DATA_NODE: rnn_name.0) -> Result1 + * -- (data_node: rnn_name.1) --> Result2 + * + * + * After transformation (with identity, no collisions): + * TI has other_name, but it doesn't affect result names due TI is not connected to Results directly. + * TI [other_name] -- (data_node: other_name.0) --> RevSequence [rnn_name.0] -- (data_node: rnn_name.0) -> + * Result1 + * -- (data_node: other_name.1) --> Identity(rnn_name.1) -- (data_node: rnn_name.1) -> Result2 + */ + new_nodes.push_back(reverse_seq_before); + new_nodes.push_back(reverse_seq_after); + nodes_to_replace.push_back(reverse_seq_after); + nodes_to_replace.push_back(tensor_iterator->output(1)); + + if (cell_state_defined) { + auto cell_state = tensor_iterator->output(2); + new_nodes.emplace_back(cell_state.get_node_shared_ptr()); + nodes_to_replace.emplace_back(cell_state); + } + + tensor_iterator->set_friendly_name(sequence->get_friendly_name() + "/tensor_iterator"); + } else { + nodes_to_replace = tensor_iterator->outputs(); + } + + for (size_t i = 0; i < nodes_to_replace.size(); i++) { + auto unsqueeze = std::make_shared(nodes_to_replace[i], axis_1); + unsqueeze->set_friendly_name(sequence->get_friendly_name() + "." + std::to_string(i)); + nodes_to_replace[i] = unsqueeze; + new_nodes.push_back(unsqueeze); + } + ngraph::copy_runtime_info(sequence, new_nodes); + ngraph::replace_node(sequence, nodes_to_replace); + + return true; +} +} // namespace ngraph::pass::ConvertRNNSequenceToTensorIterator::ConvertRNNSequenceToTensorIterator() { MATCHER_SCOPE(ConvertRNNSequenceToTensorIterator); @@ -310,24 +317,33 @@ ngraph::pass::ConvertRNNSequenceToTensorIterator::ConvertRNNSequenceToTensorIter auto B_m = pattern::any_input(); auto rnn_seq = ngraph::pattern::wrap_type({X_m, H_t_m, seq_lengths_m, W_m, R_m, B_m}); - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { auto sequence = ngraph::as_type_ptr(m.get_match_root()); // Bidirectional Sequence op should be decomposed to Reverse + Forward // (e.g. apply BidirectionalRNNSequenceDecomposition transformation before this one) - if (!sequence || sequence->get_direction() == ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL || transformation_callback(sequence)) { + if (!sequence || sequence->get_direction() == ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL || + transformation_callback(sequence)) { return false; } const auto& pattern_map = m.get_pattern_value_map(); - const auto& X = pattern_map.at(X_m); // split - const auto& H_t = pattern_map.at(H_t_m); // merged (init value + back edge) - const auto& seq_lengths = pattern_map.at(seq_lengths_m); // invariant - const auto& W = pattern_map.at(W_m); // const in the body - const auto& R = pattern_map.at(R_m); // const in the body - const auto& B = pattern_map.at(B_m); // const in the body + const auto& X = pattern_map.at(X_m); // split + const auto& H_t = pattern_map.at(H_t_m); // merged (init value + back edge) + const auto& seq_lengths = pattern_map.at(seq_lengths_m); // invariant + const auto& W = pattern_map.at(W_m); // const in the body + const auto& R = pattern_map.at(R_m); // const in the body + const auto& B = pattern_map.at(B_m); // const in the body - return convert_sequence_to_ti(sequence, X, H_t, Output(), seq_lengths, W, R, B, sequence->get_direction()); + return convert_sequence_to_ti(sequence, + X, + H_t, + Output(), + seq_lengths, + W, + R, + B, + sequence->get_direction()); }; auto m = std::make_shared(rnn_seq, matcher_name); @@ -344,12 +360,13 @@ ngraph::pass::ConvertGRUSequenceToTensorIterator::ConvertGRUSequenceToTensorIter auto B_m = pattern::any_input(); auto gru_seq = ngraph::pattern::wrap_type({X_m, H_t_m, seq_lengths_m, W_m, R_m, B_m}); - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { auto sequence = ngraph::as_type_ptr(m.get_match_root()); // Bidirectional Sequence op should be decomposed to Reverse + Forward // (e.g. apply BidirectionalRNNSequenceDecomposition transformation before this one) - if (!sequence || sequence->get_direction() == ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL || transformation_callback(sequence)) { + if (!sequence || sequence->get_direction() == ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL || + transformation_callback(sequence)) { return false; } @@ -361,7 +378,15 @@ ngraph::pass::ConvertGRUSequenceToTensorIterator::ConvertGRUSequenceToTensorIter const auto& R = pattern_map.at(R_m); // const in the body const auto& B = pattern_map.at(B_m); // const in the body - return convert_sequence_to_ti(sequence, X, H_t, Output(), seq_lengths, W, R, B, sequence->get_direction()); + return convert_sequence_to_ti(sequence, + X, + H_t, + Output(), + seq_lengths, + W, + R, + B, + sequence->get_direction()); }; auto m = std::make_shared(gru_seq, matcher_name); @@ -384,7 +409,8 @@ ngraph::pass::ConvertLSTMSequenceToTensorIterator::ConvertLSTMSequenceToTensorIt // Bidirectional Sequence op should be decomposed to Reverse + Forward // (e.g. apply BidirectionalRNNSequenceDecomposition transformation before this one) - if (!sequence || sequence->get_direction() == ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL || transformation_callback(sequence)) { + if (!sequence || sequence->get_direction() == ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL || + transformation_callback(sequence)) { return false; } diff --git a/src/common/transformations/src/transformations/op_conversions/convert_shapeof3.cpp b/src/common/transformations/src/transformations/op_conversions/convert_shapeof3.cpp index cf7a84c19fa..ea550eab3a5 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_shapeof3.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_shapeof3.cpp @@ -2,16 +2,16 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/convert_shapeof3.hpp" #include -#include - #include #include -#include #include +#include +#include + +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertShapeOf3, "ConvertShapeOf3", 0); @@ -20,7 +20,7 @@ ngraph::pass::ConvertShapeOf3::ConvertShapeOf3() { auto shapeof = pattern::wrap_type(); ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto shapeof = std::dynamic_pointer_cast (m.get_match_root()); + auto shapeof = std::dynamic_pointer_cast(m.get_match_root()); if (!shapeof) { return false; } diff --git a/src/common/transformations/src/transformations/op_conversions/convert_shuffle_channels3.cpp b/src/common/transformations/src/transformations/op_conversions/convert_shuffle_channels3.cpp index 39cb0d15ed4..4efe3843293 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_shuffle_channels3.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_shuffle_channels3.cpp @@ -2,16 +2,16 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/convert_shuffle_channels3.hpp" #include -#include - #include #include -#include #include +#include +#include + +#include "itt.hpp" using namespace ngraph; @@ -21,7 +21,7 @@ ngraph::pass::ConvertShuffleChannels3::ConvertShuffleChannels3() { MATCHER_SCOPE(ConvertShuffleChannels3); auto shuffle_channels = pattern::wrap_type(); - ngraph::matcher_pass_callback callback = [this](pattern::Matcher &m) { + ngraph::matcher_pass_callback callback = [this](pattern::Matcher& m) { auto shuffle_channels = std::dynamic_pointer_cast<::opset3::ShuffleChannels>(m.get_match_root()); if (!shuffle_channels || transformation_callback(shuffle_channels)) { return false; @@ -51,42 +51,41 @@ ngraph::pass::ConvertShuffleChannels3::ConvertShuffleChannels3() { // get input tensor dimensions divided into parts with help of VariadicSplit auto split_input_dimensions = std::make_shared<::opset2::VariadicSplit>( - original_shape->output(0), - ::opset2::Constant::create(element::i64, Shape({1}), std::vector{0}), - ::opset2::Constant::create(element::i64, Shape({split_lengts.size()}), split_lengts)); + original_shape->output(0), + ::opset2::Constant::create(element::i64, Shape({1}), std::vector{0}), + ::opset2::Constant::create(element::i64, Shape({split_lengts.size()}), split_lengts)); // calculate new dimension of the reshape. Start with two elements of {group, -1} ::OutputVector new_dimensions = { - ::opset2::Constant::create(element::i64, Shape({1}), std::vector{shuffle_group}), - ::opset2::Constant::create(element::i64, Shape({1}), std::vector{-1})}; + ::opset2::Constant::create(element::i64, Shape({1}), std::vector{shuffle_group}), + ::opset2::Constant::create(element::i64, Shape({1}), std::vector{-1})}; // add more elements to the reshape output dimensions based on shuffle_axis std::vector transpose_order; if (shuffle_axis == 0) { new_dimensions.push_back( - std::make_shared<::opset2::ReduceProd>(split_input_dimensions->output(1), reduce_axis_const, true)); + std::make_shared<::opset2::ReduceProd>(split_input_dimensions->output(1), reduce_axis_const, true)); transpose_order = {1, 0, 2}; } else if (shuffle_axis + 1 == input_rank) { - new_dimensions.insert(new_dimensions.begin(), - std::make_shared<::opset2::ReduceProd>(split_input_dimensions->output(0), - reduce_axis_const, true)); + new_dimensions.insert( + new_dimensions.begin(), + std::make_shared<::opset2::ReduceProd>(split_input_dimensions->output(0), reduce_axis_const, true)); transpose_order = {0, 2, 1}; } else { - new_dimensions.insert(new_dimensions.begin(), - std::make_shared<::opset2::ReduceProd>(split_input_dimensions->output(0), - reduce_axis_const, true)); + new_dimensions.insert( + new_dimensions.begin(), + std::make_shared<::opset2::ReduceProd>(split_input_dimensions->output(0), reduce_axis_const, true)); new_dimensions.push_back( - std::make_shared<::opset2::ReduceProd>(split_input_dimensions->output(2), reduce_axis_const, true)); + std::make_shared<::opset2::ReduceProd>(split_input_dimensions->output(2), reduce_axis_const, true)); transpose_order = {0, 2, 1, 3}; } // reshape the tensor to a new shape auto new_shape = std::make_shared<::opset2::Concat>(new_dimensions, 0); auto reshape = std::make_shared<::opset2::Reshape>(shuffle_channels->input_value(0), new_shape, false); // swap dimensions appearing after splitting the "shuffle_axis" dimension into two - auto transpose = std::make_shared<::opset2::Transpose>(reshape->output(0), - ::opset2::Constant::create(element::i64, - Shape({transpose_order.size()}), - transpose_order)); + auto transpose = std::make_shared<::opset2::Transpose>( + reshape->output(0), + ::opset2::Constant::create(element::i64, Shape({transpose_order.size()}), transpose_order)); // restore original shape auto reshape_back = std::make_shared<::opset2::Reshape>(transpose->output(0), original_shape->output(0), false); diff --git a/src/common/transformations/src/transformations/op_conversions/convert_slice_to_strided_slice.cpp b/src/common/transformations/src/transformations/op_conversions/convert_slice_to_strided_slice.cpp index 202041c1737..3ac3c409b47 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_slice_to_strided_slice.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_slice_to_strided_slice.cpp @@ -2,28 +2,27 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include +#include "transformations/op_conversions/convert_slice_to_strided_slice.hpp" +#include #include #include #include +#include -#include "transformations/op_conversions/convert_slice_to_strided_slice.hpp" -#include "transformations/utils/utils.hpp" +#include "itt.hpp" #include "ngraph/node.hpp" #include "ngraph/op/constant.hpp" #include "ngraph/op/util/op_types.hpp" #include "ngraph/validation_util.hpp" - -#include "itt.hpp" +#include "transformations/utils/utils.hpp" using namespace ngraph; NGRAPH_RTTI_DEFINITION(ngraph::pass::SliceToStridedSlice, "SliceToStridedSlice", 0); namespace { - Output align_indices(const Output& indices, +Output align_indices(const Output& indices, const Output& slice_axes, const Output& scatter_axis, size_t slice_indices_length, @@ -39,12 +38,13 @@ namespace { // axes: [2, 3] - apply slice values to 2 and 3 dimension of input data // expected_output_shape: {3, 3, 1, 1} - const auto default_indices = ngraph::opset8::Constant::create(indices.get_element_type(), Shape{slice_indices_length}, {fill_in_value}); - std::shared_ptr adjusted_indices = ngraph::op::util::make_try_fold( - default_indices, - slice_axes, - indices, // updates - scatter_axis); + const auto default_indices = + ngraph::opset8::Constant::create(indices.get_element_type(), Shape{slice_indices_length}, {fill_in_value}); + std::shared_ptr adjusted_indices = + ngraph::op::util::make_try_fold(default_indices, + slice_axes, + indices, // updates + scatter_axis); if (!ngraph::op::is_constant(adjusted_indices)) { new_ops.push_back(default_indices); @@ -95,8 +95,10 @@ ngraph::pass::SliceToStridedSlice::SliceToStridedSlice(bool use_shapes) { std::shared_ptr axes_const; if (slice_node->get_input_size() > 4) { - axes_const = use_shapes ? get_constant_from_source(slice_node->input_value(4)) - : std::dynamic_pointer_cast(slice_node->input_value(4).get_node_shared_ptr()); + axes_const = + use_shapes + ? get_constant_from_source(slice_node->input_value(4)) + : std::dynamic_pointer_cast(slice_node->input_value(4).get_node_shared_ptr()); } else { axes_const = slice_node->get_default_const_axes(start_input); } @@ -109,11 +111,9 @@ ngraph::pass::SliceToStridedSlice::SliceToStridedSlice(bool use_shapes) { auto norm_axes_vec = normalize_axes(slice_node->get_friendly_name(), axes_vec, data_shape.rank()); axes_vec = std::vector(norm_axes_vec.begin(), norm_axes_vec.end()); } else { - const bool need_normalization = std::any_of(axes_vec.begin(), - axes_vec.end(), - [](int64_t axis) { - return axis < 0; - }); + const bool need_normalization = std::any_of(axes_vec.begin(), axes_vec.end(), [](int64_t axis) { + return axis < 0; + }); if (need_normalization) return false; } @@ -133,9 +133,16 @@ ngraph::pass::SliceToStridedSlice::SliceToStridedSlice(bool use_shapes) { stop_input = align_indices(stop_input, slice_axes, scatter_axis, slice_indices_length, 0, new_ops); step_input = align_indices(step_input, slice_axes, scatter_axis, slice_indices_length, 1, new_ops); } - new_ops.insert(new_ops.end(), {start_input.get_node_shared_ptr(), stop_input.get_node_shared_ptr(), step_input.get_node_shared_ptr()}); + new_ops.insert( + new_ops.end(), + {start_input.get_node_shared_ptr(), stop_input.get_node_shared_ptr(), step_input.get_node_shared_ptr()}); - const auto strided_slice = std::make_shared(arg, start_input, stop_input, step_input, begin_end_mask, begin_end_mask); + const auto strided_slice = std::make_shared(arg, + start_input, + stop_input, + step_input, + begin_end_mask, + begin_end_mask); new_ops.push_back(strided_slice); strided_slice->set_friendly_name(slice_node->get_friendly_name()); diff --git a/src/common/transformations/src/transformations/op_conversions/convert_softmax_downgrade.cpp b/src/common/transformations/src/transformations/op_conversions/convert_softmax_downgrade.cpp index 616465ff988..b8fdcd758e3 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_softmax_downgrade.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_softmax_downgrade.cpp @@ -3,11 +3,13 @@ // #include "transformations/op_conversions/convert_softmax_downgrade.hpp" + #include #include -#include #include +#include #include + #include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertSoftMax8ToSoftMax1, "ConvertSoftMax8ToSoftMax1", 0); diff --git a/src/common/transformations/src/transformations/op_conversions/convert_softmax_upgrade.cpp b/src/common/transformations/src/transformations/op_conversions/convert_softmax_upgrade.cpp index f47701ed0f7..438e860f285 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_softmax_upgrade.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_softmax_upgrade.cpp @@ -3,10 +3,12 @@ // #include "transformations/op_conversions/convert_softmax_upgrade.hpp" + #include #include -#include #include +#include + #include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertSoftMax1ToSoftMax8, "ConvertSoftMax1ToSoftMax8", 0); diff --git a/src/common/transformations/src/transformations/op_conversions/convert_space_to_batch.cpp b/src/common/transformations/src/transformations/op_conversions/convert_space_to_batch.cpp index 1a98df74bf0..d9349f00cb7 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_space_to_batch.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_space_to_batch.cpp @@ -2,15 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/convert_space_to_batch.hpp" #include -#include - #include #include #include +#include + +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertSpaceToBatch, "ConvertSpaceToBatch", 0); @@ -18,7 +18,7 @@ void ngraph::pass::ConvertSpaceToBatch::convert_space_to_batch() { MATCHER_SCOPE(ConvertSpaceToBatch_convert_space_to_batch); auto space_to_batch = ngraph::pattern::wrap_type(); ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto space_to_batch = std::dynamic_pointer_cast (m.get_match_root()); + auto space_to_batch = std::dynamic_pointer_cast(m.get_match_root()); if (!space_to_batch) { return false; } @@ -41,7 +41,7 @@ void ngraph::pass::ConvertSpaceToBatch::convert_space_to_batch() { return false; } - const std::vector &block_values = block_const->cast_vector(); + const std::vector& block_values = block_const->cast_vector(); // Zero-pad the start and end of dimensions [D_0, ..., D_{N - 1}] of the input according to // `pads_begin` @@ -49,8 +49,8 @@ void ngraph::pass::ConvertSpaceToBatch::convert_space_to_batch() { // note: P_0 for batch dimension is expected to be 0 (no-padding). // x = [batch + P_0, D_1 + P_1, D_2 + P_2, ..., D_{N - 1} + P_{N - 1}], where P_i = // pads_begin[i] + pads_end[i] - std::shared_ptr flat_node = std::make_shared(data, pads_begin_const, pads_end_const, - ngraph::op::PadMode::CONSTANT); + std::shared_ptr flat_node = + std::make_shared(data, pads_begin_const, pads_end_const, ngraph::op::PadMode::CONSTANT); auto out_shape = flat_node->get_shape(); new_ops.push_back(flat_node); @@ -67,8 +67,7 @@ void ngraph::pass::ConvertSpaceToBatch::convert_space_to_batch() { dispersed_shape.push_back(block_values.at(i)); } - const auto out_pattern = - opset3::Constant::create(element::i64, Shape{dispersed_shape.size()}, dispersed_shape); + const auto out_pattern = opset3::Constant::create(element::i64, Shape{dispersed_shape.size()}, dispersed_shape); flat_node = std::make_shared(flat_node, out_pattern, false); new_ops.push_back(flat_node); @@ -83,9 +82,9 @@ void ngraph::pass::ConvertSpaceToBatch::convert_space_to_batch() { } const auto axes_order_const = - opset3::Constant::create(element::i64, - Shape{axes_order.size()}, - std::vector(axes_order.begin(), axes_order.end())); + opset3::Constant::create(element::i64, + Shape{axes_order.size()}, + std::vector(axes_order.begin(), axes_order.end())); flat_node = std::make_shared(flat_node, axes_order_const); new_ops.push_back(flat_node); @@ -103,8 +102,7 @@ void ngraph::pass::ConvertSpaceToBatch::convert_space_to_batch() { squeezed_shape.push_back(out_shape.at(i) / block_values.at(i)); } - const auto out_pattern_2 = - opset3::Constant::create(element::i64, Shape{squeezed_shape.size()}, squeezed_shape); + const auto out_pattern_2 = opset3::Constant::create(element::i64, Shape{squeezed_shape.size()}, squeezed_shape); flat_node = std::make_shared(flat_node, out_pattern_2, false); new_ops.push_back(flat_node); @@ -122,7 +120,7 @@ void ngraph::pass::ConvertSpaceToBatch::convert_space_to_batch_by_elements() { MATCHER_SCOPE(ConvertSpaceToBatch_convert_space_to_batch_by_elements); auto space_to_batch = ngraph::pattern::wrap_type(); ngraph::matcher_pass_callback callback = [this](pattern::Matcher& m) { - auto space_to_batch = std::dynamic_pointer_cast (m.get_match_root()); + auto space_to_batch = std::dynamic_pointer_cast(m.get_match_root()); if (!space_to_batch) { return false; } @@ -149,11 +147,12 @@ void ngraph::pass::ConvertSpaceToBatch::convert_space_to_batch_by_elements() { if (!block_const || !pads_begin_const || !pads_end_const) { return false; } - const std::vector &block_values = block_const->cast_vector(); + const std::vector& block_values = block_const->cast_vector(); NodeVector new_ops; - std::shared_ptr flat_node = std::make_shared(data, pads_begin_const, pads_end_const, ngraph::op::PadMode::CONSTANT); + std::shared_ptr flat_node = + std::make_shared(data, pads_begin_const, pads_end_const, ngraph::op::PadMode::CONSTANT); new_ops.push_back(flat_node); auto out_shape = flat_node->get_shape(); @@ -168,7 +167,7 @@ void ngraph::pass::ConvertSpaceToBatch::convert_space_to_batch_by_elements() { dispersed_shape[shape_idx] = block_values[block_idx]; axes_order[0] = shape_idx; } else if (shape_idx == block_idx) { - dispersed_shape[shape_idx] = squeezed_shape[sq_shape_idx]/block_values[block_idx]; + dispersed_shape[shape_idx] = squeezed_shape[sq_shape_idx] / block_values[block_idx]; axes_order[axis_idx] = shape_idx; axis_idx--; sq_shape_idx--; @@ -181,13 +180,13 @@ void ngraph::pass::ConvertSpaceToBatch::convert_space_to_batch_by_elements() { } const auto out_pattern_1 = - opset3::Constant::create(element::i64, Shape{dispersed_shape.size()}, dispersed_shape); + opset3::Constant::create(element::i64, Shape{dispersed_shape.size()}, dispersed_shape); const bool special_zero = false; flat_node = std::make_shared(flat_node, out_pattern_1, special_zero); new_ops.push_back(flat_node); const auto axes_order_const = - opset3::Constant::create(element::i64, + opset3::Constant::create(element::i64, Shape{axes_order.size()}, std::vector(axes_order.begin(), axes_order.end())); flat_node = std::make_shared(flat_node, axes_order_const); @@ -195,7 +194,7 @@ void ngraph::pass::ConvertSpaceToBatch::convert_space_to_batch_by_elements() { squeezed_shape[0] *= block_values[block_idx]; squeezed_shape[block_idx] /= block_values[block_idx]; const auto out_pattern_2 = - opset3::Constant::create(element::i64, Shape{squeezed_shape.size()}, squeezed_shape); + opset3::Constant::create(element::i64, Shape{squeezed_shape.size()}, squeezed_shape); flat_node = std::make_shared(flat_node, out_pattern_2, special_zero); new_ops.push_back(flat_node); } diff --git a/src/common/transformations/src/transformations/op_conversions/convert_space_to_depth.cpp b/src/common/transformations/src/transformations/op_conversions/convert_space_to_depth.cpp index cce096721c4..632d0388f33 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_space_to_depth.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_space_to_depth.cpp @@ -2,24 +2,25 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/convert_space_to_depth.hpp" #include +#include +#include +#include #include -#include -#include -#include +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertSpaceToDepth, "ConvertSpaceToDepth", 0); ngraph::pass::ConvertSpaceToDepth::ConvertSpaceToDepth() { MATCHER_SCOPE(ConvertSpaceToDepth); - auto dts = ngraph::pattern::wrap_type({pattern::any_input(pattern::has_static_shape())}); + auto dts = + ngraph::pattern::wrap_type({pattern::any_input(pattern::has_static_shape())}); ngraph::matcher_pass_callback callback = [this](pattern::Matcher& m) { - auto std_node = std::dynamic_pointer_cast (m.get_match_root()); + auto std_node = std::dynamic_pointer_cast(m.get_match_root()); if (!std_node || transformation_callback(std_node)) { return false; } @@ -57,12 +58,12 @@ ngraph::pass::ConvertSpaceToDepth::ConvertSpaceToDepth() { } switch (mode) { - case ngraph::opset1::SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST: - order.push_back(1); - break; - case ngraph::opset1::SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST: - order.insert(order.begin() + 1, 1); - break; + case ngraph::opset1::SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST: + order.push_back(1); + break; + case ngraph::opset1::SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST: + order.insert(order.begin() + 1, 1); + break; } for (size_t i = 0, j = 2; i < spatial_dims; ++i, j += 2) { @@ -78,7 +79,7 @@ ngraph::pass::ConvertSpaceToDepth::ConvertSpaceToDepth() { } shape_end.insert(shape_end.begin() + 1, C); - auto create_constant = [](std::vector & v) -> std::shared_ptr { + auto create_constant = [](std::vector& v) -> std::shared_ptr { return opset1::Constant::create(element::i64, Shape{v.size()}, v); }; diff --git a/src/common/transformations/src/transformations/op_conversions/convert_subtract.cpp b/src/common/transformations/src/transformations/op_conversions/convert_subtract.cpp index 8d8322ccfc6..83315561093 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_subtract.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_subtract.cpp @@ -2,15 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/convert_subtract.hpp" #include +#include +#include +#include #include -#include -#include -#include +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertSubtract, "ConvertSubtract", 0); @@ -42,18 +42,19 @@ ngraph::pass::ConvertSubtract::ConvertSubtract() { ov::is_type(child) || ov::is_type(child) || ov::is_type(child) || - (ov::is_type(child) && - (child->output(0).get_target_inputs().size() == 1ul) && - (ov::is_type(child->output(0).get_target_inputs().begin()->get_node()->shared_from_this()) || - ov::is_type(child->output(0).get_target_inputs().begin() - ->get_node()->shared_from_this())))) { + (ov::is_type(child) && (child->output(0).get_target_inputs().size() == 1ul) && + (ov::is_type( + child->output(0).get_target_inputs().begin()->get_node()->shared_from_this()) || + ov::is_type( + child->output(0).get_target_inputs().begin()->get_node()->shared_from_this())))) { const auto input1Type = sub->input(0).get_element_type(); const auto input2Type = sub->input(1).get_element_type(); if (((input1Type == element::u8) && (input2Type == element::u8)) || ((input1Type == element::i8) && (input2Type == element::i8))) { // we should not execute transformation by reasons: // 1. LPT asymmetric quantization pattern has to be keep as is - // 2. Subtract operation has unsigned/signed integer value which is not safe to multiply by -1 + // 2. Subtract operation has unsigned/signed integer value which is not safe to multiply by + // -1 return false; } } @@ -61,8 +62,9 @@ ngraph::pass::ConvertSubtract::ConvertSubtract() { } } - auto neg = std::make_shared(sub->input(1).get_source_output(), - opset1::Constant::create(sub->get_input_element_type(1), Shape{}, {-1})); + auto neg = std::make_shared( + sub->input(1).get_source_output(), + opset1::Constant::create(sub->get_input_element_type(1), Shape{}, {-1})); auto add = std::make_shared(sub->input(0).get_source_output(), neg); diff --git a/src/common/transformations/src/transformations/op_conversions/convert_ti_to_sequences.cpp b/src/common/transformations/src/transformations/op_conversions/convert_ti_to_sequences.cpp index 662efdcb73f..611b0632366 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_ti_to_sequences.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_ti_to_sequences.cpp @@ -2,20 +2,20 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/convert_ti_to_sequences.hpp" -#include "transformations/utils/utils.hpp" #include +#include +#include +#include +#include +#include +#include +#include #include -#include -#include -#include -#include -#include -#include -#include +#include "itt.hpp" +#include "transformations/utils/utils.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertTensorIteratorToLSTMSequence, "ConvertTensorIteratorToLSTMSequence", 0); NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertTensorIteratorToRNNSequence, "ConvertTensorIteratorToRNNSequence", 0); @@ -23,27 +23,28 @@ NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertTensorIteratorToGRUSequence, "Conver NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertTensorIteratorToSequence, "ConvertTensorIteratorToSequence", 0); namespace { -bool convertTensorIteratorToSequence( - const std::shared_ptr& ti, - const std::shared_ptr& found_cell, - const ngraph::Output& data, - const ngraph::Output& h_pattern, - const ngraph::Output& c_pattern, - const ngraph::Output& w_pattern, - const ngraph::Output& r_pattern, - const ngraph::Output& b_pattern, - const ngraph::Output& unsqueeze_after_cell) { +bool convertTensorIteratorToSequence(const std::shared_ptr& ti, + const std::shared_ptr& found_cell, + const ngraph::Output& data, + const ngraph::Output& h_pattern, + const ngraph::Output& c_pattern, + const ngraph::Output& w_pattern, + const ngraph::Output& r_pattern, + const ngraph::Output& b_pattern, + const ngraph::Output& unsqueeze_after_cell) { const auto& func = ti->get_function(); const auto& params = func->get_parameters(); std::vector> ordered_in_descs(3); int64_t stride = 0, slice_axis = 0; - // Remember the order of the X and initial_hidden_state (+ initial_cell_state in case of LSTM) in the TensorIterator params + // Remember the order of the X and initial_hidden_state (+ initial_cell_state in case of LSTM) in the TensorIterator + // params for (const auto& input_desc : ti->get_input_descriptions()) { auto param = params[input_desc->m_body_parameter_index]; if (param == data.get_node_shared_ptr()) { - auto slice_input = std::dynamic_pointer_cast(input_desc); + auto slice_input = + std::dynamic_pointer_cast(input_desc); if (!slice_input) return false; @@ -70,7 +71,8 @@ bool convertTensorIteratorToSequence( for (const auto& output_desc : ti->get_output_descriptions()) { std::shared_ptr res = results[output_desc->m_body_value_index]; if (res->input_value(0) == unsqueeze_after_cell) { - auto concat_output = std::dynamic_pointer_cast(output_desc); + auto concat_output = + std::dynamic_pointer_cast(output_desc); if (!concat_output) return false; @@ -92,21 +94,24 @@ bool convertTensorIteratorToSequence( X = std::make_shared(ti_inputs[ordered_in_descs[0]->m_input_index], order); } - // We must prepare cell inputs to sequence creation: insert num_directions elem via unsqueeze where needed (please, see specification) + // We must prepare cell inputs to sequence creation: insert num_directions elem via unsqueeze where needed (please, + // see specification) auto axis_1 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto initial_hidden_state = std::make_shared(ti_inputs[ordered_in_descs[1]->m_input_index], axis_1); + auto initial_hidden_state = + std::make_shared(ti_inputs[ordered_in_descs[1]->m_input_index], axis_1); // LSTM case - std::shared_ptr initial_cell_state = c_pattern.get_node_shared_ptr() == nullptr ? - nullptr : - std::make_shared(ti_inputs[ordered_in_descs[2]->m_input_index], axis_1); + std::shared_ptr initial_cell_state = + c_pattern.get_node_shared_ptr() == nullptr + ? nullptr + : std::make_shared(ti_inputs[ordered_in_descs[2]->m_input_index], axis_1); const size_t batch_dim = slice_axis == 0 ? 1 : 0; auto batch_dimension = ngraph::op::util::node_to_get_shape_value_of_indices_from_shape_source( ti_inputs[ordered_in_descs[0]->m_input_index], {batch_dim}); - auto seq_lengths_scalar = ngraph::opset5::Constant::create(ngraph::element::i32, {}, { ti->get_num_iterations() }); + auto seq_lengths_scalar = ngraph::opset5::Constant::create(ngraph::element::i32, {}, {ti->get_num_iterations()}); auto seq_lengths = ngraph::op::util::make_try_fold(seq_lengths_scalar, batch_dimension); auto axis_0 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); @@ -115,51 +120,55 @@ bool convertTensorIteratorToSequence( auto B = ngraph::op::util::make_try_fold(b_pattern, axis_0); std::shared_ptr sequence; - if (ngraph::is_type(found_cell) || ngraph::is_type(found_cell)) { - sequence = std::make_shared( - X, - initial_hidden_state, - initial_cell_state, - seq_lengths, - W, - R, - B, - found_cell->get_hidden_size(), - stride > 0 ? ngraph::op::RecurrentSequenceDirection::FORWARD : ngraph::op::RecurrentSequenceDirection::REVERSE, - found_cell->get_activations_alpha(), - found_cell->get_activations_beta(), - found_cell->get_activations(), - found_cell->get_clip()); + if (ngraph::is_type(found_cell) || + ngraph::is_type(found_cell)) { + sequence = + std::make_shared(X, + initial_hidden_state, + initial_cell_state, + seq_lengths, + W, + R, + B, + found_cell->get_hidden_size(), + stride > 0 ? ngraph::op::RecurrentSequenceDirection::FORWARD + : ngraph::op::RecurrentSequenceDirection::REVERSE, + found_cell->get_activations_alpha(), + found_cell->get_activations_beta(), + found_cell->get_activations(), + found_cell->get_clip()); } else if (ngraph::is_type(found_cell)) { - sequence = std::make_shared( - X, - initial_hidden_state, - seq_lengths, - W, - R, - B, - found_cell->get_hidden_size(), - stride > 0 ? ngraph::op::RecurrentSequenceDirection::FORWARD : ngraph::op::RecurrentSequenceDirection::REVERSE, - found_cell->get_activations(), - found_cell->get_activations_alpha(), - found_cell->get_activations_beta(), - found_cell->get_clip()); + sequence = + std::make_shared(X, + initial_hidden_state, + seq_lengths, + W, + R, + B, + found_cell->get_hidden_size(), + stride > 0 ? ngraph::op::RecurrentSequenceDirection::FORWARD + : ngraph::op::RecurrentSequenceDirection::REVERSE, + found_cell->get_activations(), + found_cell->get_activations_alpha(), + found_cell->get_activations_beta(), + found_cell->get_clip()); } else if (ngraph::is_type(found_cell)) { const auto gru_cell = ngraph::as_type_ptr(found_cell); - sequence = std::make_shared( - X, - initial_hidden_state, - seq_lengths, - W, - R, - B, - gru_cell->get_hidden_size(), - stride > 0 ? ngraph::op::RecurrentSequenceDirection::FORWARD : ngraph::op::RecurrentSequenceDirection::REVERSE, - gru_cell->get_activations(), - gru_cell->get_activations_alpha(), - gru_cell->get_activations_beta(), - gru_cell->get_clip(), - gru_cell->get_linear_before_reset()); + sequence = + std::make_shared(X, + initial_hidden_state, + seq_lengths, + W, + R, + B, + gru_cell->get_hidden_size(), + stride > 0 ? ngraph::op::RecurrentSequenceDirection::FORWARD + : ngraph::op::RecurrentSequenceDirection::REVERSE, + gru_cell->get_activations(), + gru_cell->get_activations_alpha(), + gru_cell->get_activations_beta(), + gru_cell->get_clip(), + gru_cell->get_linear_before_reset()); } else { throw ngraph::ngraph_error("Unsupported sequence type"); } @@ -172,7 +181,7 @@ bool convertTensorIteratorToSequence( ngraph::NodeVector outputs; // We must remove num_directions dimension that was added before sequence creation - auto axis_out = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{ 1 }, { 1 }); + auto axis_out = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); auto out_0 = std::make_shared(out, axis_out); auto out_1 = std::make_shared(sequence->output(1), axis_out); out_0->set_friendly_name(ti->get_friendly_name() + ".0"); @@ -188,11 +197,12 @@ bool convertTensorIteratorToSequence( for (size_t i = 0; i < ordered_out_descs.size(); ++i) { if (ordered_out_descs[i]) { - for (const auto &input : ti->output(ordered_out_descs[i]->m_output_index).get_target_inputs()) { + for (const auto& input : ti->output(ordered_out_descs[i]->m_output_index).get_target_inputs()) { input.replace_source_output(outputs[i]->output(0)); } NGRAPH_SUPPRESS_DEPRECATED_START - outputs[i]->get_output_tensor(0).set_name(ngraph::op::util::create_ie_output_name(ti->output(ordered_out_descs[i]->m_output_index))); + outputs[i]->get_output_tensor(0).set_name( + ngraph::op::util::create_ie_output_name(ti->output(ordered_out_descs[i]->m_output_index))); NGRAPH_SUPPRESS_DEPRECATED_END } } @@ -221,13 +231,13 @@ bool convertTensorIteratorToSequence( copy_runtime_info(ti, new_nodes); return true; } -} // namespace +} // namespace ngraph::pass::ConvertTensorIteratorToLSTMSequence::ConvertTensorIteratorToLSTMSequence() { MATCHER_SCOPE(ConvertTensorIteratorToLSTMSequence); auto tensor_iterator = pattern::wrap_type(); - ngraph::matcher_pass_callback callback = [this](pattern::Matcher &m) { + ngraph::matcher_pass_callback callback = [this](pattern::Matcher& m) { auto ti = std::dynamic_pointer_cast(m.get_match_root()); if (!ti || transformation_callback(ti)) return false; @@ -247,7 +257,7 @@ ngraph::pass::ConvertTensorIteratorToLSTMSequence::ConvertTensorIteratorToLSTMSe auto cell = ngraph::pattern::wrap_type(cell_inputs); auto pattern_2 = ngraph::pattern::wrap_type(ngraph::pattern::rank_equals(1)); - auto unsqueeze = ngraph::pattern::wrap_type({ cell, pattern_2 }); + auto unsqueeze = ngraph::pattern::wrap_type({cell, pattern_2}); ngraph::pattern::Matcher matcher(unsqueeze); bool match = false; @@ -268,14 +278,15 @@ ngraph::pass::ConvertTensorIteratorToLSTMSequence::ConvertTensorIteratorToLSTMSe if (lstm_cell == nullptr) return false; - return convertTensorIteratorToSequence(ti, lstm_cell, - pattern_map.at(data), - pattern_map.at(input_H_state), - pattern_map.at(input_C_state), - pattern_map.at(input_W), - pattern_map.at(input_R), - pattern_map.at(input_B), - pattern_map.at(unsqueeze)); + return convertTensorIteratorToSequence(ti, + lstm_cell, + pattern_map.at(data), + pattern_map.at(input_H_state), + pattern_map.at(input_C_state), + pattern_map.at(input_W), + pattern_map.at(input_R), + pattern_map.at(input_B), + pattern_map.at(unsqueeze)); }; auto m = std::make_shared(tensor_iterator, matcher_name); @@ -286,7 +297,7 @@ ngraph::pass::ConvertTensorIteratorToRNNSequence::ConvertTensorIteratorToRNNSequ MATCHER_SCOPE(ConvertTensorIteratorToRNNSequence); auto tensor_iterator = pattern::wrap_type(); - ngraph::matcher_pass_callback callback = [this](pattern::Matcher &m) { + ngraph::matcher_pass_callback callback = [this](pattern::Matcher& m) { auto ti = std::dynamic_pointer_cast(m.get_match_root()); if (!ti || transformation_callback(ti)) return false; @@ -305,7 +316,7 @@ ngraph::pass::ConvertTensorIteratorToRNNSequence::ConvertTensorIteratorToRNNSequ auto cell = ngraph::pattern::wrap_type(cell_inputs); auto pattern_2 = ngraph::pattern::wrap_type(ngraph::pattern::rank_equals(1)); - auto unsqueeze = ngraph::pattern::wrap_type({ cell, pattern_2 }); + auto unsqueeze = ngraph::pattern::wrap_type({cell, pattern_2}); ngraph::pattern::Matcher matcher(unsqueeze); bool match = false; @@ -321,18 +332,20 @@ ngraph::pass::ConvertTensorIteratorToRNNSequence::ConvertTensorIteratorToRNNSequ return false; const auto& pattern_map = matcher.get_pattern_value_map(); - const auto& rnn_cell = std::dynamic_pointer_cast(pattern_map.at(cell).get_node_shared_ptr()); + const auto& rnn_cell = + std::dynamic_pointer_cast(pattern_map.at(cell).get_node_shared_ptr()); if (rnn_cell == nullptr) return false; - return convertTensorIteratorToSequence(ti, rnn_cell, - pattern_map.at(data), - pattern_map.at(input_H_state), - ngraph::Output(), - pattern_map.at(input_W), - pattern_map.at(input_R), - pattern_map.at(input_B), - pattern_map.at(unsqueeze)); + return convertTensorIteratorToSequence(ti, + rnn_cell, + pattern_map.at(data), + pattern_map.at(input_H_state), + ngraph::Output(), + pattern_map.at(input_W), + pattern_map.at(input_R), + pattern_map.at(input_B), + pattern_map.at(unsqueeze)); }; auto m = std::make_shared(tensor_iterator, matcher_name); @@ -362,7 +375,7 @@ ngraph::pass::ConvertTensorIteratorToGRUSequence::ConvertTensorIteratorToGRUSequ auto cell = ngraph::pattern::wrap_type(cell_inputs); auto pattern_2 = ngraph::pattern::wrap_type(ngraph::pattern::rank_equals(1)); - auto unsqueeze = ngraph::pattern::wrap_type({ cell, pattern_2 }); + auto unsqueeze = ngraph::pattern::wrap_type({cell, pattern_2}); ngraph::pattern::Matcher matcher(unsqueeze); bool match = false; @@ -378,18 +391,20 @@ ngraph::pass::ConvertTensorIteratorToGRUSequence::ConvertTensorIteratorToGRUSequ return false; const auto& pattern_map = matcher.get_pattern_value_map(); - const auto& gru_cell = std::dynamic_pointer_cast(pattern_map.at(cell).get_node_shared_ptr()); + const auto& gru_cell = + std::dynamic_pointer_cast(pattern_map.at(cell).get_node_shared_ptr()); if (gru_cell == nullptr) return false; - return convertTensorIteratorToSequence(ti, gru_cell, - pattern_map.at(data), - pattern_map.at(input_H_state), - ngraph::Output(), - pattern_map.at(input_W), - pattern_map.at(input_R), - pattern_map.at(input_B), - pattern_map.at(unsqueeze)); + return convertTensorIteratorToSequence(ti, + gru_cell, + pattern_map.at(data), + pattern_map.at(input_H_state), + ngraph::Output(), + pattern_map.at(input_W), + pattern_map.at(input_R), + pattern_map.at(input_B), + pattern_map.at(unsqueeze)); }; auto m = std::make_shared(tensor_iterator, matcher_name); diff --git a/src/common/transformations/src/transformations/op_conversions/convert_topk3.cpp b/src/common/transformations/src/transformations/op_conversions/convert_topk3.cpp index 223fda0d0c2..0cb93dc9535 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_topk3.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_topk3.cpp @@ -2,18 +2,17 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/convert_topk3.hpp" #include -#include - #include #include #include -#include - #include +#include +#include + +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertTopK3, "ConvertTopK3", 0); @@ -22,7 +21,7 @@ ngraph::pass::ConvertTopK3::ConvertTopK3() { auto topk = pattern::wrap_type(); ngraph::matcher_pass_callback callback = [](pattern::Matcher& m) { - auto topk = std::dynamic_pointer_cast (m.get_match_root()); + auto topk = std::dynamic_pointer_cast(m.get_match_root()); if (!topk) { return false; } @@ -30,8 +29,12 @@ ngraph::pass::ConvertTopK3::ConvertTopK3() { Output last1; ngraph::NodeVector new_ops; - auto new_topk = std::make_shared(topk->input_value(0), topk->input_value(1), - topk->get_axis(), topk->get_mode(), topk->get_sort_type(), element::i32); + auto new_topk = std::make_shared(topk->input_value(0), + topk->input_value(1), + topk->get_axis(), + topk->get_mode(), + topk->get_sort_type(), + element::i32); new_ops.push_back(new_topk); // if the output is the i32 or output #1 has no consumers // then it matches behavior of the v1::TopK otherwise need to insert Convert diff --git a/src/common/transformations/src/transformations/op_conversions/detection_output_upgrade.cpp b/src/common/transformations/src/transformations/op_conversions/detection_output_upgrade.cpp index 43211b17a36..c86a591bd9b 100644 --- a/src/common/transformations/src/transformations/op_conversions/detection_output_upgrade.cpp +++ b/src/common/transformations/src/transformations/op_conversions/detection_output_upgrade.cpp @@ -48,19 +48,17 @@ pass::ConvertDetectionOutput1ToDetectionOutput8::ConvertDetectionOutput1ToDetect std::shared_ptr detection_output_v8_node = nullptr; if (detection_output_v1_node->get_input_size() == 3) { - detection_output_v8_node = - make_shared(detection_output_v1_node->input_value(0), - detection_output_v1_node->input_value(1), - detection_output_v1_node->input_value(2), - attributes_v8); + detection_output_v8_node = make_shared(detection_output_v1_node->input_value(0), + detection_output_v1_node->input_value(1), + detection_output_v1_node->input_value(2), + attributes_v8); } else if (detection_output_v1_node->get_input_size() == 5) { - detection_output_v8_node = - make_shared(detection_output_v1_node->input_value(0), - detection_output_v1_node->input_value(1), - detection_output_v1_node->input_value(2), - detection_output_v1_node->input_value(3), - detection_output_v1_node->input_value(4), - attributes_v8); + detection_output_v8_node = make_shared(detection_output_v1_node->input_value(0), + detection_output_v1_node->input_value(1), + detection_output_v1_node->input_value(2), + detection_output_v1_node->input_value(3), + detection_output_v1_node->input_value(4), + attributes_v8); } if (!detection_output_v8_node) return false; diff --git a/src/common/transformations/src/transformations/op_conversions/einsum_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/einsum_decomposition.cpp index 4c51af566b4..7bc0de7fbe1 100644 --- a/src/common/transformations/src/transformations/op_conversions/einsum_decomposition.cpp +++ b/src/common/transformations/src/transformations/op_conversions/einsum_decomposition.cpp @@ -57,12 +57,15 @@ std::vector> compute_einsum_path(std::shared_ptr& input_subscripts, const std::string& output_subscript, - const std::string label_to_check, const std::vector& excluded_indices) { +bool is_dimension_reduced(const std::vector& input_subscripts, + const std::string& output_subscript, + const std::string label_to_check, + const std::vector& excluded_indices) { for (size_t input_ind = 0; input_ind < input_subscripts.size(); ++input_ind) { const auto& input_subscript = input_subscripts[input_ind]; // the subscript is checked only if its index is not in excluded indices list - bool check_subscript = (std::find(excluded_indices.begin(), excluded_indices.end(), input_ind) == excluded_indices.end()); + bool check_subscript = + (std::find(excluded_indices.begin(), excluded_indices.end(), input_ind) == excluded_indices.end()); if (check_subscript && input_subscript.find(label_to_check) != std::string::npos) { return false; } @@ -76,7 +79,7 @@ bool is_dimension_reduced(const std::vector& input_subscripts, cons /// /// \return true - the input vector is a range [0; n]; false - otherwise /// -bool is_range_0_to_n(const std::vector &labels_inds) { +bool is_range_0_to_n(const std::vector& labels_inds) { int64_t check_index = 0; for (auto index : labels_inds) { if (check_index != index) { @@ -99,8 +102,10 @@ bool is_range_0_to_n(const std::vector &labels_inds) { /// /// \return An input subscript for grouping dimensions /// -std::string generate_grouping_subscript(const std::string& input_subscript, const std::vector& common_labels_inds, - const std::vector& separate_labels_inds, const std::vector& reduced_labels_inds, +std::string generate_grouping_subscript(const std::string& input_subscript, + const std::vector& common_labels_inds, + const std::vector& separate_labels_inds, + const std::vector& reduced_labels_inds, bool& is_separate_first) { // transpose is not needed if common labels, reduced labels // and separate labels indices go concurrently @@ -142,8 +147,12 @@ std::string generate_grouping_subscript(const std::string& input_subscript, cons /// \param new_node New input node to be inserted in the tail /// \param new_subscript New input subscript to be inserted in the tail /// -void update_operands(ngraph::OutputVector& input_nodes, std::vector& input_subscripts, size_t input_ind1, size_t input_ind2, - const ngraph::Output& new_node, const std::string& new_subscript) { +void update_operands(ngraph::OutputVector& input_nodes, + std::vector& input_subscripts, + size_t input_ind1, + size_t input_ind2, + const ngraph::Output& new_node, + const std::string& new_subscript) { NGRAPH_CHECK(input_ind1 < input_ind2); NGRAPH_CHECK(input_ind2 < input_nodes.size()); NGRAPH_CHECK(input_ind2 < input_subscripts.size()); @@ -167,7 +176,10 @@ void update_operands(ngraph::OutputVector& input_nodes, std::vector /// \return A vector of input nodes that can be empty (if s_end <= s_begin) /// or contains just one input node with sub-shape or its product /// -ngraph::OutputVector compute_sub_shape(const ngraph::Output& data_shape, size_t s_begin, size_t s_end, ngraph::NodeVector& subgraph_nodes, +ngraph::OutputVector compute_sub_shape(const ngraph::Output& data_shape, + size_t s_begin, + size_t s_end, + ngraph::NodeVector& subgraph_nodes, bool is_product = false) { int64_t begin = static_cast(s_begin); int64_t end = static_cast(s_end); @@ -177,14 +189,16 @@ ngraph::OutputVector compute_sub_shape(const ngraph::Output& data_ } std::vector begin_mask(1, 0); std::vector end_mask(1, 0); - auto begin_const = ngraph::opset7::Constant::create(ngraph::element::Type_t::i64, ngraph::Shape {1}, {begin}); - auto end_const = ngraph::opset7::Constant::create(ngraph::element::Type_t::i64, ngraph::Shape {1}, {end}); - auto stride_const = ngraph::opset7::Constant::create(ngraph::element::Type_t::i64, ngraph::Shape {1}, {1}); - auto sub_shape = std::make_shared(data_shape, begin_const, end_const, begin_mask, end_mask); + auto begin_const = ngraph::opset7::Constant::create(ngraph::element::Type_t::i64, ngraph::Shape{1}, {begin}); + auto end_const = ngraph::opset7::Constant::create(ngraph::element::Type_t::i64, ngraph::Shape{1}, {end}); + auto stride_const = ngraph::opset7::Constant::create(ngraph::element::Type_t::i64, ngraph::Shape{1}, {1}); + auto sub_shape = + std::make_shared(data_shape, begin_const, end_const, begin_mask, end_mask); if (is_product) { - auto reduce_axis_const = ngraph::opset7::Constant::create(ngraph::element::Type_t::i64, ngraph::Shape {1}, {0}); - auto separate_shape_prod = std::make_shared(sub_shape->output(0), reduce_axis_const, true); + auto reduce_axis_const = ngraph::opset7::Constant::create(ngraph::element::Type_t::i64, ngraph::Shape{1}, {0}); + auto separate_shape_prod = + std::make_shared(sub_shape->output(0), reduce_axis_const, true); sub_shape_vector.push_back(separate_shape_prod->output(0)); subgraph_nodes.insert(subgraph_nodes.end(), {reduce_axis_const, separate_shape_prod}); } else { @@ -205,12 +219,15 @@ ngraph::OutputVector compute_sub_shape(const ngraph::Output& data_ /// \return Unsqueezed input node if a vector of unsqueezing dimensions is not empty, /// otherwise, the original input node /// -ngraph::Output unsqueeze_input(const ngraph::Output& input_node, const std::vector& unsqueeze_axes, +ngraph::Output unsqueeze_input(const ngraph::Output& input_node, + const std::vector& unsqueeze_axes, ngraph::NodeVector& subgraph_nodes) { if (unsqueeze_axes.empty()) { return input_node; } - auto unsqueeze_axes_const = ngraph::opset7::Constant::create(ngraph::element::Type_t::i64, ngraph::Shape {unsqueeze_axes.size()}, unsqueeze_axes); + auto unsqueeze_axes_const = ngraph::opset7::Constant::create(ngraph::element::Type_t::i64, + ngraph::Shape{unsqueeze_axes.size()}, + unsqueeze_axes); auto unsqueeze = std::make_shared(input_node, unsqueeze_axes_const); subgraph_nodes.insert(subgraph_nodes.end(), {unsqueeze_axes_const, unsqueeze}); return unsqueeze->output(0); @@ -230,9 +247,12 @@ ngraph::Output unsqueeze_input(const ngraph::Output& /// /// \return Reshaped input node /// -ngraph::Output reshape_input_for_matmul(const ngraph::Output& input_node, const ngraph::OutputVector& common_sub_shape, - const ngraph::OutputVector& separate_sub_shape, const ngraph::OutputVector& reduced_sub_shape_prod, - bool is_separate_first, ngraph::NodeVector& subgraph_nodes) { +ngraph::Output reshape_input_for_matmul(const ngraph::Output& input_node, + const ngraph::OutputVector& common_sub_shape, + const ngraph::OutputVector& separate_sub_shape, + const ngraph::OutputVector& reduced_sub_shape_prod, + bool is_separate_first, + ngraph::NodeVector& subgraph_nodes) { ngraph::OutputVector new_shape_parts; new_shape_parts.insert(new_shape_parts.end(), common_sub_shape.begin(), common_sub_shape.end()); @@ -242,14 +262,15 @@ ngraph::Output reshape_input_for_matmul(const ngraph::Output 0) { // in this case compute a product of separate dimension sizes since they must be // presented with just one dimension for MatMul - auto reduce_axis_const = ngraph::opset7::Constant::create(ngraph::element::Type_t::i64, ngraph::Shape {1}, {0}); - auto separate_shape_prod = std::make_shared(separate_sub_shape[0], reduce_axis_const, true); + auto reduce_axis_const = ngraph::opset7::Constant::create(ngraph::element::Type_t::i64, ngraph::Shape{1}, {0}); + auto separate_shape_prod = + std::make_shared(separate_sub_shape[0], reduce_axis_const, true); separate_parts.push_back(separate_shape_prod->output(0)); subgraph_nodes.insert(subgraph_nodes.end(), {reduce_axis_const, separate_shape_prod}); } @@ -297,7 +318,10 @@ ngraph::Output reshape_input_for_matmul(const ngraph::Output& input_subscripts, const std::string& required_subscript, size_t input_ind, +void transpose_input(ngraph::OutputVector& input_nodes, + std::vector& input_subscripts, + const std::string& required_subscript, + size_t input_ind, ngraph::NodeVector& subgraph_nodes) { // perform sanity check for arguments auto num_inputs = input_nodes.size(); @@ -328,7 +352,8 @@ void transpose_input(ngraph::OutputVector& input_nodes, std::vector // create a sub-graph for transposing into the required layout const auto& input_node = input_nodes[input_ind]; - auto permutation_const = ngraph::opset7::Constant::create(ngraph::element::Type_t::i64, ngraph::Shape {permutation.size()}, permutation); + auto permutation_const = + ngraph::opset7::Constant::create(ngraph::element::Type_t::i64, ngraph::Shape{permutation.size()}, permutation); auto transpose = std::make_shared(input_node, permutation_const); // update a vector of inputs and input subscripts @@ -351,9 +376,12 @@ void transpose_input(ngraph::OutputVector& input_nodes, std::vector /// \param subgraph_nodes A vector of operation nodes that is included into /// a sub-graph decomposing Einsum that is needed for copy_runtime_info /// -void reduce_input(ngraph::pass::EinsumDecomposition *einsum_decompose_ptr, - ngraph::OutputVector& input_nodes, std::vector& input_subscripts, - const std::string& output_subscript, size_t input_ind, ngraph::NodeVector& subgraph_nodes) { +void reduce_input(ngraph::pass::EinsumDecomposition* einsum_decompose_ptr, + ngraph::OutputVector& input_nodes, + std::vector& input_subscripts, + const std::string& output_subscript, + size_t input_ind, + ngraph::NodeVector& subgraph_nodes) { // perform sanity check for arguments auto num_inputs = input_nodes.size(); NGRAPH_CHECK(num_inputs == input_subscripts.size(), "Each input must have own subscript."); @@ -384,7 +412,9 @@ void reduce_input(ngraph::pass::EinsumDecomposition *einsum_decompose_ptr, // reduce by summed up elements along dimension for which label is met just once const auto& input_node = input_nodes[input_ind]; - auto axes_const = ngraph::opset7::Constant::create(ngraph::element::Type_t::i64, ngraph::Shape {reduced_axes.size()}, reduced_axes); + auto axes_const = ngraph::opset7::Constant::create(ngraph::element::Type_t::i64, + ngraph::Shape{reduced_axes.size()}, + reduced_axes); auto reduce_sum = einsum_decompose_ptr->register_new_node(input_node, axes_const, false); // update a vector of inputs and input subscripts @@ -410,9 +440,12 @@ void reduce_input(ngraph::pass::EinsumDecomposition *einsum_decompose_ptr, /// sub-graph decomposing Einsum that is needed for copy_runtime_info /// void contract_two_inputs(ngraph::pass::EinsumDecomposition* einsum_decompose_ptr, - ngraph::OutputVector& input_nodes, std::vector& input_subscripts, - const std::string& output_subscript, size_t input_ind1, - size_t input_ind2, ngraph::NodeVector& subgraph_nodes) { + ngraph::OutputVector& input_nodes, + std::vector& input_subscripts, + const std::string& output_subscript, + size_t input_ind1, + size_t input_ind2, + ngraph::NodeVector& subgraph_nodes) { // assume that input_ind1 < input_ind2 without loss of generality, otherwise, just swap them if (input_ind2 < input_ind1) { std::swap(input_ind1, input_ind2); @@ -453,7 +486,8 @@ void contract_two_inputs(ngraph::pass::EinsumDecomposition* einsum_decompose_ptr const auto& label = labels1[label_ind]; auto iter = std::find(labels2.begin(), labels2.end(), label); if (iter != labels2.end()) { - bool is_dim_reduced = is_dimension_reduced(input_subscripts, output_subscript, label, {input_ind1, input_ind2}); + bool is_dim_reduced = + is_dimension_reduced(input_subscripts, output_subscript, label, {input_ind1, input_ind2}); common_part += label; if (is_dim_reduced) { reduced_labels_inds1.push_back(static_cast(label_ind)); @@ -500,7 +534,9 @@ void contract_two_inputs(ngraph::pass::EinsumDecomposition* einsum_decompose_ptr auto unsqueeze_output2 = unsqueeze_input(input_node2, unsqueeze_axis2, subgraph_nodes); // multiply both operands with broadcasting - auto mul = std::make_shared(unsqueeze_output1, unsqueeze_output2, ngraph::op::AutoBroadcastType::NUMPY); + auto mul = std::make_shared(unsqueeze_output1, + unsqueeze_output2, + ngraph::op::AutoBroadcastType::NUMPY); // update input operand and input subscript for Einsum operation update_operands(input_nodes, input_subscripts, input_ind1, input_ind2, mul->output(0), resultant_subscript); @@ -514,12 +550,18 @@ void contract_two_inputs(ngraph::pass::EinsumDecomposition* einsum_decompose_ptr // step 1. transpose both operands so that common labels, separated and reduced labels // are grouped for both operands bool is_separate_first1 = false; - auto int_subscript1 = generate_grouping_subscript(input_subscript1, common_labels_inds1, separate_labels_inds1, - reduced_labels_inds1, is_separate_first1); + auto int_subscript1 = generate_grouping_subscript(input_subscript1, + common_labels_inds1, + separate_labels_inds1, + reduced_labels_inds1, + is_separate_first1); transpose_input(input_nodes, input_subscripts, int_subscript1, input_ind1, subgraph_nodes); bool is_separate_first2 = false; - auto int_subscript2 = generate_grouping_subscript(input_subscript2, common_labels_inds2, separate_labels_inds2, - reduced_labels_inds2, is_separate_first2); + auto int_subscript2 = generate_grouping_subscript(input_subscript2, + common_labels_inds2, + separate_labels_inds2, + reduced_labels_inds2, + is_separate_first2); transpose_input(input_nodes, input_subscripts, int_subscript2, input_ind2, subgraph_nodes); // step 2. reshape both operands so that separate labels and reduced labels are represented @@ -530,22 +572,22 @@ void contract_two_inputs(ngraph::pass::EinsumDecomposition* einsum_decompose_ptr // this step is not needed for the operand if it satisfies to one of the requirements: // 1. there is just one separate dimension and just one reduced dimension // 2. there is no separate dimension, no common dimensions, and just one reduced dimension - bool no_reshape_for_matmul1 = (reduced_labels_inds1.size() == 1 && separate_labels_inds1.size() == 1) || - (reduced_labels_inds1.size() == 1 && common_labels_inds1.size() == 0 - && separate_labels_inds1.size() == 0); - bool no_reshape_for_matmul2 = (reduced_labels_inds2.size() == 1 && separate_labels_inds2.size() == 1) || - (reduced_labels_inds2.size() == 1 && common_labels_inds2.size() == 0 - && separate_labels_inds2.size() == 0); + bool no_reshape_for_matmul1 = + (reduced_labels_inds1.size() == 1 && separate_labels_inds1.size() == 1) || + (reduced_labels_inds1.size() == 1 && common_labels_inds1.size() == 0 && separate_labels_inds1.size() == 0); + bool no_reshape_for_matmul2 = + (reduced_labels_inds2.size() == 1 && separate_labels_inds2.size() == 1) || + (reduced_labels_inds2.size() == 1 && common_labels_inds2.size() == 0 && separate_labels_inds2.size() == 0); // reshape back after MatMul is not needed if one of two requrements satisfies for both operands: // 1. there is just one separate dimension // 2. there is no separate dimension and no common dimensions present. // If there is no separate dimension and common dimensions present, reshape is needed // because auxiliary separate dimension has been added by Unsqueeze operation // in the purpose for MatMul - bool no_reshape_back1 = (separate_labels_inds1.size() == 1) || - (common_labels_inds1.size() == 0 && separate_labels_inds1.size() == 0); - bool no_reshape_back2 = (separate_labels_inds2.size() == 1) || - (common_labels_inds2.size() == 0 && separate_labels_inds2.size() == 0); + bool no_reshape_back1 = + (separate_labels_inds1.size() == 1) || (common_labels_inds1.size() == 0 && separate_labels_inds1.size() == 0); + bool no_reshape_back2 = + (separate_labels_inds2.size() == 1) || (common_labels_inds2.size() == 0 && separate_labels_inds2.size() == 0); bool no_reshape_after_matmul = no_reshape_back1 && no_reshape_back2; auto matmul_operand1 = input_node1; @@ -556,25 +598,41 @@ void contract_two_inputs(ngraph::pass::EinsumDecomposition* einsum_decompose_ptr if (no_reshape_for_matmul1 == false || no_reshape_for_matmul2 == false) { auto data_shape1 = std::make_shared(input_node1); common_sub_shape = compute_sub_shape(data_shape1, common_dims_begin, common_dims_end, subgraph_nodes); - int64_t reduced_dims_begin = (is_separate_first1 ? common_labels_inds1.size() + separate_labels_inds1.size() : common_labels_inds1.size()); + int64_t reduced_dims_begin = (is_separate_first1 ? common_labels_inds1.size() + separate_labels_inds1.size() + : common_labels_inds1.size()); int64_t reduced_dims_end = reduced_dims_begin + reduced_labels_inds1.size(); - auto reduced_sub_shape_prod = compute_sub_shape(data_shape1, reduced_dims_begin, reduced_dims_end, subgraph_nodes, true); + auto reduced_sub_shape_prod = + compute_sub_shape(data_shape1, reduced_dims_begin, reduced_dims_end, subgraph_nodes, true); if (no_reshape_for_matmul1 == false || no_reshape_after_matmul == false) { - int64_t separate1_dims_begin = (is_separate_first1 ? common_labels_inds1.size() : common_labels_inds1.size() + reduced_labels_inds1.size()); + int64_t separate1_dims_begin = + (is_separate_first1 ? common_labels_inds1.size() + : common_labels_inds1.size() + reduced_labels_inds1.size()); int64_t separate1_dims_end = separate1_dims_begin + separate_labels_inds1.size(); - separate1_sub_shape = compute_sub_shape(data_shape1, separate1_dims_begin, separate1_dims_end, subgraph_nodes); - matmul_operand1 = reshape_input_for_matmul(input_node1, common_sub_shape, separate1_sub_shape, - reduced_sub_shape_prod, is_separate_first1, subgraph_nodes); + separate1_sub_shape = + compute_sub_shape(data_shape1, separate1_dims_begin, separate1_dims_end, subgraph_nodes); + matmul_operand1 = reshape_input_for_matmul(input_node1, + common_sub_shape, + separate1_sub_shape, + reduced_sub_shape_prod, + is_separate_first1, + subgraph_nodes); } if (no_reshape_for_matmul2 == false || no_reshape_after_matmul == false) { auto data_shape2 = std::make_shared(input_node2); - int64_t separate2_dims_begin = (is_separate_first2 ? common_labels_inds2.size() : common_labels_inds2.size() + reduced_labels_inds2.size()); + int64_t separate2_dims_begin = + (is_separate_first2 ? common_labels_inds2.size() + : common_labels_inds2.size() + reduced_labels_inds2.size()); int64_t separate2_dims_end = separate2_dims_begin + separate_labels_inds2.size(); - separate2_sub_shape = compute_sub_shape(data_shape2, separate2_dims_begin, separate2_dims_end, subgraph_nodes); - matmul_operand2 = reshape_input_for_matmul(input_node2, common_sub_shape, separate2_sub_shape, - reduced_sub_shape_prod, is_separate_first2, subgraph_nodes); + separate2_sub_shape = + compute_sub_shape(data_shape2, separate2_dims_begin, separate2_dims_end, subgraph_nodes); + matmul_operand2 = reshape_input_for_matmul(input_node2, + common_sub_shape, + separate2_sub_shape, + reduced_sub_shape_prod, + is_separate_first2, + subgraph_nodes); subgraph_nodes.insert(subgraph_nodes.end(), {data_shape2}); } subgraph_nodes.insert(subgraph_nodes.end(), {data_shape1}); @@ -587,7 +645,8 @@ void contract_two_inputs(ngraph::pass::EinsumDecomposition* einsum_decompose_ptr // step 4. reshape back by unrolling dimensions corresponding to separate labels if needed // now dimensions corresponding to reduced labels are reduced by the MatMul operation - std::string resultant_subscript = input_subscript1.substr(common_dims_begin, common_dims_end) + separate_part1 + separate_part2; + std::string resultant_subscript = + input_subscript1.substr(common_dims_begin, common_dims_end) + separate_part1 + separate_part2; if (no_reshape_after_matmul) { // this is a case when Reshape is not needed after MatMul operation // since there are no collapsed (or auxiliary added) separated dimensions @@ -611,7 +670,12 @@ void contract_two_inputs(ngraph::pass::EinsumDecomposition* einsum_decompose_ptr } // update input operand and input subscript for Einsum operation - update_operands(input_nodes, input_subscripts, input_ind1, input_ind2, result_op->output(0), resultant_subscript); + update_operands(input_nodes, + input_subscripts, + input_ind1, + input_ind2, + result_op->output(0), + resultant_subscript); subgraph_nodes.insert(subgraph_nodes.end(), {result_op}); } @@ -659,7 +723,13 @@ ngraph::pass::EinsumDecomposition::EinsumDecomposition() { // contract inputs by Einsum until just one is remained for (auto const& inds_pair : einsum_path) { - contract_two_inputs(this, input_nodes, input_subscripts, output_subscript, inds_pair.first, inds_pair.second, subgraph_nodes); + contract_two_inputs(this, + input_nodes, + input_subscripts, + output_subscript, + inds_pair.first, + inds_pair.second, + subgraph_nodes); } // reduce dimensions for the remained input node diff --git a/src/common/transformations/src/transformations/op_conversions/fq_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/fq_decomposition.cpp index 0b5cde9c989..f638b1098c2 100644 --- a/src/common/transformations/src/transformations/op_conversions/fq_decomposition.cpp +++ b/src/common/transformations/src/transformations/op_conversions/fq_decomposition.cpp @@ -2,22 +2,22 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/fq_decomposition.hpp" +#include #include #include -#include #include -#include - +#include #include +#include "itt.hpp" + NGRAPH_RTTI_DEFINITION(ngraph::pass::FakeQuantizeDecomposition, "FakeQuantizeDecomposition", 0); namespace { -bool isValidRangesInputs(const std::shared_ptr &fq) { +bool isValidRangesInputs(const std::shared_ptr& fq) { auto il = fq->input_value(1); auto ih = fq->input_value(2); auto greater_equal = std::make_shared(il, ih); @@ -30,10 +30,12 @@ bool isValidRangesInputs(const std::shared_ptr &fq const std::vector comp_result = res_node->cast_vector(); - return !std::any_of(comp_result.begin(), comp_result.end(), [](const bool value) { return value; }); + return !std::any_of(comp_result.begin(), comp_result.end(), [](const bool value) { + return value; + }); } -} // namespace +} // namespace ngraph::pass::FakeQuantizeDecomposition::FakeQuantizeDecomposition() { MATCHER_SCOPE(FakeQuantizeDecomposition); @@ -44,11 +46,13 @@ ngraph::pass::FakeQuantizeDecomposition::FakeQuantizeDecomposition() { auto oh = ngraph::pattern::wrap_type(); auto fake_quantize = ngraph::pattern::wrap_type({data, il, ih, ol, oh}); - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { - auto &pattern_to_output = m.get_pattern_value_map(); - const auto fake_quantize_node = std::dynamic_pointer_cast(pattern_to_output.at(fake_quantize).get_node_shared_ptr()); + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { + auto& pattern_to_output = m.get_pattern_value_map(); + const auto fake_quantize_node = std::dynamic_pointer_cast( + pattern_to_output.at(fake_quantize).get_node_shared_ptr()); - if (fake_quantize_node == nullptr || transformation_callback(fake_quantize_node) || !isValidRangesInputs(fake_quantize_node)) { + if (fake_quantize_node == nullptr || transformation_callback(fake_quantize_node) || + !isValidRangesInputs(fake_quantize_node)) { return false; } @@ -74,7 +78,8 @@ ngraph::pass::FakeQuantizeDecomposition::FakeQuantizeDecomposition() { decomp_ops.push_back(min); // (levels-1) - const auto levels_minus_one = std::make_shared(input_type, Shape{}, fake_quantize_node->get_levels() - 1); + const auto levels_minus_one = + std::make_shared(input_type, Shape{}, fake_quantize_node->get_levels() - 1); decomp_ops.push_back(levels_minus_one); // (input_high - input_low) const auto subInHighLow = std::make_shared(input_high, input_low); @@ -94,7 +99,8 @@ ngraph::pass::FakeQuantizeDecomposition::FakeQuantizeDecomposition() { decomp_ops.push_back(after_ish_apply); // round(x * (levels-1) / (input_high - input_low) - input_low * (levels-1) / (input_high - input_low)) - const auto round = std::make_shared(after_ish_apply, ngraph::opset5::Round::RoundMode::HALF_TO_EVEN); + const auto round = + std::make_shared(after_ish_apply, ngraph::opset5::Round::RoundMode::HALF_TO_EVEN); decomp_ops.push_back(round); // (output_high - output_low) @@ -104,10 +110,11 @@ ngraph::pass::FakeQuantizeDecomposition::FakeQuantizeDecomposition() { decomp_ops.push_back(sub_out_high_low); decomp_ops.push_back(osc); - // round(x * (levels-1) / (input_high - input_low) - input_low * (levels-1) / (input_high - input_low)) * (output_high - output_low) / (levels-1) + // round(x * (levels-1) / (input_high - input_low) - input_low * (levels-1) / (input_high - input_low)) * + // (output_high - output_low) / (levels-1) const auto after_osc_apply = std::make_shared(round, osc); - // round(x * (levels-1) / (input_high - input_low) - input_low * (levels-1) / (input_high - input_low)) * (output_high - output_low) / (levels-1) + - // output_low + // round(x * (levels-1) / (input_high - input_low) - input_low * (levels-1) / (input_high - input_low)) * + // (output_high - output_low) / (levels-1) + output_low std::shared_ptr result = std::make_shared(after_osc_apply, output_low); decomp_ops.push_back(after_osc_apply); decomp_ops.push_back(result); diff --git a/src/common/transformations/src/transformations/op_conversions/gather_normalize_negative_indices.cpp b/src/common/transformations/src/transformations/op_conversions/gather_normalize_negative_indices.cpp index b0c9905746d..df0621a3bed 100644 --- a/src/common/transformations/src/transformations/op_conversions/gather_normalize_negative_indices.cpp +++ b/src/common/transformations/src/transformations/op_conversions/gather_normalize_negative_indices.cpp @@ -5,11 +5,11 @@ #include "transformations/op_conversions/gather_normalize_negative_indices.hpp" #include - #include -#include -#include #include +#include +#include + #include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::GatherNegativeConstIndicesNormalize, "GatherNegativeConstIndicesNormalize", 0); @@ -25,8 +25,10 @@ ngraph::pass::GatherNegativeConstIndicesNormalize::GatherNegativeConstIndicesNor auto& pattern_to_output = m.get_pattern_value_map(); auto gather = pattern_to_output.at(gather_node).get_node_shared_ptr(); auto data = pattern_to_output.at(data_input); - auto axis_constant = std::dynamic_pointer_cast(pattern_to_output.at(axis_input).get_node_shared_ptr()); - auto indices_constant = std::dynamic_pointer_cast(pattern_to_output.at(indices_input).get_node_shared_ptr()); + auto axis_constant = + std::dynamic_pointer_cast(pattern_to_output.at(axis_input).get_node_shared_ptr()); + auto indices_constant = std::dynamic_pointer_cast( + pattern_to_output.at(indices_input).get_node_shared_ptr()); if (!gather || !axis_constant || !indices_constant) { return false; @@ -60,8 +62,10 @@ ngraph::pass::GatherNegativeConstIndicesNormalize::GatherNegativeConstIndicesNor auto input_type = indices_constant->get_element_type(); auto shape_of = std::make_shared(data, input_type); - auto input_gather = std::make_shared(shape_of, - ngraph::opset7::Constant::create(input_type, Shape{}, {axis_value}), ngraph::opset7::Constant::create(input_type, Shape{}, {0})); + auto input_gather = std::make_shared( + shape_of, + ngraph::opset7::Constant::create(input_type, Shape{}, {axis_value}), + ngraph::opset7::Constant::create(input_type, Shape{}, {0})); std::shared_ptr add = std::make_shared(input_gather, indices_constant); if (auto folded_const = ngraph::get_constant_from_source(add)) diff --git a/src/common/transformations/src/transformations/op_conversions/gelu7_downgrade.cpp b/src/common/transformations/src/transformations/op_conversions/gelu7_downgrade.cpp index 1751c14d573..def19bea8b4 100644 --- a/src/common/transformations/src/transformations/op_conversions/gelu7_downgrade.cpp +++ b/src/common/transformations/src/transformations/op_conversions/gelu7_downgrade.cpp @@ -5,11 +5,11 @@ #include "transformations/op_conversions/gelu7_downgrade.hpp" #include - #include #include -#include #include +#include + #include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::Gelu7Downgrade, "Gelu7Downgrade", 0); @@ -20,7 +20,8 @@ ngraph::pass::Gelu7Downgrade::Gelu7Downgrade() { ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { auto& pattern_to_output = m.get_pattern_value_map(); - auto gelu_node = std::dynamic_pointer_cast(pattern_to_output.at(gelu).get_node_shared_ptr()); + auto gelu_node = + std::dynamic_pointer_cast(pattern_to_output.at(gelu).get_node_shared_ptr()); if (gelu_node == nullptr || transformation_callback(gelu_node)) { return false; diff --git a/src/common/transformations/src/transformations/op_conversions/gru_cell_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/gru_cell_decomposition.cpp index e9f6a48ec99..3286d98d525 100644 --- a/src/common/transformations/src/transformations/op_conversions/gru_cell_decomposition.cpp +++ b/src/common/transformations/src/transformations/op_conversions/gru_cell_decomposition.cpp @@ -2,16 +2,16 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/gru_cell_decomposition.hpp" #include +#include +#include +#include +#include #include -#include -#include -#include -#include +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::GRUCellDecomposition, "GRUCellDecomposition", 0); @@ -19,7 +19,7 @@ ngraph::pass::GRUCellDecomposition::GRUCellDecomposition() { MATCHER_SCOPE(GRUCellDecomposition); auto gru_cell = ngraph::pattern::wrap_type(); ngraph::matcher_pass_callback callback = [this](ngraph::pattern::Matcher& m) { - auto gru_cell = std::dynamic_pointer_cast (m.get_match_root()); + auto gru_cell = std::dynamic_pointer_cast(m.get_match_root()); if (!gru_cell || transformation_callback(gru_cell)) { return false; } @@ -65,7 +65,7 @@ ngraph::pass::GRUCellDecomposition::GRUCellDecomposition() { // rt = f(Xt*(Wr^T) + Ht-1*(Rr^T) + Wbr + Rbr) auto r_t = ngraph::op::util::activation(gru_cell->get_activations()[0], clamp_r); - std::shared_ptr _h; + std::shared_ptr _h; if (gru_cell->get_linear_before_reset()) { // _h = Xt*(Wh^T) + (rt (.) (Ht-1*(Rh^T) + Rbh)) + Wbh auto Ht_Rh_Rbh = std::make_shared(Ht_R_zrh->output(2), biases_zrh->output(3)); @@ -97,8 +97,24 @@ ngraph::pass::GRUCellDecomposition::GRUCellDecomposition() { auto out_H = std::make_shared(mul_1, mul_2); out_H->set_friendly_name(gru_cell->get_friendly_name()); - ngraph::copy_runtime_info(gru_cell, {Xt_W, Ht_R, axis_0, Xt_W_zrh, R_zrh, Ht_R_zrh, biases_zrh, - add_z_1, add_z_2, add_r_1, add_r_2, h_t, one, sub, mul_1, mul_2, out_H}); + ngraph::copy_runtime_info(gru_cell, + {Xt_W, + Ht_R, + axis_0, + Xt_W_zrh, + R_zrh, + Ht_R_zrh, + biases_zrh, + add_z_1, + add_z_2, + add_r_1, + add_r_2, + h_t, + one, + sub, + mul_1, + mul_2, + out_H}); ngraph::replace_node(gru_cell, out_H); return true; }; diff --git a/src/common/transformations/src/transformations/op_conversions/hsigmoid_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/hsigmoid_decomposition.cpp index 04c3fb741d1..40387499655 100644 --- a/src/common/transformations/src/transformations/op_conversions/hsigmoid_decomposition.cpp +++ b/src/common/transformations/src/transformations/op_conversions/hsigmoid_decomposition.cpp @@ -2,14 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/hsigmoid_decomposition.hpp" #include - #include -#include #include +#include + +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::HSigmoidDecomposition, "HSigmoidDecomposition", 0); @@ -18,8 +18,8 @@ ngraph::pass::HSigmoidDecomposition::HSigmoidDecomposition() { // Decomposes HSigmoid(x) op into sub-graph (min(Relu(x + 3), 6) * const(1/6) auto hsigmoid = ngraph::pattern::wrap_type(); - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { - auto &pattern_to_output = m.get_pattern_value_map(); + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { + auto& pattern_to_output = m.get_pattern_value_map(); auto hsigmoid_node = pattern_to_output.at(hsigmoid).get_node_shared_ptr(); if (transformation_callback(hsigmoid_node)) { @@ -32,12 +32,11 @@ ngraph::pass::HSigmoidDecomposition::HSigmoidDecomposition() { auto relu = std::make_shared(add); auto min_constant = ngraph::opset5::Constant::create(input_type, ngraph::Shape{}, {6.0}); auto min = register_new_node(relu, min_constant); - auto mul_constant = ngraph::opset5::Constant::create(input_type, ngraph::Shape{}, {(1.0/6.0)}); // const(1/6) + auto mul_constant = ngraph::opset5::Constant::create(input_type, ngraph::Shape{}, {(1.0 / 6.0)}); // const(1/6) auto mul = std::make_shared(min, mul_constant); mul->set_friendly_name(m.get_match_root()->get_friendly_name()); - ngraph::copy_runtime_info(hsigmoid_node, - {add_constant, add, relu, min_constant, min, min_constant, mul}); + ngraph::copy_runtime_info(hsigmoid_node, {add_constant, add, relu, min_constant, min, min_constant, mul}); ngraph::replace_node(m.get_match_root(), mul); return true; }; diff --git a/src/common/transformations/src/transformations/op_conversions/hswish_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/hswish_decomposition.cpp index a45b2d35f76..7db29c5fe46 100644 --- a/src/common/transformations/src/transformations/op_conversions/hswish_decomposition.cpp +++ b/src/common/transformations/src/transformations/op_conversions/hswish_decomposition.cpp @@ -2,14 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/hswish_decomposition.hpp" #include - #include -#include #include +#include + +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::HSwishDecomposition, "HSwishDecomposition", 0); @@ -18,8 +18,8 @@ ngraph::pass::HSwishDecomposition::HSwishDecomposition() { // Decomposes HSwish(x) op into sub-graph x * (min(Relu(x + 3), 6) * const(1/6) auto hswish = ngraph::pattern::wrap_type(); - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { - auto &pattern_to_output = m.get_pattern_value_map(); + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { + auto& pattern_to_output = m.get_pattern_value_map(); auto hswish_node = pattern_to_output.at(hswish).get_node_shared_ptr(); if (transformation_callback(hswish_node)) { @@ -33,7 +33,7 @@ ngraph::pass::HSwishDecomposition::HSwishDecomposition() { auto min_constant = ngraph::opset4::Constant::create(input_type, ngraph::Shape{}, {6.0}); auto min = register_new_node(relu, min_constant); auto mul_first = std::make_shared(hswish_node->input_value(0), min); - auto mul_constant = ngraph::opset4::Constant::create(input_type, ngraph::Shape{}, {(1.0/6.0)}); // const(1/6) + auto mul_constant = ngraph::opset4::Constant::create(input_type, ngraph::Shape{}, {(1.0 / 6.0)}); // const(1/6) auto mul_second = std::make_shared(mul_first, mul_constant); mul_second->set_friendly_name(m.get_match_root()->get_friendly_name()); diff --git a/src/common/transformations/src/transformations/op_conversions/log_softmax_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/log_softmax_decomposition.cpp index 08e7875260b..5778dbdd7e6 100644 --- a/src/common/transformations/src/transformations/op_conversions/log_softmax_decomposition.cpp +++ b/src/common/transformations/src/transformations/op_conversions/log_softmax_decomposition.cpp @@ -2,14 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/log_softmax_decomposition.hpp" #include - #include -#include #include +#include + +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::LogSoftmaxDecomposition, "LogSoftmaxDecomposition", 0); @@ -20,14 +20,17 @@ ngraph::pass::LogSoftmaxDecomposition::LogSoftmaxDecomposition() { ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { auto& pattern_to_output = m.get_pattern_value_map(); - auto log_softmax_node = std::dynamic_pointer_cast(pattern_to_output.at(log_softmax).get_node_shared_ptr()); + auto log_softmax_node = std::dynamic_pointer_cast( + pattern_to_output.at(log_softmax).get_node_shared_ptr()); if (log_softmax_node == nullptr || transformation_callback(log_softmax_node)) { return false; } - auto axis1 = ngraph::opset5::Constant::create(element::Type_t::i64, ngraph::Shape{1}, { log_softmax_node->get_axis() }); - auto axis2 = ngraph::opset5::Constant::create(element::Type_t::i64, ngraph::Shape{1}, { log_softmax_node->get_axis() }); + auto axis1 = + ngraph::opset5::Constant::create(element::Type_t::i64, ngraph::Shape{1}, {log_softmax_node->get_axis()}); + auto axis2 = + ngraph::opset5::Constant::create(element::Type_t::i64, ngraph::Shape{1}, {log_softmax_node->get_axis()}); auto max = std::make_shared(log_softmax_node->input_value(0), axis1, true); auto sub = std::make_shared(log_softmax_node->input_value(0), max); auto exp = std::make_shared(sub); @@ -36,7 +39,7 @@ ngraph::pass::LogSoftmaxDecomposition::LogSoftmaxDecomposition() { auto sub_end = std::make_shared(sub, log); sub_end->set_friendly_name(m.get_match_root()->get_friendly_name()); - ngraph::copy_runtime_info(log_softmax_node, { axis1, axis2, max, sub, exp, sum, log, sub_end }); + ngraph::copy_runtime_info(log_softmax_node, {axis1, axis2, max, sub, exp, sum, log, sub_end}); ngraph::replace_node(m.get_match_root(), sub_end); return true; }; diff --git a/src/common/transformations/src/transformations/op_conversions/lstm_cell_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/lstm_cell_decomposition.cpp index 492dff379c2..9c8b1dfffd6 100644 --- a/src/common/transformations/src/transformations/op_conversions/lstm_cell_decomposition.cpp +++ b/src/common/transformations/src/transformations/op_conversions/lstm_cell_decomposition.cpp @@ -2,17 +2,17 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/lstm_cell_decomposition.hpp" #include +#include +#include +#include +#include +#include #include -#include -#include -#include -#include -#include +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::LSTMCellDecomposition, "LSTMCellDecomposition", 0); @@ -78,10 +78,11 @@ ngraph::pass::LSTMCellDecomposition::LSTMCellDecomposition() { auto hC = ngraph::op::util::activation(lstm_cell->get_activations()[2], out_C); auto out_H = std::make_shared(o_t, hC); - out_H->set_friendly_name(lstm_cell->get_friendly_name()+".0"); - out_C->set_friendly_name(lstm_cell->get_friendly_name()+".1"); - ngraph::copy_runtime_info(lstm_cell, {Xt_W, Ht_R, add, split, mul1, mul2, out_H, hC, out_C, axis_node, XHB, - f_t, i_t, c_t, o_t}); + out_H->set_friendly_name(lstm_cell->get_friendly_name() + ".0"); + out_C->set_friendly_name(lstm_cell->get_friendly_name() + ".1"); + ngraph::copy_runtime_info( + lstm_cell, + {Xt_W, Ht_R, add, split, mul1, mul2, out_H, hC, out_C, axis_node, XHB, f_t, i_t, c_t, o_t}); ngraph::replace_node(lstm_cell, {out_H->output(0), out_C->output(0)}); return true; }; diff --git a/src/common/transformations/src/transformations/op_conversions/mvn6_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/mvn6_decomposition.cpp index 88688c9bcfa..0890291b9fd 100644 --- a/src/common/transformations/src/transformations/op_conversions/mvn6_decomposition.cpp +++ b/src/common/transformations/src/transformations/op_conversions/mvn6_decomposition.cpp @@ -5,10 +5,10 @@ #include "transformations/op_conversions/mvn6_decomposition.hpp" #include - #include -#include #include +#include + #include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::MVN6Decomposition, "MVN6Decomposition", 0); @@ -37,17 +37,17 @@ ngraph::pass::MVN6Decomposition::MVN6Decomposition() { if (!mvn_node->get_normalize_variance()) { mean_normalization->set_friendly_name(mvn_node->get_friendly_name()); - ngraph::copy_runtime_info(mvn_node, { mean, mean_normalization }); + ngraph::copy_runtime_info(mvn_node, {mean, mean_normalization}); ngraph::replace_node(mvn_node, mean_normalization); } else { // (x - ReduceMean(x, axes)) ^ 2 - auto sqr_const = ngraph::opset6::Constant::create(data.get_element_type(), ngraph::Shape{ 1 }, { 2 }); + auto sqr_const = ngraph::opset6::Constant::create(data.get_element_type(), ngraph::Shape{1}, {2}); auto sqr = std::make_shared(mean_normalization, sqr_const); // ReduceMean((x - ReduceMean(x, axes)) ^ 2) auto mean2 = std::make_shared(sqr, axes, true); auto eps = mvn_node->get_eps(); - auto eps_node = ngraph::opset6::Constant::create(data.get_element_type(), ngraph::Shape{ 1 }, { eps }); + auto eps_node = ngraph::opset6::Constant::create(data.get_element_type(), ngraph::Shape{1}, {eps}); auto eps_mode = mvn_node->get_eps_mode(); std::shared_ptr eps_add; @@ -71,7 +71,7 @@ ngraph::pass::MVN6Decomposition::MVN6Decomposition() { } div->set_friendly_name(mvn_node->get_friendly_name()); - ngraph::copy_runtime_info(mvn_node, { mean, mean_normalization, sqr, mean2, eps_node, eps_add, sqrt, div }); + ngraph::copy_runtime_info(mvn_node, {mean, mean_normalization, sqr, mean2, eps_node, eps_add, sqrt, div}); ngraph::replace_node(mvn_node, div); } return true; diff --git a/src/common/transformations/src/transformations/op_conversions/normalize_l2_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/normalize_l2_decomposition.cpp index 832f4d2f940..bd1cbb24cd2 100644 --- a/src/common/transformations/src/transformations/op_conversions/normalize_l2_decomposition.cpp +++ b/src/common/transformations/src/transformations/op_conversions/normalize_l2_decomposition.cpp @@ -2,14 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/normalize_l2_decomposition.hpp" #include - #include -#include #include +#include + +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::NormalizeL2Decomposition, "NormalizeL2Decomposition", 0); @@ -17,28 +17,30 @@ ngraph::pass::NormalizeL2Decomposition::NormalizeL2Decomposition() { MATCHER_SCOPE(NormalizeL2Decomposition); auto normalize_l2_pattern = ngraph::pattern::wrap_type(); - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { auto normalize_l2 = std::dynamic_pointer_cast(m.get_match_root()); if (!normalize_l2 || transformation_callback(normalize_l2)) { return false; } - auto power = std::make_shared(normalize_l2->input_value(0), - opset8::Constant::create(normalize_l2->get_input_element_type(0), Shape{}, {2.0})); + auto power = std::make_shared( + normalize_l2->input_value(0), + opset8::Constant::create(normalize_l2->get_input_element_type(0), Shape{}, {2.0})); auto reduce_sum = std::make_shared(power, normalize_l2->input_value(1), true); std::shared_ptr eps_node; - auto eps_const_node = opset8::Constant::create(normalize_l2->get_input_element_type(0), Shape{}, {normalize_l2->get_eps()}); + auto eps_const_node = + opset8::Constant::create(normalize_l2->get_input_element_type(0), Shape{}, {normalize_l2->get_eps()}); switch (normalize_l2->get_eps_mode()) { - case op::EpsMode::ADD: - eps_node = std::make_shared(reduce_sum, eps_const_node); - break; - case op::EpsMode::MAX: - eps_node = std::make_shared(reduce_sum, eps_const_node); - break; - default: - return false; + case op::EpsMode::ADD: + eps_node = std::make_shared(reduce_sum, eps_const_node); + break; + case op::EpsMode::MAX: + eps_node = std::make_shared(reduce_sum, eps_const_node); + break; + default: + return false; } auto sqrt = std::make_shared(eps_node); @@ -53,4 +55,3 @@ ngraph::pass::NormalizeL2Decomposition::NormalizeL2Decomposition() { auto m = std::make_shared(normalize_l2_pattern, matcher_name); register_matcher(m, callback); } - diff --git a/src/common/transformations/src/transformations/op_conversions/reduce_l1_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/reduce_l1_decomposition.cpp index de21c3f9a7d..30aef9e95a9 100644 --- a/src/common/transformations/src/transformations/op_conversions/reduce_l1_decomposition.cpp +++ b/src/common/transformations/src/transformations/op_conversions/reduce_l1_decomposition.cpp @@ -2,14 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/reduce_l1_decomposition.hpp" #include - #include -#include #include +#include + +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ReduceL1Decomposition, "ReduceL1Decomposition", 0); @@ -18,20 +18,22 @@ ngraph::pass::ReduceL1Decomposition::ReduceL1Decomposition() { // decomposes ReduceL1 operations into ReduceSum(abs(x)) auto reduce_l1 = ngraph::pattern::wrap_type(); - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { - auto &pattern_to_output = m.get_pattern_value_map(); - auto reduce_l1_node = std::dynamic_pointer_cast(pattern_to_output.at(reduce_l1).get_node_shared_ptr()); + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { + auto& pattern_to_output = m.get_pattern_value_map(); + auto reduce_l1_node = + std::dynamic_pointer_cast(pattern_to_output.at(reduce_l1).get_node_shared_ptr()); if (reduce_l1_node == nullptr || transformation_callback(reduce_l1_node)) { return false; } auto abs = std::make_shared(reduce_l1_node->input_value(0)); - auto reduce_sum = register_new_node(abs, reduce_l1_node->input_value(1), reduce_l1_node->get_keep_dims()); + auto reduce_sum = register_new_node(abs, + reduce_l1_node->input_value(1), + reduce_l1_node->get_keep_dims()); reduce_sum->set_friendly_name(m.get_match_root()->get_friendly_name()); - ngraph::copy_runtime_info(reduce_l1_node, - {abs, reduce_sum}); + ngraph::copy_runtime_info(reduce_l1_node, {abs, reduce_sum}); ngraph::replace_node(m.get_match_root(), reduce_sum); return true; }; @@ -39,4 +41,3 @@ ngraph::pass::ReduceL1Decomposition::ReduceL1Decomposition() { auto m = std::make_shared(reduce_l1, matcher_name); register_matcher(m, callback); } - diff --git a/src/common/transformations/src/transformations/op_conversions/reduce_l2_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/reduce_l2_decomposition.cpp index c9dbaa161bd..2447fcd4f8c 100644 --- a/src/common/transformations/src/transformations/op_conversions/reduce_l2_decomposition.cpp +++ b/src/common/transformations/src/transformations/op_conversions/reduce_l2_decomposition.cpp @@ -2,14 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/reduce_l2_decomposition.hpp" #include - #include -#include #include +#include + +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ReduceL2Decomposition, "ReduceL2Decomposition", 0); @@ -18,21 +18,24 @@ ngraph::pass::ReduceL2Decomposition::ReduceL2Decomposition() { // decomposes ReduceL2 operations into sqrt(ReduceSum(x * x)) auto reduce_l2 = ngraph::pattern::wrap_type(); - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { - auto &pattern_to_output = m.get_pattern_value_map(); - auto reduce_l2_node = std::dynamic_pointer_cast(pattern_to_output.at(reduce_l2).get_node_shared_ptr()); + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { + auto& pattern_to_output = m.get_pattern_value_map(); + auto reduce_l2_node = + std::dynamic_pointer_cast(pattern_to_output.at(reduce_l2).get_node_shared_ptr()); if (reduce_l2_node == nullptr || transformation_callback(reduce_l2_node)) { return false; } - auto const_2 = ngraph::opset4::Constant::create(reduce_l2_node->input_value(0).get_element_type(), Shape{}, {2.0f}); + auto const_2 = + ngraph::opset4::Constant::create(reduce_l2_node->input_value(0).get_element_type(), Shape{}, {2.0f}); auto square = std::make_shared(reduce_l2_node->input_value(0), const_2); - auto reduce_sum = register_new_node(square, reduce_l2_node->input_value(1), reduce_l2_node->get_keep_dims()); + auto reduce_sum = register_new_node(square, + reduce_l2_node->input_value(1), + reduce_l2_node->get_keep_dims()); auto sqrt = std::make_shared(reduce_sum); sqrt->set_friendly_name(m.get_match_root()->get_friendly_name()); - ngraph::copy_runtime_info(reduce_l2_node, - {sqrt, reduce_sum, square, const_2}); + ngraph::copy_runtime_info(reduce_l2_node, {sqrt, reduce_sum, square, const_2}); ngraph::replace_node(m.get_match_root(), sqrt); return true; }; @@ -40,4 +43,3 @@ ngraph::pass::ReduceL2Decomposition::ReduceL2Decomposition() { auto m = std::make_shared(reduce_l2, matcher_name); register_matcher(m, callback); } - diff --git a/src/common/transformations/src/transformations/op_conversions/rnn_cell_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/rnn_cell_decomposition.cpp index 38418614b4d..2e39b7a36fd 100644 --- a/src/common/transformations/src/transformations/op_conversions/rnn_cell_decomposition.cpp +++ b/src/common/transformations/src/transformations/op_conversions/rnn_cell_decomposition.cpp @@ -2,16 +2,16 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/rnn_cell_decomposition.hpp" #include +#include +#include +#include +#include #include -#include -#include -#include -#include +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::RNNCellDecomposition, "RNNCellDecomposition", 0); @@ -19,7 +19,7 @@ ngraph::pass::RNNCellDecomposition::RNNCellDecomposition() { MATCHER_SCOPE(RNNCellDecomposition); auto rnn_cell = ngraph::pattern::wrap_type(); ngraph::matcher_pass_callback callback = [this](ngraph::pattern::Matcher& m) { - auto rnn_cell = std::dynamic_pointer_cast (m.get_match_root()); + auto rnn_cell = std::dynamic_pointer_cast(m.get_match_root()); if (!rnn_cell || transformation_callback(rnn_cell)) { return false; } diff --git a/src/common/transformations/src/transformations/op_conversions/simplify_ctc_greedy_decoder_seq_len.cpp b/src/common/transformations/src/transformations/op_conversions/simplify_ctc_greedy_decoder_seq_len.cpp index 1b6eb12b1c9..94e04a3e825 100644 --- a/src/common/transformations/src/transformations/op_conversions/simplify_ctc_greedy_decoder_seq_len.cpp +++ b/src/common/transformations/src/transformations/op_conversions/simplify_ctc_greedy_decoder_seq_len.cpp @@ -2,14 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" - #include "transformations/op_conversions/simplify_ctc_greedy_decoder_seq_len.hpp" #include +#include #include -#include +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::SimplifyCTCGreedyDecoderSeqLen, "SimplifyCTCGreedyDecoder", 0); @@ -18,19 +17,20 @@ ngraph::pass::SimplifyCTCGreedyDecoderSeqLen::SimplifyCTCGreedyDecoderSeqLen() { auto decoder = pattern::wrap_type(); ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { - auto decoder_seq_len = std::dynamic_pointer_cast (m.get_match_root()); + auto decoder_seq_len = std::dynamic_pointer_cast(m.get_match_root()); if (!decoder_seq_len) { return false; } if (decoder_seq_len->get_input_size() > 2) { const auto data_pshape = decoder_seq_len->get_input_partial_shape(0); - auto blank_index = std::dynamic_pointer_cast(decoder_seq_len->input_value(2).get_node_shared_ptr()); + auto blank_index = std::dynamic_pointer_cast( + decoder_seq_len->input_value(2).get_node_shared_ptr()); if (!blank_index || data_pshape.rank().is_dynamic() || data_pshape[2].is_dynamic()) { return false; } - const std::vector &blank_index_values = blank_index->cast_vector(); + const std::vector& blank_index_values = blank_index->cast_vector(); const auto num_classes = decoder_seq_len->get_input_partial_shape(0)[2].get_length(); if (blank_index_values[0] != (num_classes - 1)) { return false; @@ -40,9 +40,9 @@ ngraph::pass::SimplifyCTCGreedyDecoderSeqLen::SimplifyCTCGreedyDecoderSeqLen() { element::Type data_type = decoder_seq_len->input_value(0).get_element_type(); element::Type seq_len_type = decoder_seq_len->input_value(1).get_element_type(); // Transposing input data channels from [N, T, C] to [T, N, C]. Need for compatible with CTCGreedyDecoder v1 - auto transpose = std::make_shared(decoder_seq_len->input_value(0), - ngraph::opset6::Constant::create(element::i32, - Shape({3}), {1, 0, 2})); + auto transpose = std::make_shared( + decoder_seq_len->input_value(0), + ngraph::opset6::Constant::create(element::i32, Shape({3}), {1, 0, 2})); // Receive time and batch dimensions and concatenate to [T, N] tensor shapes auto data_shape = std::make_shared(decoder_seq_len->input_value(0)); auto axisT = ngraph::opset6::Constant::create(seq_len_type, Shape{}, {0}); @@ -61,26 +61,25 @@ ngraph::pass::SimplifyCTCGreedyDecoderSeqLen::SimplifyCTCGreedyDecoderSeqLen() { auto plusT_scalar = std::make_shared(plusT, const_plusT); auto range1T = std::make_shared(start, plusT_scalar, step, seq_len_type); - auto mask_shape = std::make_shared( - OutputVector{T->output(0), N->output(0)}, 0); + auto mask_shape = std::make_shared(OutputVector{T->output(0), N->output(0)}, 0); // Generate 2D tensor [T, N] for seq mask - auto upper_bounds = std::make_shared( - decoder_seq_len->input_value(1), mask_shape->output(0)); - auto transpose_upper_bounds = std::make_shared(upper_bounds->output(0), - ngraph::opset6::Constant::create(seq_len_type, - Shape({2}), {1, 0})); + auto upper_bounds = + std::make_shared(decoder_seq_len->input_value(1), mask_shape->output(0)); + auto transpose_upper_bounds = std::make_shared( + upper_bounds->output(0), + ngraph::opset6::Constant::create(seq_len_type, Shape({2}), {1, 0})); // Compute boolean sequence mask - auto bool_seq_mask = std::make_shared(transpose_upper_bounds->output(0), - range1T->output(0)); + auto bool_seq_mask = + std::make_shared(transpose_upper_bounds->output(0), range1T->output(0)); // Generate resulted seq mask auto mask_val_true = ngraph::opset6::Constant::create(seq_len_type, Shape{}, {1}); auto mask_val_false = ngraph::opset6::Constant::create(seq_len_type, Shape{}, {0}); auto seq_mask = std::make_shared(bool_seq_mask, mask_val_true, mask_val_false); - auto transpose_seq_mask = std::make_shared(seq_mask->output(0), - ngraph::opset6::Constant::create(seq_len_type, - Shape({2}), {1, 0})); + auto transpose_seq_mask = std::make_shared( + seq_mask->output(0), + ngraph::opset6::Constant::create(seq_len_type, Shape({2}), {1, 0})); auto transpose_seq_mask_f = std::make_shared(transpose_seq_mask->output(0), data_type); // Create CTCGreedyDecoder with original merge_repeated attribute and connect data and resulted seq_mask auto decoder = std::make_shared(transpose, @@ -96,8 +95,8 @@ ngraph::pass::SimplifyCTCGreedyDecoderSeqLen::SimplifyCTCGreedyDecoderSeqLen() { element::Type ci_type = decoder_seq_len->get_classes_index_type(); element::Type sl_type = decoder_seq_len->get_sequence_length_type(); - // CTCGreedyDecoder return floating point output. For Normalize output we need to convert output to classes_index_type - // Receive the first output with correct classes_index_type + // CTCGreedyDecoder return floating point output. For Normalize output we need to convert output to + // classes_index_type Receive the first output with correct classes_index_type auto output_i = std::make_shared(squeeze1_output_f->output(0), ci_type); auto minus1 = opset6::Constant::create(ci_type, Shape{}, {-1}); // Get to know where equal -1 @@ -106,18 +105,39 @@ ngraph::pass::SimplifyCTCGreedyDecoderSeqLen::SimplifyCTCGreedyDecoderSeqLen() { // Compute output seq mask auto seq_mask_const0 = opset6::Constant::create(ci_type, Shape{1}, {0}); auto seq_mask_const1 = opset6::Constant::create(ci_type, Shape{1}, {1}); - auto output_seq_mask = std::make_shared(where_equal_minus1, seq_mask_const0, seq_mask_const1); + auto output_seq_mask = + std::make_shared(where_equal_minus1, seq_mask_const0, seq_mask_const1); auto seq_mask_axis = opset6::Constant::create(ci_type, Shape{1}, {1}); // Receive the second output auto output_seq_len = std::make_shared(output_seq_mask, seq_mask_axis); // Receive the second output with correct seq_len_type auto output_seq_len_i = std::make_shared(output_seq_len->output(0), sl_type); - ngraph::copy_runtime_info(decoder_seq_len, {transpose, decoder, data_shape, T, N, plusT, plusT_scalar, range1T, mask_shape, upper_bounds, - squeeze2_output_f, squeeze1_output_f, transpose_upper_bounds, bool_seq_mask, seq_mask, transpose_seq_mask, - transpose_seq_mask_f, output_i, where_equal_minus1, output_seq_mask, output_seq_len, output_seq_len_i}); + ngraph::copy_runtime_info(decoder_seq_len, + {transpose, + decoder, + data_shape, + T, + N, + plusT, + plusT_scalar, + range1T, + mask_shape, + upper_bounds, + squeeze2_output_f, + squeeze1_output_f, + transpose_upper_bounds, + bool_seq_mask, + seq_mask, + transpose_seq_mask, + transpose_seq_mask_f, + output_i, + where_equal_minus1, + output_seq_mask, + output_seq_len, + output_seq_len_i}); - output_i->set_friendly_name(decoder_seq_len->get_friendly_name()+".0"); - output_seq_len_i->set_friendly_name(decoder_seq_len->get_friendly_name()+".1"); + output_i->set_friendly_name(decoder_seq_len->get_friendly_name() + ".0"); + output_seq_len_i->set_friendly_name(decoder_seq_len->get_friendly_name() + ".1"); ngraph::replace_node(decoder_seq_len, {output_i->output(0), output_seq_len_i->output(0)}); return true; diff --git a/src/common/transformations/src/transformations/op_conversions/softmax_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/softmax_decomposition.cpp index 569c5b60a84..f26c33012bf 100644 --- a/src/common/transformations/src/transformations/op_conversions/softmax_decomposition.cpp +++ b/src/common/transformations/src/transformations/op_conversions/softmax_decomposition.cpp @@ -2,17 +2,16 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" -#include - #include +#include +#include +#include +#include +#include +#include #include -#include -#include -#include -#include -#include +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::SoftmaxDecomposition, "SoftmaxDecomposition", 0); diff --git a/src/common/transformations/src/transformations/op_conversions/softplus_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/softplus_decomposition.cpp index 66aef8cdb98..113bda734f5 100644 --- a/src/common/transformations/src/transformations/op_conversions/softplus_decomposition.cpp +++ b/src/common/transformations/src/transformations/op_conversions/softplus_decomposition.cpp @@ -2,15 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "itt.hpp" #include "transformations/op_conversions/softplus_decomposition.hpp" #include +#include +#include +#include #include -#include -#include -#include +#include "itt.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::SoftPlusDecomposition, "SoftPlusDecomposition", 0); @@ -21,7 +21,7 @@ ngraph::pass::SoftPlusDecomposition::SoftPlusDecomposition() { auto softplus = std::make_shared(input); ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { - auto &pattern_to_output = m.get_pattern_value_map(); + auto& pattern_to_output = m.get_pattern_value_map(); auto softplus_input = pattern_to_output.at(input); auto softplus_node = pattern_to_output.at(softplus).get_node_shared_ptr(); @@ -30,7 +30,8 @@ ngraph::pass::SoftPlusDecomposition::SoftPlusDecomposition() { } auto exp = std::make_shared(softplus_input); - auto add = std::make_shared(exp, + auto add = std::make_shared( + exp, opset4::Constant::create(softplus_input.get_element_type(), ngraph::Shape{1}, {1.0})); auto log = std::make_shared(add); diff --git a/src/common/transformations/src/transformations/opset_conversions/convert_opset2_to_opset1.cpp b/src/common/transformations/src/transformations/opset_conversions/convert_opset2_to_opset1.cpp index 15fffe231d1..6886b74b0ef 100644 --- a/src/common/transformations/src/transformations/opset_conversions/convert_opset2_to_opset1.cpp +++ b/src/common/transformations/src/transformations/opset_conversions/convert_opset2_to_opset1.cpp @@ -4,14 +4,13 @@ #include "transformations/opset_conversions/convert_opset2_to_opset1.hpp" -#include "transformations/op_conversions/convert_batch_to_space.hpp" -#include "transformations/op_conversions/convert_space_to_batch.hpp" -#include "itt.hpp" - #include +#include #include -#include +#include "itt.hpp" +#include "transformations/op_conversions/convert_batch_to_space.hpp" +#include "transformations/op_conversions/convert_space_to_batch.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertOpSet2ToOpSet1, "ConvertOpSet2ToOpSet1", 0); diff --git a/src/common/transformations/src/transformations/opset_conversions/convert_opset3_to_opset2.cpp b/src/common/transformations/src/transformations/opset_conversions/convert_opset3_to_opset2.cpp index fb9b36cd6a2..2a910dae4ad 100644 --- a/src/common/transformations/src/transformations/opset_conversions/convert_opset3_to_opset2.cpp +++ b/src/common/transformations/src/transformations/opset_conversions/convert_opset3_to_opset2.cpp @@ -4,17 +4,16 @@ #include "transformations/opset_conversions/convert_opset3_to_opset2.hpp" +#include +#include +#include + +#include "itt.hpp" #include "transformations/op_conversions/convert_broadcast3.hpp" #include "transformations/op_conversions/convert_shapeof3.hpp" #include "transformations/op_conversions/convert_shuffle_channels3.hpp" #include "transformations/op_conversions/convert_topk3.hpp" #include "transformations/op_conversions/softplus_decomposition.hpp" -#include "itt.hpp" - -#include -#include - -#include NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertOpSet3ToOpSet2, "ConvertOpSet3ToOpSet2", 0); diff --git a/src/common/transformations/src/transformations/resolve_names_collisions.cpp b/src/common/transformations/src/transformations/resolve_names_collisions.cpp index fda4d38e6dd..a1066b3e0be 100644 --- a/src/common/transformations/src/transformations/resolve_names_collisions.cpp +++ b/src/common/transformations/src/transformations/resolve_names_collisions.cpp @@ -2,11 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "transformations/resolve_names_collisions.hpp" + #include #include #include -#include "transformations/resolve_names_collisions.hpp" #include "openvino/op/parameter.hpp" #include "openvino/op/result.hpp" #include "openvino/op/sink.hpp" @@ -27,7 +28,7 @@ bool ov::pass::ResolveNameCollisions::run_on_model(const std::shared_ptr(node) || - dynamic_cast(node)) { + if (dynamic_cast(node) || dynamic_cast(node)) { // Resolve names for public ops with autogenerated name if (node->m_friendly_name.empty()) nodes_with_conflicts.emplace_back(node); @@ -78,4 +78,3 @@ bool ov::pass::ResolveNameCollisions::run_on_model(const std::shared_ptrget_rt_info().emplace(NmsSelectedIndices::get_type_info_static(), NmsSelectedIndices{}); } -bool ov::has_nms_selected_indices(const Node * node) { +bool ov::has_nms_selected_indices(const Node* node) { return node->get_rt_info().count(NmsSelectedIndices::get_type_info_static()); } diff --git a/src/common/transformations/src/transformations/smart_reshape/broadcast_const_range_replacement.cpp b/src/common/transformations/src/transformations/smart_reshape/broadcast_const_range_replacement.cpp index bc987f6e40f..6b5202fd5bf 100644 --- a/src/common/transformations/src/transformations/smart_reshape/broadcast_const_range_replacement.cpp +++ b/src/common/transformations/src/transformations/smart_reshape/broadcast_const_range_replacement.cpp @@ -2,19 +2,16 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "transformations/utils/utils.hpp" - #include -#include - #include -#include #include +#include #include #include +#include #include "itt.hpp" - +#include "transformations/utils/utils.hpp" NGRAPH_RTTI_DEFINITION(ngraph::pass::BroadcastConstRangeReplacement, "BroadcastConstRangeReplacement", 0); @@ -35,7 +32,8 @@ ngraph::pass::BroadcastConstRangeReplacement::BroadcastConstRangeReplacement() { const auto data_const_out = broadcast->get_input_source_output(0); const auto target_shape_out = broadcast->get_input_source_output(1); - const auto const_node = std::dynamic_pointer_cast(data_const_out.get_node_shared_ptr()); + const auto const_node = + std::dynamic_pointer_cast(data_const_out.get_node_shared_ptr()); if (!const_node || !const_node->get_element_type().is_integral_number()) return false; @@ -52,19 +50,23 @@ ngraph::pass::BroadcastConstRangeReplacement::BroadcastConstRangeReplacement() { std::vector sequence_pattern(elem_count); std::iota(sequence_pattern.begin(), sequence_pattern.end(), 0); - const auto &const_values = const_node->cast_vector(); + const auto& const_values = const_node->cast_vector(); // Check if the value sequence is contiguous if (const_values != sequence_pattern) return false; const auto data_elem_type = data_const_out.get_element_type(); - const auto target_dim_index = std::distance(const_node_shape.cbegin(), std::find(const_node_shape.cbegin(), const_node_shape.cend(), elem_count)); + const auto target_dim_index = + std::distance(const_node_shape.cbegin(), + std::find(const_node_shape.cbegin(), const_node_shape.cend(), elem_count)); const int64_t target_dim_neg_index = target_dim_index - const_node_shape.size(); const auto axis_node = ngraph::opset8::Constant::create(ngraph::element::i32, {}, {0}); - const auto target_dim_index_node = ngraph::opset8::Constant::create(ngraph::element::i64, {}, {target_dim_neg_index}); - const auto gather_dim = std::make_shared(target_shape_out, target_dim_index_node, axis_node); + const auto target_dim_index_node = + ngraph::opset8::Constant::create(ngraph::element::i64, {}, {target_dim_neg_index}); + const auto gather_dim = + std::make_shared(target_shape_out, target_dim_index_node, axis_node); // If the corresponding target dim is 1, use the original end of range const auto one_dim_const = ngraph::opset8::Constant::create(target_shape_out.get_element_type(), {}, {1}); @@ -77,17 +79,31 @@ ngraph::pass::BroadcastConstRangeReplacement::BroadcastConstRangeReplacement() { const auto select_end = std::make_shared(dim_check_one, original_end, cast_gather_dim); const auto default_range_step = ngraph::opset8::Constant::create(data_elem_type, {}, {1}); - const auto range = std::make_shared(start, select_end, default_range_step, data_elem_type); + const auto range = + std::make_shared(start, select_end, default_range_step, data_elem_type); // Unsqueeze the output of the Range op to the original shape of data input std::vector final_shape_axes(const_node_shape.size()); std::iota(final_shape_axes.begin(), final_shape_axes.end(), 0); final_shape_axes.erase(final_shape_axes.begin() + target_dim_index); - const auto axes_to_unsqueeze = ngraph::opset8::Constant::create(ngraph::element::i64, {final_shape_axes.size()}, final_shape_axes); + const auto axes_to_unsqueeze = + ngraph::opset8::Constant::create(ngraph::element::i64, {final_shape_axes.size()}, final_shape_axes); const auto unsqueeze_range = std::make_shared(range, axes_to_unsqueeze); - copy_runtime_info(const_node, {axis_node, target_dim_index_node, gather_dim, cast_gather_dim, one_dim_const, dim_check_one, - start, original_end, select_end, default_range_step, range, axes_to_unsqueeze, unsqueeze_range}); + copy_runtime_info(const_node, + {axis_node, + target_dim_index_node, + gather_dim, + cast_gather_dim, + one_dim_const, + dim_check_one, + start, + original_end, + select_end, + default_range_step, + range, + axes_to_unsqueeze, + unsqueeze_range}); broadcast->input(0).replace_source_output(unsqueeze_range); return false; }; diff --git a/src/common/transformations/src/transformations/smart_reshape/proposal_scales_stridedslice.cpp b/src/common/transformations/src/transformations/smart_reshape/proposal_scales_stridedslice.cpp index c6353c71246..b95fb129b39 100644 --- a/src/common/transformations/src/transformations/smart_reshape/proposal_scales_stridedslice.cpp +++ b/src/common/transformations/src/transformations/smart_reshape/proposal_scales_stridedslice.cpp @@ -48,8 +48,8 @@ ngraph::pass::Proposal1Scales::Proposal1Scales() { (shape[1].get_length() == 3 || shape[1].get_length() == 4); }); auto convert_label = ngraph::pattern::wrap_type({parameter_label}); - auto param_or_convert = std::make_shared(ngraph::OutputVector{parameter_label, - convert_label}); + auto param_or_convert = + std::make_shared(ngraph::OutputVector{parameter_label, convert_label}); auto reshape_label = ngraph::pattern::wrap_type( {param_or_convert, ngraph::pattern::wrap_type()}, [](const Output& output) { @@ -76,8 +76,8 @@ ngraph::pass::Proposal4Scales::Proposal4Scales() { (shape[1].get_length() == 3 || shape[1].get_length() == 4); }); auto convert_label = ngraph::pattern::wrap_type({parameter_label}); - auto param_or_convert = std::make_shared(ngraph::OutputVector{parameter_label, - convert_label}); + auto param_or_convert = + std::make_shared(ngraph::OutputVector{parameter_label, convert_label}); auto reshape_label = ngraph::pattern::wrap_type( {param_or_convert, ngraph::pattern::wrap_type()}, [](const Output& output) { diff --git a/src/common/transformations/src/transformations/smart_reshape/strided_slice_squeeze.cpp b/src/common/transformations/src/transformations/smart_reshape/strided_slice_squeeze.cpp index 789e6e689d5..a440e4e37ec 100644 --- a/src/common/transformations/src/transformations/smart_reshape/strided_slice_squeeze.cpp +++ b/src/common/transformations/src/transformations/smart_reshape/strided_slice_squeeze.cpp @@ -106,8 +106,7 @@ ngraph::pass::StridedSliceSqueeze::StridedSliceSqueeze() { shrink_axis_mask, ellipsis_mask); - return replace_output_update_name(squeeze->output(0), - new_slice->output(squeeze->input_value(0).get_index())); + return replace_output_update_name(squeeze->output(0), new_slice->output(squeeze->input_value(0).get_index())); }; auto m = std::make_shared(squeeze_label /*, matcher_name */); register_matcher(m, callback); @@ -125,11 +124,13 @@ ngraph::pass::SqueezeStridedSlice::SqueezeStridedSlice() { matcher_pass_callback callback = [](pattern::Matcher& m) -> bool { auto slice = std::dynamic_pointer_cast(m.get_match_root()); - if (!slice) return false; + if (!slice) + return false; auto squeeze = slice->get_input_node_shared_ptr(0); const auto& const_axes = std::dynamic_pointer_cast(squeeze->get_input_node_shared_ptr(1)); - if (!const_axes) return false; + if (!const_axes) + return false; auto begin = std::dynamic_pointer_cast(slice->input_value(1).get_node_shared_ptr()); auto end = std::dynamic_pointer_cast(slice->input_value(2).get_node_shared_ptr()); diff --git a/src/common/transformations/src/transformations/utils/utils.cpp b/src/common/transformations/src/transformations/utils/utils.cpp index b0a844e27bc..c5164fa3d21 100644 --- a/src/common/transformations/src/transformations/utils/utils.cpp +++ b/src/common/transformations/src/transformations/utils/utils.cpp @@ -8,12 +8,12 @@ #include #include -#include #include #include -#include #include +#include #include +#include namespace ngraph { namespace op { @@ -50,8 +50,7 @@ bool get_single_value(const std::shared_ptr& const_node, float& va } } -std::shared_ptr normalize_constant(const std::shared_ptr& constant, - const PartialShape& shape) { +std::shared_ptr normalize_constant(const std::shared_ptr& constant, const PartialShape& shape) { auto const_shape = constant->get_shape(); if (static_cast(const_shape.size()) == shape.rank().get_length()) { return constant; @@ -65,11 +64,14 @@ std::shared_ptr normalize_constant(const std::shared_ptr& co } std::shared_ptr broadcastTo(const Output& input, const ngraph::Shape& shape) { - return std::make_shared(input, op::Constant::create(ngraph::element::i64, Shape {shape.size()}, shape)); + return std::make_shared(input, + op::Constant::create(ngraph::element::i64, Shape{shape.size()}, shape)); } -std::shared_ptr reshapeTo(const Output & input, const Shape& shape) { - return std::make_shared(input, op::Constant::create(element::i64, Shape{shape.size()}, shape), true); +std::shared_ptr reshapeTo(const Output& input, const Shape& shape) { + return std::make_shared(input, + op::Constant::create(element::i64, Shape{shape.size()}, shape), + true); } bool constantIsEqualTo(const std::shared_ptr& const_node, float value, float eps) { @@ -81,16 +83,17 @@ bool constantIsEqualTo(const std::shared_ptr& const_node, return std::abs(res - value) < eps; } -bool has_f16_constants(const std::shared_ptr &function) { - for (auto & layer : function->get_ops()) { - if (std::dynamic_pointer_cast(layer) && layer->output(0).get_element_type() == ngraph::element::f16) { +bool has_f16_constants(const std::shared_ptr& function) { + for (auto& layer : function->get_ops()) { + if (std::dynamic_pointer_cast(layer) && + layer->output(0).get_element_type() == ngraph::element::f16) { return true; } } return false; } -bool check_for_broadcast(const ngraph::PartialShape &ref_shape, const ngraph::PartialShape &other_shape) { +bool check_for_broadcast(const ngraph::PartialShape& ref_shape, const ngraph::PartialShape& other_shape) { // Check that other_shape doesn't broadcast ref_shape if (ref_shape.rank().is_dynamic() || other_shape.rank().is_dynamic() || other_shape.size() > ref_shape.size()) { return true; @@ -111,7 +114,8 @@ bool check_for_broadcast(const ngraph::PartialShape &ref_shape, const ngraph::Pa return false; } -std::shared_ptr activation(const std::string& activation_name, const ngraph::Output& apply_to) { +std::shared_ptr activation(const std::string& activation_name, + const ngraph::Output& apply_to) { if (activation_name == "relu") { return std::make_shared(apply_to); } else if (activation_name == "sigmoid") { @@ -123,9 +127,9 @@ std::shared_ptr activation(const std::string& activation_name, con } } -bool is_seq_len_provided(const std::shared_ptr &seq_len_input, int64_t max_seq_len) { - if (const auto &seq_len_const = std::dynamic_pointer_cast(seq_len_input)) { - const auto &seq_len_values = seq_len_const->cast_vector(); +bool is_seq_len_provided(const std::shared_ptr& seq_len_input, int64_t max_seq_len) { + if (const auto& seq_len_const = std::dynamic_pointer_cast(seq_len_input)) { + const auto& seq_len_values = seq_len_const->cast_vector(); return std::any_of(seq_len_values.begin(), seq_len_values.end(), [max_seq_len](const int64_t val) { return val != max_seq_len; }); @@ -155,21 +159,23 @@ std::vector> get_node_target_inputs(const std::shared_ptr& nod return result; } -std::shared_ptr node_to_get_shape_value_of_indices_from_shape_node(const std::shared_ptr& shape_node, - const std::vector& indices) { - return make_try_fold( - shape_node, - v0::Constant::create(ngraph::element::i64, {indices.size()}, indices), - v0::Constant::create(ngraph::element::i64, {}, {0})); +std::shared_ptr node_to_get_shape_value_of_indices_from_shape_node( + const std::shared_ptr& shape_node, + const std::vector& indices) { + return make_try_fold(shape_node, + v0::Constant::create(ngraph::element::i64, {indices.size()}, indices), + v0::Constant::create(ngraph::element::i64, {}, {0})); } -std::shared_ptr node_to_get_shape_value_of_indices_from_shape_source(const ngraph::Output& shape_source, +std::shared_ptr node_to_get_shape_value_of_indices_from_shape_source( + const ngraph::Output& shape_source, const std::vector& indices) { const auto& shape_node = make_try_fold(shape_source); return node_to_get_shape_value_of_indices_from_shape_node(shape_node, indices); } -bool shapes_equal_except_dynamic_expected_batch(const ngraph::PartialShape& expected, const ngraph::PartialShape& actual) { +bool shapes_equal_except_dynamic_expected_batch(const ngraph::PartialShape& expected, + const ngraph::PartialShape& actual) { if (expected[0].is_static()) { return actual == expected; } else { @@ -179,9 +185,7 @@ bool shapes_equal_except_dynamic_expected_batch(const ngraph::PartialShape& expe } } -void visit_shape_path(Node * node, - std::unordered_set& visited, - std::function func) { +void visit_shape_path(Node* node, std::unordered_set& visited, std::function func) { if (!node) return; visited.insert(node); @@ -190,7 +194,8 @@ void visit_shape_path(Node * node, auto curr_node = nodes.front(); nodes.pop_front(); // Do not check if already visited - if (ngraph::is_type(curr_node) || ngraph::is_type(curr_node)) { + if (ngraph::is_type(curr_node) || + ngraph::is_type(curr_node)) { continue; } @@ -198,7 +203,8 @@ void visit_shape_path(Node * node, for (auto& input_value : curr_node->input_values()) { // continue searching const auto& input_node = input_value.get_node(); - if (visited.count(input_node)) continue; + if (visited.count(input_node)) + continue; nodes.push_front(input_node); visited.insert(input_node); } @@ -238,10 +244,10 @@ bool is_dequantization_subgraph(const Output& node) { return input_type.is_integral() && output_type.is_real(); } -bool can_eliminate_eltwise_node(const std::shared_ptr& eltwise, const Output& constant, const Output& non_constant_input) { - if (!is_type(eltwise) && - !is_type(eltwise) && - !is_type(eltwise) && +bool can_eliminate_eltwise_node(const std::shared_ptr& eltwise, + const Output& constant, + const Output& non_constant_input) { + if (!is_type(eltwise) && !is_type(eltwise) && !is_type(eltwise) && !is_type(eltwise)) { return false; } @@ -261,42 +267,41 @@ bool can_eliminate_eltwise_node(const std::shared_ptr& eltwise, const Outp float actual_const = 0; const void* data_ptr = constant_ptr->get_data_ptr(); switch (constant_ptr->get_element_type()) { - case element::f32: - actual_const = reinterpret_cast(data_ptr)[0]; - break; - case element::i32: - actual_const = static_cast(reinterpret_cast(data_ptr)[0]); - break; - case element::u32: - actual_const = static_cast(reinterpret_cast(data_ptr)[0]); - break; - case element::i64: - actual_const = static_cast(reinterpret_cast(data_ptr)[0]); - break; - case element::u64: - actual_const = static_cast(reinterpret_cast(data_ptr)[0]); - break; - case element::i8: - actual_const = static_cast(reinterpret_cast(data_ptr)[0]); - break; - case element::u8: - actual_const = static_cast(reinterpret_cast(data_ptr)[0]); - break; - case element::i16: - actual_const = static_cast(reinterpret_cast(data_ptr)[0]); - break; - case element::u16: - actual_const = static_cast(reinterpret_cast(data_ptr)[0]); - break; - case element::f64: - actual_const = static_cast(reinterpret_cast(data_ptr)[0]); - break; - default: - return false; + case element::f32: + actual_const = reinterpret_cast(data_ptr)[0]; + break; + case element::i32: + actual_const = static_cast(reinterpret_cast(data_ptr)[0]); + break; + case element::u32: + actual_const = static_cast(reinterpret_cast(data_ptr)[0]); + break; + case element::i64: + actual_const = static_cast(reinterpret_cast(data_ptr)[0]); + break; + case element::u64: + actual_const = static_cast(reinterpret_cast(data_ptr)[0]); + break; + case element::i8: + actual_const = static_cast(reinterpret_cast(data_ptr)[0]); + break; + case element::u8: + actual_const = static_cast(reinterpret_cast(data_ptr)[0]); + break; + case element::i16: + actual_const = static_cast(reinterpret_cast(data_ptr)[0]); + break; + case element::u16: + actual_const = static_cast(reinterpret_cast(data_ptr)[0]); + break; + case element::f64: + actual_const = static_cast(reinterpret_cast(data_ptr)[0]); + break; + default: + return false; } float expected_const = 0; - if (is_type(eltwise) || - is_type(eltwise)) { + if (is_type(eltwise) || is_type(eltwise)) { expected_const = 1; } if (actual_const != expected_const) {