From 3be946371d97e207151e8dcd655d745d55723685 Mon Sep 17 00:00:00 2001 From: Xuejun Zhai Date: Fri, 7 Apr 2023 12:37:25 +0800 Subject: [PATCH] Xuejun/remove api tensor related (#15877) * [Remove APIs] remove api set_partial_shape() Signed-off-by: Zhai, Xuejun * [Remove APIs] remove api set_element_type() Signed-off-by: Zhai, Xuejun * [Remove APIs] remove api set_tensor_type() Signed-off-by: Zhai, Xuejun * Revert "[Remove APIs] remove api set_tensor_type()" This reverts commit 96f89e222dd3dbebfb3c7b98cbdacfc09f5897a7. * Revert "[Remove APIs] remove api set_element_type()" This reverts commit 33ebb61977b3921ae6eedc5e46c2656e69e43b0b. * Apply suggestions from code review --------- Signed-off-by: Zhai, Xuejun Co-authored-by: Evgenya Stepyreva Co-authored-by: Evgenya Stepyreva --- .../openvino/core/descriptor/tensor.hpp | 4 +-- src/core/src/descriptor/tensor.cpp | 8 ++---- src/core/src/runtime/host_tensor.cpp | 5 ++-- .../utils/shape_inference/shape_inference.cpp | 7 ++--- .../single_layer_tests/convolution.cpp | 5 +++- .../single_layer_tests/group_convolution.cpp | 5 +++- .../template/backend/int_executable.cpp | 28 +++++++++++-------- 7 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/core/include/openvino/core/descriptor/tensor.hpp b/src/core/include/openvino/core/descriptor/tensor.hpp index 7aa5b225a8c..d264d568ab4 100644 --- a/src/core/include/openvino/core/descriptor/tensor.hpp +++ b/src/core/include/openvino/core/descriptor/tensor.hpp @@ -70,9 +70,6 @@ public: 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); - OPENVINO_DEPRECATED( - "set_partial_shape() is deprecated. To change Tensor partial shape please change the Parameter partial shape") - void set_partial_shape(const PartialShape& partial_shape); /// \brief sets lower bound value description void set_lower_value(const ov::Tensor& value); @@ -148,6 +145,7 @@ protected: 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 class pass::ReverseShapeAndTypeInfer; + friend class ngraph::runtime::HostTensor; }; OPENVINO_API diff --git a/src/core/src/descriptor/tensor.cpp b/src/core/src/descriptor/tensor.cpp index ed87ce606bf..18a024835bd 100644 --- a/src/core/src/descriptor/tensor.cpp +++ b/src/core/src/descriptor/tensor.cpp @@ -38,17 +38,13 @@ ov::descriptor::Tensor::Tensor(const element::Type& element_type, OPENVINO_SUPPRESS_DEPRECATED_START void ov::descriptor::Tensor::set_tensor_type(const element::Type& element_type, const PartialShape& pshape) { set_element_type(element_type); - set_partial_shape(pshape); + 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; } - -void ov::descriptor::Tensor::set_partial_shape(const PartialShape& partial_shape) { - m_partial_shape = partial_shape; - m_shape_changed = true; -} OPENVINO_SUPPRESS_DEPRECATED_END void ov::descriptor::Tensor::invalidate_values() { diff --git a/src/core/src/runtime/host_tensor.cpp b/src/core/src/runtime/host_tensor.cpp index 1a0b5248c23..90bc88e968d 100644 --- a/src/core/src/runtime/host_tensor.cpp +++ b/src/core/src/runtime/host_tensor.cpp @@ -143,9 +143,8 @@ void runtime::HostTensor::set_shape(const Shape& shape) { shape, " must be compatible with the partial shape: ", get_partial_shape()); - OPENVINO_SUPPRESS_DEPRECATED_START - m_descriptor->set_partial_shape(shape); - OPENVINO_SUPPRESS_DEPRECATED_END + m_descriptor->m_partial_shape = shape; + m_descriptor->m_shape_changed = true; } void runtime::HostTensor::set_unary(const HostTensorPtr& arg) { diff --git a/src/plugins/intel_cpu/src/utils/shape_inference/shape_inference.cpp b/src/plugins/intel_cpu/src/utils/shape_inference/shape_inference.cpp index 8b4342e3be3..691350d9544 100644 --- a/src/plugins/intel_cpu/src/utils/shape_inference/shape_inference.cpp +++ b/src/plugins/intel_cpu/src/utils/shape_inference/shape_inference.cpp @@ -233,13 +233,12 @@ public: local_op = op->clone_with_new_inputs(new_inputs); } else { local_op = local_op_default; - OPENVINO_SUPPRESS_DEPRECATED_START for (size_t i = 0; i < local_op->get_input_size(); i++) { - if (dynamic_cast(local_op->get_input_node_ptr(i))) { - local_op->get_input_tensor(i).set_partial_shape(input_shapes[i].to_partial_shape()); + if (auto parameter = dynamic_cast(local_op->get_input_node_ptr(i))) { + parameter->set_partial_shape(input_shapes[i].to_partial_shape()); + parameter->validate_and_infer_types(); } } - OPENVINO_SUPPRESS_DEPRECATED_END } local_op->validate_and_infer_types(); diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/convolution.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/convolution.cpp index dae6945e49f..44dc9771e8e 100755 --- a/src/plugins/intel_cpu/tests/functional/single_layer_tests/convolution.cpp +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/convolution.cpp @@ -145,7 +145,10 @@ protected: } std::vector secondParameterShapes; - opToShapeInfer->get_input_tensor(0).set_partial_shape(targetShapes.front()); + if (auto parameter = dynamic_cast(opToShapeInfer->get_input_node_ptr(0))) { + parameter->set_partial_shape(targetShapes.front()); + parameter->validate_and_infer_types(); + } opToShapeInfer->validate_and_infer_types(); targetShapes.push_back(opToShapeInfer->get_output_shape(0)); } diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/group_convolution.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/group_convolution.cpp index 7ee67d278cf..41fba438744 100644 --- a/src/plugins/intel_cpu/tests/functional/single_layer_tests/group_convolution.cpp +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/group_convolution.cpp @@ -142,7 +142,10 @@ protected: } std::vector secondParameterShapes; - opToShapeInfer->get_input_tensor(0).set_partial_shape(targetShapes.front()); + if (auto parameter = dynamic_cast(opToShapeInfer->get_input_node_ptr(0))) { + parameter->set_partial_shape(targetShapes.front()); + parameter->validate_and_infer_types(); + } opToShapeInfer->validate_and_infer_types(); targetShapes.push_back(opToShapeInfer->get_output_shape(0)); } diff --git a/src/plugins/template/backend/int_executable.cpp b/src/plugins/template/backend/int_executable.cpp index 6091a62e3f0..481b0b6e601 100644 --- a/src/plugins/template/backend/int_executable.cpp +++ b/src/plugins/template/backend/int_executable.cpp @@ -75,23 +75,27 @@ inline void update_output_tensors(ov::TensorVector& output_values, const ngraph: } // namespace class TemporaryOverrideOutputs { - std::shared_ptr node; - std::vector orig_shapes; + std::shared_ptr model; + std::unordered_map, ov::PartialShape> orig_paramter_shapes_map; public: - TemporaryOverrideOutputs(std::shared_ptr node, const std::vector& args) : node(node) { - for (size_t i = 0; i < args.size(); ++i) { - auto output = node->get_input_source_output(i); - orig_shapes.push_back(output.get_partial_shape()); - output.get_tensor().set_partial_shape(args[i].get_shape()); + TemporaryOverrideOutputs(std::shared_ptr& model, + const std::unordered_map, ov::Tensor>& tensor_map) + : model(model) { + for (const auto& param : model->get_parameters()) { + auto output_tensor = param->output(0).get_tensor_ptr(); + orig_paramter_shapes_map.insert({output_tensor, param->get_partial_shape()}); + param->set_partial_shape(tensor_map.at(output_tensor).get_shape()); } + model->validate_nodes_and_infer_types(); } ~TemporaryOverrideOutputs() { - for (size_t i = 0; i < orig_shapes.size(); ++i) { - auto output = node->get_input_source_output(i); - output.get_tensor().set_partial_shape(orig_shapes[i]); + for (const auto& param : model->get_parameters()) { + auto output_tensor = param->output(0).get_tensor_ptr(); + param->set_partial_shape(orig_paramter_shapes_map.at(output_tensor)); } + model->validate_nodes_and_infer_types(); } }; @@ -147,12 +151,13 @@ bool ov::runtime::interpreter::INTExecutable::call(std::vector& outp results_map.emplace(output, output_count); } + auto overrider = TemporaryOverrideOutputs(m_model, tensor_map); + // for each ordered op in the graph for (const auto& op : m_nodes) { if (std::dynamic_pointer_cast(op)) { continue; } - // get op inputs from map std::vector op_inputs; for (auto input : op->inputs()) { @@ -160,7 +165,6 @@ bool ov::runtime::interpreter::INTExecutable::call(std::vector& outp op_inputs.push_back(tensor_map.at(tensor)); } - TemporaryOverrideOutputs overrider(op, op_inputs); OutputVector output_ports; for (size_t i = 0; i < op->inputs().size(); ++i) { output_ports.push_back(op->get_input_source_output(i));