@@ -73,20 +73,14 @@ bool parse_slice_window(const std::shared_ptr<ov::Node>& node, int64_t& start, i
7373 const auto & new_axis_mask = strided_slice->get_new_axis_mask ();
7474 const auto & shrink_axis_mask = strided_slice->get_shrink_axis_mask ();
7575 const auto & ellipsis_mask = strided_slice->get_ellipsis_mask ();
76- for (const auto v : new_axis_mask) {
77- if (v != 0 ) {
78- return false ;
79- }
80- }
81- for (const auto v : shrink_axis_mask) {
82- if (v != 0 ) {
83- return false ;
84- }
85- }
86- for (const auto v : ellipsis_mask) {
87- if (v != 0 ) {
88- return false ;
89- }
76+
77+ auto pred = [](int64_t a) {
78+ return a != 0 ;
79+ };
80+ if (std::any_of (new_axis_mask.begin (), new_axis_mask.end (), pred) ||
81+ std::any_of (shrink_axis_mask.begin (), shrink_axis_mask.end (), pred) ||
82+ std::any_of (ellipsis_mask.begin (), ellipsis_mask.end (), pred)) {
83+ return false ;
9084 }
9185
9286 if (strides[0 ] != 1 || strides[1 ] != 1 ) {
@@ -167,7 +161,7 @@ bool parse_slice_window(const std::shared_ptr<ov::Node>& node, int64_t& start, i
167161 return false ;
168162}
169163
170- bool is_reshape_for_concat_axis (const std::shared_ptr<op::v1::Reshape>& reshape, int64_t concat_axis ) {
164+ bool is_reshape_to_unsqueeze_on_axis_1 (const std::shared_ptr<op::v1::Reshape>& reshape) {
171165 const auto input_pshape = reshape->get_input_partial_shape (0 );
172166 const auto output_pshape = reshape->get_output_partial_shape (0 );
173167 if (input_pshape.rank ().is_dynamic () || output_pshape.rank ().is_dynamic ()) {
@@ -178,12 +172,7 @@ bool is_reshape_for_concat_axis(const std::shared_ptr<op::v1::Reshape>& reshape,
178172 return false ;
179173 }
180174
181- if (!input_pshape[0 ].is_static () || !input_pshape[1 ].is_static () || !output_pshape[0 ].is_static () ||
182- !output_pshape[1 ].is_static () || !output_pshape[2 ].is_static ()) {
183- return false ;
184- }
185-
186- if (concat_axis != 1 ) {
175+ if (!input_pshape.is_static () || !output_pshape.is_static ()) {
187176 return false ;
188177 }
189178
@@ -196,32 +185,26 @@ bool is_reshape_for_concat_axis(const std::shared_ptr<op::v1::Reshape>& reshape,
196185StridedSliceReshapeConcatFusion::StridedSliceReshapeConcatFusion () {
197186 MATCHER_SCOPE (StridedSliceReshapeConcatFusion);
198187
199- auto concat_pattern = ov::pass:: pattern::wrap_type<op::v0::Concat>();
188+ auto concat_pattern = pattern::wrap_type<op::v0::Concat>(pattern::has_static_rank () );
200189
201- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS ](ov::pass:: pattern::Matcher& m) {
190+ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS ](pattern::Matcher& m) {
202191 const auto & pattern_to_output = m.get_pattern_value_map ();
203192 auto concat = ov::as_type_ptr<op::v0::Concat>(pattern_to_output.at (concat_pattern).get_node_shared_ptr ());
204193 if (!concat || concat->get_input_size () < 2 ) {
205194 return false ;
206195 }
207196
208197 const auto output_rank = concat->get_output_partial_shape (0 ).rank ();
209- if (output_rank.is_dynamic ()) {
210- return false ;
211- }
212-
213198 int64_t concat_axis = concat->get_axis ();
214199 const auto rank = output_rank.get_length ();
215200 if (!ov::util::is_axis_valid (concat_axis, rank)) {
216201 return false ;
217202 }
218203 concat_axis = static_cast <int64_t >(ov::util::normalize_axis (concat_axis, rank));
219-
220204 if (concat_axis != 1 ) {
221205 return false ;
222206 }
223207
224- std::shared_ptr<Node> common_data_node;
225208 Output<Node> common_data;
226209 int64_t window_size = -1 ;
227210 std::vector<int64_t > starts;
@@ -230,30 +213,26 @@ StridedSliceReshapeConcatFusion::StridedSliceReshapeConcatFusion() {
230213 NodeVector matched_nodes{concat};
231214
232215 for (size_t i = 0 ; i < concat->get_input_size (); ++i) {
233- const auto reshape = ov::as_type_ptr<op::v1::Reshape>(concat->get_input_node_shared_ptr (i));
216+ auto reshape = ov::as_type_ptr<op::v1::Reshape>(concat->get_input_node_shared_ptr (i));
234217 if (!reshape || reshape->output (0 ).get_target_inputs ().size () != 1 ||
235- !is_reshape_for_concat_axis (reshape, concat_axis )) {
218+ !is_reshape_to_unsqueeze_on_axis_1 (reshape)) {
236219 return false ;
237220 }
238- matched_nodes.push_back (reshape);
239221
240222 int64_t start = 0 ;
241223 int64_t stop = 0 ;
242224 Output<Node> data;
243- const auto slice_like = reshape->input_value (0 ).get_node_shared_ptr ();
244- if (! parse_slice_window ( slice_like, start, stop, data) ) {
225+ auto slice_like = reshape->input_value (0 ).get_node_shared_ptr ();
226+ if (slice_like-> output ( 0 ). get_target_inputs (). size () != 1 ) {
245227 return false ;
246228 }
247-
248- if (slice_like->output (0 ).get_target_inputs ().size () != 1 ) {
229+ if (!parse_slice_window (slice_like, start, stop, data)) {
249230 return false ;
250231 }
251- matched_nodes.push_back (slice_like);
252232
253- if (!common_data_node) {
254- common_data_node = data.get_node_shared_ptr ();
233+ if (!common_data.get_node_shared_ptr ()) {
255234 common_data = data;
256- } else if (common_data_node != data. get_node_shared_ptr () ) {
235+ } else if (common_data != data) {
257236 return false ;
258237 }
259238
@@ -264,6 +243,8 @@ StridedSliceReshapeConcatFusion::StridedSliceReshapeConcatFusion() {
264243 return false ;
265244 }
266245
246+ matched_nodes.push_back (std::move (reshape));
247+ matched_nodes.push_back (std::move (slice_like));
267248 starts.push_back (start);
268249 }
269250
@@ -291,7 +272,7 @@ StridedSliceReshapeConcatFusion::StridedSliceReshapeConcatFusion() {
291272 return true ;
292273 };
293274
294- auto m = std::make_shared<ov::pass:: pattern::Matcher>(concat_pattern, matcher_name);
275+ auto m = std::make_shared<pattern::Matcher>(concat_pattern, matcher_name);
295276 register_matcher (m, callback);
296277}
297278
0 commit comments