Migrate Maximum operator to new API (#20602)
Co-authored-by: Michal Lukaszewski <michal.lukaszewski@intel.com>
This commit is contained in:
co-authored by
Michal Lukaszewski
parent
7cfeb413d4
commit
e2ea571926
@@ -29,9 +29,7 @@ public:
|
||||
|
||||
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
|
||||
|
||||
@@ -12,13 +12,28 @@
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
namespace func {
|
||||
template <class T>
|
||||
T max(const T a, const T b) {
|
||||
return std::max(a, b);
|
||||
}
|
||||
} // namespace func
|
||||
|
||||
template <typename T>
|
||||
void maximum(const T* arg0, const T* arg1, T* out, size_t count) {
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
out[i] = arg0[i] > arg1[i] ? arg0[i] : arg1[i];
|
||||
}
|
||||
std::transform(arg0, std::next(arg0, count), arg1, out, func::max<T>);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reference implementation of binary elementwise Maximum 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>
|
||||
void maximum(const T* arg0,
|
||||
const T* arg1,
|
||||
@@ -26,9 +41,7 @@ void maximum(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) -> T {
|
||||
return x > y ? x : y;
|
||||
});
|
||||
autobroadcast_binop(arg0, arg1, out, arg0_shape, arg1_shape, broadcast_spec, func::max<T>);
|
||||
}
|
||||
} // namespace reference
|
||||
} // namespace ov
|
||||
|
||||
+46
-63
@@ -2,92 +2,75 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "ngraph/op/maximum.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include "openvino/op/maximum.hpp"
|
||||
|
||||
#include "element_visitor.hpp"
|
||||
#include "itt.hpp"
|
||||
#include "ngraph/op/convert.hpp"
|
||||
#include "ngraph/op/greater.hpp"
|
||||
#include "ngraph/op/multiply.hpp"
|
||||
#include "ngraph/runtime/host_tensor.hpp"
|
||||
#include "ngraph/type/element_type.hpp"
|
||||
#include "openvino/reference/maximum.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ngraph;
|
||||
namespace ov {
|
||||
namespace op {
|
||||
|
||||
// ------------------------------------ v0 -------------------------------------
|
||||
namespace maximum {
|
||||
struct Evaluate : element::NoAction<bool> {
|
||||
using element::NoAction<bool>::visit;
|
||||
|
||||
OPENVINO_SUPPRESS_DEPRECATED_START
|
||||
namespace maximumop {
|
||||
namespace {
|
||||
template <element::Type_t ET>
|
||||
bool evaluate(const HostTensorPtr& arg0,
|
||||
const HostTensorPtr& arg1,
|
||||
const HostTensorPtr& out,
|
||||
const op::AutoBroadcastSpec& broadcast_spec) {
|
||||
ov::reference::maximum(arg0->get_data_ptr<ET>(),
|
||||
arg1->get_data_ptr<ET>(),
|
||||
out->get_data_ptr<ET>(),
|
||||
arg0->get_shape(),
|
||||
arg1->get_shape(),
|
||||
broadcast_spec);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool evaluate_maximum(const HostTensorPtr& arg0,
|
||||
const HostTensorPtr& arg1,
|
||||
const HostTensorPtr& out,
|
||||
const op::AutoBroadcastSpec& broadcast_spec) {
|
||||
bool rc = true;
|
||||
out->set_broadcast(broadcast_spec, arg0, arg1);
|
||||
switch (arg0->get_element_type()) {
|
||||
OPENVINO_TYPE_CASE(evaluate_maximum, i32, arg0, arg1, out, broadcast_spec);
|
||||
OPENVINO_TYPE_CASE(evaluate_maximum, i64, arg0, arg1, out, broadcast_spec);
|
||||
OPENVINO_TYPE_CASE(evaluate_maximum, u32, arg0, arg1, out, broadcast_spec);
|
||||
OPENVINO_TYPE_CASE(evaluate_maximum, u64, arg0, arg1, out, broadcast_spec);
|
||||
OPENVINO_TYPE_CASE(evaluate_maximum, f16, arg0, arg1, out, broadcast_spec);
|
||||
OPENVINO_TYPE_CASE(evaluate_maximum, f32, arg0, arg1, out, broadcast_spec);
|
||||
default:
|
||||
rc = false;
|
||||
break;
|
||||
template <element::Type_t ET, class T = fundamental_type_for<ET>>
|
||||
static result_type visit(const Tensor& arg0,
|
||||
const Tensor& arg1,
|
||||
Tensor& out,
|
||||
const Shape& shape0,
|
||||
const Shape& shape1,
|
||||
const AutoBroadcastSpec& broadcast_spec) {
|
||||
reference::maximum(arg0.data<const T>(), arg1.data<const T>(), out.data<T>(), shape0, shape1, broadcast_spec);
|
||||
return true;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
} // namespace
|
||||
} // namespace maximumop
|
||||
};
|
||||
} // namespace maximum
|
||||
|
||||
// ------------------------------------ v1 -------------------------------------
|
||||
|
||||
op::v1::Maximum::Maximum(const Output<Node>& arg0, const Output<Node>& arg1, const AutoBroadcastSpec& auto_broadcast)
|
||||
namespace v1 {
|
||||
Maximum::Maximum(const Output<Node>& arg0, const Output<Node>& arg1, const AutoBroadcastSpec& auto_broadcast)
|
||||
: BinaryElementwiseArithmetic(arg0, arg1, auto_broadcast) {
|
||||
constructor_validate_and_infer_types();
|
||||
}
|
||||
|
||||
shared_ptr<Node> op::v1::Maximum::clone_with_new_inputs(const OutputVector& new_args) const {
|
||||
std::shared_ptr<Node> Maximum::clone_with_new_inputs(const OutputVector& new_args) const {
|
||||
OV_OP_SCOPE(v1_Maximum_clone_with_new_inputs);
|
||||
check_new_args_count(this, new_args);
|
||||
return make_shared<op::v1::Maximum>(new_args.at(0), new_args.at(1), this->get_autob());
|
||||
return std::make_shared<Maximum>(new_args.at(0), new_args.at(1), get_autob());
|
||||
}
|
||||
|
||||
bool op::v1::Maximum::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const {
|
||||
bool Maximum::evaluate(TensorVector& outputs, const TensorVector& inputs) const {
|
||||
OV_OP_SCOPE(v1_Maximum_evaluate);
|
||||
return maximumop::evaluate_maximum(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<f16, f32, i32, i64, u32, u64>::apply<maximum::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::Maximum::has_evaluate() const {
|
||||
bool Maximum::has_evaluate() const {
|
||||
OV_OP_SCOPE(v1_Maximum_has_evaluate);
|
||||
switch (get_input_element_type(0)) {
|
||||
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::i32:
|
||||
case element::i64:
|
||||
case element::u32:
|
||||
case element::u64:
|
||||
case element::f16:
|
||||
case element::f32:
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // namespace v1
|
||||
} // namespace op
|
||||
} // namespace ov
|
||||
|
||||
Reference in New Issue
Block a user