Skip to content

Commit

Permalink
[Deprecated API] Move api set_element_type() & set_tensor_type() from…
Browse files Browse the repository at this point in the history
… public to private

Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com>
  • Loading branch information
zhaixuejun1993 committed Feb 4, 2024
1 parent b60526c commit 4b3acb2
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 61 deletions.
36 changes: 30 additions & 6 deletions src/core/include/openvino/core/descriptor/tensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,19 @@ using TensorLabelVector = std::vector<TensorLabel>;

namespace pass {
class ReverseShapeAndTypeInfer;
class SymbolicPropagation;
}

namespace op {
class TypeRelaxedBase;
class TemporaryReplaceOutputType;
std::unordered_map<size_t, std::pair<ov::Tensor, ov::Tensor>> OPENVINO_API
convert_input_types(OutputVector& inputs, const element::TypeVector& types);
void OPENVINO_API
reset_input_types(const std::unordered_map<size_t, std::pair<ov::Tensor, ov::Tensor>>& original_input_vals,
OutputVector& inputs);
}

namespace descriptor {

class Tensor;
Expand Down Expand Up @@ -58,12 +70,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 @@ -107,6 +113,14 @@ class OPENVINO_API Tensor {

void clone_from(const Tensor& old);

private:
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_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);

protected:
element::Type m_element_type;

Expand Down Expand Up @@ -137,7 +151,17 @@ 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 OPENVINO_API std::unordered_map<size_t, std::pair<ov::Tensor, ov::Tensor>> ov::op::convert_input_types(
OutputVector& inputs,
const element::TypeVector& types);
friend OPENVINO_API void ov::op::reset_input_types(
const std::unordered_map<size_t, std::pair<ov::Tensor, ov::Tensor>>& original_input_vals,
OutputVector& inputs);
friend class pass::ReverseShapeAndTypeInfer;
friend class op::TypeRelaxedBase;
friend class op::TemporaryReplaceOutputType;
friend class pass::SymbolicPropagation;
friend class ov::Node;
};

OPENVINO_API
Expand Down
70 changes: 33 additions & 37 deletions src/core/src/op/type_relaxed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,6 @@ namespace op {
TypeRelaxedBase::~TypeRelaxedBase() = default;

namespace {
void convert_types(std::shared_ptr<v0::Parameter>& parameter,
std::shared_ptr<v0::Convert>& convert,
Output<Node>& output,
const element::Type& new_type) {
parameter->set_element_type(output.get_element_type());
parameter->set_partial_shape(output.get_shape());
parameter->validate_and_infer_types();
if (auto& bound = output.get_tensor().get_lower_value())
parameter->get_output_tensor(0).set_lower_value(bound);
if (auto& bound = output.get_tensor().get_upper_value())
parameter->get_output_tensor(0).set_upper_value(bound);

convert->set_destination_type(new_type);
convert->validate_and_infer_types();

ov::TensorVector lower_tensor = {ov::Tensor(new_type, output.get_shape())};
ov::TensorVector upper_tensor = {ov::Tensor(new_type, output.get_shape())};
bool lower_success = convert->evaluate_lower(lower_tensor);
bool upper_success = convert->evaluate_upper(upper_tensor);
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
}
if (lower_success)
tensor.set_lower_value(lower_tensor[0]);
if (upper_success)
tensor.set_upper_value(upper_tensor[0]);
if (lower_success && upper_success) {
if (memcmp(lower_tensor[0].data(), upper_tensor[0].data(), lower_tensor[0].get_byte_size()) == 0)
tensor.set_upper_value(lower_tensor[0]);
}
}

void reset_convert(std::shared_ptr<v0::Parameter> parameter,
std::shared_ptr<v0::Convert> convert,
const ov::Tensor& tensor,
Expand Down Expand Up @@ -85,7 +49,39 @@ std::unordered_map<size_t, std::pair<ov::Tensor, ov::Tensor>> convert_input_type
parameter = std::make_shared<op::v0::Parameter>(element::undefined, PartialShape());
convert = std::make_shared<ov::op::v0::Convert>(parameter, element::undefined);
}
ov::op::convert_types(parameter, convert, input, original_type);
// ov::op::convert_types(parameter, convert, input, original_type);
{
parameter->set_element_type(input.get_element_type());
parameter->set_partial_shape(input.get_shape());
parameter->validate_and_infer_types();
if (auto& bound = input.get_tensor().get_lower_value())
parameter->get_output_tensor(0).set_lower_value(bound);
if (auto& bound = input.get_tensor().get_upper_value())
parameter->get_output_tensor(0).set_upper_value(bound);

convert->set_destination_type(original_type);
convert->validate_and_infer_types();

ov::TensorVector lower_tensor = {ov::Tensor(original_type, input.get_shape())};
ov::TensorVector upper_tensor = {ov::Tensor(original_type, input.get_shape())};
bool lower_success = convert->evaluate_lower(lower_tensor);
bool upper_success = convert->evaluate_upper(upper_tensor);
auto& tensor = input.get_tensor();

if (lower_success || upper_success) {
OPENVINO_SUPPRESS_DEPRECATED_START
tensor.set_element_type(original_type); // deprecated piece
OPENVINO_SUPPRESS_DEPRECATED_END
}
if (lower_success)
tensor.set_lower_value(lower_tensor[0]);
if (upper_success)
tensor.set_upper_value(upper_tensor[0]);
if (lower_success && upper_success) {
if (memcmp(lower_tensor[0].data(), upper_tensor[0].data(), lower_tensor[0].get_byte_size()) == 0)
tensor.set_upper_value(lower_tensor[0]);
}
}
original_inputs[i] = {parameter->get_output_tensor(0).get_lower_value(),
parameter->get_output_tensor(0).get_upper_value()};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ov::op::v6::Assign>(out_cell, var_cell);
auto hidden_memory_write = std::make_shared<ov::op::v6::Assign>(out_hidden, var_hidden);

Expand Down Expand Up @@ -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<ov::op::v0::Constant>(element::i64, Shape{4}, std::vector<size_t>({1, 1, 1, hiddenSize}));
auto final_reshape = std::make_shared<ov::op::v1::Reshape>(out_unsqueeze, final_reshape_pattern, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ov::op::v6::Assign>(out_cell, var_cell);
auto hidden_memory_write = std::make_shared<ov::op::v6::Assign>(out_hidden, var_hidden);

Expand Down Expand Up @@ -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<ov::op::v6::Assign>(out_cell_2, var_cell_2);
auto hidden_memory_2_write = std::make_shared<ov::op::v6::Assign>(out_hidden_2, var_hidden_2);

Expand Down Expand Up @@ -380,9 +374,6 @@ void MultipleLSTMCellTest::create_pure_tensor_iterator_model() {
auto out_unsqueeze = tensor_iterator->get_iter_value(unsqueeze_o, -1);
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 =
Expand Down Expand Up @@ -443,9 +434,6 @@ void MultipleLSTMCellTest::create_pure_tensor_iterator_model() {
auto out_unsqueeze_2 = tensor_iterator_2->get_iter_value(unsqueeze_o_2, -1);
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<ov::op::v0::Constant>(element::i64, Shape{4}, std::vector<size_t>({1, 1, 1, hiddenSize}));
Expand Down

0 comments on commit 4b3acb2

Please sign in to comment.