|
2 | 2 | // SPDX-License-Identifier: Apache-2.0 |
3 | 3 | // |
4 | 4 |
|
5 | | -#include "ngraph/op/add.hpp" |
| 5 | +#include "openvino/op/add.hpp" |
6 | 6 |
|
| 7 | +#include "element_visitor.hpp" |
7 | 8 | #include "itt.hpp" |
8 | | -#include "ngraph/runtime/host_tensor.hpp" |
9 | 9 | #include "openvino/reference/add.hpp" |
| 10 | +#include "utils.hpp" |
10 | 11 |
|
11 | | -using namespace std; |
12 | | -using namespace ngraph; |
13 | | - |
14 | | -OPENVINO_SUPPRESS_DEPRECATED_START |
| 12 | +namespace ov { |
| 13 | +namespace op { |
15 | 14 | namespace add { |
16 | | -namespace { |
17 | | -template <element::Type_t ET> |
18 | | -bool evaluate(const HostTensorPtr& arg0, |
19 | | - const HostTensorPtr& arg1, |
20 | | - const HostTensorPtr& out, |
21 | | - const op::AutoBroadcastSpec& broadcast_spec) { |
22 | | - ov::reference::add(arg0->get_data_ptr<ET>(), |
23 | | - arg1->get_data_ptr<ET>(), |
24 | | - out->get_data_ptr<ET>(), |
25 | | - arg0->get_shape(), |
26 | | - arg1->get_shape(), |
27 | | - broadcast_spec); |
28 | | - return true; |
29 | | -} |
| 15 | +struct Evaluate : element::NoAction<bool> { |
| 16 | + using ov::element::NoAction<bool>::visit; |
30 | 17 |
|
31 | | -bool evaluate_add(const HostTensorPtr& arg0, |
32 | | - const HostTensorPtr& arg1, |
33 | | - const HostTensorPtr& out, |
34 | | - const op::AutoBroadcastSpec& broadcast_spec) { |
35 | | - bool rc = true; |
36 | | - out->set_broadcast(broadcast_spec, arg0, arg1); |
37 | | - switch (arg0->get_element_type()) { |
38 | | - NGRAPH_TYPE_CASE(evaluate_add, i8, arg0, arg1, out, broadcast_spec); |
39 | | - NGRAPH_TYPE_CASE(evaluate_add, i16, arg0, arg1, out, broadcast_spec); |
40 | | - NGRAPH_TYPE_CASE(evaluate_add, i32, arg0, arg1, out, broadcast_spec); |
41 | | - NGRAPH_TYPE_CASE(evaluate_add, i64, arg0, arg1, out, broadcast_spec); |
42 | | - NGRAPH_TYPE_CASE(evaluate_add, u8, arg0, arg1, out, broadcast_spec); |
43 | | - NGRAPH_TYPE_CASE(evaluate_add, u16, arg0, arg1, out, broadcast_spec); |
44 | | - NGRAPH_TYPE_CASE(evaluate_add, u32, arg0, arg1, out, broadcast_spec); |
45 | | - NGRAPH_TYPE_CASE(evaluate_add, u64, arg0, arg1, out, broadcast_spec); |
46 | | - NGRAPH_TYPE_CASE(evaluate_add, bf16, arg0, arg1, out, broadcast_spec); |
47 | | - NGRAPH_TYPE_CASE(evaluate_add, f16, arg0, arg1, out, broadcast_spec); |
48 | | - NGRAPH_TYPE_CASE(evaluate_add, f32, arg0, arg1, out, broadcast_spec); |
49 | | - default: |
50 | | - rc = false; |
51 | | - break; |
| 18 | + template <element::Type_t ET> |
| 19 | + static result_type visit(const Tensor& in0, |
| 20 | + const Tensor& in1, |
| 21 | + Tensor& out, |
| 22 | + const AutoBroadcastSpec& broadcast_spec) { |
| 23 | + using T = typename element_type_traits<ET>::value_type; |
| 24 | + reference::add(in0.data<const T>(), |
| 25 | + in1.data<const T>(), |
| 26 | + out.data<T>(), |
| 27 | + in0.get_shape(), |
| 28 | + in1.get_shape(), |
| 29 | + broadcast_spec); |
| 30 | + return true; |
52 | 31 | } |
53 | | - return rc; |
54 | | -} |
55 | | -} // namespace |
| 32 | +}; |
56 | 33 | } // namespace add |
57 | 34 |
|
58 | 35 | // ------------------------------- v1 ------------------------------------------ |
59 | | - |
60 | | -op::v1::Add::Add(const Output<Node>& arg0, const Output<Node>& arg1, const AutoBroadcastSpec& auto_broadcast) |
| 36 | +namespace v1 { |
| 37 | +Add::Add(const Output<Node>& arg0, const Output<Node>& arg1, const AutoBroadcastSpec& auto_broadcast) |
61 | 38 | : BinaryElementwiseArithmetic(arg0, arg1, auto_broadcast) { |
62 | 39 | constructor_validate_and_infer_types(); |
63 | 40 | } |
64 | 41 |
|
65 | | -bool op::v1::Add::visit_attributes(AttributeVisitor& visitor) { |
66 | | - OV_OP_SCOPE(v1_Add_visit_attributes); |
67 | | - BinaryElementwiseArithmetic::visit_attributes(visitor); |
68 | | - return true; |
69 | | -} |
70 | | - |
71 | | -shared_ptr<Node> op::v1::Add::clone_with_new_inputs(const OutputVector& new_args) const { |
| 42 | +std::shared_ptr<Node> Add::clone_with_new_inputs(const OutputVector& new_args) const { |
72 | 43 | OV_OP_SCOPE(v1_Add_clone_with_new_inputs); |
73 | 44 | check_new_args_count(this, new_args); |
74 | | - return make_shared<op::v1::Add>(new_args.at(0), new_args.at(1), this->get_autob()); |
| 45 | + return std::make_shared<op::v1::Add>(new_args.at(0), new_args.at(1), this->get_autob()); |
75 | 46 | } |
76 | 47 |
|
77 | | -bool op::v1::Add::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { |
| 48 | +bool Add::evaluate(ov::TensorVector& outputs, const ov::TensorVector& inputs) const { |
78 | 49 | OV_OP_SCOPE(v1_Add_evaluate); |
79 | | - return add::evaluate_add(inputs[0], inputs[1], outputs[0], get_autob()); |
80 | | -} |
| 50 | + OPENVINO_ASSERT(outputs.size() == 1); |
| 51 | + OPENVINO_ASSERT(inputs.size() == 2); |
81 | 52 |
|
82 | | -bool op::v1::Add::evaluate(ov::TensorVector& outputs, const ov::TensorVector& inputs) const { |
83 | | - OV_OP_SCOPE(v1_Add_evaluate); |
84 | | - if (std::none_of(inputs.cbegin(), inputs.cend(), [](const ov::Tensor& t) { |
85 | | - return is_vector(t.get_shape()) && t.get_shape().front() == 0; |
86 | | - })) { |
87 | | - return BinaryElementwiseArithmetic::evaluate(outputs, inputs); |
88 | | - } else { |
89 | | - return true; |
90 | | - } |
| 53 | + outputs[0].set_shape(infer_broadcast_shape(this, inputs[0].get_shape(), inputs[1].get_shape())); |
| 54 | + using namespace ov::element; |
| 55 | + return IfTypeOf<bf16, f16, f32, i8, i16, i32, i64, u8, u16, u32, u64>::apply<add::Evaluate>( |
| 56 | + inputs[0].get_element_type(), |
| 57 | + inputs[0], |
| 58 | + inputs[1], |
| 59 | + outputs[0], |
| 60 | + get_autob()); |
91 | 61 | } |
92 | 62 |
|
93 | | -bool op::v1::Add::has_evaluate() const { |
| 63 | +bool Add::has_evaluate() const { |
94 | 64 | OV_OP_SCOPE(v1_Add_has_evaluate); |
95 | 65 | switch (get_input_element_type(0)) { |
96 | | - case ngraph::element::i8: |
97 | | - case ngraph::element::i16: |
98 | | - case ngraph::element::i32: |
99 | | - case ngraph::element::i64: |
100 | | - case ngraph::element::u8: |
101 | | - case ngraph::element::u16: |
102 | | - case ngraph::element::u32: |
103 | | - case ngraph::element::u64: |
104 | | - case ngraph::element::bf16: |
105 | | - case ngraph::element::f16: |
106 | | - case ngraph::element::f32: |
| 66 | + case element::i8: |
| 67 | + case element::i16: |
| 68 | + case element::i32: |
| 69 | + case element::i64: |
| 70 | + case element::u8: |
| 71 | + case element::u16: |
| 72 | + case element::u32: |
| 73 | + case element::u64: |
| 74 | + case element::bf16: |
| 75 | + case element::f16: |
| 76 | + case element::f32: |
107 | 77 | return true; |
108 | 78 | default: |
109 | | - break; |
| 79 | + return false; |
110 | 80 | } |
111 | | - return false; |
112 | 81 | } |
| 82 | +} // namespace v1 |
| 83 | +} // namespace op |
| 84 | +} // namespace ov |
0 commit comments