From 973b194776ceec9e15d29135feb21eeacb9ae817 Mon Sep 17 00:00:00 2001 From: Tomasz Jankowski Date: Wed, 25 Oct 2023 07:10:54 +0200 Subject: [PATCH] [core] Migrate DepthToSpace operator to new API (#20515) * Move into ov namespace * Use ov::Tensor in place of HostTensor --------- Co-authored-by: Michal Lukaszewski --- .../include/openvino/op/depth_to_space.hpp | 4 +- src/core/src/op/depth_to_space.cpp | 85 ++++++++----------- 2 files changed, 37 insertions(+), 52 deletions(-) diff --git a/src/core/include/openvino/op/depth_to_space.hpp b/src/core/include/openvino/op/depth_to_space.hpp index 802eddbd665..c7b946e71e9 100644 --- a/src/core/include/openvino/op/depth_to_space.hpp +++ b/src/core/include/openvino/op/depth_to_space.hpp @@ -55,9 +55,7 @@ public: } std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; void validate_and_infer_types() override; - OPENVINO_SUPPRESS_DEPRECATED_START - bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; - OPENVINO_SUPPRESS_DEPRECATED_END + bool evaluate(TensorVector& outputs, const TensorVector& inputs) const override; bool has_evaluate() const override; protected: diff --git a/src/core/src/op/depth_to_space.cpp b/src/core/src/op/depth_to_space.cpp index ce3003ed83f..e914f83d4a8 100644 --- a/src/core/src/op/depth_to_space.cpp +++ b/src/core/src/op/depth_to_space.cpp @@ -2,46 +2,45 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/depth_to_space.hpp" +#include "openvino/op/depth_to_space.hpp" #include #include -#include #include -#include -#include +#include "depth_to_space_shape_inference.hpp" #include "itt.hpp" -#include "ngraph/shape.hpp" +#include "openvino/core/shape.hpp" #include "openvino/core/validation_util.hpp" #include "openvino/reference/depth_to_space.hpp" -using namespace ngraph; - -op::DepthToSpace::DepthToSpace(const Output& data, const DepthToSpaceMode& mode, const size_t block_size) +namespace ov { +namespace op { +namespace v0 { +DepthToSpace::DepthToSpace(const Output& data, const DepthToSpaceMode& mode, const size_t block_size) : Op({data}), m_blocksize(block_size), m_mode(mode) { constructor_validate_and_infer_types(); } -op::DepthToSpace::DepthToSpace(const Output& data, const std::string& mode, const size_t block_size) +DepthToSpace::DepthToSpace(const Output& data, const std::string& mode, const size_t block_size) : DepthToSpace(data, as_enum(mode), block_size) {} -bool op::DepthToSpace::visit_attributes(AttributeVisitor& visitor) { +bool DepthToSpace::visit_attributes(AttributeVisitor& visitor) { OV_OP_SCOPE(v0_DepthToSpace_visit_attributes); visitor.on_attribute("block_size", m_blocksize); visitor.on_attribute("mode", m_mode); return true; } -std::shared_ptr op::DepthToSpace::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr DepthToSpace::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v0_DepthToSpace_clone_with_new_inputs); check_new_args_count(this, new_args); return std::make_shared(new_args.at(0), m_mode, m_blocksize); } -void op::DepthToSpace::validate_and_infer_types() { +void DepthToSpace::validate_and_infer_types() { OV_OP_SCOPE(v0_DepthToSpace_validate_and_infer_types); OPENVINO_SUPPRESS_DEPRECATED_START @@ -50,60 +49,48 @@ void op::DepthToSpace::validate_and_infer_types() { set_output_type(0, get_input_element_type(0), output_shape); } -OPENVINO_SUPPRESS_DEPRECATED_START -namespace { -bool evaluate_depth_to_space(const HostTensorVector& outputs, - const HostTensorVector& inputs, - const std::size_t block_size, - const op::DepthToSpace::DepthToSpaceMode mode) { +bool DepthToSpace::evaluate(TensorVector& outputs, const TensorVector& inputs) const { + OV_OP_SCOPE(v0_DepthToSpace_evaluate); + OPENVINO_ASSERT(outputs.size() == 1); + const auto& in = inputs[0]; const auto& out = outputs[0]; - const size_t elem_size = in->get_element_type().size(); - if (in->get_partial_shape().is_dynamic()) { - return false; - } - ov::reference::depth_to_space(in->get_data_ptr(), - in->get_shape(), - out->get_data_ptr(), - out->get_shape(), - block_size, - mode, - elem_size); + reference::depth_to_space(static_cast(in.data()), + in.get_shape(), + static_cast(out.data()), + out.get_shape(), + m_blocksize, + m_mode, + in.get_element_type().size()); return true; } -} // namespace -bool op::DepthToSpace::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { - OV_OP_SCOPE(v0_DepthToSpace_evaluate); - return evaluate_depth_to_space(outputs, inputs, m_blocksize, m_mode); -} -OPENVINO_SUPPRESS_DEPRECATED_END - -bool op::DepthToSpace::has_evaluate() const { +bool DepthToSpace::has_evaluate() const { OV_OP_SCOPE(v0_DepthToSpace_has_evaluate); return !get_input_partial_shape(0).is_dynamic(); } -std::ostream& ov::operator<<(std::ostream& s, const ov::op::v0::DepthToSpace::DepthToSpaceMode& type) { - return s << as_string(type); -} - -void op::v0::DepthToSpace::set_block_size(size_t block_size) { +void DepthToSpace::set_block_size(size_t block_size) { m_blocksize = block_size; } -void op::v0::DepthToSpace::set_mode(DepthToSpaceMode mode) { +void DepthToSpace::set_mode(DepthToSpaceMode mode) { m_mode = mode; } +} // namespace v0 +} // namespace op + +std::ostream& operator<<(std::ostream& s, const op::v0::DepthToSpace::DepthToSpaceMode& type) { + return s << as_string(type); +} -namespace ov { template <> -NGRAPH_API EnumNames& -EnumNames::get() { - static auto enum_names = EnumNames( +OPENVINO_API EnumNames& +EnumNames::get() { + static auto enum_names = EnumNames( "op::DepthToSpace::DepthToSpaceMode", - {{"blocks_first", ngraph::op::DepthToSpace::DepthToSpaceMode::BLOCKS_FIRST}, - {"depth_first", ngraph::op::DepthToSpace::DepthToSpaceMode::DEPTH_FIRST}}); + {{"blocks_first", op::v0::DepthToSpace::DepthToSpaceMode::BLOCKS_FIRST}, + {"depth_first", op::v0::DepthToSpace::DepthToSpaceMode::DEPTH_FIRST}}); return enum_names; } } // namespace ov