Skip to content

Commit

Permalink
Xuejun/set element type private (#22722)
Browse files Browse the repository at this point in the history
### Details:
- Removes` get_ov_tensor_legacy_name(); set_ov_tensor_legacy_name();
set_tensor_type; set_element_type;` functions from public API and
deprecates them.
 - Refactoring

### Tickets:
 - *CVS-132032*

---------

Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com>
Co-authored-by: Zhai, Xuejun <xuejun.zhai@intel.com>
  • Loading branch information
ilya-lavrenov and zhaixuejun1993 authored Feb 8, 2024
1 parent a090338 commit 0215d27
Show file tree
Hide file tree
Showing 20 changed files with 124 additions and 120 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code_snippets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
5 changes: 3 additions & 2 deletions docs/snippets/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/common/snippets/src/op/subgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#include "snippets/pass/manager.hpp"
#include "openvino/pass/constant_folding.hpp"
#include "ov_ops/type_relaxed.hpp"
#include <openvino/pass/serialize.hpp>
#include "openvino/pass/serialize.hpp"

#include <algorithm>
#include <memory>
Expand Down
68 changes: 6 additions & 62 deletions src/common/transformations/include/ov_ops/type_relaxed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Node> m_output;
element::Type orig_type;

public:
/// Replace element type for a given output port by tmp_type
TemporaryReplaceOutputType(Output<Node> 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<Node> output, element::Type tmp_type);

/// Return the output port that was used in the constructor
Output<Node> get() const {
return m_output;
}
Output<Node> 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
Expand Down Expand Up @@ -338,13 +287,8 @@ bool TypeRelaxed<BaseOp>::evaluate_upper(TensorVector& outputs) const {
template <typename BaseOp>
void TypeRelaxed<BaseOp>::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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <memory>
#include <vector>

#include "openvino/core/descriptor_tensor.hpp"
#include "openvino/core/rt_info.hpp"
#include "openvino/opsets/opset4.hpp"
#include "openvino/opsets/opset8.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <vector>

#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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -117,9 +118,7 @@ bool ov::pass::SymbolicPropagation::run_on_model(const std::shared_ptr<ov::Model
for (auto& output : op->outputs()) {
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;
Expand Down
25 changes: 25 additions & 0 deletions src/core/dev_api/openvino/core/descriptor_tensor.hpp
Original file line number Diff line number Diff line change
@@ -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
16 changes: 2 additions & 14 deletions src/core/include/openvino/core/descriptor/tensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -56,12 +48,6 @@ class OPENVINO_API Tensor {
void set_names(const std::unordered_set<std::string>& names);
void add_names(const std::unordered_set<std::string>& 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
Expand Down Expand Up @@ -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;
};

Expand Down
25 changes: 13 additions & 12 deletions src/core/src/descriptor/tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down
1 change: 1 addition & 0 deletions src/core/src/graph_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <vector>

#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"
Expand Down
5 changes: 2 additions & 3 deletions src/core/src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/core/src/node_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading

0 comments on commit 0215d27

Please sign in to comment.