Migrate LessEqual and GreaterEqual to new API (#20645)
Co-authored-by: Michal Lukaszewski <michal.lukaszewski@intel.com>
This commit is contained in:
parent
2b65855793
commit
5fee2ef67e
@ -26,9 +26,7 @@ public:
|
||||
const AutoBroadcastSpec& auto_broadcast = AutoBroadcastSpec(AutoBroadcastType::NUMPY));
|
||||
|
||||
std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& new_args) const 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;
|
||||
};
|
||||
} // namespace v1
|
||||
|
@ -27,9 +27,7 @@ public:
|
||||
const AutoBroadcastSpec& auto_broadcast = AutoBroadcastSpec(AutoBroadcastType::NUMPY));
|
||||
|
||||
std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& new_args) const 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;
|
||||
};
|
||||
} // namespace v1
|
||||
|
@ -4,23 +4,13 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/op/util/attr_types.hpp"
|
||||
#include "openvino/reference/autobroadcast_binop.hpp"
|
||||
#include "openvino/reference/less_eq.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
template <typename T>
|
||||
void greater_eq(const T* arg0,
|
||||
const T* arg1,
|
||||
char* out,
|
||||
size_t count) // TODO: using char for bool, is this right?
|
||||
{
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
out[i] = arg0[i] >= arg1[i];
|
||||
}
|
||||
void greater_eq(const T* arg0, const T* arg1, char* out, size_t count) {
|
||||
less_eq(arg1, arg0, out, count);
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
@ -30,9 +20,7 @@ void greater_eq(const T* arg0,
|
||||
const Shape& arg0_shape,
|
||||
const Shape& arg1_shape,
|
||||
const op::AutoBroadcastSpec& broadcast_spec) {
|
||||
autobroadcast_binop(arg0, arg1, out, arg0_shape, arg1_shape, broadcast_spec, [](T x, T y) -> U {
|
||||
return static_cast<U>(x >= y);
|
||||
});
|
||||
less_eq(arg1, arg0, out, arg1_shape, arg0_shape, broadcast_spec);
|
||||
}
|
||||
} // namespace reference
|
||||
} // namespace ov
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <algorithm>
|
||||
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/op/util/attr_types.hpp"
|
||||
@ -12,17 +12,30 @@
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
template <typename T>
|
||||
void less_eq(const T* arg0,
|
||||
const T* arg1,
|
||||
char* out,
|
||||
size_t count) // TODO: using char for bool, is this right?
|
||||
{
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
out[i] = arg0[i] <= arg1[i];
|
||||
namespace func {
|
||||
// Use custom implementation as function instead std::less_equal functor, gives smaller binary size.
|
||||
// If removed or replace check impact on library binary size.
|
||||
template <class T>
|
||||
constexpr bool less_eq(const T lhs, const T rhs) {
|
||||
return lhs <= rhs;
|
||||
}
|
||||
} // namespace func
|
||||
|
||||
template <typename T>
|
||||
void less_eq(const T* arg0, const T* arg1, char* out, const size_t count) {
|
||||
std::transform(arg0, std::next(arg0, count), arg1, out, func::less_eq<T>);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reference implementation of binary elementwise LessEqual operator.
|
||||
*
|
||||
* @param arg0 Pointer to input 0 data.
|
||||
* @param arg1 Pointer to input 1 data.
|
||||
* @param out Pointer to output data.
|
||||
* @param arg0_shape Input 0 shape.
|
||||
* @param arg1_shape Input 1 shape.
|
||||
* @param broadcast_spec Broadcast specification mode.
|
||||
*/
|
||||
template <typename T, typename U>
|
||||
void less_eq(const T* arg0,
|
||||
const T* arg1,
|
||||
@ -30,9 +43,7 @@ void less_eq(const T* arg0,
|
||||
const Shape& arg0_shape,
|
||||
const Shape& arg1_shape,
|
||||
const op::AutoBroadcastSpec& broadcast_spec) {
|
||||
autobroadcast_binop(arg0, arg1, out, arg0_shape, arg1_shape, broadcast_spec, [](T x, T y) -> U {
|
||||
return static_cast<U>(x <= y);
|
||||
});
|
||||
autobroadcast_binop(arg0, arg1, out, arg0_shape, arg1_shape, broadcast_spec, func::less_eq<T>);
|
||||
}
|
||||
} // namespace reference
|
||||
} // namespace ov
|
||||
|
@ -2,92 +2,81 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "ngraph/op/greater_eq.hpp"
|
||||
#include "openvino/op/greater_eq.hpp"
|
||||
|
||||
#include "element_visitor.hpp"
|
||||
#include "itt.hpp"
|
||||
#include "ngraph/runtime/host_tensor.hpp"
|
||||
#include "ngraph/validation_util.hpp"
|
||||
#include "openvino/reference/greater_eq.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ngraph;
|
||||
namespace ov {
|
||||
namespace op {
|
||||
namespace greater_equal {
|
||||
|
||||
OPENVINO_SUPPRESS_DEPRECATED_START
|
||||
namespace greater_equalop {
|
||||
namespace {
|
||||
template <element::Type_t ET>
|
||||
bool evaluate(const HostTensorPtr& arg0,
|
||||
const HostTensorPtr& arg1,
|
||||
const HostTensorPtr& out,
|
||||
const op::AutoBroadcastSpec& broadcast_spec) {
|
||||
ov::reference::greater_eq(arg0->get_data_ptr<ET>(),
|
||||
arg1->get_data_ptr<ET>(),
|
||||
out->get_data_ptr<element::Type_t::boolean>(),
|
||||
arg0->get_shape(),
|
||||
arg1->get_shape(),
|
||||
struct Evaluate : element::NoAction<bool> {
|
||||
using element::NoAction<bool>::visit;
|
||||
|
||||
template <element::Type_t ET, class T = fundamental_type_for<ET>>
|
||||
static result_type visit(const Tensor& in0,
|
||||
const Tensor& in1,
|
||||
Tensor& out,
|
||||
const Shape& shape0,
|
||||
const Shape& shape1,
|
||||
const AutoBroadcastSpec& broadcast_spec) {
|
||||
reference::greater_eq(in0.data<const T>(),
|
||||
in1.data<const T>(),
|
||||
out.data<fundamental_type_for<element::boolean>>(),
|
||||
shape0,
|
||||
shape1,
|
||||
broadcast_spec);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
} // namespace greater_equal
|
||||
|
||||
bool evaluate_greater_equal(const HostTensorPtr& arg0,
|
||||
const HostTensorPtr& arg1,
|
||||
const HostTensorPtr& out,
|
||||
const op::AutoBroadcastSpec& broadcast_spec) {
|
||||
bool rc = true;
|
||||
out->set_broadcast(broadcast_spec, arg0, arg1, element::boolean);
|
||||
switch (arg0->get_element_type()) {
|
||||
OPENVINO_TYPE_CASE(evaluate_greater_equal, boolean, arg0, arg1, out, broadcast_spec);
|
||||
OPENVINO_TYPE_CASE(evaluate_greater_equal, i32, arg0, arg1, out, broadcast_spec);
|
||||
OPENVINO_TYPE_CASE(evaluate_greater_equal, i64, arg0, arg1, out, broadcast_spec);
|
||||
OPENVINO_TYPE_CASE(evaluate_greater_equal, u32, arg0, arg1, out, broadcast_spec);
|
||||
OPENVINO_TYPE_CASE(evaluate_greater_equal, u64, arg0, arg1, out, broadcast_spec);
|
||||
OPENVINO_TYPE_CASE(evaluate_greater_equal, f16, arg0, arg1, out, broadcast_spec);
|
||||
OPENVINO_TYPE_CASE(evaluate_greater_equal, f32, arg0, arg1, out, broadcast_spec);
|
||||
default:
|
||||
rc = false;
|
||||
break;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
} // namespace
|
||||
} // namespace greater_equalop
|
||||
|
||||
//---------------------------------- v1 ----------------------------------------
|
||||
|
||||
op::v1::GreaterEqual::GreaterEqual(const Output<Node>& arg0,
|
||||
const Output<Node>& arg1,
|
||||
const AutoBroadcastSpec& auto_broadcast)
|
||||
//-------------------------------------- v1 ------------------------------------
|
||||
namespace v1 {
|
||||
GreaterEqual::GreaterEqual(const Output<Node>& arg0, const Output<Node>& arg1, const AutoBroadcastSpec& auto_broadcast)
|
||||
: BinaryElementwiseComparison(arg0, arg1, auto_broadcast) {
|
||||
constructor_validate_and_infer_types();
|
||||
}
|
||||
|
||||
shared_ptr<Node> op::v1::GreaterEqual::clone_with_new_inputs(const OutputVector& new_args) const {
|
||||
std::shared_ptr<Node> GreaterEqual::clone_with_new_inputs(const OutputVector& new_args) const {
|
||||
OV_OP_SCOPE(v1_GreaterEqual_clone_with_new_inputs);
|
||||
check_new_args_count(this, new_args);
|
||||
return make_shared<op::v1::GreaterEqual>(new_args.at(0), new_args.at(1), this->get_autob());
|
||||
return std::make_shared<GreaterEqual>(new_args.at(0), new_args.at(1), get_autob());
|
||||
}
|
||||
|
||||
bool op::v1::GreaterEqual::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const {
|
||||
bool GreaterEqual::evaluate(TensorVector& outputs, const TensorVector& inputs) const {
|
||||
OV_OP_SCOPE(v1_GreaterEqual_evaluate);
|
||||
OPENVINO_SUPPRESS_DEPRECATED_START
|
||||
OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 2));
|
||||
OPENVINO_SUPPRESS_DEPRECATED_END
|
||||
return greater_equalop::evaluate_greater_equal(inputs[0], inputs[1], outputs[0], get_autob());
|
||||
OPENVINO_ASSERT(outputs.size() == 1);
|
||||
|
||||
outputs[0].set_shape(infer_broadcast_shape(this, inputs));
|
||||
using namespace ov::element;
|
||||
return IfTypeOf<boolean, f16, f32, i32, i64, u32, u64>::apply<greater_equal::Evaluate>(inputs[0].get_element_type(),
|
||||
inputs[0],
|
||||
inputs[1],
|
||||
outputs[0],
|
||||
inputs[0].get_shape(),
|
||||
inputs[1].get_shape(),
|
||||
get_autob());
|
||||
}
|
||||
|
||||
bool op::v1::GreaterEqual::has_evaluate() const {
|
||||
bool GreaterEqual::has_evaluate() const {
|
||||
OV_OP_SCOPE(v1_GreaterEqual_has_evaluate);
|
||||
switch (get_input_element_type(0)) {
|
||||
case ngraph::element::boolean:
|
||||
case ngraph::element::i32:
|
||||
case ngraph::element::i64:
|
||||
case ngraph::element::u32:
|
||||
case ngraph::element::u64:
|
||||
case ngraph::element::f16:
|
||||
case ngraph::element::f32:
|
||||
case element::boolean:
|
||||
case element::f16:
|
||||
case element::f32:
|
||||
case element::i32:
|
||||
case element::i64:
|
||||
case element::u32:
|
||||
case element::u64:
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} // namespace v1
|
||||
} // namespace op
|
||||
} // namespace ov
|
||||
|
@ -2,88 +2,81 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "ngraph/op/less_eq.hpp"
|
||||
#include "openvino/op/less_eq.hpp"
|
||||
|
||||
#include "element_visitor.hpp"
|
||||
#include "itt.hpp"
|
||||
#include "ngraph/runtime/host_tensor.hpp"
|
||||
#include "openvino/reference/less_eq.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ngraph;
|
||||
namespace ov {
|
||||
namespace op {
|
||||
namespace less_equal {
|
||||
|
||||
// ---------------------------------- v1 ---------------------------------------
|
||||
struct Evaluate : element::NoAction<bool> {
|
||||
using element::NoAction<bool>::visit;
|
||||
|
||||
op::v1::LessEqual::LessEqual(const Output<Node>& arg0,
|
||||
const Output<Node>& arg1,
|
||||
const AutoBroadcastSpec& auto_broadcast)
|
||||
template <element::Type_t ET, class T = fundamental_type_for<ET>>
|
||||
static result_type visit(const Tensor& in0,
|
||||
const Tensor& in1,
|
||||
Tensor& out,
|
||||
const Shape& shape0,
|
||||
const Shape& shape1,
|
||||
const AutoBroadcastSpec& broadcast_spec) {
|
||||
reference::less_eq(in0.data<const T>(),
|
||||
in1.data<const T>(),
|
||||
out.data<fundamental_type_for<element::boolean>>(),
|
||||
shape0,
|
||||
shape1,
|
||||
broadcast_spec);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
} // namespace less_equal
|
||||
|
||||
// ----------------------------- v1 --------------------------------------------
|
||||
namespace v1 {
|
||||
LessEqual::LessEqual(const Output<Node>& arg0, const Output<Node>& arg1, const AutoBroadcastSpec& auto_broadcast)
|
||||
: BinaryElementwiseComparison(arg0, arg1, auto_broadcast) {
|
||||
constructor_validate_and_infer_types();
|
||||
}
|
||||
|
||||
shared_ptr<Node> op::v1::LessEqual::clone_with_new_inputs(const OutputVector& new_args) const {
|
||||
std::shared_ptr<Node> LessEqual::clone_with_new_inputs(const OutputVector& new_args) const {
|
||||
OV_OP_SCOPE(v1_LessEqual_clone_with_new_inputs);
|
||||
check_new_args_count(this, new_args);
|
||||
return make_shared<v1::LessEqual>(new_args.at(0), new_args.at(1), this->get_autob());
|
||||
return std::make_shared<LessEqual>(new_args.at(0), new_args.at(1), get_autob());
|
||||
}
|
||||
|
||||
OPENVINO_SUPPRESS_DEPRECATED_START
|
||||
namespace less_equalop {
|
||||
namespace {
|
||||
template <element::Type_t ET>
|
||||
bool evaluate(const HostTensorPtr& arg0,
|
||||
const HostTensorPtr& arg1,
|
||||
const HostTensorPtr& out,
|
||||
const op::AutoBroadcastSpec& broadcast_spec) {
|
||||
ov::reference::less_eq(arg0->get_data_ptr<ET>(),
|
||||
arg1->get_data_ptr<ET>(),
|
||||
out->get_data_ptr<element::Type_t::boolean>(),
|
||||
arg0->get_shape(),
|
||||
arg1->get_shape(),
|
||||
broadcast_spec);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool evaluate_less_equal(const HostTensorPtr& arg0,
|
||||
const HostTensorPtr& arg1,
|
||||
const HostTensorPtr& out,
|
||||
const op::AutoBroadcastSpec& broadcast_spec) {
|
||||
bool rc = true;
|
||||
out->set_broadcast(broadcast_spec, arg0, arg1, element::boolean);
|
||||
switch (arg0->get_element_type()) {
|
||||
OPENVINO_TYPE_CASE(evaluate_less_equal, boolean, arg0, arg1, out, broadcast_spec);
|
||||
OPENVINO_TYPE_CASE(evaluate_less_equal, i32, arg0, arg1, out, broadcast_spec);
|
||||
OPENVINO_TYPE_CASE(evaluate_less_equal, i64, arg0, arg1, out, broadcast_spec);
|
||||
OPENVINO_TYPE_CASE(evaluate_less_equal, u32, arg0, arg1, out, broadcast_spec);
|
||||
OPENVINO_TYPE_CASE(evaluate_less_equal, u64, arg0, arg1, out, broadcast_spec);
|
||||
OPENVINO_TYPE_CASE(evaluate_less_equal, f16, arg0, arg1, out, broadcast_spec);
|
||||
OPENVINO_TYPE_CASE(evaluate_less_equal, f32, arg0, arg1, out, broadcast_spec);
|
||||
default:
|
||||
rc = false;
|
||||
break;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
} // namespace
|
||||
} // namespace less_equalop
|
||||
|
||||
bool op::v1::LessEqual::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const {
|
||||
bool LessEqual::evaluate(TensorVector& outputs, const TensorVector& inputs) const {
|
||||
OV_OP_SCOPE(v1_LessEqual_evaluate);
|
||||
return less_equalop::evaluate_less_equal(inputs[0], inputs[1], outputs[0], get_autob());
|
||||
OPENVINO_ASSERT(outputs.size() == 1);
|
||||
|
||||
outputs[0].set_shape(infer_broadcast_shape(this, inputs));
|
||||
using namespace ov::element;
|
||||
return IfTypeOf<boolean, f16, f32, i32, i64, u32, u64>::apply<less_equal::Evaluate>(inputs[0].get_element_type(),
|
||||
inputs[0],
|
||||
inputs[1],
|
||||
outputs[0],
|
||||
inputs[0].get_shape(),
|
||||
inputs[1].get_shape(),
|
||||
get_autob());
|
||||
}
|
||||
|
||||
bool op::v1::LessEqual::has_evaluate() const {
|
||||
bool LessEqual::has_evaluate() const {
|
||||
OV_OP_SCOPE(v1_LessEqual_has_evaluate);
|
||||
switch (get_input_element_type(0)) {
|
||||
case ngraph::element::boolean:
|
||||
case ngraph::element::i32:
|
||||
case ngraph::element::i64:
|
||||
case ngraph::element::u32:
|
||||
case ngraph::element::u64:
|
||||
case ngraph::element::f16:
|
||||
case ngraph::element::f32:
|
||||
case element::boolean:
|
||||
case element::f16:
|
||||
case element::f32:
|
||||
case element::i32:
|
||||
case element::i64:
|
||||
case element::u32:
|
||||
case element::u64:
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} // namespace v1
|
||||
} // namespace op
|
||||
} // namespace ov
|
||||
|
Loading…
Reference in New Issue
Block a user