diff --git a/.github/workflows/code_snippets.yml b/.github/workflows/code_snippets.yml index e4091556da1ac0..e9431dee1b44bf 100644 --- a/.github/workflows/code_snippets.yml +++ b/.github/workflows/code_snippets.yml @@ -44,4 +44,4 @@ jobs: id: cpu-cores - name: Build snippets - run: cmake --build build --target ie_docs_snippets --parallel ${{ steps.cpu-cores.outputs.count }} + run: cmake --build build --target openvino_docs_snippets --parallel ${{ steps.cpu-cores.outputs.count }} diff --git a/docs/snippets/CMakeLists.txt b/docs/snippets/CMakeLists.txt index 757d95b8771ded..89c39d706d33d2 100644 --- a/docs/snippets/CMakeLists.txt +++ b/docs/snippets/CMakeLists.txt @@ -1,8 +1,8 @@ -# Copyright (C) 2018-2020 Intel Corporation +# Copyright (C) 2018-2024 Intel Corporation # SPDX-License-Identifier: Apache-2.0 # -set(TARGET_NAME ie_docs_snippets) +set(TARGET_NAME openvino_docs_snippets) if(CMAKE_COMPILER_IS_GNUCXX) ov_add_compiler_flags(-Wall) @@ -50,6 +50,7 @@ list(REMOVE_ITEM SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/dldt_optimization_guide2.c add_library(${TARGET_NAME} STATIC ${SOURCES}) target_include_directories(${TARGET_NAME} PRIVATE "${OpenVINO_SOURCE_DIR}/src/inference/include" "${OpenVINO_SOURCE_DIR}/src/inference/dev_api" + "${OpenVINO_SOURCE_DIR}/src/core/dev_api" "${OpenVINO_SOURCE_DIR}/src/core/include" "${OpenVINO_SOURCE_DIR}/src/bindings/c/include" "${OpenVINO_SOURCE_DIR}/src/common/transformations/include" diff --git a/src/common/snippets/src/op/subgraph.cpp b/src/common/snippets/src/op/subgraph.cpp index 6524dcda3d9605..3b23da523d53ca 100644 --- a/src/common/snippets/src/op/subgraph.cpp +++ b/src/common/snippets/src/op/subgraph.cpp @@ -49,7 +49,7 @@ #include "snippets/pass/manager.hpp" #include "openvino/pass/constant_folding.hpp" #include "ov_ops/type_relaxed.hpp" -#include +#include "openvino/pass/serialize.hpp" #include #include diff --git a/src/common/transformations/include/ov_ops/type_relaxed.hpp b/src/common/transformations/include/ov_ops/type_relaxed.hpp index 5fdd9ba4bb87c4..62728f39c63c5d 100644 --- a/src/common/transformations/include/ov_ops/type_relaxed.hpp +++ b/src/common/transformations/include/ov_ops/type_relaxed.hpp @@ -80,48 +80,9 @@ class OPENVINO_API TypeRelaxedBase { } protected: - void remember_input_data_types(Node& node, element::TypeVector& old_input_types) { - // Remember all input data types - for (size_t i = 0; i < node.get_input_size(); ++i) { - old_input_types.push_back(node.get_input_element_type(i)); - } - - // Reset input data types to m_output_data_type. - for (size_t i = 0; i < node.get_input_size(); ++i) { - auto origin_input_type = get_origin_input_type(i); - if (origin_input_type != element::undefined) { - OPENVINO_SUPPRESS_DEPRECATED_START - node.get_input_tensor(i).set_tensor_type(origin_input_type, node.get_input_partial_shape(i)); - OPENVINO_SUPPRESS_DEPRECATED_END - } - } - } - - void restore_input_data_types(Node& node, const element::TypeVector& old_input_types) { - // Restore original input data types - for (size_t i = 0; i < node.get_input_size(); ++i) { - OPENVINO_SUPPRESS_DEPRECATED_START - node.get_input_tensor(i).set_tensor_type(old_input_types[i], node.get_input_partial_shape(i)); - OPENVINO_SUPPRESS_DEPRECATED_END - } - - if (m_original_output_data_types.empty()) { - m_original_output_data_types = element::TypeVector(node.get_output_size()); - } - - // Save inferred output types - for (size_t i = 0; i < node.get_output_size(); ++i) { - m_original_output_data_types[i] = node.get_output_element_type(i); - } + void remember_input_data_types(Node& node, element::TypeVector& old_input_types); - // Override (some) output types - for (size_t i = 0; i < node.get_output_size(); ++i) { - auto overridden_output_type = get_overridden_output_type(i); - if (overridden_output_type != element::undefined) { - node.set_output_type(i, overridden_output_type, node.get_output_partial_shape(i)); - } - } - } + void restore_input_data_types(Node& node, const element::TypeVector& old_input_types); void visit_attributes(AttributeVisitor& visitor) { bool type_relax = true; @@ -152,31 +113,19 @@ class OPENVINO_API TypeRelaxedBase { /// in case when inputs have types that are not compatible with BaseOp infer function. In this case /// before TypeRelaxed is constructed the BaseOp contructor requires modified data types. /// So it should be -class TemporaryReplaceOutputType { +class OPENVINO_API TemporaryReplaceOutputType { Output m_output; element::Type orig_type; public: /// Replace element type for a given output port by tmp_type - TemporaryReplaceOutputType(Output output, element::Type tmp_type) : m_output(output) { - // save original element type in order to restore it in the destructor - orig_type = m_output.get_element_type(); - OPENVINO_SUPPRESS_DEPRECATED_START - m_output.get_tensor().set_element_type(tmp_type); - OPENVINO_SUPPRESS_DEPRECATED_END - } + TemporaryReplaceOutputType(Output output, element::Type tmp_type); /// Return the output port that was used in the constructor - Output get() const { - return m_output; - } + Output get() const; /// Restores the original element type for the output - ~TemporaryReplaceOutputType() { - OPENVINO_SUPPRESS_DEPRECATED_START - m_output.get_tensor().set_element_type(orig_type); - OPENVINO_SUPPRESS_DEPRECATED_END - } + ~TemporaryReplaceOutputType(); }; /// Relaxes tensor element type requirements for BaseOp inputs and outputs @@ -338,13 +287,8 @@ bool TypeRelaxed::evaluate_upper(TensorVector& outputs) const { template void TypeRelaxed::validate_and_infer_types() { element::TypeVector old_input_types; - remember_input_data_types(*this, old_input_types); - - OPENVINO_SUPPRESS_DEPRECATED_START BaseOp::validate_and_infer_types(); - OPENVINO_SUPPRESS_DEPRECATED_END - restore_input_data_types(*this, old_input_types); } diff --git a/src/common/transformations/include/transformations/utils/utils.hpp b/src/common/transformations/include/transformations/utils/utils.hpp index b6f4c853c5cb3a..05ff1a23bae040 100644 --- a/src/common/transformations/include/transformations/utils/utils.hpp +++ b/src/common/transformations/include/transformations/utils/utils.hpp @@ -11,6 +11,7 @@ #include #include +#include "openvino/core/descriptor_tensor.hpp" #include "openvino/core/rt_info.hpp" #include "openvino/opsets/opset4.hpp" #include "openvino/opsets/opset8.hpp" 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 2936028a3badec..dbddf574292998 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 @@ -8,6 +8,7 @@ #include #include "itt.hpp" +#include "openvino/core/descriptor_tensor.hpp" #include "openvino/core/graph_util.hpp" #include "openvino/core/rt_info.hpp" #include "openvino/op/concat.hpp" diff --git a/src/common/transformations/src/transformations/symbolic_transformations/symbolic_optimizations.cpp b/src/common/transformations/src/transformations/symbolic_transformations/symbolic_optimizations.cpp index 4ab4e069299c84..1676c7206fad95 100644 --- a/src/common/transformations/src/transformations/symbolic_transformations/symbolic_optimizations.cpp +++ b/src/common/transformations/src/transformations/symbolic_transformations/symbolic_optimizations.cpp @@ -5,6 +5,7 @@ #include "transformations/symbolic_transformations/symbolic_optimizations.hpp" #include "itt.hpp" +#include "openvino/core/descriptor_tensor.hpp" #include "openvino/core/dimension_tracker.hpp" #include "openvino/core/validation_util.hpp" #include "openvino/op/reshape.hpp" @@ -117,9 +118,7 @@ bool ov::pass::SymbolicPropagation::run_on_model(const std::shared_ptroutputs()) { auto shape = output.get_partial_shape(); symbolic_set_up_for_shape(dt, shape); - OPENVINO_SUPPRESS_DEPRECATED_START - output.get_tensor().set_tensor_type(output.get_element_type(), shape); - OPENVINO_SUPPRESS_DEPRECATED_END + ov::descriptor::set_tensor_type(output.get_tensor(), output.get_element_type(), shape); } } return true; diff --git a/src/core/dev_api/openvino/core/descriptor_tensor.hpp b/src/core/dev_api/openvino/core/descriptor_tensor.hpp new file mode 100644 index 00000000000000..9e89086f36a1fb --- /dev/null +++ b/src/core/dev_api/openvino/core/descriptor_tensor.hpp @@ -0,0 +1,25 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "openvino/core/descriptor/tensor.hpp" + +namespace ov { +namespace descriptor { + +// To change Tensor element type please change the Parameter type. +void set_element_type(Tensor& tensor, const element::Type& elemenet_type); + +// To change Tensor type please change the Parameter type. +void set_tensor_type(Tensor& tensor, const element::Type& element_type, const PartialShape& pshape); + +OPENVINO_DEPRECATED("get_ov_tensor_legacy_name() is deprecated. Please don't use this function.") +OPENVINO_API +std::string get_ov_tensor_legacy_name(const Tensor& tensor); + +OPENVINO_DEPRECATED("set_ov_tensor_legacy_name() is deprecated. Please don't use this function.") +OPENVINO_API +void set_ov_tensor_legacy_name(Tensor& tensor, const std::string& tensor_name); + +} // namespace descriptor +} // namespace ov diff --git a/src/core/include/openvino/core/descriptor/tensor.hpp b/src/core/include/openvino/core/descriptor/tensor.hpp index 8a37af24710e79..fbdc23ee3988c2 100644 --- a/src/core/include/openvino/core/descriptor/tensor.hpp +++ b/src/core/include/openvino/core/descriptor/tensor.hpp @@ -32,14 +32,6 @@ namespace descriptor { class Tensor; -OPENVINO_DEPRECATED("get_ov_tensor_legacy_name() is deprecated. Please don't use this function.") -OPENVINO_API -std::string get_ov_tensor_legacy_name(const Tensor& tensor); - -OPENVINO_DEPRECATED("set_ov_tensor_legacy_name() is deprecated. Please don't use this function.") -OPENVINO_API -void set_ov_tensor_legacy_name(Tensor& tensor, const std::string& tensor_name); - /// \brief Compile-time descriptor of a first-class value that is a tensor. class OPENVINO_API Tensor { public: @@ -56,12 +48,6 @@ class OPENVINO_API Tensor { void set_names(const std::unordered_set& names); void add_names(const std::unordered_set& names); - OPENVINO_DEPRECATED("set_tensor_type() is deprecated. To change Tensor type please change the Parameter type") - void set_tensor_type(const element::Type& element_type, const PartialShape& pshape); - OPENVINO_DEPRECATED( - "set_element_type() is deprecated. To change Tensor element type please change the Parameter type") - void set_element_type(const element::Type& elemenet_type); - /// \brief sets lower bound value description void set_lower_value(const ov::Tensor& value); /// \brief sets upper bound value description @@ -135,6 +121,8 @@ class OPENVINO_API Tensor { friend OPENVINO_API std::string get_ov_tensor_legacy_name(const Tensor& tensor); friend OPENVINO_API void set_ov_tensor_legacy_name(Tensor& tensor, const std::string& tensor_name); + friend void set_element_type(Tensor& tensor, const element::Type& elemenet_type); + friend void set_tensor_type(Tensor& tensor, const element::Type& element_type, const PartialShape& pshape); friend class pass::ReverseShapeAndTypeInfer; }; diff --git a/src/core/src/descriptor/tensor.cpp b/src/core/src/descriptor/tensor.cpp index 062a740bbd80b6..33d9e88af5b881 100644 --- a/src/core/src/descriptor/tensor.cpp +++ b/src/core/src/descriptor/tensor.cpp @@ -4,6 +4,7 @@ #include "openvino/core/descriptor/tensor.hpp" +#include "openvino/core/descriptor_tensor.hpp" #include "openvino/core/except.hpp" #include "openvino/core/node.hpp" #include "openvino/op/util/symbolic_info.hpp" @@ -27,18 +28,6 @@ ov::descriptor::Tensor::Tensor(const element::Type& element_type, m_name_it = m_names.cend(); } -OPENVINO_SUPPRESS_DEPRECATED_START -void ov::descriptor::Tensor::set_tensor_type(const element::Type& element_type, const PartialShape& pshape) { - set_element_type(element_type); - m_partial_shape = pshape; - m_shape_changed = true; -} - -void ov::descriptor::Tensor::set_element_type(const element::Type& element_type) { - m_element_type = element_type; -} -OPENVINO_SUPPRESS_DEPRECATED_END - void ov::descriptor::Tensor::invalidate_values() { if (ov::skip_invalidation(*this)) return; @@ -146,6 +135,18 @@ void ov::descriptor::set_ov_tensor_legacy_name(ov::descriptor::Tensor& tensor, c tensor.m_legacy_name = tensor_name; } +void ov::descriptor::set_tensor_type(ov::descriptor::Tensor& tensor, + const element::Type& element_type, + const PartialShape& pshape) { + tensor.m_element_type = element_type; + tensor.m_partial_shape = pshape; + tensor.m_shape_changed = true; +} + +void ov::descriptor::set_element_type(ov::descriptor::Tensor& tensor, const element::Type& element_type) { + tensor.m_element_type = element_type; +} + std::ostream& ov::descriptor::operator<<(std::ostream& out, const ov::descriptor::Tensor& tensor) { std::string names; for (const auto& name : tensor.get_names()) { diff --git a/src/core/src/graph_util.cpp b/src/core/src/graph_util.cpp index ec24a5cba81444..d66cc703a45d34 100644 --- a/src/core/src/graph_util.cpp +++ b/src/core/src/graph_util.cpp @@ -11,6 +11,7 @@ #include #include "openvino/core/descriptor/tensor.hpp" +#include "openvino/core/descriptor_tensor.hpp" #include "openvino/core/rt_info.hpp" #include "openvino/op/broadcast.hpp" #include "openvino/op/constant.hpp" diff --git a/src/core/src/node.cpp b/src/core/src/node.cpp index e152bcb7f4a63e..f2d5f603c3b46d 100644 --- a/src/core/src/node.cpp +++ b/src/core/src/node.cpp @@ -13,6 +13,7 @@ #include "bound_evaluate.hpp" #include "itt.hpp" #include "openvino/core/descriptor/input.hpp" +#include "openvino/core/descriptor_tensor.hpp" #include "openvino/core/rt_info.hpp" #include "openvino/core/shape_util.hpp" #include "openvino/op/util/op_types.hpp" @@ -273,9 +274,7 @@ void ov::Node::set_input_is_relevant_to_value(size_t i, bool relevant) { } void ov::Node::set_output_type(size_t i, const element::Type& element_type, const PartialShape& pshape) { - OPENVINO_SUPPRESS_DEPRECATED_START - get_output_descriptor(i).get_tensor_ptr()->set_tensor_type(element_type, pshape); - OPENVINO_SUPPRESS_DEPRECATED_END + ov::descriptor::set_tensor_type(get_output_descriptor(i).get_tensor(), element_type, pshape); } std::string ov::Node::description() const { diff --git a/src/core/src/node_output.cpp b/src/core/src/node_output.cpp index 4d5de39b75132a..3bdbce3b763e2f 100644 --- a/src/core/src/node_output.cpp +++ b/src/core/src/node_output.cpp @@ -4,6 +4,7 @@ #include "openvino/core/node_output.hpp" +#include "openvino/core/descriptor_tensor.hpp" #include "openvino/core/node.hpp" #include "openvino/core/rt_info.hpp" #include "openvino/op/parameter.hpp" diff --git a/src/core/src/op/type_relaxed.cpp b/src/core/src/op/type_relaxed.cpp index 0794bce61cfd19..994ccc3394fcac 100644 --- a/src/core/src/op/type_relaxed.cpp +++ b/src/core/src/op/type_relaxed.cpp @@ -8,10 +8,68 @@ #include #include +#include "openvino/core/descriptor_tensor.hpp" + namespace ov { namespace op { + TypeRelaxedBase::~TypeRelaxedBase() = default; +void TypeRelaxedBase::remember_input_data_types(Node& node, element::TypeVector& old_input_types) { + // Remember all input data types + for (size_t i = 0; i < node.get_input_size(); ++i) { + old_input_types.push_back(node.get_input_element_type(i)); + } + + // Reset input data types to m_output_data_type. + for (size_t i = 0; i < node.get_input_size(); ++i) { + auto origin_input_type = get_origin_input_type(i); + if (origin_input_type != element::undefined) { + ov::descriptor::set_tensor_type(node.get_input_tensor(i), + origin_input_type, + node.get_input_partial_shape(i)); + } + } +} + +void TypeRelaxedBase::restore_input_data_types(Node& node, const element::TypeVector& old_input_types) { + // Restore original input data types + for (size_t i = 0; i < node.get_input_size(); ++i) { + ov::descriptor::set_tensor_type(node.get_input_tensor(i), old_input_types[i], node.get_input_partial_shape(i)); + } + + if (m_original_output_data_types.empty()) { + m_original_output_data_types = element::TypeVector(node.get_output_size()); + } + + // Save inferred output types + for (size_t i = 0; i < node.get_output_size(); ++i) { + m_original_output_data_types[i] = node.get_output_element_type(i); + } + + // Override (some) output types + for (size_t i = 0; i < node.get_output_size(); ++i) { + auto overridden_output_type = get_overridden_output_type(i); + if (overridden_output_type != element::undefined) { + node.set_output_type(i, overridden_output_type, node.get_output_partial_shape(i)); + } + } +} + +TemporaryReplaceOutputType::TemporaryReplaceOutputType(Output output, element::Type tmp_type) : m_output(output) { + // save original element type in order to restore it in the destructor + orig_type = m_output.get_element_type(); + ov::descriptor::set_element_type(m_output.get_tensor(), tmp_type); +} + +Output TemporaryReplaceOutputType::get() const { + return m_output; +} + +TemporaryReplaceOutputType::~TemporaryReplaceOutputType() { + ov::descriptor::set_element_type(m_output.get_tensor(), orig_type); +} + namespace { void convert_types(std::shared_ptr& parameter, std::shared_ptr& convert, @@ -35,9 +93,7 @@ void convert_types(std::shared_ptr& parameter, auto& tensor = output.get_tensor(); if (lower_success || upper_success) { - OPENVINO_SUPPRESS_DEPRECATED_START - tensor.set_element_type(new_type); // deprecated piece - OPENVINO_SUPPRESS_DEPRECATED_END + ov::descriptor::set_element_type(tensor, new_type); } if (lower_success) tensor.set_lower_value(lower_tensor[0]); @@ -115,9 +171,7 @@ void reset_input_types(const std::unordered_mapoutput(0).get_tensor(); + OPENVINO_SUPPRESS_DEPRECATED_START auto legacy_name = op::util::create_ie_output_name(output); descriptor::set_ov_tensor_legacy_name(convertTensor, legacy_name); + OPENVINO_SUPPRESS_DEPRECATED_END if (!output.get_names().empty()) { convertTensor.set_names(output.get_names()); diff --git a/src/tests/functional/shared_test_classes/src/subgraph/memory_LSTMCell.cpp b/src/tests/functional/shared_test_classes/src/subgraph/memory_LSTMCell.cpp index 6533b799add5ed..29dd924bc2c5b1 100644 --- a/src/tests/functional/shared_test_classes/src/subgraph/memory_LSTMCell.cpp +++ b/src/tests/functional/shared_test_classes/src/subgraph/memory_LSTMCell.cpp @@ -121,9 +121,6 @@ void MemoryLSTMCellTest::SetUp() { auto out_hidden = tensor_iterator->get_iter_value(H_o, -1); auto out_cell = tensor_iterator->get_iter_value(C_o, -1); - out_hidden.get_tensor().set_element_type(element_type); - out_cell.get_tensor().set_element_type(element_type); - auto cell_memory_write = std::make_shared(out_cell, var_cell); auto hidden_memory_write = std::make_shared(out_hidden, var_hidden); @@ -271,9 +268,6 @@ void MemoryLSTMCellTest::create_pure_tensor_iterator_model() { auto out_hidden = tensor_iterator->get_iter_value(H_o, -1); auto out_cell = tensor_iterator->get_iter_value(C_o, -1); - out_hidden.get_tensor().set_element_type(element_type); - out_cell.get_tensor().set_element_type(element_type); - auto final_reshape_pattern = std::make_shared(element::i64, Shape{4}, std::vector({1, 1, 1, hiddenSize})); auto final_reshape = std::make_shared(out_unsqueeze, final_reshape_pattern, false); diff --git a/src/tests/functional/shared_test_classes/src/subgraph/multiple_LSTMCell.cpp b/src/tests/functional/shared_test_classes/src/subgraph/multiple_LSTMCell.cpp index 3a89093af9a4ee..49a99d795579ee 100644 --- a/src/tests/functional/shared_test_classes/src/subgraph/multiple_LSTMCell.cpp +++ b/src/tests/functional/shared_test_classes/src/subgraph/multiple_LSTMCell.cpp @@ -122,9 +122,6 @@ void MultipleLSTMCellTest::SetUp() { auto out_hidden = tensor_iterator->get_iter_value(H_o, -1); auto out_cell = tensor_iterator->get_iter_value(C_o, -1); - out_hidden.get_tensor().set_element_type(element_type); - out_cell.get_tensor().set_element_type(element_type); - auto cell_memory_write = std::make_shared(out_cell, var_cell); auto hidden_memory_write = std::make_shared(out_hidden, var_hidden); @@ -193,9 +190,6 @@ void MultipleLSTMCellTest::SetUp() { auto out_hidden_2 = tensor_iterator_2->get_iter_value(H_o_2, -1); auto out_cell_2 = tensor_iterator_2->get_iter_value(C_o_2, -1); - out_hidden_2.get_tensor().set_element_type(element_type); - out_cell_2.get_tensor().set_element_type(element_type); - auto cell_memory_2_write = std::make_shared(out_cell_2, var_cell_2); auto hidden_memory_2_write = std::make_shared(out_hidden_2, var_hidden_2); @@ -381,8 +375,6 @@ void MultipleLSTMCellTest::create_pure_tensor_iterator_model() { auto out_hidden = tensor_iterator->get_iter_value(H_o, -1); auto out_cell = tensor_iterator->get_iter_value(C_o, -1); - out_hidden.get_tensor().set_element_type(element_type); - out_cell.get_tensor().set_element_type(element_type); tensor_iterator->validate_and_infer_types(); auto first_reshape_pattern = @@ -444,8 +436,6 @@ void MultipleLSTMCellTest::create_pure_tensor_iterator_model() { auto out_hidden_2 = tensor_iterator_2->get_iter_value(H_o_2, -1); auto out_cell_2 = tensor_iterator_2->get_iter_value(C_o_2, -1); - out_hidden_2.get_tensor().set_element_type(element_type); - out_cell_2.get_tensor().set_element_type(element_type); tensor_iterator_2->validate_and_infer_types(); auto final_reshape_pattern = std::make_shared(element::i64, Shape{4}, std::vector({1, 1, 1, hiddenSize})); diff --git a/src/tests/ov_helpers/ov_snippets_models/src/subgraph_simple.cpp b/src/tests/ov_helpers/ov_snippets_models/src/subgraph_simple.cpp index 79ddd5ca00c641..b2d894b7e5a64f 100644 --- a/src/tests/ov_helpers/ov_snippets_models/src/subgraph_simple.cpp +++ b/src/tests/ov_helpers/ov_snippets_models/src/subgraph_simple.cpp @@ -4,6 +4,7 @@ #include "subgraph_simple.hpp" #include "common_test_utils/data_utils.hpp" +#include "openvino/core/descriptor_tensor.hpp" #include namespace ov {