From 5fd3a395459c7f48da3eba7717d8cf92a89d248e Mon Sep 17 00:00:00 2001 From: Tomasz Jankowski Date: Fri, 10 Jan 2025 11:29:23 +0100 Subject: [PATCH 1/5] Replace std dynamic casts with ov defined std::dynamic_pointer_cast -> ov::as_type_ptr std::dynamic_cast -> ov::as_type Signed-off-by: Tomasz Jankowski --- .../src/assign_and_read_value.cpp | 2 +- .../src/low_precision.cpp | 2 +- .../src/markup_can_be_quantized.cpp | 8 ++--- .../src/compress_quantize_weigths.cpp | 2 +- .../src/pruning/init_const_mask.cpp | 2 +- .../src/pruning/init_masks.cpp | 5 ++- .../src/pruning/propagate_masks.cpp | 12 +++---- .../src/pruning/shrink_weights.cpp | 4 +-- src/common/snippets/src/generator.cpp | 16 ++++----- src/common/snippets/src/op/subgraph.cpp | 2 +- .../snippets/src/pass/fq_decomposition.cpp | 4 +-- .../depth_to_space_fusion.hpp | 2 +- .../convert_reduce_to_pooling.hpp | 2 +- .../convert_reduce_to_reshape.hpp | 2 +- .../transformations/utils/gen_pattern.hpp | 6 ++-- .../transformations/utils/print_model.hpp | 6 ++-- .../include/transformations/utils/utils.hpp | 6 ++-- .../broadcast_elementwise_fusion.cpp | 2 +- .../convert_nms_gather_path_to_unsigned.cpp | 2 +- .../eliminate_duplicate_ti_inputs.cpp | 18 +++++----- .../fold_subgraph_empty_inputs.cpp | 2 +- .../common_optimizations/glu_fusion.cpp | 16 ++++----- .../common_optimizations/nop_elimination.cpp | 24 ++++++------- .../common_optimizations/pad_fusion.cpp | 10 +++--- .../common_optimizations/prelu_fusion.cpp | 2 +- .../pull_through_reduce.cpp | 6 ++-- .../push_constant_to_subgraph.cpp | 2 +- .../reduce_reshape_fusion.cpp | 9 ++--- ...move_multi_subgraph_op_dangling_params.cpp | 2 +- .../reverse_shape_and_type_infer.cpp | 6 ++-- .../common_optimizations/ric_fusion.cpp | 2 +- .../common_optimizations/sdpa_fusion.cpp | 3 +- .../common_optimizations/sequence_fusion.cpp | 36 +++++++++---------- .../shared_ops_optimization.cpp | 4 +-- .../space_to_batch_fusion.cpp | 2 +- .../transpose_sinking.cpp | 4 +-- .../control_flow/unroll_if.cpp | 2 +- .../control_flow/unroll_tensor_iterator.cpp | 11 +++--- .../src/transformations/convert_precision.cpp | 6 ++-- .../flush_fp32_subnormals_to_zero.cpp | 2 +- .../batch_norm_decomposition.cpp | 4 +-- .../op_conversions/convert_batch_to_space.cpp | 4 +-- .../convert_fc_to_compressed.cpp | 4 +-- ...rt_multiclass_nms_to_multiclass_nms_ie.cpp | 2 +- .../convert_pad_to_group_conv.cpp | 2 +- .../op_conversions/convert_space_to_batch.cpp | 4 +-- .../convert_ti_to_sequences.cpp | 16 ++++----- .../convert_xor_to_logical_xor.cpp | 2 +- .../lstm_cell_decomposition.cpp | 2 +- .../smart_reshape/lstm_states_broadcast.cpp | 12 +++---- .../smart_reshape/reshape_sinking.cpp | 16 ++++----- .../symbol_optimization.cpp | 2 +- .../src/transformations/utils/utils.cpp | 2 +- .../eliminate_duplicate_ti_inputs.cpp | 2 +- .../common_optimizations/gru_cell_fusion.cpp | 4 +-- .../transpose_sinking_test.cpp | 4 +-- .../tests/transpose_sinking/ts_test_utils.cpp | 4 +-- src/core/reference/src/op/loop.cpp | 9 +++-- src/core/reference/src/op/tensor_iterator.cpp | 9 +++-- src/core/src/bound_evaluate.cpp | 4 +-- src/core/src/model.cpp | 2 +- src/core/src/op/convert_like.cpp | 2 +- src/core/src/op/loop.cpp | 2 +- src/core/src/op/reshape.cpp | 2 +- src/core/src/op/unique.cpp | 8 ++--- src/core/src/op/unsqueeze.cpp | 2 +- src/core/src/op/util/gather_base.cpp | 6 ++-- src/core/src/op/util/squeeze_base.cpp | 2 +- src/core/src/op/util/symbolic_info.cpp | 2 +- src/core/src/pass/constant_folding.cpp | 2 +- src/core/src/pass/graph_rewrite.cpp | 6 ++-- src/core/src/pass/low_latency.cpp | 13 ++++--- src/core/src/pass/make_stateful.cpp | 2 +- src/core/src/pass/manager.cpp | 6 ++-- src/core/src/pass/sdpa_to_paged_attention.cpp | 2 +- src/core/src/pass/stateful_to_stateless.cpp | 7 ++-- src/core/src/pass/visualize_tree.cpp | 4 +-- src/core/src/preprocess/preprocess_impls.cpp | 2 +- src/core/src/runtime/itensor.cpp | 3 +- src/core/tests/copy.cpp | 2 +- src/core/tests/graph_rewrite.cpp | 2 +- src/core/tests/pass/constant_folding.cpp | 18 +++++----- .../tests/pass/serialization/from_model.cpp | 2 +- src/core/tests/pass_config.cpp | 4 +-- src/core/tests/preprocess.cpp | 4 +-- src/core/tests/type_prop/if.cpp | 2 +- src/inference/src/check_network_batchable.cpp | 4 +-- src/inference/src/dev/icompiled_model.cpp | 2 +- src/inference/tests/functional/local_test.cpp | 6 ++-- 89 files changed, 234 insertions(+), 251 deletions(-) diff --git a/src/common/low_precision_transformations/src/assign_and_read_value.cpp b/src/common/low_precision_transformations/src/assign_and_read_value.cpp index 6b49f0b21c6675..587f65be3afc87 100644 --- a/src/common/low_precision_transformations/src/assign_and_read_value.cpp +++ b/src/common/low_precision_transformations/src/assign_and_read_value.cpp @@ -109,7 +109,7 @@ bool AssignAndReadValueTransformation::canBeTransformed(const TransformationCont return false; } - const auto readValue = std::dynamic_pointer_cast(op->get_control_dependencies()[0]); + const auto readValue = ov::as_type_ptr(op->get_control_dependencies()[0]); if (!readValue) { return false; } diff --git a/src/common/low_precision_transformations/src/low_precision.cpp b/src/common/low_precision_transformations/src/low_precision.cpp index 52479a5c2dc1fa..4045e409a413eb 100644 --- a/src/common/low_precision_transformations/src/low_precision.cpp +++ b/src/common/low_precision_transformations/src/low_precision.cpp @@ -112,7 +112,7 @@ void make_matcher_type_relaxed(ov::pass::GraphRewrite* transformation) { auto p_node = std::make_shared(element::f32, Shape{}, is_op_type); ov::graph_rewrite_callback callback = [](ov::pass::pattern::Matcher& m) { - auto l_node = std::dynamic_pointer_cast(m.get_match_root()); + auto l_node = ov::as_type_ptr(m.get_match_root()); if (!l_node) { THROW_TRANSFORMATION_EXCEPTION << "unexpected operation type for type relaxed conversion"; } diff --git a/src/common/low_precision_transformations/src/markup_can_be_quantized.cpp b/src/common/low_precision_transformations/src/markup_can_be_quantized.cpp index 6097498ca59ea6..94e5ca396017f5 100644 --- a/src/common/low_precision_transformations/src/markup_can_be_quantized.cpp +++ b/src/common/low_precision_transformations/src/markup_can_be_quantized.cpp @@ -36,25 +36,25 @@ bool ov::pass::low_precision::MarkupCanBeQuantized::run_on_model(const std::shar continue; } - if (const auto convolution = std::dynamic_pointer_cast(node)) { + if (const auto convolution = ov::as_type_ptr(node)) { if (!ConvolutionTransformation::isQuantizedStatic(convolution, defaultPrecisions)) { setEmptyPrecisions(convolution); } continue; } - if (const auto convolutionBackpropData = std::dynamic_pointer_cast(node)) { + if (const auto convolutionBackpropData = ov::as_type_ptr(node)) { if (!ConvolutionBackpropDataTransformation::isQuantizedStatic(convolutionBackpropData, defaultPrecisions)) { setEmptyPrecisions(convolutionBackpropData); } continue; } - if (const auto groupConvolution = std::dynamic_pointer_cast(node)) { + if (const auto groupConvolution = ov::as_type_ptr(node)) { if (!GroupConvolutionTransformation::isQuantizedStatic(groupConvolution, defaultPrecisions)) { setEmptyPrecisions(groupConvolution); } continue; } - if (const auto concat = std::dynamic_pointer_cast(node)) { + if (const auto concat = ov::as_type_ptr(node)) { if (!ConcatTransformation::isQuantizedStatic(concat)) { setEmptyPrecisions(concat); } diff --git a/src/common/offline_transformations/src/compress_quantize_weigths.cpp b/src/common/offline_transformations/src/compress_quantize_weigths.cpp index 1ad52a488904d7..10ebb81854f885 100644 --- a/src/common/offline_transformations/src/compress_quantize_weigths.cpp +++ b/src/common/offline_transformations/src/compress_quantize_weigths.cpp @@ -89,7 +89,7 @@ ov::pass::CompressWeightsWithFakeQuantize::CompressWeightsWithFakeQuantize() { {weights_pattern, input_low_pattern, input_high_pattern, output_low_pattern, output_high_pattern}); ov::matcher_pass_callback callback = [=](pattern::Matcher& m) { - auto fq = std::dynamic_pointer_cast(m.get_match_root()); + auto fq = ov::as_type_ptr(m.get_match_root()); if (!fq) return false; const auto& high_precision_type = fq->get_element_type(); diff --git a/src/common/offline_transformations/src/pruning/init_const_mask.cpp b/src/common/offline_transformations/src/pruning/init_const_mask.cpp index 5b9b2b42cb098d..b88ebc7420fb50 100644 --- a/src/common/offline_transformations/src/pruning/init_const_mask.cpp +++ b/src/common/offline_transformations/src/pruning/init_const_mask.cpp @@ -18,7 +18,7 @@ ov::pass::InitConstMask::InitConstMask(const ov::AxisSet& dims, pattern::type_matches_any({element::i8, element::u8, element::f16, element::f32, element::f64})); matcher_pass_callback callback = [=](pattern::Matcher& m) { - auto const_node = std::dynamic_pointer_cast(m.get_match_root()); + auto const_node = ov::as_type_ptr(m.get_match_root()); if (!const_node) return false; diff --git a/src/common/offline_transformations/src/pruning/init_masks.cpp b/src/common/offline_transformations/src/pruning/init_masks.cpp index 6cdede0b5f8252..abe843a8b56d30 100644 --- a/src/common/offline_transformations/src/pruning/init_masks.cpp +++ b/src/common/offline_transformations/src/pruning/init_masks.cpp @@ -68,8 +68,7 @@ class ov::pass::init_masks::InitMatMulMask : public MatcherPass { ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) { const auto& pattern_map = m.get_pattern_value_map(); - const auto& matmul = - std::dynamic_pointer_cast(pattern_map.at(matmul_pattern).get_node_shared_ptr()); + const auto& matmul = ov::as_type_ptr(pattern_map.at(matmul_pattern).get_node_shared_ptr()); if (!matmul) return false; @@ -117,7 +116,7 @@ class ov::pass::init_masks::InitMatMulMask : public MatcherPass { return false; } // 2. Get constant rank to set mask on last dimension - const auto const_op = std::dynamic_pointer_cast(cur_node); + const auto const_op = ov::as_type_ptr(cur_node); const auto shape_rank = const_op->get_shape().size(); const size_t shift = (matmul->get_transpose_b()) ? 2 : 1; if (shape_rank < shift) { diff --git a/src/common/offline_transformations/src/pruning/propagate_masks.cpp b/src/common/offline_transformations/src/pruning/propagate_masks.cpp index 081a49109ec947..fad5908a35a827 100644 --- a/src/common/offline_transformations/src/pruning/propagate_masks.cpp +++ b/src/common/offline_transformations/src/pruning/propagate_masks.cpp @@ -100,7 +100,7 @@ class ov::pass::mask_propagation::MatMul : public MatcherPass { a_mask_row = a_mask.get(); auto b_mask_row = b_mask.get(); - const auto matmul_op = std::dynamic_pointer_cast(m_matmul.get_node_shared_ptr()); + const auto matmul_op = ov::as_type_ptr(m_matmul.get_node_shared_ptr()); const auto transpose_a = matmul_op->get_transpose_a(); const auto transpose_b = matmul_op->get_transpose_b(); @@ -717,13 +717,13 @@ class ov::pass::mask_propagation::FakeQuantize : public MatcherPass { m_input_high.get_node_shared_ptr(), m_output_low.get_node_shared_ptr(), m_output_high.get_node_shared_ptr()}; - auto fq_node = std::dynamic_pointer_cast(m_output.get_node_shared_ptr()); + auto fq_node = ov::as_type_ptr(m_output.get_node_shared_ptr()); if (!fq_node) return false; size_t idx = 0; if (fq_node->get_auto_broadcast() != ov::op::AutoBroadcastType::NONE) { for (const auto& node : fq_params_nodes) { - auto const_node = std::dynamic_pointer_cast(node); + auto const_node = ov::as_type_ptr(node); if (!const_node) OPENVINO_THROW("Unexpected operation type."); auto new_shape = broadcast_shape_to_rank(const_node->get_shape(), @@ -771,7 +771,7 @@ class ov::pass::mask_propagation::Concat : public MatcherPass { ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) { const auto& pattern_map = m.get_pattern_value_map(); const auto& m_output = pattern_map.at(concat); - auto concat_ptr = std::dynamic_pointer_cast(m_output.get_node_shared_ptr()); + auto concat_ptr = ov::as_type_ptr(m_output.get_node_shared_ptr()); if (!concat_ptr) { return false; } @@ -930,7 +930,7 @@ class ov::pass::mask_propagation::Reduce : public MatcherPass { // Check reduce operation reduces only dimension without masks if (auto input_mask = getMask(m_input)) { auto output_mask = std::make_shared(m_output.get_partial_shape().rank().get_length()); - const auto constant = std::dynamic_pointer_cast(m_weights.get_node_shared_ptr()); + const auto constant = ov::as_type_ptr(m_weights.get_node_shared_ptr()); OPENVINO_ASSERT(!!constant, "Dynamic cast returned a nullptr"); const auto reduce_dims = constant->cast_vector(); @@ -1144,7 +1144,7 @@ class ov::pass::mask_propagation::Reshape : public MatcherPass { if (is_type(inp.get_node())) return true; - auto constant = std::dynamic_pointer_cast(m_weights.get_node_shared_ptr()); + auto constant = ov::as_type_ptr(m_weights.get_node_shared_ptr()); if (!constant) { constant = ov::util::get_constant_from_source(m_weights.get_node_shared_ptr()); if (!constant) { diff --git a/src/common/offline_transformations/src/pruning/shrink_weights.cpp b/src/common/offline_transformations/src/pruning/shrink_weights.cpp index a476c56195f952..a3e55f7f19b67e 100644 --- a/src/common/offline_transformations/src/pruning/shrink_weights.cpp +++ b/src/common/offline_transformations/src/pruning/shrink_weights.cpp @@ -28,7 +28,7 @@ static bool not_empty_mask(ov::Mask::Ptr mask) { } static bool is_static_reshape_op(std::shared_ptr node) { - auto reshape_node = std::dynamic_pointer_cast(node); + auto reshape_node = ov::as_type_ptr(node); if (!reshape_node) return false; @@ -224,7 +224,7 @@ bool ov::pass::ShrinkWeights::run_on_model(const std::shared_ptr& f) continue; // TODO: constant can be shared across functions so we need to avoid consumers from other function - auto const_node = std::dynamic_pointer_cast(node); + auto const_node = ov::as_type_ptr(node); if (!const_node) continue; diff --git a/src/common/snippets/src/generator.cpp b/src/common/snippets/src/generator.cpp index fad0086427c93d..c04d1b4b13dd8e 100644 --- a/src/common/snippets/src/generator.cpp +++ b/src/common/snippets/src/generator.cpp @@ -69,14 +69,14 @@ RegType Generator::get_op_out_reg_type(const ov::Output& out) const { if (reg_type != RegType::undefined) return reg_type; const auto op = out.get_node_shared_ptr(); - if (std::dynamic_pointer_cast(op) || - std::dynamic_pointer_cast(op) || + if (ov::as_type_ptr(op) || + ov::as_type_ptr(op) || std::dynamic_pointer_cast(op) || std::dynamic_pointer_cast(op) || std::dynamic_pointer_cast(op) || std::dynamic_pointer_cast(op) || std::dynamic_pointer_cast(op) || - std::dynamic_pointer_cast(op) || + ov::as_type_ptr(op) || std::dynamic_pointer_cast(op) || std::dynamic_pointer_cast(op) #ifdef SNIPPETS_DEBUG_CAPS @@ -91,13 +91,13 @@ RegType Generator::get_op_out_reg_type(const ov::Output& out) const { ov::op::util::is_binary_elementwise_arithmetic(op) || ov::op::util::is_binary_elementwise_comparison(op) || ov::op::util::is_binary_elementwise_logical(op) || - std::dynamic_pointer_cast(op) || - std::dynamic_pointer_cast(op) || - std::dynamic_pointer_cast(op) || - std::dynamic_pointer_cast(op) || + ov::as_type_ptr(op) || + ov::as_type_ptr(op) || + ov::as_type_ptr(op) || + ov::as_type_ptr(op) || std::dynamic_pointer_cast(op) || std::dynamic_pointer_cast(op) || - std::dynamic_pointer_cast(op) || + ov::as_type_ptr(op) || std::dynamic_pointer_cast(op) || std::dynamic_pointer_cast(op) || std::dynamic_pointer_cast(op)) diff --git a/src/common/snippets/src/op/subgraph.cpp b/src/common/snippets/src/op/subgraph.cpp index aff2341cc8bf9d..5cdf1b353a1969 100644 --- a/src/common/snippets/src/op/subgraph.cpp +++ b/src/common/snippets/src/op/subgraph.cpp @@ -290,7 +290,7 @@ auto Subgraph::constant_input_should_be_inside_body(const std::shared_ptr& node) noexcept { - const auto elementwise = std::dynamic_pointer_cast(node); + const auto elementwise = ov::as_type_ptr(node); return (elementwise == nullptr) || (elementwise->get_input_partial_shape(0).size() == elementwise->get_input_partial_shape(1).size()) || diff --git a/src/common/snippets/src/pass/fq_decomposition.cpp b/src/common/snippets/src/pass/fq_decomposition.cpp index fe5e98e8a8a4c9..2ac2cac1fff5d9 100644 --- a/src/common/snippets/src/pass/fq_decomposition.cpp +++ b/src/common/snippets/src/pass/fq_decomposition.cpp @@ -35,7 +35,7 @@ ov::snippets::pass::FakeQuantizeDecomposition::FakeQuantizeDecomposition() { ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) { OV_ITT_SCOPED_TASK(ov::pass::itt::domains::SnippetsTransform, "Snippets::op::FakeQuantizeDecomposition") auto& pattern_to_output = m.get_pattern_value_map(); - const auto fake_quantize_node = std::dynamic_pointer_cast( + const auto fake_quantize_node = ov::as_type_ptr( pattern_to_output.at(fake_quantize).get_node_shared_ptr()); if (!fake_quantize_node || transformation_callback(fake_quantize_node)) { @@ -358,7 +358,7 @@ bool ov::snippets::pass::CommonFakeQuantizeDecomposition::is_supported_fq(const if (!greater_equal->constant_fold(result, greater_equal->input_values())) return false; - const auto res_node = std::dynamic_pointer_cast(result[0].get_node_shared_ptr()); + const auto res_node = ov::as_type_ptr(result[0].get_node_shared_ptr()); const auto comp_result = res_node->cast_vector(); return !std::any_of(comp_result.begin(), comp_result.end(), [](const bool value) { return value; 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 2aa5b8f0efa8c1..466f2de99f77aa 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 @@ -31,7 +31,7 @@ class TRANSFORMATIONS_API DepthToSpaceFusion; * * // This callback enables DepthToSpaceFusion transformation * auto callback = [](const std::shared_ptr & node) -> bool { - * return std::dynamic_pointer_cast(node) != nullptr; + * return ov::as_type_ptr(node) != nullptr; * }; * * auto p = ov::pass::DepthToSpaceFusion(); 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 32a2f7a3ace512..c7172fc87e50ac 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 @@ -80,7 +80,7 @@ ov::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 = ov::as_type_ptr(reduce->input_value(1).get_node_shared_ptr()); if (!axes_node) { return false; } diff --git a/src/common/transformations/include/transformations/op_conversions/convert_reduce_to_reshape.hpp b/src/common/transformations/include/transformations/op_conversions/convert_reduce_to_reshape.hpp index 9eeb3e5c0f8da6..2e640548b36e04 100644 --- a/src/common/transformations/include/transformations/op_conversions/convert_reduce_to_reshape.hpp +++ b/src/common/transformations/include/transformations/op_conversions/convert_reduce_to_reshape.hpp @@ -101,7 +101,7 @@ class ov::pass::ConvertReduceToReshape : public ov::pass::GraphRewrite { template ov::matcher_pass_callback CvtReduceBase::convert_reduce_to_reshape() { return [&](ov::pass::pattern::Matcher& m) { - auto reduce = std::dynamic_pointer_cast(m.get_match_root()); + auto reduce = ov::as_type_ptr(m.get_match_root()); if (!reduce) return false; diff --git a/src/common/transformations/include/transformations/utils/gen_pattern.hpp b/src/common/transformations/include/transformations/utils/gen_pattern.hpp index 215825d2cd13eb..c80f1490bb5607 100644 --- a/src/common/transformations/include/transformations/utils/gen_pattern.hpp +++ b/src/common/transformations/include/transformations/utils/gen_pattern.hpp @@ -1262,7 +1262,7 @@ class PatternValidator { if (rt_info.count("symbolic_const_value")) { // symbolic constant node, a symbol reference is observed auto& symbols = rt_info["symbolic_const_value"].as>(); - auto constop = std::dynamic_pointer_cast(value_node); + auto constop = ov::as_type_ptr(value_node); if (!constop) { _VERBOSE_LOG("symbolic_const_value unexpected OP: ", value_node->get_friendly_name()); return false; @@ -1292,9 +1292,9 @@ class PatternValidator { } continue; } - if (auto pconst_node = std::dynamic_pointer_cast(pnode)) { + if (auto pconst_node = ov::as_type_ptr(pnode)) { // const_node needs to match type/shape/value - auto vconst_node = std::dynamic_pointer_cast(value_node); + auto vconst_node = ov::as_type_ptr(value_node); if (!vconst_node) { _VERBOSE_LOG("expecting Constant op, but got ", value_node); return false; diff --git a/src/common/transformations/include/transformations/utils/print_model.hpp b/src/common/transformations/include/transformations/utils/print_model.hpp index 53fa7de51c5eca..a254cd1c663ea1 100644 --- a/src/common/transformations/include/transformations/utils/print_model.hpp +++ b/src/common/transformations/include/transformations/utils/print_model.hpp @@ -262,7 +262,7 @@ void dump_cpp_style(std::ostream& os, const std::shared_ptr& model) { // collect all scalar & short 1D vectors for literal-style display std::map, std::string> literal_consts; for (auto op : f.get_ordered_ops()) { - if (auto constop = std::dynamic_pointer_cast(op)) { + if (auto constop = ov::as_type_ptr(op)) { // only i32/f32 type const literal can be parsed by C++ compiler if (constop->get_output_element_type(0) != ov::element::i32 && constop->get_output_element_type(0) != ov::element::i64 && @@ -328,7 +328,7 @@ void dump_cpp_style(std::ostream& os, const std::shared_ptr& model) { auto name = opname[op.get()]; os << prefix << " "; - if (auto constop = std::dynamic_pointer_cast(op)) { + if (auto constop = ov::as_type_ptr(op)) { os << "auto " << name << " = makeConst(" << to_code(op->get_output_element_type(0)) << ", " << to_code(op->get_output_shape(0)) << ", " << to_code(constop, true) << ");" << std::endl; } else { @@ -376,7 +376,7 @@ void dump_cpp_style(std::ostream& os, const std::shared_ptr& model) { } // recursively output subgraphs - if (auto msubgraph = std::dynamic_pointer_cast(op)) { + if (auto msubgraph = ov::as_type_ptr(op)) { auto cnt = msubgraph->get_internal_subgraphs_size(); for (size_t i = 0; i < cnt; i++) { os << " MultiSubGraphOp " << tag << msubgraph->get_friendly_name() << "[" << i << "]" << std::endl; diff --git a/src/common/transformations/include/transformations/utils/utils.hpp b/src/common/transformations/include/transformations/utils/utils.hpp index 6bcc50e29b3733..d591e581bca3d1 100644 --- a/src/common/transformations/include/transformations/utils/utils.hpp +++ b/src/common/transformations/include/transformations/utils/utils.hpp @@ -54,7 +54,7 @@ bool has_op_with_type(const std::shared_ptr& function) { inline bool has_decompression_converts(const std::shared_ptr& function) { for (const auto& op : function->get_ops()) { - if (std::dynamic_pointer_cast(op)) { + if (ov::as_type_ptr(op)) { if (ov::is_decompression(op)) return true; } @@ -125,7 +125,7 @@ bool has_constant_value(const std::shared_ptr& node, return false; } - auto constant = std::dynamic_pointer_cast(node); + auto constant = ov::as_type_ptr(node); if (!constant) { return false; } @@ -159,7 +159,7 @@ bool has_constant_value(const std::shared_ptr& node, return false; } - auto constant = std::dynamic_pointer_cast(node); + auto constant = ov::as_type_ptr(node); if (!constant) { return false; } 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 99e5b829b1eb6b..efbaada9655d8b 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 @@ -16,7 +16,7 @@ namespace { bool can_eliminate_broadcast(const ov::Output& eltwise, const ov::Output& eltwise_input, const ov::Output& broadcast) { - auto b = std::dynamic_pointer_cast(eltwise.get_node_shared_ptr()); + auto b = ov::as_type_ptr(eltwise.get_node_shared_ptr()); if (!b || b->get_autob() == ov::op::AutoBroadcastType::NONE) { return false; } 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 5abe0b5b8c87e3..e98a9f4052e86a 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 @@ -130,7 +130,7 @@ class UpdateConvertGather : public pass::MatcherPass { 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()); + auto existing_convert = ov::as_type_ptr(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(); diff --git a/src/common/transformations/src/transformations/common_optimizations/eliminate_duplicate_ti_inputs.cpp b/src/common/transformations/src/transformations/common_optimizations/eliminate_duplicate_ti_inputs.cpp index c28779f4c1e498..ce010f04e15aee 100644 --- a/src/common/transformations/src/transformations/common_optimizations/eliminate_duplicate_ti_inputs.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/eliminate_duplicate_ti_inputs.cpp @@ -31,14 +31,14 @@ ov::pass::EliminateDuplicateTIInputs::EliminateDuplicateTIInputs() { for (auto& key : input_descs) { auto is_equal = [&](const std::shared_ptr& input) -> bool { if (ti->input_value(input->m_input_index) == ti->input_value(key->m_input_index)) { - auto invariant_l = std::dynamic_pointer_cast(input); - auto invariant_r = std::dynamic_pointer_cast(key); + auto invariant_l = ov::as_type_ptr(input); + auto invariant_r = ov::as_type_ptr(key); if (invariant_l && invariant_r) { return true; } - auto slice_l = std::dynamic_pointer_cast(input); - auto slice_r = std::dynamic_pointer_cast(key); + auto slice_l = ov::as_type_ptr(input); + auto slice_r = ov::as_type_ptr(key); if (slice_l && slice_r) { return slice_l->m_axis == slice_r->m_axis && slice_l->m_start == slice_r->m_start && @@ -46,8 +46,8 @@ ov::pass::EliminateDuplicateTIInputs::EliminateDuplicateTIInputs() { slice_l->m_stride == slice_r->m_stride; } - auto merged_l = std::dynamic_pointer_cast(input); - auto merged_r = std::dynamic_pointer_cast(key); + auto merged_l = ov::as_type_ptr(input); + auto merged_r = ov::as_type_ptr(key); if (merged_l && merged_r) { return merged_l->m_body_value_index == merged_r->m_body_value_index; @@ -91,12 +91,12 @@ ov::pass::EliminateDuplicateTIInputs::EliminateDuplicateTIInputs() { for (const auto& remain : should_stay) { auto par = body->get_parameters()[remain->m_body_parameter_index]; auto in = ti->input_value(remain->m_input_index); - if (auto invariant = std::dynamic_pointer_cast(remain)) { + if (auto invariant = ov::as_type_ptr(remain)) { new_ti->set_invariant_input(par, in); - } else if (auto merged = std::dynamic_pointer_cast(remain)) { + } else if (auto merged = ov::as_type_ptr(remain)) { auto results = body->get_results(); new_ti->set_merged_input(par, in, results[merged->m_body_value_index]); - } else if (auto slice = std::dynamic_pointer_cast(remain)) { + } else if (auto slice = ov::as_type_ptr(remain)) { new_ti->set_sliced_input(par, in, slice->m_start, diff --git a/src/common/transformations/src/transformations/common_optimizations/fold_subgraph_empty_inputs.cpp b/src/common/transformations/src/transformations/common_optimizations/fold_subgraph_empty_inputs.cpp index 7052ce5848321f..aa4e7696056e84 100644 --- a/src/common/transformations/src/transformations/common_optimizations/fold_subgraph_empty_inputs.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/fold_subgraph_empty_inputs.cpp @@ -19,7 +19,7 @@ ov::pass::FoldSubgraphEmptyInputs::FoldSubgraphEmptyInputs() { MATCHER_SCOPE(FoldSubgraphEmptyInputs); auto multi_subgraph_op_pattern = pattern::wrap_type(); ov::matcher_pass_callback callback = [=](pattern::Matcher& m) { - auto multi_subgraph_op = std::dynamic_pointer_cast(m.get_match_root()); + auto multi_subgraph_op = ov::as_type_ptr(m.get_match_root()); if (multi_subgraph_op == nullptr) { return false; } diff --git a/src/common/transformations/src/transformations/common_optimizations/glu_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/glu_fusion.cpp index 2b6c2092a054c2..e6a24a7486bc20 100644 --- a/src/common/transformations/src/transformations/common_optimizations/glu_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/glu_fusion.cpp @@ -53,7 +53,7 @@ GLUFusion::GLUFusion() { OPENVINO_ASSERT(pattern_map.count(variadic_split_m)); OPENVINO_ASSERT(pattern_map.count(split_lengths_const_m)); OPENVINO_ASSERT(pattern_map.count(axis_const_m)); - auto mul = std::dynamic_pointer_cast(pattern_map.at(mul_m).get_node_shared_ptr()); + auto mul = ov::as_type_ptr(pattern_map.at(mul_m).get_node_shared_ptr()); if (!mul || transformation_callback(mul)) return false; @@ -63,7 +63,7 @@ GLUFusion::GLUFusion() { ov::op::internal::GLU::GluType glu_type = ov::op::internal::GLU::GluType::Swish; if (isSwiGLU) { - auto swish = std::dynamic_pointer_cast(pattern_map.at(swish_m).get_node_shared_ptr()); + auto swish = ov::as_type_ptr(pattern_map.at(swish_m).get_node_shared_ptr()); glu_type = ov::op::internal::GLU::GluType::Swish; split_to_glu_idx = swish->input_value(0).get_index(); @@ -71,7 +71,7 @@ GLUFusion::GLUFusion() { if (mul->input_value(split_in_idx).get_index() == split_to_glu_idx) return false; } else if (isGeGLU) { - auto gelu = std::dynamic_pointer_cast(pattern_map.at(gelu_m).get_node_shared_ptr()); + auto gelu = ov::as_type_ptr(pattern_map.at(gelu_m).get_node_shared_ptr()); glu_type = (gelu->get_approximation_mode() == ov::op::GeluApproximationMode::ERF) ? ov::op::internal::GLU::GluType::Gelu : ov::op::internal::GLU::GluType::Gelu_Tanh; @@ -84,20 +84,20 @@ GLUFusion::GLUFusion() { OPENVINO_THROW("'glu_type' not initialized"); } - auto variadic_split = std::dynamic_pointer_cast( - pattern_map.at(variadic_split_m).get_node_shared_ptr()); + auto variadic_split = + ov::as_type_ptr(pattern_map.at(variadic_split_m).get_node_shared_ptr()); auto variadic_split_in_ps = variadic_split->get_input_partial_shape(0); auto last_dim = variadic_split_in_ps.rank().get_length() - 1; - auto axis = std::dynamic_pointer_cast(pattern_map.at(axis_const_m).get_node_shared_ptr()); + auto axis = ov::as_type_ptr(pattern_map.at(axis_const_m).get_node_shared_ptr()); bool valid_axis_const_values = ov::op::util::has_constant_value(axis, -1) || ov::op::util::has_constant_value(axis, last_dim); if (!valid_axis_const_values) return false; auto axis_value = axis->cast_vector()[0]; - auto split_lengths = std::dynamic_pointer_cast( - pattern_map.at(split_lengths_const_m).get_node_shared_ptr()); + auto split_lengths = + ov::as_type_ptr(pattern_map.at(split_lengths_const_m).get_node_shared_ptr()); auto split_lengths_value = split_lengths->cast_vector()[0]; // Allow only case that exactly splits in half along the last dimension auto split_length = variadic_split_in_ps[last_dim].get_length() / 2; 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 3883e94b74d33c..1b1e4386c6ed37 100644 --- a/src/common/transformations/src/transformations/common_optimizations/nop_elimination.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/nop_elimination.cpp @@ -463,7 +463,7 @@ pass::EliminateConvert::EliminateConvert() { auto convert_pattern = pattern::wrap_type(); matcher_pass_callback callback = [](pattern::Matcher& m) { - auto convert = dynamic_pointer_cast(m.get_match_root()); + auto convert = ov::as_type_ptr(m.get_match_root()); if (!convert) { return false; } @@ -517,7 +517,7 @@ pass::EliminateSplit::EliminateSplit() { auto convert_pattern = pattern::wrap_type(); matcher_pass_callback callback = [](pattern::Matcher& m) { - auto split = dynamic_pointer_cast(m.get_match_root()); + auto split = ov::as_type_ptr(m.get_match_root()); if (!split || split->get_num_splits() != 1) { return false; } @@ -632,9 +632,9 @@ int64_t make_positive(int64_t value, const Output& node) { }; bool check_squeeze(const shared_ptr& node) { - auto squeeze = dynamic_pointer_cast(node); + auto squeeze = ov::as_type_ptr(node); if (squeeze) { - auto axis = dynamic_pointer_cast(squeeze->input_value(1).get_node_shared_ptr()); + auto axis = ov::as_type_ptr(squeeze->input_value(1).get_node_shared_ptr()); if (axis) { auto axis_val = axis->cast_vector(); if (axis_val.size() == 1 && make_positive(axis_val[0], squeeze->input_value(0)) == 1) { @@ -648,9 +648,9 @@ bool check_squeeze(const shared_ptr& node) { // Checks that Reshape actually equals to Squeeze op // 0, -1 values in the shape pattern are not allowed. bool check_reshape(const shared_ptr& node) { - auto reshape = dynamic_pointer_cast(node); + auto reshape = ov::as_type_ptr(node); if (reshape) { - auto shape_pattern = dynamic_pointer_cast(reshape->input_value(1).get_node_shared_ptr()); + auto shape_pattern = ov::as_type_ptr(reshape->input_value(1).get_node_shared_ptr()); if (shape_pattern) { auto pattern_val = shape_pattern->cast_vector(); bool is_valid_pattern = find(pattern_val.begin(), pattern_val.end(), 0) == pattern_val.end(); @@ -675,7 +675,7 @@ bool check_reshape(const shared_ptr& node) { bool check_axis(const shared_ptr& concat, const shared_ptr& split, bool is_special_case = false) { - auto axis = dynamic_pointer_cast(split->input_value(1).get_node_shared_ptr()); + auto axis = ov::as_type_ptr(split->input_value(1).get_node_shared_ptr()); if (!axis) { return false; } @@ -731,9 +731,9 @@ shared_ptr check_all_inputs(const shared_ptr& concat) { auto seq_node = seq_out.get_node_shared_ptr(); if (!seq_node || seq_out.get_index() != 0 || - !(dynamic_pointer_cast(seq_node) || - dynamic_pointer_cast(seq_node) || - dynamic_pointer_cast(seq_node))) { + !(ov::as_type_ptr(seq_node) || + ov::as_type_ptr(seq_node) || + ov::as_type_ptr(seq_node))) { return {}; } @@ -787,7 +787,7 @@ ov::pass::EliminateSplitConcat::EliminateSplitConcat() { auto pattern_concat = pattern::wrap_type(); matcher_pass_callback callback = [=](pattern::Matcher& m) { const auto& pattern_map = m.get_pattern_map(); - const auto concat = dynamic_pointer_cast(pattern_map.at(pattern_concat)); + const auto concat = ov::as_type_ptr(pattern_map.at(pattern_concat)); if (!concat) { return false; } @@ -814,7 +814,7 @@ pass::EliminateTranspose::EliminateTranspose() { matcher_pass_callback callback = [=](pattern::Matcher& m) { const auto& pattern_map = m.get_pattern_map(); - auto order_const = dynamic_pointer_cast(pattern_map.at(order)); + auto order_const = ov::as_type_ptr(pattern_map.at(order)); if (!order_const) { return false; } 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 5d6edf9aee6d0c..9499ed85973b1e 100644 --- a/src/common/transformations/src/transformations/common_optimizations/pad_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/pad_fusion.cpp @@ -105,7 +105,7 @@ pass::PadFusionAvgPool::PadFusionAvgPool() { matcher_pass_callback callback = [=](pattern::Matcher& m) { auto pattern_map = m.get_pattern_value_map(); auto data = pattern_map[data_pattern]; - auto pad = std::dynamic_pointer_cast(pattern_map[pad_node_pattern].get_node_shared_ptr()); + auto pad = ov::as_type_ptr(pattern_map[pad_node_pattern].get_node_shared_ptr()); auto pad_value = pattern_map[pad_value_pattern].get_node_shared_ptr(); auto pads_begin = ov::as_type_ptr(pattern_map[pads_begin_pattern].get_node_shared_ptr()); auto pads_end = ov::as_type_ptr(pattern_map[pads_end_pattern].get_node_shared_ptr()); @@ -205,7 +205,7 @@ pass::PadFusionConvolution::PadFusionConvolution() { auto pattern_map = m.get_pattern_value_map(); auto data = pattern_map[data_pattern]; auto filter = pattern_map[filter_pattern]; - auto pad = std::dynamic_pointer_cast(pattern_map[pad_node_pattern].get_node_shared_ptr()); + auto pad = ov::as_type_ptr(pattern_map[pad_node_pattern].get_node_shared_ptr()); auto pad_value = pattern_map[pad_value_pattern].get_node_shared_ptr(); auto pads_begin = ov::as_type_ptr(pattern_map[pads_begin_pattern].get_node_shared_ptr()); auto pads_end = ov::as_type_ptr(pattern_map[pads_end_pattern].get_node_shared_ptr()); @@ -250,7 +250,7 @@ pass::PadFusionConvolutionBackpropData::PadFusionConvolutionBackpropData() { auto pattern_map = m.get_pattern_value_map(); auto data = pattern_map[data_pattern]; auto filter = pattern_map[filter_pattern]; - auto pad = std::dynamic_pointer_cast(pattern_map[pad_node_pattern].get_node_shared_ptr()); + auto pad = ov::as_type_ptr(pattern_map[pad_node_pattern].get_node_shared_ptr()); auto pad_value = pattern_map[pad_value_pattern].get_node_shared_ptr(); auto pads_begin = ov::as_type_ptr(pattern_map[pads_begin_pattern].get_node_shared_ptr()); auto pads_end = ov::as_type_ptr(pattern_map[pads_end_pattern].get_node_shared_ptr()); @@ -306,7 +306,7 @@ pass::PadFusionGroupConvolution::PadFusionGroupConvolution() { auto pattern_map = m.get_pattern_value_map(); auto data = pattern_map[data_pattern]; auto filter = pattern_map[filter_pattern]; - auto pad = std::dynamic_pointer_cast(pattern_map[pad_node_pattern].get_node_shared_ptr()); + auto pad = ov::as_type_ptr(pattern_map[pad_node_pattern].get_node_shared_ptr()); auto pad_value = pattern_map[pad_value_pattern].get_node_shared_ptr(); auto pads_begin = ov::as_type_ptr(pattern_map[pads_begin_pattern].get_node_shared_ptr()); auto pads_end = ov::as_type_ptr(pattern_map[pads_end_pattern].get_node_shared_ptr()); @@ -352,7 +352,7 @@ pass::PadFusionGroupConvolutionBackpropData::PadFusionGroupConvolutionBackpropDa auto pattern_map = m.get_pattern_value_map(); auto data = pattern_map[data_pattern]; auto filter = pattern_map[filter_pattern]; - auto pad = std::dynamic_pointer_cast(pattern_map[pad_node_pattern].get_node_shared_ptr()); + auto pad = ov::as_type_ptr(pattern_map[pad_node_pattern].get_node_shared_ptr()); auto pad_value = pattern_map[pad_value_pattern].get_node_shared_ptr(); auto pads_begin = ov::as_type_ptr(pattern_map[pads_begin_pattern].get_node_shared_ptr()); auto pads_end = ov::as_type_ptr(pattern_map[pads_end_pattern].get_node_shared_ptr()); diff --git a/src/common/transformations/src/transformations/common_optimizations/prelu_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/prelu_fusion.cpp index c4be0311ca54c4..1bb06fd46536da 100644 --- a/src/common/transformations/src/transformations/common_optimizations/prelu_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/prelu_fusion.cpp @@ -171,7 +171,7 @@ ov::pass::PReluFusionAbsSubMulMulAdd::PReluFusionAbsSubMulMulAdd() { const auto equals_half = [](const Output& node) { float v; - const auto constant = dynamic_pointer_cast(node.get_node_shared_ptr()); + const auto constant = ov::as_type_ptr(node.get_node_shared_ptr()); return constant && op::util::get_single_value(constant, v) && v == 0.5f; }; diff --git a/src/common/transformations/src/transformations/common_optimizations/pull_through_reduce.cpp b/src/common/transformations/src/transformations/common_optimizations/pull_through_reduce.cpp index e25ae9989d97b5..a3e3d22112e765 100644 --- a/src/common/transformations/src/transformations/common_optimizations/pull_through_reduce.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/pull_through_reduce.cpp @@ -120,8 +120,7 @@ ov::pass::PullUnsqueezeThroughReduce::PullUnsqueezeThroughReduce() { matcher_pass_callback callback = [=](pattern::Matcher& m) { auto& pattern_map = m.get_pattern_value_map(); const auto input_node = pattern_map.at(input); - const auto reduce_node = - std::dynamic_pointer_cast(pattern_map.at(reduce).get_node_shared_ptr()); + const auto reduce_node = ov::as_type_ptr(pattern_map.at(reduce).get_node_shared_ptr()); const auto unsqueeze_node = pattern_map.at(unsqueeze).get_node_shared_ptr(); auto unsqueeze_axes_input = ov::as_type_ptr(pattern_map.at(unsqueeze_axes).get_node_shared_ptr()); @@ -193,8 +192,7 @@ ov::pass::PullReshapeThroughReduce::PullReshapeThroughReduce() { matcher_pass_callback callback = [=](pattern::Matcher& m) { auto& pattern_map = m.get_pattern_value_map(); const auto input_node = pattern_map.at(input); - const auto reduce_node = - std::dynamic_pointer_cast(pattern_map.at(reduce).get_node_shared_ptr()); + const auto reduce_node = ov::as_type_ptr(pattern_map.at(reduce).get_node_shared_ptr()); if (!reduce_node) { return false; } diff --git a/src/common/transformations/src/transformations/common_optimizations/push_constant_to_subgraph.cpp b/src/common/transformations/src/transformations/common_optimizations/push_constant_to_subgraph.cpp index fe9c359be00830..6281af16eebeed 100644 --- a/src/common/transformations/src/transformations/common_optimizations/push_constant_to_subgraph.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/push_constant_to_subgraph.cpp @@ -15,7 +15,7 @@ static std::shared_ptr try_constantfold_input( const std::shared_ptr& op, const MultiSubGraphOp::InputDescription::Ptr& input_desc, std::map, std::shared_ptr>& cache) { - if (!std::dynamic_pointer_cast(input_desc)) { + if (!ov::as_type_ptr(input_desc)) { return nullptr; } const auto outer_input = op->input_value(input_desc->m_input_index); diff --git a/src/common/transformations/src/transformations/common_optimizations/reduce_reshape_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/reduce_reshape_fusion.cpp index b2f8d98e715a30..bdcc8a0de3d4e9 100644 --- a/src/common/transformations/src/transformations/common_optimizations/reduce_reshape_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/reduce_reshape_fusion.cpp @@ -31,8 +31,7 @@ ov::pass::ReduceReshapeFusion::ReduceReshapeFusion() { matcher_pass_callback callback = [=](pattern::Matcher& m) { auto& pattern_map = m.get_pattern_value_map(); auto reshape_node = pattern_map.at(reshape).get_node_shared_ptr(); - const auto reduce_node = - std::dynamic_pointer_cast(pattern_map.at(reduce).get_node_shared_ptr()); + const auto reduce_node = ov::as_type_ptr(pattern_map.at(reduce).get_node_shared_ptr()); if (!reduce_node) { return false; } @@ -57,11 +56,9 @@ ov::pass::ReduceReshapeFusion::ReduceReshapeFusion() { return false; } - if (auto arithmetic_reduce_node = - std::dynamic_pointer_cast(reduce_node)) { + if (auto arithmetic_reduce_node = ov::as_type_ptr(reduce_node)) { arithmetic_reduce_node->set_keep_dims(true); - } else if (auto logical_reduce_node = - std::dynamic_pointer_cast(reduce_node)) { + } else if (auto logical_reduce_node = ov::as_type_ptr(reduce_node)) { logical_reduce_node->set_keep_dims(true); } reduce_node->validate_and_infer_types(); 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 fed6eaf9710420..00b6fafa65e0be 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 @@ -41,7 +41,7 @@ bool ov::pass::RemoveMultiSubGraphOpDanglingParamsResults::run_on_model(const st auto ops = m->get_ordered_ops(); // Going in reverse order for (auto it = ops.rbegin(); it != ops.rend(); ++it) { - auto multi_subgraph_op = std::dynamic_pointer_cast(*it); + auto multi_subgraph_op = ov::as_type_ptr(*it); if (!multi_subgraph_op) continue; auto if_op = ov::as_type_ptr(multi_subgraph_op); diff --git a/src/common/transformations/src/transformations/common_optimizations/reverse_shape_and_type_infer.cpp b/src/common/transformations/src/transformations/common_optimizations/reverse_shape_and_type_infer.cpp index 9fbaed822cdfba..eb24c252b27b2e 100644 --- a/src/common/transformations/src/transformations/common_optimizations/reverse_shape_and_type_infer.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/reverse_shape_and_type_infer.cpp @@ -154,7 +154,7 @@ bool ov::pass::ReverseShapeAndTypeInfer::run_on_model(const std::shared_ptr(op)) { is_changed |= inherit_output_rank(op, {0, 1, 2, 3}); is_changed |= inherit_output_type(op, {0, 1, 2, 3}); - } else if (std::dynamic_pointer_cast(op)) { + } else if (ov::as_type_ptr(op)) { // Shape of pads_begin and pads_end must match rank of input if (op->get_input_partial_shape(0).rank().is_dynamic()) { auto pads_begin_shape = op->get_input_partial_shape(1); @@ -168,10 +168,10 @@ bool ov::pass::ReverseShapeAndTypeInfer::run_on_model(const std::shared_ptr(op)) { + } else if (ov::as_type_ptr(op)) { is_changed |= inherit_output_shape(op, {0}); is_changed |= inherit_output_type(op, {0}); - } else if (const auto& eltwise = std::dynamic_pointer_cast(op)) { + } else if (const auto& eltwise = ov::as_type_ptr(op)) { if (output_shape.rank().is_static()) { auto in0_rank = op->get_input_partial_shape(0).rank(); auto in1_rank = op->get_input_partial_shape(1).rank(); 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 1e6d7caec39ac0..a0bfd3133864d3 100644 --- a/src/common/transformations/src/transformations/common_optimizations/ric_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/ric_fusion.cpp @@ -823,7 +823,7 @@ class Constant : public ov::pass::ModelPass { bool run_on_model(const std::shared_ptr& model) override { RUN_ON_FUNCTION_SCOPE(Constant); for (const auto& node : model->get_ordered_ops()) { - if ((std::dynamic_pointer_cast(node) || + if ((ov::as_type_ptr(node) || ov::as_type_ptr(node) || ov::as_type_ptr(node)) && node->get_output_partial_shape(0).rank().is_static()) { continue; diff --git a/src/common/transformations/src/transformations/common_optimizations/sdpa_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/sdpa_fusion.cpp index fc581580f70001..3ebecd0b343d32 100644 --- a/src/common/transformations/src/transformations/common_optimizations/sdpa_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/sdpa_fusion.cpp @@ -31,8 +31,7 @@ SDPAFusion::SDPAFusion() { auto mask = makePattern(); auto k_transpose_order = pattern::wrap_type([](const Output& node) { - auto axis_order = - std::dynamic_pointer_cast(node.get_node_shared_ptr())->cast_vector(); + auto axis_order = ov::as_type_ptr(node.get_node_shared_ptr())->cast_vector(); return axis_order == std::vector{0, 1, 3, 2}; }); diff --git a/src/common/transformations/src/transformations/common_optimizations/sequence_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/sequence_fusion.cpp index d3527c5f4a00bb..553d3c192f95b3 100644 --- a/src/common/transformations/src/transformations/common_optimizations/sequence_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/sequence_fusion.cpp @@ -33,8 +33,8 @@ using namespace ov::op::util; namespace { bool is_equal_consts(const shared_ptr& l, const shared_ptr& r) { - auto l_const = dynamic_pointer_cast(l); - auto r_const = dynamic_pointer_cast(r); + auto l_const = ov::as_type_ptr(l); + auto r_const = ov::as_type_ptr(r); if (l_const && r_const) { auto l_ptr = l_const->get_data_ptr(); auto r_ptr = r_const->get_data_ptr(); @@ -52,14 +52,14 @@ bool check_WRB(const shared_ptr& cell_1, const shared_ptr(cell_1); - auto lstm_cell_v4_2 = dynamic_pointer_cast(cell_2); + auto lstm_cell_v4_1 = ov::as_type_ptr(cell_1); + auto lstm_cell_v4_2 = ov::as_type_ptr(cell_2); // 2nd input is Cell State if (lstm_cell_v4_1 && lstm_cell_v4_2) { increase_indexes(); } - auto lstm_cell_v0_1 = dynamic_pointer_cast(cell_1); - auto lstm_cell_v0_2 = dynamic_pointer_cast(cell_2); + auto lstm_cell_v0_1 = ov::as_type_ptr(cell_1); + auto lstm_cell_v0_2 = ov::as_type_ptr(cell_2); if (lstm_cell_v0_1 && lstm_cell_v0_2) { if (lstm_cell_v0_1->get_weights_format() != lstm_cell_v0_2->get_weights_format() || lstm_cell_v0_1->get_input_forget() != lstm_cell_v0_2->get_input_forget()) { @@ -81,8 +81,8 @@ bool check_WRB(const shared_ptr& cell_1, const shared_ptr& cell_1, const shared_ptr& cell_2) { bool is_equal = true; - auto gru_cell_1 = dynamic_pointer_cast(cell_1); - auto gru_cell_2 = dynamic_pointer_cast(cell_2); + auto gru_cell_1 = ov::as_type_ptr(cell_1); + auto gru_cell_2 = ov::as_type_ptr(cell_2); if (gru_cell_1 && gru_cell_2) { is_equal = gru_cell_1->get_linear_before_reset() == gru_cell_2->get_linear_before_reset(); } @@ -98,8 +98,7 @@ bool is_equal_cells(const shared_ptr& cell_1, const shared_ptr& prev_cell, const shared_ptr& current_cell) { // check intermediate C outputs in case of LSTMCell // LSTMCell - C -> LSTMCell - if ((dynamic_pointer_cast(prev_cell) || - dynamic_pointer_cast(prev_cell))) { + if ((ov::as_type_ptr(prev_cell) || ov::as_type_ptr(prev_cell))) { const auto& target_inputs = prev_cell->get_output_target_inputs(1); bool valid = target_inputs.empty() || (target_inputs.size() == 1 && @@ -127,7 +126,7 @@ shared_ptr find_cell_chain(ov::pass::NodeRegistry& cp_from, cp_from.add(current); // check the source node of HiddenState input auto prev = current->input_value(1).get_node_shared_ptr(); - auto prev_cell = dynamic_pointer_cast(prev); + auto prev_cell = ov::as_type_ptr(prev); auto in_X = current->input(0); x_to_concat.push_back(cp_to.make(in_X.get_source_output(), axis_1)); @@ -162,8 +161,7 @@ bool create_sequence(ov::pass::NodeRegistry& cp_to, int64_t idx_W = 2, idx_R = 3, idx_B = 4; // 2nd input is Cell State bool is_lstm = false; - if (dynamic_pointer_cast(last_cell) || - dynamic_pointer_cast(last_cell)) { + if (ov::as_type_ptr(last_cell) || ov::as_type_ptr(last_cell)) { is_lstm = true; idx_B++; idx_R++; @@ -184,7 +182,7 @@ bool create_sequence(ov::pass::NodeRegistry& cp_to, cp_to.add(ov::op::util::make_try_fold(seq_lengths_scalar, batch_dimension)); shared_ptr sequence; ov::OutputVector outputs(1); - if (dynamic_pointer_cast(first_cell)) { + if (ov::as_type_ptr(first_cell)) { const auto Ct_in = cp_to.make(first_cell->input_value(2), axis_1); sequence = cp_to.make(X_in, Ht_in, @@ -201,7 +199,7 @@ bool create_sequence(ov::pass::NodeRegistry& cp_to, first_cell->get_clip()); outputs.resize(2); outputs[1] = cp_to.make(sequence->output(2), axis_1); - } else if (auto lstm_cell_v0 = dynamic_pointer_cast(first_cell)) { + } else if (auto lstm_cell_v0 = ov::as_type_ptr(first_cell)) { // input_forget modification is not supported if (lstm_cell_v0->get_input_forget()) { return false; @@ -229,7 +227,7 @@ bool create_sequence(ov::pass::NodeRegistry& cp_to, first_cell->get_clip()); outputs.resize(2); outputs[1] = cp_to.make(sequence->output(2), axis_1); - } else if (auto gru_cell = dynamic_pointer_cast(first_cell)) { + } else if (auto gru_cell = ov::as_type_ptr(first_cell)) { sequence = cp_to.make(X_in, Ht_in, sequence_lengths_in, @@ -243,7 +241,7 @@ bool create_sequence(ov::pass::NodeRegistry& cp_to, first_cell->get_activations_beta(), first_cell->get_clip(), gru_cell->get_linear_before_reset()); - } else if (dynamic_pointer_cast(first_cell)) { + } else if (ov::as_type_ptr(first_cell)) { sequence = cp_to.make(X_in, Ht_in, sequence_lengths_in, @@ -307,7 +305,7 @@ ov::pass::SequenceFusion::SequenceFusion() { NodeRegistry copy_from; NodeRegistry copy_to; auto cell = m.get_match_root(); - shared_ptr current_cell = dynamic_pointer_cast(cell); + shared_ptr current_cell = ov::as_type_ptr(cell); if (!current_cell) { return false; } @@ -315,7 +313,7 @@ ov::pass::SequenceFusion::SequenceFusion() { // GRUCell -> GRUCell (the last cell) -> OtherNode // GRUCell (hidden_size = 128) -> GRUCell (hs = 128, the last) -> GRUCell (hs = 64) for (const auto& target : cell->get_output_target_inputs(0)) { - auto cell_1 = dynamic_pointer_cast(target.get_node()->shared_from_this()); + auto cell_1 = ov::as_type_ptr(target.get_node()->shared_from_this()); if (cell_1 && is_equal_cells(cell_1, current_cell)) { return false; } diff --git a/src/common/transformations/src/transformations/common_optimizations/shared_ops_optimization.cpp b/src/common/transformations/src/transformations/common_optimizations/shared_ops_optimization.cpp index 188d0b07684098..a64f5739244520 100644 --- a/src/common/transformations/src/transformations/common_optimizations/shared_ops_optimization.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/shared_ops_optimization.cpp @@ -109,7 +109,7 @@ bool shared_node_optimization(const shared_ptr& model) { index_map[order[i]] = i; for (const auto& op : order) { // Recursively apply transformation for sub-graph based operations - if (auto multi_subgraph_op = dynamic_pointer_cast(op)) { + if (auto multi_subgraph_op = ov::as_type_ptr(op)) { for (const auto& sub_graph : multi_subgraph_op->get_functions()) { if (sub_graph) rewritten = shared_node_optimization(sub_graph) || rewritten; @@ -168,7 +168,7 @@ bool shape_of_upgrade(const shared_ptr& model) { bool rewritten = false; for (const auto& op : model->get_ordered_ops()) { // Recursively apply transformation for sub-graph based operations - if (auto multi_subgraph_op = dynamic_pointer_cast(op)) { + if (auto multi_subgraph_op = ov::as_type_ptr(op)) { for (const auto& sub_graph : multi_subgraph_op->get_functions()) { if (sub_graph) rewritten = shape_of_upgrade(sub_graph) || rewritten; 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 78913756c16065..54f1d32e49cfb0 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 @@ -93,7 +93,7 @@ ov::pass::SpaceToBatchFusion::SpaceToBatchFusion() { if (!check_input_output_shape(reshape_or_trans_after)) return false; - auto pad = std::dynamic_pointer_cast(pattern_map.at(pad_pattern).get_node_shared_ptr()); + auto pad = ov::as_type_ptr(pattern_map.at(pad_pattern).get_node_shared_ptr()); if (!pad || pad->get_pad_mode() != op::PadMode::CONSTANT) return false; auto pad_value_const = ov::as_type_ptr(pattern_map.at(pad_value).get_node_shared_ptr()); 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 274535d55ea4f2..19cfbf489faa7b 100644 --- a/src/common/transformations/src/transformations/common_optimizations/transpose_sinking.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/transpose_sinking.cpp @@ -164,8 +164,8 @@ ov::pass::TransposeReduction::TransposeReduction() { 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(); - auto arithmetic_reduce = std::dynamic_pointer_cast(reduction); - auto logical_reduce = std::dynamic_pointer_cast(reduction); + auto arithmetic_reduce = ov::as_type_ptr(reduction); + auto logical_reduce = ov::as_type_ptr(reduction); auto squeeze = ov::as_type_ptr(reduction); if (!transpose || !(arithmetic_reduce || logical_reduce || squeeze)) return false; 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 14d28a3a3fcfa3..e212bcbeca2e16 100644 --- a/src/common/transformations/src/transformations/control_flow/unroll_if.cpp +++ b/src/common/transformations/src/transformations/control_flow/unroll_if.cpp @@ -20,7 +20,7 @@ bool ov::pass::UnrollIf::run_on_model(const std::shared_ptr& f) { RUN_ON_FUNCTION_SCOPE(UnrollIf); bool is_applicable = false; for (const auto& op : f->get_ordered_ops()) { - auto multisubgraph_op = std::dynamic_pointer_cast(op); + auto multisubgraph_op = ov::as_type_ptr(op); if (multisubgraph_op) { for (size_t i = 0; i < multisubgraph_op->get_internal_subgraphs_size(); ++i) { run_on_model(multisubgraph_op->get_function(static_cast(i))); 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 dde1ab35898b67..e11a45c963772f 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 @@ -25,7 +25,7 @@ bool ov::pass::UnrollTensorIterator::run_on_model(const std::shared_ptrget_ops()) { ov::op::util::process_subgraph(*this, op); - auto sub_graph_op = std::dynamic_pointer_cast(op); + auto sub_graph_op = ov::as_type_ptr(op); if (!sub_graph_op || transformation_callback(sub_graph_op)) { continue; } @@ -52,8 +52,7 @@ bool ov::pass::UnrollTensorIterator::run_on_model(const std::shared_ptrget_input_descriptions()) { - if (const auto& input_desc = - std::dynamic_pointer_cast(desc)) { + if (const auto& input_desc = ov::as_type_ptr(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. @@ -81,7 +80,7 @@ bool ov::pass::UnrollTensorIterator::run_on_model(const std::shared_ptr(desc)) { + ov::as_type_ptr(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]; @@ -98,7 +97,7 @@ bool ov::pass::UnrollTensorIterator::run_on_model(const std::shared_ptr(desc)) { + ov::as_type_ptr(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++) { @@ -155,7 +154,7 @@ bool ov::pass::UnrollTensorIterator::run_on_model(const std::shared_ptr(desc)) { + ov::as_type_ptr(desc)) { // Connect outputs of the bodies to the corresponding TI outputs auto iter = output_desc->m_iteration; iter = iter >= 0 ? iter : num_iter - 1; diff --git a/src/common/transformations/src/transformations/convert_precision.cpp b/src/common/transformations/src/transformations/convert_precision.cpp index bcf44c74d29f04..4562c2e15620a2 100644 --- a/src/common/transformations/src/transformations/convert_precision.cpp +++ b/src/common/transformations/src/transformations/convert_precision.cpp @@ -274,7 +274,7 @@ bool convert_function_precision(ov::pass::PassBase& pass, if (skip_precision_sensitive && fp16_compression_is_disabled(node) && has_fp16_compression) continue; // Recursively apply transformation for sub-graph based operations - if (auto sub_graph_node = std::dynamic_pointer_cast(node)) { + if (auto sub_graph_node = ov::as_type_ptr(node)) { size_t sub_graphs_num = sub_graph_node->get_internal_subgraphs_size(); for (size_t sub_graph_ind = 0; sub_graph_ind < sub_graphs_num; ++sub_graph_ind) { is_changed = convert_function_precision(pass, @@ -400,7 +400,7 @@ precisions_set_t find_all_used_precisions(const std::shared_ptr& fn) for (const auto& output : node->outputs()) { used_precisions.emplace(output.get_element_type()); } - if (auto sub_graph_node = std::dynamic_pointer_cast(node)) { + if (auto sub_graph_node = ov::as_type_ptr(node)) { size_t sub_graphs_num = sub_graph_node->get_internal_subgraphs_size(); for (size_t sub_graph_ind = 0; sub_graph_ind < sub_graphs_num; ++sub_graph_ind) { auto sub_graph_precisions = @@ -1050,7 +1050,7 @@ bool extend_select_type(const std::shared_ptr& node, const precisions_ } bool extend_reverse_type(const std::shared_ptr& node, const precisions_map& precisions) { - if (const auto casted = std::dynamic_pointer_cast(node)) { + if (const auto casted = ov::as_type_ptr(node)) { if (casted->get_mode() == ov::op::v1::Reverse::Mode::MASK) { auto relaxed_op = std::make_shared>( *casted, diff --git a/src/common/transformations/src/transformations/flush_fp32_subnormals_to_zero.cpp b/src/common/transformations/src/transformations/flush_fp32_subnormals_to_zero.cpp index f9176e4f9a86da..b05f6f9189a5be 100644 --- a/src/common/transformations/src/transformations/flush_fp32_subnormals_to_zero.cpp +++ b/src/common/transformations/src/transformations/flush_fp32_subnormals_to_zero.cpp @@ -22,7 +22,7 @@ ov::pass::FlushFP32SubnormalsToZero::FlushFP32SubnormalsToZero() { auto node_pattern = pattern::wrap_type(); matcher_pass_callback callback = [=](pattern::Matcher& m) { - auto node = dynamic_pointer_cast(m.get_match_root()); + auto node = ov::as_type_ptr(m.get_match_root()); if (!node) return false; 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 5bb57bd3a2f2c4..2af54faef28b65 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 @@ -44,14 +44,14 @@ ov::pass::BatchNormDecomposition::BatchNormDecomposition() { auto m_bn = m.get_match_root(); Output m_input, m_gamma, m_beta, m_mean, m_var; double eps; - if (auto m_bn_v1 = dynamic_pointer_cast(m_bn)) { + if (auto m_bn_v1 = ov::as_type_ptr(m_bn)) { m_gamma = m_bn_v1->input_value(0); m_beta = m_bn_v1->input_value(1); m_input = m_bn_v1->input_value(2); m_mean = m_bn_v1->input_value(3); m_var = m_bn_v1->input_value(4); eps = m_bn_v1->get_eps_value(); - } else if (auto m_bn_v5 = dynamic_pointer_cast(m_bn)) { + } else if (auto m_bn_v5 = ov::as_type_ptr(m_bn)) { m_input = m_bn_v5->input_value(0); m_gamma = m_bn_v5->input_value(1); m_beta = m_bn_v5->input_value(2); 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 7fd664331dab55..0f01d3af203227 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 @@ -33,7 +33,7 @@ void ov::pass::ConvertBatchToSpace::convert_batch_to_space() { MATCHER_SCOPE(ConvertBatchToSpace_convert_batch_to_space); const auto batch_to_space = pattern::wrap_type(); matcher_pass_callback callback = [this](pattern::Matcher& m) { - const auto batch_to_space = dynamic_pointer_cast(m.get_match_root()); + const auto batch_to_space = ov::as_type_ptr(m.get_match_root()); if (!batch_to_space || transformation_callback(batch_to_space)) { return false; } @@ -120,7 +120,7 @@ void ov::pass::ConvertBatchToSpace::convert_batch_to_space_by_elements() { MATCHER_SCOPE(ConvertBatchToSpace_convert_batch_to_space_by_elements); const auto batch_to_space = pattern::wrap_type(); matcher_pass_callback callback = [this](pattern::Matcher& m) { - const auto batch_to_space = dynamic_pointer_cast(m.get_match_root()); + const auto batch_to_space = ov::as_type_ptr(m.get_match_root()); if (!batch_to_space || transformation_callback(batch_to_space)) { return false; } diff --git a/src/common/transformations/src/transformations/op_conversions/convert_fc_to_compressed.cpp b/src/common/transformations/src/transformations/op_conversions/convert_fc_to_compressed.cpp index 87c3b669d98c6d..45611b4c52cdd0 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_fc_to_compressed.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_fc_to_compressed.cpp @@ -93,7 +93,7 @@ ov::pass::ConvertFullyConnectedToFullyConnectedCompressed::ConvertFullyConnected return false; auto reshape_const_to_2d = [has_transpose, grouped](std::shared_ptr node) { - auto constant = std::dynamic_pointer_cast(node); + auto constant = ov::as_type_ptr(node); OPENVINO_ASSERT(constant != nullptr); ov::Shape current_shape = constant->get_shape(); if (current_shape.size() <= 2) @@ -109,7 +109,7 @@ ov::pass::ConvertFullyConnectedToFullyConnectedCompressed::ConvertFullyConnected }; auto convert_u4const_to_u8 = [convert_u4zp_to_u8](std::shared_ptr node) -> std::shared_ptr { - auto constant = std::dynamic_pointer_cast(node); + auto constant = ov::as_type_ptr(node); if (constant->get_element_type() != ov::element::u4 || !convert_u4zp_to_u8) return std::dynamic_pointer_cast(constant); return std::make_shared(node, ov::element::u8); 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 8938333d69be73..0329cd7ea6b258 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 @@ -21,7 +21,7 @@ pass::ConvertMulticlassNmsToMulticlassNmsIE::ConvertMulticlassNmsToMulticlassNms auto nms = pattern::wrap_type(); matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) { - auto nms = std::dynamic_pointer_cast(m.get_match_root()); + auto nms = ov::as_type_ptr(m.get_match_root()); if (!nms || transformation_callback(nms)) { return false; } 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 4c86bbf11543d3..af373b90237e66 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 @@ -20,7 +20,7 @@ ov::pass::ConvertPadToGroupConvolution::ConvertPadToGroupConvolution() { auto neg = ov::pass::pattern::wrap_type(pattern::has_static_dim(1)); matcher_pass_callback callback = [](pattern::Matcher& m) { - auto pad = std::dynamic_pointer_cast(m.get_match_root()); + auto pad = ov::as_type_ptr(m.get_match_root()); if (!pad) { return false; } 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 ee35c20611049b..1bca57b6c8cd05 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 @@ -31,7 +31,7 @@ void ov::pass::ConvertSpaceToBatch::convert_space_to_batch() { MATCHER_SCOPE(ConvertSpaceToBatch_convert_space_to_batch); const auto space_to_batch = pattern::wrap_type(); matcher_pass_callback callback = [this](pattern::Matcher& m) { - const auto space_to_batch = dynamic_pointer_cast(m.get_match_root()); + const auto space_to_batch = ov::as_type_ptr(m.get_match_root()); if (!space_to_batch || transformation_callback(space_to_batch)) { return false; } @@ -128,7 +128,7 @@ void ov::pass::ConvertSpaceToBatch::convert_space_to_batch_by_elements() { MATCHER_SCOPE(ConvertSpaceToBatch_convert_space_to_batch_by_elements); const auto space_to_batch = pattern::wrap_type(); matcher_pass_callback callback = [this](pattern::Matcher& m) { - const auto space_to_batch = dynamic_pointer_cast(m.get_match_root()); + const auto space_to_batch = ov::as_type_ptr(m.get_match_root()); if (!space_to_batch || transformation_callback(space_to_batch)) { return false; } 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 119816266ffdc4..cb0c7cd5ee966f 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 @@ -70,7 +70,7 @@ bool convertTensorIteratorToSequence(const std::shared_ptrget_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 = ov::as_type_ptr(input_desc); if (!slice_input) return false; @@ -568,7 +568,7 @@ ov::pass::ConvertTensorIteratorToLSTMSequence::ConvertTensorIteratorToLSTMSequen const auto& pattern_map = matcher.get_pattern_value_map(); std::shared_ptr found_cell = pattern_map.at(cell).get_node_shared_ptr(); - const auto lstm_cell = std::dynamic_pointer_cast(found_cell); + const auto lstm_cell = ov::as_type_ptr(found_cell); if (lstm_cell == nullptr) return false; @@ -859,7 +859,7 @@ ov::pass::ConvertLoopWithScatterUpdateToLSTMSequence::ConvertLoopWithScatterUpda if (output_descs.size() != 1) return false; const auto body_output_desc = - std::dynamic_pointer_cast(output_descs[0]); + ov::as_type_ptr(output_descs[0]); if (!body_output_desc || body_output_desc->m_iteration != -1) return false; @@ -932,7 +932,7 @@ ov::pass::ConvertLoopWithScatterUpdateToLSTMSequence::ConvertLoopWithScatterUpda const auto& input_descs = loop->get_input_descriptions(); for (const auto& desc : input_descs) { if (body_parameters[desc->m_body_parameter_index] == X_body) { - if (!std::dynamic_pointer_cast(desc)) { + if (!ov::as_type_ptr(desc)) { return false; } if (loop->input_value(desc->m_input_index) != pattern_map.at(scatter_label)) { @@ -940,7 +940,7 @@ ov::pass::ConvertLoopWithScatterUpdateToLSTMSequence::ConvertLoopWithScatterUpda } } if (body_parameters[desc->m_body_parameter_index] == H_body) { - auto merged_desc = std::dynamic_pointer_cast(desc); + auto merged_desc = ov::as_type_ptr(desc); if (!merged_desc) { return false; } @@ -951,7 +951,7 @@ ov::pass::ConvertLoopWithScatterUpdateToLSTMSequence::ConvertLoopWithScatterUpda } } if (body_parameters[desc->m_body_parameter_index] == C_body) { - auto merged_desc = std::dynamic_pointer_cast(desc); + auto merged_desc = ov::as_type_ptr(desc); if (!merged_desc) { return false; } @@ -962,13 +962,13 @@ ov::pass::ConvertLoopWithScatterUpdateToLSTMSequence::ConvertLoopWithScatterUpda } } if (body_parameters[desc->m_body_parameter_index] == sequence_index) { - auto merged_desc = std::dynamic_pointer_cast(desc); + auto merged_desc = ov::as_type_ptr(desc); if (!merged_desc) { return false; } } if (body_parameters[desc->m_body_parameter_index] == iteration_counter) { - auto merged_desc = std::dynamic_pointer_cast(desc); + auto merged_desc = ov::as_type_ptr(desc); if (!merged_desc) { return false; } diff --git a/src/common/transformations/src/transformations/op_conversions/convert_xor_to_logical_xor.cpp b/src/common/transformations/src/transformations/op_conversions/convert_xor_to_logical_xor.cpp index 581de029d584a9..97414817019f0b 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_xor_to_logical_xor.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_xor_to_logical_xor.cpp @@ -16,7 +16,7 @@ ov::pass::ConvertXorToLogicalXor::ConvertXorToLogicalXor() { auto xor_v1 = pattern::wrap_type(); matcher_pass_callback callback = [=](pattern::Matcher& m) { - auto xor_v1_node = std::dynamic_pointer_cast(m.get_match_root()); + auto xor_v1_node = ov::as_type_ptr(m.get_match_root()); if (!xor_v1_node) return false; 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 a63896993a317c..22ef0c662f284e 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 @@ -24,7 +24,7 @@ ov::pass::LSTMCellDecomposition::LSTMCellDecomposition() { auto any_lstm = pattern::wrap_type(); matcher_pass_callback callback = [this](ov::pass::pattern::Matcher& m) { - auto lstm_cell = std::dynamic_pointer_cast(m.get_match_root()); + auto lstm_cell = ov::as_type_ptr(m.get_match_root()); if (!lstm_cell || transformation_callback(lstm_cell)) { return false; } diff --git a/src/common/transformations/src/transformations/smart_reshape/lstm_states_broadcast.cpp b/src/common/transformations/src/transformations/smart_reshape/lstm_states_broadcast.cpp index b828b7a6a16f65..89e20934b0c263 100644 --- a/src/common/transformations/src/transformations/smart_reshape/lstm_states_broadcast.cpp +++ b/src/common/transformations/src/transformations/smart_reshape/lstm_states_broadcast.cpp @@ -104,7 +104,7 @@ shared_ptr deduce_outer_source_of_batch_for_inner_lstm_cell( } bool broadcast_state_by_batch(ov::Input input, const shared_ptr& batch_delivering_node) { - auto constant_state = dynamic_pointer_cast(input.get_source_output().get_node_shared_ptr()); + auto constant_state = ov::as_type_ptr(input.get_source_output().get_node_shared_ptr()); if (constant_state == nullptr) return false; const auto& constant_shape = constant_state->get_shape(); @@ -132,11 +132,11 @@ bool relax_batch_for_initial_states_of_lstm_in_ti(const shared_ptr(lstm_cell->get_input_node_shared_ptr(1))) { + if (auto init_hidden_state = ov::as_type_ptr(lstm_cell->get_input_node_shared_ptr(1))) { auto outer_init_hidden_state_input = get_outer_input_of_ti_by_parameter(init_hidden_state, ti); rewritten = broadcast_state_by_batch(outer_init_hidden_state_input, batch_delivering_node) || rewritten; } - if (auto init_cell_state = dynamic_pointer_cast(lstm_cell->get_input_node_shared_ptr(2))) { + if (auto init_cell_state = ov::as_type_ptr(lstm_cell->get_input_node_shared_ptr(2))) { auto outer_init_cell_state_input = get_outer_input_of_ti_by_parameter(init_cell_state, ti); rewritten = broadcast_state_by_batch(outer_init_cell_state_input, batch_delivering_node) || rewritten; } @@ -165,16 +165,16 @@ bool ov::pass::LSTMStatesBroadcast::run_on_model(const shared_ptr& f) rewritten = ov::op::util::process_subgraph(*this, node) || rewritten; // Case without TI (LSTMCell and Constant are in the same ov::Model) - if (const auto& lstm_cell = dynamic_pointer_cast(node)) + if (const auto& lstm_cell = ov::as_type_ptr(node)) rewritten = relax_batch_for_initial_states_of_lstm(lstm_cell) || rewritten; // Case with TI (LSTMCell and Constant are in different ov::Model objects) - if (auto ti = dynamic_pointer_cast(node)) { + if (auto ti = ov::as_type_ptr(node)) { auto body = ti->get_body(); if (body == nullptr) continue; for (const auto& body_node : body->get_ordered_ops()) - if (const auto& lstm_cell = dynamic_pointer_cast(body_node)) + if (const auto& lstm_cell = ov::as_type_ptr(body_node)) rewritten = relax_batch_for_initial_states_of_lstm_in_ti(ti, lstm_cell) || rewritten; } } diff --git a/src/common/transformations/src/transformations/smart_reshape/reshape_sinking.cpp b/src/common/transformations/src/transformations/smart_reshape/reshape_sinking.cpp index f92f7673dd8902..7d12e741a19b53 100644 --- a/src/common/transformations/src/transformations/smart_reshape/reshape_sinking.cpp +++ b/src/common/transformations/src/transformations/smart_reshape/reshape_sinking.cpp @@ -52,7 +52,7 @@ ov::pass::ReshapeSinkingMatMul::ReshapeSinkingMatMul() { // check first Reshape eligibility: has a constant output pattern in a form of [-1, K] auto reshape = pattern_to_node.at(reshape_label); int64_t K = -1; - if (const auto& constant = dynamic_pointer_cast(reshape->get_input_node_shared_ptr(1))) { + if (const auto& constant = ov::as_type_ptr(reshape->get_input_node_shared_ptr(1))) { auto output_pattern_vector = constant->cast_vector(); if (output_pattern_vector.size() != 2 || output_pattern_vector[0] != -1) return false; @@ -70,11 +70,11 @@ ov::pass::ReshapeSinkingMatMul::ReshapeSinkingMatMul() { return false; // check matmul eligibility: has constant second input in a form of [O, K] - auto matmul = dynamic_pointer_cast(pattern_to_node.at(matmul_label)); + auto matmul = ov::as_type_ptr(pattern_to_node.at(matmul_label)); if (!matmul || matmul->get_transpose_a()) return false; int64_t O = -1; - if (const auto& constant = dynamic_pointer_cast(matmul->get_input_node_shared_ptr(1))) { + if (const auto& constant = ov::as_type_ptr(matmul->get_input_node_shared_ptr(1))) { const auto& constant_shape = constant->get_shape(); if (constant_shape.size() != 2) return false; @@ -90,10 +90,10 @@ ov::pass::ReshapeSinkingMatMul::ReshapeSinkingMatMul() { // check add eligibility if present: has constant second input that has a form of [1, 1, ..., O] (doesn't // broadcast first input) if (pattern_to_node.count(add_label)) { - auto add = dynamic_pointer_cast(pattern_to_node.at(add_label)); + auto add = ov::as_type_ptr(pattern_to_node.at(add_label)); if (!add || add->get_autob() != ov::op::AutoBroadcastType::NUMPY) return false; - const auto& constant = dynamic_pointer_cast(add->get_input_node_shared_ptr(1)); + const auto& constant = ov::as_type_ptr(add->get_input_node_shared_ptr(1)); if (!constant) return false; const auto& constant_shape = constant->get_shape(); @@ -110,7 +110,7 @@ ov::pass::ReshapeSinkingMatMul::ReshapeSinkingMatMul() { // input_shape of the pattern except for the batch and last dimension auto reshape_1 = m.get_match_root(); - const auto& constant = dynamic_pointer_cast(reshape_1->get_input_node_shared_ptr(1)); + const auto& constant = ov::as_type_ptr(reshape_1->get_input_node_shared_ptr(1)); if (constant == nullptr) return false; auto output_pattern = constant->cast_vector(); @@ -131,8 +131,8 @@ ov::pass::ReshapeSinkingMatMul::ReshapeSinkingMatMul() { return false; } - auto first_reshape = dynamic_pointer_cast(reshape); - auto second_reshape = dynamic_pointer_cast(reshape_1); + auto first_reshape = ov::as_type_ptr(reshape); + auto second_reshape = ov::as_type_ptr(reshape_1); if (!first_reshape || !second_reshape) return false; diff --git a/src/common/transformations/src/transformations/symbolic_transformations/symbol_optimization.cpp b/src/common/transformations/src/transformations/symbolic_transformations/symbol_optimization.cpp index 55f0794e0ee008..f79c1f7f6b6703 100644 --- a/src/common/transformations/src/transformations/symbolic_transformations/symbol_optimization.cpp +++ b/src/common/transformations/src/transformations/symbolic_transformations/symbol_optimization.cpp @@ -29,7 +29,7 @@ void update_symbol(std::shared_ptr& symbol) { void apply_table_of_equivalence_on_model(const std::shared_ptr& m) { for (const auto& op : m->get_ordered_ops()) { // handle inner sub-graphs - if (auto multi_subgraph_op = std::dynamic_pointer_cast(op)) + if (auto multi_subgraph_op = ov::as_type_ptr(op)) for (const auto& sub_graph : multi_subgraph_op->get_functions()) if (sub_graph) apply_table_of_equivalence_on_model(sub_graph); diff --git a/src/common/transformations/src/transformations/utils/utils.cpp b/src/common/transformations/src/transformations/utils/utils.cpp index f23817af80a51c..8514d17fba84de 100644 --- a/src/common/transformations/src/transformations/utils/utils.cpp +++ b/src/common/transformations/src/transformations/utils/utils.cpp @@ -484,7 +484,7 @@ bool is_on_constant_path(const ov::Output& output) { bool process_subgraph(ov::pass::ModelPass& model_pass, const std::shared_ptr& node) { bool changed = false; - if (const auto& multi_subgraph_op = std::dynamic_pointer_cast(node)) { + if (const auto& multi_subgraph_op = ov::as_type_ptr(node)) { for (const auto& sub_graph : multi_subgraph_op->get_functions()) { if (sub_graph) { changed = model_pass.run_on_model(sub_graph) || changed; diff --git a/src/common/transformations/tests/common_optimizations/eliminate_duplicate_ti_inputs.cpp b/src/common/transformations/tests/common_optimizations/eliminate_duplicate_ti_inputs.cpp index 6af176b48eef4c..f6ca65db6bf0d1 100644 --- a/src/common/transformations/tests/common_optimizations/eliminate_duplicate_ti_inputs.cpp +++ b/src/common/transformations/tests/common_optimizations/eliminate_duplicate_ti_inputs.cpp @@ -69,7 +69,7 @@ TEST(TransformationTests, EliminateDuplicateTIInputs) { shared_ptr ti_after_transformation; for (const auto& op : model->get_ordered_ops()) { - if ((ti_after_transformation = dynamic_pointer_cast(op))) { + if ((ti_after_transformation = ov::as_type_ptr(op))) { break; } } diff --git a/src/common/transformations/tests/common_optimizations/gru_cell_fusion.cpp b/src/common/transformations/tests/common_optimizations/gru_cell_fusion.cpp index a5546f06b3922a..f0e7eecc120070 100644 --- a/src/common/transformations/tests/common_optimizations/gru_cell_fusion.cpp +++ b/src/common/transformations/tests/common_optimizations/gru_cell_fusion.cpp @@ -99,12 +99,12 @@ shared_ptr gen_reference(WeightsFormat format, shared_ptr B = make_shared(f32, Shape{1, 2 * hidden_size}, 0); if (use_bias_add_1) { B = make_shared(f32, Shape{1, 2 * hidden_size}); - params.push_back(dynamic_pointer_cast(B)); + params.push_back(ov::as_type_ptr(B)); } shared_ptr Bh = make_shared(f32, Shape{1, hidden_size}, 0); if (use_bias_add_2) { Bh = make_shared(f32, Shape{1, hidden_size}); - params.push_back(dynamic_pointer_cast(Bh)); + params.push_back(ov::as_type_ptr(Bh)); } auto axis_0 = make_shared(i64, Shape{}, 0); diff --git a/src/common/transformations/tests/common_optimizations/transpose_sinking_test.cpp b/src/common/transformations/tests/common_optimizations/transpose_sinking_test.cpp index f551d753295b0d..2ace6defd9e21f 100644 --- a/src/common/transformations/tests/common_optimizations/transpose_sinking_test.cpp +++ b/src/common/transformations/tests/common_optimizations/transpose_sinking_test.cpp @@ -209,9 +209,9 @@ class TransposeSinking : public ov::test::TestsCommon, " version: ", reduction_type_info.version_id); - if (auto arithmetic_reduce = std::dynamic_pointer_cast(reduction)) + if (auto arithmetic_reduce = ov::as_type_ptr(reduction)) arithmetic_reduce->set_keep_dims(keep_dims); - else if (auto logical_reduce = std::dynamic_pointer_cast(reduction)) + else if (auto logical_reduce = ov::as_type_ptr(reduction)) logical_reduce->set_keep_dims(keep_dims); reduction->validate_and_infer_types(); return reduction; diff --git a/src/common/transformations/tests/transpose_sinking/ts_test_utils.cpp b/src/common/transformations/tests/transpose_sinking/ts_test_utils.cpp index 31be099f03a868..bad5e590337a2b 100644 --- a/src/common/transformations/tests/transpose_sinking/ts_test_utils.cpp +++ b/src/common/transformations/tests/transpose_sinking/ts_test_utils.cpp @@ -30,7 +30,7 @@ ParameterVector filter_parameters(const OutputVector& out_vec) { ParameterVector parameters; for (const auto& out : out_vec) { auto node = out.get_node_shared_ptr(); - if (auto param = dynamic_pointer_cast(node)) { + if (auto param = ov::as_type_ptr(node)) { parameters.push_back(param); } } @@ -98,4 +98,4 @@ Output parameter(ov::element::Type el_type, const PartialShape& ps) { } // namespace utils } // namespace testing -} // namespace transpose_sinking \ No newline at end of file +} // namespace transpose_sinking diff --git a/src/core/reference/src/op/loop.cpp b/src/core/reference/src/op/loop.cpp index 17d9a57e538b93..de23668fe8b16f 100644 --- a/src/core/reference/src/op/loop.cpp +++ b/src/core/reference/src/op/loop.cpp @@ -62,7 +62,7 @@ void loop(const std::shared_ptr& func, std::vector back_edges; for (const auto& desc : input_descs) { inputs_to_body[desc->m_body_parameter_index] = args[desc->m_input_index]; - if (const auto& merged_desc = std::dynamic_pointer_cast(desc)) { + if (const auto& merged_desc = ov::as_type_ptr(desc)) { back_edges.push_back({merged_desc->m_body_parameter_index, merged_desc->m_body_value_index}); cur_iter_back_edge_exist |= merged_desc->m_body_parameter_index == static_cast(cur_iter_idx); } @@ -87,7 +87,7 @@ void loop(const std::shared_ptr& func, // Find all ConcatOutputDescription std::vector> concat_outputs; for (const auto& desc : out_descs) { - if (const auto& concat_desc = std::dynamic_pointer_cast(desc)) { + if (const auto& concat_desc = ov::as_type_ptr(desc)) { concat_outputs.push_back(concat_desc); } } @@ -97,8 +97,7 @@ void loop(const std::shared_ptr& func, std::vector sliced_values; int slice_in_idx = 0; for (const auto& desc : input_descs) { - if (const auto& slice_desc = - std::dynamic_pointer_cast(desc)) { + if (const auto& slice_desc = ov::as_type_ptr(desc)) { const auto el_size = args[slice_desc->m_input_index].get_element_type().size(); slice_inputs.push_back(slice_desc); auto shape = args[slice_desc->m_input_index].get_shape(); @@ -196,7 +195,7 @@ void loop(const std::shared_ptr& func, } for (const auto& desc : out_descs) { - if (const auto& body_desc = std::dynamic_pointer_cast(desc)) { + if (const auto& body_desc = ov::as_type_ptr(desc)) { const auto& res = body_outputs[body_desc->m_body_value_index]; res.copy_to(out[body_desc->m_output_index]); } diff --git a/src/core/reference/src/op/tensor_iterator.cpp b/src/core/reference/src/op/tensor_iterator.cpp index 96fb53e579d7f2..764db04aba0ad4 100644 --- a/src/core/reference/src/op/tensor_iterator.cpp +++ b/src/core/reference/src/op/tensor_iterator.cpp @@ -32,15 +32,14 @@ void tensor_iterator(uint64_t num_iterations, std::vector back_edges; for (const auto& desc : input_descs) { inputs_to_body[desc->m_body_parameter_index] = args[desc->m_input_index]; - if (const auto& merged_desc = std::dynamic_pointer_cast(desc)) { + if (const auto& merged_desc = ov::as_type_ptr(desc)) { back_edges.push_back({merged_desc->m_body_parameter_index, merged_desc->m_body_value_index}); } } // Find all ConcatOutputDescription std::vector> concat_outputs; for (const auto& desc : out_descs) { - if (const auto& concat_desc = - std::dynamic_pointer_cast(desc)) { + if (const auto& concat_desc = ov::as_type_ptr(desc)) { concat_outputs.push_back(concat_desc); } } @@ -50,7 +49,7 @@ void tensor_iterator(uint64_t num_iterations, std::vector sliced_values; int slice_in_idx = 0; for (const auto& desc : input_descs) { - if (const auto& slice_desc = std::dynamic_pointer_cast(desc)) { + if (const auto& slice_desc = ov::as_type_ptr(desc)) { const auto el_size = args[slice_desc->m_input_index].get_element_type().size(); slice_inputs.push_back(slice_desc); auto shape = args[slice_desc->m_input_index].get_shape(); @@ -106,7 +105,7 @@ void tensor_iterator(uint64_t num_iterations, } for (const auto& desc : out_descs) { - if (const auto& body_desc = std::dynamic_pointer_cast(desc)) { + if (const auto& body_desc = ov::as_type_ptr(desc)) { // Copy output values from the last iteration const auto& res = body_outputs[body_desc->m_body_value_index]; res.copy_to(out[body_desc->m_output_index]); diff --git a/src/core/src/bound_evaluate.cpp b/src/core/src/bound_evaluate.cpp index f1c6a0601eea90..0b4ab39a7bc2d3 100644 --- a/src/core/src/bound_evaluate.cpp +++ b/src/core/src/bound_evaluate.cpp @@ -590,7 +590,7 @@ bool ov::tensor_has_max_value(const Tensor& bound) { folded = std::make_shared(equal[0], axes)->constant_fold(all, {equal[0], axes}); OPENVINO_ASSERT(folded && ov::is_type(all[0].get_node_shared_ptr())); OPENVINO_ASSERT(all[0].get_shape() == Shape{}); - return std::dynamic_pointer_cast(all[0].get_node_shared_ptr())->cast_vector()[0]; + return ov::as_type_ptr(all[0].get_node_shared_ptr())->cast_vector()[0]; } bool ov::tensor_has_zero_value(const Tensor& bound) { @@ -611,7 +611,7 @@ bool ov::tensor_has_zero_value(const Tensor& bound) { folded = std::make_shared(equal[0], axes)->constant_fold(all, {equal[0], axes}); OPENVINO_ASSERT(folded && ov::is_type(all[0].get_node_shared_ptr())); OPENVINO_ASSERT(all[0].get_shape() == Shape{}); - return std::dynamic_pointer_cast(all[0].get_node_shared_ptr())->cast_vector()[0]; + return ov::as_type_ptr(all[0].get_node_shared_ptr())->cast_vector()[0]; } bool ov::has_and_set_equal_bounds(const Output& source) { diff --git a/src/core/src/model.cpp b/src/core/src/model.cpp index e2e4115d925b16..97e53f78457a13 100644 --- a/src/core/src/model.cpp +++ b/src/core/src/model.cpp @@ -75,7 +75,7 @@ ov::ParameterVector auto_detect_parameters(const std::vector(op)) { + if (const auto& param = ov::as_type_ptr(op)) { parameter_vector.push_back(param); } } diff --git a/src/core/src/op/convert_like.cpp b/src/core/src/op/convert_like.cpp index 4ae4ea982f8cd9..f65e95bf14af06 100644 --- a/src/core/src/op/convert_like.cpp +++ b/src/core/src/op/convert_like.cpp @@ -39,7 +39,7 @@ bool ConvertLike::constant_fold(OutputVector& output_values, const OutputVector& return false; } - if (auto data_const = std::dynamic_pointer_cast(input_values[0].get_node_shared_ptr())) { + if (auto data_const = ov::as_type_ptr(input_values[0].get_node_shared_ptr())) { auto convert = std::make_shared(input_values[0], input_values[1].get_element_type()); return convert->constant_fold(output_values, OutputVector{data_const}); } diff --git a/src/core/src/op/loop.cpp b/src/core/src/op/loop.cpp index 9e5d207162098b..20592b0c8b7a30 100644 --- a/src/core/src/op/loop.cpp +++ b/src/core/src/op/loop.cpp @@ -90,7 +90,7 @@ void Loop::validate_and_infer_types() { m_num_iterations = 1; // condition_always_false, do_while mode } } else if (const auto& cond_param = - std::dynamic_pointer_cast(body_execution_condition.get_node_shared_ptr())) { + ov::as_type_ptr(body_execution_condition.get_node_shared_ptr())) { // Const(true or false) -> Loop (body: Parameter -> execution_condition output) for (const auto& desc : get_input_descriptions()) { if (m_bodies[0]->get_parameters().at(desc->m_body_parameter_index) == cond_param) { diff --git a/src/core/src/op/reshape.cpp b/src/core/src/op/reshape.cpp index 477e210f574269..a388266f343ec4 100644 --- a/src/core/src/op/reshape.cpp +++ b/src/core/src/op/reshape.cpp @@ -101,7 +101,7 @@ bool Reshape::constant_fold(OutputVector& output_values, const OutputVector& inp return false; } - if (auto data_const = std::dynamic_pointer_cast(inputs_values[0].get_node_shared_ptr())) { + if (auto data_const = ov::as_type_ptr(inputs_values[0].get_node_shared_ptr())) { output_values[0] = std::make_shared(*data_const, get_output_shape(0)); return true; } else { diff --git a/src/core/src/op/unique.cpp b/src/core/src/op/unique.cpp index 78156687bfcdf7..46e28dac93af1d 100644 --- a/src/core/src/op/unique.cpp +++ b/src/core/src/op/unique.cpp @@ -34,8 +34,7 @@ std::tuple calculate_static_output_shapes(const Tensor& inp const auto maybe_extract_axis = [&op]() { std::unique_ptr axis; if (op.get_input_size() == 2 && ov::op::util::is_constant(op.input_value(1).get_node())) { - const auto axis_constant = - std::dynamic_pointer_cast(op.input_value(1).get_node_shared_ptr()); + const auto axis_constant = ov::as_type_ptr(op.input_value(1).get_node_shared_ptr()); axis = std::unique_ptr(new int64_t{extract_axis(axis_constant)}); } return axis; @@ -112,7 +111,7 @@ void op::v10::Unique::validate_and_infer_types() { output_shapes[3] = output_shapes[1]; if (ov::op::util::is_constant(input_value(0).get_node())) { - const auto input_const = std::dynamic_pointer_cast(input_value(0).get_node_shared_ptr()); + const auto input_const = ov::as_type_ptr(input_value(0).get_node_shared_ptr()); ov::Tensor input_data = ov::Tensor(input_const->get_element_type(), input_const->get_shape()); memcpy(input_data.data(), input_const->get_data_ptr(), input_data.get_byte_size()); const auto tensor_shapes = calculate_static_output_shapes(input_data, *this); @@ -137,8 +136,7 @@ void op::v10::Unique::validate_and_infer_types() { get_input_partial_shape(1) == PartialShape{} || get_input_partial_shape(1) == PartialShape{1}, "The 'axis' input tensor of the Unique operator must be a scalar or 1D tensor with 1 element."); - const int64_t axis = - extract_axis(std::dynamic_pointer_cast(input_value(1).get_node_shared_ptr())); + const int64_t axis = extract_axis(ov::as_type_ptr(input_value(1).get_node_shared_ptr())); if (input_shape.rank().is_static()) { const auto normalized_axis = ov::util::try_normalize_axis(axis, input_shape.rank(), *this); diff --git a/src/core/src/op/unsqueeze.cpp b/src/core/src/op/unsqueeze.cpp index f8c14a08f70d30..eb9d5e3bf839f2 100644 --- a/src/core/src/op/unsqueeze.cpp +++ b/src/core/src/op/unsqueeze.cpp @@ -88,7 +88,7 @@ bool ov::op::v0::Unsqueeze::constant_fold(OutputVector& output_values, const Out const auto& shape = get_output_shape(0); - if (auto data_const = std::dynamic_pointer_cast(inputs_values[0].get_node_shared_ptr())) { + if (auto data_const = ov::as_type_ptr(inputs_values[0].get_node_shared_ptr())) { output_values[0] = std::make_shared(*data_const, shape); return true; } diff --git a/src/core/src/op/util/gather_base.cpp b/src/core/src/op/util/gather_base.cpp index dd35edf695ec16..3863f2aeeb6824 100644 --- a/src/core/src/op/util/gather_base.cpp +++ b/src/core/src/op/util/gather_base.cpp @@ -32,9 +32,9 @@ Shape out_shape_infer(const Shape& data_shape, const Shape& indices_shape, int64 bool cf_gather_with_subgraph(OutputVector& output_values, const OutputVector& input_values, const PartialShape& gather_ps) { - const auto concat = std::dynamic_pointer_cast(input_values[0].get_node_shared_ptr()); - const auto indices = std::dynamic_pointer_cast(input_values[1].get_node_shared_ptr()); - const auto axis = std::dynamic_pointer_cast(input_values[2].get_node_shared_ptr()); + const auto concat = ov::as_type_ptr(input_values[0].get_node_shared_ptr()); + const auto indices = ov::as_type_ptr(input_values[1].get_node_shared_ptr()); + const auto axis = ov::as_type_ptr(input_values[2].get_node_shared_ptr()); if (!concat || !indices || !axis) { return false; diff --git a/src/core/src/op/util/squeeze_base.cpp b/src/core/src/op/util/squeeze_base.cpp index be5a20cbb58620..6e048044ab1b94 100644 --- a/src/core/src/op/util/squeeze_base.cpp +++ b/src/core/src/op/util/squeeze_base.cpp @@ -73,7 +73,7 @@ bool SqueezeBase::constant_fold(OutputVector& output_values, const OutputVector& return false; } - if (auto data_const = std::dynamic_pointer_cast(inputs_values[0].get_node_shared_ptr())) { + if (auto data_const = ov::as_type_ptr(inputs_values[0].get_node_shared_ptr())) { const auto& shape = get_output_shape(0); output_values[0] = std::make_shared(*data_const, shape); return true; diff --git a/src/core/src/op/util/symbolic_info.cpp b/src/core/src/op/util/symbolic_info.cpp index 51d917ab256979..ecf096d5a850e9 100644 --- a/src/core/src/op/util/symbolic_info.cpp +++ b/src/core/src/op/util/symbolic_info.cpp @@ -35,7 +35,7 @@ void ov::populate_tensor_with_missing_symbols(ov::descriptor::Tensor& tensor) { void ov::remove_skip_invalidation_rti(const std::shared_ptr& model, bool outermost_model) { const auto& type = ov::SkipInvalidation::get_type_info_static(); for (const auto& op : model->get_ops()) { - if (auto multi_subgraph_op = std::dynamic_pointer_cast(op)) + if (auto multi_subgraph_op = ov::as_type_ptr(op)) for (const auto& sub_graph : multi_subgraph_op->get_functions()) if (sub_graph) remove_skip_invalidation_rti(sub_graph, false); diff --git a/src/core/src/pass/constant_folding.cpp b/src/core/src/pass/constant_folding.cpp index cc1a7cea5b5add..3f02c7ff87e72c 100644 --- a/src/core/src/pass/constant_folding.cpp +++ b/src/core/src/pass/constant_folding.cpp @@ -106,7 +106,7 @@ bool ov::pass::ConstantFolding::run_on_model(const std::shared_ptr& m for (const auto& original_node : model->get_ordered_ops()) { auto node = original_node; if (!original_node->can_constant_fold(original_node->input_values())) { - if (auto sub_graph_node = std::dynamic_pointer_cast(node)) { + if (auto sub_graph_node = ov::as_type_ptr(node)) { // recursively constant fold operators containing subgraphs (ie: TensorIterator, Loop) size_t sub_graphs_num = sub_graph_node->get_internal_subgraphs_size(); for (size_t sub_graph_ind = 0; sub_graph_ind < sub_graphs_num; ++sub_graph_ind) { diff --git a/src/core/src/pass/graph_rewrite.cpp b/src/core/src/pass/graph_rewrite.cpp index f8a1f1e723d7a7..b53f58513e5e35 100644 --- a/src/core/src/pass/graph_rewrite.cpp +++ b/src/core/src/pass/graph_rewrite.cpp @@ -117,7 +117,7 @@ bool ov::pass::GraphRewrite::apply_matcher_passes(std::shared_ptr f, auto root = matcher->get_pattern_value().get_node_shared_ptr(); // pattern::op::AnyOutput operation automatically appends for multi output operations inside // Matcher and to gen actual root node we need to take it's parent. - if (auto any_type = std::dynamic_pointer_cast(root)) { + if (auto any_type = ov::as_type_ptr(root)) { root = any_type->input_value(0).get_node_shared_ptr(); } @@ -126,7 +126,7 @@ bool ov::pass::GraphRewrite::apply_matcher_passes(std::shared_ptr f, // and use it in unordered_map as key for fast MatcherPass search. Otherwise type is unknown // and default algorithm is used. if (auto p = std::dynamic_pointer_cast(root)) { - if (auto any_type = std::dynamic_pointer_cast(p)) { + if (auto any_type = ov::as_type_ptr(p)) { for (const auto& root_type_info : any_type->get_wrapped_types()) { type_to_matcher[root_type_info].push_back(matcher_index); } @@ -186,7 +186,7 @@ bool ov::pass::GraphRewrite::apply_matcher_passes(std::shared_ptr f, continue; // Recursive apply Matchers for sub-graph based nodes - if (auto sub_graph_node = std::dynamic_pointer_cast(node)) { + if (auto sub_graph_node = ov::as_type_ptr(node)) { if (sub_graph_node->get_transformations_allowed()) { size_t sub_graphs_num = sub_graph_node->get_internal_subgraphs_size(); for (size_t sub_graph_ind = 0; sub_graph_ind < sub_graphs_num; ++sub_graph_ind) { diff --git a/src/core/src/pass/low_latency.cpp b/src/core/src/pass/low_latency.cpp index 4b9f606b3e4b28..5666c404361455 100644 --- a/src/core/src/pass/low_latency.cpp +++ b/src/core/src/pass/low_latency.cpp @@ -158,7 +158,7 @@ std::vector> process_sequence(const std::sha std::shared_ptr cell; std::vector> new_assigns; bool unroll = false; - if (auto lstm_seq_v5 = std::dynamic_pointer_cast(op)) { + if (auto lstm_seq_v5 = ov::as_type_ptr(op)) { unroll = need_unroll(op); new_assigns = replace_with_memory(op, {1, 2}, m_use_const_initializer, to); if (unroll) { @@ -175,7 +175,7 @@ std::vector> process_sequence(const std::sha lstm_seq_v5->get_activations_beta(), lstm_seq_v5->get_clip()); } - } else if (auto gru_seq = std::dynamic_pointer_cast(op)) { + } else if (auto gru_seq = ov::as_type_ptr(op)) { unroll = need_unroll(op); new_assigns = replace_with_memory(op, {1}, m_use_const_initializer, to); if (unroll) { @@ -192,7 +192,7 @@ std::vector> process_sequence(const std::sha gru_seq->get_clip(), gru_seq->get_linear_before_reset()); } - } else if (auto rnn_seq = std::dynamic_pointer_cast(op)) { + } else if (auto rnn_seq = ov::as_type_ptr(op)) { unroll = need_unroll(op); new_assigns = replace_with_memory(op, {1}, m_use_const_initializer, to); if (unroll) { @@ -245,21 +245,20 @@ bool ov::pass::LowLatency2::run_on_model(const std::shared_ptr& f) { for (const auto& op : f->get_ordered_ops()) { ov::op::util::process_subgraph(*this, op); - if (const auto& sub_graph_op = std::dynamic_pointer_cast(op)) { + if (const auto& sub_graph_op = ov::as_type_ptr(op)) { int64_t variable_id = 0; const auto& func = sub_graph_op->get_function(); const auto& params = func->get_parameters(); for (const auto& in : sub_graph_op->get_input_descriptions()) { // Process all back edges - if (const auto& merged_in = std::dynamic_pointer_cast(in)) { + if (const auto& merged_in = ov::as_type_ptr(in)) { // create new Variable const std::string& param_name = params.at(merged_in->m_body_parameter_index)->get_friendly_name(); const std::string& var_name = generate_variable_name(sub_graph_op->get_friendly_name(), param_name, variable_id); const auto& input = sub_graph_op->input(merged_in->m_input_index); - if (std::dynamic_pointer_cast(input.get_source_output().get_node_shared_ptr()) != - nullptr) { + if (ov::as_type_ptr(input.get_source_output().get_node_shared_ptr()) != nullptr) { OPENVINO_DEBUG(msg_low_latency_2_already_applied); return false; } diff --git a/src/core/src/pass/make_stateful.cpp b/src/core/src/pass/make_stateful.cpp index 4b6c26e59c8a8e..4242d85377877d 100644 --- a/src/core/src/pass/make_stateful.cpp +++ b/src/core/src/pass/make_stateful.cpp @@ -70,7 +70,7 @@ std::tuple> find " are already involved in the transformation."); uniq_res.insert(unused_res); - if (auto casted = std::dynamic_pointer_cast(unused_res->shared_from_this())) + if (auto casted = ov::as_type_ptr(unused_res->shared_from_this())) pairs_to_replace.emplace_back(*param, casted); variable_names.push_back(param_name + res_name); } diff --git a/src/core/src/pass/manager.cpp b/src/core/src/pass/manager.cpp index b084ec4dc38e09..24bede795bb390 100644 --- a/src/core/src/pass/manager.cpp +++ b/src/core/src/pass/manager.cpp @@ -385,11 +385,11 @@ bool ov::pass::Manager::run_pass(const std::shared_ptr& pass, OV_ITT_SCOPE(FIRST_INFERENCE, ov::itt::domains::ov_pass, ov::pass::perf_counters()[pass->get_type_info()]); - if (auto matcher_pass = std::dynamic_pointer_cast(pass)) { + if (auto matcher_pass = ov::as_type_ptr(pass)) { // GraphRewrite is a temporary container for MatcherPass to make execution on entire ov::Model return GraphRewrite(matcher_pass).run_on_model(model); - } else if (auto model_pass = std::dynamic_pointer_cast(pass)) { - if (std::dynamic_pointer_cast(model_pass) && !needs_validate) { + } else if (auto model_pass = ov::as_type_ptr(pass)) { + if (ov::as_type_ptr(model_pass) && !needs_validate) { return false; } return model_pass->run_on_model(model); diff --git a/src/core/src/pass/sdpa_to_paged_attention.cpp b/src/core/src/pass/sdpa_to_paged_attention.cpp index ea3f3c3e79e196..74b00a16a4fdb0 100644 --- a/src/core/src/pass/sdpa_to_paged_attention.cpp +++ b/src/core/src/pass/sdpa_to_paged_attention.cpp @@ -112,7 +112,7 @@ bool ov::pass::SDPAToPagedAttention::run_on_model(const std::shared_ptr(element::i64, PartialShape{-1}), "position_ids"); model->add_parameters({position_ids}); } else { - position_ids = std::dynamic_pointer_cast(model->input("position_ids").get_node_shared_ptr()); + position_ids = ov::as_type_ptr(model->input("position_ids").get_node_shared_ptr()); position_ids->set_partial_shape(PartialShape{-1}); position_ids->validate_and_infer_types(); } diff --git a/src/core/src/pass/stateful_to_stateless.cpp b/src/core/src/pass/stateful_to_stateless.cpp index 95f289c71c201e..6be4a9622e5930 100644 --- a/src/core/src/pass/stateful_to_stateless.cpp +++ b/src/core/src/pass/stateful_to_stateless.cpp @@ -96,9 +96,8 @@ bool ov::pass::StatefulToStateless::run_on_model(const std::shared_ptr& input : beam_idx->get_output_target_inputs(0)) { - if (auto gather = std::dynamic_pointer_cast(input.get_node()->shared_from_this())) { - auto read_value = - std::dynamic_pointer_cast(gather->get_input_node_shared_ptr(0)); + if (auto gather = ov::as_type_ptr(input.get_node()->shared_from_this())) { + auto read_value = ov::as_type_ptr(gather->get_input_node_shared_ptr(0)); OPENVINO_ASSERT(read_value, "Unexpected model topology in StatefulToStateless: no ReadValue is found at the first " "input of Gather by `beam_idx` parameter"); @@ -118,7 +117,7 @@ bool ov::pass::StatefulToStateless::run_on_model(const std::shared_ptr assign_index_by_var_id; const auto& sinks = model->get_sinks(); for (size_t i = 0; i < sinks.size(); ++i) { - if (auto assign = std::dynamic_pointer_cast(sinks[i])) { + if (auto assign = ov::as_type_ptr(sinks[i])) { const auto& var_id = assign->get_variable_id(); assigns_by_var_id[var_id] = std::move(assign); assign_index_by_var_id[var_id] = i; diff --git a/src/core/src/pass/visualize_tree.cpp b/src/core/src/pass/visualize_tree.cpp index cf7bb6e85bdf37..5be54f1a6b98fe 100644 --- a/src/core/src/pass/visualize_tree.cpp +++ b/src/core/src/pass/visualize_tree.cpp @@ -185,7 +185,7 @@ static void collect_symbol_print_values(const std::shared_ptr& m, std::unordered_map, size_t>& symbol_to_number) { size_t n = symbol_to_number.size() + 1; for (const auto& node : m->get_ops()) { - if (auto multi_subgraph_op = std::dynamic_pointer_cast(node)) + if (auto multi_subgraph_op = ov::as_type_ptr(node)) for (size_t i = 0; i < multi_subgraph_op->get_internal_subgraphs_size(); ++i) if (const auto& sub_graph = multi_subgraph_op->get_function(i)) collect_symbol_print_values(sub_graph, symbol_to_number); @@ -241,7 +241,7 @@ bool ov::pass::VisualizeTree::run_on_model(const std::shared_ptr& f) for (auto it = nodes.rbegin(); it != nodes.rend(); ++it) { auto& node = *it; - if (auto multi_subgraph_op = std::dynamic_pointer_cast(node)) { + if (auto multi_subgraph_op = ov::as_type_ptr(node)) { for (size_t i = 0; i < multi_subgraph_op->get_internal_subgraphs_size(); ++i) if (const auto& sub_graph = multi_subgraph_op->get_function(i)) ov::pass::VisualizeTree(name_of_subgraph_file(multi_subgraph_op, m_name, i), diff --git a/src/core/src/preprocess/preprocess_impls.cpp b/src/core/src/preprocess/preprocess_impls.cpp index e0cdee2e76a140..d87d1fac69b8fa 100644 --- a/src/core/src/preprocess/preprocess_impls.cpp +++ b/src/core/src/preprocess/preprocess_impls.cpp @@ -415,7 +415,7 @@ void OutputInfo::OutputInfoImpl::dump(std::ostream& str) const { std::shared_ptr result; auto node = m_output_node; const auto& start_out_node_names = node.get_tensor().get_names(); - result = std::dynamic_pointer_cast(node.get_node_shared_ptr()); + result = ov::as_type_ptr(node.get_node_shared_ptr()); auto model_layout = get_model_data()->is_layout_set() ? get_model_data()->get_layout() : result->get_layout(); PostprocessingContext context(model_layout); if (get_tensor_data()->is_layout_set()) { diff --git a/src/core/src/runtime/itensor.cpp b/src/core/src/runtime/itensor.cpp index caa19d8c8ea36b..87b24f5234eb8b 100644 --- a/src/core/src/runtime/itensor.cpp +++ b/src/core/src/runtime/itensor.cpp @@ -68,8 +68,7 @@ void ITensor::copy_to(const std::shared_ptr& dst) const { dst->set_shape(shape); } - if (std::dynamic_pointer_cast(dst)) { - auto remote_tensor_dst = std::dynamic_pointer_cast(dst); + if (auto remote_tensor_dst = std::dynamic_pointer_cast(dst)) { remote_tensor_dst->copy_from(shared_from_this()); return; } diff --git a/src/core/tests/copy.cpp b/src/core/tests/copy.cpp index 106cb20fdfbfb0..a720b0f0410060 100644 --- a/src/core/tests/copy.cpp +++ b/src/core/tests/copy.cpp @@ -422,7 +422,7 @@ TEST(copy, loop) { OutputVector new_args = {trip_count, exec_condition, X_new, Y_new, M_new}; auto loop_copy = loop->clone_with_new_inputs(new_args); - auto node_cast = std::dynamic_pointer_cast(loop_copy); + auto node_cast = ov::as_type_ptr(loop_copy); ASSERT_NE(node_cast, nullptr); ASSERT_TRUE(nullptr != loop_copy); EXPECT_EQ(loop->get_num_iterations(), node_cast->get_num_iterations()); diff --git a/src/core/tests/graph_rewrite.cpp b/src/core/tests/graph_rewrite.cpp index c47b6d5a473666..8c7461bef2f0b7 100644 --- a/src/core/tests/graph_rewrite.cpp +++ b/src/core/tests/graph_rewrite.cpp @@ -71,7 +71,7 @@ inline std::shared_ptr get_model() { inline ov::pass::param_callback get_callback() { return [](const std::shared_ptr& node) -> bool { - if (std::dynamic_pointer_cast(node)) { + if (ov::as_type_ptr(node)) { return true; } else { return false; diff --git a/src/core/tests/pass/constant_folding.cpp b/src/core/tests/pass/constant_folding.cpp index 84fc18794da452..f42ed11175e6c3 100644 --- a/src/core/tests/pass/constant_folding.cpp +++ b/src/core/tests/pass/constant_folding.cpp @@ -2584,8 +2584,8 @@ TEST(constant_folding, const_reshape_no_data_copy) { run_constant_folding(f); - auto const1 = std::dynamic_pointer_cast(consumer1->input_value(0).get_node_shared_ptr()); - auto const2 = std::dynamic_pointer_cast(consumer2->input_value(0).get_node_shared_ptr()); + auto const1 = ov::as_type_ptr(consumer1->input_value(0).get_node_shared_ptr()); + auto const2 = ov::as_type_ptr(consumer2->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(const1); ASSERT_TRUE(const2); @@ -2604,8 +2604,8 @@ TEST(constant_folding, const_squeeze_no_data_copy) { run_constant_folding(f); - auto const1 = std::dynamic_pointer_cast(consumer1->input_value(0).get_node_shared_ptr()); - auto const2 = std::dynamic_pointer_cast(consumer2->input_value(0).get_node_shared_ptr()); + auto const1 = ov::as_type_ptr(consumer1->input_value(0).get_node_shared_ptr()); + auto const2 = ov::as_type_ptr(consumer2->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(const1); ASSERT_TRUE(const2); @@ -2624,8 +2624,8 @@ TEST(constant_folding, const_unsqueeze_no_data_copy) { run_constant_folding(f); - auto const1 = std::dynamic_pointer_cast(consumer1->input_value(0).get_node_shared_ptr()); - auto const2 = std::dynamic_pointer_cast(consumer2->input_value(0).get_node_shared_ptr()); + auto const1 = ov::as_type_ptr(consumer1->input_value(0).get_node_shared_ptr()); + auto const2 = ov::as_type_ptr(consumer2->input_value(0).get_node_shared_ptr()); ASSERT_TRUE(const1); ASSERT_TRUE(const2); @@ -3914,7 +3914,7 @@ TEST(constant_folding, gather_with_dynamic_shapes_in_data_input) { ASSERT_EQ(count_ops_of_type(model), 0); ASSERT_EQ(count_ops_of_type(model), 1); - auto new_const = dynamic_pointer_cast(strided_slice->input_value(1).get_node_shared_ptr()); + auto new_const = ov::as_type_ptr(strided_slice->input_value(1).get_node_shared_ptr()); EXPECT_NE(new_const, nullptr); check_names(new_const, {"shape_of", "indices", "axis", "test"}); @@ -3943,9 +3943,9 @@ TEST(constant_folding, sq_diff) { ops = model->get_ordered_ops(); // constant + result ASSERT_EQ(ops.size(), 2); - auto const_node = std::dynamic_pointer_cast(ops.front()); + auto const_node = ov::as_type_ptr(ops.front()); ASSERT_NE(const_node, nullptr); - auto res_node = std::dynamic_pointer_cast(ops.back()); + auto res_node = ov::as_type_ptr(ops.back()); ASSERT_NE(res_node, nullptr); } diff --git a/src/core/tests/pass/serialization/from_model.cpp b/src/core/tests/pass/serialization/from_model.cpp index cbb3e617e75d24..b1c3f0bad6212c 100644 --- a/src/core/tests/pass/serialization/from_model.cpp +++ b/src/core/tests/pass/serialization/from_model.cpp @@ -191,7 +191,7 @@ TEST_P(SerializationFromModelTest_large, DISABLED_Model_very_large) { auto actual = ov::test::readModel(m_out_xml_path, m_out_bin_path); bool found = false; for (const auto& op : actual->get_ordered_ops()) { - if (auto const1 = std::dynamic_pointer_cast(op)) { + if (auto const1 = ov::as_type_ptr(op)) { auto ptr = const1->get_data_ptr(); for (size_t i = 0; i < s; i++) { EXPECT_EQ(ptr[i], uint8_t(i + 42)) << "Index " << i << " has value " << static_cast(ptr[i]); diff --git a/src/core/tests/pass_config.cpp b/src/core/tests/pass_config.cpp index 56d9b2fedf8197..900b565c3f4bf9 100644 --- a/src/core/tests/pass_config.cpp +++ b/src/core/tests/pass_config.cpp @@ -265,11 +265,11 @@ class TestNestedMatcher : public ov::pass::MatcherPass { ov::matcher_pass_callback callback = [this](pattern::Matcher& m) { auto root = m.get_match_root(); auto pass_config = this->get_pass_config(); - if (std::dynamic_pointer_cast(root) && !pass_config->is_disabled()) { + if (ov::as_type_ptr(root) && !pass_config->is_disabled()) { auto pass = std::make_shared(); pass->set_pass_config(pass_config); pass->apply(root); - } else if (std::dynamic_pointer_cast(root) && !pass_config->is_disabled()) { + } else if (ov::as_type_ptr(root) && !pass_config->is_disabled()) { auto pass = std::make_shared(); pass->set_pass_config(pass_config); pass->apply(root); diff --git a/src/core/tests/preprocess.cpp b/src/core/tests/preprocess.cpp index 86b8dad63ba01e..ace5d92ba1428f 100644 --- a/src/core/tests/preprocess.cpp +++ b/src/core/tests/preprocess.cpp @@ -1547,7 +1547,7 @@ TEST(pre_post_process, postprocess_convert_element_type_explicit) { EXPECT_EQ(f->output().get_tensor().get_names(), old_names); auto ops = f->get_ordered_ops(); auto res_count = std::count_if(ops.begin(), ops.end(), [](const std::shared_ptr& n) { - return std::dynamic_pointer_cast(n) != nullptr; + return ov::as_type_ptr(n) != nullptr; }); EXPECT_EQ(res_count, 1); auto names_count = std::count_if(ops.begin(), ops.end(), [](std::shared_ptr n) { @@ -1575,7 +1575,7 @@ TEST(pre_post_process, trivial_model_convert_element_type_explicit) { EXPECT_THAT(f->output().get_tensor().get_names(), old_names); const auto ops = f->get_ordered_ops(); const auto res_count = std::count_if(ops.begin(), ops.end(), [](const std::shared_ptr& n) { - return std::dynamic_pointer_cast(n) != nullptr; + return ov::as_type_ptr(n) != nullptr; }); EXPECT_EQ(res_count, 1); const auto names_count = std::count_if(ops.begin(), ops.end(), [](std::shared_ptr n) { diff --git a/src/core/tests/type_prop/if.cpp b/src/core/tests/type_prop/if.cpp index d893b34472ad2b..35ae641bed5dc9 100644 --- a/src/core/tests/type_prop/if.cpp +++ b/src/core/tests/type_prop/if.cpp @@ -118,7 +118,7 @@ TEST(type_prop, if_clone_test) { if_op->set_input(X, Xt, Xe); if_op->set_input(Y, Yt, Ye); auto res = if_op->set_output(then_body_res, else_body_res); - auto new_if = std::dynamic_pointer_cast(if_op->clone_with_new_inputs(OutputVector{cond, Xnew, Ynew})); + auto new_if = ov::as_type_ptr(if_op->clone_with_new_inputs(OutputVector{cond, Xnew, Ynew})); EXPECT_EQ(true, true); } diff --git a/src/inference/src/check_network_batchable.cpp b/src/inference/src/check_network_batchable.cpp index 9a6c3f6aff6694..e1f7128c12077a 100644 --- a/src/inference/src/check_network_batchable.cpp +++ b/src/inference/src/check_network_batchable.cpp @@ -19,7 +19,7 @@ bool model_has_suitable_do(const std::shared_ptr& model) { convert_node = do_node; do_node = convert_node->get_input_node_shared_ptr(0); } - auto detectionOutputBase = std::dynamic_pointer_cast(do_node); + auto detectionOutputBase = ov::as_type_ptr(do_node); if (detectionOutputBase) { bDetectionOutput = true; } @@ -83,7 +83,7 @@ std::shared_ptr apply_batch_affinity(const std::shared_ptr(do_node); + auto detectionOutputBase = ov::as_type_ptr(do_node); if (detectionOutputBase) { result_node->get_rt_info()["affinity"] = deviceNameWithoutBatch; do_node->get_rt_info()["affinity"] = deviceNameWithoutBatch; diff --git a/src/inference/src/dev/icompiled_model.cpp b/src/inference/src/dev/icompiled_model.cpp index 230ddd209c0df5..b1d7550515da21 100644 --- a/src/inference/src/dev/icompiled_model.cpp +++ b/src/inference/src/dev/icompiled_model.cpp @@ -101,7 +101,7 @@ ov::ICompiledModel::ICompiledModel(const std::shared_ptr& model result->output(0).get_tensor().add_names({res_name}); new_result->output(0).get_tensor().add_names({res_name}); } - auto r = std::dynamic_pointer_cast(new_result); + auto r = ov::as_type_ptr(new_result); r->set_layout(result->get_layout()); new_result->output(0).get_rt_info() = result->output(0).get_rt_info(); auto old_tensor = result->output(0).get_tensor_ptr(); diff --git a/src/inference/tests/functional/local_test.cpp b/src/inference/tests/functional/local_test.cpp index dafd87dc457370..276228fa1330e2 100644 --- a/src/inference/tests/functional/local_test.cpp +++ b/src/inference/tests/functional/local_test.cpp @@ -235,7 +235,7 @@ class LocaleTests : public ::testing::Test { for (const auto& op : model->get_ops()) { if (!isLSTM) { if (op->get_friendly_name() == "output") { - const auto roi = std::dynamic_pointer_cast(op); + const auto roi = ov::as_type_ptr(op); ASSERT_TRUE(roi); ASSERT_EQ(roi->get_pooled_h(), 7); ASSERT_EQ(roi->get_pooled_w(), 7); @@ -244,7 +244,7 @@ class LocaleTests : public ::testing::Test { } } else { if (op->get_friendly_name() == "LSTMCell") { - const auto lstm_seq = std::dynamic_pointer_cast(op); + const auto lstm_seq = ov::as_type_ptr(op); ASSERT_TRUE(lstm_seq); ASSERT_EQ(lstm_seq->get_clip(), 0.0f); ASSERT_EQ(lstm_seq->get_hidden_size(), 256); @@ -349,4 +349,4 @@ TEST_F(LocaleTestsWithCacheDir, WithUSLocale) { setlocale(LC_ALL, "en_US.UTF-8"); testBody(); } -#endif // defined(ENABLE_OV_IR_FRONTEND) \ No newline at end of file +#endif // defined(ENABLE_OV_IR_FRONTEND) From 6a1ecea61e11371400fde631fea4caefe4ab64bb Mon Sep 17 00:00:00 2001 From: Tomasz Jankowski Date: Fri, 10 Jan 2025 13:22:26 +0100 Subject: [PATCH 2/5] Replace std dynamic casts with ov defined std::dynamic_pointer_cast -> ov::as_type_ptr std::dynamic_cast -> ov::as_type Signed-off-by: Tomasz Jankowski --- src/common/snippets/src/lowered/pass/pass.cpp | 6 +++--- .../transformations/control_flow/unroll_tensor_iterator.cpp | 2 +- .../op_conversions/convert_ti_to_sequences.cpp | 2 +- src/core/include/openvino/core/any.hpp | 2 +- src/core/src/pass/serialize.cpp | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/common/snippets/src/lowered/pass/pass.cpp b/src/common/snippets/src/lowered/pass/pass.cpp index 235d248d8e9838..d7477f8e495240 100644 --- a/src/common/snippets/src/lowered/pass/pass.cpp +++ b/src/common/snippets/src/lowered/pass/pass.cpp @@ -35,7 +35,7 @@ void PassPipeline::run(const lowered::LinearIR& linear_ir) const { if (m_pass_config->is_disabled(pass->get_type_info())) { continue; } - const auto const_pass = std::dynamic_pointer_cast(pass); + const auto const_pass = ov::as_type_ptr(pass); OPENVINO_ASSERT(const_pass != nullptr, "Unexpected pass (", pass->get_type_info(), @@ -58,9 +58,9 @@ void PassPipeline::run(LinearIR& linear_ir, LinearIR::constExprIt begin, LinearI } if (auto lir_pass = std::dynamic_pointer_cast(pass)) { lir_pass->run(linear_ir); - } else if (auto const_pass = std::dynamic_pointer_cast(pass)) { + } else if (auto const_pass = ov::as_type_ptr(pass)) { const_pass->run(linear_ir); - } else if (auto ranged_pass = std::dynamic_pointer_cast(pass)) { + } else if (auto ranged_pass = ov::as_type_ptr(pass)) { ranged_pass->run(linear_ir, begin, end); } else { OPENVINO_THROW("Unexpected pass (", pass->get_type_info(), ") is registered in PassPipeline"); 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 e11a45c963772f..d046e2cb421f18 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 @@ -115,7 +115,7 @@ bool ov::pass::UnrollTensorIterator::run_on_model(const std::shared_ptrget_output_descriptions()) { if (const auto& concat_desc = - std::dynamic_pointer_cast(desc)) { + ov::as_type_ptr(desc)) { if (!concat_desc) { return false; } 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 cb0c7cd5ee966f..e7ca6ec863f219 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 @@ -98,7 +98,7 @@ bool convertTensorIteratorToSequence(const 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); + ov::as_type_ptr(output_desc); if (!concat_output) return false; diff --git a/src/core/include/openvino/core/any.hpp b/src/core/include/openvino/core/any.hpp index e002756d361f1f..37735e4dd25ab2 100644 --- a/src/core/include/openvino/core/any.hpp +++ b/src/core/include/openvino/core/any.hpp @@ -739,7 +739,7 @@ class OPENVINO_API Any { OPENVINO_THROW("Any does not contains pointer to runtime_attribute. It contains ", _impl->type_info().name()); } - auto vptr = std::dynamic_pointer_cast(runtime_attribute); + auto vptr = ov::as_type_ptr(runtime_attribute); if (vptr == nullptr && T::element_type::get_type_info_static() != runtime_attribute->get_type_info() && T::element_type::get_type_info_static() != RuntimeAttribute::get_type_info_static()) { OPENVINO_THROW("Could not as Any runtime_attribute to ", diff --git a/src/core/src/pass/serialize.cpp b/src/core/src/pass/serialize.cpp index f179630b155d22..a9845c07d66323 100644 --- a/src/core/src/pass/serialize.cpp +++ b/src/core/src/pass/serialize.cpp @@ -842,7 +842,7 @@ class PaddingsFixer { std::make_shared(input.get_element_type(), input.get_partial_shape())); } m_cloned_node = op->clone_with_new_inputs(m_parameters); - auto typed_cloned_node = std::dynamic_pointer_cast(m_cloned_node); + auto typed_cloned_node = ov::as_type_ptr(m_cloned_node); OPENVINO_ASSERT(typed_cloned_node); typed_cloned_node->set_pads_begin(P(op->get_pads_begin().size(), 0)); typed_cloned_node->set_pads_end(P(op->get_pads_end().size(), 0)); From 988ff76da8611df230b570797415223005cd0f5f Mon Sep 17 00:00:00 2001 From: Tomasz Jankowski Date: Fri, 10 Jan 2025 15:22:24 +0100 Subject: [PATCH 3/5] Replace std dynamic casts with ov defined std::dynamic_pointer_cast -> ov::as_type_ptr std::dynamic_cast -> ov::as_type Signed-off-by: Tomasz Jankowski --- src/common/snippets/src/generator.cpp | 32 +++++++++---------- .../pass/fake_quantize_decomposition_test.cpp | 6 ++-- .../common_optimizations/sequence_fusion.cpp | 4 +-- .../convert_fc_to_compressed.cpp | 2 +- .../convert_fc_to_quantized_legacy.cpp | 2 +- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/common/snippets/src/generator.cpp b/src/common/snippets/src/generator.cpp index c04d1b4b13dd8e..972ebf2852bfdf 100644 --- a/src/common/snippets/src/generator.cpp +++ b/src/common/snippets/src/generator.cpp @@ -71,22 +71,22 @@ RegType Generator::get_op_out_reg_type(const ov::Output& out) const { const auto op = out.get_node_shared_ptr(); if (ov::as_type_ptr(op) || ov::as_type_ptr(op) || - std::dynamic_pointer_cast(op) || - std::dynamic_pointer_cast(op) || - std::dynamic_pointer_cast(op) || - std::dynamic_pointer_cast(op) || - std::dynamic_pointer_cast(op) || + ov::as_type_ptr(op) || + ov::as_type_ptr(op) || + ov::as_type_ptr(op) || + ov::as_type_ptr(op) || + ov::as_type_ptr(op) || ov::as_type_ptr(op) || - std::dynamic_pointer_cast(op) || - std::dynamic_pointer_cast(op) + ov::as_type_ptr(op) || + ov::as_type_ptr(op) #ifdef SNIPPETS_DEBUG_CAPS - || std::dynamic_pointer_cast(op) - || std::dynamic_pointer_cast(op) + || ov::as_type_ptr(op) + || ov::as_type_ptr(op) #endif ) return RegType::gpr; - else if (std::dynamic_pointer_cast(op) || - std::dynamic_pointer_cast(op) || + else if (ov::as_type_ptr(op) || + ov::as_type_ptr(op) || ov::op::util::is_unary_elementwise_arithmetic(op) || ov::op::util::is_binary_elementwise_arithmetic(op) || ov::op::util::is_binary_elementwise_comparison(op) || @@ -95,12 +95,12 @@ RegType Generator::get_op_out_reg_type(const ov::Output& out) const { ov::as_type_ptr(op) || ov::as_type_ptr(op) || ov::as_type_ptr(op) || - std::dynamic_pointer_cast(op) || - std::dynamic_pointer_cast(op) || + ov::as_type_ptr(op) || + ov::as_type_ptr(op) || ov::as_type_ptr(op) || - std::dynamic_pointer_cast(op) || - std::dynamic_pointer_cast(op) || - std::dynamic_pointer_cast(op)) + ov::as_type_ptr(op) || + ov::as_type_ptr(op) || + ov::as_type_ptr(op)) return RegType::vec; else OPENVINO_THROW("Register type of the operation " + std::string(op->get_type_name()) + " isn't determined!"); diff --git a/src/common/snippets/tests/src/pass/fake_quantize_decomposition_test.cpp b/src/common/snippets/tests/src/pass/fake_quantize_decomposition_test.cpp index 0a428665360048..9bb07573f6c60d 100644 --- a/src/common/snippets/tests/src/pass/fake_quantize_decomposition_test.cpp +++ b/src/common/snippets/tests/src/pass/fake_quantize_decomposition_test.cpp @@ -26,10 +26,10 @@ class FakeQuantizeDecompositionTest : public TransformationTestsF { TransformationTestsF::TearDown(); auto subgraph = FunctionHelper::getSubgraph(model); - auto body = subgraph == nullptr ? nullptr : std::dynamic_pointer_cast(subgraph)->body_ptr(); + auto body = subgraph == nullptr ? nullptr : ov::as_type_ptr(subgraph)->body_ptr(); auto subgraph_ref = FunctionHelper::getSubgraph(model_ref); - auto body_ref = subgraph_ref == nullptr ? nullptr : std::dynamic_pointer_cast(subgraph_ref)->body_ptr(); + auto body_ref = subgraph_ref == nullptr ? nullptr : ov::as_type_ptr(subgraph_ref)->body_ptr(); auto res = comparator.compare(body, body_ref); ASSERT_TRUE(res.valid) << res.message; @@ -48,4 +48,4 @@ TEST_F(FakeQuantizeDecompositionTest, smoke_Snippets_PerTensorFakeQuantizeDecomp } // namespace snippets } // namespace test -} // namespace ov \ No newline at end of file +} // namespace ov diff --git a/src/common/transformations/src/transformations/common_optimizations/sequence_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/sequence_fusion.cpp index 553d3c192f95b3..72873bd1c236ff 100644 --- a/src/common/transformations/src/transformations/common_optimizations/sequence_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/sequence_fusion.cpp @@ -132,7 +132,7 @@ shared_ptr find_cell_chain(ov::pass::NodeRegistry& cp_from, x_to_concat.push_back(cp_to.make(in_X.get_source_output(), axis_1)); h_outputs_to_redirect[cells_cnt] = current->output(0); - if (auto augru = dynamic_pointer_cast(current)) { + if (auto augru = ov::as_type_ptr(current)) { attention_to_concat.push_back(cp_to.make(augru->input_value(5), axis_1)); } @@ -254,7 +254,7 @@ bool create_sequence(ov::pass::NodeRegistry& cp_to, first_cell->get_activations_alpha(), first_cell->get_activations_beta(), first_cell->get_clip()); - } else if (dynamic_pointer_cast(first_cell)) { + } else if (ov::as_type_ptr(first_cell)) { const auto A_in = cp_to.make(attention_to_concat, 1); sequence = cp_to.make(X_in, Ht_in, diff --git a/src/common/transformations/src/transformations/op_conversions/convert_fc_to_compressed.cpp b/src/common/transformations/src/transformations/op_conversions/convert_fc_to_compressed.cpp index 45611b4c52cdd0..49fa4045c45f9e 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_fc_to_compressed.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_fc_to_compressed.cpp @@ -71,7 +71,7 @@ ov::pass::ConvertFullyConnectedToFullyConnectedCompressed::ConvertFullyConnected OPENVINO_ASSERT(pattern_map.count(weights_m)); OPENVINO_ASSERT(pattern_map.count(bias_m)); OPENVINO_ASSERT(pattern_map.count(convert_m)); - auto fc = std::dynamic_pointer_cast( + auto fc = ov::as_type_ptr( pattern_map.at(fully_connected_m).get_node_shared_ptr()); if (!fc || transformation_callback(fc)) { return false; diff --git a/src/common/transformations/src/transformations/op_conversions/convert_fc_to_quantized_legacy.cpp b/src/common/transformations/src/transformations/op_conversions/convert_fc_to_quantized_legacy.cpp index a0c16e24f04bad..806365d835f96f 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_fc_to_quantized_legacy.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_fc_to_quantized_legacy.cpp @@ -48,7 +48,7 @@ ov::pass::ConvertFCToFCQuantizedLegacy::ConvertFCToFCQuantizedLegacy() { return false; } - auto fc_node = std::dynamic_pointer_cast( + auto fc_node = ov::as_type_ptr( pattern_map.at(fully_connected_m).get_node_shared_ptr()); ov::NodeVector new_ops; From cbca154cbcda7fae88c615bd50609811e629cc9e Mon Sep 17 00:00:00 2001 From: Tomasz Jankowski Date: Sun, 12 Jan 2025 16:26:30 +0100 Subject: [PATCH 4/5] Replace std dynamic casts with ov defined Signed-off-by: Tomasz Jankowski --- src/common/snippets/src/lowered/pass/pass.cpp | 2 +- .../op_conversions/convert_reduce_to_pooling.hpp | 2 +- .../include/transformations/utils/utils.hpp | 2 +- .../control_flow/unroll_tensor_iterator.cpp | 3 +-- .../src/transformations/convert_precision.cpp | 8 ++++---- .../op_conversions/convert_fc_to_compressed.cpp | 4 ++-- .../op_conversions/convert_fc_to_quantized_legacy.cpp | 4 ++-- .../op_conversions/convert_ti_to_sequences.cpp | 3 +-- 8 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/common/snippets/src/lowered/pass/pass.cpp b/src/common/snippets/src/lowered/pass/pass.cpp index d7477f8e495240..3ea83d43b5be15 100644 --- a/src/common/snippets/src/lowered/pass/pass.cpp +++ b/src/common/snippets/src/lowered/pass/pass.cpp @@ -56,7 +56,7 @@ void PassPipeline::run(LinearIR& linear_ir, LinearIR::constExprIt begin, LinearI if (m_pass_config->is_disabled(pass->get_type_info())) { continue; } - if (auto lir_pass = std::dynamic_pointer_cast(pass)) { + if (auto lir_pass = ov::as_type_ptr(pass)) { lir_pass->run(linear_ir); } else if (auto const_pass = ov::as_type_ptr(pass)) { const_pass->run(linear_ir); 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 c7172fc87e50ac..02cd3cb4f56676 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 @@ -72,7 +72,7 @@ class ov::pass::ConvertReduceToPooling : public ov::pass::GraphRewrite { template ov::matcher_pass_callback ConvertReduceBase::convert_reduce_to_pooling() { return [&](ov::pass::pattern::Matcher& m) { - auto reduce = std::dynamic_pointer_cast(m.get_match_root()); + auto reduce = ov::as_type_ptr(m.get_match_root()); if (!reduce || transformation_callback(reduce) || ov::shape_size(reduce->input_value(0).get_shape()) == 0) { return false; diff --git a/src/common/transformations/include/transformations/utils/utils.hpp b/src/common/transformations/include/transformations/utils/utils.hpp index d591e581bca3d1..c15041c02537f3 100644 --- a/src/common/transformations/include/transformations/utils/utils.hpp +++ b/src/common/transformations/include/transformations/utils/utils.hpp @@ -45,7 +45,7 @@ bool normalize_single_value(std::vector vec, float& value, bool check_value_r template bool has_op_with_type(const std::shared_ptr& function) { for (const auto& op : function->get_ops()) { - if (std::dynamic_pointer_cast(op)) { + if (ov::as_type_ptr(op)) { return true; } } 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 d046e2cb421f18..489d40af796c51 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 @@ -114,8 +114,7 @@ bool ov::pass::UnrollTensorIterator::run_on_model(const std::shared_ptrget_output_descriptions()) { - if (const auto& concat_desc = - ov::as_type_ptr(desc)) { + if (const auto& concat_desc = ov::as_type_ptr(desc)) { if (!concat_desc) { return false; } diff --git a/src/common/transformations/src/transformations/convert_precision.cpp b/src/common/transformations/src/transformations/convert_precision.cpp index 4562c2e15620a2..dfac520be82da4 100644 --- a/src/common/transformations/src/transformations/convert_precision.cpp +++ b/src/common/transformations/src/transformations/convert_precision.cpp @@ -79,7 +79,7 @@ bool fuse_type_to_binary_comparision(const std::shared_ptr& node, cons if (auto type_relaxed = std::dynamic_pointer_cast(node)) { type_relaxed->set_overridden_output_type(to); return true; - } else if (auto casted = std::dynamic_pointer_cast(node)) { + } else if (auto casted = ov::as_type_ptr(node)) { auto relaxed_op = std::make_shared>(*casted, ov::element::TypeVector{}, ov::element::TypeVector{to}); replace_node(node, relaxed_op); @@ -99,7 +99,7 @@ bool fuse_type_to_logical(const std::shared_ptr& node, const precision for (size_t i = 0; i < node->get_input_size(); ++i) type_relaxed->set_origin_input_type(ov::element::boolean, i); return true; - } else if (auto casted = std::dynamic_pointer_cast(node)) { + } else if (auto casted = ov::as_type_ptr(node)) { ov::element::TypeVector input_types(node->get_input_size(), ov::element::boolean); auto relaxed_op = std::make_shared>(*casted, input_types, ov::element::TypeVector{to}); replace_node(node, relaxed_op); @@ -118,7 +118,7 @@ bool fuse_type_to_reduce_logical(const std::shared_ptr& node, const pr type_relaxed->set_overridden_output_type(to); type_relaxed->set_origin_input_type(ov::element::boolean, 0); return true; - } else if (auto casted = std::dynamic_pointer_cast(node)) { + } else if (auto casted = ov::as_type_ptr(node)) { auto relaxed_op = std::make_shared>(*casted, ov::element::TypeVector{ov::element::boolean}, ov::element::TypeVector{to}); @@ -139,7 +139,7 @@ bool fuse_type_to_prior_box(const std::shared_ptr& node, const precisi if (auto type_relaxed = std::dynamic_pointer_cast(node)) { type_relaxed->set_overridden_output_type(to); return true; - } else if (const auto casted = std::dynamic_pointer_cast(node)) { + } else if (const auto casted = ov::as_type_ptr(node)) { auto relaxed_op = std::make_shared>( *casted, ov::element::TypeVector{casted->get_input_element_type(0), casted->get_input_element_type(1)}, diff --git a/src/common/transformations/src/transformations/op_conversions/convert_fc_to_compressed.cpp b/src/common/transformations/src/transformations/op_conversions/convert_fc_to_compressed.cpp index 49fa4045c45f9e..91e1f3bfebc2f8 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_fc_to_compressed.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_fc_to_compressed.cpp @@ -71,8 +71,8 @@ ov::pass::ConvertFullyConnectedToFullyConnectedCompressed::ConvertFullyConnected OPENVINO_ASSERT(pattern_map.count(weights_m)); OPENVINO_ASSERT(pattern_map.count(bias_m)); OPENVINO_ASSERT(pattern_map.count(convert_m)); - auto fc = ov::as_type_ptr( - pattern_map.at(fully_connected_m).get_node_shared_ptr()); + auto fc = + ov::as_type_ptr(pattern_map.at(fully_connected_m).get_node_shared_ptr()); if (!fc || transformation_callback(fc)) { return false; } diff --git a/src/common/transformations/src/transformations/op_conversions/convert_fc_to_quantized_legacy.cpp b/src/common/transformations/src/transformations/op_conversions/convert_fc_to_quantized_legacy.cpp index 806365d835f96f..902aecffb4bf52 100644 --- a/src/common/transformations/src/transformations/op_conversions/convert_fc_to_quantized_legacy.cpp +++ b/src/common/transformations/src/transformations/op_conversions/convert_fc_to_quantized_legacy.cpp @@ -48,8 +48,8 @@ ov::pass::ConvertFCToFCQuantizedLegacy::ConvertFCToFCQuantizedLegacy() { return false; } - auto fc_node = ov::as_type_ptr( - pattern_map.at(fully_connected_m).get_node_shared_ptr()); + auto fc_node = + ov::as_type_ptr(pattern_map.at(fully_connected_m).get_node_shared_ptr()); ov::NodeVector new_ops; auto zp = std::make_shared(element::undefined, Shape{0}); 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 e7ca6ec863f219..77973b497340f2 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 @@ -97,8 +97,7 @@ bool convertTensorIteratorToSequence(const std::shared_ptrget_output_descriptions()) { std::shared_ptr res = results[output_desc->m_body_value_index]; if (res->input_value(0) == unsqueeze_after_cell) { - auto concat_output = - ov::as_type_ptr(output_desc); + auto concat_output = ov::as_type_ptr(output_desc); if (!concat_output) return false; From 07389086afd392f00299f2f2b6cab5d5272dd20a Mon Sep 17 00:00:00 2001 From: Tomasz Jankowski Date: Sun, 12 Jan 2025 21:32:31 +0100 Subject: [PATCH 5/5] Replace std dynamic casts with ov defined Signed-off-by: Tomasz Jankowski --- .../common_optimizations/sequence_fusion.cpp | 2 +- src/core/src/layout.cpp | 2 +- src/core/src/op/util/op_types.cpp | 48 +++++++++---------- src/core/src/pass/low_latency.cpp | 2 +- src/core/src/pass/serialize.cpp | 2 +- src/core/src/preprocess/preprocess_impls.cpp | 2 +- src/core/tests/threading.cpp | 2 +- 7 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/common/transformations/src/transformations/common_optimizations/sequence_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/sequence_fusion.cpp index 72873bd1c236ff..d4a00eeee4e2ed 100644 --- a/src/common/transformations/src/transformations/common_optimizations/sequence_fusion.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/sequence_fusion.cpp @@ -102,7 +102,7 @@ bool check_lstm_cell(const shared_ptr& prev_cell, const shared_ptr< const auto& target_inputs = prev_cell->get_output_target_inputs(1); bool valid = target_inputs.empty() || (target_inputs.size() == 1 && - dynamic_cast(target_inputs.begin()->get_node()) == current_cell.get() && + ov::as_type(target_inputs.begin()->get_node()) == current_cell.get() && target_inputs.begin()->get_index() == 2); // if intermediate C output is connected to other node, except ov::op::v4::LSTMCell, diff --git a/src/core/src/layout.cpp b/src/core/src/layout.cpp index 7c3c29909088fd..ced594f749c5b3 100644 --- a/src/core/src/layout.cpp +++ b/src/core/src/layout.cpp @@ -604,7 +604,7 @@ ov::Layout get_layout(const ov::Output& output) { void set_layout(ov::Output output, const ov::Layout& layout) { OPENVINO_ASSERT( - dynamic_cast(output.get_node()) || dynamic_cast(output.get_node()), + ov::as_type(output.get_node()) || ov::as_type(output.get_node()), "Layout can be set only for Parameter and Result operations."); if (layout.empty()) { output.get_rt_info().erase(ov::LayoutAttribute::get_type_info_static()); diff --git a/src/core/src/op/util/op_types.cpp b/src/core/src/op/util/op_types.cpp index 053051535aef21..b930f198e391ef 100644 --- a/src/core/src/op/util/op_types.cpp +++ b/src/core/src/op/util/op_types.cpp @@ -26,60 +26,60 @@ #include "openvino/op/xor.hpp" bool ov::op::util::is_unary_elementwise_arithmetic(const ov::Node* node) { - return dynamic_cast(node) != nullptr; + return ov::as_type(node) != nullptr; } bool ov::op::util::is_binary_elementwise_arithmetic(const ov::Node* node) { - return dynamic_cast(node) != nullptr; + return ov::as_type(node) != nullptr; } bool ov::op::util::is_binary_elementwise_comparison(const ov::Node* node) { - return dynamic_cast(node) != nullptr; + return ov::as_type(node) != nullptr; } bool ov::op::util::is_binary_elementwise_logical(const ov::Node* node) { - return dynamic_cast(node) != nullptr; + return ov::as_type(node) != nullptr; } bool ov::op::util::supports_auto_broadcast(const ov::Node* node) { - return dynamic_cast(node) != nullptr || - dynamic_cast(node) != nullptr || - dynamic_cast(node) != nullptr || - dynamic_cast(node) != nullptr || - dynamic_cast(node) != nullptr; + return ov::as_type(node) != nullptr || + ov::as_type(node) != nullptr || + ov::as_type(node) != nullptr || + ov::as_type(node) != nullptr || + ov::as_type(node) != nullptr; } bool ov::op::util::is_op(const ov::Node* node) { - return dynamic_cast(node) != nullptr; + return ov::as_type(node) != nullptr; } bool ov::op::util::is_parameter(const ov::Node* node) { - return dynamic_cast(node) != nullptr; + return ov::as_type(node) != nullptr; } bool ov::op::util::is_output(const ov::Node* node) { - return dynamic_cast(node) != nullptr; + return ov::as_type(node) != nullptr; } bool ov::op::util::is_sink(const ov::Node* node) { - return dynamic_cast(node) != nullptr; + return ov::as_type(node) != nullptr; } bool ov::op::util::is_constant(const ov::Node* node) { - return dynamic_cast(node) != nullptr; + return ov::as_type(node) != nullptr; } bool ov::op::util::is_commutative(const ov::Node* node) { - return dynamic_cast(node) != nullptr || - dynamic_cast(node) != nullptr || - dynamic_cast(node) != nullptr || - dynamic_cast(node) != nullptr || - dynamic_cast(node) != nullptr || - dynamic_cast(node) != nullptr || - dynamic_cast(node) != nullptr || - dynamic_cast(node) != nullptr || - dynamic_cast(node) != nullptr || - dynamic_cast(node) != nullptr; + return ov::as_type(node) != nullptr || + ov::as_type(node) != nullptr || + ov::as_type(node) != nullptr || + ov::as_type(node) != nullptr || + ov::as_type(node) != nullptr || + ov::as_type(node) != nullptr || + ov::as_type(node) != nullptr || + ov::as_type(node) != nullptr || + ov::as_type(node) != nullptr || + ov::as_type(node) != nullptr; } bool ov::op::util::is_unary_elementwise_arithmetic(const std::shared_ptr& node) { diff --git a/src/core/src/pass/low_latency.cpp b/src/core/src/pass/low_latency.cpp index 5666c404361455..419e25ba26b5ae 100644 --- a/src/core/src/pass/low_latency.cpp +++ b/src/core/src/pass/low_latency.cpp @@ -266,7 +266,7 @@ bool ov::pass::LowLatency2::run_on_model(const std::shared_ptr& f) { const auto& param = sub_graph_op->get_function()->get_parameters().at(merged_in->m_body_parameter_index); for (const auto& in_to : param->output(0).get_target_inputs()) { - if (dynamic_cast(in_to.get_node()) != nullptr) { + if (ov::as_type(in_to.get_node()) != nullptr) { OPENVINO_DEBUG(msg_low_latency_already_applied); return false; } diff --git a/src/core/src/pass/serialize.cpp b/src/core/src/pass/serialize.cpp index a9845c07d66323..b9d62a142a956b 100644 --- a/src/core/src/pass/serialize.cpp +++ b/src/core/src/pass/serialize.cpp @@ -1045,7 +1045,7 @@ void ngfunction_2_ir(pugi::xml_node& netXml, pugi::xml_node input = layer.append_child("input"); for (auto& i : node->inputs()) { // WA for LSTMCellv0, peephole input shall not be serialized - if (i.get_index() == 6 && dynamic_cast(node)) { + if (i.get_index() == 6 && ov::as_type(node)) { port_id++; continue; } diff --git a/src/core/src/preprocess/preprocess_impls.cpp b/src/core/src/preprocess/preprocess_impls.cpp index d87d1fac69b8fa..aa0abd4901a21b 100644 --- a/src/core/src/preprocess/preprocess_impls.cpp +++ b/src/core/src/preprocess/preprocess_impls.cpp @@ -211,7 +211,7 @@ bool InputInfo::InputInfoImpl::build(const std::shared_ptr& model, // Replace parameter for (auto consumer : consumers) { - if (dynamic_cast(consumer.get_node())) { + if (ov::as_type(consumer.get_node())) { // Some result points to old parameter (Param->Result case), need to trigger revalidation need_validate = true; } diff --git a/src/core/tests/threading.cpp b/src/core/tests/threading.cpp index 0b429a32a3a74d..6023ff75017a00 100644 --- a/src/core/tests/threading.cpp +++ b/src/core/tests/threading.cpp @@ -158,7 +158,7 @@ TEST(threading, clone_with_new_inputs) { const auto inSize = op->get_input_size(); for (size_t i = 0; i < inSize; i++) { - if (dynamic_cast(op->get_input_node_ptr(i))) { + if (ov::as_type(op->get_input_node_ptr(i))) { inputsForShapeInfer.push_back(op->get_input_node_ptr(i)->clone_with_new_inputs(ov::OutputVector{})); } else { inputsForShapeInfer.push_back(