0fae1b49f462459711d04962fad448f3e5fcc10c
[platform/upstream/dldt.git] / ngraph / core / src / op / ceiling.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 "ngraph/op/ceiling.hpp"
18 #include "itt.hpp"
19 #include "ngraph/op/util/eval_copy.hpp"
20 #include "ngraph/runtime/host_tensor.hpp"
21 #include "ngraph/runtime/reference/ceiling.hpp"
22 #include "ngraph/runtime/reference/copy.hpp"
23
24 using namespace std;
25 using namespace ngraph;
26
27 constexpr NodeTypeInfo op::Ceiling::type_info;
28
29 op::Ceiling::Ceiling(const Output<Node>& arg)
30     : UnaryElementwiseArithmetic(arg)
31 {
32     constructor_validate_and_infer_types();
33 }
34
35 shared_ptr<Node> op::Ceiling::clone_with_new_inputs(const OutputVector& new_args) const
36 {
37     check_new_args_count(this, new_args);
38     return make_shared<Ceiling>(new_args.at(0));
39 }
40
41 namespace
42 {
43     // function used by TYPE_CASE
44     template <element::Type_t ET>
45     inline bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count)
46     {
47         using T = typename element_type_traits<ET>::value_type;
48         runtime::reference::ceiling<T>(arg0->get_data_ptr<ET>(), out->get_data_ptr<ET>(), count);
49         return true;
50     }
51
52     // function used by COPY_TENSOR
53     template <element::Type_t ET>
54     inline bool copy_tensor(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count)
55     {
56         runtime::reference::copy(arg0->get_data_ptr<ET>(), out->get_data_ptr<ET>(), count);
57         return true;
58     }
59
60     bool evaluate_ceiling(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count)
61     {
62         bool rc = true;
63         out->set_unary(arg0);
64
65         switch (arg0->get_element_type())
66         {
67             COPY_TENSOR(boolean)(arg0, out, count);
68             break;
69             COPY_TENSOR(i8)(arg0, out, count);
70             break;
71             COPY_TENSOR(i16)(arg0, out, count);
72             break;
73             COPY_TENSOR(i32)(arg0, out, count);
74             break;
75             COPY_TENSOR(i64)(arg0, out, count);
76             break;
77             COPY_TENSOR(u8)(arg0, out, count);
78             break;
79             COPY_TENSOR(u16)(arg0, out, count);
80             break;
81             COPY_TENSOR(u32)(arg0, out, count);
82             break;
83             COPY_TENSOR(u64)(arg0, out, count);
84             break;
85             TYPE_CASE(f16)(arg0, out, count);
86             break;
87             TYPE_CASE(f32)(arg0, out, count);
88             break;
89         default: rc = false; break;
90         }
91         return rc;
92     }
93 }
94
95 bool op::Ceiling::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const
96 {
97     OV_ITT_SCOPED_TASK(itt::domains::nGraphOp, "op::Ceiling::evaluate");
98     return evaluate_ceiling(inputs[0], outputs[0], shape_size(get_output_shape(0)));
99 }