[core] Migrate DepthToSpace operator to new API (#20515)
* Move into ov namespace * Use ov::Tensor in place of HostTensor --------- Co-authored-by: Michal Lukaszewski <michal.lukaszewski@intel.com>
This commit is contained in:
parent
84732515b4
commit
973b194776
@ -55,9 +55,7 @@ public:
|
|||||||
}
|
}
|
||||||
std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& new_args) const override;
|
std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& new_args) const override;
|
||||||
void validate_and_infer_types() override;
|
void validate_and_infer_types() override;
|
||||||
OPENVINO_SUPPRESS_DEPRECATED_START
|
bool evaluate(TensorVector& outputs, const TensorVector& inputs) const override;
|
||||||
bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override;
|
|
||||||
OPENVINO_SUPPRESS_DEPRECATED_END
|
|
||||||
bool has_evaluate() const override;
|
bool has_evaluate() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -2,46 +2,45 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "ngraph/op/depth_to_space.hpp"
|
#include "openvino/op/depth_to_space.hpp"
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <depth_to_space_shape_inference.hpp>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <ngraph/op/constant.hpp>
|
|
||||||
#include <ngraph/ops.hpp>
|
|
||||||
|
|
||||||
|
#include "depth_to_space_shape_inference.hpp"
|
||||||
#include "itt.hpp"
|
#include "itt.hpp"
|
||||||
#include "ngraph/shape.hpp"
|
#include "openvino/core/shape.hpp"
|
||||||
#include "openvino/core/validation_util.hpp"
|
#include "openvino/core/validation_util.hpp"
|
||||||
#include "openvino/reference/depth_to_space.hpp"
|
#include "openvino/reference/depth_to_space.hpp"
|
||||||
|
|
||||||
using namespace ngraph;
|
namespace ov {
|
||||||
|
namespace op {
|
||||||
op::DepthToSpace::DepthToSpace(const Output<Node>& data, const DepthToSpaceMode& mode, const size_t block_size)
|
namespace v0 {
|
||||||
|
DepthToSpace::DepthToSpace(const Output<Node>& data, const DepthToSpaceMode& mode, const size_t block_size)
|
||||||
: Op({data}),
|
: Op({data}),
|
||||||
m_blocksize(block_size),
|
m_blocksize(block_size),
|
||||||
m_mode(mode) {
|
m_mode(mode) {
|
||||||
constructor_validate_and_infer_types();
|
constructor_validate_and_infer_types();
|
||||||
}
|
}
|
||||||
|
|
||||||
op::DepthToSpace::DepthToSpace(const Output<Node>& data, const std::string& mode, const size_t block_size)
|
DepthToSpace::DepthToSpace(const Output<Node>& data, const std::string& mode, const size_t block_size)
|
||||||
: DepthToSpace(data, as_enum<DepthToSpaceMode>(mode), block_size) {}
|
: DepthToSpace(data, as_enum<DepthToSpaceMode>(mode), block_size) {}
|
||||||
|
|
||||||
bool op::DepthToSpace::visit_attributes(AttributeVisitor& visitor) {
|
bool DepthToSpace::visit_attributes(AttributeVisitor& visitor) {
|
||||||
OV_OP_SCOPE(v0_DepthToSpace_visit_attributes);
|
OV_OP_SCOPE(v0_DepthToSpace_visit_attributes);
|
||||||
visitor.on_attribute("block_size", m_blocksize);
|
visitor.on_attribute("block_size", m_blocksize);
|
||||||
visitor.on_attribute("mode", m_mode);
|
visitor.on_attribute("mode", m_mode);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Node> op::DepthToSpace::clone_with_new_inputs(const OutputVector& new_args) const {
|
std::shared_ptr<Node> DepthToSpace::clone_with_new_inputs(const OutputVector& new_args) const {
|
||||||
OV_OP_SCOPE(v0_DepthToSpace_clone_with_new_inputs);
|
OV_OP_SCOPE(v0_DepthToSpace_clone_with_new_inputs);
|
||||||
check_new_args_count(this, new_args);
|
check_new_args_count(this, new_args);
|
||||||
return std::make_shared<DepthToSpace>(new_args.at(0), m_mode, m_blocksize);
|
return std::make_shared<DepthToSpace>(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);
|
OV_OP_SCOPE(v0_DepthToSpace_validate_and_infer_types);
|
||||||
|
|
||||||
OPENVINO_SUPPRESS_DEPRECATED_START
|
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);
|
set_output_type(0, get_input_element_type(0), output_shape);
|
||||||
}
|
}
|
||||||
|
|
||||||
OPENVINO_SUPPRESS_DEPRECATED_START
|
bool DepthToSpace::evaluate(TensorVector& outputs, const TensorVector& inputs) const {
|
||||||
namespace {
|
OV_OP_SCOPE(v0_DepthToSpace_evaluate);
|
||||||
bool evaluate_depth_to_space(const HostTensorVector& outputs,
|
OPENVINO_ASSERT(outputs.size() == 1);
|
||||||
const HostTensorVector& inputs,
|
|
||||||
const std::size_t block_size,
|
|
||||||
const op::DepthToSpace::DepthToSpaceMode mode) {
|
|
||||||
const auto& in = inputs[0];
|
const auto& in = inputs[0];
|
||||||
const auto& out = outputs[0];
|
const auto& out = outputs[0];
|
||||||
const size_t elem_size = in->get_element_type().size();
|
reference::depth_to_space(static_cast<const char*>(in.data()),
|
||||||
if (in->get_partial_shape().is_dynamic()) {
|
in.get_shape(),
|
||||||
return false;
|
static_cast<char*>(out.data()),
|
||||||
}
|
out.get_shape(),
|
||||||
ov::reference::depth_to_space(in->get_data_ptr<char>(),
|
m_blocksize,
|
||||||
in->get_shape(),
|
m_mode,
|
||||||
out->get_data_ptr<char>(),
|
in.get_element_type().size());
|
||||||
out->get_shape(),
|
|
||||||
block_size,
|
|
||||||
mode,
|
|
||||||
elem_size);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} // namespace
|
|
||||||
|
|
||||||
bool op::DepthToSpace::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const {
|
bool DepthToSpace::has_evaluate() 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 {
|
|
||||||
OV_OP_SCOPE(v0_DepthToSpace_has_evaluate);
|
OV_OP_SCOPE(v0_DepthToSpace_has_evaluate);
|
||||||
return !get_input_partial_shape(0).is_dynamic();
|
return !get_input_partial_shape(0).is_dynamic();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& ov::operator<<(std::ostream& s, const ov::op::v0::DepthToSpace::DepthToSpaceMode& type) {
|
void DepthToSpace::set_block_size(size_t block_size) {
|
||||||
return s << as_string(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
void op::v0::DepthToSpace::set_block_size(size_t block_size) {
|
|
||||||
m_blocksize = block_size;
|
m_blocksize = block_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void op::v0::DepthToSpace::set_mode(DepthToSpaceMode mode) {
|
void DepthToSpace::set_mode(DepthToSpaceMode mode) {
|
||||||
m_mode = 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 <>
|
template <>
|
||||||
NGRAPH_API EnumNames<ngraph::op::DepthToSpace::DepthToSpaceMode>&
|
OPENVINO_API EnumNames<op::v0::DepthToSpace::DepthToSpaceMode>&
|
||||||
EnumNames<ngraph::op::DepthToSpace::DepthToSpaceMode>::get() {
|
EnumNames<op::v0::DepthToSpace::DepthToSpaceMode>::get() {
|
||||||
static auto enum_names = EnumNames<ngraph::op::DepthToSpace::DepthToSpaceMode>(
|
static auto enum_names = EnumNames<op::v0::DepthToSpace::DepthToSpaceMode>(
|
||||||
"op::DepthToSpace::DepthToSpaceMode",
|
"op::DepthToSpace::DepthToSpaceMode",
|
||||||
{{"blocks_first", ngraph::op::DepthToSpace::DepthToSpaceMode::BLOCKS_FIRST},
|
{{"blocks_first", op::v0::DepthToSpace::DepthToSpaceMode::BLOCKS_FIRST},
|
||||||
{"depth_first", ngraph::op::DepthToSpace::DepthToSpaceMode::DEPTH_FIRST}});
|
{"depth_first", op::v0::DepthToSpace::DepthToSpaceMode::DEPTH_FIRST}});
|
||||||
return enum_names;
|
return enum_names;
|
||||||
}
|
}
|
||||||
} // namespace ov
|
} // namespace ov
|
||||||
|
Loading…
Reference in New Issue
Block a user