From b372a70fbde9758094ef02db4d6e37f958945a4c Mon Sep 17 00:00:00 2001 From: Tikhonov Ivan Date: Wed, 27 Sep 2023 16:43:51 +0330 Subject: [PATCH] codestyle --- .../transpose_sinking/ts_strided_slice.cpp | 36 +++--- .../transpose_sinking/ts_strided_slice.cpp | 114 +++++++++--------- 2 files changed, 78 insertions(+), 72 deletions(-) diff --git a/src/common/transformations/src/transformations/transpose_sinking/ts_strided_slice.cpp b/src/common/transformations/src/transformations/transpose_sinking/ts_strided_slice.cpp index 0517cb03193275..4928c948301a8a 100644 --- a/src/common/transformations/src/transformations/transpose_sinking/ts_strided_slice.cpp +++ b/src/common/transformations/src/transformations/transpose_sinking/ts_strided_slice.cpp @@ -140,25 +140,27 @@ bool align_inputs(const std::shared_ptr& strided_slice // `stride` input has to be initialized with 1 input_const_val.resize(expected_size, 1); } - new_inputs[input_idx-1] = ov::op::v0::Constant::create(input_const->get_element_type(), {input_const_val.size()}, input_const_val); + new_inputs[input_idx - 1] = ov::op::v0::Constant::create(input_const->get_element_type(), + {input_const_val.size()}, + input_const_val); - copy_runtime_info(input_const, new_inputs[input_idx-1]); + copy_runtime_info(input_const, new_inputs[input_idx - 1]); } } // connect the new begin, end, stride inputs to StridedSlice operation auto axis = std::make_shared(element::i32, Shape{}, 0); for (size_t i = 1; i <= new_inputs.size(); ++i) { - if (new_inputs[i-1]) { - strided_slice->input(i).replace_source_output(new_inputs[i-1]); + if (new_inputs[i - 1]) { + strided_slice->input(i).replace_source_output(new_inputs[i - 1]); } // insert Gather strided_slice->input(i).replace_source_output( - ChangeValuesOrder(strided_slice->input_value(i), transpose_order_values, axis)); + ChangeValuesOrder(strided_slice->input_value(i), transpose_order_values, axis)); } return true; } -} +} // namespace TSStridedSliceForward::TSStridedSliceForward() { MATCHER_SCOPE(TSStridedSliceForward); @@ -209,14 +211,16 @@ TSStridedSliceForward::TSStridedSliceForward() { // apply shrink_mask to get the correct order. // the mask have not to be transposed, so apply transpose 2nd time to get the original order. - auto shrink_axes = convert_mask_to_axis_vec(transpose_mask(strided_slice->get_shrink_axis_mask(), transpose_order_values)); + auto shrink_axes = + convert_mask_to_axis_vec(transpose_mask(strided_slice->get_shrink_axis_mask(), transpose_order_values)); transpose_order_values = GetOrderAfterReduction(shrink_axes, transpose_order_values); // add Transpose op to StridedSlice output - auto new_transpose_order = std::make_shared(transpose_info.transpose_const->get_element_type(), - Shape{transpose_order_values.size()}, - transpose_order_values); + auto new_transpose_order = + std::make_shared(transpose_info.transpose_const->get_element_type(), + Shape{transpose_order_values.size()}, + transpose_order_values); TransposeInputsInfo transpose_input_info = {transpose_info.transpose, new_transpose_order, 0}; strided_slice->validate_and_infer_types(); @@ -230,14 +234,14 @@ TSStridedSliceForward::TSStridedSliceForward() { TSStridedSliceBackward::TSStridedSliceBackward() { MATCHER_SCOPE(TSStridedSliceBackward); - auto main_node_label = wrap_type([](const Output &output) -> bool { + auto main_node_label = wrap_type([](const Output& output) -> bool { return has_static_rank()(output) && CheckTransposeConsumers(output); }); auto transpose_const_label = wrap_type(); auto transpose_label = wrap_type({main_node_label, transpose_const_label}, - [](const Output &output) -> bool { + [](const Output& output) -> bool { return has_static_rank()(output); }); @@ -250,8 +254,8 @@ TSStridedSliceBackward::TSStridedSliceBackward() { return false; } - auto strided_slice = ov::as_type_ptr(main_node);f - if (!strided_slice) { + auto strided_slice = ov::as_type_ptr(main_node); + f if (!strided_slice) { return false; } @@ -280,8 +284,8 @@ TSStridedSliceBackward::TSStridedSliceBackward() { size_t num_elements_in_begin_input = expected_size; // apply shrink_ mask to get the correct order - auto shrink_axes = convert_shrink_mask_to_axis_vec(strided_slice->get_shrink_axis_mask(), - strided_slice->get_new_axis_mask()); + auto shrink_axes = + convert_shrink_mask_to_axis_vec(strided_slice->get_shrink_axis_mask(), strided_slice->get_new_axis_mask()); transpose_order_values = GetOrderBeforeReduction(shrink_axes, transpose_order_values); if (!align_inputs(strided_slice, transpose_order_values, expected_size, num_elements_in_begin_input)) { diff --git a/src/common/transformations/tests/transpose_sinking/ts_strided_slice.cpp b/src/common/transformations/tests/transpose_sinking/ts_strided_slice.cpp index a94ccad06343f8..a317345fab6113 100644 --- a/src/common/transformations/tests/transpose_sinking/ts_strided_slice.cpp +++ b/src/common/transformations/tests/transpose_sinking/ts_strided_slice.cpp @@ -51,6 +51,7 @@ class StridedSliceFactory : public IFactory { void set_masks(const StridedSliceMasks& masks) { m_masks = masks; } + private: StridedSliceMasks m_masks; }; @@ -109,11 +110,10 @@ auto test_forward_strided_slice = [](const StridedSliceForwardArguments& test_ar // Reference model description const auto& ref_transpose_order = test_arguments.reference_transpose_order; const auto& ref_gather_order = test_arguments.reference_gather_order; - auto new_transpose = [ref_transpose_order](const vector& idxs, const OutputVector& out_vec) -> OutputVector { + auto new_transpose = [ref_transpose_order](const vector& idxs, + const OutputVector& out_vec) -> OutputVector { OutputVector new_out_vec(out_vec.size()); - auto order = make_shared(element::i32, - Shape{ref_transpose_order.size()}, - ref_transpose_order); + auto order = make_shared(element::i32, Shape{ref_transpose_order.size()}, ref_transpose_order); new_out_vec[0] = make_shared(out_vec[0], order); return new_out_vec; }; @@ -125,8 +125,8 @@ auto test_forward_strided_slice = [](const StridedSliceForwardArguments& test_ar } } - - auto update_gather_inputs = [ref_gather_order, new_axes_cnt](const vector& idxs, const OutputVector& out_vec) -> OutputVector { + auto update_gather_inputs = [ref_gather_order, new_axes_cnt](const vector& idxs, + const OutputVector& out_vec) -> OutputVector { OutputVector new_out_vec = out_vec; auto axis = std::make_shared(element::i32, Shape{}, 0); size_t expected_size = out_vec[0].get_partial_shape().rank().get_length() + new_axes_cnt; @@ -146,11 +146,12 @@ auto test_forward_strided_slice = [](const StridedSliceForwardArguments& test_ar // `stride` input have to be initialized with 1 input_const_val.resize(expected_size, 1); } - auto new_input = ov::op::v0::Constant::create(input_const->get_element_type(), {input_const_val.size()}, input_const_val); + auto new_input = ov::op::v0::Constant::create(input_const->get_element_type(), + {input_const_val.size()}, + input_const_val); - auto indices = std::make_shared(element::i32, - Shape{ref_gather_order.size()}, - ref_gather_order); + auto indices = + std::make_shared(element::i32, Shape{ref_gather_order.size()}, ref_gather_order); new_out_vec[idx] = std::make_shared(new_input, indices, axis); } return new_out_vec; @@ -169,10 +170,10 @@ auto test_forward_strided_slice = [](const StridedSliceForwardArguments& test_ar auto fw_test_1 = []() { StridedSliceForwardArguments args; args.inputs_to_main = { - parameter(f32, {7, 10}), // data - constant(i32, {2}, {1, 2}), // begin - constant(i32, {2}, {7, 6}), // end - constant(i32, {2}, {1, 2}) // stride + parameter(f32, {7, 10}), // data + constant(i32, {2}, {1, 2}), // begin + constant(i32, {2}, {7, 6}), // end + constant(i32, {2}, {1, 2}) // stride }; // empty masks args.masks.begin = {0, 0}; @@ -198,10 +199,10 @@ auto fw_test_1 = []() { auto fw_test_2 = []() { StridedSliceForwardArguments args; args.inputs_to_main = { - parameter(f32, {7, 10}), // data - constant(i32, {2}, {1, 2}), // begin - constant(i32, {2}, {7, 6}), // end - constant(i32, {2}, {1, 2}) // stride + parameter(f32, {7, 10}), // data + constant(i32, {2}, {1, 2}), // begin + constant(i32, {2}, {7, 6}), // end + constant(i32, {2}, {1, 2}) // stride }; // begin and end masks args.masks.begin = {1, 0}; @@ -226,15 +227,15 @@ auto fw_test_2 = []() { auto fw_test_3 = []() { StridedSliceForwardArguments args; args.inputs_to_main = { - parameter(f32, {7, 10}), // data - constant(i32, {2}, {1, 2}), // begin - constant(i32, {2}, {7, 6}), // end - constant(i32, {2}, {1, 2}) // stride + parameter(f32, {7, 10}), // data + constant(i32, {2}, {1, 2}), // begin + constant(i32, {2}, {7, 6}), // end + constant(i32, {2}, {1, 2}) // stride }; // new axis mask args.masks.begin = {0, 0, 0, 0}; args.masks.end = {0, 0, 0, 0}; - args.masks.new_axis = {1, 1, 0 ,0}; + args.masks.new_axis = {1, 1, 0, 0}; args.masks.shrink_axis = {0, 0, 0, 0}; args.masks.ellipsis = {0, 0, 0, 0}; @@ -254,10 +255,10 @@ auto fw_test_3 = []() { auto fw_test_4 = []() { StridedSliceForwardArguments args; args.inputs_to_main = { - parameter(f32, {7, 10}), // data - constant(i32, {2}, {1, 2}), // begin - constant(i32, {2}, {7, 6}), // end - constant(i32, {2}, {1, 2}) // stride + parameter(f32, {7, 10}), // data + constant(i32, {2}, {1, 2}), // begin + constant(i32, {2}, {7, 6}), // end + constant(i32, {2}, {1, 2}) // stride }; // shrink mask args.masks.begin = {0, 0}; @@ -282,10 +283,10 @@ auto fw_test_4 = []() { auto fw_test_5 = []() { StridedSliceForwardArguments args; args.inputs_to_main = { - parameter(f32, {7, 4, 5, 10}), // data - constant(i32, {4}, {1, 2, 2, 1}), // begin - constant(i32, {4}, {5, 4, 4, 4}), // end - constant(i32, {4}, {1, 2, 1, 2}) // stride + parameter(f32, {7, 4, 5, 10}), // data + constant(i32, {4}, {1, 2, 2, 1}), // begin + constant(i32, {4}, {5, 4, 4, 4}), // end + constant(i32, {4}, {1, 2, 1, 2}) // stride }; // 4dims input, shrink mask args.masks.begin = {0, 0, 0, 0}; @@ -310,10 +311,10 @@ auto fw_test_5 = []() { auto fw_test_6 = []() { StridedSliceForwardArguments args; args.inputs_to_main = { - parameter(f32, {7, 10}), // data - constant(i32, {4}, {1, 0, 2, 0}), // begin - constant(i32, {4}, {7, 1, 6, 1}), // end - constant(i32, {4}, {1, 1, 2, 1}) // stride + parameter(f32, {7, 10}), // data + constant(i32, {4}, {1, 0, 2, 0}), // begin + constant(i32, {4}, {7, 1, 6, 1}), // end + constant(i32, {4}, {1, 1, 2, 1}) // stride }; // mixed masks: new_axis and shrink_mask @@ -340,10 +341,10 @@ auto fw_test_6 = []() { auto fw_test_7 = []() { StridedSliceForwardArguments args; args.inputs_to_main = { - parameter(f32, {7, 10}), // data - constant(i32, {4}, {1, 0, 2, 0}), // begin - constant(i32, {4}, {7, 1, 6, 1}), // end - constant(i32, {4}, {1, 1, 2, 1}) // stride + parameter(f32, {7, 10}), // data + constant(i32, {4}, {1, 0, 2, 0}), // begin + constant(i32, {4}, {7, 1, 6, 1}), // end + constant(i32, {4}, {1, 1, 2, 1}) // stride }; // mixed masks: new_axis and shrink_mask @@ -370,10 +371,10 @@ auto fw_test_7 = []() { auto fw_test_8 = []() { StridedSliceForwardArguments args; args.inputs_to_main = { - parameter(f32, {7, 4, 5, 10}), // data - constant(i32, {6}, {0, 0, 1, 2, 2, 1}), // begin - constant(i32, {6}, {1, 1, 5, 4, 4, 4}), // end - constant(i32, {6}, {1, 1, 1, 2, 1, 2}) // stride + parameter(f32, {7, 4, 5, 10}), // data + constant(i32, {6}, {0, 0, 1, 2, 2, 1}), // begin + constant(i32, {6}, {1, 1, 5, 4, 4, 4}), // end + constant(i32, {6}, {1, 1, 1, 2, 1, 2}) // stride }; // mixed masks: begin, end, shrink, new_axis args.masks.begin = {0, 0, 0, 1, 0, 0}; @@ -398,10 +399,10 @@ auto fw_test_8 = []() { auto fw_test_9 = []() { StridedSliceForwardArguments args; args.inputs_to_main = { - parameter(f32, {7, 4, 5, 10}), // data - constant(i32, {4}, {1, 2, 2, 1}), // begin - constant(i32, {4}, {5, 4, 4, 4}), // end - constant(i32, {4}, {1, 2, 1, 2}) // stride + parameter(f32, {7, 4, 5, 10}), // data + constant(i32, {4}, {1, 2, 2, 1}), // begin + constant(i32, {4}, {5, 4, 4, 4}), // end + constant(i32, {4}, {1, 2, 1, 2}) // stride }; // mixed masks: shrink, new_axis args.masks.begin = {0, 0, 0, 0}; @@ -451,11 +452,10 @@ auto test_backward_strided_slice = [](const StridedSliceForwardArguments& test_a // Reference model description const auto& ref_transpose_order = test_arguments.reference_transpose_order; const auto& ref_gather_order = test_arguments.reference_gather_order; - auto new_transpose = [ref_transpose_order](const vector& idxs, const OutputVector& out_vec) -> OutputVector { + auto new_transpose = [ref_transpose_order](const vector& idxs, + const OutputVector& out_vec) -> OutputVector { OutputVector new_out_vec = out_vec; - auto order = make_shared(element::i32, - Shape{ref_transpose_order.size()}, - ref_transpose_order); + auto order = make_shared(element::i32, Shape{ref_transpose_order.size()}, ref_transpose_order); new_out_vec[0] = make_shared(out_vec[0], order); return new_out_vec; }; @@ -467,7 +467,8 @@ auto test_backward_strided_slice = [](const StridedSliceForwardArguments& test_a } } - auto update_gather_inputs = [ref_gather_order, new_axes_cnt](const vector& idxs, const OutputVector& out_vec) -> OutputVector { + auto update_gather_inputs = [ref_gather_order, new_axes_cnt](const vector& idxs, + const OutputVector& out_vec) -> OutputVector { OutputVector new_out_vec = out_vec; auto axis = std::make_shared(element::i32, Shape{}, 0); size_t expected_size = out_vec[0].get_partial_shape().rank().get_length() + new_axes_cnt; @@ -487,11 +488,12 @@ auto test_backward_strided_slice = [](const StridedSliceForwardArguments& test_a // `stride` input have to be initialized with 1 input_const_val.resize(expected_size, 1); } - auto new_input = ov::op::v0::Constant::create(input_const->get_element_type(), {input_const_val.size()}, input_const_val); + auto new_input = ov::op::v0::Constant::create(input_const->get_element_type(), + {input_const_val.size()}, + input_const_val); - auto indices = std::make_shared(element::i32, - Shape{ref_gather_order.size()}, - ref_gather_order); + auto indices = + std::make_shared(element::i32, Shape{ref_gather_order.size()}, ref_gather_order); new_out_vec[idx] = std::make_shared(new_input, indices, axis); } return new_out_vec;