[IE][NGRAPH][BUILD] Enable UNITY build for more targets (#2592)
[platform/upstream/dldt.git] / ngraph / core / src / op / tanh.cpp
1 //*****************************************************************************
2 // Copyright 2017-2020 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //*****************************************************************************
16
17 #include "itt.hpp"
18
19 #include "ngraph/op/multiply.hpp"
20 #include "ngraph/op/subtract.hpp"
21 #include "ngraph/op/tanh.hpp"
22
23 #include "ngraph/runtime/host_tensor.hpp"
24 #include "ngraph/runtime/reference/tanh.hpp"
25
26 using namespace std;
27 using namespace ngraph;
28
29 constexpr NodeTypeInfo op::Tanh::type_info;
30
31 op::Tanh::Tanh(const Output<Node>& arg)
32     : UnaryElementwiseArithmetic(arg)
33 {
34     constructor_validate_and_infer_types();
35 }
36
37 bool ngraph::op::v0::Tanh::visit_attributes(AttributeVisitor& visitor)
38 {
39     return true;
40 }
41
42 shared_ptr<Node> op::Tanh::clone_with_new_inputs(const OutputVector& new_args) const
43 {
44     check_new_args_count(this, new_args);
45     return make_shared<Tanh>(new_args.at(0));
46 }
47
48 namespace tanhop
49 {
50     template <element::Type_t ET>
51     inline bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count)
52     {
53         using T = typename element_type_traits<ET>::value_type;
54         runtime::reference::tanh<T>(arg0->get_data_ptr<ET>(), out->get_data_ptr<ET>(), count);
55         return true;
56     }
57
58     bool evaluate_tanh(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count)
59     {
60         bool rc = true;
61         out->set_unary(arg0);
62
63         switch (arg0->get_element_type())
64         {
65             TYPE_CASE(i32)(arg0, out, count);
66             break;
67             TYPE_CASE(i64)(arg0, out, count);
68             break;
69             TYPE_CASE(u32)(arg0, out, count);
70             break;
71             TYPE_CASE(u64)(arg0, out, count);
72             break;
73             TYPE_CASE(f16)(arg0, out, count);
74             break;
75             TYPE_CASE(f32)(arg0, out, count);
76             break;
77         default: rc = false; break;
78         }
79         return rc;
80     }
81 }
82
83 bool op::Tanh::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const
84 {
85     OV_ITT_SCOPED_TASK(itt::domains::nGraphOp, "op::Tanh::evaluate");
86     return tanhop::evaluate_tanh(inputs[0], outputs[0], shape_size(get_output_shape(0)));
87 }