Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove 'evaluate' from I420toRGB/BGR operations #10128

Merged
merged 6 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/template_plugin/backend/evaluates_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3356,6 +3356,26 @@ inline bool evaluate(const shared_ptr<op::v8::NV12toBGR>& op,
ov::op::util::ConvertColorNV12Base::ColorConversion::NV12_TO_BGR);
}

template <ov::element::Type_t ET>
inline bool evaluate(const shared_ptr<op::v8::I420toRGB>& op,
const HostTensorVector& outputs,
const HostTensorVector& inputs) {
return runtime::reference::color_convert_i420<ET>(op,
outputs,
inputs,
ov::op::util::ConvertColorI420Base::ColorConversion::I420_TO_RGB);
}

template <ov::element::Type_t ET>
inline bool evaluate(const shared_ptr<op::v8::I420toBGR>& op,
const HostTensorVector& outputs,
const HostTensorVector& inputs) {
return runtime::reference::color_convert_i420<ET>(op,
outputs,
inputs,
ov::op::util::ConvertColorI420Base::ColorConversion::I420_TO_BGR);
}

template <element::Type_t ET>
bool evaluate(const shared_ptr<op::v0::Interpolate>& op,
const HostTensorVector& outputs,
Expand Down
2 changes: 2 additions & 0 deletions docs/template_plugin/backend/opset_int_tbl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ NGRAPH_OP(GatherND, op::v8)
NGRAPH_OP(DetectionOutput, op::v8)
NGRAPH_OP(NV12toRGB, op::v8)
NGRAPH_OP(NV12toBGR, op::v8)
NGRAPH_OP(I420toRGB, op::v8)
NGRAPH_OP(I420toBGR, op::v8)

NGRAPH_OP(Sigmoid, op::v0)
NGRAPH_OP(Tanh, op::v0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@ class OPENVINO_API ConvertColorI420Base : public Op {

bool visit_attributes(AttributeVisitor& visitor) override;

OPENVINO_SUPPRESS_DEPRECATED_START
bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override;
OPENVINO_SUPPRESS_DEPRECATED_END

bool has_evaluate() const override;

protected:
bool is_type_supported(const ov::element::Type& type) const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,55 @@ inline bool color_convert_nv12(const std::shared_ptr<Node>& op,
return true;
}

template <ov::element::Type_t ET>
inline bool color_convert_i420(const std::shared_ptr<Node>& op,
const ov::HostTensorVector& outputs,
const ov::HostTensorVector& inputs,
ov::op::util::ConvertColorI420Base::ColorConversion type) {
static const size_t N_DIM = 0;
static const size_t H_DIM = 1;
static const size_t W_DIM = 2;
NGRAPH_CHECK(op->get_input_size() == 1 || op->get_input_size() == 3,
"I420 conversion shall have one or 3 inputs, but it is ",
op->get_input_size());
auto single_plane = op->get_input_size() == 1;

const auto& y_tensor = inputs[0];
auto batch_size = y_tensor->get_shape()[N_DIM];
auto image_w = y_tensor->get_shape()[W_DIM];
auto image_h = y_tensor->get_shape()[H_DIM];
if (single_plane) {
image_h = image_h * 2 / 3;
}
outputs[0]->set_shape({batch_size, image_h, image_w, 3}); // 3 is RGB
if (single_plane) {
color_convert_i420(y_tensor->get_data_ptr<ET>(),
y_tensor->get_data_ptr<ET>() + image_w * image_h,
y_tensor->get_data_ptr<ET>() + 5 * image_w * image_h / 4,
outputs[0]->get_data_ptr<ET>(),
batch_size,
image_h,
image_w,
image_w * image_h * 3 / 2,
image_w * image_h * 3 / 2,
type);
} else {
const auto& u_tensor = inputs[1];
const auto& v_tensor = inputs[2];
color_convert_i420(y_tensor->get_data_ptr<ET>(),
u_tensor->get_data_ptr<ET>(),
v_tensor->get_data_ptr<ET>(),
outputs[0]->get_data_ptr<ET>(),
batch_size,
image_h,
image_w,
image_w * image_h,
image_w * image_h / 4,
type);
}
return true;
}

} // namespace reference
} // namespace runtime
} // namespace ngraph
85 changes: 0 additions & 85 deletions src/core/src/op/util/convert_color_i420_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
#include <ngraph/validation_util.hpp>

#include "itt.hpp"
#include "ngraph/runtime/reference/convert_color_nv12.hpp"
#include "openvino/core/layout.hpp"

namespace i420_op {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like OSX reports unused variables below

static const size_t N_DIM = 0;
static const size_t H_DIM = 1;
static const size_t W_DIM = 2;
static const size_t C_DIM = 3;
Expand Down Expand Up @@ -120,93 +118,10 @@ void ov::op::util::ConvertColorI420Base::validate_and_infer_types() {
set_output_type(0, out_type, out_shape);
}

namespace i420_op {
namespace {

template <ov::element::Type_t ET>
inline bool evaluate(const ov::HostTensorVector& input_values,
const ov::HostTensorPtr& output_value,
bool single_tensor,
ov::op::util::ConvertColorI420Base::ColorConversion color_format) {
using namespace ov::op::util;
const auto& y_tensor = input_values[0];
auto batch_size = y_tensor->get_shape()[N_DIM];
auto image_w = y_tensor->get_shape()[W_DIM];
auto image_h = y_tensor->get_shape()[H_DIM];
if (single_tensor) {
OPENVINO_ASSERT(ngraph::validate_host_tensor_vector(input_values, 1));
image_h = image_h * 2 / 3;
} else {
OPENVINO_ASSERT(ngraph::validate_host_tensor_vector(input_values, 3));
}
output_value->set_shape({batch_size, image_h, image_w, 3}); // 3 is RGB
if (single_tensor) {
ngraph::runtime::reference::color_convert_i420(y_tensor->get_data_ptr<ET>(),
y_tensor->get_data_ptr<ET>() + image_w * image_h,
y_tensor->get_data_ptr<ET>() + 5 * image_w * image_h / 4,
output_value->get_data_ptr<ET>(),
batch_size,
image_h,
image_w,
image_w * image_h * 3 / 2,
image_w * image_h * 3 / 2,
color_format);
} else {
const auto& u_tensor = input_values[1];
const auto& v_tensor = input_values[2];
ngraph::runtime::reference::color_convert_i420(y_tensor->get_data_ptr<ET>(),
u_tensor->get_data_ptr<ET>(),
v_tensor->get_data_ptr<ET>(),
output_value->get_data_ptr<ET>(),
batch_size,
image_h,
image_w,
image_w * image_h,
image_w * image_h / 4,
color_format);
}
return true;
}

bool evaluate_i420_convert(const ov::HostTensorVector& input_values,
const ov::HostTensorPtr& output_value,
bool single_tensor,
ov::op::util::ConvertColorI420Base::ColorConversion conv_format) {
bool rc = false;
switch (input_values[0]->get_element_type()) {
NGRAPH_TYPE_CASE(evaluate_i420_convert, u8, input_values, output_value, single_tensor, conv_format);
NGRAPH_TYPE_CASE(evaluate_i420_convert, f32, input_values, output_value, single_tensor, conv_format);
default:
break;
}
return rc;
}

} // namespace
} // namespace i420_op

bool ov::op::util::ConvertColorI420Base::visit_attributes(AttributeVisitor& visitor) {
return true;
}

bool ov::op::util::ConvertColorI420Base::evaluate(const HostTensorVector& output_values,
const HostTensorVector& input_values) const {
NGRAPH_OP_SCOPE(v0_ConvertColorI420_evaluate);
OPENVINO_ASSERT(ngraph::validate_host_tensor_vector(output_values, 1));
NODE_VALIDATION_CHECK(this,
get_input_size() == 1 || get_input_size() == 3,
"I420 conversion shall have one or 3 inputs, but it is ",
get_input_size());
auto single_plane = get_input_size() == 1;
return i420_op::evaluate_i420_convert(input_values, output_values[0], single_plane, m_format);
}

bool ov::op::util::ConvertColorI420Base::has_evaluate() const {
NGRAPH_OP_SCOPE(v0_ConvertColorI420Base_has_evaluate);

return is_type_supported(get_input_element_type(0));
}

bool ov::op::util::ConvertColorI420Base::is_type_supported(const ov::element::Type& type) const {
return type.is_dynamic() || type.is_real() || type == ov::element::u8;
}
2 changes: 0 additions & 2 deletions src/core/src/op/util/convert_color_nv12_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

#include "openvino/op/util/convert_color_nv12_base.hpp"

#include <memory>
#include <ngraph/validation_util.hpp>

#include "itt.hpp"
#include "ngraph/runtime/reference/convert_color_nv12.hpp"
#include "openvino/core/layout.hpp"

static const size_t N_DIM = 0;
Expand Down